//FUNCTION FOR VALIDATION OF REGISTRATION PAGE
var xmlHttp

function checkEmptyRegistrationPage()
{

/*if(document.getElementById('s_no').value!='')
{
	if(!check_studentid())
	{
		return false;
	}
}*/

var emailValidation = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var username=document.getElementById("user_name").value;
	
	if(username=="")
	{
		alert("Please enter the UserName");
		document.getElementById("user_name").focus();	
		return false;
	}
	if(document.getElementById("user_password").value=="")
	{
		alert("Please enter the Password");
		document.getElementById("user_password").focus();	
		return false;
	}
	
	if(document.getElementById("user_password").value.length <6 )
	{
		alert("Please enter the password atleast six character.");
		document.getElementById("user_password").focus();	
		return false;
	}
	
	if(document.getElementById("confpassword").value=="")
	{
		alert ("Please Fill the Confirm Password!!");	
		document.getElementById("confpassword").focus();
		return false;	
	}
	if(document.getElementById("first_name").value=="")
	{
		alert("Please enter the First Name");
		document.getElementById("first_name").focus();
		return false;
	}
	if(document.getElementById("user_password").value != document.getElementById("confpassword").value)	
	{
		alert ("Your Confirm Password is not Matched with Password");
		document.getElementById("confpassword").focus();
		return false;	
	}
	if(document.getElementById("email_id").value=="")
	{
		alert("Please enter the Email");
		document.getElementById("email_id").focus();
		return false;
	}
	if(document.getElementById("email_id").value!="")
	{
		if(!(document.getElementById("email_id").value.match(emailValidation)))
		{
		alert("Please enter Valid Email Id.");
		document.getElementById("email_id").focus();
		return false;
		}
	}
	if(document.getElementById("city").value=="")
	{
		alert("Please enter the city");
		document.getElementById("city").focus();
		return false;
	}
	//alert(document.getElementById("country").value);return false;
	if(document.getElementById("country").value==0)
	{
		alert("Please enter the country");
		document.getElementById("country").focus();
		return false;
	}
	if(document.getElementById('telephone').value=="")
	{
		alert("Please enter the telephone number");
		document.getElementById('telephone').focus();
		return false;
	}
	if(document.getElementById('telephone').value.length >14){
		//document.getElementById('telephone').value=document.getElementById('telephone').value.substring(0,13);
		alert("Invalid Phone Number!")
		document.getElementById('telephone').focus();
		return false;
	}
	if(document.getElementById('cell').value.length>14)
	{
		alert("Invalid Number");
		document.getElementById('cell').focus();
		return false;
	}
}

//FUNCTION FOR  MATCHING OF PASSWORD AND CONFIRM PASSWORD

function passwordmatch(){
if(document.getElementById("user_password").value != document.getElementById("confpassword").value)	
	{
		alert ("Your Confirm Password is not Matched with Password");
		//document.getElementById("confpassword").focus();
		return false;	
	}	
	
}

function check_studentid()
	{
		var s_no	=	document.getElementById('s_no').value;
		xmlHttp = GetXmlHttpObject();
				
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return false;
		}
		var url="ajax_file.php?s_no="+s_no;    
		xmlHttp.onreadystatechange = function(){ 
													if (xmlHttp.readyState == 4)
													{ 
														var ar	=	xmlHttp.responseText;
														if(ar=="found")
															return true;
														else
														{
															alert('Student Number not found !');
															//document.getElementById('s_id').innerHTML=ar;
															document.getElementById('s_no').value="";	
															document.getElementById('s_no').focus();
															return false;
														}
													} 
											  }// end function
		xmlHttp.open("GET",url, true);
		xmlHttp.send(null);
		return false;
	}
	
	
	
	function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}





//funtion to reset the form

function formReset()
{
document.getElementById("registration").reset();
}



/*function valid_phone()
{	//alert ( document.getElementById('telephone').value);
	var phone = document.getElementById('telephone').value;
	
	if(isNaN(phone)){
		alert("Phone number should be numeric!");
		return false;
	}
	/*if(phone.length != 9){
		phone=phone.substring(0,9);
		alert("Phome No should not be more than 10 characters!")
		return ;
	}*/
//}





function checkusername()
	{	
		var user_name	=	document.getElementById('user_name').value;
		xmlHttp = GetXmlHttpObject();
				
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return false;
		}
		var url="usercheck.php?user_name="+user_name; 
		
		xmlHttp.onreadystatechange = function(){ 
													if (xmlHttp.readyState == 4)
													{ 
														var ar	=	xmlHttp.responseText;
														//alert(xmlHttp.responseText);return false;
														if(ar=="notfound")
															return true;
														else
														{
															alert('User name already exist !');
															//document.getElementById('s_id').innerHTML=ar;
															document.getElementById('user_name').value="";	
															//document.getElementById('user_name').focus();
															return false;
														}
													} 
											  }// end function
		xmlHttp.open("GET",url, true);
		xmlHttp.send(null);
		return false;
	}
	
	
	
	function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}










function checkemail()
	{	
		var user_email	=	document.getElementById('email_id').value;
		xmlHttp = GetXmlHttpObject();
				
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return false;
		}
		var url="emailcheck.php?user_email="+user_email; 
		
		xmlHttp.onreadystatechange = function(){ 
													if (xmlHttp.readyState == 4)
													{ 
														var ar	=	xmlHttp.responseText;
														//alert(xmlHttp.responseText);return false;
														if(ar=="notfound")
															return true;
														else
														{
															alert('Your email Id already exist !');
															//document.getElementById('s_id').innerHTML=ar;
															document.getElementById('email_id').value="";	
															//document.getElementById('user_name').focus();
															return false;
														}
													} 
											  }// end function
		xmlHttp.open("GET",url, true);
		xmlHttp.send(null);
		return false;
	}
	
	
	
	function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}




