
var typedcity = 0;
//Ajax
function parseZipCodeReturn(req) {
	var xmlDocument = req.responseXML;
	var country = xmlDocument.getElementsByTagName('country').item(0).firstChild.data;
	document.getElementById('lstCountry').value = country;
	
	var state = xmlDocument.getElementsByTagName('state').item(0).firstChild.data;
	document.getElementById('lstState').value = state;
	
	var city = xmlDocument.getElementsByTagName('city').item(0).firstChild.data;
	document.getElementById('txtCity').value = city;
  typedcity = 0;  
	
	
}
function parseZipCode() {
	var zipValue = document.getElementById('txtZipCode').value;
	if(zipValue != '') {
		AjaxRequest.get(
			{
				'url':'/xml/parseZipCode.php',
				'zipcode':escape(zipValue),
				'onSuccess':parseZipCodeReturn
			}
		);
	}
}


//Validation


function validateFormRegisterPage1() {
	if(document.FormRegister.wrntxtHandle && document.FormRegister.wrntxtHandle.value == "") {
		alert("Please enter your Wild Rose Network Username");
		document.FormRegister.wrntxtHandle.focus();
		return(false);
	}
	if(document.FormRegister.wrntxtHandle && document.FormRegister.wrntxtPassword.value == "") {
		alert("Please enter your Wild Rose Network Password");
		document.FormRegister.wrntxtPassword.focus();
		return(false);
	}
	   
   if (document.FormRegister.txtHandle.value == "")
   {
	 alert("Please enter at least 4 characters in the \"Username\" field.");
	 document.FormRegister.txtHandle.focus();
	 return (false);
   }
   if (document.FormRegister.txtHandle.value.length > 16)
   {
	 alert("Please enter no more than 16 characters in the \"Username\" field.");
	 document.FormRegister.txtHandle.focus();
	 return (false);
   }
   if (document.FormRegister.txtHandle.value.length < 4)
   {
	 alert("Please enter at least 4 characters in the \"Username\" field.");
	 document.FormRegister.txtHandle.focus();
	 return (false);
   }
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_";
   var checkStr = document.FormRegister.txtHandle.value;
   var allValid = true;
   for (i = 0;  i < checkStr.length;  i++)
   {
	 ch = checkStr.charAt(i);
	 for (j = 0;  j < checkOK.length;  j++)
	   if (ch == checkOK.charAt(j))
		   break;
	 if (j == checkOK.length)
	 {
	   allValid = false;
	   break;
	 }
   }
   if (!allValid)
   {
	 alert("Please enter only letter, numbers and \"-\" or \"_\"characters in the \"Username\" field.");
	 document.FormRegister.txtHandle.focus();
	 return (false);
   }
   
   if (document.FormRegister.txtPassword.value.length < 6)
   {
     alert("Please enter between 6-10 characters in the \"Password\" field.");
     document.FormRegister.txtPassword.focus();
     return (false);
   }
 
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
   var checkStr = document.FormRegister.txtPassword.value;
   var allValid = true;
   for (i = 0;  i < checkStr.length;  i++)
   {
     ch = checkStr.charAt(i);
     for (j = 0;  j < checkOK.length;  j++)
       if (ch == checkOK.charAt(j))
         break;
     if (j == checkOK.length)
     {
       allValid = false;
       break;
     }
   }
   if (!allValid)
   {
     alert("Please enter only letters and numbers in the \"Password\" field.");
     document.FormRegister.txtPassword.focus();
     return (false);
   }
   
   if (document.FormRegister.txtPassword.value.length > 10)
    {
      alert("Please enter no more than 10 characters in the \"Password\" field.");
      document.FormRegister.txtPassword.focus();
      return (false);
   }
   
   if (document.FormRegister.txtConfirm.value.length < 6)
   {
     alert("Please enter between 6-10 characters in the \"Confirm\" field.");
     document.FormRegister.txtConfirm.focus();
     return (false);
   }
 
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????1234567890";
   var checkStr = document.FormRegister.txtConfirm.value;
   var allValid = true;
   for (i = 0;  i < checkStr.length;  i++)
   {
     ch = checkStr.charAt(i);
     for (j = 0;  j < checkOK.length;  j++)
       if (ch == checkOK.charAt(j))
         break;
     if (j == checkOK.length)
     {
       allValid = false;
       break;
     }
   }
   if (!allValid)
   {
     alert("Please enter only letters and numbers in the \"Confirm\" field.");
     document.FormRegister.txtConfirm.focus();
     return (false);
   }
   
   if (document.FormRegister.txtConfirm.value.length > 10)
    {
      alert("Please enter no more than 10 characters in the \"Confirm\" field.");
      document.FormRegister.txtConfirm.focus();
      return (false);
   }
   if (document.FormRegister.txtPassword.value != document.FormRegister.txtConfirm.value)
    {
      alert("Password confirmation does not match password - please re-enter");
      document.FormRegister.txtPassword.focus();
      return (false);
   }	
  
 
   
  
   
   if (document.FormRegister.txtEmail.value.length < 5)
   {
     alert("Please enter at least 5 characters in the \"Email\" field.");
     document.FormRegister.txtEmail.focus();
     return (false);
   }
 
   if (document.FormRegister.txtEmail.value.indexOf("@") < 0 || document.FormRegister.txtEmail.value.indexOf(".") < 0)
   {
     alert("An invalid \"Email\" address has been supplied please re-enter.");
     document.FormRegister.txtEmail.focus();
     return (false);
   }
   //alert("lstCountry=["+document.FormRegister.lstCountry.value+"]");
   if (document.FormRegister.lstCountry.value == "0") {
       	alert("Please select your Country.");
       	document.FormRegister.lstCountry.focus();
        return (false);
   }   
   if(document.FormRegister.lstCountry.value == '39'|| document.FormRegister.lstCountry.value == '240') {
	   if(document.FormRegister.lstState.value == '0') {
		   alert("Please select a State/Province");
		   document.FormRegister.lstState.focus();
		   return(false);
	   }
	   if(document.FormRegister.txtCity.value == '') {
		   alert("Please enter a city");
		   document.FormRegister.txtCity.focus();
		   return(false);
	   }
	   if(document.FormRegister.txtzipcode.value == "") {
		   alert("Please enter your Zip/Postal Code");
		   document.FormRegister.txtzipcode.focus();
		   return(false);
	   }
   }
  
   if (document.FormRegister.lstUserSexType.value == '0') {
     	alert("Please make a selection for I am/We Are");
     	document.FormRegister.lstUserSexType.focus();
     	return (false);
   }   
    
   
  
   return (true);
 }
 
function validateFormRegisterPage2() {
	//alert("p1_txtname="+document.FormRegister.p1_txtName.value+",p2_txtname="+document.FormRegister.p2_txtName.value+",p2_exists="+document.FormRegister.profile2_exists.value+",and="+(document.FormRegister.profile2_exists.value == '1' && document.FormRegister.p2_txtName.value == ""));
	
	if(document.FormRegister.p1_txtName.value == "" || (document.FormRegister.profile2_exists.value == '1' && document.FormRegister.p2_txtName.value == "")) {
		alert("Please enter your profile name(s)");
		document.FormRegister.p1_txtName.focus();
		return(false);
	}
		
	return(true);
}
	 
function citykey(e) {
	if(typedcity == 0) {
		if (e) keyCode = e.which
		else if (event) keyCode=event.keyCode
		else return
		if(keyCode != 0) {		//some other key
			document.FormRegister.txtCity.value = '';
			typedcity = 1;
		}
	}
}
