// JavaScript Document

var arrCountry = new Array();
arrCountry[1]=new Array("Canada","CA",
				"Alberta",
				"British Columbia",
				"Manitoba",
				"New Brunswick",
				"Newfoundland",
				"Northwest Territories",
				"Nova Scotia",
				"Nunavut",
				"Ontario",
				"Prince Edward Island",
				"Quebec",
				"Saskatchewan",
				"Yukon Territory");
					
arrCountry[2]=new Array("United States","US",
				"Alabama",
				"Alaska",
				"Arizona",
				"Arkansas",
				"Armed Forces Asia",
				"Armed Forces Europe",
				"Armed Forces Pacific",
				"California",
				"Colorado",
				"Connecticut",
				"Delaware",
				"District of Columbia",
				"Florida",
				"Georgia",
				"Hawaii",
				"Idaho",
				"Illinois",
				"Indiana",
				"Iowa",
				"Kansas",
				"Kentucky",
				"Louisiana",
				"Maine",
				"Maryland",
				"Massachusetts",
				"Michigan",
				"Minnesota",
				"Mississippi",
				"Missouri",
				"Montana",
				"Nebraska",
				"Nevada",
				"New Hampshire",
				"New Jersey",
				"New Mexico",
				"New York",
				"North Carolina",
				"North Dakota",
				"Ohio",
				"Oklahoma",
				"Oregon",
				"Pennsylvania",
				"Rhode Island",
				"South Carolina",
				"South Dakota",
				"Tennessee",
				"Texas",
				"Utah",
				"Vermont",
				"Virginia",
				"Washington",
				"West Virginia",
				"Wisconsin",
				"Wyoming");

function update_State(regForm)
{
	//Obtain the first dimension position of the currently selected Country
	var i = regForm.country.selectedIndex;
	if (i > 0){
	   //Inititalise the new 'PROVINCE' selection 
	   regForm.province.options.length = arrCountry[i].length-1;
	   //Populate with the correct values associated with the selected Country
	   for (var j=2; j < arrCountry[i].length; j++){
	   		regForm.province.options[j-1].text = arrCountry[i][j];
			regForm.province.options[j-1].value = arrCountry[i][j];
	   }
	}else{
	   // User has reselected the blank 'Country' option
	   regForm.province.options.length = 1;
	   regForm.province.options[0].text = "Select Country";
	   regForm.province.options[0].value = "";
	}
	regForm.province.options[0].selected = true;

}

function validate(){
	var fieldName = new Array("firstName",
	"lastName",
	"email",
	"password",
	"confirmPassword",
	"addressLine1",
	"city",
	"postalCode"
	);

	var fieldMsg = new Array("First Name",
	"Last Name",
	"Email",
	"Password",
	"Confirm Password",
	"Address Line1",
	"City",
	"Postal Code"
	);
	
	for(var i=0; i<fieldName.length; i++){
		var tmp = eval("document.addUser."+fieldName[i]);
		if(tmp.value==""){//checks that field is not left blank 
			alert(fieldMsg[i]+" Cannot be left Blank");
			tmp.focus();
			return false;
		}else if(trim(tmp.value)==""){//checks that field does not contain blank spaces
			alert(fieldMsg[i]+" Cannot contain Spaces");
			tmp.value="";
			tmp.focus();
			return false;
		}
	}

   //check to see that Password is minimum 5 chars
   if(document.addUser.password.value.length < 5 ){
	   alert("The Password should contain atleast 5 characters");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }
   //check to see if Password and Confirm Password Matches
   if(document.addUser.password.value != document.addUser.confirmPassword.value){
	   alert("The Password and Confirm Password Do Not Match");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }
   //check to see that postalCode is minimum 6 chars
   if(document.addUser.postalCode.value.length < 6 ){
	   alert("The Postal Code should contain atleast 6 characters");
	   document.addUser.postalCode.focus();
   	   return false;
   }
   //validates email address
   if(!emailCheck(document.addUser.email.value)){
  	 document.addUser.email.focus();
  	 return false;
   }
   //validates country
   if(document.addUser.country.value == "none"){
   	 alert("Select Country to Continue");
	 document.addUser.country.focus();
   	 return false;
   }
   //validates province
   if(document.addUser.province.value == ""){
   	 alert("Select Province to Continue");
	 document.addUser.province.focus();
   	 return false;
   }
   
   return true;
}

function validate_ebill(){

	var tmp1 = eval("document.addUser.identificationtype1");
	var tmp = eval("document.addUser.newemail");
	var tmp2 = eval("document.addUser.confirmemail");
	if(tmp1.checked)
	{
		if(tmp.value=="")
		{
			alert("New Email cannot be left Blank");
			tmp.focus();
			return false;
		}
		else if(tmp2.value=="")
		{
			alert("Confirm Email cannot be left Blank");
			tmp2.focus();
			return false;
		}
		
		//validates email address
		if(!emailCheck(document.addUser.newemail.value)){
			document.addUser.newemail.focus();
			return false;
		}
		else if(!emailCheck(document.addUser.confirmemail.value)){
			document.addUser.confirmemail.focus();
			return false;
		}
		
		//check to see if email and Confirm email Matches
		if(document.addUser.newemail.value != document.addUser.confirmemail.value)
		{
			alert("The New Email and Confirm Email do Not Match");
			document.addUser.newemail.focus();
			return false;
		}
	}
	return true;
}

function validate_reg(){
	var fieldName = new Array("firstName",
	"acc",
	"tel",
	"tel1",
	"tel2",
	"postalCode",
	"postalCode1"
	);

	var fieldMsg = new Array("Name",
	"Account Number",
	"Telephone",
	"Telephone",
	"Telephone",
	"postalCode",
	"postalCode"
	);
	
	for(var i=0; i<fieldName.length; i++){
		var tmp = eval("document.addUser."+fieldName[i]);
		if(tmp.value==""){//checks that field is not left blank 
			alert(fieldMsg[i]+" Cannot be left Blank");
			tmp.focus();
			return false;
		}else if(trim(tmp.value)==""){//checks that field does not contain blank spaces
			alert(fieldMsg[i]+" Cannot contain Spaces");
			tmp.value="";
			tmp.focus();
			return false;
		}
	}

   //check to see that Password is minimum 5 chars
   if(document.addUser.password.value.length < 5 ){
	   alert("The Password should contain atleast 5 characters");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }
   //check to see if Password and Confirm Password Matches
   if(document.addUser.password.value != document.addUser.confirmPassword.value){
	   alert("The Password and Confirm Password Do Not Match");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }
   //check to see that postalCode is minimum 7 chars
   if(document.addUser.postalCode.value.length < 3){
	   alert("The Postal Code should contain 6 characters");
	   document.addUser.postalCode.focus();
   	   return false;
   }

   //check to see that postalCode is minimum 7 chars
   if(document.addUser.postalCode1.value.length < 3 ){
	   alert("The Postal Code should contain 6 characters");
	   document.addUser.postalCode1.focus();
   	   return false;
   }

  //check to see if Account number is a valid number
   if(document.addUser.acc.value.length < 6 || isNaN(document.addUser.acc.value) || document.addUser.acc.value.length > 6){
	alert("Account Number should be a valid Number \n ie  6 Digit Number");
	document.addUser.acc.focus();
	return false;
   }

  //check to see if Telephone number is a valid number
   if(document.addUser.tel.value.length < 3 || isNaN(document.addUser.tel.value) || document.addUser.tel.value.length > 3){
	alert("Telephone should be a valid 10 Digit Number");
	document.addUser.tel.focus();
	return false;
   }

   //check to see if Telephone number is a valid number
  if(document.addUser.tel1.value.length < 3 || isNaN(document.addUser.tel1.value) || document.addUser.tel1.value.length > 3){
	alert("Telephone should be a valid 10 Digit Number");
	document.addUser.tel1.focus();
	return false;
   }

   //check to see if Telephone number is a valid number
   if(document.addUser.tel2.value.length < 4 || isNaN(document.addUser.tel2.value) || document.addUser.tel2.value.length > 4){
	alert("Telephone should be a valid 10 Digit Number");
	document.addUser.tel2.focus();
	return false;
   }

   return true;
}


function validate_pwd(){
	var fieldName = new Array("prevpassword",
	"password",
	"confirmPassword"
	);

	var fieldMsg = new Array("Old Password",
	"Password",
	"Confirm Password"
	);
	
	for(var i=0; i<fieldName.length; i++){
		var tmp = eval("document.addUser."+fieldName[i]);
		if(tmp.value==""){//checks that field is not left blank 
			alert(fieldMsg[i]+" Cannot be left Blank");
			tmp.focus();
			return false;
		}else if(trim(tmp.value)==""){//checks that field does not contain blank spaces
			alert(fieldMsg[i]+" Cannot contain Spaces");
			tmp.value="";
			tmp.focus();
			return false;
		}
	}

    //check to see that Password is minimum 5 chars
   if(document.addUser.prevpassword.value.length < 5 ){
	   alert("The Old Password should contain atleast 5 characters");
	   document.addUser.prevpassword.value="";
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }

   //check to see that Password is minimum 5 chars
   if(document.addUser.password.value.length < 5 ){
	   alert("The Password should contain atleast 5 characters");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }
   //check to see if Password and Confirm Password Matches
   if(document.addUser.password.value != document.addUser.confirmPassword.value){
	   alert("The Password and Confirm Password Do Not Match");
	   document.addUser.password.value="";
	   document.addUser.confirmPassword.value="";
	   document.addUser.password.focus();
   	   return false;
   }   
   return true;
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
