// JavaScript Document
function formValidate()
{
	
	var divMessage = document.getElementById("txtMess").innerHTML;
	//var divEmailMess = document.getElementById("txtEmail").innerHTML;
	
	if(document.frmReg.memberid.value == "")
	{
		
		document.getElementById("firstRow").style.backgroundColor = "yellow";
		document.frmReg.memberid.focus();
		return false;
	}
	// > 5 means any error message showed and <= 5 means no error/message
	else if(divMessage.length > 5){
		document.getElementById("firstRow").style.backgroundColor = "yellow";
		document.frmReg.memberid.focus();
		return false;
	}


	if(document.frmReg.password.value=="")
	{
		
		document.getElementById("secondRow").style.backgroundColor = "yellow";
		document.frmReg.password.focus();
		return false;
	}
	else{
		document.getElementById("secondRow").style.backgroundColor = "white";
	}


	if(document.frmReg.re_password.value==""){
		document.getElementById("secondRow").style.backgroundColor = "yellow";
		document.frmReg.re_password.focus();
		return false;
	}else{
		document.getElementById("secondRow").style.backgroundColor = "white";
	}

	if(document.frmReg.password.value != document.frmReg.re_password.value){
		
		document.getElementById("secondRow").style.backgroundColor = "yellow";
		document.frmReg.password.value = '';
		document.frmReg.password.focus();
		document.frmReg.re_password.value = '';
		
		//document.getElementById("txtPasswd").innerHTML = "Both password must be same.";
		//alert("Both password must be same.");
		
		return false;
	}
	else{
		document.getElementById("firstRow").style.backgroundColor = "white";
		//document.getElementById("txtPasswd").innerHTML = "";
	}
	
	if(document.frmReg.fullname.value == ""){	
		document.getElementById("thirdRow").style.backgroundColor = "yellow";
		document.frmReg.fullname.focus();
		return false;
	}
	else{
		document.getElementById("thirdRow").style.backgroundColor = "white";
	}

	if(document.frmReg.day.value=="")
	{
		document.getElementById("thirdRow").style.backgroundColor = "yellow";
		document.frmReg.day.focus();
		return false;
	}

	if(document.frmReg.month.value=="")
	{
		document.getElementById("thirdRow").style.backgroundColor = "yellow";
		document.frmReg.month.focus();
		return false;
	}

	if(document.frmReg.year.value=="")
	{
		document.getElementById("thirdRow").style.backgroundColor = "yellow";
		document.frmReg.year.focus();
		return false;
	}

	if(document.frmReg.email.value=="")
	{
		document.getElementById("fourthRow").style.backgroundColor = "yellow";
		document.frmReg.email.focus();
		return false;
	}
	else{
		document.getElementById("fourthRow").style.backgroundColor = "white";
	}

	if(document.frmReg.re_email.value==""){
		
		document.getElementById("fourthRow").style.backgroundColor = "yellow";
		document.frmReg.re_email.focus();
		return false;
	}
	else{
		document.getElementById("fourthRow").style.backgroundColor = "white";
	}
	
	if(document.frmReg.profession.value=="")
	{
		document.getElementById("fifthRow").style.backgroundColor = "yellow";
		document.frmReg.profession.focus();
		return false;
	}
	else{
		document.getElementById("fifthRow").style.backgroundColor = "white";
	}

	if(document.frmReg.gender.value=="")
	{
		document.getElementById("fifthRow").style.backgroundColor = "yellow";
		document.frmReg.gender.focus();
		return false;
	}

	if(document.frmReg.country.value=="")
	{
		document.getElementById("sixthRow").style.backgroundColor = "yellow";
		document.frmReg.country.focus();
		return false;
	}
	else{
		document.getElementById("sixthRow").style.backgroundColor = "white";
	}

	if(document.frmReg.city.value=="")
	{
		document.getElementById("sixthRow").style.backgroundColor = "yellow";
		document.frmReg.city.focus();
		return false;
	}
	else{
		document.getElementById("sixthRow").style.backgroundColor = "white";
	}


	
	return true;
}

// focus on first text box on load
function focus(){
	document.frmReg.memberid.focus();
}

// Validate username 
function validateUsername(memberid){

	xmlHttp = GetXmlHttpObject();
	
	if(xmlHttp == null) { 
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url = "validateUsername.php";
	url = url+"?memberid="+memberid;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
} 

//validate email id
function validateEmail(emailId){
	
	xmlHttp = GetXmlHttpObject();
	
	if(xmlHttp == null) { 
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "validateEmail.php";
	url = url+"?emailId="+emailId;
		
	xmlHttp.onreadystatechange = stateChangedEmail;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
			
}

// State Changed User Name
function stateChanged() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{ 
		document.getElementById("txtMess").innerHTML = xmlHttp.responseText 
		alert(xmlHttp.responseText);

	}
	else{
		document.getElementById("txtMess").innerHTML = "Loading.....";
	} 
}

// State Changed Email 
function stateChangedEmail() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{ 
		document.getElementById("txtEmail").innerHTML = xmlHttp.responseText 
		

	}
	else{
		document.getElementById("txtEmail").innerHTML = "Loading.....";
	} 

} 


// Checking browser compatabile
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

// State Changed 
function stateChanged() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{ 
		document.getElementById("txtMess").innerHTML = xmlHttp.responseText 

	}
	else{
		document.getElementById("txtMess").innerHTML = "Loading.....";
	} 
}


// State Changed 
function stateChangedEmail() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{ 
		document.getElementById("txtEmail").innerHTML = xmlHttp.responseText 

	}
	else{
		document.getElementById("txtEmail").innerHTML = "Loading.....";
	} 

} 