/*
This file contains the data validation JavaScript functions
It is included in the HTML pages with forms that need these
data validation routines.
The functions in this file are

1.	IsPassportNo		-	Checks for valid Passport number
2.	IsPetitionNo		-	Checks for valid petition number
3.	IsDate				-	Checks for valid Date and date not => today's date
4.	IsEarlier			-	Checks for valid Date and date not < today's date
5.	IsLater				-	Checks for valid Date and date not > today's date
6.	DaysInMonth			-	Checks for the no of days in a given month
7.	IsNumber			-	Checks for valid Numeric Entry
8.	IsPhone				-	Checks for valid Phone Numbers
9.	IsZipcode			-	Checks for valid zipcode
10.	CheckisEmail		-	Force Entry for a particular field
11.	IsEmpty				-	Force numeric entry 
12.	IsWhitespace		-	Checks if the string contains space, tab, carriage return
13.	Trim				-	Trims a string on both sides
14.	RTrim				-	Right Trims a string  
15.	LTrim				-	Left Trims a given string
16.	BlnCheckSplChar		-	Checks for invalid entry of special characters		 
17. ForceDate			-	Checks for valid date
18. IsTimeValid			-	Checks for Valid Time.
19.`DateDiff			-	checks whether the FromDate is smaller than the ToDate.
20.	ContainsSpecialChar	-	To check for valid entry of special characters
21.	IsAlphabetsOnly		-	checks for  the invalid entry of numbers.
22.	IsAlphaNumericOnly	-	checks for the availability of alphanumeric characters alone.
23.	IsAllowed			-	checks whether the entered string consists of the valid 
							special characters
24.	IsDateDMY			-	checks for the format of the date.
25.	ChangeFormat		-	checks for a valid input date format
26.CheckAddress			-	checks for a valid input address
27.CheckName			-	checks for a valid name
*/

// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";

/*************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks in for the valid passport number entered,returns 
					true if the number is in a valid format else false.
*************************************************************************/

function IsPassportNo(strField)
	{
		for (var i = 0; i < strField.length; i++)
		if ((strField.charCodeAt(i)<48) || ((strField.charCodeAt(i)>57) && (strField.charCodeAt(i)<65)) || ((strField.charCodeAt(i)>90) && (strField.charCodeAt(i)<97)) || (strField.charCodeAt(i)>123))
			{
				return false;
			}
	return true;
	}


/*************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks in for the valid petition number entered,returns 
					true if the number is in a valis format else false.
*************************************************************************/

function IsPetitionNo(strField)
	{
		for (var i = 0; i < strField.length; i++)
		if ((strField.charCodeAt(i)!=45) && ((strField.charCodeAt(i)<48) || (strField.charCodeAt(i)>57)) && ((strField.charCodeAt(i)<65) || (strField.charCodeAt(i)>90)) && ((strField.charCodeAt(i)<97) || (strField.charCodeAt(i)>123)))
			{
				return false;
			}
		return true;
	}

/*************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Checks whether the given date is in a proper date format as	(mm/dd/yyyy) 
					This function calls the daysInMonth to get the number of days for 
					a given month & date Returns true if dteCheck is a valid date 
					else false. It checks for leap year also.
*************************************************************************/
function DateFormat(dteCheck)
{
	var intDate
	
	for(var intCtr=0;intCtr<=dteCheck.length-1;intCtr++)
		if(dteCheck.charAt(intCtr)=="-")
		dteCheck=dteCheck.replace(/\-/,"/");
		intDate=dteCheck.split("/") 
	//Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (intDate[0].length > 2 || intDate[1].length > 2 || intDate[0].length < 1 || intDate[1].length < 1 || intDate[2].length != 4 )
			return false;
		if (intDate[2]>1850 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else
			return false;

}

/*************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Checks whether the given date is valid or not and it is not equal
					to or greater than today's date
					Checks for the Following formats
					(mm/dd/yyyy) or (m/dd/yyyy) or (mm/d/yyyy) or (m/d/yyyy)
					(mm-dd-yyyy) or (m-dd-yyyy) or (mm-d-yyyy) or (m-d-yyyy)
					This function calls the daysInMonth to get the number of days for 
					a given month & date Returns true if dteCheck is a valid date 
					else false. It checks for leap year also.
*************************************************************************/
function IsDate(dteCheck) 
	{
		var intDate
		var today
		if (typeof vServerDate == 'undefined')
			{
				dtetoday = new Date();
			}
		else
			{
				if (vServerDate != "")
					{
						dtetoday = new Date(vServerDate);
					}
				else
					{
						dtetoday = new Date();
					}
			}
		for(var intCtr=0;intCtr<=dteCheck.length-1;intCtr++)
		if(dteCheck.charAt(intCtr)=="-")
		dteCheck=dteCheck.replace(/\-/,"/");
		intDate=dteCheck.split("/") 
	//Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (intDate[0].length > 2 || intDate[1].length > 2 || intDate[0].length < 1 || intDate[1].length < 1 || intDate[2].length != 4 )
			return false;
		if (eval(intDate[2])>dtetoday.getFullYear())
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0])> (dtetoday.getMonth() + 1))
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0]) == (dtetoday.getMonth() +1) && eval(intDate[1]) >= dtetoday.getDate())
			return false;
		if (intDate[2]>1850 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else
			return false;
	}
/**************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Checks whether the given date is valid & is earlier than Today's Date
					Checks for the Following formats
					(mm/dd/yyyy) or (m/dd/yyyy) or (mm/d/yyyy) or (m/d/yyyy)
					(mm-dd-yyyy) or (m-dd-yyyy) or (mm-d-yyyy) or (m-d-yyyy)
					This function calls the IsEarlier function to Check for valid date
					and then checks for date lesser than today.
					Returns true if dteCheck is lesser than today else false
****************************************************************************/
function IsEarlier(dteCheck) 
	{
		var intDate
		var today
		if (typeof vServerDate == 'undefined')
			{
				dtetoday = new Date();
			}
		else
			{
				if (vServerDate != "")
					{
						dtetoday = new Date(vServerDate);
					}
				else
					{
						dtetoday = new Date();
					}
			}

		for(var intCtr=0;intCtr<=dteCheck.length-1;intCtr++)
		if(dteCheck.charAt(intCtr)=="-")
		dteCheck=dteCheck.replace(/\-/,"/");
		intDate=dteCheck.split("/") //Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (intDate[0].length > 2 ||  intDate[1].length > 2 || intDate[0].length < 1 || intDate[1].length < 1 || intDate[2].length != 4 )
			return false;
		if (eval(intDate[2])<dtetoday.getFullYear())
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0])< (dtetoday.getMonth() + 1))
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0]) == (dtetoday.getMonth() +1) && eval(intDate[1]) < dtetoday.getDate())
			return false;
		if (intDate[2]>1850 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else
			return false;
	}
/******************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function DateDiff returns the No. of days between the 
					entered Fromdate and Todate and also
					Checks for the Following formats
					(mm/dd/yyyy) or (m/dd/yyyy) or (mm/d/yyyy) or (m/d/yyyy)
					(mm-dd-yyyy) or (m-dd-yyyy) or (mm-d-yyyy) or (m-d-yyyy)
					This function calls the DateDiff function to Check for valid dates
					and then returns true if FromDate is smaller than ToDate else returns false
					
*******************************************************************************/


function DateDiff(FromDate, ToDate) 
	{
		var intDate
		var today
		dtetoday = new Date(FromDate);
		for(var intCtr=0;intCtr<=ToDate.length-1;intCtr++)
		if(ToDate.charAt(intCtr)=="-")
		ToDate=ToDate.replace(/\-/,"/");
		intDate=ToDate.split("/") //Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (intDate[0].length > 2 || intDate[1].length > 2 || intDate[0].length < 1 || intDate[1].length < 1 || intDate[2].length != 4 )
			return false;
		if (eval(intDate[2])<dtetoday.getFullYear())
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0])< (dtetoday.getMonth() + 1))
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0]) == (dtetoday.getMonth() +1) && eval(intDate[1]) < dtetoday.getDate())
			return false;
		if (intDate[2]>1850 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else	
			return false;
	}
/*****************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Checks whether the given date is valid & is later than Today's Date
					Checks for the Following formats
					(mm/dd/yyyy) or (m/dd/yyyy) or (mm/d/yyyy) or (m/d/yyyy)
					(mm-dd-yyyy) or (m-dd-yyyy) or (mm-d-yyyy) or (m-d-yyyy)
					This function calls the IsLater function to Check for valid date
					and then checks for date greater than today.
					Returns true if dteCheck is greater than today else false
****************************************************************/
function IsLater(dteCheck)	
	{
		var intDate
		var today
		if (typeof vServerDate == 'undefined')
			{
				dtetoday = new Date();
			}
		else
			{
				if (vServerDate != "")
					{
						dtetoday = new Date(vServerDate);
					}
				else
					{
						dtetoday = new Date();
					}
			}
		for(var intCtr=0;intCtr<=dteCheck.length-1;intCtr++)
		if(dteCheck.charAt(intCtr)=="-")
		dteCheck=dteCheck.replace(/\-/,"/");
		intDate=dteCheck.split("/") //Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (eval(intDate[2])>dtetoday.getFullYear())
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0])> (dtetoday.getMonth() + 1))
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[0]) == (dtetoday.getMonth() +1) && eval(intDate[1]) > dtetoday.getDate())
			return false;
		if (intDate[2]>1850 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else
			return false;
	}


/***************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function DaysInMonth returns the No. of days for given 
					valid Month & Year. It checks for leap year also which accurs 
					in years divisible by four. If the year is a century checks it  
					is divisible by 400.
****************************************************************/
function DaysInMonth(intMon,intYr)
	{
		switch(eval(intMon))
			{
				case 2:
					if ((intYr%100)==0)
						if ((intYr%400)==0) 
							return 29;
						else
							return 28;
							else if((intYr%4)==0)
								return 29;
					else
						return 28;
				break;
				case 4:
						return 30
				break;
				case 6:
						return 30
				break;
				case 9:
						return 30
				break;
				case 11:
						return 30
				break;
				default:
						return 31;
				break;
			}
	}



/******************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Returns true if the string passed in is a valid number
					(no alpha characters), else it displays an error message
****************************************************************/

function IsNumber(objValue)
	{
		var strField = objValue;
		if (IsWhitespace(strField)) return false;
		var i = 0;
		for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') 
			{
				return false;
			}
		return true;
	}

/******************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Returns true if the string passed in is a valid phone number
					(no alpha characters), else it displays an error message
****************************************************************/
function IsPhone(phnnum)
	{
		var pos;
		if (((phnnum == 'nil') || (phnnum == 'none') || (phnnum == 'NIL') || (phnnum == 'NONE')))
			{
				return true;
			}
		for (pos=0;pos<phnnum.length;pos++)
			{
				if (phnnum.charCodeAt(pos) != 45)
					{
						if ((phnnum.charCodeAt(pos) <=47) || (phnnum.charCodeAt(pos) >=58))
						return false;
					}
				
			}
		return true;
	}


/***************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function determines if the string passed in is a valid
					Indian zip code.  It accepts  ######. If the
					string is valid, it returns true, else false.
****************************************************************/
function IsZipcode(strZip)
	{
		var s = strZip;
		if(strZip=="")
		{
		return true;
		}
		if (s.length != 6)
			{
				return false;
			}
		for (var i=0; i < s.length; i++)
		if (s.charAt(i) < '0' || s.charAt(i) > '9')
			{
				return false;
			}
		return true;
	}




/***************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Check whether string s is empty.
***************************************************************/
function IsEmpty(s)
	{   
		return ((s == null) || (s.length == 0))
	}



/*****************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Returns true if string s is empty or 
					whitespace characters only.
*****************************************************************/
function IsWhitespace (s)
	{
	   var i;
    // Is s empty?
    if (IsEmpty(s)) 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 < s.length; i++)
	    {   
	// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (whitespace.indexOf(c) == -1) 
			return false;
		}
    // All characters are whitespace.
    return true;
	}


/*************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function Trim is used to trim blank spaces in the 
					given string on both sides(right & left)
****************************************************************/

function Trim(s) 
	{
		var j='';
		var i ='';
		var first='';
		var last ='';
		var val;
		val = s;
		for(i = 0;i<val.length;i++)
			{
				if(val.charCodeAt(i)!=32)
					{
						for(j=i;j <val.length ;j++)
						first = first + val.charAt(j);
						break;
					}	
			}

		i= first.length-1;
		while(first.charCodeAt(i)==32)
		i=i-1;	
		j=0;
		for(j=0;j<i+1;j++)
		last = last + first.charAt(j);
		return last;
	}


/**************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function RTrim is used to trim blank spaces in the 
					given string on right side
****************************************************************/
function RTrim(strVal)
	{
		var j=strVal.length-1;
		while(strVal.charAt(j--)==' ');
		return strVal.substr(0,j+2);
	}


/*****************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	This function RTrim is used to trim blank spaces in the 
					given string on left side
****************************************************************/
function LTrim(strVal)
	{
		var i=0;
		while(strVal.charAt(i++)==' '); 
		alert(i);
		return strVal.substr(--i,strVal.length-i+2);
	}


/********************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	To check for invalid entry of special characters
					in the email text box
*****************************************************************/
function BlnCheckSplChar(prmStrTextField)
	{
		var strX = prmStrTextField     //strX and strY variables to check for a matching string
		var strY = (prmStrTextField.match("\[^@]+\[@]{1}\[^@]+"));
		if ((prmStrTextField.match("\[^@]+\[@]{1}\[^@]+"))==null)
			{
				return true;
			}
		else
			{
				if (strX == strY)
					{
						return false;
					}			
				else
					{
						return true;
					}
			}
	}
/*********************************************************************************

Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for a valid date
***********************************************************************************/
function ForceDate(val)
	{
		var intDate
		var today
		if (typeof vServerDate == 'undefined')
			{
				dtetoday = new Date();
			}
		else
			{
				if (vServerDate != "")
					{
						dtetoday = new Date(vServerDate);
					}
				else
					{
						dtetoday = new Date();
					}
			}
		for(var intCtr=0;intCtr<=val.length-1;intCtr++)
		if(val.charAt(intCtr)=="-")
		val=val.replace(/\-/,"/");
		intDate=val.split("/") 
	//Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the month
	// intdate[1] is the day
	// intDate[2] is the year
		if (intDate.length != 3)
		return false;
		if (intDate[0].length > 2 || intDate[0].length==0 || intDate[1].length > 2 || intDate[1].length==0 )
			return false;
		if (intDate[2].length != 4)
			return false;
		if (intDate[2]>1950 && intDate[0]>=1 && intDate[0]<=12 && intDate[1]>=1 && intDate[1]<=DaysInMonth(intDate[0],intDate[2]))
			return true;
		else
			return false;
	}
/*******************************************************************************

Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	Force Entry for a particular field
********************************************************************************/

function CheckIsmail(obj)
	{
		var locAt=0;
		var locDot=0;
		var flagAt=0;
		var flagDot=0;
		var cntAt=0;
		var cntDot=0;
		var defaultval=obj.toLowerCase();
		if (((defaultval == 'nil') || (defaultval == 'none')|| (defaultval == 'NIL')|| (defaultval == 'NONE')))
			{
				return true;
			}
		for (i=0;i<obj.length;i++)
			{
				s =  obj.charCodeAt(i)
				if (i==0 || i==obj.length-1)
					{
						if ((s ==45) || (s==95))
							{
								return false;
							} 
					}
			   cndt=(s >=48 && s <= 57) || (s>=65 && s<=90) || (s>=97 && s<=122) || (s==64) || (s==46) || (s==95) || (s==45)
				if (!(cndt))
					{
						return false;
					}
				s1=obj.substr(i,1)
				if (s1=='@')
					{
						cntAt=cntAt+1
						locAt=i
					}
				if (s1=='.')
					{
						cntDot=cntDot+1
						locDot=i
					}
   				if (cntAt >1)
					{
						return false;
					}        
			}
		s2=obj.charCodeAt(locAt+1)
		s3=obj.charCodeAt(locAt-1)
		s=s2
		cndtBef=(s >= 48 && s <= 57) || (s>=65 && s<=90) || (s>=97 && s<=122) 
		s=s3
		cndtAft=(s >= 48 && s <= 57) || (s>=65 && s<=90) || (s>=97 && s<=122) 
		if (cndtBef && cndtAft)
			{
				flagAt=1
			}
		s2=obj.charCodeAt(locDot+1)
		s3=obj.charCodeAt(locDot-1)
		s=s2
		cndtBef=(s >= 48 && s <= 57) || (s>=65 && s<=90) || (s>=97 && s<=122) 
		s=s3
		cndtAft=(s >= 48 && s <= 57) || (s>=65 && s<=90) || (s>=97 && s<=122) 
		if (cndtBef && cndtAft)
			{
				flagDot=1 
			}
	  
		if (flagAt==1 && flagDot==1)
			{
				return true;
			}
		else
			{
				return false;
			}		
	} 
 
 /******************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	To check for valid entry of special characters
					in the email text box
 
 *******************************************************************************/
 function ContainsSpecialChar(strVal)
	{
		var pos;
		for (pos=0;pos<strVal.length;pos++)
			{
				if(strVal.charCodeAt(pos)==60 ||strVal.charCodeAt(pos)==62 ||strVal.charCodeAt(pos)==34 || strVal.charCodeAt(pos)>127)
					return true;
			}
		return false;
	}
/*******************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for  the invalid entry of numbers.

*******************************************************************************/
function IsAlphabetsOnly(strVal)
	{
		var pos;
		for (pos=0;pos<strVal.length;pos++)
			{
				if (strVal.charCodeAt(pos) != 32)
					{
						if ((strVal.charCodeAt(pos) > 90 && strVal.charCodeAt(pos) < 97) || strVal.charCodeAt(pos)< 65 || strVal.charCodeAt(pos)> 122)
							return false;
					}
			}
		return true;
	}

/********************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for the availability of alphanumeric characters alone.
**********************************************************************************/
function IsAlphaNumericOnly(strVal)
	{
		var pos;
		for (pos=0;pos<strVal.length;pos++)
			{
				if ((strVal.charCodeAt(pos) != 32)&&(strVal.charCodeAt(pos) != 45))
					{
						if ((strVal.charCodeAt(pos) > 90 && strVal.charCodeAt(pos) < 97) || (strVal.charCodeAt(pos) > 57 && strVal.charCodeAt(pos) < 65) || strVal.charCodeAt(pos)< 48 || strVal.charCodeAt(pos)> 122)
							return false;
					}
			}
			return true;
	}

function isAlphaNumeric(strVal)
	{
		var pos;
		for (pos=0;pos<strVal.length;pos++)
			{
				if (strVal.charCodeAt(pos) != 32)
					{
						if ((strVal.charCodeAt(pos) > 90 && strVal.charCodeAt(pos) < 97) || (strVal.charCodeAt(pos) > 57 && strVal.charCodeAt(pos) < 65) || strVal.charCodeAt(pos)< 48 || strVal.charCodeAt(pos)> 122)
						return false;
					}
			}
		return true;
	}


/**********************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks whether the entered string consists of the valid 
					special characters

***************************************************************************************/
function IsAllowed(strVal)
	{
		var pos;
		for (pos=0;pos<strVal.length;pos++)
			{
				if (strVal.charCodeAt(pos) != 38 && strVal.charCodeAt(pos) != 39 && strVal.charCodeAt(pos) != 32)
					{
						if ((strVal.charCodeAt(pos) > 90 && strVal.charCodeAt(pos) < 97) || (strVal.charCodeAt(pos) > 57 && strVal.charCodeAt(pos) < 65) || strVal.charCodeAt(pos)< 48 || strVal.charCodeAt(pos)> 122)
							return false;
					}
			}
		return true;
	}


/****************************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for the format of the date 

********************************************************************************/
function IsDateDMY(dteCheck) 
	{
		var intDate
		var today
		if (typeof vServerDate == 'undefined')
			{
				dtetoday = new Date();
			}
		else
			{
				if (vServerDate != "")
					{
						dtetoday = new Date(vServerDate);
					}
				else
					{
						dtetoday = new Date();
					}
			}

		for(var intCtr=0;intCtr<=dteCheck.length-1;intCtr++)
		if(dteCheck.charAt(intCtr)=="-")
		dteCheck=dteCheck.replace(/\-/,"/");
		intDate=dteCheck.split("/") //Splits the given date as day,month,year & stores in intDate array
	//After dteCheck is split it stores in intDate as 
	// intDate[0] is the day
	// intdate[1] is the month
	// intDate[2] is the year
		if (intDate.length != 3)
			return false;
		if (intDate[1].length > 2 || intDate[0].length > 2 || intDate[1].length < 1 || intDate[0].length < 1 || intDate[2].length != 4 )
			return false;
		if (eval(intDate[2])>dtetoday.getFullYear())
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[1])> (dtetoday.getMonth() + 1))
			return false;
		if (eval(intDate[2])==dtetoday.getFullYear() && eval(intDate[1]) == (dtetoday.getMonth() +1) && eval(intDate[0]) >= dtetoday.getDate())
			return false;
		if (intDate[2]>1850 && intDate[1]>=1 && intDate[1]<=12 && intDate[0]>=1 && intDate[0]<=DaysInMonth(intDate[1],intDate[2]))
			return true;
		else
			return false;
	}

/*******************************************************************************

Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for a valid input date format and assigns the date
					in mm/dd/yyy format


************************************************************************************/

function ChangeFormat(InputDate)
	{
		var OutputDate;
		var dteDate;
		for(var intCtr=0;intCtr<=InputDate.length-1;intCtr++)
		if(InputDate.charAt(intCtr)=="-")
		InputDate=InputDate.replace(/\-/,"/");
		dteDate=InputDate.split("/"); //Splits the given date as day,month,year & stores in intDate array
	//After InputDate is split it stores in intDate as 
	// dteDate[0] is the day
	// dtedate[1] is the month
	// dteDate[2] is the year
		OutputDate = dteDate[1] + '/' + dteDate[0] + '/' + dteDate[2];
		return OutputDate;
	}

/*********************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for a valid input time format.



*************************************************************************/

function IsTimeValid(strTime)
	{
		if(strTime.value.length!=5)
		return false;
		for (i = 0; i < strTime.value.length; i++)
			{
				if(i!=2)
					{
						if (strTime.value.charAt(i) < '0' || strTime.value.charAt(i) > '9')
							return false;
					}	
				else if(i==2)
					{
						if (strTime.value.charAt(i)!=':') 
						return false;
					}	
			}	
				
		/*startArr=strTime.value.split(":")
		if ((startArr[0]>23) || (startArr[1]>59))
			return false;*/
	}


//function for time validity


/*********************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for a valid address format.

*************************************************************************/
function CheckAddress(val)
	{
		var b;
		for (b=0;b<val.length;b++)
			{
			if(b>=0)
			{
			  if (!((val.charCodeAt(b)== 39) ||
				 (val.charCodeAt(b)== 45) || 
				 (val.charCodeAt(b)== 46) || 
				 (val.charCodeAt(b)== 36) ||
				 (val.charCodeAt(b) > 47 && val.charCodeAt(b) < 58) || 
				 (val.charCodeAt(b) > 64 && val.charCodeAt(b) < 91) || 
				 (val.charCodeAt(b) > 96 && val.charCodeAt(b) < 123)|| 
				 (val.charCodeAt(b)== 32)))
					{
					
						 return false;
					}
					if (val.charCodeAt(b)==44)
					{
					return false;
					}
				}
					
			}
			return true;							
	 }
/*********************************************************************
Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	checks for a valid name.

*************************************************************************/						
function PtnRcptNo(val)					
	{				
		var i;
		for (i = 0; i < val.length; i++)
			{					
				if (!((val.charCodeAt(i) > 47 && val.charCodeAt(i) < 58) || 
					(val.charCodeAt(i) > 64 && val.charCodeAt(i) < 91) || 
					(val.charCodeAt(i)== 45)))
					{						
						return false;
					}
					return true;
			}
	}
	
/******************************************************************************************

Create History
Name			:	Sunil Bharath
Created Date	:	13/06/2006
Logic Summary	:	prevents the user from copying the datas and pasting it.
					

*******************************************************************************************/

function blockPasteOper()
	{
		 window.clipboardData.clearData()
	}
	
	
	function fnMessage(obj)
					{
					
					if (obj.parentElement.parentElement.childNodes[1].innerText == "Active ")
					{
								var st = window.confirm("De-Activating... Are you sure? ")
								if (st)
								
									return true
								else
								alert("Not DeActivated");
									return false
					}
					else if (obj.parentElement.parentElement.childNodes[1].innerText == "Inactive ")
					
					{
								var st = window.confirm("Activating... Are you sure? ")
								if (st)
								
									return true
								else
								alert("Not Activated");
									return false
					}
					
					
				}
	//function for validating sevis id
	
	function IsSevisId(val)			
	{		
		if(val.length!=11)
			{
				return false;
			}
		for(i=0;i<val.length;i++)
			{
				if (i==0)
					{
						if (val.charAt(i)!='N' && val.charAt(i)!='n')
							{
								return false;
							}
					}
				if(i>=1)
					{
						if (val.charAt(i) < '0' || val.charAt(i) > '9')
							{
								return false;
							}
					}
			}
		return true;
	}

function IsAmount(objValue)
	{
		var strField = objValue;
		if (IsWhitespace(strField)) return false;
		var i = 0;
		for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') 
			{
								
				return false;
				
			}
		return true;
	}
	
	
function IsTimeValid1(strTime)
	{
		if(strTime.length!=5)
		return false;
		for (i = 0; i < strTime.length; i++)
			{
				if(i==0)
					{
						if (strTime.charAt(i) < '0' || strTime.charAt(i) > '2')
						return false;
					}
				if(i!=2)
					{
						if (strTime.charAt(i) < '0' || strTime.charAt(i) > '9')
						return false;
					
					}	
				else if(i==2)
					{
						if (strTime.charAt(i)!=':') 
						return false;
				
					}
				if((strTime.charAt(0)==2 && strTime.charAt(1)>'3') ||(strTime.charAt(0)==2 && strTime.charAt(3)>'5'))
					{
						return false;
					}
					return true;
			}	
			
		
	}


function checkequality(starttime,endtime)
	{
		if((starttime.charAt(3)==endtime.charAt(3))&&(starttime.charAt(4)==endtime.charAt(4))&&(starttime.charAt(0)==endtime.charAt(0))&&(starttime.charAt(1)==endtime.charAt(1)))
			{
				return false;
			}
		return true;
	}
//function for time validity

function timevalid(starttime,endtime)
	{
		if((starttime.charAt(0)==endtime.charAt(0)) && (starttime.charAt(1)>endtime.charAt(1)))
			{
				return false;
			}
		if((starttime.charAt(3)>endtime.charAt(3)) || (starttime.charAt(4)>endtime.charAt(4)))
			{
				return false;
			}
		return true;
	}

function ChkArrivalDate(ToDate)
	{
				var intDate
		var today
		dtetoday = new Date();
		for(var intCtr=0;intCtr<=ToDate.length-1;intCtr++)
		if(ToDate.charAt(intCtr)=="-")
		ToDate=ToDate.replace(/\-/,"/");
		intDate=ToDate.split("/")
		var ddate=DaysInMonth(dtetoday.getMonth()+1,dtetoday.getFullYear())
		var enddate=ddate-dtetoday.getDate()
		if(enddate<12)
			{
				var cdate=42-enddate
				var nextdate=DaysInMonth(dtetoday.getMonth() + 2,dtetoday.getFullYear())
				if(cdate>=nextdate)
					{	
					if(eval(intDate[1])>=(cdate-nextdate) && eval(intDate[0]) < (dtetoday.getMonth() + 3) && eval(intDate[2])<=dtetoday.getFullYear())
							{
								return false;
							}
											
						if(eval(intDate[1])<=(cdate-nextdate) && eval(intDate[0]) < (dtetoday.getMonth() + 3) && eval(intDate[2])<=dtetoday.getFullYear())
							{
								return false;
							}
							
						else
							{
								return true;
							}	
					}
			}
		else
			{
				var cdate=42-enddate
				if(eval(intDate[1])<=cdate && eval(intDate[0]) <= (dtetoday.getMonth() + 2) && eval(intDate[2])<=dtetoday.getFullYear())
					{
						return false;
					}
				
				else
					{
						return true;
					}
			}
	}
function displayPaymentMode()
			{
				
				payMode = document.forms[0].cboPayment.options[document.forms[0].cboPayment.selectedIndex].value
				if (payMode == "C")
				{
					document.getElementById("divPayCash").style.display="block";
					document.getElementById("divPayDraft").style.display="none";
				}	
				else
				{
					document.getElementById("divPayCash").style.display="none";
					document.getElementById("divPayDraft").style.display="block";
					
				}
						
			}
			function serviceOption()
			{
				
				servOption = document.forms[0].cboService.options[document.forms[0].cboService.selectedIndex].value
				if (servOption == "2")				{
					
					document.getElementById("divotherservice").style.display="block";
				}	
				else
				{					
					document.getElementById("divotherservice").style.display="none";					
				}
						
			}
			
			function checkOtherServices()
			{
				val = Trim(window.document.frmOtherServices.txtFirstName.value);
				if (val == "")
				{
					alert("First Name field cannot be left blank. Please Enter the First Name");
					window.document.frmOtherServices.txtFirstName.focus();
					return false;
				}
				if (!IsAlphabetsOnly(val))
				{
					alert("First Name can contain only characters and spaces");
					window.document.frmOtherServices.txtFirstName.focus();
					window.document.frmOtherServices.txtFirstName.select();		
					return false;
				}				
				window.document.frmOtherServices.txtFirstName.value = val;
				
				val = Trim(window.document.frmOtherServices.txtLastName.value);
				if (val == "")
				{
					alert("Last Name field cannot be left blank. Please Enter the Last Name");
					window.document.frmOtherServices.txtLastName.focus();
					return false;
				}
				if (!IsAlphabetsOnly(val))
				{
					alert("Last Name can contain only characters and spaces");
					window.document.frmOtherServices.txtLastName.focus();
					window.document.frmOtherServices.txtLastName.select();		
					return false;
				}				
				window.document.frmOtherServices.txtLastName.value = val;
				
				val=Trim(window.document.frmOtherServices.txtPassportNumber.value);
				if (val == "") 
				{
					alert("Passport Number field cannot be left blank.Please Enter the Passport Number");
					document.frmOtherServices.txtPassportNumber.value = "";
					document.frmOtherServices.txtPassportNumber.focus();
					return false;
				}		
				
				val = Trim(window.document.frmOtherServices.txtEmail.value);
				if (val != "")
				{
					if (!CheckIsmail(val))
					{
						alert("Please check the E-Mail Address entered. For Example : Someone@microsoft.com");
						window.document.frmOtherServices.txtEmail.focus();
						window.document.frmOtherServices.txtEmail.select();
						return false;
					}
				}
				window.document.frmOtherServices.txtEmail.value = val;		
				
				val = Trim(window.document.frmOtherServices.txtTelephoneNumber.value);				
				if (!(val == ""))
				{
					if (!(IsPhone(val)))
						{
							alert ("Please enter a valid Phone No.");
							window.document.frmOtherServices.txtTelephoneNumber.focus();
							window.document.frmOtherServices.txtTelephoneNumber.select();
							return false;
						}
				}
				window.document.frmOtherServices.txtTelephoneNumber.value = val;
				
				payMode = document.forms[0].cboPayment.options[document.forms[0].cboPayment.selectedIndex].value
				if (payMode == "D")
				{	
				 val = Trim(window.document.frmOtherServices.txtDraftNo.value);
				 if (val == "")
				 {
					alert("Please Enter Draft No");
					window.document.frmOtherServices.txtDraftNo.focus();
					return false;
				 }
				 if (ContainsSpecialChar(val))
				 {
					alert('Draft No cannot contain <,> and "');
					window.document.frmOtherServices.txtDraftNo.focus();
					window.document.frmOtherServices.txtDraftNo.select();		
					return false;
				 }
				
				 val = Trim(window.document.frmOtherServices.txtBankName.value);
				 if (val == "")
				 {
					alert("Please Enter Bank Name");
					window.document.frmOtherServices.txtBankName.focus();
					return false;
				 }
				 if (ContainsSpecialChar(val))
				 {
					alert('Draft No cannot contain special characters like <,> and "');
					window.document.frmOtherServices.txtBankName.focus();
					window.document.frmOtherServices.txtBankName.select();		
					return false;
				 }
				
				 val = Trim(window.document.frmOtherServices.txtDDDate.value);
				 if (val == "")
				 {
					alert("Please Enter DD Date");
					window.document.frmOtherServices.txtDDDate.focus();
					return false;
				 }
				 if (!ForceDate(Trim(document.frmOtherServices.txtDDDate.value)))
				 {
					alert("Please Enter date in specified format");
					document.frmOtherServices.txtDDDate.focus();
					return false;
				 }
				 
				 if(!IsLater(Trim(document.frmOtherServices.txtDDDate.value)) == true)
				{
				alert("Enter valid date (Cannot be greater than the Current Date)");
				document.frmOtherServices.txtDDDate.select()
				return false;					
				}
				 
				 var dtTodayDate,dtDDDate,dtDiff,timeDiff,days
				dtTodayDate=new Date(document.frmOtherServices.hidCurrDate.value)
				dtDDDate=new Date(document.frmOtherServices.txtDDDate.value)
				dtDiff=new Date()
				timeDiff=Math.abs(dtTodayDate.getTime()-dtDDDate.getTime())
				days=Math.floor(timeDiff/(1000 * 60 * 60 * 24))
				if (days>170)
				{
				alert("Please Check the DD Date You have Entered.")
				document.frmOtherServices.txtDDDate.focus();
				return false;
				}
				
				
				
			
				 val = Trim(window.document.frmOtherServices.txtAmount.value);
				 if (val == "")
				 {
					alert("Please Enter Draft Amount");
					window.document.frmOtherServices.txtAmount.focus();
					return false;
				 }
				 if (!(val == ""))
				 {
					if (val<0)
						{
							alert ("Please enter a valid Draft Amount");
							window.document.frmOtherServices.txtAmount.focus();
							window.document.frmOtherServices.txtAmount.select();
							return false;
						}
					if (!(IsNumber(val)))
						{
							alert ("Please enter a valid Draft Amount");
							window.document.frmOtherServices.txtAmount.focus();
							window.document.frmOtherServices.txtAmount.select();
							return false;
						}
				 }
				}
				if (payMode == "C")
				{
				  val = Trim(window.document.frmOtherServices.txtcashamount.value);
				  if (val == "")
				  {
					alert("Please Enter Cash Amount");
					window.document.frmOtherServices.txtcashamount.focus();
					return false;
				  }
				  if (!(val == ""))
				  {
					if (val<0)
						{
							alert ("Please enter a valid  Amount");
							window.document.frmOtherServices.txtcashamount.focus();
							window.document.frmOtherServices.txtcashamount.select();
							return false;
						}
					 if (!(IsNumber(val)))
						{
							alert ("Please enter a valid  Amount");
							window.document.frmOtherServices.txtcashamount.focus();
							window.document.frmOtherServices.txtcashamount.select();
							return false;
						}
				  }
				}
			}