function ajaxSigupValidate(emailID)
{	
var xmlHttp;
	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.onreadystatechange=function()
  	{
  		if(xmlHttp.readyState==4)
		{		
			if(xmlHttp.responseText==1)
			{
			 document.getElementById('error_text').innerHTML="Email Id already exist";
			}	
			else
			{
			var frm=document.signup_email_form;
			 frm.submit();
			}		
		}
		else
		{	
		
			//document.getElementById("ajaxMsg").innerHTML = "Loading...";
  		}
	}

	var passData='emailid='+emailID;
	
	xmlHttp.open("POST", "login/check_email_exist", true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(passData);
}
function trimAll(sString) 
	{
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
	}
	
//First Name - display and clear message on text box
function clear_txt_first_name()
{
		var frm=document.signup_email_form;	
		if(trimAll(frm.first_name.value)=="First Name")
		frm.first_name.value="";
		frm.first_name.focus();
}

function check_txt_first_name()
{
	
	    var frm=document.signup_email_form;
		
		if(trimAll(frm.first_name.value)=="")
		frm.first_name.value="First Name";
		
}

//Last Name 
function clear_txt_last_name()
{
		var frm=document.signup_email_form;	
		if(trimAll(frm.last_name.value)=="Last Name")
		frm.last_name.value="";
		frm.last_name.focus();
}

function check_txt_last_name()
{
	
	    var frm=document.signup_email_form;
		
		if(trimAll(frm.last_name.value)=="")
		frm.last_name.value="Last Name";
		
}

//E-mail - display and clear message on text box
function clear_txt_email()
{
		var frm=document.signup_email_form;
		if(trimAll(frm.user_email.value)=="Email Address")
		frm.user_email.value="";
		frm.user_email.focus();
}

function check_txt_email()
{
		var frm=document.signup_email_form;
		if(trimAll(frm.user_email.value)=="")
		frm.user_email.value="Email Address";
}



function signup_validate()
{
	var frm=document.signup_email_form;
	var err=0;
	var empty=0;
	if(trimAll(frm.first_name.value) == "" || trimAll(frm.first_name.value) == "First Name")
	{
		var error_fname="Please enter First Name.";
		empty++;
	}
	else if(!(/^[a-zA-Z]+[a-zA-Z\'\-\,\. ]*$/.test(trimAll(frm.first_name.value))))
	{
		var error_fname="The First Name allow only text and - . , ' symbols.";
		err++;
	}
	
	if(trimAll(frm.last_name.value) == "" || trimAll(frm.last_name.value) == "Last Name")
	{
		var error_lname="Please enter Last Name.";
		empty++;
	}
	else if(!(/^[a-zA-Z]+[a-zA-Z\'\-\,\. ]*$/.test(trimAll(frm.last_name.value))))
	{
		var error_lname="The Last Name allow only text and - . , ' symbols.";
		err++;
	}
	
	
	if(trimAll(frm.user_email.value) == "" || trimAll(frm.user_email.value) == "Email Address")
	{
		var error="Please enter Email Address.";
		empty++;
	}
	else
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.[A-Za-z]{2,3})+$/.test(frm.user_email.value))	//This condition will true if the e-mail id is valid	
		{
		//ok;
		}
		else
		{
		var error="Invalid Email Address.";
		err++;
		
		}
	}	

	if(err!=0 || empty<3)
	{
	if(error_fname)
	{
		document.getElementById('error_fname').innerHTML=error_fname;
		if(error_lname)
		{
			document.getElementById('error_lname').innerHTML=error_lname;
		}
		
		if(error)
		{
		document.getElementById('error_text').innerHTML=error;
		}
	}
	else if(error_lname)
	{
		
		document.getElementById('error_lname').innerHTML=error_lname;
		if(error_fname)
		{
			document.getElementById('error_fname').innerHTML=error_fname;
		}
		
		if(error)
		{
		document.getElementById('error_text').innerHTML=error;
		}
	}
	else if(error)
	{
		document.getElementById('error_fname').innerHTML='';
		document.getElementById('error_lname').innerHTML='';
		document.getElementById('error_text').innerHTML=error;
	}
	else
	{
		var email=frm.user_email.value;
		ajaxSigupValidate(email);
	}
	}
	else
	{
		if(empty==0)
		{
			var email=frm.user_email.value;
		    ajaxSigupValidate(email);
		}
		else 
		{
			window.location = "signup-type";
		}
	}
}

//for sign up 30 seconds change text value
function change_text_value(object)
{
	
	if(object.id == 'first_name')
	{
		
		if(object.value == "FIRST NAME")
		{
			object.value	= "";
		}
		else if(object.value == "")
		{
			object.value	= "FIRST NAME";
		}
		
		
			
	}
	if(object.id == 'last_name')
	{
		if(object.value == "")
		{
			object.value	= "LAST NAME";
		}
		else if(object.value == "LAST NAME")
		{
			object.value	= "";
		}
			
	}
	
	if(object.id == 'user_email')
	{
		if(object.value == "")
		{
			object.value	= "EMAIL";
		}
		else if(object.value == "EMAIL")
		{
			object.value	= "";
		}
			
	}
}

function executor_signup()
{
	
	var frm			= document.signup_email_form;
	
	no_error 		= true;
	error			= "";

	if(trimAll(frm.email.value) == "" || trimAll(frm.email.value) == "EMAIL")
	{
		var error	= "Please enter Email id.";
		no_error 	= false
	}
	else
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.[A-Za-z]{2,3})+$/.test(frm.email.value))	//This condition will true if the e-mail id is valid	
		{
		//ok;
		}
		else
		{
		var error="Invalid Email id.";
		no_error = false
		
		}
	}
	password_msg		= "";
	password_error 		= false;
	if(frm.password.value.length < 7 || frm.password.value.length >20 )
	{
		password_msg	= "The Password must contain at least 7-20 characters."
		password_error 	= false;
	}
	$cond				= 0;
	
	if(/^.*(?=.*\d).*$/.test(frm.password.value))
	{
		$cond++;
	}
	if(/^.*(?=.*[a-z]).*$/.test(frm.password.value))
	{
		$cond++;
	}
	if(/^.*(?=.*[A-Z]).*$/.test(frm.password.value))
	{
		$cond++;
	}
	if( /^.*(?=.*[~!@#$%^&*]).*$/.test(frm.password.value))
	{
		$cond++;
	}
	if($cond>=3)
	{
		if(/^.*(?=.{7,10}).*$/.test(frm.password.value))
		{
			password_error 	= true;
		}
		else
			password_error 	= false;
	}
	else
		password_error 	= false;
	
	if(password_error==false && password_msg =="")
		password_msg	= "The Password must contain at least one lowercase letter, one capital letter, one special character and one number."

		
	document.getElementById('error_text').innerHTML=error;
	document.getElementById('error_password').innerHTML=password_msg;
	if(no_error == true && password_error== true)
	ajaxSigupValidate(frm.email.value);
}


