function postRequest(strUrl){
var xmlHttp;
var res='';
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.open("POST",strUrl,true);
  xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			  ret=xmlHttp.responseText;
			  res=outputCheck(ret);
  		}
  }
   xmlHttp.send(null);  
   return res;
}

function outputCheck(ret){
	var email 		= document.form_register.email.value;
	var str = email
    var filter=/^.+@.+\..{2,3}$/
	var result;

 	if (filter.test(str)){
    	validformat = true;
	} else {
    	validformat = false;
	}
	
	if(email.length>0){
		if(ret=="true" && validformat==true){
			document.getElementById('emailvalidator').setAttribute('src','images/icon/icon_check1.png');
			document.form_register.uniqueemail.value="true";
			document.form_register.error.value="";
			return "correct";
		}
    	else{
    	error='';
    		if(ret=="false"){
    			document.getElementById('emailvalidator').setAttribute('src','images/btn/btn_delete.png');
    			document.form_register.uniqueemail.value="false";
    	    	error="The email you entered is already used by another person\n";
                document.form_register.error.value=error;
    	    	return "duplicate";
    		}	
    		else if(validformat==false){
				document.getElementById('emailvalidator').setAttribute('src','images/btn/btn_delete.png');
				document.form_register.uniqueemail.value="true";
				error = error+"The data you entered is not a valid email address!\n";
				document.form_register.error.value=error;
				return "wrongformat";
    		}
    		
    	}
	}
	else
		document.getElementById('emailvalidator').setAttribute('src','images/blankcheck.jpg');
}

function validateEmail2(){
	var email 	= document.form_register.email.value;
	url			= 'emailvalidator.php?emailaddress='+trim(email);
	res			= postRequest(url);

	return res;
}

function validateEmailEdit(){
	var email 	= document.form_register.email.value;
	var userid 	= document.form_register.user_id.value;
	url 		= 'emailvalidator.php?emailaddress='+trim(email)+'&userid='+userid;
	res 		= postRequest(url);
}

function validateCountry(){
	
	var country = document.form_register.country;
	var countryFilter = /^[a-zA-Z]+$/;
	if(trim(country.value) != ""){
		if(!countryFilter.test(country.value)){
			alert("Please enter country in English!");
			country.focus();
			return false;
		}
	}	
}

