// JavaScript Document
var errEmail = "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>Please enter a valid email id. <input type='hidden' name='mailID' id='mailID' value='fail'> </td></tr></table>";
var chkEmail = '<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>Checking for availability. <input type="hidden" name="mailID" id="mailID" value="fail"> </td></tr></table></td></tr></table>';
var errPass ="<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>Please enter a valid password. </td></tr></table>";
var errBEmail = '<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>Please enter a valid email id.<input type="hidden" name="mailID" id="mailID" value="fail"> </td></tr></table>';

var errConfPass = "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>The confirm password and the password do not match.</td></tr></table>";

var errconform = "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>The passwords do not match.</td></tr></table>";

var errtoolong = "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>The passwords do not match.</td></tr></table>";

var errplease = "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>The passwords do not match.</td></tr></table>";

var chkSecImg = '<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>Veifying the security code please wait. <input type="hidden" name="secverify" id="secverify" value="fail"> </td></tr></table></td></tr></table>';

var pass ='<table width="200"  border="0" cellspacing="0" cellpadding="0"><tr><td width="5" class="passFirstBox"></td><td width="190" class="passSBoxCopy">&nbsp;OK</td></tr></table>';
var checkterms= "<table width=200  border=0 cellspacing=0 cellpadding=0><tr><td width=5 class=errFirstBox></td><td width=190 class=errSBox>You need to agree "+portal+" of  Use Agreement.  </td></tr></table></td></tr></table>";


var BussEmail=false;
var Password=false;
var ConfPassword=false;
var JobTitOther=false;
var readyToChkSec=false;
var SECURITY=false;
var TERMS=false;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function submit_form()
	{
if(document.step1.onsubmit())
 {
 var res=validatestep1();
// alert(res);
 if(res==true){
	 document.getElementById("checkpost").value=1;
document.step1.submit();
 }
	 }
}

/* validate the step1 form*/

function validatestep1(){
var passForm=true;					/*   default return value  */
var ok=document.getElementById('mailID').value;
if(ok=="fail"){
		checkBusinessEmail1();		
		passForm=false;	}               /*   for work email validation  */

if(!Password)
	{
		checkPassword();
		passForm=false;	}				/*   for password validation  */


	if(!ConfPassword)
	{
		checkConfPassword();
		passForm=false;	}				/*   for password confirmation validation  */

if(!SECURITY)
			{
			checkSec();		
			passForm=false;		}				/*   for security code validation  */


if(!TERMS)
			{
			checkTerms();
			passForm=false;
			
			}				/*   for terms and conditions check box validation  */
return passForm;
}


/*Check businees email*/

function checkBusinessEmail() 
{
	var Bemail = document.getElementById("bemail").value;
	Bemail=Bemail.toLowerCase();
	document.getElementById("bemail").value=Bemail;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Bemail))
	{
		document.getElementById('BEmailVal').innerHTML = chkEmail;
		//var ok=document.getElementById('mailID').value;
		//alert(ok);
		checkAvail1(Bemail);
		var ok=document.getElementById('mailID').value;
			//alert(ok);
		if(ok=="pass"){
			document.getElementById('BEmailVal').innerHTML = pass;
			BussEmail=true;
		}
		else{
			BussEmail=false;

		}
	}
	else 
	{	
		document.getElementById('BEmailVal').innerHTML = errBEmail;
		BussEmail=false;
	}
}

/*Check Business Avalilability in database*/
function checkAvail1(emailid)
{
	//alert(emailid);
	     var current1 = new Date().getTime();
 if (http.readyState != 4 && http.readyState!=0){ 
		return;
		}
	else{
	http.open("GET","checkid.php?idmail="+escape(emailid)+"&cdt1="+escape(current1),true);

    http.onreadystatechange = handleHttpResponseMail;
    http.send(null);
	}
}

function handleHttpResponseMail() 
{
	if(http.readyState == 4) 
	{
		var results=http.responseText;
			document.getElementById('BEmailVal').innerHTML = results;
	}
}

/*check password*/

function checkPassword()
{
	passok=false;
	
	var passwd = document.getElementById("password").value;
	passwd = passwd.trim();
		
	if(passwd.length > 5)
	{
		passok=true;
	}
	
	var patn = /^[a-zA-Z0-9]+$/; 
	
	if(passok) {
		if(patn.test(passwd)){
			passok=true;
		}
	}
	
	if(passok){
		document.getElementById('passVal').innerHTML = pass;
		var confpasswd = document.getElementById("confirmPassword").value;
		if(confpasswd != "")
		{
			checkConfPassword()
		}
		Password=true;
	}
	else
	{
		document.getElementById('passVal').innerHTML = errPass;
		Password=false;
	}
}

/* check confirmation password*/


function checkConfPassword()
{
	if(Password)
	{

		var passwd = document.getElementById("password").value;
		var confpasswd = document.getElementById("confirmPassword").value;
		confpasswd = confpasswd.trim();
	
			if((confpasswd.length==passwd.length))
			{
				if((confpasswd==passwd))
					{
			document.getElementById('ConpassVal').innerHTML = pass;
			ConfPassword=true;
					}
				
				else {
		document.getElementById('ConpassVal').innerHTML = errConfPass;
		ConfPassword=false;
					}
					return;
			}
		else if(confpasswd.length<passwd.length)
		{
			document.getElementById('ConpassVal').innerHTML = errconform;
			ConfPassword=false;
			return;
		}
		else if(confpasswd.length>passwd.length)
		{
			document.getElementById('ConpassVal').innerHTML = errtoolong;
			ConfPassword=false;
			return;
		}
		
}
	else
	{
	//alert("please enter the password");
	document.getElementById('ConpassVal').innerHTML = errplease;
	ConfPassword=false;

	return;
	}
}

/* Verify Registeration*/
function checkSec() {
		var newsec=document.getElementById("imagePassword").value;
			 if (http.readyState != 4 && http.readyState!=0){ 
		return;
		}
	else{
		http.open("GET","secverify.php?userin="+escape(newsec),true);

		http.onreadystatechange = handleHttpResponseSec;
        http.send(null);		
	}
}

function handleHttpResponseSec() 
{
	if(http.readyState == 4) 
	{
			var results=http.responseText;
var matchPos1 = results.search("OK");
if(matchPos1==-1){
SECURITY=false;
}
else{
SECURITY=true;
}
			document.getElementById('secver').innerHTML = results;
			
		}
	}

/*check the terms*/
function checkTerms()
{
	if(document.step1.terms.checked==false)
	{
			document.getElementById('checkterms').innerHTML = checkterms;
	        TERMS=false;
	}
		if(document.step1.terms.checked==true){
			
			document.getElementById('checkterms').innerHTML = pass;
			TERMS=true;
		}
		return TERMS;
}

/* New Image */

function createimage(){
	//alert("imagar");
     var current = new Date().getTime();
 if (http.readyState != 4 && http.readyState!=0){ 
		return;
		}
	else{
	http.open("GET","verimg.php?cdate="+escape(current),true);

		http.onreadystatechange = handleHttpResponseImage;
        http.send(null);		
	}
}

function handleHttpResponseImage() 
{
	     
	if(http.readyState == 4) 
	{
			var results=http.responseText;
			var current1 = new Date().getTime();
            var newimg='<img src="verimg.php?cdt='+escape(current1)+'" id="vimage" width="60" height="30" align="absmiddle" />&nbsp;&nbsp; <a href="#" class="bluelink" onclick="createimage();">New image</a>';
			document.getElementById('createimage').innerHTML = newimg;
			document.getElementById('secver').innerHTML='<input type="hidden" name="secverify" id="secverify" value="fail"><table width="200"  border="0" cellspacing="0" cellpadding="0"><tr><td width="5" class="errFirstBox"></td><td width="190" class="errSBox">Please enter the security code shown in the image.</td></tr></table>';
			SECURITY=false;
	}
}



function getHTTPObject() 
{
	var xmlhttp;
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (!xmlhttp)
			{
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		}
	return xmlhttp;
}

var http = getHTTPObject();


function checkBusinessEmail1() 
{
	var Bemail = document.getElementById("bemail").value;
	Bemail=Bemail.toLowerCase();
	document.getElementById("bemail").value=Bemail;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Bemail))
	{
	
var ok=document.getElementById('mailID').value;
		if(ok=="pass"){
			document.getElementById('BEmailVal').innerHTML = pass;
			BussEmail=true;
		}
		else{
			BussEmail=false;

		}

	}
	else 
	{	
		document.getElementById('BEmailVal').innerHTML = errBEmail;
		BussEmail=false;
	}
}

function checkanitha(){
var vl="0";
var vl1="1";
//alert("callfun");
document.getElementById("textname").value="1";
}