function prepareSubmit(var1,var2)
{
	document.getElementById("studentName").value = var1;
	document.getElementById("anticipatedGradYear").value = var2;
}
function displaySection(varformname1)
{
var varformname = document.getElementById(varformname1);
var arrLength = varformname.userType.length;
if (arrLength != undefined)
{
	for (num = 0; num < arrLength-1; num++)
	{
		var ischecked = varformname.userType[num].checked;
		var string = varformname.userType[num].value;		
		if (ischecked)
		{
			document.getElementById(string).style.visibility="visible";
			document.getElementById(string).style.display="block";
		}
		else
		{
			document.getElementById(string).style.visibility="hidden";
			document.getElementById(string).style.display="none";
			P7_colH2();
		}
	}
  }
}
function formsubmit()
{	
	var formElement = document.getElementById("profileUpdate");
	document.profileUpdate.phone1.value = document.profileUpdate.textphone1.value+document.profileUpdate.textphone2.value+document.profileUpdate.textphone3.value;
	document.profileUpdate.phone2.value = document.profileUpdate.cellphone1.value+document.profileUpdate.cellphone2.value+document.profileUpdate.cellphone3.value;
	
 /* REMOVED AS A PART OF RELEASE - 4.6D
	if(formElement.demographicField1.checked)
    {
	   formElement.demographicField1.value='Y';
	}
	else
	{
	   formElement.demographicField1.value='N';
	}*/

	if(formElement.demographicField2.checked)
	{
		formElement.demographicField2.value='Y';
	}
	else
	{
		formElement.demographicField2.value='N';
	}
	if(formElement.cellPhoneAlertOptInFlag.checked)
	{
		formElement.cellPhoneAlertOptIn.value='Y';
	}
	else
	{
	formElement.cellPhoneAlertOptIn.value='N';
	}
	/* REMOVED AS A PART OF RELEASE - 4.6D
	var studentName = document.getElementById("txtStudentName").value;
	var anticipatedGradYear = document.getElementById("txtAnticipatedGradYear").value;
	
	var retVal  = true;
	if(studentName != '' || anticipatedGradYear != '')
	{
		retVal = addStudent(true);

	}
	if (retVal)
	{*/
		formElement.addressField1.value = 'Y';
		
		formElement.addressField2.value = formElement.demographicField2.value;
		formElement.submit();
	//}
}

//This function adds Student section to the Parent Student div.
function addStudent(isReturn)
{
	var retVal = true;
	var studentName = document.getElementById("txtStudentName").value;
	var anticipatedGradYear = document.getElementById("txtAnticipatedGradYear").value;

	if(studentName.trim() =='' || anticipatedGradYear.trim() =='')
	{
		alert("Please enter full details for the student.");
		retVal = false;
	}
	else
	{
	//Variable which will hold name of the newly created div
	var divIdName;

	//Variable that holds the value of div that have to be created on the fly
	var objElem = document.getElementById('divCounter');
	//increment the div number
	var num = (document.getElementById("divCounter").value -1)+2;

	//The new div to be created
	var newdiv = document.createElement('div');
	//Assigning the incremented number to hidden object
	objElem.value = num;

	//Create the div name on the fly
	divIdName = "DivStudent_"+num;
	studentNameParam = "DivStudent_Name_"+num;
	//Set the id for newly created div
	newdiv.setAttribute("id",divIdName);
	//If there is only one div, create the Add Student section only
	newdiv.innerHTML =  document.getElementById("studentData").innerHTML.replace('divIdName',divIdName);
	//Reset the div name
	divIdName = "";
	//Set the parent div as visible	
	newdiv.innerHTML = newdiv.innerHTML.replace('txtStudentName', studentName);
	newdiv.innerHTML = newdiv.innerHTML.replace('studentNameDiv', studentNameParam);
	newdiv.innerHTML = newdiv.innerHTML.replace('txtAnticipatedGradYear', anticipatedGradYear);
	newdiv.innerHTML = newdiv.innerHTML.replace('txtAnticipatedGradYear', anticipatedGradYear);
	document.getElementById("divStudent").style.visibility="";
	document.getElementById("divStudent").style.position="";
	//Append newly created div to the Parent Student div
	document.getElementById("divStudent").appendChild(newdiv);	
	document.getElementById(studentNameParam).value=studentName;
	//var inputType = '<input type="text" property="studentName" value="'+studentName+'">';
	document.getElementById("txtStudentName").value = "";	
	document.getElementById("txtAnticipatedGradYear").value = "";
	}
	if (isReturn)
	{
		return retVal;
	}
}

function validateAndSave()
{
var allAddresses = document.AddCard.address;
var oneChecked = "false";
var validate= false;

 formSubmit1();
 
 if (allAddresses.length == undefined)
	{
		if (allAddresses.checked)
		{
			oneChecked = "true";
		}
	}
	else
	{
		for(var i = 0; i< allAddresses.length; i++)
		{
			if(allAddresses[i].checked)
			{
				oneChecked = "true";
				break;
			}
		}
	}
	
	if (document.AddCard.cardType.value == '' )
	{
	alert("Please select a card type.");
	validate= false;
	}else{
		var res = checkCCBin(document.AddCard);
		if(res)
		{
			if(oneChecked == "false")
			{
				alert("Please select one billing address for the card");
				validate= false;
			}
			validate= true;
		}else
		{
			alert("Card number is invalid. Please enter a valid card number.");
			validate= false;
		}
	}
return validate;
}

function isNumeric(val)
{
	if (val.match(/^[0-9]+$/))
	{
	return true;
	}
	else
	{
	return false;
	} 
}


function checkCCBin(addCardForm)
{
var retVal= false;

	if ( addCardForm.cardType.value == 'MasterCard')
	{
		if ((addCardForm.cardNumber.value.trim().length == 14) || (addCardForm.cardNumber.value.trim().length == 16))
		{
			if(isNumeric(addCardForm.cardNumber.value))
			{
			var crdNo= addCardForm.cardNumber.value.trim();
			crdNo=crdNo.substring(0,2);
			var num= crdNo - 0;
				if((num == 36) || (num >= 51 && num <= 55))
				{
				retVal=true;			
				}
				else
				{
				retVal=false;					
				}
			}
			else
			{
			retVal=false;
			}
		}
		else
		{
		retVal=false;
		}
	}else if ( addCardForm.cardType.value == 'Visa')
	{
		if ((addCardForm.cardNumber.value.trim().length == 13) || (addCardForm.cardNumber.value.trim().length == 16))
		{
	
			if(isNumeric(addCardForm.cardNumber.value))
			{
			var crdNo= addCardForm.cardNumber.value.trim();
			crdNo=crdNo.substring(0,1);
			var num= crdNo - 0;
				if(num == 4)
				{
				retVal=true;			
				}else{
				retVal=false;			
				}			
			}
			else
			{
			retVal=false;
			}
		}
		else
		{
		retVal=false;
		}
		
	}else if ( addCardForm.cardType.value == 'American Express')
	{
		if ( addCardForm.cardNumber.value.trim().length == 15 )
		{
			if(isNumeric(addCardForm.cardNumber.value))
			{
			var crdNo= addCardForm.cardNumber.value.trim();
			crdNo=crdNo.substring(0,2);
			var num= crdNo - 0;
				if(num == 34 || num == 37 )
				{
				retVal=true;			
				}
				else
				{
				retVal=false;					
				}
			}
			else
			{
			retVal=false;
			}
		}
		else
		{
		retVal=false;
		}
	}else if ( addCardForm.cardType.value == 'Discover')
	{
		if ( addCardForm.cardNumber.value.trim().length == 16 )
		{
			if(isNumeric(addCardForm.cardNumber.value))
			{
			var crdNo= addCardForm.cardNumber.value.trim();
			crdNo=crdNo.substring(0,4);
			var num= crdNo - 0;
				if ((num == 6011)|| (num >= 6500 && num <= 6500))
				{
				retVal=true;			
				}
				else
				{
				retVal=false;					
				}			
			}
			else
			{
			retVal=false;
			}
		}
		else
		{
		retVal=false;
		}			
	}
	else if  ( addCardForm.cardType.value == 'Diners Club')
	{
	retVal=true;
	}
return retVal; 
}


//This function removes Student from the Parent div depending on the divNum passed.
function removeStudent(divNum)
{
	//Array object that holds the div name
	divArray =  divNum.split("_");

	//Variable that holds the parent div from which the child has to be removed,

	//Variable that holds the child div that has to be removed.
	var olddiv = document.getElementById(divNum);
	divParent = document.getElementById('divStudent');
	//Removing the child div from parent.
	divParent.removeChild(olddiv);
	//divStudent.style.position="";
	P7_colH2();
	P7_equalCols2(0,'leftNav','P','ctrContent','P','rtContent','P');	
}
/*
 * Javascript to submit change logon id and password
 */
function submitChangeLogonIdPassword(form)
{
	if (form.newEmail.value.trim().length == 0)
	{
		form.logonId.value = form.currentLogonId.value;
	}
	else
	{
		form.logonId.value = form.newEmail.value;
	}
	form.email1.value = form.logonId.value;
	form.submit();
}

//The above function removes the blank spaces
String.prototype.trim=function()
{
     var
         r=/^\s+|\s+$/,
         a=this.split(/\n/g),
         i=a.length;
     while(i-->0)
     {
         a[i]=a[i].replace(r,'');
	 }
     return a.join('\n');
}


/* creating a new pop up window */

function openRequestedPopup(url)
{
  /* Declaring a global variable which will store
  a reference to the new window to be created */
  var windowObjectReference;

  windowObjectReference = window.open(url, "HomepageAnnouncement_WindowName",
        "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,height=300,width=650");

}

function confirmDelete(param)
{
	var answer = confirm ("Are you sure you want to delete this "+param+"?");
	return answer;
}

function validateNumeric(e)
{

	var keyPressed;
	if(window.event)
	{
		keyPressed = window.event.keyCode; // IE
		
	} else {
		keyPressed = e.which; // Firefox
	}

	//KeyCode -> Numbers=45 to 57 Tab/Del/Arrow keys=0 and Backspace=8: KeyCode for Tab is 9 on MAC Safari
	if((keyPressed < 45 || keyPressed > 57) && keyPressed != 0 && keyPressed !=8 && keyPressed !=9) {
		if(window.event){
			window.event.returnValue = false; // IE
		} else {
			e.preventDefault(); // Firefox
		}
	} 
	
	
}

function autofocus(field, limit, next, evt) 
{
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && field.value.length == limit) 
    {
        field.form.elements[next].focus();
    }

}

//Account Pages
 /* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */
 function populateStateAndCountryDropDown(){
  	   	
	var internationalPhone= document.getElementById("internationalPhone");
	var usPhone= document.getElementById("usPhone");
		
	if (document.getElementById('poAddressFlag').checked == true) {
		poOnCheck();
		if(usPhone.style.display == "block")
		{
		}else{
			usPhone.style.display="block";
			internationalPhone.style.display="none";
		} 
	}else{
		poOnUnCheck();
	}	
 }
 
 /* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */  
 function poOnCheck(){
 
    document.getElementById('country').disabled = true;
    document.getElementById('state').disabled = true;
    document.getElementById('country').selectedIndex = 0;
	document.getElementById('state').selectedIndex = 0;
		
		while(document.getElementById('state').length > 1){
			document.getElementById('state').remove(document.getElementById('state').length - 1);
		}		
		while(document.getElementById('country').length > 1){
			document.getElementById('country').remove(document.getElementById('country').length - 1);
		}
			var oOption = document.createElement("OPTION");
			oOption.value = 'US';
			oOption.text = 'United States';
			oOption.selected = 'selected';
			try{
				document.getElementById('country').options.add(oOption);
			}
			catch(error){
				document.getElementById('country').add(oOption);
			}
		onPOChange(true,false);
			
		document.getElementById('country').disabled = false;	
 }
 
/* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */  
 function poOnUnCheck(){
    document.getElementById('country').disabled = true;
    
	document.getElementById('country').selectedIndex = 0;

		while(document.getElementById('country').length > 1){
			document.getElementById('country').remove(document.getElementById('country').length - 1);
		}
		
			for(var i = 0; i < countries.length; i++){
				var oOption = document.createElement("OPTION");
			
				oOption.text = countries[i];
					oOption.value = countrieKeys[i];
					if(countrieKeys[i] == 'US')
					{
						oOption.selected = 'selected';
					}
				try{
					document.getElementById('country').options.add(oOption);
				}
				catch(error){
					document.getElementById('country').add(oOption);
				}
			}
		onPOChange(false,true);
		document.getElementById('country').disabled = false;	
  } 
  
  /* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */    
 function OnStateChange()
 {
       document.getElementById('country').disabled = true;
    
   	   var state = document.getElementById('state').value;
	   var country = null;
    
		document.getElementById('country').selectedIndex = 0;

		while(document.getElementById('country').length > 1){
			document.getElementById('country').remove(document.getElementById('country').length - 1);
		}
		
		for(var i = 0; i < statesCode.length; i++)
		{
			if(statesCode[i] == state)
			{
				country = countrieCode[i]; 
			}
		}
		
			for(var i = 0; i < countries.length; i++){
				var oOption = document.createElement("OPTION");
			
				oOption.text = countries[i];
					oOption.value = countrieKeys[i];
					
					if(countrieKeys[i] == country)
					{
						oOption.selected = 'selected';
					}
				try{
					document.getElementById('country').options.add(oOption);
				}
				catch(error){
					document.getElementById('country').add(oOption);
				}
			}
		document.getElementById('country').disabled = false;
		updateTelephoneTextBoxOnCountry();	
  }
  
/* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */    
  function updateTelephoneTextBoxOnCountry(){

	   	var textphone1= document.getElementById("textphone1");
		var textphone2= document.getElementById("textphone2");
		var textphone3= document.getElementById("textphone3");
		var textphone4= document.getElementById("textphone4");
		var internationalPhone= document.getElementById("internationalPhone");
		var phone1= document.getElementById("phone1");
		var usPhone= document.getElementById("usPhone");
		var notUSPhoneFormat= document.getElementById("notUSPhoneFormat");
		
		if(document.getElementById('poAddressFlag').checked == false)
		{	
			if(countryUsPhone[document.getElementById('country').selectedIndex] == false){
				usPhone.style.display="none";
				internationalPhone.style.display="block";
				notUSPhoneFormat.value="true";
				textphone2.value="";
				textphone3.value="";
				textphone1.value="";
				textphone4.value="";
		  	}
		  	else{
		  		usPhone.style.display="block";
				internationalPhone.style.display="none";
				notUSPhoneFormat.value="false";
				textphone4.value="";
				phone1.value="";
				}						
		}	
 } 
/* Release 4.3 Scope 5.1/5.2 | International/PO Shipping | Owner: Ashok */  
 function updateShippingMethodComboboxOnCountry(){
   
  }
  
/* Release 4.6 Scope 6.10 | Akamai front end changes| Owner: Ravi*/  
function processCartData(){
var strId = document.getElementById("storeId").value;
var cmdUrl='';
//if the page is http then call BNCBShowShoppingCartDetailsCmd (http) else call BNCBShowShoppingCartHttpsCmd (https) command 
if(location.protocol=="http:")
{
cmdUrl = '/webapp/wcs/stores/servlet/BNCBShowShoppingCartDetailsCmd';
}else{
cmdUrl='/webapp/wcs/stores/servlet/BNCBShowShoppingCartHttpsCmd';
}
		var miniArgs = 
			{
				url:	cmdUrl,
				content: 
				{
					catalogId:10001,
					langId:-1,
					storeId:strId
				},
				preventCache: true,
				error:	function(type, errObj)
				{
				},
				load:	function(type, data, evt)
				{
			     var miniC = document.getElementById("miniCart");
 				miniC.innerHTML = data;
				}
			};
			var requestObjs = dojo.io.bind(miniArgs);			
}
