var xmlHttp1;
var xmlHttp3;


function check(userid,password,confirmpassword,city,zip,firstname,email,phone,address)
{ 

xmlHttp1=GetXmlHttpObject1();
if (xmlHttp1==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

//alert(businessname);
//alert(bphno);
//alert(addr1);
//alert(addr2);
//alert(country);
//alert(city);
//alert(website);
//alert(zip);


if (userid!=="" && password!=="" && confirmpassword!=="" && city!=="" && zip!=="" && firstname!==""  && email!=="" && phone!=="" && address!=="" && (password==confirmpassword))

{

// check userid exists







xmlHttp3=GetXmlHttpObject3();
if (xmlHttp3==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 




var post_file_check="checkuidexists.asp";
url = "";
url=url+"userid="+userid;
url=url+"&sid3="+Math.random();
xmlHttp3.onreadystatechange=checkuidexists;
xmlHttp3.open("POST",post_file_check,true);
xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp3.setRequestHeader("Content-length", url.length);
xmlHttp3.setRequestHeader("Connection", "close");
xmlHttp3.send(url);





//return false;





}

else
{

var post_file="checkfields.asp";
url = "";
url=url+"userid="+userid;
url=url+"&password="+password;
url=url+"&confirmpassword="+confirmpassword;
url=url+"&city="+city;
url=url+"&zip="+zip;
url=url+"&firstname="+firstname;
url=url+"&email="+email;
url=url+"&phone="+phone;
url=url+"&address="+address;
url=url+"&sid1="+Math.random();
xmlHttp1.onreadystatechange=alertContents;
xmlHttp1.open("POST",post_file,true);
xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp1.setRequestHeader("Content-length", url.length);
xmlHttp1.setRequestHeader("Connection", "close");
xmlHttp1.send(url);

}

}




function alertContents() 
{ 
if (xmlHttp1.readyState==4)
{ 

 if (xmlHttp1.status == 200)
 {
		var sContentType = xmlHttp1.getResponseHeader("Content-Type");
                //alert(sContentType);            

//alert(xmlHttp1.responseText);



var error_userid;
var error_password;
var error_confirm;
var error_doesnotmatch;
var error_city;
var error_zip;
var error_firstname;
var error_email;
var error_phone;
var error_address;
var error_exists;

error_userid="Userid field is empty";
error_password="Password field is empty";
error_confirm="Confirm password field is empty";
error_doesnotmatch="passwords doesnot match";
error_city="City field is empty";
error_zip="Zip field is empty";
error_firstname="Firstname field is empty;"
error_email="Email field is empty";
error_phone="Phone field is empty";
error_address="Address field is empty";
error_exists="Userid already exists";


/*
document.getElementById("userid_error").innerHTML="";
document.getElementById("password_error").innerHTML="";
document.getElementById("doesnotmatch_error").innerHTML="";
document.getElementById("city_error").innerHTML="";
document.getElementById("zip_error").innerHTML="";
document.getElementById("firstname_error").innerHTML="";
document.getElementById("email_error").innerHTML="";
document.getElementById("phone_error").innerHTML="";
document.getElementById("address_error").innerHTML="";

*/




var x;
x=xmlHttp1.responseText;

//alert(x);



			if ( x.indexOf('userid') > 0 )
				
				document.getElementById("userid_error").innerHTML=error_userid;
			else
				document.getElementById("userid_error").innerHTML="";
			
			
			if ( x.indexOf('already') > 0 && (x.indexOf('userid')) < 0)
				
				document.getElementById("userid_error").innerHTML=error_exists;
			else if ( x.indexOf('already') <  0 && (x.indexOf('userid')) < 0) 
				document.getElementById("userid_error").innerHTML="";

				

			
			if ( x.indexOf('password') > 0 )
				document.getElementById("password_error").innerHTML=error_password;

			else
				document.getElementById("password_error").innerHTML="";



			
			if ( x.indexOf('confirm') > 0 )
				document.getElementById("confirmpassword_error").innerHTML=error_confirm;

			else
				document.getElementById("confirmpassword_error").innerHTML="";


			
			if ( x.indexOf('doesnot match') > 0 )
				document.getElementById("doesnotmatch_error").innerHTML=error_doesnotmatch;

			else
				document.getElementById("doesnotmatch_error").innerHTML="";
				


			if ( x.indexOf('city') > 0 )
				document.getElementById("city_error").innerHTML=error_city;

			else
				document.getElementById("city_error").innerHTML="";
			

			if ( x.indexOf('zip') > 0 )
				document.getElementById("zip_error").innerHTML=error_zip;

			else
				document.getElementById("zip_error").innerHTML="";


			if ( x.indexOf('firstname') > 0 )
				document.getElementById("firstname_error").innerHTML=error_firstname;

			else
				document.getElementById("firstname_error").innerHTML="";



			if ( x.indexOf('email') > 0 )
				document.getElementById("email_error").innerHTML=error_email;
			else
				document.getElementById("email_error").innerHTML="";


			if ( x.indexOf('phone') > 0 )
				document.getElementById("phone_error").innerHTML=error_phone;

			else
				document.getElementById("phone_error").innerHTML="";
				

			if ( x.indexOf('address') > 0 )
				document.getElementById("address_error").innerHTML=error_address;
			else
				document.getElementById("address_error").innerHTML="";




		//document.getElementById("errortext").innerHTML=xmlHttp1.responseText;
 }
else
{
alert("error");
}

}


}







function GetXmlHttpObject1()
{
var xmlHttp1=null;
//xmlHttp1 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlHttp1 = new XMLHttpRequest();
         if (xmlHttp1.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlHttp1.overrideMimeType('text/xml');
            xmlHttp1.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlHttp1) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      

return xmlHttp1;
}




var xmlHttp;

function showCountry(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

var url = "getstatelist.asp";
url=url+"?country="+str;
url=url+"&sid2="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
//xmlHttp.setRequestHeader("Connection", "close");
//xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlHttp.setRequestHeader("Content-length", url.length);
//xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(null);




}




function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{
			if (xmlHttp.status == 200)
 			{
                                       
					document.getElementById("statencity").innerHTML=xmlHttp.responseText;
			}
			else	
			{
					alert('There was a problem with the request.');

			}
}

}

function GetXmlHttpObject()
{
var xmlHttp=null;
xmlHttp = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlHttp = new XMLHttpRequest();
         if (xmlHttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlHttp.overrideMimeType('text/xml');
            xmlHttp.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlHttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      

return xmlHttp;
}






var xmlHttp2;

function showcity(str)
{ 
xmlHttp2=GetXmlHttpObject();
if (xmlHttp2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

//alert(str);
var url = "getcitylist.asp";
url=url+"?state="+str;
url=url+"&sid3="+Math.random();
xmlHttp2.onreadystatechange=stateChangedvalue;
xmlHttp2.open("GET",url,true);
//xmlHttp.setRequestHeader("Connection", "close");
//xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlHttp.setRequestHeader("Content-length", url.length);
//xmlHttp.setRequestHeader("Connection", "close");
xmlHttp2.send(null);




}




function stateChangedvalue() 
{ 
if (xmlHttp2.readyState==4)
{
			if (xmlHttp2.status == 200)
 			{
                                       
					document.getElementById("statencity").innerHTML=xmlHttp2.responseText;
			}
			else	
			{
					alert('There was a problem with the request.');

			}
}

}

function checkuidexists() 
{ 



if (xmlHttp3.readyState==4)
{
			if (xmlHttp3.status == 200)
 			{
                                       

				


				var error_userid_exists;
					error_userid_exists="Userid already exists";
				var check_error;
				check_error=xmlHttp3.responseText;
				//alert(check_error);

					if ( check_error.indexOf('already exists') > 0 )
					{
						//alert("ok");
						document.getElementById("userid_error").innerHTML=error_userid_exists;	
						return false;	

					}	
					else
					{	
						//alert("fail")	;
						//return false;
					document.selectlocation.submit();
						
					}



					//document.getElementById("statencity").innerHTML=xmlHttp2.responseText;
			}
			else	
			{
					//alert('There was a problem with the request.');

			}
}

}








function GetXmlHttpObject()
{
var xmlHttp2=null;
xmlHttp2 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlHttp2 = new XMLHttpRequest();
         if (xmlHttp2.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlHttp2.overrideMimeType('text/xml');
            xmlHttp2.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlHttp2) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      

return xmlHttp2;
}

function GetXmlHttpObject3()
{
var xmlHttp3=null;
xmlHttp3 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlHttp3 = new XMLHttpRequest();
         if (xmlHttp3.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlHttp3.overrideMimeType('text/xml');
            xmlHttp3.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlHttp3 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlHttp3) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      

return xmlHttp3;
}



