//FUNCTIONS

var whitespace =" \t\n\r ";

// function for checking empty filed

function isEmpty(str)
{  
	return ((str == null) || (str.length == 0))
}

// end of function
	
// function to check the whitespace

function isWhitespace(str)
{    var i;
	 var flag

 	  
 	  if (isEmpty(str)) return true;		
 	   // Search through string's characters one by one
 	   // until we find a non-whitespace character.
 	   // When we do, return false; if we don't, return true.
 	   for (i = 0; i < str.length; i++)
 	   {   
 	       // Check that current character isn't whitespace.
 	       var c = str.charAt(i);

		   if (whitespace.indexOf(c) == -1)
		   		return false
 	   }	
 	   // All characters are whitespace.
		    return true;
}

// end of function
 
function checkMaxLength(val,maxlength)
{
	var val1
	val1 = val.length
	if (parseInt(val1)>parseInt(maxlength))
	{
		lflag=false
		return lflag;
		//return true;
	}
	else
	{
		lflag=true
		return lflag;
		//return false;
	}
}

// end of function

function checkLength(val,length)
{
	var val1
	val1 = val.length
	if (parseInt(val1) != parseInt(length))
	{
		lflag=false
		return lflag;
		//return true;
	}
	else
	{
		lflag=true
		return lflag;
		//return false;
	}
}

// end of function

// function to check all the entered values are characters only

function isAllCharacters(objValue)
{
		var characters="' -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

// function to check all the entered values are alphanumeric only

function isAlphaNumeric(objValue)
{
		var characters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

//These Blocks Are Done By Debashish Kapuria
//------------------------Begin-------------------------------

// function to check all the entered values are alphanumeric only

function isAlphaNumericWithDash(objValue)
{
		var characters="-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

// function to check all the entered values are Details/Remark Format only

function isDetails(objValue)
{
		var characters="' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.?!;:/"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

// function to check all the entered values are Report Format only

function isReports(objValue)
{
		var characters="' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.?!;:/+-"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

function isAllCharactersWithWhiteSpaceAndSpecialChar(objValue)
	{
		var characters=" -'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890øæåØÆÅ!@#$%^&*()?></.,~`"
		var tmp
		var lTag
		
		lTag = 0
		temp = objValue.length
		
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)				
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}	
		
		if(lTag == 1)
			return false
		else
			return true
	}	

// end of function

function isAllCharactersWithSpecialChar(objValue)
	{
		var characters=" -'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZøæåØÆÅ!@#$%^&*()?></.,~`"
		var tmp
		var lTag
		
		lTag = 0
		temp = objValue.length
		
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)				
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}	
		
		if(lTag == 1)
			return false
		else
			return true
	}	

// end of function
//--------------------------------End--------------------------------

// function to check all the entered values are numerics only

function isAllNumerics(objValue)
{
		var characters="0123456789."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		//alert(objValue);
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
		  if(objValue<=0)
		   {
			return false
		   }else{ 	
			return true
		  }
}
	
// end of function

// function to check all the entered values are numerics only

function isAllWithZeroNumerics(objValue)
{
		var characters="0123456789."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
	
}
	
// end of function

//-------------- email validation -------

function isValidEmail(emailStr)
{
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address. 
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			//var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var specialChars="\\(\\)<>@,`';:~!#$%^&*+=|{}?\\\\\\\"\\.\\[\\]"
			
			/* The following string represents the range of characters allowed in a 
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "sg cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. sg@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in sg.sg@somewhere.com, sg and sg are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
			  /* Too many/few @'s or something; basically, this address doesn't
			     even fit the general mould of a valid e-mail address. */
				//alert("Email address seems incorrect (check @ and .'s)")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]

			// See if "user" is valid 
			if (user.match(userPat)==null) {
			    // user is not valid
			    //alert("The username doesn't seem to be valid.")
			    return false
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
			    // this is an IP address
				  for (var i=1;i<=4;i++) {
				    if (IPArray[i]>255) {
				        //alert("Destination IP address is invalid!")
					return false
				    }
			    }
			    return true
			}

			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
			//alert("The domain name doesn't seem to be valid.")
			    return false
			}

			/* domain name seems valid, but now make sure that it ends in a
			   three-letter word (like com, edu, gov) or a two-letter word,
			   representing country (uk, nl, no), and that there's a hostname preceding 
			   the domain or country. */

			/* Now we need to break up the domain to get a count of how many atoms
			   it consists of. */
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 || 
			    domArr[domArr.length-1].length>3) {
			   // the address must end in a two letter or three letter word.
			   //alert("The address must end in a three-letter domain, or two letter country.")
			   return false
			}

			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			   //alert(errStr)
			   return false
			}

			// If we've gotten this far, everything's valid!
			return true;
}

// end of function

// function for triming

function trim(pstrString)
{
	var intLoop=0;

	for(intLoop=0; intLoop<pstrString.length; )
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(intLoop+1, pstrString.length);
		else
			break;
	}

	for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(0,intLoop);
		else
			break;
	}
	return pstrString;
}



// function for valid file to be upload
// @ param : val = value , msg = for which, typ = for which type - A = All files(.htm,.html,.jpg,.gif,.bmp,.jpeg) 
// H - .htm, .html
// I - .jpg, .jpeg, .gif, .bmp
// Att - all fileas are valid and only length is validated for 50 characters

function IsValidFile(val,msg,typ)
{
		val = trim(val)
		strlen = val.length
		strcnt = val.lastIndexOf("\\")
		newstr = val.substr(strcnt+1,strlen)
		tempval = val.toUpperCase()
		val = tempval.substr(val.lastIndexOf("."),val.length)
		var flg= 0
		var err = ""


		if( (typ=='A')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF')&&(val!='.BMP')&&(val!='.TXT'))))||(val.length>5) ))
		{
			err = "Only .gif/.jpg/.jpeg/.bmp/.html/.htm/.txt can be selected for "+msg+".<br>"
		}	
		else if( (typ=='H')&&( ( ((val.length==5)&&(val!='.HTML'))|| ((val.length==4)&&(val!='.HTM')))||(val.length>5) ))
		{
			err = "Only .html/.htm files can be selected for "+msg+".<br>"
		}
		else if( (typ=='I')&&( ( ((val.length==5)&&(val!='.JPEG'))|| ((val.length==4)&&((val!='.JPG')&&(val!='.GIF')&&(val!='.BMP'))))||(val.length>5) ))
		{
			err = "Only .gif/.jpg/.jpeg/.bmp files can be selected for "+msg+".<br>"
		}
		/*
		else if((typ=='T')&&(((val.length==4)&&(val!='.TXT'))))
		{
			err = "Only .txt file can be selected for "+msg+".<br>"
		}
		*/
		else if ( (newstr.indexOf(".") == 0)|| (val.indexOf('.') == -1) || (val.length <4) ) 
			err = "File selected for "+msg+" is invalid.<br>"
		else if(newstr.indexOf("'") != -1)
			err = "File selected for "+msg+" contains invalid character.<br>"	
		else if (newstr.length > 50)
			err = "Length of file name selected for "+msg+" must be less then or equal to 50.<br>"
	    
		return err
}	

// end of function

// this is the same function for checking the valid file extension except it returns true or false

function isInValidFile(val,msg,typ)
{
		alert(val)
		alert(msg)
		alert(typ)
		val = trim(val)
		strlen = val.length
		strcnt = val.lastIndexOf("\\")
		newstr = val.substr(strcnt+1,strlen)
		tempval = val.toUpperCase()
		val = tempval.substr(val.lastIndexOf("."),val.length)
		var flg= 0
		var err = ""
		
		if( (typ=='A')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF')&&(val!='.TXT'))))||(val.length>5) ))
		{
			return true;
		}	
		else if( (typ=='H')&&( ( ((val.length==5)&&(val!='.HTML'))|| ((val.length==4)&&(val!='.HTM')))||(val.length>5) ))
		{
			return true;
		}
		else if( (typ=='I')&&( ( ((val.length==5)&&(val!='.JPEG'))|| ((val.length==4)&&((val!='.JPG')&&(val!='.GIF'))))||(val.length>5) ))
		{
			alert("checkeree")
			
			return true;
		}
		if( (typ=='HI')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF'))))||(val.length>5) ))
		{
			return true;
		}
		/*
		else if((typ=='T')&&(((val.length==4)&&(val!='.TXT'))))
		{
			err = "Only .txt file can be selected for "+msg+".<br>"
		}
		*/
		else if((typ=='X')&&(((val.length==4)&&(val!='.XLS'))))
		{
			return true;
		}
		else if((typ=='K')&&((((val.length==3)&&((val!='.KW')))||(val.length>3))))
		{
			return true;
		}
		else if ( (newstr.indexOf(".") == 0)|| (val.indexOf('.') == -1) || (val.length <4) ) 
			return true;
		else if(newstr.indexOf("'") != -1)
			return true;
		else if (newstr.length > 50)
			return true;
	    		
}	

// end of function

//start of function
//function to check for length of username 

function isValidUserName(val)
{
strval = val
if (strval.length < 6 || strval.length > 15)
   {
   	return false
   }	
else
   {
	return true;
   }	
}			
//function Ends

//start of Function
//function to check for length of password
function isValidPassword(val)
{
strval = val
if (strval.length < 6 || strval.length > 15)
   {
   	return false
   }	
else
   {
	return true;
   }	
}			
//End Function

//start of Function
//To Check whether password and confirm password match or no 
function MatchPasswords(val1,val2)
{
strval1 = val1
strval2 = val2
if (strval1!= strval2)
   {
   	return false
   }	
else
   {
	return true;
   }	
}			
//End Function

// function to check if date is valid or not
	// @param tempDate - numeric value 
	// @param tempMonth - numeric value (Januar=0, Februar=1, ...)
	// @param tempYear - 4 digit numeric value	
	function isValidDate(tempDate, tempMonth, tempYear)
		{
		var tempNoOfDayss
			var lArrMonthDays = new Array(2)
			var dateFlag
			
			dateFlag = false
			tempNoOfDays=0
			
			lArrMonthDays[0] = new Array(12)	// number of days in a month
			lArrMonthDays[1] = new Array(12) 	// month name
						
			lArrMonthDays[0][0] = "January"
			lArrMonthDays[1][0] = "31"
			
			lArrMonthDays[0][1] = "February"
			lArrMonthDays[1][1] = "28"
			
			lArrMonthDays[0][2] = "March"
			lArrMonthDays[1][2] = "31"
			
			lArrMonthDays[0][3] = "April"
			lArrMonthDays[1][3] = "30"
			
			lArrMonthDays[0][4] = "May"
			lArrMonthDays[1][4] = "31"
			
			lArrMonthDays[0][5] = "June"
			lArrMonthDays[1][5] = "30"
			
			lArrMonthDays[0][6] = "July"
			lArrMonthDays[1][6] = "31"
			
			lArrMonthDays[0][7] = "August"
			lArrMonthDays[1][7] = "31"
			
			lArrMonthDays[0][8] = "September"
			lArrMonthDays[1][8] = "30"
			
			lArrMonthDays[0][9] = "October"
			lArrMonthDays[1][9] = "31"
			
			lArrMonthDays[0][10] = "November"
			lArrMonthDays[1][10] = "30"
			
			lArrMonthDays[0][11] = "December"
			lArrMonthDays[1][11] = "31"						
			
			if(tempMonth == 2)
			{			
				if(tempYear % 4 == 0 || tempYear % 400 == 0)
				{
					//change the days of Feb to 29 b'coz LEAP YEAR
					lArrMonthDays[1][1] = "29"							
				}
			}			
			tempNoOfDays = lArrMonthDays[1][tempMonth-1]			
			
			// if no. of days passed to function is greater than 
			// the actual days of that month then date is invalid			
			


			if(tempDate > tempNoOfDays)
			{
				dateFlag = false				
			}
			else				
			{
				dateFlag = true				
			}
			
			return dateFlag

		/*	var tempNoOfDays
			var lArrMonthDays = new Array(2)
			var dateFlag
			
			dateFlag = false
			tempNoOfDays=0
			
			lArrMonthDays[0] = new Array(12)	// number of days in a month
			lArrMonthDays[1] = new Array(12) 	// month name
						
			lArrMonthDays[0][0] = "01"
			lArrMonthDays[1][0] = "31"
			
			lArrMonthDays[0][1] = "02"
			lArrMonthDays[1][1] = "28"
			
			lArrMonthDays[0][2] = "03"
			lArrMonthDays[1][2] = "31"
			
			lArrMonthDays[0][3] = "04"
			lArrMonthDays[1][3] = "30"
			
			lArrMonthDays[0][4] = "05"
			lArrMonthDays[1][4] = "31"
			
			lArrMonthDays[0][5] = "06"
			lArrMonthDays[1][5] = "30"
			
			lArrMonthDays[0][6] = "07"
			lArrMonthDays[1][6] = "31"
			
			lArrMonthDays[0][7] = "08"
			lArrMonthDays[1][7] = "31"
			
			lArrMonthDays[0][8] = "09"
			lArrMonthDays[1][8] = "30"
			
			lArrMonthDays[0][9] = "10"
			lArrMonthDays[1][9] = "31"
			
			lArrMonthDays[0][10] = "11"
			lArrMonthDays[1][10] = "30"
			
			lArrMonthDays[0][11] = "12"
			lArrMonthDays[1][11] = "31"						
			
			if(tempMonth == 2)
			{	
				if(tempYear % 4 == 0 || tempYear % 400 == 0)
				{
					//change the days of Feb to 29 b'coz LEAP YEAR
					lArrMonthDays[1][1] = "29"							
				}
			}			
			tempNoOfDays = lArrMonthDays[1][tempMonth-1]			
			
			// if no. of days passed to function is greater than 
			// the actual days of that month then date is invalid			
			
			if(tempDate > tempNoOfDays)
			{
				dateFlag = false				
			}
			else				
			{
				dateFlag = true				
			}
			
			return dateFlag  */
		}
//End Function


// compare from date with todate
// Return  0 if todate and fromdate is same
// please check lclCurrDifference value for datediff
//second date is grater than first date
function fnDatecomp(fday,fmonth,fyear,sday,smonth,syear)
{
	var lclDtDiff;
	var lclDifference;
	lclCurrDtDiff=Date.UTC(syear,smonth,sday,0,0,0) - Date.UTC(fyear,fmonth,fday,0,0,0); 
	lclCurrDifference = lclCurrDtDiff/1000/60/60/24;
	
	if(lclCurrDifference >= 0 )
	 return true
	else
	 return false
}   




//start of Function
//To Check whether start time is less than or equal to end time
function isLessEqualTime(starthr,startmin,endhr,endmin)
{
		var start_hr
		var start_min
		var end_hr
		var end_min
		
		start_hr = starthr
		start_min = startmin
		end_hr = endhr
		end_min = endmin		
		
		if ((start_hr != "") && (end_hr != "") && (start_min != "" )&& (end_min != ""))
		{
			if ((start_hr != "") && (end_hr != ""))
			{
					
				if (start_hr > end_hr )
				{					
					return(false)
				}
				
			}	
			if (start_hr != "" && end_hr != "" && start_min != "" && end_min != "")
			{
				if (start_hr == end_hr )
				{
					if (start_min >= end_min)
					{
						return(false)
					}
				}	
			}	
					
		}
		
return (true)

}
//End of Function

//To Check whether start date is less than end date by passing dates
function isLessDate2(start_Date,end_date)
{////

var start_day , start_month , start_year , end_day, end_month , end_year
var lmonth1
var lmonth2

start_Date=start_Date.split("/");
end_date=end_date.split("/");

start_day=start_Date[0]
start_month=start_Date[1]
start_year=start_Date[2]

end_day=end_date[0]
end_month=end_date[1]
end_year=end_date[2]

	if (start_year != "" && end_year != "" && start_month != "" && end_month != "" && start_day 
	!= "" && end_day != "")
			{
				if (start_year != "" && end_year != "")
				{
						
					if (start_year > end_year )
					{
						return(false)
					}
				}
		
				if (start_year != "" && end_year != "" && start_month != "" && end_month != "")
				{
					if (start_year == end_year )
					{
						lmonth1 = start_month 
						lmonth2 = end_month 
					
						if (eval(lmonth1) == eval(lmonth2))
						{
							if (start_day > end_day )
							{
								return(false)								
							}
						}
						if (eval(lmonth1) > eval(lmonth2))
						{
							return(false)							
						}
					}	
				}		
			}
		
return(true)		
}///


//

//start of Function
//To Check whether start date is less than end date
function isLessDate(start_day , start_month , start_year , end_day, end_month , end_year)
{////
var lmonth1
var lmonth2

	if (start_year != "" && end_year != "" && start_month != "" && end_month != "" && start_day 
	!= "" && end_day != "")
			{
				if (start_year != "" && end_year != "")
				{
						
					if (start_year > end_year )
					{
						return(false)
					}
				}
		
				if (start_year != "" && end_year != "" && start_month != "" && end_month != "")
				{
					if (start_year == end_year )
					{
						lmonth1 = start_month 
						lmonth2 = end_month 
					
						if (eval(lmonth1) == eval(lmonth2))
						{
							if (start_day > end_day )
							{
								return(false)								
							}
						}
						if (eval(lmonth1) > eval(lmonth2))
						{
							return(false)							
						}
					}	
				}		
			}
		
return(true)		
}///
//End of function

//start of Function
//To Check whether start date is less than end date
function isEqualDate(start_day , start_month , start_year , end_day, end_month , end_year)
{////

	if (start_year != "" && end_year != "" && start_month != "" && end_month != "" && start_day 
	!= "" && end_day != "")
			{
				if ((start_year == end_year) && (start_month == end_month)  && (start_day == end_day))
				{
					return(true)
				}
				else 
				{
					return(false)
				}			
			}	
	
}///
//End of function
// function to check if emp number is valid

function isValidEmpNumber(objValue)
{
		var characters="PTA1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

// function to check all the entered values are alphanumeric only

function isAlphaNumeric1(objValue)
{
		var characters=" -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function

function isWholeNumerics(objValue)
{
		var characters="0123456789"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
		  if(objValue<=0)
		   {
			return false
		   }else{ 	
			return true
		  }
}


function isAlpha(objValue)
{
		var characters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var errmsg ;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   

        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }

    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var 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){
    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){
		errmsg = errmsg+ "The date format should be dd/mm/yyyy" ;
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		errmsg = errmsg + ("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		errmsg = errmsg + ("Please enter a valid day ")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		errmsg = errmsg + ("Please enter a valid 4 digit year between "+minYear+" and "+maxYear  )
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		errmsg = errmsg + ("Please enter a valid date ")
		return false
	}
return true
}


function convzero(objvalue)
{

	if(objvalue=="")
	{
	 return eval(0)
	}else{
	return eval(objvalue)
	}

}


function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
errmsg = errmsg + ("Time is not in a valid format.") ;
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23)
{
errmsg = errmsg +("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}

if  (hour > 12 && ampm != null) 
{
errmsg = errmsg +("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
errmsg = errmsg + ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
errmsg = errmsg +("Second must be between 0 and 59.");
return false;
}
return true ;
}

function TimeKeyUp(frmname) 
{
var dt=frmname
t=frmname.value
var dl=t

if (dl.length == 2)
	frmname.value  = frmname.value + ':' ;
if (dl.length == 5)
	frmname.value  = frmname.value + ':' ;

	if ((dl.length == 5) )
	{
		if (IsValidTime(dt.value)==false)
		{
			alert(" Invalid Time" )	
			//dt.value = ""
			dt.focus()
			return false
		}
		else
		{
		    return true
		}
	}		
}

function DateOnkeyUp(frmname) 
{

var dt=frmname
t=frmname.value
var dl=t

if (dl.length == 2)
	frmname.value  = frmname.value + '/' ;
if (dl.length == 5)
	frmname.value  = frmname.value + '/' ;
	
if (dl.length == 10)
	{
	
	if (isDate(dt.value)==false)
	{
		alert(" Invalid Date" )	
		dt.value = ""
		dt.focus()
		return false
	}
    return true
	}
if (dl.length>10)
	{
	 alert("Invalid Date")
	 frm =""
	 }	
}

function MonthYearOnkeyUp(frmname) 
{
	var i
	var dt=frmname
	t=frmname.value
	var dl=t

	if (dl.length == 2)
		frmname.value  = frmname.value + '/' ;
	if (dl.length == 7 || dl.length == 6)
	{

	  i=dl.indexOf("/",0)	
	  if (dl.substring(0,i)>12) 
		alert ("Enter valid month")
	} 
	else
		alert ("Enter valid month")

}

function isPhone(objValue)
{
		var characters="()[]-1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}


//function blockError(){return true;}
//	window.onerror = blockError;


function DateAdd( start, interval, number ) {
	var ndate
    // Create 3 error messages, 1 for each argument. 
    var startMsg = "Sorry the start parameter of the dateAdd function\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( start ) ;
	
    // check that the start parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    var ndate= new Date( buffer + number ) ;
    
    var nmdate= new Date(ndate)
       
    var nndate=nmdate.getDate()+"/"+(nmdate.getMonth()+1)+"/"+nmdate.getYear()
    return nndate
}

// function to check all the entered values are alphanumeric only

function isVehicle(objValue)
{
		var characters="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
	
// end of function


function fnConvDate(objValue)
{
var mdate=objValue
var arrdate=mdate.split("/")
return arrdate[1]+"/"+arrdate[0]+"/"+arrdate[2]
}
	
// end of functin



