//this function is used to check all or uncheck all the check box when a CHECK ALL check box is checked

function select_deselectAll()
		 {
		 
			
		 	var ml = document.forms[0]
		    var len = ml.elements.length	
		    if (ml.chkall.checked)
				{
					for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" &&  !(e.id=="chkall") )
								{
									e.checked= true;
								}
							}
				}			
			else
			    {
					for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" &&  !(e.id=="chkall") )
								{
									e.checked= false;
								}
							}
			    }	 
		 }

//this function is used to check whether only one check box is checked

function selectOne()
		 {
			var blnResult;
		 	var ml = document.forms[0];
		    var len = ml.elements.length;	
		    blnResult = 0;
			for(var i = 0 ; i < len ; i++) 
					{
						var e=ml.elements[i];
						if (e.type == "checkbox" &&  e.checked == true )
						{
							if (blnResult == 0)
							{
								blnResult = 1;
							}
							else
							{
								return false;
							}
						}
					}
			if (blnResult == 1 )
			{
				return true;
			}
		}
		


//This function checks if the check box have been checked for deletion

function checknone()
		{
			var ml = document.forms[0];
		    var len = ml.elements.length;	
			for(var i = 0 ; i < len ; i++) 
				{
					var e= ml.elements[i];
					if (e.type == "checkbox" && e.checked && !(e.name=="chkall")  ) 
					{
						return true;
					}
				}
			return false;
		}
		
// this function is to check whether the from date is less than to date		
function FromLessTo(from,to)
{
	var day = from.substring(0,2);
	var mon = from.substring(3,5)-1;
	var yar = from.substring(6,10);
	var datfrom =  new Date(yar,mon,day);

	var day = to.substring(0,2);
	var mon = to.substring(3,5)-1;
	var yar = to.substring(6,10);
	var datto =  new Date(yar,mon,day);

	if (datfrom < datto)
		return true;
	else 
		return false;
}		
//This function is called when the delete button is pressed
		function confirmDelete(title)
		{
				
		 var ml = document.forms[0];
		 var len = ml.elements.length;
			if (false==checknone()) 
				{
					alert("Atleast one " + title + " has to be selected for deletion");
					return false;
				}
			else
				{
					if (confirm("Are you sure you want to delete?"))
					{
						return true;
					}
					else
					{
						for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" && e.checked)
								{
									e.checked= false;
								}
							}
							return false;
					}
				}
		  }


// date validation  for dd/mm/yyyy. <---START HERE---> 

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=3000;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
    {
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}
// date validation  for dd/mm/yyyy. <---END HERE---> 
//this function check the given value is decimal
function isDecimal(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}




//this function check the given value as correct no.of.days
/*function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}
*/

//this function check the given value is decimal
function isAmount(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 999999999999.99)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


		function isAmountValid(strString)
			{
			var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
			if (strString > 999999999999999.99)
			{
			return false;
			}


			if (oRegExp.test(strString))
				{
				if (strString.indexOf(".") == -1 )	
					{
						return true;
					}
				else
					{  
					if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 					{return true;}
					else
							{return false;}
					} 
				}
				else
				{
					return false;
				}
			}

//this function check the given value is decimal
function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 999.9)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3  || strString.indexOf(".") == strString.length - 2 || strString.indexOf(".") == strString.length)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


//this function check the given value is Email
function isEmail(strEmail)
{
	var oRegExp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/g;
	if (oRegExp.test(strEmail))
    {
         return true;
    }
    else
    {
		return false;
    }
}


//this function check given value for valid WEBSITE address
function isWeb(theUrl)
{
  if(theUrl.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
	 theUrl.match(/^(www)\.\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
     theUrl.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i)  
     )
      {
		return true;
	  }
   else 
	  {
		return false;
	  }

}




//this function used to check the value to be empty
function isEmpty(strString)
{
if (((strString == null) || (strString.length == 0)))
{
	return true;
}
else
{

var strLen= strString.length;
var intLen=0;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		
		/*	if(strString.charAt(intLenIndex)==String.fromCharCode(13))//This will check ENTER KEY VALUE 
			{
			   intLen=intLen+2;
			}
			else
			{
		*/
				//if(strString.charAt(intLenIndex)==" ")
				if(strString.charAt(intLenIndex)==" ") 
						{
							intLen=intLen+1;
						}
		//	}	    
	}
	
	if (intLen==strString.length)
	{
			return true;
	}		
	else
	{	
		return false;
	}
}
}


//this function check the given value is number
function isNumber(strString)
{

var oRegExp = /(^-?\d\d*$)/;

if (oRegExp.test(strString))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}


// phone number Validation <--START HERE -->

// Declaring required variables
var digits = "0123456789";

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ,";

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isPhone(strPhone)
{
	var cnt=0;
	s=stripCharsInBag(strPhone,phoneNumberDelimiters);
	if (isInteger(s))
	{
		if ((isSpecial(strPhone.charAt(0),"(")==false) && (isNumber(strPhone.charAt(strPhone.length-1))==true) )
			{
				for (i = 0; i < strPhone.length; i++)
				{
						if (strPhone.charAt(i)=="(") {cnt++;}
						if (strPhone.charAt(i)==")") {cnt--;}
				}				
				if (cnt==0)
					{return true;}
				else 
					{return false;}
			}
		else
			{
				return false;
			}
	}
	else
	{
		return false;
	}		
	
}


// phone number Validation <--END HERE -->


//this function used to check the positive decimal value
function isPositiveDecimal(strString)
{
	var blnReturn;
  	if (parseFloat(strString)>=0)
	{
		blnReturn =true;
	}
	else
	{
		blnReturn=false;
	}

return blnReturn;
}


//This function will check for blank spaces 
function isSpace(strString)
{	
	var strLen= strString.length; 	
	var blnReturn;
	blnReturn = true;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		if(strString.charAt(intLenIndex)==" ")
		{
			//strString.IsValid = false;			 
			blnReturn =false; 
		}
	}	    
	return blnReturn;  
}

//This function will check whether it contains any special characters with given chars
//Special Character Validation for General fields
function isSpecial(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
  
  //Commented by Sai to relax the special characters as per Nicole and Steve Niss request - Feb 06 2009 
  //strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890. " + strSplChar;
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+=|\}]{[:;/?.,äöüß " + strSplChar;
  
  
  for (intLoop=0;intLoop<strString.length;intLoop++)
  	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
	   		{ 
				blnReturn=true;
			}
	}
	return blnReturn;
}
//Special Character Validation for Email field
function isSpecialEmail(strStringEmail,strSplCharEmail)
{
  var blnReturnEmail;
  var strFoundEmail;
  blnReturnEmail=false;
  var strvalueEmail;
   
  //Commented by Sai to relax the special characters as per Nicole and Steve Niss request - Feb 06 2009
  //strvalueEmail = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.!#$%&*+-/=?^_`{|}~" + strSplCharEmail;
  strvalueEmail = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+=|\}]{[:;/?.,äöüß " + strSplCharEmail;
  
  for (intLoopE=0;intLoopE<strStringEmail.length;intLoopE++)
  	{
		
	   if ((strvalueEmail.indexOf(strStringEmail.charAt(intLoopE)))<0)
	   		{ 
				blnReturnEmail=true;
			}
	}
	return blnReturnEmail;
}
//Special Character Validation for Description fields
function isSpecialDesc(strStringDesc,strSplCharDesc)
{
  var blnReturnDesc;
  var strFoundDesc;
  blnReturnDesc=false;
  var strvalueDesc;
  
  //Commented by Sai to relax the special characters as per Nicole and Steve Niss request - Feb 06 2009  
  //strvalueDesc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.!@%&()-,; " + strSplCharDesc;
  strvalueDesc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+=|\}]{[:;/?.,äöüß " + strSplCharDesc;
  
  for (intLoopD=0;intLoopD<strStringDesc.length;intLoopD++)
  	{
		
	   if ((strvalueDesc.indexOf(strStringDesc.charAt(intLoopD)))<0)
	   		{ 
				blnReturnDesc=true;
			}
	}
	return blnReturnDesc;
}
//This function will check whether it contains any special characters with given chars
function isChar(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
     
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + strSplChar;
    
  for (intLoop=0;intLoop<strString.length;intLoop++)
	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
			{ 
				blnReturn=true;
 			}
	}
	return blnReturn;
}



//function to get the current date
function currentdate()
	    {
		  	 datX=new Date();
			 datY=new String(new Date());
					
			if (navigator.appName=="Netscape")
				{
							if (parseFloat(navigator.appVersion.substring(0,3))>4.01)
							{
								thisYear=parseInt(datY.substring(51,55))
							}
							else
							{
								thisYear=datX.getYear();
							}
				}
				else
				{
						thisYear=datX.getYear();
				}
			thisMonth=datX.getMonth()+1;
			thisDate=datX.getDate();
		  return ((thisDate+'/'+thisMonth+'/'+thisYear));
	    }		


//Date Comparison
function datecompare(arguments1, arguments2,arguments3)
		{
		 // to check date1 as valid Date
		    dategiven=arguments1;
	        datX=new Date();
			datY=new String(new Date());
			
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
		
			d1=Date.UTC(year,month,day,0,0,0,0)
			// check for second date
			dategiven=arguments2;
					datX=new Date();
					datY=new String(new Date());
						
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			
			d2=Date.UTC(year,month,day,0,0,0,0)
							
						
			// check for date 
			if (arguments3 == "<" )
				{
					if(d1<d2)
						{ return  true;	}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '<=' )
				{
					if(d1<=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>' )
				{
					if(d1>d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>=' )
				{
					if(d1>=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
			if (arguments3 == "=" )
				{
					if(d1==d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
		  return false;  
		 
			}

  			
// This function will return the Selected Date to the CtrlName Control.
 function GetDate(CtrlName)
 {
	ChildWindow = window.open('../calendar/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=232,height=198,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no,minimize=no,maximise=no");    
 }
 
 
//This is used to check the currency format 
 function currencyCheck(mystr)
{
	var blnreturn;
	   	
	var c=Number(0);
	
	for(i=0;i<mystr.length;i++)
	{
		if(mystr.charAt(i)==".")
		{
			c=c+1;
				
		}
	}
	if(c>1)
	{
		return true
	}
	else
	{
		  	if ((mystr.charAt(0)==".") || (mystr.charAt(mystr.length-1)==".") )
   			{
     		//return bln=true;
				return true
			}
		  	else
   			{
				subs=mystr.substr(mystr.indexOf("."));
				if(subs.length>3)
					return true
				else
					return false
			}
	}
	
}

function LTrim(str) {
 for (var i=0; str.charAt(i)<=" "; i++);
 return str.substring(i,str.length);
}

function rev(str) {
    var s = "";
    var i = str.length;
    while (i>0) {
        s += str.substring(i-1,i);
        i--;
    }
    return s;
}

function RTrim(str) {
 for (var i=str.length-1; str.charAt(i)<=" "; i--);
 return str.substring(0,i+1);
}

function isSpacebar(str)
{
	var strLen=str.length;
	if (str.charAt(0)==" ")
	{
		return true;
	}
	
	if (str.charAt(strLen-1)==" ")
	{
		return true;
	}
	return false;
}

// This function will return the Selected Date to the CtrlName Control.
 function GetDate(CtrlName)
 {
	ChildWindow = window.open('../Calender/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=232,height=198,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no,minimize=no,maximise=no");    
 }
	
// This function will limit the maxlength for a TextArea.it will be used like this, in Textbox tag
// onKeyDown="maxlength(document.forms[0].field,250)" onKeyUp="maxlength(document.forms[0].field,250)"
function maxlength(field,maxlimit)
			{
				if (field.value.length > maxlimit)
				field.value = field.value.substr(0, maxlimit);
			}

//Open a new URL
 function vOpen(strUrl)
			{
				window.open(strUrl); 
			}
	
	//date compare function

function DateValidate(Dat1,Dat2)
		{
			var d1;
			var d2;
			
					d1=Dat1.split('/');
					d2=Dat2.split('/');
					var Date1=new Date(d1[2],d1[1],d1[0]);
					var Date2=new Date(d2[2],d2[1],d2[0]);
					if (Date1 > Date2)
					 { 
						return false ; 
					} 	
					return true;
      	}		
     
  // function YearValidate(Dat1,Dat2)
//		{
//			var d1;
//			var d2;
			
//					d1=Dat1.split('/');
//					d2=Dat2.split('/');
//					var Date1=new Date(d1[2],d1[1],d1[0]);
//					var Date2=new Date(d2[2],d2[1],d2[0]);
//					if (Date1 > Date2)
//					 { 
//						return false ; 
//					} 	
//					return true;
  //    	}		
   	



//new tvs code;




function validate()
{
    switch(validate.arguments[0])
	{
		case "notempty":
		//to check whether the field is empty
			var intNullValid=0;
		strLen=validate.arguments[1].length; 
			for(numLenindex=0; numLenindex < strLen; numLenindex++)
			{
				  if(validate.arguments[1].charAt(numLenindex)!=" ")
					{
					 intNullValid=1;
					}
	        }
	        if (intNullValid==0 || validate.arguments[1].length==0 )
	        {
			       return false;
		    }     	 
			break;

		case "mail":
		a=mail(validate.arguments[1]);
		 return a
		break; 
		
		case "website":
		return checkurl(validate.arguments[1]);
		break; 
		
		case "phone":
		return PhoneValidate(validate.arguments[1],4,20,'y'); 
		break; 
		
		case "fax":
		return PhoneValidate(validate.arguments[1],4,20,'y');
		break;
				
		case "maxlen":
		//to check whether the given string is of given length
		//received string length and received maximum length is checked
		//and if found less false is returned
			if(validate.arguments[1].length < validate.arguments[2])
				return false
				break;
				
	    case "confirmpass":
			    if(validate.arguments[1] != validate.arguments[2])			    
				return false
	    		break;
	    
	    // to check whether loginname has minimum of 4 characters
	    case "checklogin":
			    if(validate.arguments[1].length<4)			    
				return false
	    		break;
   
	   
	    
	    // to check whether password has minimum of 4 characters
	    case "checkpass":
			    if(validate.arguments[1].length<4)			    
				return false
	    		break;

		case "numberonly":
		// to check whether the entered value is number
			
			
				if(validate.arguments[1].indexOf('e')!= -1)
					return false;
				
			if (isNaN(validate.arguments[1])) 
				return false;
				
				
				break;
		
		case "num1ltnum2":
		//to check first number is less than the second number
			if ( parseInt(validate.arguments[1]) > parseInt(validate.arguments[2]))
  				return flase;
			break;

		case "num1eqnum2":
		//to check whether the given two numbers are equal
			if ( parseInt(validate.arguments[1]) != parseInt(validate.arguments[2]))
  				return false;
			break;
							
		
		case "checkspchar":
		//
			return checkspchar(validate.arguments[1]);
			break;
	
		case "checkspchar1":
		//
			return checkspchar1(validate.arguments[1]);
			break;

		case "checkspchar2":
		//
			return checkspchar2(validate.arguments[1]);
			break;
			
		case "checkspchar3":
		//
			return checkspchar3(validate.arguments[1]);
			break;
		
		case "checkspchar4":
		//
			return checkspchar4(validate.arguments[1]);
			break;
			
		case "checkspchar5":
		//
			return checkspchar5(validate.arguments[1]);
			break;
			
		case "checkspchar6":
		//
			return checkspchar6(validate.arguments[1]);
			break;
		
		case "alphaonly":
		//
			for(i=0;i<=(validate.arguments[1].length)-1;i++)
  		  	{ 
	 			var r=""+parseInt((validate.arguments[1].charAt(i)))
    				if(r.indexOf("N")==-1) 
     				{ 
  					return false;
				} 
		  	}
			break;
			
		//to check the decimal values of specified format	
		case "numlength":
		//value to be checked ,no of digits before the decimal point and after the decimal point are given
		// the given value is checked for the format if so returned true else false
		 //check to be done only if the length is greater than zero
		if((validate.arguments[1]).length >0){ 
			numval=(validate.arguments[1]);
			
			//checks whether it is a number or not
			if(isNaN(numval)){   
				return false
			}	
		//check whether the length is lessthan the specified without the decimal point			
		if(numval.indexOf(".") == -1 && numval.length> validate.arguments[2]){
					return false
			}
		//check whether digits after the decimal point is as specified or whether the digits before the decimal point grater than the specified 	
		if(numval.indexOf(".")!=-1 && (numval.substring((numval.indexOf(".")+1),numval.length).length> validate.arguments[3] || numval.substring(0,numval.indexOf(".")).length>validate.arguments[2])){
					return false
			}
			}
		break;
		

		case "timeformat":
		//to check the entered time is of given format
			giventime=validate.arguments[1];
			format=/^(\d{1,2})(:)(\d{2})$/; 
			//check format as one or  two digit: two digit  
			if(giventime.match(format)==null )return false
			//check whether the hour is less 24 and minutes less than 60
			if(giventime.substring(0,giventime.indexOf(":"))>23 ||giventime.substring(giventime.indexOf(":")+1,giventime.length)>59) return false
				 
			break;
		
		case "timevalidate":
		//to check the one time is always less than the other
			fromtime=validate.arguments[1];
			totime=validate.arguments[2];
		// 	check hour of first time is less than the hour of the second time passed
			if(fromtime.substring(0,fromtime.indexOf(":")) > totime.substring(0,totime.indexOf(":") ))
				return false
		// 	check minutes of first time is less than the hour of the second minutes passed
				if(fromtime.substring(0,fromtime.indexOf(":")) == totime.substring(0,totime.indexOf(":") )){
					if(fromtime.substring(fromtime.indexOf(":")+1,fromtime.length) >= totime.substring(totime.indexOf(":")+1,totime.length) )  
						return false
				}
				break;

		case "dateformat":
			// to check date format
			givendate=validate.arguments[1]
			if(givendate.length >0){
			//pattern is one or two digits/one or two digits/four digits
			var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/;
			var matchArray = givendate.match(datePat);
				//check for the format			
			if (matchArray == null)
			{
			//alert("Date is not in a valid format.")
			return false;
			}
			//month day and year values are assigned to the variables below
			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			
			arrmonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
			arrmonname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec")
			
			 
			if (month < 1 || month > 12) 
			{ // check month range
				//alert("Month should be between 1 and 12.");
				return false;
			}
			//check for leap year
				if(month==2){
					if(year%4==0){
					arrmonth[1]=29
						if(year%100==0 && year%400!=0) arrmonth[1]=28;
				}
				if (day < 1 || day > arrmonth[1] ){
				 //alert("February Should not have more than "+arrmonth[1])
				 return false;
				 				 }
			}
			else if(day < 1 || day>arrmonth[month-1] ) 
			{
			//days  in the month
				//alert(arrmonname[month-1]+" should have day between 1 and " + arrmonth[month-1]);
				return false;
			}
			
			if(year<1850){
			//alert("Year should not be less than 1850")
				return false;
			}

		}
		break;

		case "multiselect":
		//in multiselect combo to check  to select not more than the given value
			count=0
			for(i=0;i<validate.arguments[1].length;i++){
				if(validate.arguments[1].options[i].selected){//if selected 
					count++;
						if (count > validate.arguments[2]) 	return false //check if selected is more than specified 
					}
			}
			break;
			
		case "selectednothing":
		//inmultiselect to check nothing is selected
			count=0
			for(i=0;i<validate.arguments[1].length;i++){
				if(validate.arguments[1].options[i].selected)
					count++;
					}
				if(count==0) return false;									
			break;

		case "datevalidate":
//to check the realyion between the to dates
				from=validate.arguments[1];
						to=validate.arguments[2];
						operater=validate.arguments[3];
						pattern=validate.arguments[4];
						if(operater== "=") operater="==";
						if(operater== "#" || operater== "<>" ) operater="!=";
						
						valid="/~\\~-~,~"
						delimiter=valid.split("~")

						flag1=0 
						flag2=0
						//check whether the delimiter is found or not
						for (k=0;k<delimiter.length;k++)	{		
									if (from.indexOf(delimiter[k])!= -1 && flag1==0)
									{
										flag1=1
										fromdelimit=delimiter[k]
									}
									
									if (to.indexOf(delimiter[k])!= -1 && flag2==0)
									{
										flag2=1
										todelimit=delimiter[k]
									}
									
							}			

						//delimiter is replaced by special characters
						//newFrom=from.replace(fromdelimit,"þ")
						newFrom=from.replace(fromdelimit,"^")
						//newFrom=newFrom.replace(fromdelimit,"Ü")
						newFrom=newFrom.replace(fromdelimit,"|")
						//newto=to.replace(todelimit,"þ")
						newto=to.replace(todelimit,"^")
						//newto=newto.replace(todelimit,"Ü")
						newto=newto.replace(todelimit,"|")
						// year month and day part are split
						//yystr1=newFrom.substring((newFrom.indexOf("Ü")+1),newFrom.length)
						yystr1=newFrom.substring((newFrom.indexOf("|")+1),newFrom.length)
						//mmstr1=newFrom.substring((newFrom.indexOf("þ")+1),newFrom.indexOf("Ü"))
						mmstr1=newFrom.substring((newFrom.indexOf("^")+1),newFrom.indexOf("|"))
						//ddstr1=newFrom.substring(0,newFrom.indexOf("þ"))
						ddstr1=newFrom.substring(0,newFrom.indexOf("^"))

						//yystr2=newto.substring((newto.indexOf("Ü")+1),newto.length)
						yystr2=newto.substring((newto.indexOf("|")+1),newto.length)
						//mmstr2=newto.substring((newto.indexOf("þ")+1),newto.indexOf("Ü"))
						mmstr2=newto.substring((newto.indexOf("^")+1),newto.indexOf("|"))
						//ddstr2=newto.substring(0,newto.indexOf("þ"))
						ddstr2=newto.substring(0,newto.indexOf("^"))
						if(mmstr1.indexOf("0")==0)
							mmstr1=mmstr1.substring(1,2);
						if(mmstr2.indexOf("0")==0)
							mmstr2=mmstr2.substring(1,2);
							
						d1=Date.UTC(yystr1,parseInt(mmstr1)-1,ddstr1,0,0,0,0)
						d2=Date.UTC(yystr2,parseInt(mmstr2)-1,ddstr2,0,0,0,0)
						
						return (eval("d1="+d1+";d2="+d2+";d1 "+operater+" d2"))
						//returns true or false depending on the dates and operater received
						break;

				case "textarealength":
				//to check whether textarea doesnt have more than the given charecters 
				taContent=validate.arguments[1];
				taLength=validate.arguments[2];
				//check received string's length is greater than the specified
					if(taContent.length > taLength)
					  return false
					  break;
	
	
	
				case "datecheck":
		// to check whether the date is greater than today or from tommorow
				dategiven=validate.arguments[1];
						datX=new Date();
					datY=new String(new Date());
					
					if (navigator.appName=="Netscape")
					{
					if (parseFloat(navigator.appVersion.substring(0,3))>4.01)
					{
						thisYear=parseInt(datY.substring(51,55))
						
					}
					else
					{
						thisYear=datX.getYear();
					}
					}
			else
			{
						thisYear=datX.getYear();
										}
			thisMonth=datX.getMonth()+1;
			thisDate=datX.getDate();

			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

				//check for format
			if (matchArray == null)
			{
			alert("Date is not in a valid format.")
			return false;
			}
			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			if (month < 1 || month > 12) 
			{ // check month range
				alert("Month must be between 1 and 12.");
				return false;
			}
			if (day < 1 || day > 31) 
			{//check for days in the month
				alert("Day must be between 1 and 31.");
				return false;
			}
			d1=Date.UTC(year,month,day,0,0,0,0)
			d2=Date.UTC(thisYear,thisMonth,thisDate,0,0,0,0)
			// check for date whether it is from today
			if(validate.arguments[2]=="fromtoday")
			{
						if(d1<d2)
						{
						// alert("Date Should be equal to or greater than the Current Date");
						return false	
						}
			}
			//check for date whether it is from tomorrow
			 if(validate.arguments[2]=="fromtomorrow"){
					if(d1<=d2){
						alert("Date Should be greater than the Current Date");
						return false	
				 }
			}
	
	
	}
	
	return true;
}
//End of Validation for general text field

//Checking for URL
function checkurl(val)
{
// url of the format
	if(!(val.substring(0,1)=="w" ||val.substring(0,1)=="W" ||val.substring(0,3)=="www" ||val.substring(0,1)=="WWW" ||(val.substring(0,4)).toUpperCase()== "HTTP" )){
			return false;
			}
		return true;
		}


//End of URL

//Validation for phone
function PhoneValidate(strPhoneNo,intMinChars,intMaxChars,strCheckNull)
{
//code to check null
var intPhoneNullValid=0;

    	PhoneLen=strPhoneNo.length
		for(PhoneLenindex=0; PhoneLenindex < PhoneLen; PhoneLenindex++)
				{
				  if(strPhoneNo.charAt(PhoneLenindex)!=" ")
					{
					 PhoneLenindex=PhoneLen;
					 intPhoneNullValid=1;
					}
	          	 }
	     if (intPhoneNullValid==0 && strCheckNull=="y")
	     {
			return false;
		 }     	 

//if the field is not empty then the following conditions are checked
if(intPhoneNullValid==1)
{

	//code to check minimum / maximum chars
	//if (strPhoneNo.length < intMinChars || strPhoneNo.length > intMaxChars)
	//{
	//	return false;
	//}

	//code for last char not to be + or - or (
	if(strPhoneNo.substring(strPhoneNo.length-1,strPhoneNo.length) == "+" || strPhoneNo.substring(strPhoneNo.length-1,strPhoneNo.length) == "(" || strPhoneNo.substring(strPhoneNo.length-1,strPhoneNo.length) == "-")
	{
		return false;
	}
	//check for mutual occurance of ) and (  
	            if( (strPhoneNo.indexOf(')') == -1 && strPhoneNo.indexOf('(') != -1 ) || (strPhoneNo.indexOf(')') != -1 && strPhoneNo.indexOf('(') == -1 )  )       
	            {return false;}
	//check for + or - in between ()            
	            if( (strPhoneNo.indexOf('+') > strPhoneNo.indexOf('(') && strPhoneNo.indexOf('+') < strPhoneNo.indexOf(')') ) || (strPhoneNo.indexOf('-') > strPhoneNo.indexOf('(') && strPhoneNo.indexOf('-') < strPhoneNo.indexOf(')') ) )
	            {return false;}

	//general check 
	var strAllowCharValid="no"
	var intRBraceCnt=0
	var intLBraceCnt=0
	var intPlusCnt=0
	var intHypnCnt=0
	var strContiSplChar=""
	strAllowChars="(,),-,+,0,1,2,3,4,5,6,7,8, ,9,x,X"
	arrAllowChars=strAllowChars.split(",")
																											
	            
	for( intPhoneIndex=0 ; intPhoneIndex<strPhoneNo.length ; intPhoneIndex++)
	 {
                //getting count for more than 1 occurance of ),(,+,-	          
	            if(strPhoneNo.charAt(intPhoneIndex)==")")
	            {
	            intRBraceCnt++;
	            }
	            else if(strPhoneNo.charAt(intPhoneIndex)=="(")
	            {
	            intLBraceCnt++;
	            }
	            else if(strPhoneNo.charAt(intPhoneIndex)=="+")
	            {
	            intPlusCnt++;
	            }
	            else if(strPhoneNo.charAt(intPhoneIndex)=="-")
	            {
	            intHypnCnt++;
	            }
	            
	            //check for continous occurence of spl chars
	            if((strContiSplChar=="+" && (strPhoneNo.charAt(intPhoneIndex)=="-" || strPhoneNo.charAt(intPhoneIndex)=="(" || strPhoneNo.charAt(intPhoneIndex)==")" || strPhoneNo.charAt(intPhoneIndex)=="+")) || (strContiSplChar=="("  && (strPhoneNo.charAt(intPhoneIndex)=="-" || strPhoneNo.charAt(intPhoneIndex)=="(" || strPhoneNo.charAt(intPhoneIndex)==")" || strPhoneNo.charAt(intPhoneIndex)=="+")) || (strContiSplChar==")"  && (strPhoneNo.charAt(intPhoneIndex)=="(") ) || (strContiSplChar=="-"  && (strPhoneNo.charAt(intPhoneIndex)=="-" || strPhoneNo.charAt(intPhoneIndex)=="(" || strPhoneNo.charAt(intPhoneIndex)==")" || strPhoneNo.charAt(intPhoneIndex)=="+")))
	            {
	            return false;
	            }
	            strContiSplChar=strPhoneNo.charAt(intPhoneIndex)
	               
	            strAllowCharValid="no" 
	            
	            //check with the array
	            for(intAllowCharIndex = 0 ; intAllowCharIndex < arrAllowChars.length ; intAllowCharIndex++ )
				{
					if (strPhoneNo.charAt(intPhoneIndex) == arrAllowChars[intAllowCharIndex])
					{
						strAllowCharValid="yes"
						intAllowCharIndex=arrAllowChars.length;			
					}
				}
	            if(strAllowCharValid=="no")
				{
					return false;
				}
				else{}
	 }

	 //spl chars like ) , ( , + should appear only once
	 if(intRBraceCnt > 1 || intLBraceCnt > 1 || intPlusCnt > 1 || intHypnCnt > 3 )
	 {
	 return false;
	 }

}//end of if loop that checks to allow the validation if field is not null

return true
}
//End of validation for phone

//Checking whether year entered is number or not
function checkYear(year)
{
  datX=new Date();
  
  if (navigator.appName=="Netscape")
							{
							
				if (parseFloat(navigator.appVersion.substring(0,3))>4.01)
					{
						datX =new String(datX);
						limitYear=parseInt(datX.substring(51,55))
						
					}
					else
					{
						//alert(datX);
						limitYear=datX.getYear();
						//limitYear=parseInt(datX.substring(51,55))
					}
					}
			else
			{
						limitYear=datX.getYear();
										}
  var str = year
  var len = str.length;
  if (len!=4)
  {return false}
  if (year < 1900 || year >limitYear)
  {return false}
  for(i=0;i<len;i++)
  { 
      if(!((str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57)))
		{
		return false
		}
  } 
 return  true
}
//end of checkyear function

// Checking whether name fields have anything other than characters
function checkname(name)
{  
 var flag=0;
 leave=new Array(20)
 var len=name.length
 
	if(checkname.arguments.length>2){
		for(i=0;i<checkname.arguments[2].length;i++){
			leave[i]=checkname.arguments[2].charCodeAt(i)
		}
		}
  label1:for(i=0;i<len;i++)
         { 
         if((name.charCodeAt(i)>48 && name.charCodeAt(i)<58) ||(name.charCodeAt(i)>64 && name.charCodeAt(i)<92) || (name.charCodeAt(i)>96 && name.charCodeAt(i)<123)||(name.charCodeAt(i)==32)||(name.charAt(i)=="'")||(name.charAt(i)=="."))
            {  
            if(checkname.arguments[1]=="nonumbers" && name.charCodeAt(i)>48 && name.charCodeAt(i)<58){
					flag=1
					break;
				}
            flag=0;
            }
           else
            {
            for(j=0;j<leave.length;j++){
				if(name.charCodeAt(i)==leave[j]){
							flag=0
							continue label1;					
					}
				}
	    	flag=1;
            break;
            } 
         }        
    
  if(flag==0)
    return true;
  else
    return false;      
 }
//end of checkname function

//To check for valid date entry.
//Returns true if a valid date is entered, else returns false.
function DateValidate(dtmDateValue)
{
	var strDate, intDay, intMonth, intYear, strSep1, strSep2;

	strDate=dtmDateValue;

	intDay=strDate.substr(0,2);
	strSep1=strDate.substr(2,1);	  
  
	intMonth=strDate.substr(3,2);
	strSep2=strDate.substr(5,1);	    
	intYear=strDate.substr(6,4);

	if(strSep1 != '-')	
	{
	  if(strSep1 != '/')	 
	  {
	    alert('Date is not in a valid format');
	    return 0;
	  }
	}

	if(strSep2 != '-')	
	{
	  if(strSep2 != '/')	 
	  {
	    alert('Date is not in a valid format');
	    return 0;
	  }
	}

	if(strSep1 == '-')	
	{
	  if(strSep2 == '/')				
	  {
	     alert('Date is not in a valid format');
	     return 0;
	  }
	}

	if(strSep1 == '/')	
	{
	  if(strSep2 == '-')				
	  {
	     alert('Date is not in a valid format');
	     return 0;
	  }
	}
  
	if(intDay>31 || intDay<=0)
	{
	   alert('Date is not in a valid format');
	  return false;
	}	
 
	if(intDay.length<2)
	{
	  alert('Date is not in a valid format');
	  return false;
	}	

	if(isNaN(intDay) || isNaN(intMonth) || isNaN(intYear)) 
	{
	  alert('Date is not in a valid format');
	  return false;
	}		  

    if(intMonth>12 || intMonth<=0)
    {
      alert('Date is not in a valid format');
      return false;
    }	

    if(intMonth.length<2)
    {
      alert('Date is not in a valid format');
      return false;
    }	

    if(intYear=='0000' || intYear.length<4)
    {
      alert('Date is not in a valid format');
      return false;
    }	

   switch(intMonth)
   {
    case '01':
    case '03':		
    case '05':		
    case '07':		
    case '08':		
    case '10':		
    case '12':		
 		if(intDay>31)
 		{
		   alert('Date is not in a valid format');
		   return false;
		}	
		break;

    case '02':
		if(intYear%4==0)
 		{
		  if(intDay>29)
 		  {
		     alert('Date should be less than 30');
		     return false;
		  }	
		}
		else
		{
		  if(intDay>28)
 		  {
             alert('Date should be less than 29');
		     return false;
		  }	
		}
		break;
    case '04':		
    case '06':		
    case '09':		
    case '11':		
 		if(intDay>30)
 		{
		   alert("The entered month doesn't have 31 days");
		   return false;
		}			
		break;
  } 	
	  
  return true;
}

//Purpose : To validate for alphanumeric characters on keypress event.
function AlphaNumbers()
{
 if(event.keyCode==32)
    return 1;

 if(!(event.keyCode >=48 && event.keyCode <= 57))
 {
   if(!((event.keyCode >=65 && event.keyCode <=90) || (event.keyCode >=97 && 
  	 event.keyCode <=122)))
   {
     event.keyCode=0;
     return 0
   }
 }

 if(event.keyCode==46)
    return false; 
}


//Purpose : To validate for numbers on keypress event.
function Numbers()
{
 if(event.keyCode==32)
    event.keyCode=0;

 if(!(event.keyCode >=48 && event.keyCode <= 57))
 {
     if(event.keyCode==46)
         return 1; 

     event.keyCode=0;
     return 0;
 }
}


//Purpose : To check for the numbers with decimal points.
//Inputs  : Pass the string holding the value, the decimal points required and the 
//			maximum length of the whole no.
function Decimals(strValue, intDecimal, intWholeNoMax)
{
 var intCount, intIndex, intSearchPos, strTemp;

 intCount=0;
 intSearchPos=0; 
 strTemp="";

 if(isNaN(strValue) || isNaN(intDecimal) || isNaN(intWholeNoMax))
 {
   alert("Invalid entry");
   return false;           
 }   

 for(intIndex=0; intIndex<=strValue.length; intIndex++)
 {
   if(strValue.substr(intIndex,1)=='.')
   {   
     intSearchPos=intIndex;
     intCount=intCount + 1;

     if(intCount > 1)
     {
       alert("Invalid entry");
       intCount=0;
       return false;           
     }  
   }      
 } 

 if(intSearchPos > 0)
    strTemp=strValue.substr(intSearchPos+1,strValue.length);

 if(strTemp.length > intDecimal)
 {
    strTemp="Only " + intDecimal + " digits are allowed after the decimal point";
    alert(strTemp);
    return false;
 }

 if(intSearchPos==0)
 {
	if(strValue.length > intWholeNoMax) 
    {
       alert("Can accept only " + intWholeNoMax + " for whole numbers");
       return false;           
    }
 }   
 else
 {
    if(intSearchPos > intWholeNoMax) 
    {
       alert("Can accept only " + intWholeNoMax + " for whole numbers");
       return false;           
    }
}
 
 return true; 
}

function Calendarfunc(objfrm,objfld)
{

var rdate= objfrm+'.'+objfld
window.open('/emis/includes/calendar.asp?val='+rdate,1,'scrollbars=no,status=no,toolbars=no,resizable=no,movable=no,width=240,height=183,screenX=150,screenY=150,top=270,left=300')
}

/*
if(isNaN(validate.arguments[1])) return false
if(validate.arguments[2]=="positive"){
		if(validate.arguments[2]<0) return false
}
if(validate.arguments[2]=="greaterthanzero"){
	if(validate.arguments[2]<=0) return false
}
*/

// Function to choose the combo
	function selcombvl(obj,cmbnm){
		//alert(obj.form.name)
		var slcnt=0
		//cmbobj = document.forms[0].manifestid
		cmbobj = obj.form.elements[cmbnm]
		for (i=1;i<cmbobj.length;i++)
		{
			if ((cmbobj.options[i].text.substr(0,obj.value.length).toUpperCase()== obj.value.toUpperCase())&&(obj.value.length>0)){
				cmbobj.selectedIndex=i
				slcnt++;	
				break
			}
		}
		if (slcnt==0){
			cmbobj.selectedIndex=0;
		}
	}



