/*
'******************************************************************************
'    Date	    By    Bug/Req#     Comments
'  07/14/2003   MMN   BUG12911     modified the email format validation. 
'                                  The actual validation routine is located
'                                  at wwwroot/js/validate_Email.js
'******************************************************************************
*/

/**************************************************************************************
 Utility Functions: 1. isFunction 2. isObject
 isObject is used here to chk whether a formElement Exists or not
*/

function isFunction(a) {

    return typeof a == 'function';

}
function isObject(a) {

    return (typeof a == 'object' && !!a) || isFunction(a);

}

/*  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
   In case of a select box where multiple selects are allowed. This function returns the count of 
   all that were selected
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  */
function getSelectedCount(selectBox)
{
	var totCount=0;
	for(var i=0; i<selectBox.length;i++)
	{
		if (selectBox[i].selected)
		{
			totCount+=1;
		}
	}
	return totCount;
}
//--------------------------------------------------
function removeSpaces(string) {
	var newString = '';
	for (var i = 0; i < string.length; i++) {
		if (string.charAt(i) != ' ') newString += string.charAt(i);
	}
	return newString;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function popup(url){
   self.name="popup";
   remote = open(url, "remote", "scrollbars,width=525,height=300");
}

function before_registerCheck(DnEvents)
{
	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) registerCheck(); 
}

function getCurrentUrl()
{
	return document.location.toString()
}

function registerCheck()
{
	var strUserName = "Please enter your Username"
	var strPassword = "Please enter your Password"
	
	var check_flag = true;

 	if ( document.prompt.username.value == "" && check_flag )	{
 		alert(strUserName)
 		document.prompt.username.focus();
 		check_flag = false;
 	}
 	if ( document.prompt.password.value == "" && check_flag )	{
 		alert(strPassword)
 		document.prompt.password.focus();
 		check_flag = false;
 	}

	if (check_flag)
	{
		document.prompt.submit();				
	}	

}

function before_currentUserCheck(DnEvents)
{
	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) currentUserCheck(); 
}

function currentUserCheck()
{
	var strUserName = "Please enter your Username"
	var strPassword = "Please enter your Password"
	
	var check_flag = true;

 	if ( document.prompt.username.value == "" && check_flag )	{
 		alert(strUserName)
 		document.prompt.username.focus();
 		check_flag = false;
 	}
 	if ( document.prompt.password.value == "" && check_flag )	{
 		alert(strPassword)
 		document.prompt.password.focus();
 		check_flag = false;
 	}

	if (check_flag)
	{
		document.prompt.submit();				
	}	

}

function before_currentVUserCheck(DnEvents)
{
	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) currentUserCheck(); 
}

function currentVUserCheck()
{
	var strUserName = "Please enter your Username"
	var strPassword = "Please enter your Password"
	
	var check_flag = true;

 	if ( document.prompt.REusername.value == "" && check_flag )	{
 		alert(strUserName)
 		document.prompt.REusername.focus();
 		check_flag = false;
 	}
 	if ( document.prompt.REpassword.value == "" && check_flag )	{
 		alert(strPassword)
 		document.prompt.REpassword.focus();
 		check_flag = false;
 	}

	if (check_flag)
	{
		document.prompt.submit();				
	}	

}


function gotoregister()
{
	document.registerit.submit();			
}

function gotocurrentprompt()
{
	document.gotocurrentprompt.action = "prompt_current.asp"
	document.gotocurrentprompt.submit();			
}

function gotocurrentregister()
{
	document.gotocurrentprompt.userflag.value = true;
	document.gotocurrentprompt.action = "register.asp"
	document.gotocurrentprompt.submit();			
}

function before_destinationCheck(DnEvents)
{
	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) checkKeyEntryForm(); 
}


function checkKeyEntryForm() 
{

	var check_flag = true;
	var strActcodeMsg = "Please enter your Activation Key Code"
	var strActcodeLenMsg = "Please enter a valid Activation Key Code"
	var ActcodeVal = document.ActForm.Actcode.value; 	 	
 	
 	if ( document.ActForm.Actcode.value == "" && check_flag )	{
 		alert(strActcodeMsg)
 		document.ActForm.Actcode.focus();
 		check_flag = false;
 	}
 	 	
 	
 	if ( ActcodeVal.length < 6 && check_flag )	{
 		alert(strActcodeLenMsg)
 		document.ActForm.Actcode.focus();
 		check_flag = false; 	
 	}
 	 	 	
	if (check_flag)
	{
		document.ActForm.submit();		
	}	
}

function before_regdestinationCheck(DnEvents)
{
	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) checkForm(); 
}
//--------------------------------



function checkCCForm() 
{

	var check_flag = true;

	var strCCName = "Please enter your name as it appears on the creditcard"
	var strStreet = "Please enter your street address "
	var strCity = "Please enter your city"
	var strState = "Please enter your State/Province/Region"
	var strCountry = "Please enter your Country"
	var strZipcode = "Please enter your Zip Code"
	var strPostalcode = "Please enter your Postal Code"
	var strCCcode = "Please enter your Credit Card number"
	var strCCcodeNumeric = "Credit card number must be numeric."
	var strZipcodeLen = "Zip Code must be 5 numeric characters."
	var strPostalcodeLen = "Postal Code must be 5 numeric characters."
	var strZipcodeNumeric = "Postal Code must be numeric."
	var ZipcodeLen = document.ccpage.Zipcode.value;
	var strUserName = "Please enter a User Name"
	var strUserNameLength = "Username must be at least four characters"
	var strPasswordLength = "Password must be at least four characters"
	
	

 	if ( document.ccpage.cc_name.value == "" && check_flag )	{
 		alert(strCCName)
 		document.ccpage.cc_name.focus();
 		check_flag = false;
 	}
 		
 	if ( document.ccpage.Streetaddress1.value == "" && check_flag )	{
 		alert(strStreet)
 		document.ccpage.Streetaddress1.focus();
 		check_flag = false;
 	}
  	
  	if ( document.ccpage.cc_City.value == "" && check_flag )	{
 		alert(strCity)
 		document.ccpage.cc_City.focus();
 		check_flag = false;
 	}
 	
 	if ( ( document.ccpage.cc_Country.options[document.ccpage.cc_Country.selectedIndex].value == "US" || document.ccpage.cc_Country.options[document.ccpage.cc_Country.selectedIndex].value == "CA" ) && check_flag )
	{
 		if ( document.ccpage.cc_State.selectedIndex == "0" && check_flag )	{
 			alert(strState)
 			document.ccpage.cc_State.focus();
 			check_flag = false;
 		}
 	}
 	
 	if ( document.ccpage.cc_Country.selectedIndex == "0" && check_flag )	{
 		alert(strCountry)
 		document.ccpage.cc_Country.focus();
 		check_flag = false;
 	}
 	
 	var selected_country = document.ccpage.cc_Country.selectedIndex;
 	alert("selected_country: " + selected_country);
	if (selected_country != 0 && selected_country != 1 && selected_country != 39)  	
	{	
		document.ccpage.Zipcode.value = "00000"
	}
 	
 	 	 	
 	if ( document.ccpage.Zipcode.value == "" && check_flag )	{
 		alert(strZipcode)
 		document.ccpage.Zipcode.focus();
 		check_flag = false;
 	}
 	
 	if ( document.ccpage.cc_number.value == "" && check_flag )	{
 		alert(strCCcode)
 		document.ccpage.cc_number.focus();
 		check_flag = false;
 	}
 	
 	if ( document.ccpage.cc_number.value - 0 != document.ccpage.cc_number.value  && check_flag)	{
 			alert(strCCcodeNumeric)
 			document.ccpage.cc_number.value = "";
 			document.ccpage.cc_number.focus();
 			check_flag = false;
 		} 	
 	 	 	
 	if (selected_country == 1 )
 	{
 		if ( ZipcodeLen.length != 5 && check_flag )	{
 			alert(strZipcodeLen)
 			document.ccpage.Zipcode.value = "";
 			document.ccpage.Zipcode.focus();
 			check_flag = false; 		 		
 		}
 		if ( document.ccpage.Zipcode.value - 0 != document.ccpage.Zipcode.value  && check_flag)	{
 			alert(strZipcodeNumeric)
 			document.ccpage.Zipcode.value = "";
 			document.ccpage.Zipcode.focus();
 			check_flag = false;
 		} 	
 	}

	
 	
	if (check_flag)
	{
		document.ccpage.submit();		
	}	
}





//-----------------------
function checkStateUS(checkstate) {
	var statenumber = 60;
	var returnFlag = false;
	var statearray = new Array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MS","MO","MT","NE","NM","NV","NH","NJ","NM","NY","MN","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY", "PR", "AS", "FM", "GU", "MH", "MP", "PW", "VI")
	for (var i = 0; i < statenumber; i++)
	{
		if (statearray[i] == checkstate)
			returnFlag = true;
	}
	return returnFlag
}
 

function checkStateCA(checkstate) {
	var statenumber = 13;
	var returnFlag = false;
	var statearray = new Array("AB","BC","MB","NB","NF","NS","ON","PE","PQ","SK", "NT", "YT", "QC")
	for (var i = 0; i < statenumber; i++)
	{
		if (statearray[i] == checkstate)
			returnFlag = true;
	}
	return returnFlag
}


function checkForm() 
{

	var check_flag = true;

	var strFirstName = "Please enter your First Name"
	var strLastName = "Please enter your Last Name"
	var strMembertype = "Please enter your Member type"	
	var strZipcode = "Please enter your Zip Code"
	var strPostalcode = "Please enter your Postal Code"
	var strZipcodeLen = "Zip Code must be 5 numeric characters."
	var strPostalcodeLen = "Postal Code must be 5 numeric characters."
	var strZipcodeNumeric = "Postal Code must be numeric."
	var strreEmailaddress = "Please enter your Confirmation Email Address"
	var strcoEmailaddress = "Confirmation e-mail address does not match your original email address."
	var strUserName = "Please enter a Username"
	var strUserNameLength = "Username must be at least four characters"
	var strPassword = "Please enter your Password"
	var strStreet = "Please enter your street address (line 1)"
	var strCity = "Please enter your city"
	var strState = "Please enter your State/Province/Region"
	var strCountry = "Please enter your Country"
	var strReenterPassword = "Please confirm the Password by reentering the Password"
	var strPasswordNoMatch = "Re-Entered Password does not match Password" 
	var strGender = "Please select gender"
	var ZipcodeLen = document.regpage.Zipcode.value;
	var strUserName = "Please enter a User Name"
	var strUserNameLength = "Username must be at least four characters"
	var strPasswordLength = "Password must be at least four characters"
	var strPassword = "Please enter your Password"
	var strReenterPassword = "Please confirm the Password by reentering the Password"
	var strPasswordNoMatch = "Re-Entered Password does not match Password" 
	var strGender = "Please select gender"
	var strChallengequestion = "Please select a Challenge Question"
	var strChallengeResponse = "Please enter a Challenge Question Response"
	var usernameLen = trim(document.regpage.Username.value);
	var passwordLen = trim(document.regpage.userPassword.value);
	var nonvalidCountry = "The Country you have selected does not match your selection for State/Province/Region."
	var nonvalidUSstate = "The selection you have made for State/Province/Region does not match the Country you have selected."
	var nonvalidCAstate = "The selection you have made for State/Province/Region does not match the Country you have selected."
	var strTestDate = "Please select a test date"
	var strValidZipcode = "Please enter valid Zip Code"
	var strValidPostalcode = "Please enter valid Postal Code"
	var strEnrollment = "Please enter your Anticipated Enrollment Date"	
	
	var strPhone = "Please enter a valid phone number."
//	var phone_area = document.regpage.phone_area.value;
//	var phone1 = document.regpage.phone1.value;
//	var phone2 = document.regpage.phone2.value;
//	var phone_ext = document.regpage.phone_ext.value;


 	if (removeSpaces(document.regpage.Firstname.value) == "" && check_flag )	{
 		alert(strFirstName);
 		document.regpage.Firstname.value = '';
 		document.regpage.Firstname.focus();
 		check_flag = false;
 	}
 	if ( removeSpaces(document.regpage.Lastname.value) == "" && check_flag )	{ 		
 		alert(strLastName)
 		document.regpage.Lastname.value = '';
 		document.regpage.Lastname.focus();
 		check_flag = false;
 	}
 	
 		//Srinayan
 	
 	
 	
 	if (isObject(document.regpage.Membertype) && check_flag)
 	   {
 	   var mt;
 	   mt = document.regpage.Membertype.options[document.regpage.Membertype.selectedIndex].value;
 	    if ( (mt== "X" ||mt=="") && check_flag )	
 	    {
 		   //alert("Please choose an Education Level")
 		    alert(strMembertype)
 		    document.regpage.Membertype.focus();
 		    check_flag = false;
 	   }	    
 	}
 	
 	if (isObject(document.regpage.EnrollmentMonth) && check_flag)
 	   {
 	   var my,mm;
       var now = new Date(); 
       var d   = new Date(); 
 	   my = document.regpage.EnrollmentYear.options[document.regpage.EnrollmentYear.selectedIndex].value;
 	   mm = document.regpage.EnrollmentMonth.options[document.regpage.EnrollmentMonth.selectedIndex].value;
       if ( (my== "X" ||my=="" || mm== "X" ||mm=="" ) && check_flag )	
       {
 		    alert(strEnrollment)
 		    document.regpage.EnrollmentMonth.focus();
 		    check_flag = false;
 	   }
 	   else
 	   {
            d.setYear(my); 
            d.setMonth(mm-1); 
            d.setDate(now.getDate()+1)
            if (d-now<0)
            {
                alert("Anticipated Enrollment Date already passed.");
       		    document.regpage.EnrollmentYear.focus();
 	    	    check_flag = false;
     	    }
 	   }
 	}

 	if (isObject(document.regpage.EnrollmentYear) && check_flag)
 	   {
 	   var my,mm;
       var now = new Date(); 
       var d   = new Date(); 
 	   my = document.regpage.EnrollmentYear.options[document.regpage.EnrollmentYear.selectedIndex].value;
 	   mm = document.regpage.EnrollmentMonth.options[document.regpage.EnrollmentMonth.selectedIndex].value;
       if ( (my== "X" ||my=="" || mm== "X" ||mm=="" ) && check_flag )	
       {
 		    alert(strEnrollment)
 		    document.regpage.EnrollmentYear.focus();
 		    check_flag = false;
 	   }
 	   else
 	   {
            d.setYear(my); 
            d.setMonth(mm-1); 
            d.setDate(now.getDate()+1)
            if (d-now<0)
            {
                alert("Anticipated Enrollment Date already passed.");
       		    document.regpage.EnrollmentYear.focus();
 	    	    check_flag = false;
     	    }
 	   }
 	}

 	if (isObject(document.regpage.Academic_Field) && check_flag)
 	   {
 	    	   
 	    /* This check for free GMAT, it does not have a label item. So checking for X is immaterial - SP TST28539*/
 	    if(document.regpage.Academic_Field.selectedIndex==-1)
 			{alert("Please choose a Field of Interest")
 		    document.regpage.Academic_Field.focus();
 		    check_flag = false;
 		    }
 	   else
 	   /*  the stipulation for max of 10 was imposed for FREE GMAT TST28539*/
 		if(document.regpage.Academic_Field.type=="select-multiple" && getSelectedCount(document.regpage.Academic_Field)>10)
 		{
 		    var selectedCount =getSelectedCount(document.regpage.Academic_Field);
 		    if (selectedCount == document.regpage.Academic_Field.length)
 				{selectedCount="everything."}
 		    
 			alert("Please limit your selections to a maximum of 10 Fields of Interest.\nYou have currently selected " + selectedCount)
 		    document.regpage.Academic_Field.focus();
 		    check_flag = false;
 		} 			
 	   else
 	    if(document.regpage.Academic_Field.options[document.regpage.Academic_Field.selectedIndex].value == "X" && check_flag )	
 	    {
 		    alert("Please choose a Field of Interest")
 		    document.regpage.Academic_Field.focus();
 		    check_flag = false;
 	   }	    
 	}
 	
 	if (isObject(document.regpage.Academic_Area) && check_flag)
 	   {
 	    if (document.regpage.Academic_Area.options[document.regpage.Academic_Area.selectedIndex].value == "X" && check_flag )	
 	    {
 		    alert("Please choose an Area of Interest")
 		    document.regpage.Academic_Area.focus();
 		    check_flag = false;
 	   }	    
 	}
 	//<--Srinayan
 	//added to validate only when regmode is new
 	if ( document.regpage.regmode.value != "EDIT" ) {
 		if ( document.regpage.Membertype.selectedIndex == "0" && check_flag )	{
 			alert(strMembertype)
 			document.regpage.Membertype.focus();
 			check_flag = false;
 		}
 		if ( isObject(document.regpage.EnrollmentMonth) && document.regpage.EnrollmentMonth.selectedIndex == "0" && check_flag )	{
 			alert(strEnrollment)
 			document.regpage.EnrollmentMonth.focus();
 			check_flag = false;
 		}
 		if ( isObject(document.regpage.EnrollmentYear) && document.regpage.EnrollmentYear.selectedIndex == "0" && check_flag )	{
 			alert(strEnrollment)
 			document.regpage.EnrollmentYear.focus();
 			check_flag = false;
 		}

 	}
 	
	// MMN BUG12911 ->
 	var validEmail = validate_Email(document.regpage.Emailaddress.value);
 		if (!(validEmail[0])  && check_flag){ 
			alert(validEmail[1]);
			document.regpage.Emailaddress.focus();
			check_flag = false;
		}
	// MMN BUG12911 ->	
	
 	if ( document.regpage.Emailaddress.value != document.regpage.reEmailaddress.value && check_flag )	{
 		alert(strcoEmailaddress)
 		document.regpage.reEmailaddress.focus();
 		check_flag = false;
 	}
 	
/*	if 	(check_flag && phone_area != "") {
		if (check_flag && !verifyDigit(phone_area, 3))	{
 			alert(strPhone)
 			document.regpage.phone_area.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone1 == "") {
 			alert(strPhone)
 			document.regpage.phone1.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone2 == "") {
 			alert(strPhone)
 			document.regpage.phone2.focus();
 			check_flag = false;
 		}
 	} 	
	if 	(check_flag && phone1 != "") {
		if (check_flag && !verifyDigit(phone1, 3))	{
 			alert(strPhone)
 			document.regpage.phone1.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone_area == "") {
 			alert(strPhone)
 			document.regpage.phone_area.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone2 == "") {
 			alert(strPhone)
 			document.regpage.phone2.focus();
 			check_flag = false;
 		}
 	}
	if 	(check_flag && phone2 != "") {
		if (check_flag && !verifyDigit(phone2, 4))	{
 			alert(strPhone)
 			document.regpage.phone2.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone_area == "") {
 			alert(strPhone)
 			document.regpage.phone_area.focus();
 			check_flag = false;
 		}
 		if (check_flag && phone1 == "") {
 			alert(strPhone)
 			document.regpage.phone1.focus();
 			check_flag = false;
 		}
 	}
 	
 	if (check_flag && phone_ext != "")  {					
		
			if(phone_ext.length > 5)
			{
				alert(strPhone)
 				document.regpage.phone_ext.focus();
 				check_flag = false;
			}
			else
			{
				var nonnumberCheck = /\D/i	
				if (nonnumberCheck.test(phone_ext)) 
				{
					alert(strPhone);
					document.regpage.phone_ext.focus();
					check_flag = false;	
				} 
			}
 	}
*/ 	
 	
 	/* NEW FUNCTIONALITY PUT IN PLACE TT: BUG16607 
	* if 	(check_flag && phone_ext != "") {
	* 	if (check_flag && !verifyDigit(phone_ext, 5))	{
 	* 		alert(strPhone)
 	* 		document.regpage.phone_ext.focus();
 	* 		check_flag = false;
 	* 	}
 	* }
 	*/

	//Srinayan for gre free
	if (isObject(document.regpage.free_gre_Gender) && check_flag)
 	   {
 	   var fgg;
 	   fgg=document.regpage.free_gre_Gender.options[document.regpage.free_gre_Gender.selectedIndex].value;
 	    if ((fgg == "X"||fgg=="") && check_flag )	
 	    {
 		    alert("Please choose a gender")
 		    document.regpage.free_gre_Gender.focus();
 		    check_flag = false;
 	   }	    
 	}
 	
 	if (isObject(document.regpage.free_gmat_Gender) && check_flag)
 	   {
 	   var fgg;
 	   fgg=document.regpage.free_gmat_Gender.options[document.regpage.free_gmat_Gender.selectedIndex].value;
 	    if ((fgg == "X"||fgg=="") && check_flag )	
 	    {
 		    alert("Please choose a gender")
 		    document.regpage.free_gmat_Gender.focus();
 		    check_flag = false;
 	   }	    
 	}
// ADDED BY AC FOR EGS 050203
//modified by srinayan bundles Jan0204, putting in checks for object existence

 	if (isObject(document.regpage.test_id))
	{
	  if ( document.regpage.test_id.value == "32" && check_flag )	{
 			if ( document.regpage.Gender.selectedIndex == "0"  && check_flag )	{
 				alert(strGender)
 				document.regpage.Gender.focus();
 				check_flag = false;
 			}
 		 }
 	} // end brace for isobject
	
/*	if ( document.regpage.testdate.selectedIndex == "0" && check_flag )	{
 		alert(strTestDate)
 		document.regpage.testdate.focus();
 		check_flag = false;
 	}
*/	
 	if ( trim(document.regpage.Streetaddress1.value) == "" && check_flag )	{
 		alert(strStreet)
 		document.regpage.Streetaddress1.value = '';
 		document.regpage.Streetaddress1.focus();
 		check_flag = false;
 	}
  	if ( trim(document.regpage.City.value) == "" && check_flag )	{
 		alert(strCity)
 		document.regpage.City.value = '';
 		document.regpage.City.focus();
 		check_flag = false;
 	}
 	
 	if (check_flag && document.regpage.Country.selectedIndex == "0")	{
 		alert(strCountry)
 		document.regpage.Country.focus();
 		check_flag = false;
 	}

	//---

 	if ( ( document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "US" || document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "CA" ) && check_flag )
	{ 
 		if ( document.regpage.State.selectedIndex == "0" && check_flag )	
 			{
 				alert(strState)
 				document.regpage.State.focus();
 				check_flag = false;
 			}
 	}
 		 	
 	if ( document.regpage.Country.selectedIndex == "0" && check_flag )	
 	{
 		alert(strCountry)
 		document.regpage.Country.focus();
 		check_flag = false;
 	}

	if ( ( document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "US") && check_flag )
	{  	 	
 		if ( document.regpage.Zipcode.value == "" && check_flag )	{
 			alert(strZipcode)
 			document.regpage.Zipcode.focus();
 			check_flag = false;
 		}
 		 	 	
 		if ( document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "US" )
 		{
 			if ( ZipcodeLen.length != 5 && check_flag )	{
 				alert(strZipcodeLen)
 				document.regpage.Zipcode.value = "";
 				document.regpage.Zipcode.focus();
 				check_flag = false; 		 		
 			}
 		}
 	}
	
	if ( (document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "CA" ) && check_flag )
	{  	 	
 		if ( document.regpage.Zipcode.value == "" && check_flag )	{
 			alert(strPostalcode)
 			document.regpage.Zipcode.focus();
 			check_flag = false;
 		}
 	}

	//---

 	var selected_country = document.regpage.Country.selectedIndex;	 	 	
 	var selected_State = document.regpage.State.selectedIndex;
 	var selected_Territory = document.regpage.State.selectedIndex;
 	
 	if (document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "PR" || 
        document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "AS" ||	
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "FM" ||
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "GU" ||
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "MH" ||
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "MP" ||
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "PW" ||
 		document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "VI")
 	{
		if (check_flag && !checkTerritoryUS(document.regpage.State.options[document.regpage.State.selectedIndex].value)) {
 			alert("The territory you have selected does not match the selected country.")
 			document.regpage.State.focus();
 			check_flag = false;
 		}

 	} 	
 		 	 	
 	if (document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "US")
 	{
		if (check_flag && !checkStateUS(document.regpage.State.options[document.regpage.State.selectedIndex].value)) {
 			alert(nonvalidUSstate)
 			document.regpage.State.focus();
 			check_flag = false;
 		}
		if (check_flag && !verifyDigit(document.regpage.Zipcode.value, 5)) {
 			alert(strValidZipcode)
 			document.regpage.Zipcode.focus();
 			check_flag = false;
 		}
 	}
 	if ( document.regpage.Country.options[document.regpage.Country.selectedIndex].value == "CA" )
 	{
		if (check_flag && !checkStateCA(document.regpage.State.options[document.regpage.State.selectedIndex].value)) {
 			alert(nonvalidCAstate)
 			document.regpage.State.focus();
 			check_flag = false;
 		}
		if (check_flag && !isValidPostalcode(document.regpage.Zipcode.value)) {
 			alert(strValidPostalcode)
 			document.regpage.Zipcode.focus();
 			check_flag = false;
 		}
 	}

	if (check_flag && document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "CA" && 
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "US" && 
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "PR" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "AS" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "FM" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "GU" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "MH" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "MP" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "PW" &&
	    document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "VI") {
		if (selected_State > 1) {
 			alert(nonvalidCountry)
 			document.regpage.Country.focus();
 			check_flag = false;			
		}
	}
	
	if (check_flag && document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "CA" && document.regpage.Country.options[document.regpage.Country.selectedIndex].value != "US") {
		document.regpage.Zipcode.value = ""
	}

 	if ( removeSpaces(document.regpage.Username.value) == "" && check_flag )	{
 		alert(strUserName)
 		document.regpage.Username.focus();
 		check_flag = false;
 	}
 	if ( usernameLen.length < 4 && check_flag )	{
 		alert(strUserNameLength)
 		document.regpage.Username.focus();
 		check_flag = false; 	
 	}

 	if ( removeSpaces(document.regpage.userPassword.value) == "" && check_flag )	{
 		alert(strPassword)
 		document.regpage.userPassword.focus();
 		check_flag = false;
 	}

 	if ( passwordLen.length < 4 && check_flag )	{
 		alert(strPasswordLength)
 		document.regpage.userPassword.focus();
 		check_flag = false; 	
 	}

 	if ( document.regpage.Reenterpassword.value == "" && check_flag )	{
 		alert(strReenterPassword)
 		document.regpage.Reenterpassword.focus();
 		check_flag = false;
 	}
 	if ( document.regpage.userPassword.value != document.regpage.Reenterpassword.value && check_flag) {
      alert(strPasswordNoMatch);
      document.regpage.userPassword.focus();
      check_flag = false;;        
    }
 	if ( document.regpage.Challengequestion.selectedIndex == "0" && check_flag )	{
 		alert(strChallengequestion);
 		document.regpage.Challengequestion.focus();
 		check_flag = false;
 	}
 	if ( removeSpaces(document.regpage.Challengeresponse.value) == "" && check_flag )	{
 		alert(strChallengeResponse)
 		document.regpage.Challengeresponse.focus();
 		check_flag = false;
 	}
 	
 	if ((isObject(document.regpage.customRegisterAgreeRulesChkBox)) && check_flag)
 	   {
 	    if ( document.regpage.customRegisterAgreeRulesChkBox.checked == false && check_flag )	{
 		    alert("Please confirm that you agree to the Terms and Conditions of this site.")
 		    document.regpage.customRegisterAgreeRulesChkBox.focus();
 		    check_flag = false;
 	   }	    
 	}
 	
 		
 	
 	for (var i=0; i<document.regpage.elements.length; i++)
 	{
 				
 		name = document.regpage.elements[i].name
 		if (name.indexOf("McGrawHill_Reg_Sharing") > 0 )
 		{
 			if ( document.regpage.elements[i].checked == false && check_flag )	
 			{
 			    alert("Please confirm that you agree to the Terms and Privacy Notice of this site.")
 			    check_flag = false;
 			 }
 			 break;
 		} 
 	}
 	 	
	if (check_flag)
	{
		document.regpage.submit();		
	}	
}
//-->
