var SAlertMess = new Array(20);
var SErrmes ;

SAlertMess[0] = "Invalid Date."
SAlertMess[1] = "Invalid Time."
SAlertMess[2] = "Cannot Be Greater Then Current Date."
SAlertMess[3] = "Invalid Number."
SAlertMess[4] = "Cannot Be Zero."
SAlertMess[5] = "Invalid String."
SAlertMess[6] = "Select From The Dropdown."
SAlertMess[7] = "Selection Is mandatory."
SAlertMess[8] = "Age Cannot Be Less Then 18 years."
SAlertMess[9] = "Click On search To Select."
SAlertMess[10] = "Invalid Email Address."
SAlertMess[11] = "Cannot Be Blank."
SAlertMess[12] = "Invalid Zipcode."
SAlertMess[13] = "Invalid Phone Number."
SAlertMess[14] = "Invalid Fax Number."
SAlertMess[15] = "Invalid SSN Number."
SAlertMess[16] = "Invalid  Number."
SAlertMess[17] = "Please Select CheckBox."
SAlertMess[18] = "Invalid Fax Number."


function ReturnErr(IErr)
{
 SErrmes =   SAlertMess[IErr] ; 
 return SErrmes ; 
}


var SAbort ; // used as flag for excuting the functions
SAbort = "TRUE" ;
//***************************************************

function CheckText(objName,sAlertmess)
{
if(SAbort == "FALSE")
{
return (false) ;
}

// this can be altered for any "checkOK" string you desire

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var checkStr = objName.value;

var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess);
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);

}





//****************************************************

function CheckSentence(objName,sAlertmess)
{
if(SAbort == "FALSE")
{
return (false) ;
}

// this can be altered for any "checkOK" string you desire

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz &";
var checkStr = objName.value;

var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess);

objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);

}



//****************************************************



function CheckAlphaNumeric(objName,sAlertmess)
{
if(SAbort == "FALSE")
{
return (false) ;
}

// this can be altered for any "checkOK" string you desire

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
var checkStr = objName.value;

var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess);

objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);

}


//***********************************************

function CheckNumeric(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}


// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789";
var checkStr = objName.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess);

objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}

//***********************************************

function CheckDecimal(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789.,";
var checkStr = objName.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;

if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess);

objName.focus();
SAbort = "FALSE" ;
return (false);
}

var checkStr ;
var validnum ;
validnum = "F"
checkStr = objName.value;
 for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="." && i!=0)
                       {
                        validnum = "T"                                 
                       }   
                 }            
         if(validnum=="F")
         {
               alert(sAlertmess) ;
			   objName.focus();
			   SAbort = "FALSE" ;
			   return (false);             
         } 
         else
         {
         validnum = "F"
         }       
                 
return(true);
}

//************************************************

function CheckPassword(objName1,objName2,passnum,sAlertmess)
{
// require at least passnum characters in the password field
//alert(SAbort) ;
if(SAbort == "FALSE")
{
return (false);
}


if (objName1.value.length < parseInt(passnum) || objName1.value.length == 0)
{
objName1.focus();
SAbort = "FALSE" ;
alert("Please Enter Password");
return (false);
}

// check if both password fields are the same
if (objName1.value != objName2.value)
{
	alert("The two passwords are not the same.");
	objName2.focus();
        SAbort = "FALSE" ;
	return (false);
}
return(true);
}


//**********************************************************


function CheckDropdownbox(objName,sAlertmess) // use alert str so that it can b use forcompany //selectio,gender selection ,etc
{

if(SAbort == "FALSE")
{
return (false);
}

// check if no drop down has been selected
if (objName.selectedIndex == 0)
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false) ;
}
return (true) ;
}


//check for valid Email******************************************************


function CheckEmail(objName,sAlertmess)
 {

if(SAbort == "FALSE")
{
return (false);
}
   Ctrl = objName.value ;
   
  
   if (Ctrl == "" || Ctrl.indexOf ('@', 0) == -1 || Ctrl.indexOf ('.', 0) == -1 || Ctrl.indexOf (',', 0) >= 0 ||  Ctrl.indexOf ('?', 0) >= 0 || Ctrl.indexOf ('#', 0) >= 0 || Ctrl.indexOf ('$', 0) >= 0 || Ctrl.indexOf ('%', 0) >= 0 || Ctrl.indexOf ('^', 0) >= 0 || Ctrl.indexOf ('~', 0) >= 0 || Ctrl.indexOf ('!', 0) >= 0 || Ctrl.indexOf ('`', 0) >= 0 || Ctrl.indexOf ('&', 0) >= 0 || Ctrl.indexOf ('*', 0) >= 0 || Ctrl.indexOf ('(', 0) >= 0 || Ctrl.indexOf (')', 0) >= 0 || Ctrl.indexOf ('<', 0) >= 0 || Ctrl.indexOf ('>', 0) >= 0 || Ctrl.indexOf ('+', 0) >= 0)
    {
   // p = Ctrl.indexOf (',', 0) ;
   //alert(p);
      alert(sAlertmess) ;
      objName.focus();
      SAbort = "FALSE" ;
      return (false);   
   } 
   
      var EmailOk  = true ;
	  var Temp     = objName ;
      var AtSym    = Temp.value.indexOf('@') ;
      var period1  = Temp.value.indexOf('.');
      var Period   = Temp.value.lastIndexOf('.') ;
      var Space    = Temp.value.indexOf(' ') ;
      var Length   = Temp.value.length - 1 ;  // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (period1 < 1) ||
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
    //  EmailOk = false
     alert(sAlertmess) ;
     objName.focus() ;
     SAbort = "FALSE" ;
     return (false);
     a=1;

   }
     
   var bTemp,sTempEmail;
   sTempEmail = objName.value ;
   bTemp = CheckAtRate(sTempEmail)
   
   if(bTemp)
   {
      return (true);
   }
   else{
		alert("Invalid Email Address.");
		objName.focus() ;
		SAbort = "FALSE" ;
		return (false);
		a=1;
   }
} 

function CheckEmail2(objName,sValue,sAlertmess)
 {

if(SAbort == "FALSE")
{
return (false);
}
   Ctrl = sValue ;
   
  
   if (Ctrl == "" || Ctrl.indexOf ('@', 0) == -1 || Ctrl.indexOf ('.', 0) == -1 || Ctrl.indexOf (',', 0) >= 0 ||  Ctrl.indexOf ('?', 0) >= 0 || Ctrl.indexOf ('#', 0) >= 0 || Ctrl.indexOf ('$', 0) >= 0 || Ctrl.indexOf ('%', 0) >= 0 || Ctrl.indexOf ('^', 0) >= 0 || Ctrl.indexOf ('~', 0) >= 0 || Ctrl.indexOf ('!', 0) >= 0 || Ctrl.indexOf ('`', 0) >= 0 || Ctrl.indexOf ('&', 0) >= 0 || Ctrl.indexOf ('*', 0) >= 0 || Ctrl.indexOf ('(', 0) >= 0 || Ctrl.indexOf (')', 0) >= 0 || Ctrl.indexOf ('<', 0) >= 0 || Ctrl.indexOf ('>', 0) >= 0 || Ctrl.indexOf ('+', 0) >= 0)
    {
   // p = Ctrl.indexOf (',', 0) ;
   //alert(p);
      alert(sAlertmess) ;
      objName.focus();
      SAbort = "FALSE" ;
      return (false);   
   } 
   
      var EmailOk  = true ;
	  var Temp     = objName ;
      var AtSym    = Temp.value.indexOf('@') ;
      var period1  = Temp.value.indexOf('.');
      var Period   = Temp.value.lastIndexOf('.') ;
      var Space    = Temp.value.indexOf(' ') ;
      var Length   = Temp.value.length - 1 ;  // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (period1 < 1) ||
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
    //  EmailOk = false
     alert(sAlertmess) ;
     objName.focus() ;
     SAbort = "FALSE" ;
     return (false);
     a=1;

   }
     
   var bTemp,sTempEmail;
   sTempEmail = Ctrl ;
   bTemp = CheckAtRate(sTempEmail)
   
   if(bTemp)
   {
      return (true);
   }
   else{
		alert("Invalid Email Address.");
		objName.focus() ;
		SAbort = "FALSE" ;
		return (false);
		a=1;
   }
} 
function CheckAtRate(sTempEmail){
	var sEmail = new String(sTempEmail);
	var iAtTheRate;
	iAtTheRate = sEmail.indexOf("@");
	sEmail = sEmail.slice(iAtTheRate+1,sEmail.length);
	//alert(sEmail);
	iAtTheRate = sEmail.indexOf("@");
	//alert(iAtTheRate);
	if(iAtTheRate == -1){
		return true;
	}
	else{
		return false;
	}
}
//************************************************************************

function CheckBirthdate(datefield,yeardiff,agelimit,sAlertmess) 
{
// to check whether date is entered or not in the field

if(SAbort == "FALSE")
{
return (false);
}
  

if (datefield.value == "")
{
alert("Enter Value In Date Field");
datefield.focus();
SAbort = "FALSE" ;
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789/";
var checkStr = datefield.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess) ;
datefield.focus();
SAbort = "FALSE" ;
return(false)    ;
}
     

//to check whether its of length 11(mm/dd/yyyy) and /'s are on 2nd  and 5th postion or not
var iPos ;
iPos = 0 ;
  if (checkStr.length != 10) 
       {
alert(sAlertmess) ;
          datefield.focus() ;
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else//to find the positoins of /'s 
       {
         for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="/")
                       {
                         iPos = iPos + i   ;                        
                       }   
                 }            
       }
  //to check valid month day and year
	if(iPos==7) // Sinc 2 and 5 addition
           { 
              strDateArray = checkStr.split("/"); // to extract month,day,year

              
	      strMonth = strDateArray[0] ;
          strDay   = strDateArray[1] ; 
	      strYear  = strDateArray[2] ; 

                    if(strMonth<01 || strMonth>12)              
			{
			 alert(sAlertmess) ;
             datefield.focus() ;
			 SAbort = "FALSE" ;
	         return(false)    ;  
	        }
	        
		    if(strDay<01 || strDay>31)              
			{
			 alert(sAlertmess) ;
			 datefield.focus() ;
			 SAbort = "FALSE" ;
	  		 return(false)    ;
			}
                //to caluclate todays date so that we can validate for 100 yrs back for 		//valication and also it shd not b greater then 2days date..

                   var itoday = new Date(); 
                   var itodayfin = new Date();  
                   var stodayyear ;
                       // itoday = itoday.getYear() - yeardiff ;
                     //to calculate the present year
              
                     stodayyear = itoday.toString() ;
                     itodayyearlen = stodayyear.length - 4 ;
                     itoday1 =   stodayyear.substr(itodayyearlen, 4) ;  //present year        
                     yeardifffin =  parseInt(itoday1) - parseInt(strYear) ;  
		   
			               
                    if(yeardifffin>yeardiff || strYear>itoday1)//to check date is <year passed //diff and not greater then present year
			{
						 alert(sAlertmess) ;
                         datefield.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
                       else
                        {                      
            
                      //check the age whether its greater then 18 or not -----
                        var iAge ;                        
                        iAge =   itoday1  - parseInt(strYear )
                        alertsay = "Age is less Then " + agelimit + " Years";
                        if(iAge<agelimit)              
			{
			  alert(alertsay);
			  datefield.focus() ;
              SAbort = "FALSE" ;
	  		  return(false)    ;
			}

                        } 
           }
         else
           {
	   		 alert(sAlertmess) ;
             datefield.focus();
             SAbort = "FALSE" ;
	  		 return(false)    ;
           } 
return(true);
}


//**********************************************************************

function CheckDate(datefield,sAlertmess) 
{
// to check whether date is entered or not in the field

if(SAbort == "FALSE")
{
return (false);
}
  

if (datefield.value == "")
{
alert("Enter Value In Date Field");
datefield.focus();
SAbort = "FALSE" ;
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789/";
var checkStr = datefield.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess) ;
datefield.focus();
SAbort = "FALSE" ;
return(false)    ;
}
     

//to check whether its of length 11(mm/dd/yyyy) and /'s are on 2nd  and 5th postion or not
var iPos ;
iPos = 0 ;
  if (checkStr.length != 10) 
       {
          alert(sAlertmess) ;
          datefield.focus() ;
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else//to find the positoins of /'s 
       {
         for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="/")
                       {
                         iPos = iPos + i   ;                        
                       }   
                 }            
       }
  //to check valid month day and year
	if(iPos==7) // Sinc 2 and 5 addition
           { 
              strDateArray = checkStr.split("/"); // to extract month,day,year

              
	      strMonth = strDateArray[0] ;
          strDay   = strDateArray[1] ; 
	      strYear  = strDateArray[2] ; 

          if(strMonth<01 || strMonth>12)              
			{
			 alert(sAlertmess) ;
             datefield.focus() ;
			 SAbort = "FALSE" ;
	         return(false)    ;  
	        }
		    if(strDay<01 || strDay>31)              
			{
			 alert(sAlertmess) ;
			 datefield.focus() ;
			 SAbort = "FALSE" ;
	  		 return(false)    ;
			}
                //to caluclate todays date so that we can validate for 100 yrs back for 		//valication and also it shd not b greater then 2days date..
                   var yeardiff ;
                   yeardiff = 100
                   var itoday = new Date(); 
                   var itodayfin = new Date();  
                   var stodayyear ;
                      // itoday = itoday.getYear() - yeardiff ;
                     //to calculate the present year
              
                     stodayyear = itoday.toString() ;
                     itodayyearlen = stodayyear.length - 4 ;
                     itoday1 =   stodayyear.substr(itodayyearlen, 4) ;  //present year        
                     yeardifffin =  itoday1 - strYear ;  
		             
			               
                    if(yeardifffin>yeardiff)//to check date is <year passed
			{
						 alert(sAlertmess) ;
                         datefield.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
                      
           }
         else
           {
	   	   alert(sAlertmess) ;
           datefield.focus();
           SAbort = "FALSE" ;
	  	   return(false)    ;
           } 
           
var iPoszero ; 
iPoszero= 0  ;          
           for (i = 0;  i < checkStr.length;  i++)
                {                 
                  ch = checkStr.charAt(i);
                    if(ch=="0")
                       {
                         iPoszero = iPoszero + 1   ;                        
                         //alert(iPoszero);
                       }                             
                 }            
                  
	   if(iPoszero==8) // Since 3 and 6 addition           
           {
 		     alert(sAlertmess) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	         return(false)    ;
			}
                 
return(true);
}




//*************************************************************************************

//to compare datefield1 shd greater then datefield2
function CompareDates(datefield1,datefield2,sAlertsay) 
{
// to check whether date is entered or not in the field

if(SAbort == "FALSE")
{
return (false);
}            

var sdatefield1 ;
var sdatefield2 ;
var idatefield1len ;
var idatefield2len ;
var idatefield1 ; 
var idatefield2 ; 
var valdatefield1 ; 
var valdatefield2 ; 
valdatefield2 = datefield2.value ;
valdatefield1 = datefield1.value ;

                     sdatefield1 = valdatefield1.toString() ;
                     sdatefield2 = valdatefield2.toString() ;
                     
                     //alert(sdatefield2);
                     
                     idatefield1len = sdatefield1.length - 4 ;
                     idatefield2len = sdatefield2.length - 4 ;
                      
                     // alert(idatefield2len);
                       
                     idatefield1 =   sdatefield1.substr(idatefield1len, 4) ;  //present year 
                     idatefield2 =   sdatefield2.substr(idatefield2len, 4) ;  //present year 
                             
                     //alert(idatefield2);
                     
		            // alert(parseInt(idatefield1)); 
		            // alert(parseInt(idatefield1)); 
			               
                    if(idatefield2<idatefield1)//to check date is <year passed
			{
						 alert(sAlertsay) ;
                         datefield2.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
			
			else
			{
			if(idatefield2==idatefield1)//to check date is <month passed
			{
			var strDate1Array ;
			var strDate2Array ;
			
			var strMonth1 ; 
			var strMonth2 ;
			//alert(valdatefield1)  ;
			 
			strDate1Array = valdatefield1.split("/"); // to extract month,day,year
            strDate2Array = valdatefield2.split("/"); // to extract month,day,year  
              
            // alert(strDate1Array[0])  ;
             
            strMonth1 = strDate1Array[0] ;  
	        strMonth2 = strDate2Array[0] ;
	        
	         if(strMonth2<strMonth1)//to check date is < month passed
			{
						 alert(sAlertsay) ;
                         datefield2.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
			else
			{	
			if(strMonth2==strMonth1)//to check date is < month passed
			{	
			strDay1   = strDate1Array[1] ;  
	        strDay2   = strDate2Array[1] ;	        
	         if(strDay2<strDay1)//to check date is < day passed
			{
						 alert(sAlertsay) ;
                         datefield2.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
			}
			}	
			}//end of outer end if for month
			
            }//end of outer end if for year          
          
return(true);
}
//*******************************************************************
function CheckListbox(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}

// check if less than 1 options are selected
var numSelected = 0;
var i;
for (i = 0;  i < objName.length;  i++)
{
if (objName.options[i].selected)
numSelected++;
}

if (numSelected < 1)
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}

//**************************************************************
function CheckBlank(objName,sAlertmess)
{
//alert(SAbort);
if(SAbort == "FALSE")
{
return (false);
}

// require a value be entered in the field
if (objName.value == "")
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}

// require a value be entered in the field
if (objName.value == "")
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
var checkStr ;
checkStr = objName.value;
 for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch==" " && i==0)
                       {
                         alert("First Character Cannot Be Blank.") ;
						 objName.focus();
		    		     SAbort = "FALSE" ;
						 return (false);                      
                       }   
                 }            
       

return(true);
}

//*********************************************************
function CheckPhone(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert("Please Enter Value In Field");
objName.focus();
SAbort = "FALSE" ;
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789-";
var checkStr = objName.value;
var allValid = true;
var iPoszero ; 
iPoszero= 0 ;  

for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
else//check for valid phone number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 12) 
       {
          alert(sAlertmess) ;
          objName.focus() ;
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else//to find the positoins of -'s 
       {
         for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="-")
                       {
                         iPos = iPos + i   ;                        
                       }   
                       
                    if(ch=="0")
                       {
                         iPoszero = iPoszero + 1   ;                        
                         //alert(iPoszero);
                       }      
                 }      
                 
                   
                   
       }
		if(iPos!=10 || iPoszero==10) // Since 3 and 7 addition           
          {
 		     alert(sAlertmess) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	          return(false)    ;
			}  
	
           
}
return(true);
}

//*********************************************************
function CheckFax(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert("Please Enter Value In Field");
objName.focus();
SAbort = "FALSE" ;
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789-";
var checkStr = objName.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
else//check for valid phone number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 12) 
       {
          alert(sAlertmess) ;
          objName.focus() ;
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else//to find the positoins of -'s 
       {
         for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="-")
                       {
                         iPos = iPos + i   ;                        
                       }   
                 }            
       }
 
	if(iPos!=10) // Since 3 and 7 addition           
          {
 		      alert(sAlertmess) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	          return(false)    ;

			}
}
return(true);
}

//*********************************************************

function CheckSsn(objName,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}

// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = "0123456789-";
var checkStr = objName.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(sAlertmess) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
else//check for valid Ssn number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
var sCheckzero ;
var iPoszero ;
iPoszero = 0 ;

  if (checkStr.length != 11) 
       {
          alert(sAlertmess) ;
          objName.focus() ;
          SAbort = "FALSE" ;
		  return(false)    ;
       }      
     else//to find the positoins of -'s 
       {
         for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="-")
                       {
                         iPos = iPos + i   ;                        
                        // alert(iPos);
                       }   
                  ch = checkStr.charAt(i);
                    if(ch=="0")
                       {
                         iPoszero = iPoszero + 1   ;                        
                         //alert(iPoszero);
                       }                             
                 }            
       }
     //alert(iPos);
    
    sCheckzero =   checkStr.substr(4,2) ;  //to check middle 2 digits cannot b zero
    //alert(sCheckzero);
    
	if(iPos!=9 || iPoszero==9 || sCheckzero=="00") // Since 3 and 6 addition           
          {
 		     alert(sAlertmess) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	         return(false)    ;

			}
}
return(true);
}

//***********************************************************
function CheckMaxlength(objName,maxvalue,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}


// require a value be entered in the field
ilen = objName.value.length ;
//alert(ilen);
alertsay = "Maximum Length of " + sAlertmess + " is " + maxvalue + " .";
if (ilen > maxvalue)
{
alert(alertsay) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}



//***********************************************************
function CheckMinlength(objName,minvalue,sAlertmess)
{

if(SAbort == "FALSE")
{
return (false);
}



// require a value be entered in the field
ilen = objName.value.length ;
//alert(ilen);
alertsay = "Minium Length of " + sAlertmess + " is " + minvalue + " .";

//alertsay = "Minium Length is " + minvalue ;
if (ilen < minvalue)
{
alert(alertsay) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}


//***********************************************************
function CheckCheckbox(objName,sAlertmess)
{

 if(SAbort == "FALSE")
	{
	  return (false);
	}

 if(objName.checked==false)
   {
    alert(sAlertmess) ;
	objName.focus();
	SAbort = "FALSE" ;
	return (false);
   } 
	return(true);
}

//************************************************************
function CheckHigherdate(datefield1,sAlertmess)
{
if(SAbort == "FALSE")
	{
	  return (false);
	}

    var itoday = new Date(); 
    var stodayyear ;
       
   stodayyear = itoday.toString() ;
   itodayyearlen = stodayyear.length - 4 ;
   itoday1 =   stodayyear.substr(itodayyearlen, 4) ;  //present year      
   
   sidatefield1 = datefield1.value ;
   idatefield1len = sidatefield1.length - 4 ;
   idatefield1 =   sidatefield1.substr(idatefield1len, 4) ;  //field year      
   
   yeardifffin =   parseInt(idatefield1) - parseInt(itoday1) ;  		   
  //alert(yeardifffin);
  if(yeardifffin<=-1) //to check date is < year passed //diff and not greater then present year
		{
           alert(sAlertmess) ;
	       datefield1.focus();
	       SAbort = "FALSE" ;
	       return (false);
        } 
    else
     {    
      //for checking month and date  
		if(yeardifffin==0)	// chk month and day only for the current year
		  {
			var strDate1Array ;
			var strDate2Array ;			
			var strMonth1 ; 
			var strMonth2 ;	
						
            strDate2Array = sidatefield1.split("/"); // to extract month,day              
            
			var strMonth1 = itoday.getMonth() + 1;          
	        var strMonth2 = strDate2Array[0] ;
	        
	        //alert(strMonth1);
	        //alert(strMonth2);
	        
	         if(strMonth2<strMonth1)//to check date is <month passed
			{
						 alert(sAlertmess) ;
                         datefield1.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
			else
			{
			var strDay1   = itoday.getDate();  
	        strDay2   = strDate2Array[1] ;
	       
	        var monthdiff ;
	        monthdiff = parseInt(strMonth2)-parseInt(strMonth1);
	        //alert(monthdiff);
	         if(monthdiff==0)
	         {
	          if(parseInt(strDay2)<parseInt(strDay1))//to check date is <year passed
			     {
						 alert(sAlertmess) ;
                         datefield1.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			      } 
			 }     
			}          
			
		 }	// inner else if
    }  //outer else if       
        
        return true ;

}

//************************************************************
function CheckYear(datefield1,iDiff,sAlertmess)
{
	if(SAbort == "FALSE")
	{
		return (false);
	}

    var itoday = new Date(); 
    var stodayyear ;
       
	stodayyear = itoday.toString() ;
	itodayyearlen = stodayyear.length - 4 ;
	itoday1 =   stodayyear.substr(itodayyearlen, 4) ;  //present year      
   
	sidatefield1 = datefield1.value ;
	idatefield1len = sidatefield1.length - 4 ;
	idatefield1 =   sidatefield1.substr(idatefield1len, 4) ;  //field year      
		 
	yeardifffin =   parseInt(idatefield1) - parseInt(itoday1) ;  		   
	//alert(yeardifffin);
	if(yeardifffin > iDiff) //to check date is < year passed //diff and not greater then present year
	{
		alert(sAlertmess) ;
		datefield1.focus();
		SAbort = "FALSE" ;
		return (false);
	} 
    return true ;
}

//************************************************************
function CheckLesserDate(datefield1,sAlertmess)
{
if(SAbort == "FALSE")
	{
	  return (false);
	}

    var itoday = new Date(); 
    var stodayyear ;
       
   stodayyear = itoday.toString() ;
   itodayyearlen = stodayyear.length - 4 ;
   itoday1 =   stodayyear.substr(itodayyearlen, 4) ;  //present year      
   
   sidatefield1 = datefield1.value ;
   idatefield1len = sidatefield1.length - 4 ;
   idatefield1 =   sidatefield1.substr(idatefield1len, 4) ;  //field year      
   
   yeardifffin =   parseInt(itoday1) - parseInt(idatefield1) ;  		   
  //alert(yeardifffin);
  if(yeardifffin<=-1) //to check date is < year passed //diff and not greater then present year
		{
           alert(sAlertmess) ;
	       datefield1.focus();
	       SAbort = "FALSE" ;
	       return (false);
        } 
    else
     {    
      //for checking month and date  
		if(yeardifffin==0)	// chk month and day only for the current year
		  {
			var strDate1Array ;
			var strDate2Array ;			
			var strMonth1 ; 
			var strMonth2 ;	
						
            strDate2Array = sidatefield1.split("/"); // to extract month,day              
            
			var strMonth1 = itoday.getMonth() + 1;          
	        var strMonth2 = strDate2Array[0] ;
	        
	        //alert(strMonth1);
	        //alert(strMonth2);
	        
	         if(strMonth2<strMonth1)//to check date is <month passed
			{
						 alert(sAlertmess) ;
                         datefield1.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			}
			else
			{
			var strDay1   = itoday.getDate();  
	        strDay2   = strDate2Array[1] ;
	       
	        var monthdiff ;
	        monthdiff = parseInt(strMonth1)-parseInt(strMonth2);
	        //alert(monthdiff);
	         if(monthdiff==0)
	         {
	          if(parseInt(strDay1)<parseInt(strDay2))//to check date is <year passed
			     {
						 alert(sAlertmess) ;
                         datefield1.focus() ;
                         SAbort = "FALSE" ;
	  		 			 return(false)    ;
			      } 
			 }     
			}          
			
		 }	// inner else if
    }  //outer else if       
        
        return true ;

}
function intialise()
{

SAbort = "TRUE" ;
}



