// JavaScript Document


function submitLoginForm(form) {
  form.action = "login.do?methodLogin=getLogin";
  form.submit();
}
	
function submitLangCode(form) {
  form.submit();
}
       
   
function test(form) {
      
    
  if(navigator.appName == "Microsoft Internet Explorer")
    {
		
      form.action = "productKeys.do?showCopy=yes";
          
      form.submit();
    }
  else
    {
			
			
      form.action = "productKeys.do?showCopy=no";
          
      form.submit();
			
    }
			
}
function submitLangCode1(form, fPage) {
  form.cPage.value =fPage;
  form.submit();
}
function openHelp(){
  window.open("/amsweb/help/help.jsp","","width=560,height=400,scrollbars=1");
}
		
function help(a) {
  var lang = getCookie("amslang");
  var ancre = a;
  var helpURL;
  
  if (lang == "jp" || lang == "JP") {
	  helpURL = "/amsweb/help/help_ja.jsp" + "#" + ancre;
  } else {
	  helpURL = "/amsweb/help/help.jsp" + "#" + ancre;
  }
	
  window.open(helpURL,'Help','width=535,height=600,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,left=300,top=50,screenX=300,screenY=150');
}
function submitForgetPassword(form) {
  form.action = "login.do?methodLogin=forgotPassword";
  form.submit( );
}


function submitPostPurchaseLoginForm(action) {
  document.postPurchaseTransactionForm.action = "processPostPurchaseTransaction.do?method=";
  document.postPurchaseTransactionForm.action += action;
  document.postPurchaseTransactionForm.submit( );
}

function enterForgetPassword(form) {
  form.action = "forgotPassword.do?method=forgotPassword";
        
  form.submit();
}   
     
function editAccountUpdate(form) {
  form.action = "editAccount.do?method=accUpdate";
          
  form.submit();
}  
     
function editAccountCancel(form) {
  form.action = "editAccount.do?method=accCancel";
        
  form.submit();
}  
     
function changeUpdate(form) {
  form.action = "changePassword.do?method=changeUpdate";
          
  form.submit();
}  
     
function changeCancel(form) {
  form.action = "changePassword.do?method=changeCancel";
        
  form.submit();
}  
     
  
function noContextMenu() {
  if (document.all) {
    document.oncontextmenu=new Function("return false");
  }
}
function ClipBoard(index)
{
  var myTextArea = document.all("holdtext" + index);
  myTextArea.innerText = document.all("copytext" + index).innerText;
  myTextArea.innerText = "{311079D6-ACEA-4f99-81EA-4AFE051DE402}" + myTextArea.innerText;
  Copied = myTextArea.createTextRange();
  Copied.execCommand("RemoveFormat");
  Copied.execCommand("Copy");
}
	
function clearAnswer(form) {
  form.securityAnswer.value = "";
       
}
     
function checkBrowser(form)
{
  if(navigator.appName == "Microsoft Internet Explorer")
    {
      form.showCopy.value = "yes";
    }
}
     
function togglemarkOption1(form) {
  setCookie('naMarketing', 'checked');
  if (form.markOption1.checked == false) {
      form.marketing1.value = "unset";
    } else {
      form.marketing1.value = "off";
    }
}
      
function togglemarkOption2(form) {
  setCookie('naMarketing', 'checked');
  if (form.markOption1.checked == false) {
      form.marketing1.value = "unset";
   } else {
      form.marketing1.value = "off";
    }
}
     
/* 04-08-08 - Added code to function below to properly handle the automatic checking and unchecking of the marketing questions based on user interaction. This checks for the setCookie() method added at the beginning of the two pre-existing togglemarkOption functions above. The "out" value is set by an added onmousedown function to the Cancel button in the createAccount.jsp. This addition to the Cancel button was made to assure the marketing checkbox behaviors continued to be correct in the event that the user cancled the account creation and then decided to re-enter the create account page.*/

function changeCountry(form,origin) {
   var marketingChecked = getCookie('naMarketing');
  if (form.accountCountry.value == "US" && !marketingChecked) {
	  form.markOption1.checked = true;
      form.markOption2.checked = true;
      if (origin == 'edit')
      	form.action = "editAccount.do?param=country";
      else 
      	form.action = "createAccount.do?param=country";
	  form.submit( );
  } else if (form.accountCountry.value == "US" && marketingChecked == "out") {
      form.markOption1.checked = true;
      form.markOption2.checked = true;
      if (origin == 'edit')
      	form.action = "editAccount.do?param=country";
      else 
      	form.action = "createAccount.do?param=country";
	  form.submit( );
  } else if (form.accountCountry.value == "US" && marketingChecked == "checked") {
	  if (origin == 'edit')
	  	form.action = "editAccount.do?param=country";
	  else 
      	form.action = "createAccount.do?param=country";
	  form.submit( );
    }       
  
   if (form.accountCountry.value !== "US" && !marketingChecked) {
	   form.markOption1.checked = false;
       form.markOption2.checked = false;
       if (origin == 'edit')
       		form.action = "editAccount.do?param=country";
	   else 
      		form.action = "createAccount.do?param=country";
	   form.submit( );
  } else if (form.accountCountry.value !== "US" && marketingChecked == "out"){
	  form.markOption1.checked = false;
      form.markOption2.checked = false;
      if (origin == 'edit')
      		form.action = "editAccount.do?param=country";
  	  else 
      		form.action = "createAccount.do?param=country";
  	  form.submit( );
  } else if (form.accountCountry.value !== "US" && marketingChecked == "checked"){
  		if (origin == 'edit')
  			form.action = "editAccount.do?param=country";
	  	else 
      		form.action = "createAccount.do?param=country";
	  	form.submit( );
  }
}

function changeBillingCountry(form) {
	form.action = "editBilling.do?param=country";
	form.submit( );
}
     
function clearAnswer(form) {
  form.securityAnswer.value = "";
         
}
function clearCardNo(form) {
  form.creditCardNo.value = "";
         
}
     
function changeCardType(form) {
  form.creditCardNo.value = "";
  form.submit();
}

/*
  ns4 = (document.layers) ?1:0;
  ie4 = (document.all) ?1:0;
  dom = (document.getElementsById) ?1:0;
  if (ns4) document.captureEvents(Event.KEYDOWN);
  document.onkeydown = keyDown;
  window.onkeydown = keyDown;

  function keyDown(e) {
  var keyPress = (ie4) ? window.event.keyCode : e.which ;
  shft = ((ns4) ? e.modifiers && Event.SHIFT_MASK   :
  window.event.shiftKey) ? " shft " :"";
  alt  = ((ns4) ? e.modifiers && Event.ALT_MASK     :
  window.event.altKey)   ? " alt "  :"";
  ctrl = ((ns4) ? e.modifiers && Event.CONTROL_MASK :
  window.event.ctrlKey)  ? " ctrl " :"";
  meta = ((ns4) ? e.modifiers && Event.META_MASK    :
  window.event.metaKey)  ? " meta " :"";
  var key = String.fromCharCode(keyPress);
  window.status= key + ' (' +keyPress + ') ' + shft + ' ' + alt + ' '
  + ctrl + ' ' + meta;
  return false;
  }
*/

function onKeyDown() {
  // current pressed key
	
  var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
  alert("pressedKey= " + pressedKey);
  var msg = "Paste is disabled in this field."

    if (event.ctrlKey && (pressedKey == "c" || pressedKey == "v")) {
      alert(msg);
      // disable key press porcessing
      event.returnValue = false;
    }
 
}
 
function disablePaste() {
  var msg = "Paste is disabled in this field."
  var pasteAttempted = false
  if (document.all) { // IE
    if (event.button == 2) { // right-click
      pasteAttempted = true
    }
  }
  if (pasteAttempted) {
      alert(msg);
      return false; 
  }
}

function keyDown(e) {
  if (e.keyCode == 91) commandkey = true;
}

function ck(e) {
  alert(e.metaKey);
  if (e.metaKey) {
    alert("metaKey is true! You are pressing the Command key.")
      } else {
    alert("metaKey is false or undefined.");
  }
}
  
  
var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

