// JavaScript Document

/*  Script Name - queryvalid.js */
/* Created by :Mrunal Malusare date(‘Y-m-d’)->2009/02/5 */

/* Modified by :<author name> date(‘Y-m-d’)  */
/* Modification details : <Description of modification> */


function queryvalid()
{
//	alert("hi");
	document.getElementById("errorName").innerHTML = "";	
	document.getElementById("errorAdd").innerHTML = "";	
	document.getElementById("errorphn").innerHTML = "";	
	document.getElementById("errormob").innerHTML = "";	
	document.getElementById("errorEid").innerHTML = "";	
	document.getElementById("errorcomm").innerHTML = "";	
	document.getElementById("errorCity").innerHTML = "";	
	document.getElementById("errorState").innerHTML = "";	
		
	
	//email
	var eid=document.getElementById('id_email').value;
	var posa= eid.indexOf('@');	
	var posd= eid.indexOf('.');
	var sp=eid.indexOf(" ");//get position of space in email
	var len=document.getElementById('id_email').value.length; //length of email
	
	var nm=document.getElementById('id_name').value;// name

	var con=document.getElementById('id_phn').value; // contact number
	var scon=con.indexOf(" "); //get position of space in contact number
	
	var mob=document.getElementById('id_mob').value; // mobile
	var smob=mob.indexOf(" "); //get position of space in mobile number		

	var ad;
	
	var std=document.getElementById('id_std').value;// STD
	var sstd=std.indexOf(" ");//get position of space in stc number		
//name
	if(document.getElementById('id_name').value=="")
	{
		document.getElementById('errorName').innerHTML = "<font color='RED'> Please enter name.</font>";	
		//document.query.id_name.focus();
	   return false;
	}else
	if(!( (nm.charCodeAt(0)>=65 && nm.charCodeAt(0)<=90 ) || ( nm.charCodeAt(0)>=97 && nm.charCodeAt(0)<=122 ) ))
	{
		document.getElementById('errorName').innerHTML = "<font color='RED'> Invalid start of name.</font>";	
		//document.query.id_name.focus();
	   return false;
	}
		
//address	
	if((document.getElementById('id_address').value)=="")
	{
		document.getElementById("errorAdd").innerHTML = "<font color='RED'> Please enter Postal Address.</font>";
		//document.query.id_address.focus();
	   return false;
	}else
	ad=document.getElementById('id_address').value;
	if(!( (ad.charCodeAt(0)>=65 && ad.charCodeAt(0)<=90 ) || ( ad.charCodeAt(0)>=97 && ad.charCodeAt(0)<=122 ) ))
	{
		document.getElementById('errorAdd').innerHTML = "<font color='RED'> Invalid start of address.</font>";	
		//document.query.id_address.focus();
	   return false;
	}
		
//state	
	if ( document.query.state.selectedIndex == 0 )
    {
		
        document.getElementById("errorState").innerHTML = "<font color='RED'>Please select State.</font>";
		//document.query.state.focus();
        return false;
    }
	
//city
	if(document.getElementById('id_city').value=="")
	{
		document.getElementById('errorCity').innerHTML = "<font color='RED'> Please enter city.</font>";	
		//document.query.id_city.focus();
	   return false;
	}else
	ad=document.getElementById('id_city').value;
	if(!( (ad.charCodeAt(0)>=65 && ad.charCodeAt(0)<=90 ) || ( ad.charCodeAt(0)>=97 && ad.charCodeAt(0)<=122 ) ))
	{
		document.getElementById('errorCity').innerHTML = "<font color='RED'> Invalid start of city name.</font>";	
		//document.query.id_city.focus();
	   return false;
	}	
	

//phn	
	if( (document.getElementById('id_phn').value!="") || (document.getElementById('id_std').value!="") ) 
	{
		if ((document.getElementById('id_std').value)=="") 
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> Please enter STD code.</font>";
	 
		return false;
		}
		
		if(isNaN(document.getElementById('id_std').value))
		{

	 	document.getElementById("errorphn").innerHTML = "<font color='RED'> Please enter STD in digits</font>";
	   
	   	return false;
		}
		
		if( (std.length > 5) || (std.length < 3) )
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> Please check the length of STD</font>";
	   
	   	return false;
		}
		
		if (sstd>-1)
		{
		document.getElementById("errorphn").innerHTML = "<font color='RED'> invalid STD.</font>";
	   
	   return false;
		}
		
		if ((document.getElementById('id_phn').value)=="") 
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> Please enter contact number.</font>";
	 
		return false;
		}
		
		if(isNaN(document.getElementById('id_phn').value))
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> Please enter digits</font>";
			//document.query.id_phn.focus();	   

	   		return false;
		}
		else
		if(scon>-1)
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> invalid contact.</font>";
			//document.query.id_phn.focus();	   
	   		return false;
		}
		else
		if( ((document.getElementById('id_phn').value).length<6) || ((document.getElementById('id_phn').value).length>10) )
		{
			document.getElementById("errorphn").innerHTML = "<font color='RED'> Please enter valid contact</font>";
			//document.query.id_phn.focus();	   
		   	return false;
		}
	}
	/*else
	{
		document.getElementById('errorphn').innerHTML = "<font color='RED'> Please enter contact number.</font>";	
		document.query.id_phn.focus();
	   	return false;
	}*/
	
//mobile
	if((document.getElementById('id_mob').value)!="")
	{
		if(isNaN(document.getElementById('id_mob').value))
		{
			document.getElementById("errormob").innerHTML = "<font color='RED'> Please enter digits</font>";
			//document.query.mob.focus();	   
		   	return false;
		}
		else
		if (smob>-1)
		{
			document.getElementById("errormob").innerHTML = "<font color='RED'> Invalid contact no.</font>";
			//document.query.id_mob.focus();	   
			return false;
		}
		else
		if ((document.getElementById('id_mob').value).length!=10)
		{
			document.getElementById("errormob").innerHTML = "<font color='RED'> Please enter valid number</font>";
			//document.query.id_mob.focus();	   
		   	return false;
		}
	}
	
	if( (document.getElementById('id_mob').value =="" ) && (document.getElementById('id_phn').value =="") )
	{
		document.getElementById('errormob').innerHTML = "<font color='RED'> Please enter atleast one contact number.</font>";	
		//document.query.id_mob.focus();
	   	return false;
	}
	
//email	
	if((document.getElementById('id_email').value)!="")
	{
	   /*document.getElementById("errorEid").innerHTML = "<font color='RED'> Please enter Email Id</font>";
	   //document.query.id_email.focus();
	   return false;
	}
	
	else
	{*/
		if(posa==-1)
		{
	   		document.getElementById("errorEid").innerHTML = "<font color='RED'> Please enter valid email id</font>";
			//document.query.id_email.focus();	   
	   		return false;
		}
	
		else if(posd==-1)
		{
	   		document.getElementById("errorEid").innerHTML = "<font color='RED'> Please enter valid email id</font>";
			//document.query.id_email.focus();	   
		    return false;
		}
	
		else if(sp>-1)
		{	
			document.getElementById("errorEid").innerHTML = "<font color='RED'>Please enter valid email id</font>";
			//document.query.id_email.focus();	
			return false;
		}
		
		else if((eid.charAt(1)=='@')||(eid.charAt(1)=='.'))
		{
    	   document.getElementById("errorEid").innerHTML = "<font color='RED'>Please enter valid email id</font>";
		   //document.query.id_email.focus();
		   return false;
		}
		
        else if((eid.charAt(len-2)=='@')||(eid.charAt(len-2)=='.'))
    	 {
			document.getElementById("errorEid").innerHTML = "<font color='RED'>Please enter valid email id</font>";
			//document.query.id_email.focus();	
			return false;
		 }        
	}
	
//comment	
	if((document.getElementById('id_comm').value)=="")
	{
		document.getElementById("errorcomm").innerHTML = "<font color='RED'> Please enter comment.</font>";
		//document.query.id_comm.focus();
	   return false;
	}
	
}
