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" ;
//***************************Alphabets with '-_ Validation*********************
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);

if (objName.disabled=false)
{
	objName.focus();
}	
SAbort = "FALSE" ;
return (false);
}
return(true);

}
//***************************Alphabets with '-_ Validation Over*********************

//******************Check Confirm Password********************

function CheckConfirmPassword(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("Password Cannot Be less than " + passnum + " characters.");
		return (false);
	}
	// check if both password fields are the same
	if (objName1.value != objName2.value){
		alert(sAlertmess);
		objName2.focus();
        SAbort = "FALSE" ;
		return (false);
	}
return(true);
}
//******************Check Confirm Password Overs here*****************
//********************Check Sentence*********************
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);
}
//***************************************************


//***************************Alphanumeric with '-_ Validation*********************
function CheckAlphaNumeric(objName,sAlertmess){
	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(sAlertmess);
		objName.focus();
		objName.select;
		SAbort = "FALSE" ;
		return (false);	
	}
	else
		return true;
}
//***************************Alphanumeric with '-_ Validation Over*********************

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);
}

//*********************Check Password******************************
function CheckPassword(objName,sAlertmess){
	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,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) ;
}


//***************************Email Validation*********************
function CheckEmail(objName,sAlertmess){
	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,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);
}

//*********************Check date********************
function CheckDate(datefield,sAlertmess){
	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(sAlertmess) ;
			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(sAlertmess) ;
		datefield.select();
		datefield.focus();
		SAbort = "FALSE" ;
		return(false);
	}
	return true;
}
//*********************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,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,flag)
{
//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 CheckBlankLogin(objName,sAlertmess,flag)
{
//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;
       

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);
}

//********************Check Higher Date(compared to current Date)**********
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) ;  		   
	 
	if(yeardifffin<=-1){
		//to check date is < year passed //diff and not greater then present year
		alert(sAlertmess) ;
		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(sAlertmess) ;
				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(sAlertmess) ;
					datefield1.select() ;
					SAbort = "FALSE" ;
					return(false)    ;
					} 
				}     
			}          
		}	// inner else if
	}  //outer else if       
	return true ;
}
//********************Check Higher Date Overs Here**********
function intialise()
{

SAbort = "TRUE" ;
}


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 += "/";	
} 


function _ALLOW_NUMBER_OnKeyPress(objTextBox){
			
					if(event.keyCode < 48 || event.keyCode > 57)
					{
						event.keyCode = 0;
						return;
					}	
		}
		
// ALLOW DECIMAL INPUTS ONLY VALIDATED ON KEY PRESS		
		function _ALLOW_Decimal_OnKeyPress(objTextBox){
					
					var value = objTextBox.value;
					var bDecimal = false;
					if(value.indexOf('.') >= 0 && event.keyCode == 46)
						bDecimal = true;
					
					
								
					
					if(event.keyCode == 46)
					{
						
						if(bDecimal == true)
						 { event.keyCode = 0;
						   return;
						  }
					}
						
					else if( (event.keyCode < 48 || event.keyCode > 57) )
					{
						event.keyCode = 0;
						return;
					}	
					
		}
		
/*	ValidDate - true for valid date, false for invalid*/
function IsValidDate(PossibleDate)
{	
	
	var PDate = new String(PossibleDate);	
	var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	if( regex.test(PDate) )
		{
		 var month = new String(RegExp.$1);		
		 var day = new String(RegExp.$2);		
		 var year = new String(RegExp.$3);		
		 if( month.length == 0 )		
		 {			
		 month = new String(RegExp.$4);			
		 day = new String(RegExp.$5);			
		 year = new String(RegExp.$6);
		 }				
		 var today = new Date();		
		 var thisYear = new String(today.getFullYear());				
		 if( year.length == 2 )		
		 {								
		 if( year > 50 )			
		 {				
		 year = String(Number(thisYear.substring(0,2))-1) + year;			
		 }			
		 else			
		 {				
		 year = thisYear.substring(0,2) + year;			
		 }		
		 }				
		 if( month < 1 || month > 12 ) { return false; 
		 }		
		 if( day < 1 || day > 31 ) { return false; 
		 }		
		 if ((month==4 || month==6 || month==9 || month==11) && day>30) { return false; 
		 }		
		 if (month == 2) // check for february 29th		
		 { 			
		 var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));			
		 if (day>29 || (day==29 && !isleap)) 			
		 {				
		 return false;			
		 }		
		 }						
		 if( (Number(year) < Number(thisYear) - 250) ||	(Number(year) > Number(thisYear) + 250) )			
		 { return false; 
		 }					
		 return true;	
		 }	
		 return false;
		 }
