
var sErrorCol = new Array(20);
var SErrmes ;

sErrorCol[0] = "Invalid Date."
sErrorCol[1] = "Invalid Time."
sErrorCol[2] = "Cannot Be Greater Then Current Date."
sErrorCol[3] = "Invalid Number."
sErrorCol[4] = "Cannot Be Zero."
sErrorCol[5] = "Invalid String."
sErrorCol[6] = "Select From The Dropdown."
sErrorCol[7] = "Selection Is mandatory."
sErrorCol[8] = "Age Cannot Be Less Then 18 years."
sErrorCol[9] = "Click On search To Select."
sErrorCol[10] = "Invalid Email Address."
sErrorCol[11] = "Cannot Be Blank."
sErrorCol[12] = "Invalid Zipcode."
sErrorCol[13] = "Invalid Phone Number."
sErrorCol[14] = "Invalid Fax Number."
sErrorCol[15] = "Invalid SSN Number."
sErrorCol[16] = "Invalid Number."
sErrorCol[17] = "Please Select CheckBox."
sErrorCol[18] = "Invalid Fax Number."


//////*****************

function _FORMAT_DATE(objTextBox)
{
					if(event.keyCode < 48 || event.keyCode > 57)
					{
						event.keyCode = 0;
						return;
					}	
					
					var iLength;
					iLength = objTextBox.value.length;
					
					if(iLength)
					if(iLength == 2 || iLength == 5)
					objTextBox.value += "/";
}
///*************

//////*****************Niranjan - 2nd Feb '05

function _FORMAT_MON_YEAR(objTextBox)
{
					if(event.keyCode < 48 || event.keyCode > 57)
					{
						event.keyCode = 0;
						return;
					}	
					
					var iLength;
					iLength = objTextBox.value.length;
					
					if(iLength)
					//if(iLength == 2 || iLength == 5)
					if(iLength == 2)
					objTextBox.value += "/";
}
///*************


function ReturnErr(IErr)
{
 SErrmes =   sErrorCol[IErr] ; 
 return SErrmes ; 
}


var SAbort ; // used as flag for excuting the functions
SAbort = "TRUE" ;
//***************************Alphabets with '-_ Validation*********************
function CheckText(objName,sErrorCol)
{
	if(SAbort == "FALSE")
	{	
		return (false) ;
	}

	// this can be altered for any "checkOK" string you desire

	var RegExpres = /['A-Za-z0-9]/;
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789";
	var checkStr = objName.value;
	
	var allValid = true;
	var ch = checkStr.charAt(0);
	if(RegExpres.test(ch))
		allValid = true;
	else
	{
		alert("Name cannot start with special character");
		objName.focus();
		objName.select();
		SAbort = "FALSE" ;
		return (false);
		}


	if (!allValid)
	{
		alert(sErrorCol);
		objName.focus();
		objName.select();
		SAbort = "FALSE" ;
		return (false);
	}
	return true;
}
//***************************Alphabets with '-_ Validation Over*********************

//******************Check Confirm Password********************

function CheckConfirmPassword(objName1,objName2,passnum,sErrorCol){
	// 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("Password Cannot Be less than " + passnum + " characters.");
		return (false);
	}
	// check if both password fields are the same
	if (objName1.value != objName2.value){
		alert(sErrorCol);
		objName2.focus();
        SAbort = "FALSE" ;
		return (false);
	}
return(true);
}
//******************Check Confirm Password Overs here*****************
//********************Check Sentence*********************
function CheckSentence(objName,sErrorCol){
	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(sErrorCol);
		objName.focus();
		SAbort = "FALSE" ;
		return (false);
	}
	return(true);
}
//***************************************************


//***************************Alphanumeric with '-_ Validation*********************
function CheckAlphaNumeric(objName,sErrorCol){
	if(SAbort == "FALSE")
		return (false);
	//alert("sdasdasas");
	var FieldValue;
	var bValid = false;
	FieldValue = objName.value;
	var RegExpres = /['A-Za-z0-9_-]/;
	if(RegExpres.test(FieldValue))
			bValid = true;
	else
		bValid = false;
	if(! bValid){
		alert(sErrorCol);
		objName.focus();
		objName.select;
		SAbort = "FALSE" ;
		return (false);	
	}
	else
		return true;
}
//***************************Alphanumeric with '-_ Validation Over*********************

function CheckNumeric(objName,sErrorCol)
{

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(sErrorCol);

objName.focus();
objName.select();
SAbort = "FALSE" ;
return (false);
}
return(true);
}

//***********************************************

function CheckDecimal(objName,sErrorCol)
{

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(sErrorCol);

objName.focus();
SAbort = "FALSE" ;
return (false);
}

var checkStr ;
var validnum ;
validnum = "F"
checkStr = objName.value;
if (checkStr.search("\\.") != -1)
{
 for (i = 0;  i < checkStr.length;  i++)
                {
                  ch = checkStr.charAt(i);
                    if(ch=="." && i!=0)
                       {
                        validnum = "T"                                 
                       }   
                 }            
         if(validnum=="F")
         {
               alert(sErrorCol) ;
			   objName.focus();
			   SAbort = "FALSE" ;
			   return (false);             
         } 
         else
         {
         validnum = "F"
         }       
}                
return(true);
}	

//***********************************************

function CheckDecimalPos(objName,sAlertmess)
{
if(SAbort == "FALSE")
{
return (false);
}
	rateStr = objName.value;
	if (rateStr.indexOf(".") > -1) 
	{
		if (rateStr.indexOf(".") > 4)
			{
				alert(sAlertmess);
				objName.focus();
				objName.select();
				SAbort = "FALSE" ;
				return(false);
			}
		else
			{
			 arrStr = rateStr.split(".");
			 if (arrStr[1].length > 2) 
				{
					alert(sAlertmess);
					objName.focus();
					objName.select();
					SAbort = "FALSE" ;
					return(false);
				}
			 if (arrStr[1].length == 0) 
				{
					alert(sAlertmess);
					objName.focus();
					objName.select();
					SAbort = "FALSE" ;
					return(false);
				}
			}	
	}
	else
	   {
	      if (rateStr.length > 4) 
		{
		  alert(sAlertmess);
		  objName.focus();
          objName.select();
		  SAbort = "FALSE" ;
		  return(false);
		}
			
	  }

                 
return(true);
}
//************************************************

//*********************Check Password******************************
function CheckPassword(objName,sErrorCol){
	if(SAbort == "FALSE")
		return (false) ;
	// this can be altered for any "checkOK" string you desire
	var bValid = true;
	FieldValue = objName.value;
	//alert(FieldValue);
	//Validation for length
	if(FieldValue.length < 4){
		alert("Password cannot be less than 4 characters in length.");
		objName.focus();
		objName.select();
		SAbort = "FALSE" ;
		return (false);
	}
	var RegExpres = /\W/;
	if(RegExpres.test(FieldValue)){
		bValid = false;
	}
	else{
		for(var i=0;i <= FieldValue.length; i++){
			if(FieldValue.charAt(i) == " "){
				bValid = false;
				break;
			}
		}
		//bValid = true;
		//alert("hi");	
	}
	if(bValid == false){
		alert("Only characters from a-z, A-Z and integers from 0-9 are allowed in password.\nAny special character including white space is not allowed in password.");
		objName.focus();
		objName.select();
		SAbort = "FALSE" ;
		return (false);
	}
}
//******************Check Password Overs here********************

function CheckDropdownbox(objName,sErrorCol) // 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(sErrorCol) ;
objName.focus();
SAbort = "FALSE" ;
return (false) ;
}
return (true) ;
}


//***************************Email Validation*********************
function CheckEmail(objName,sErrorCol){
	if(SAbort == "FALSE" || SAbort == "false"){
		return (false);
	}
	var FieldValue;
	FieldValue = objName.value;
	var RegExpres = /^['a-zA-Z0-9._-]+@([a-zA-Z0-9._-]+\.)+[a-zA-Z0-9._-]{2,8}$/;
	if(RegExpres.test(FieldValue)){
		//now check for two consecutive dots
		var bValid = true;
		for(i = 0; i < FieldValue.length; i++){
			//alert("FieldValue.length = " + FieldValue.length);
			if(FieldValue.charAt(i) == "."){
				if(FieldValue.charAt(i+1) == "."){
					bValid = false;
					break;
				}
			}
			if(FieldValue.charAt(i) == "@"){
				if(FieldValue.charAt(i+1) == "."){
					bValid = false;
					break;
				}
			}
		}
		if(bValid){
			if(FieldValue.charAt(0) == "." || FieldValue.charAt(0) == "@" || FieldValue.charAt(0) == "_" || FieldValue.charAt(0) == "-")
				bValid = false;
			else if(FieldValue.charAt(FieldValue.length - 1) == "."  || FieldValue.charAt(FieldValue.length - 1) == "@" || FieldValue.charAt(FieldValue.length - 1) == "_" || FieldValue.charAt(FieldValue.length - 1) == "-")
				bValid = false;
			else
				bValid = true;
		}
	}
	else{
			bValid = false;
	}
	if(! bValid){
		alert("Email field is not entered correctly. \n" +"\nCorrect email Format:ValidName@ValidDomain.com ");
		objName.focus();
		objName.select();
		SAbort = "FALSE" ;
		return false;				
	}
	else
		return true;
}
//***************************Email Validation Over*********************

function CheckBirthdate(datefield,yeardiff,agelimit,sErrorCol) 
{
// 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(sErrorCol) ;
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(sErrorCol) ;
          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(sErrorCol) ;
             datefield.focus() ;
			 SAbort = "FALSE" ;
	         return(false)    ;  
	        }
	        
		    if(strDay<01 || strDay>31)              
			{
			 alert(sErrorCol) ;
			 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(sErrorCol) ;
                         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(sErrorCol) ;
             datefield.focus();
             SAbort = "FALSE" ;
	  		 return(false)    ;
           } 
return(true);
}

//*********************Check date********************
function CheckDate(datefield,sErrorCol){
	var bValid;
	var sAllowed = "1234567890/";
	if(SAbort == "FALSE")
		return (false);

	for(var i=0;i<datefield.value.length;i++){
		if(sAllowed.indexOf(datefield.value.charAt(i)) == -1){
			alert(sErrorCol) ;
			datefield.select();
			datefield.focus();
			SAbort = "FALSE" ;
			return(false);
		}
	}

	var strDate = datefield.value.split("/");
	bValid = 1;
	
	//if date format is " / / " its ok then
	//split date on "/" to get dd,mm and yyyy sperated
	//this will create a array of three elements where:
	//strDate[0] = MM, strDate[1] = DD, strDate[2] = "YYYY"
	
	var sMM,sDD,sYYYY;
	if(datefield.value.indexOf(" ") == -1){
		//if array has three elements i.e " / / " format is correct. check further
		if(strDate.length == 3){
			sMM=strDate[0];
			sDD=strDate[1];
			sYYYY=strDate[2];
			
			//if all elements in array are numbers i.e. "#/#/#" format is correct. check further
			if(! (isNaN(sMM) || isNaN(sDD) || isNaN(sYYYY)) )	{
				while(sMM.substr(0,1) == "0")
					sMM = sMM.substr(1,sMM.length);
				while(sDD.substr(0,1) == "0")
					sDD = sDD.substr(1,sDD.length);
				while(sYYYY.substr(0,1) == "0")
					sYYYY = sYYYY.substr(1,sYYYY.length);
				
				//if MM is between 1 - 12 i.e. "MM/#/#" is correct. check further			
				if(parseInt(sMM) >=1 && parseInt(sMM) <=12){
					var sToday = new Date();
				
					//if YYYY is between curren year + - 100 i.e "MM/#/YYYY" format is correct. check further
					if(parseInt(sYYYY) >= eval(sToday.getFullYear()-100) 
					&& parseInt(sYYYY) <= eval(sToday.getFullYear()+100)){
	
						//if DD is between 1 - Last day of MM/YYYY i.e "MM/DD/YYYY" format is correct. return true
						if(parseInt(sDD) >= 1 && parseInt(sDD) <= getMaxDays(parseInt(sMM),parseInt(sYYYY))){
							return (true);
						}
						
					}
				}
			}
		}
	}
	if(datefield.value != ""){
		//if any of the above check fails return false
		alert(sErrorCol) ;
		datefield.select();
		datefield.focus();
		SAbort = "FALSE" ;
		return(false);
	}
}
//*********************Check date Overs here********************

//*********************Get Maximum Days of a Month***************
function getMaxDays(iMonth,iYear){
	switch(iMonth){
		case 4:
		case 6:
		case 9:
		case 11:
			return(30);
		case 2:
			if(iYear % 100 == 0 || iYear % 4 == 0 || iYear % 400 == 0)
				return(29);
			else
				return(28);
	}
	return(31);	
}
//*********************Get Maximum Days of a Month Overs here******

//*************************************************************************************

//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,sErrorCol)
{

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(sErrorCol) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}

//**************************************************************
function CheckBlank(objName,sErrorCol)
{
	//alert(SAbort);
	if(SAbort == "FALSE")
	{
		return (false);
	}

	// require a value be entered in the field
	if (objName.value == "")
	{
		alert(sErrorCol) ;
		objName.focus();
		objName.select();
		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();
		  objName.select();
		  SAbort = "FALSE" ;
		  return (false);                      
        }   
     }            
       
return true;

}

//*********************************************************
function CheckCellPhone(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 CheckPhone(objName,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert(sErrorCol);
objName.focus();
objName.select();
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(sErrorCol) ;
objName.focus();
objName.select();
SAbort = "FALSE" ;
return (false);
}
else//check for valid phone number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 12) 
       {
          alert(sErrorCol) ;
          objName.focus() ;
          objName.select();
          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(sErrorCol) ;
             objName.focus() ;
             objName.select();
             SAbort = "FALSE" ;
	          return(false)    ;
			}  
	
           
}
return(true);
}

//*********************************************************
function CheckSSN(objName,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert(sErrorCol);
objName.focus();
objName.select();
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(sErrorCol) ;
objName.focus();
objName.select();
SAbort = "FALSE" ;
return (false);
}
else//check for valid phone number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 11) 
       {
          alert(sErrorCol) ;
          objName.focus() ;
          objName.select();
          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!=9 || iPoszero==9) // Since 3 and 7 addition
          {
 		     alert(sErrorCol) ;
             objName.focus() ;
             objName.select();
             SAbort = "FALSE" ;
	          return(false)    ;
			}  
	
           
}
return(true);
}

//*********************************************************
function CheckZip(objName,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert(sErrorCol);
objName.focus();
objName.select();
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 ;  

var iPos ;
iPos = 0 ;
  if (checkStr.length < 5) 
       {
          alert(sErrorCol) ;
          objName.focus() ;
          objName.select();
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else
      {
		if (checkStr.length == 5) //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);
			               }      
					} // for

			if(iPos!=0 || iPoszero==5) // 
			{
 				alert(sErrorCol) ;
				objName.focus() ;
	             objName.select();
		         SAbort = "FALSE" ;
			      return(false)    ;
			}  
			 
		 }
		 else
		 {
			if (checkStr.length != 10) //to find the positoins of -'s 
			{
	          alert(sErrorCol) ;
			  objName.focus() ;
	          objName.select();
		      SAbort = "FALSE" ;
			  return(false);
	        }
		    else
	        {
			for (i = 0;  i < checkStr.length;  i++)
					{
	                  ch = checkStr.charAt(i);
		                if(ch=="-")
	                       {
							iPos = iPos + i   ;
	                       }   
	                       
		                if(ch=="0")
	                       {
	                         iPoszero = iPoszero + 1;
		                     //alert(iPoszero);
			               }      
				     } // for

				if(iPos!=5 || iPoszero==9) // 
		          {
			 		    alert(sErrorCol) ;
						objName.focus() ;
						objName.select();
						SAbort = "FALSE" ;
						return(false)    ;
				  }  
	        }
		 }
      } 

//}
return(true);
}

//*********************************************************
function CheckFax(objName,sErrorCol)
{

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(sErrorCol) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
else//check for valid phone number ..
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 12) 
       {
          alert(sErrorCol) ;
          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(sErrorCol) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	          return(false)    ;

			}
}
return(true);
}

//*********************************************************

function CheckSsn(objName,sErrorCol)
{

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(sErrorCol) ;
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(sErrorCol) ;
          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(sErrorCol) ;
             objName.focus() ;
             SAbort = "FALSE" ;
	         return(false)    ;

			}
}
return(true);
}

//***********************************************************
function CheckMaxlength(objName,maxvalue,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}


// require a value be entered in the field
ilen = objName.value.length ;
//alert(ilen);
alertsay = "Maximum Length of " + sErrorCol + " is " + maxvalue + " .";
if (ilen > maxvalue)
{
alert(alertsay) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}



//***********************************************************
function CheckMinlength(objName,minvalue,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}



// require a value be entered in the field
ilen = objName.value.length ;
//alert(ilen);
alertsay = "Minium Length of " + sErrorCol + " is " + minvalue + " .";

//alertsay = "Minium Length is " + minvalue ;
if (ilen < minvalue)
{
alert(alertsay) ;
objName.focus();
SAbort = "FALSE" ;
return (false);
}
return(true);
}


//***********************************************************
function CheckCheckbox(objName,sErrorCol)
{

 if(SAbort == "FALSE")
	{
	  return (false);
	}

 if(objName.checked==false)
   {
    alert(sErrorCol) ;
	objName.focus();
	SAbort = "FALSE" ;
	return (false);
   } 
	return(true);
}

//********************Check Higher Date(compared to current Date)**********
function CheckHigherdate(datefield1,sErrorCol){
	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) ;  		   
	 
	if(yeardifffin<=-1){
		//to check date is < year passed //diff and not greater then present year
		alert(sErrorCol) ;
		datefield1.select();
		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 ;	
			var monthdiff ;
            strDate2Array = sidatefield1.split("/"); // to extract month,day              
			var strMonth1 = itoday.getMonth() + 1;          
	        var strMonth2 = strDate2Array[0] ;
			//alert(strMonth1);
			// alert(strMonth2);
			monthdiff = strMonth2-strMonth1;
			//alert(monthdiff);
			if(strMonth2<strMonth1){
				//to check date is <month passed
				alert(sErrorCol) ;
				datefield1.select() ;
				SAbort = "FALSE" ;
				return(false)    ;
			}
			else{
				var strDay1   = itoday.getDate();  
				strDay2   = strDate2Array[1] ;
				var daydiff ;
				daydiff = strDay2-strDay1 ;
				// alert(strDay1) ;
				// alert(strDay2) ;
				// alert(daydiff);
				if(parseInt(monthdiff)==0){
					if(strDay2<strDay1){
						//to check date is <year passed
					alert(sErrorCol) ;
					datefield1.select() ;
					SAbort = "FALSE" ;
					return(false)    ;
					} 
				}     
			}          
		}	// inner else if
	}  //outer else if       
	return true ;
}
//********************Check Higher Date Overs Here**********
function intialise()
{

SAbort = "TRUE" ;
}



//*******************Check For Numeric 
function IsNumeric(str)
{
	var i;
	for(i=0;i<str.length;i++)
	{
		if(!((str.charAt(i) <= '9') && (str.charAt(i) >= '0')))
			return(false);
	}
	return(true);
}

//*********************************************************
function CheckReportDate(objName,sErrorCol)
{

if(SAbort == "FALSE")
{
return (false);
}


var alertsay = ""; // define for long lines
// check to see if the field is blank

if (objName.value == "")
{
alert(sErrorCol);
objName.focus();
objName.select();
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(sErrorCol) ;
objName.focus();
objName.select();
SAbort = "FALSE" ;
return (false);
}
else
{
//alert(checkStr.length);

var iPos ;
iPos = 0 ;
  if (checkStr.length != 7) 
       {
          alert(sErrorCol) ;
          objName.focus() ;
          objName.select();
          SAbort = "FALSE" ;
		   return(false)    ;
       }      
     else//to find the positoins of -'s 
       {
		 var day,year
		 day = checkStr.charAt(0) + checkStr.charAt(1)
		 year = checkStr.charAt(3) + checkStr.charAt(4) + checkStr.charAt(5) + checkStr.charAt(6)
		 if (day < 1 || day > 12)
		 {
			alert(sErrorCol) ;
			objName.focus() ;
			objName.select();
			SAbort = "FALSE" ;
			return(false)    ;
		 }
         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!=2 || iPoszero==5) // Since 3 and 7 addition
          {
 		     alert(sErrorCol) ;
             objName.focus() ;
             objName.select();
             SAbort = "FALSE" ;
	          return(false)    ;
			}  
	
           
}
return(true);
}

//*********************************************************
function AllowOnlyNumeric()
{
	var ch = event.keyCode;
	if (ch<48 || ch>57)
	{
		if (ch != 45)
			event.keyCode = 0;
	}
}

//*********************************************************
function changephone(objzip)
{
	var sval,sexp;
	sval = objzip.value;
	if (sval.length == 10)
	{	
		objzip.value = sval.substr(0,3) + "-" + sval.substr(3,3) + "-" + sval.substr(6,4) 
	}
}
