function checkAvail(id) {
	
	var http_check = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	field	= id;
	val		= (document.getElementById(id)) ? document.getElementById(id).value : "";
	divObj	= (document.getElementById(id+"_div")) ? document.getElementById(id+"_div") : "";
	url		= "checkAvail.php?f="+field+"&v="+val;
	//alert(url);
	if (val)
	{
		http_check.open("GET", url, true);
		http_check.onreadystatechange = function getResponse() {
			
			if(http_check.readyState == 1) {
				divObj.innerHTML = loading();
			}
			if(http_check.readyState == 4) {
				//alert(http_check.responseText);
				if (http_check.responseText == "Y")
				{
					divObj.innerHTML = '<FONT COLOR="red">Already Exists.</FONT>';
				}else{
					divObj.innerHTML = '<FONT COLOR="GREEn">Congratulation!</FONT>';
				}
				//divObj.innerHTML = loading();
				//http_check.responseText;
			}
		}

		http_check.send(null);
	}else{
		alert("Field should not be empty.");
	}
}

function loading(){
	return div = '<IMG SRC="images_site/wait-indicator.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT=""> Please wait...';
}

var defaultemptyok = false;
var whitespace = "\t\n\r";

function isempty(s)
{
   return ((s == null) || (s.length == 0))
}

function iswhitespace (s)
{   var i;

    if (isempty(s)) return true;
    {
      for (i = 0; i < s.length; i++)
       {
       var c = s.charat(i);
       if (whitespace.indexof(c) == -1) return false;
       }
    return true;
    }
}

function validateemail()
{
	 var flag;
	 flag=isemail(document.form.email.value);
	 if(flag==false)
	 {
	 alert("Email Should Be In This Format :  Abc@Xyz.Com")
	 document.form.email.value="";
	 document.form.email.focus;
	 return false;
	 }
}


function isemail(eid)
{
	var i=1;
	var len=eid.length;
	while((i<len) && (eid.charAt(i)!="@"))
	 i++;
	if((i>=len)||(eid.charAt(i)!="@"))
	 return false;
	 else
	 i=i+2;
	while((i<len) && (eid.charAt(i)!="."))
	 i++;
	if((i>=len-1)||(eid.charAt(i)!="."))
	 return false;
	else
	 return true;
}



function checkform(butt_obj)
{
	key= obj = "" ;
	
	if(document.form.fname.value==""){
		key= key + " First Name, ";
		obj = "fname";
	}
	
	if(document.form.lname.value==""){
	 key= key + " Last Name, ";
	 obj = (obj) ? obj : "lname";
	}
	if(document.form.cname.value==""){
	 key= key + "Company Name, ";
	 obj = (obj) ? obj :  "cname";
	}
	if(document.form.email.value==""){
	 key= key + "Email, ";
	 obj = (obj) ? obj :  "email";
	}

	if(isemail(document.form.email.value) == false){
	 key= key + "Invalid Email, ";
	 obj = (obj) ? obj :  "email";
	}

	if(document.form.phone.value==""){
	 key= key + "Phone,";
	obj =  (obj) ? obj : "phone";
	}
	if(document.form.state.value==""){
	 key= key + "State,";
	obj =  (obj) ? obj : "state";
	}
	
	if(document.form.country.value==""){
	 key= key + "Country, ";
		obj =  (obj) ? obj : "country";
	}
	if(document.form.apps_name.value==""){
	 key= key + "Apps Name, ";
		obj =  (obj) ? obj : "apps_name";
	}
	
	if(document.form.username.value==""){
	 key= key + "User Name, ";
	 obj =  (obj) ? obj : "username";
	}

	if(document.form.password.value==""){
		key= key + "Password, ";
		obj =  (obj) ? obj : "password";
	}
	
	
	
	 if(document.form.confpwd.value==""){
	 key= key + "Confirm Password ";
	 obj =  (obj) ? obj : "confpwd";
	 }
	 if (document.form.password.value != document.form.confpwd.value){
		 key= key + "Password and Confirm Password does not match.";
		 obj =  (obj) ? obj : "password";
	 }
	
	if(document.form.scode.value==""){
		 key= key + "Security Code, ";
		 obj =  (obj) ? obj : "scode";
	}

	if(document.form.agree && document.form.agree.checked == false){
		 key= key + "if you are agree, then you can continue this registration.";
		// obj =  (obj) ? obj : "agree";
	}

	if(key!="")
	{
		alert("Cannot Submit!!\n\n"+key+" Cannot Be Left Blank !");
		if (obj){
			getObj = eval("document.form."+obj);
			getObj.focus();
		}
		return false;
	}

	var passVal = document.form.password.value;
	if(checkPunctuationChar(passVal) == false){
		alert("Your password must be between 6 and 10 characters, and contain at least 1 number or \n\n punctuation character ( ! @ # $ % ^ & * + - = / ~ ).");
		return false;
	}
	if (document.getElementById("btn_submit"))
	{
		document.getElementById("btn_submit").disabled = true;
	}
	
}


function wright_url(obj){
	apps_url_obj = document.getElementById("apps_url_div");
	apps_url_obj.innerHTML = obj.value;
}

function checkPunctuationChar(passVal)
{
	if(passVal.length < 5 || passVal.length > 10)
	{
		return false;
	}
	var chr = false;
	var Intchr = false;
	var spChr = false;
	var len = passVal.length;
	for (i=0; i<len; i++ )
	{
		if (punctuation_char.indexOf(passVal.charAt(i)) != -1)
		{
			spChr = true;
			break;
		}
	}

	for (i=0; i<len; i++ )
	{
		if (isNaN(passVal.charAt(i)) && punctuation_char.indexOf(passVal.charAt(i)) == -1)
		{
			chr = true;
			break;
		}
	}

	for (i=0; i<len; i++ )
	{
		if (!isNaN(passVal.charAt(i)) && punctuation_char.indexOf(passVal.charAt(i)) == -1)
		{
			Intchr = true;
			break;
		}
	}
	if (Intchr == false || chr == false || spChr == false)
	{
		return false;
	}
	return true;
}
