
        //----------start of Ajax PostCode

          var xmlHttp
          var xmlHttpUserName
          var xmlHttpEmail
          function getLocalityFromPostCode(postcode)
          {
                  var countryCode=document.userJoinFrm.user_country.value;               
            
                  xmlHttp=GetXmlHttpObject()
                  if (xmlHttp==null)
                  {
                  alert ("Browser does not support HTTP Request")
                  return
                  }
                  var url="inc/ajax.php"
                  url=url+"?type=getLocStateFromZip&country="+countryCode+"&postCode="+postcode;
                  url=url+"&sid="+Math.random()
                  url=(url)   
                  xmlHttp.onreadystatechange=stateChanged
                  xmlHttp.open("GET",url,true)
                  xmlHttp.send(null)          
          }
          
            
          function stateChanged()
          {

              if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
              {
                  var str=xmlHttp.responseText;
                  countryCode=document.userJoinFrm.user_country.value; 
                  postcode=document.userJoinFrm.user_postcode.value; 
                  if (str.indexOf("wrong")>=0 && checkPostCodeValidity(postcode,countryCode) )
                  {
                     if(countryCode=="AU" && postcode.length<=3)
                     {                     
                     }else
                     {
                        alert ("Sorry, we can not find the postcode in the database, if you confirm that you entered a valid postcode, please manually input the city and state name, otherwise, please enter your postcode again.")
                        document.userJoinFrm.user_locality.value=""; 
                     }
                  }else
                  {  
                      pos=str.indexOf(";");  
                      city=str.substring(0,pos);   
                      document.userJoinFrm.user_locality.value=trim(city);
                      if(countryCode!="UK")
                      {
                            state=str.substring(pos+1);
                            document.userJoinFrm.user_state.value=state; 
                      }
                 }
              }
          }
       //-------end of Ajax PostCode
          
          function chkUsername(userName)
          {                 
                  xmlHttpUserName=GetXmlHttpObject()
                  if (xmlHttpUserName==null)
                  {
                  alert ("Browser does not support HTTP Request")
                  return
                  }
                  var url="inc/ajax.php"
                  url=url+"?type=chkUserNameAvalibility&userName="+userName;
                  url=url+"&sid="+Math.random()
                  url=(url)  
                  xmlHttpUserName.onreadystatechange=stateChangedUserName
                  xmlHttpUserName.open("GET",url,true)
                  xmlHttpUserName.send(null)  
                  
          }
          
          function chkEmail(email)
          {
                  xmlHttpEmail=GetXmlHttpObject()
                  if (xmlHttpEmail==null)
                  {
                  alert ("Browser does not support HTTP Request")
                  return
                  }
                  var url="inc/ajax.php"
                  url=url+"?type=chkEmailAvalibility&email="+email;
                  url=url+"&sid="+Math.random()
                  url=(url)  
                  xmlHttpEmail.onreadystatechange=stateChangedEmail
                  xmlHttpEmail.open("GET",url,true)
                  xmlHttpEmail.send(null)   
          }
           
           function stateChangedEmail()
          { 
              if (xmlHttpEmail.readyState==4 || xmlHttpEmail.readyState=="complete")
              {
                  var str=xmlHttpEmail.responseText;
                  if (str.indexOf("existed")>=0)
                  {                     
                        alert ("Email already existed in our system, you can not use this email again!\nPlease login with your email and password or register with another email!\nThanks");
                        document.getElementById("user_email").value="";
                        document.getElementById("user_email_validate").value="";  
                        document.getElementById("user_email").focus();
                        return false;
                  }
              }
          } 
               
          function stateChangedUserName()
          {  
              if (xmlHttpUserName.readyState==4 || xmlHttpUserName.readyState=="complete")
              {
                  var str=xmlHttpUserName.responseText; 
                  if (str.indexOf("existed")>=0)
                  {                     
                        alert ("Sorry, but the username you selected is already in use, please select another username.");
                        document.getElementById("user_name").value="";
                        document.getElementById("user_name_validate").value=""; 
                        document.getElementById("user_name").focus();
                        return false;
                  }
              }
          }
          
          function setPostCodeKeyUp(str)
          {
               var countryCode=document.userJoinFrm.user_country.value;               
               if(countryCode=="US" || countryCode=="AU")  //because US and AU postcode are continuous, so they can be checked onfly
               {
                   if(countryCode=="US" && str.length>4)   //US has 5 digits
                   {
                        if (checkPostCodeValidity(str,"US")) 
                        {
                            document.getElementById('user_postcode').value = checkPostCodeValidity(str,"US")
                            str= document.getElementById('user_postcode').value
                            getLocalityFromPostCode(str);                       
                        }else
                        {
                            alert ("Postcode has invalid format");
                            document.getElementById('user_postcode').value="";
                            document.getElementById('user_postcode').focus();
                            return false;
                        }                        
                   }
                   
                   if(countryCode=="AU" && str.length>2)      //Au has 3 or 4 digits
                   {
                       if (checkPostCodeValidity(str,"AU")) 
                        {
                            document.getElementById('user_postcode').value = checkPostCodeValidity(str,"AU") 
                            str= document.getElementById('user_postcode').value
                            getLocalityFromPostCode(str);                        
                        }else
                        {
                            alert ("Postcode has invalid format");
                            document.getElementById('user_postcode').value="";
                            document.getElementById('user_postcode').focus();
                            return false;
                        }    
                   }
               }
                 
               if (str.length<3)
               {
                     document.userJoinFrm.user_state.value="";
                     document.userJoinFrm.user_locality.value="";                    
               }           
          }

          function setPostCodeChange(str)
          {
               var countryCode=document.userJoinFrm.user_country.value;               
               if(countryCode=="UK" || countryCode=="CA")  //because UK and CA postcode are seperate by space and it is outer and inner two parts, so deal here by onchange
               {
                   if(countryCode=="UK")   //US has 5 digits
                   {
                        if (checkPostCodeValidity(str,"UK")) 
                        {
                            document.getElementById('user_postcode').value = checkPostCodeValidity(str,"UK")  
                            str= document.getElementById('user_postcode').value
                            getLocalityFromPostCode(str);                       
                        }else
                        {
                            alert ("Postcode has invalid format");
                            document.getElementById('user_postcode').value="";
                            document.getElementById('user_postcode').focus();
                            return false;
                        }                        
                   }
                   
                   if(countryCode=="CA")      //Au has 3 or 4 digits
                   {
                       if (checkPostCodeValidity(str,"CA")) 
                        {
                            document.getElementById('user_postcode').value = checkPostCodeValidity(str,"CA");
                            str= document.getElementById('user_postcode').value
                            getLocalityFromPostCode(str);                         
                        }else
                        {
                            alert ("Postcode has invalid format");
                            document.getElementById('user_postcode').value="";
                            document.getElementById('user_postcode').focus();
                            return false;
                        }    
                   }
               }          
          }
 
        function  selState()
        {
                  if(document.getElementById("user_state").value=="other")
                  {
                     document.userJoinFrm.user_state_other.value="";
                     document.userJoinFrm.user_state_other.disabled=false;
                     document.userJoinFrm.user_state_other.style.display="";
                     document.userJoinFrm.user_state_other.focus();
                     document.getElementById("spanOtherState").style.display="";
                  }else
                  {
                     document.userJoinFrm.user_state_other.value="";
                     document.userJoinFrm.user_state_other.disabled=true;
                     document.userJoinFrm.user_state_other.style.display="none";
                     document.getElementById("spanOtherState").style.display="none";
                  }
        }

        function setCountry()
        {

                document.userJoinFrm.user_postcode.value="";
                document.userJoinFrm.user_locality.value="";
                country=document.getElementById("user_country").value;
                updateStateForDifferentCountry(country,"user_state","user_timezone");   
             
        }

        function chkReg()
        {
                 //to add, using Ajax to judge is email already exist!


                 //here we need to check the validity of the input
                 //1. check the email
                 var email1=document.userJoinFrm.user_email.value;
                 var email2=document.userJoinFrm.user_email_validate.value;
                 if(!isEmailValid(email1) || email1.length==0)
                 {
                     alert ("Please input valid Email Address.");
                     document.userJoinFrm.user_email.value="";
                     document.userJoinFrm.user_email_validate.value="";
                     document.userJoinFrm.user_email.focus();
                     return false;
                 }
                 if(!isEmailValid(email2) || email2.length==0)
                 {
                     alert ("Please input valid Email Address for validation.");
                     document.userJoinFrm.user_email_validate.value="";
                     document.userJoinFrm.user_email_validate.focus();
                     return false;
                 }
                 if(email1!=email2)
                 {
                     alert ("Validate Email is not the save as original email, please input again.");
                     document.userJoinFrm.user_email_validate.value="";
                     document.userJoinFrm.user_email_validate.focus();
                     return false;
                 }

                 var pass1= document.userJoinFrm.user_password.value;
                 var pass2= document.userJoinFrm.user_password_validate.value;
                 if(pass1.length<6)
                 {
                     alert ("Your password is too short, should be at least 6 characters long.");
                     document.userJoinFrm.user_password.value="";
                     document.userJoinFrm.user_password_validate.value="";
                     document.userJoinFrm.user_password.focus();
                     return false;
                 }
                 if(pass1!=pass2)
                 {
                     alert ("Two passwords are not same, please retype your validate password.");
                     document.userJoinFrm.user_password_validate.value="";
                     document.userJoinFrm.user_password_validate.focus();
                     return false;
                 }

                 //check postCode
                 var postcode=document.userJoinFrm.user_postcode.value;
                 if(postcode.length==0)
                 {
                    alert("Please input your postcode.");
                    document.userJoinFrm.user_postcode.value="";
                    document.userJoinFrm.user_postcode.focus();
                    return false;
                 } 
             

                 //check locality,city name
                 //locality is mandatory, must fill
                  var locality=document.userJoinFrm.user_locality.value;
                  if(locality.length==0)
                  {
                     alert ("Please input locality name.");
                     document.userJoinFrm.user_locality.disabled=false;
                     document.userJoinFrm.user_locality.focus();
                     return false;
                  }


                 //now check other state field
                 //1. other coutnries; 2. select other state
                 var state=document.userJoinFrm.user_state.value;
                 var otherstate= document.userJoinFrm.user_state_other.value;
                 var country= document.userJoinFrm.user_country.value;
                 if( (state=="other" && otherstate.length==0))
                 {
                  str="You selected other state option, but you did not enter other state name.\nIf you are sure it is empty, please cancel it to proceed, otherwise, please click OK and return to fill other state name.";
                  if(confirm(str))
                  {
                     document.userJoinFrm.user_state_other.focus();
                     return false;
                  }
                 }

               

                 //check hte username
                 var username=document.userJoinFrm.user_name.value;
                 if(username.length==0 || username.indexOf(" ")>0)
                 {
                  alert ("Please input your desired user name without space in it.");
                  document.userJoinFrm.user_name.focus();
                  return false;
                 }

                 if(username.indexOf(" ")>=0)
                 {
                    alert ("Please remove space in your username.");
                    document.userJoinFrm.user_name.focus();
                    return false;
                 }

                 var username1=document.userJoinFrm.user_name_validate.value;
                 if(username1.length==0)
                 {
                  alert ("Please input validation user name.");
                  document.userJoinFrm.user_name_validate.focus();
                  return false;
                 }

                 if(username!=username1)
                 {
                     alert ("The validated user name is not the same as original user name, please enter again.");
                     document.userJoinFrm.user_name_validate.value="";
                     document.userJoinFrm.user_name_validate.focus();
                     return false;
                 }



                  if(username.indexOf("@")>=0 || username.indexOf("'")>=0 || username.indexOf('"')>=0 )
                 {
                  alert ("Please input your desired user name without symble @ or '");
                  document.userJoinFrm.user_name.value="";
                  document.userJoinFrm.user_name.focus();
                  return false;
                 }

                  //check hte fullname
                 var fullname=document.userJoinFrm.user_fullname.value;
                 if(fullname.length==0)
                 {
                  alert ("Please input your full name or firm name.");
                  document.userJoinFrm.user_fullname.focus();
                  return false;
                 }

                //finally check the check box of contract
                if(!document.userJoinFrm.legal_terms_agree.checked)
                {
                   alert ("Please check the box to indicate that you accept the terms as stated in order to proceed.");
                   document.userJoinFrm.legal_terms_agree.focus();
                   return false;
                }
                
                if((document.userJoinFrm.user_joinnumber_1.value!="" || document.userJoinFrm.user_joinnumber_2.value!="" || document.userJoinFrm.user_joinnumber_3.value!="") 
                    && (document.userJoinFrm.user_joinnumber_1.value=="" || document.userJoinFrm.user_joinnumber_2.value=="" || document.userJoinFrm.user_joinnumber_3.value==""))
                {
                   alert ("Please fill all the boxes for the joining number or keep all boxes empty.");
                   document.userJoinFrm.user_joinnumber_1.focus();
                   return false;
                }

                return true;
        }