/* COMPANY NAME : INDICOM SOFTECH PVT. LTD.
   AUTHOR : SUCHETA , SACHIN  AND AMISH.  
            ----------------------------
   CREATED ON :  25 JUNE 2000,
				 modified on 1 June 2001 
				 modified on 2 Nov 2001 
				 
   DESCRIPTION : THIS FUNCTION HELPS FOR VALIDATION OF FIELDS IN HTML DOCUMENTS
                 HENCE USER DOES NOT HAVE TO WRITE VALIDATIONS ALL TIME 
				 JUST FOLLOW SIMPLE RULES GIVEN BELOW
   
   
   SPECIFICATIONS: HERE ANY NAME IN HTML TAG STARTS WITH. 
   1. "req" IT BECOMES CUMPOLSORY FIELD , NO BLANKS ALLOWED.
   2. "creq" IT BECOMES CUMPOLSORY FIELD & ALLOWS ONLY CHARACTERS , NO NUMERIC ALLOWED.
   3. "nreq" IT BECOMES CUMPOLSORY FIELD & ALLOWS ONLY NUMERICS , NO CHARACTERS ALLOWED.
   4. "mail" IF USER ENTERS IT AUTOMATICALLY CHECKS FOR CORRECT FORMAT. 
   5. "onlc" IT IS NOT CUMPOLSORY FIELD , BUT WHEN VALUE ENTERED SHOULD ONLY BE CHARACTER.
   6. "onln" IT IS NOT CUMPOLSORY FIELD , BUT WHEN VALUE ENTERED SHOULD ONLY BE NUMERIC.
   7. "ph_" IT IS NOT A COMPULSORY FIELD, BUT WHEN IF VALUE ENTERED SHOULD BE A VALID PHONE
   
   8. "pro" IT IS NOT COMPULSORY FIELD BUT THE VALUE SHOULD NOT BE LESS THAN 1 KG.
	   AS MINIMUM 1 KG TEA IS COMPULSORY FOR ORDER.//specific for maharashtra tea
    
   NUMBER WHICH ALLOWS 0 TO 9 DIGITS AND CHARACTERS LIKE "-", "," , "(" , ")". 
   
   Note :  While calling the function add the following to your form tag

   <form name="" action="" onsubmit="return validateform(this)">
   
   Copyright 2000. Indicom Softech, INDIA.  All Rights Reserved. No part of this code should be
   changed or copied or distributed publically or used for professional purposes, without written 
   permision from Indicom Softech to do the same.
   */  

function validateform(theform)
{
 	var s=false
	var mes
	var noofelements = theform.elements.length
    var digits="0123456789"   
for (i = 0 ; i < noofelements - 1 ; i++)
{
/*--------------- req for cumpulsory required field may be char or numeric---------- */
    
	if(theform.elements[i].name.substring(0,3)=="req")
	{
		if(theform.elements[i].value == "")
		{
		//mes=theform.elements[i].name
		//s=true
		alert("Blank not allowed , Please enter a valid value for " + theform.elements[i].name.substring(3,20))
		theform.elements[i].focus()
		return false
	    }
	}
/*--------------- cumpulsory and character value----------------------------------------- */	
	
        if(theform.elements[i].name.substring(0,4)=="creq")
	    {
	     if(theform.elements[i].value == "")
	     {
	     // s=true
	    //  mes=mes+theform.elements[i].name
		 alert("Blank not allowed , Please enter a valid Character value for " + theform.elements[i].name.substring(4,20))
		  theform.elements[i].focus()
		  return false
		 }
		 else
		 {
		 var le=theform.elements[i].value.length
	//	 alert(le)
		     for(j=0;j<le;j++)
        	 {
			    if( (theform.elements[i].value.substring(j,j+1)=="0")||
			   	(theform.elements[i].value.substring(j,j+1)=="1")||
				(theform.elements[i].value.substring(j,j+1)=="2")||
				(theform.elements[i].value.substring(j,j+1)=="3")||
				(theform.elements[i].value.substring(j,j+1)=="4")||
				(theform.elements[i].value.substring(j,j+1)=="5")||
				(theform.elements[i].value.substring(j,j+1)=="6")||
				(theform.elements[i].value.substring(j,j+1)=="7")||
			 	(theform.elements[i].value.substring(j,j+1)=="8")||
		  		(theform.elements[i].value.substring(j,j+1)=="9"))
		           	{
					      alert("Please enter only character value for " + theform.elements[i].name.substring(4,20))
			              theform.elements[i].focus()
			              return false
			        } 
		      }//end of for
		 }//end of else
	}// end of creq
				
/*----------------------For fields which are numeric and compulsory.-------------------- */			    

	if(theform.elements[i].name.substring(0,4)=="nreq")
	{
	 if(theform.elements[i].value == "")
		{
		alert("Blank not allowed , Please enter a valid Numeric value for " + theform.elements[i].name.substring(4,20))
		theform.elements[i].focus()
		return false
		}
	 else
		{
	 	if(isNaN(theform.elements[i].value))  {
			   alert("Please enter a Only Numeric value only " + theform.elements[i].name.substring(4,20))
			   theform.elements[i].focus()
			   return false
			}//end of if
		 }//end of else
	  }//end of nreq
	  
/*----------------------------------------------------------------------------*/  
	if(theform.elements[i].name.substring(0,3)=="Pro")
		{
		var flag8=0	
		if(theform.elements[i].value=="")   {  flag8=2  }
		else {
			if(theform.elements[i].value < 1)
     		{
			 alert("You need to Order minimum 1kg")
			 theform.elements[i].focus()
			 theform.elements[i].select()
			 return false
			}//end of if
			}//end of else
		}//end of Pro
	  
/*--------------checking for valid phone numbers and fax numbers -------------*/  
	  
//Following characters are allowed "0123456789-,()".	  
var flag3=0
if(theform.elements[i].name.substring(0,3)=="Ph_"){  
	if(theform.elements[i].value=="")   {  flag3=2  }
else {    
	  var le=theform.elements[i].value.length
           for(j=0;j<le;j++)	 {
			if( (theform.elements[i].value.substring(j,j+1)!="0")&&
				(theform.elements[i].value.substring(j,j+1)!="1")&&
				(theform.elements[i].value.substring(j,j+1)!="2")&&
				(theform.elements[i].value.substring(j,j+1)!="3")&&
				(theform.elements[i].value.substring(j,j+1)!="4")&&
				(theform.elements[i].value.substring(j,j+1)!="5")&&	
				(theform.elements[i].value.substring(j,j+1)!="6")&&
				(theform.elements[i].value.substring(j,j+1)!="7")&&
				(theform.elements[i].value.substring(j,j+1)!="8")&&
				(theform.elements[i].value.substring(j,j+1)!="9")&&
     			(theform.elements[i].value.substring(j,j+1)!=",")&&
     			(theform.elements[i].value.substring(j,j+1)!="-")&&
     			(theform.elements[i].value.substring(j,j+1)!="(")&&
     			(theform.elements[i].value.substring(j,j+1)!=")"))
	           	{
					alert("Please enter a valid Phone number for  "+ theform.elements[i].name.substring(3,20))
			        theform.elements[i].focus()
			        return false
			    } //end of alert
		      }//end of for
		     }//end for else
          }//end of phone
          
/*--------------- Checking for valid Email --------------------------------------------*/		
	if(theform.elements[i].name.substring(0,4)=="mail")  {		
		var astr
		var dstr
		strEmail=theform.elements[i].value.length
		astr=theform.elements[i].value.indexOf("@")
		dstr=theform.elements[i].value.indexOf(".")
		
		var flag9=0	
		if(theform.elements[i].value=="")   {  flag9=2  }
		else {
			/*if (strEmail==""){
				alert("Email Address is Compulsory");
				theform.elements[i].focus();
				theform.elements[i].select();
				return false;}*/
			if ( (astr == -1) || (astr==0) || (astr== strEmail-1)){
				alert("Please enter correct Email Address")
				theform.elements[i].focus();
				theform.elements[i].select();
				return false;
				}
			if ( (dstr == -1) || (dstr==0) || (dstr== strEmail-1) )	{
				alert("Please enter correct Email Address")
				theform.elements[i].focus();
				theform.elements[i].select();
				return false;
				}
			if ( (astr == dstr-1) || (astr==dstr+1) ){
				alert("Please enter correct Email Address")
				theform.elements[i].focus();
				theform.elements[i].select();
				return false;
				}
			}//end of else
		}//end of ph_
/*-----------------Not compulsory but Should be Character---------------------------*/
var flag1=0
if(theform.elements[i].name.substring(0,4)=="onlc")
      {
	       if(theform.elements[i].value=="")
           {
		   flag1=2
		   }
 else
	{    
	  var le=theform.elements[i].value.length
	 
           for(j=0;j<le;j++)
        	 {
			    if( (theform.elements[i].value.substring(j,j+1)=="0")||
			   	(theform.elements[i].value.substring(j,j+1)=="1")||
				(theform.elements[i].value.substring(j,j+1)=="2")||
				(theform.elements[i].value.substring(j,j+1)=="3")||
				(theform.elements[i].value.substring(j,j+1)=="4")||
				(theform.elements[i].value.substring(j,j+1)=="5")||
				(theform.elements[i].value.substring(j,j+1)=="6")||
				(theform.elements[i].value.substring(j,j+1)=="7")||
			 	(theform.elements[i].value.substring(j,j+1)=="8")||
		  		(theform.elements[i].value.substring(j,j+1)=="9"))
		           	{
					      alert("Please enter Only Character value for " + theform.elements[i].name.substring(4,20))
			              theform.elements[i].focus()
			              return false
			        } 
		      }//end of for
		
		     }//end for else
          }
/*----------------------------for Numeric and not compulsory fields-------------------*/
var flag1=0
if(theform.elements[i].name.substring(0,4)=="onln")
{	if(theform.elements[i].value=="")
       {  flag1=2   }
	else
	{ if(isNaN(theform.elements[i].value))
		{	alert("Please enter only Numeric value for " + theform.elements[i].name.substring(4,20))
		    theform.elements[i].focus()
		    return false
		}//end of If 
	 }//end for else
 }//end of onln
/*-----------------------------------------------------------------------------------*/
	     
	}//end of for
 return true
}//end of function
