// Author : Sai/Kiran
// This File contains all the validations for the asp files
// naming conventions has to be used to use this file
// This function check the type of the form field and uses respective logic to check whther it is empty
//Flash Checking is Done From Here

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var UserName
var Password
var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;


var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;


var isWin = ( navigator.userAgent.indexOf('Windows') != -1 );

var flashEnabled = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;


var cnstADDMODE = 1;
var cnstEDITMODE = 2;
var cnstDELETEMODE = 3;

/* The handle of the calendar & customize screen */
var vWinCal = 0;
var bWinOpen = new Boolean();
var m_oCustomScreen = 0;
var m_hwnd = 0;

// This Code Is For Handling Table Row Mouse Over
var clickElement='',initColor='#ffffff',rollOverColor="#DFE3D5";

function changeColor(source,restore,clickEvent)
{
	var ns6=document.getElementById&&!document.all
	var ie=document.all
	
	
	if(clickEvent && clickElement=='')
		return;
	
	if(clickElement==source && !clickEvent)
		return;
	
	
			
	if(restore)
	{
		source.style.backgroundColor=initColor
		source.style.cursor="default"
	}	
	else
	{	
		source.style.backgroundColor=rollOverColor
		source.style.cursor=ie? "hand" : "pointer"
	}	
	
}

function restoreRow()
{
	changeColor(clickElement,true,true);
	clickElement='';
}

function handleRowClick(source)
{
	restoreRow();
	clickElement=source;
}





// End Of Code For Handling Table Row Mouse Over





function isValidCurrency(f)

{

	var nNum = 0;			// Total numbers for currency value.

	var nDollarSign = 0;	// Total times a dollar sign occurs.

	var nDecimal = 0;		// Total times a decimal point occurs.

	var nCommas = 0;		// Total times a comma occurs.

	var txtLen;				// Length of string passed.

	var xTxt;				// Assigned object passed.

	var sDollarVal;			// Assigned dollar amount with or without commas.

	var bComma;				

	var decPos;				// Assigned value of numbers or positions after decimal point.

	var nNumCount = 0;		// Total number between commas.

	var i;					// For forloop indexing.

	var x;					// Assigned each indivual character in string.

	

	// Set the xTxt variable to the object passed to this function.

	// Assign the length of the string to txtLen.

	xTxt = f;

	txtLen = xTxt.value.length



	for(i = 0; i < txtLen; i++)

	{

		// Assign charater in substring to x.

		x = xTxt.value.substr(i, 1);

		

		

		if(x == "$")

			nDollarSign = nDollarSign + 1; // Sum total times dollar sign occurs.

		else if(x == ".")

			nDecimal = nDecimal + 1; // Sum total times decimal point occurs.

		else if(x == ",")

			nCommas = nCommas + 1; // Sum total times comma occurs.

		else if(parseInt(x) >= 0 || parseInt(x) <= 9)

			nNum = nNum + 1; // If the character is a number sum total times a number occurs.

		else

		{

			// Error occurs if any other character value is in the string

			// othere then the valid characters.

			alert("ERROR! \n\nYou have entered an illegal value!\nPlease enter only: Dollar" +

				  " Signs, Commas, Decimal Points, and numbers between 0...9!");

			return false;

		} // end else

	} // end for



	if(nDollarSign > 1)

	{

		alert("ERROR! \n\nYou have entered more then one dollar sign!\nPlease only enter one!");

		return false;

	} // end if

		

	if(nDecimal > 1)

	{

		alert("ERROR! \n\nYou have entered more then one decimal point!\nPlease only enter one!");

		return false;

	} // end if

		

	if(nDollarSign == 1)

	{

		// Make sure dollar sign in the first character in string

		// if there is a dollar sign present.

		if(xTxt.value.indexOf("$") != 0)

		{

			alert("ERROR!  \n\nThe dollar sign you entered is not in the correct position!");

			return false;

		} // end if

	}// end if

	

	if(nDecimal == 1)

	{

		// Get the number of numbers after the decimal point in

		// the string if there is a decimal point present

		decPos = (txtLen - 1) - xTxt.value.indexOf(".");

		

		// Floating point cannot be more then two.

		// Valid format after decimal point.

		/**********************************/

		/*   $#.##, $#.#, $.#, $#., $.##  */

		/**********************************/

		if(decPos > 2)

		{

			alert("ERROR! \n\nThe decimal point you entered is not in the correct position!");

			return false;

		} // end if

	} // end if

	

	if(nCommas == 0)

	{

		// If no commas are present value is a valid US

		// currency.

		return true;

	}

	else

	{

		// Get total number of dollar number(s), removing

		// floating point numbers or cents.

		nNum = nNum - decPos;

		

		// Determine if dollar sign is in string so to be 

		// removed.

		// After determining dollar sign, assign sDollarVal

		// numbers and comma(s)

		if(xTxt.value.indexOf("$", 0) == 0)

			sDollarVal = xTxt.value.substr(1, (nNum + nCommas));

		else

			sDollarVal = xTxt.value.substr(0, (nNum + nCommas));

		

		

		// Determine if a zero is the first number or if a

		// comma is the first or last character in the string.

		if(sDollarVal.lastIndexOf("0", 0) == 0 )

		{

			alert("ERROR! \n\nYou cannot start the dollar amount out with a zero!");

			return false;

		}

		else if(sDollarVal.lastIndexOf(",", 0) == 0)

		{

			alert("ERROR! \n\nYou cannot start the dollar amount out with a comma!");

			return false;

		}

		else if(sDollarVal.indexOf(",", (sDollarVal.length - 1)) == (sDollarVal.length - 1))

		{

			alert("ERROR! \n\nYou cannot end the dollar amount with a comma!");

			return false;

		}

		else

		{

			// Initialize bComma indicating a comma has not been

			// occured yet.

			bComma = false;

			for(i = 0; i < sDollarVal.length; i++)

			{

				// Assign charater in substring to x.

				x = sDollarVal.substr(i, 1);

				

				if(parseInt(x) >= 0 || parseInt(x) <= 9)

				{

					// If x is a number add one to the number counter.

					nNumCount = nNumCount + 1;

					

					// Sense comma(s) are present number counter cannot

					// be more then three before the first or next comma.

					if(nNumCount > 3)

					{

						alert("ERROR! \n\nYou have a mis-placed comma!");

						return false;

					} // end if

				}

				else

				{

					// If the number counter is less then three and

					// the comma indicator is true the comma is either

					// mis-placed or there are not enough values.

					if(nNumCount != 3 && bComma)

					{

						alert("ERROR! \n\nYou have a mis-placed comma!");

						return false;

					} // end if

					

					// Reset the number counter back to zero.

					nNumCount = 0;

					

					// Set the comma indicator to true indicating

					// that the first comma has been found and that

					// there now MUST be three numbers after each

					// comma until the loop hits the end.

					bComma = true;

				} // end if

			} // end for

			

			// Determine if after the loop ended that there

			// was a total of three final numbers after the

			// last comma.

			if(nNumCount != 3 && bComma)

			{

				alert("ERROR! \n\nYou have a mis-placed comma!");

				return false;

			} // end if

		} // end if

	} // end if

	

	// Return true indicating that the value is a valid

	// currency.

	return true;

}




function isValidSSN(f)

{

	var nNum = 0;			// Total numbers for currency value.

	var nDollarSign = 0;	// Total times a dollar sign occurs.

	var nDecimal = 0;		// Total times a decimal point occurs.

	var nCommas = 0;		// Total times a comma occurs.

	var txtLen;				// Length of string passed.

	var xTxt;				// Assigned object passed.

	var sDollarVal;			// Assigned dollar amount with or without commas.

	var bComma;				

	var decPos;				// Assigned value of numbers or positions after decimal point.

	var nNumCount = 0;		// Total number between commas.

	var i;					// For forloop indexing.

	var x;					// Assigned each indivual character in string.

	

	// Set the xTxt variable to the object passed to this function.

	// Assign the length of the string to txtLen.

	xTxt = f;

	txtLen = xTxt.value.length

	if(txtLen<8 && txtLen>0)
	{
		alert("ERROR! \n\nSSN will be minimum 8 digits")
		return false;
	}

	for(i = 0; i < txtLen; i++)

	{

		// Assign charater in substring to x.

		x = xTxt.value.substr(i, 1);

		if(x == "$")

			nDollarSign = nDollarSign + 1; // Sum total times dollar sign occurs.

		else if(x == ".")

			nDecimal = nDecimal + 1; // Sum total times decimal point occurs.

		else if(x == ",")

			nCommas = nCommas + 1; // Sum total times comma occurs.

		else if(parseInt(x) >= 0 || parseInt(x) <= 9)

			nNum = nNum + 1; // If the character is a number sum total times a number occurs.

		else

		{

			// Error occurs if any other character value is in the string

			// othere then the valid characters.

			alert("ERROR! \n\nYou have entered an illegal value!\nPlease enter only: Dollar" +

				  " Signs, Commas, Decimal Points, and numbers between 0...9!");

			return false;

		} // end else

	} // end for





	if(nDecimal > 0)

	{

		alert("ERROR! \n\nYou have entered a decimal point!\nSSN does not contain Decimal Points!");

		return false;

	} // end if

		

	

	

	// Return true indicating that the value is a valid

	//  Valid SSN.

	return true;

}













// Handle all the the FSCommand messages in a Flash movie
function pensionEZ12_Aug_DoFSCommand(command, args) {
  var pensionEZ12_AugObj = InternetExplorer ? pensionEZ12_Aug : document.pensionEZ12_Aug;
  //

  
	UserName = command;
	Password = args;


	if (UserName== 'allowscale' || UserName=='showmenu')
	{
		return false;
	}

	if(UserName == '')
	{
		alert('Please enter user name');
		return false;
	}
	if (Password == '')
	{
		 alert('Plese enter Password ');
		 return false;
	}		 
	document.Mainform.UserName_req.value=UserName;
	document.Mainform.PasWord_req.value=Password;
	document.Mainform.method="post"
	document.Mainform.action="Mainmenu.asp"
	document.Mainform.submit()

// Place your code here...
//
}
// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub pensionEZ12_Aug_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call pensionEZ12_Aug_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}



if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');  // Must break up tag so it doesn't break our script
	document.write('on error resume next \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');	
	document.write('</SCR' + 'IPT\> \n'); 		// Must break up tag so it doesn't break our script
}

if( navigator.plugins && (navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]) ) {
	var flashName = navigator.plugins["Shockwave Flash 2.0"] ? "Shockwave Flash 2.0" : "Shockwave Flash";
	var flashDesc = navigator.plugins[flashName].description;
	var flashVersion = parseInt(flashDesc.charAt(flashDesc.indexOf(".")-1));
	flash4Installed = flashVersion == 4 || flashVersion == 5;
	flash5Installed = flashVersion == 5;
	flash6Installed = flashVersion == 6;
}

flashEnabled =  flash5Installed || flash6Installed ? true : flashEnabled;

var ie=document.all;
var ns=document.layers;
var ns6=document.getElementById&&!document.all;


var reqErrorMessage;

function ValidateEmptyField(FieldName)
{ 
   	  switch(FieldName.type)
       {
         case "text":
            if(IsEmpty(FieldName))
               return false;
		    break;
         case "file":
            if(IsEmpty(FieldName))
               return false;
		    break;    
 	     case "textarea":
            if(IsEmpty(FieldName))
		       return false;
	        break;   
	     case "password":
	        if(IsEmpty(FieldName))
		       return false;
			break;   
		 case "select-one":
		    if(IsSelect(FieldName))
		    {
		       return false;  
		       } 
	        break;
		case "select-multiple":
		  
		    if(IsMultipleSelect(FieldName))
		    { 
			   //alert("Please Select From The List");
		       return false;  
		       } 

	        break;	
       }
             
	return true;
}


// This function is used to validate email address

function ValidateEmail(FieldName)
{ 

if(FieldName.value.length!=0)
   if((FieldName.value.indexOf("@")!=-1) && (FieldName.value.indexOf(".")!=-1))
       return true; 
   
   else
       
   return false;
   
}

// This is function validate a numerica value in a form field which is passed as parameter

function ValidatePositiveNumeric(FieldName)
{ 

if(FieldName.value.length!=0)
{
   if(isNaN(FieldName.value)==false)
   {
     if(parseInt(FieldName.value)>0)
	  return true; 
	 else return false; 
	}	  
   else    
   return false;
}  

}

// This is function validate a numerica value in a form field which is passed as parameter

function ValidateNumeric(FieldName)
{ 

if(FieldName.value.length!=0)
{
   if(isNaN(FieldName.value)==false)
   {
     if(parseInt(FieldName.value)>=0)
	  return true; 
	 else return false; 
	}	  
   else    
   return false;
}  

}

// This is function validate a Retype password option like same password is entered in both the text boxes
// This is used in reenter password option

function ValidateReTypePassWord(FieldName1,FieldName2)
{ 

if(FieldName1.value==FieldName2.value)
       return true; 
else    
   return false;


}

// This Function validates date whether entered data is valid or not

function ValidateDate()
{   
	var Datestr = new Array();
	
	if(arguments.length == 3) 
	{
	
		var MonthName,DayName,yearname;
		MonthName = arguments[0];
		DayName = arguments[1];
		yearname = arguments[2];
		
		if((yearname.options[yearname.selectedIndex].value%4)==0 || (yearname.options[yearname.selectedIndex].value)==0)
			Datestr = [31,29,31,30,31,30,31,31,30,31,30,31,30,31];
		else
			Datestr = [31,28,31,30,31,30,31,31,30,31,30,31,30,31];
			
		if(DayName.options[DayName.selectedIndex].value > Datestr[MonthName.options[MonthName.selectedIndex].value-1])	
			return false;
			
	}
	else if(arguments.length == 1) 
	{
		//alert(arguments[0].value);
		//alert(IsValidDate(arguments[0].value));
		return( IsValidDate(arguments[0].value));
	}
	else
	{
		alert('Invalid arguments');
	}
	
}


/*
 
 This Function validates date whether entered data is less than or equal to current date.
 This function works with 3 parameters and 1 parameter.
 
 When 3 Parameters are passed it expected the list box objects. The format is month/day/year.
 ex:
	ValidateCurDate(MonthName,DayName,YearName);
	
 When 1 Parameter is passed it expected a string object. The format is mm/dd/yyyy.
 ex:
	ValidateCurDate("1/1/2003");
*/

function ValidateCurDate()
{
	var CurrentDate=new Date();

	if(arguments.length == 3) 
	{
		var MonthName,DayName,YearName;
		MonthName = arguments[0];
		DayName = arguments[1];
		yearname = arguments[2];
		 
		var date1=new Date(YearName.options[YearName.selectedIndex].value + "/" + MonthName.options[MonthName.selectedIndex].value + "/" + DayName.options[DayName.selectedIndex].value);
		
		if(date1<=CurrentDate)
		   return true;
		else
		   return false; 
	}
	else if(arguments.length == 1) 
	{
		//alert(arguments.length);
		//alert(arguments[0].value);
		
		//alert(str2dt(arguments[0].value));
		//alert(CurrentDate);
		return( str2dt(arguments[0].value) <= CurrentDate );
	}
	
}

//This Function compares two dates and return whther first date is greater than second or not
function GetDateFromDateTime(sDateTime)
{   

	//Constructing a regular expression for the format 1/1/2000 12:00:00
	var re_date = /^(\d+)\/(\d+)\/(\d+)\s+(\d+)\:(\d+)\:(\d+)/;
	var syear= new String();
	var sDate= new String();
	var nPos = new Number();
	
	//If the format is not found then we return a false value.
	if (!re_date.exec(sDateTime))
		return -1;
	else
	{	
		//From the format value we extract the year part.	
		sYear = RegExp.$3;
		
		//Finds the position of year in the datetime string.
		nPos = sDateTime.indexOf(sYear);
		
		if(nPos != -1)
		{
			//Splitting the DateTime string into Time and Date parts.
			//sTime = sDateTime.substring(nPos + 5,sDateTime.length);
			sDate = sDateTime.substring(0,nPos + 4);
			
			if(IsValidDate(sDate))
				return sDate;
			else
				return -1;
			
		}
		else
			return -1;
	}
		   
}


//This Function compares two dates and return whther first date is greater than or equal to second date or not
function CompareDate()
{   

	//alert(arguments.length);
	if(arguments.length == 6) 
	{
		
		MonthName1=arguments[0].value;
		DayName1=arguments[1].value;
		YearName1=arguments[2].value;
		MonthName2=arguments[3].value;
		DayName2=arguments[4].value;
		YearName2=arguments[5].value;
		
		var date1=new Date(YearName1.options[YearName1.selectedIndex].value + "/" + MonthName1.options[MonthName1.selectedIndex].value + "/" + DayName1.options[DayName1.selectedIndex].value);
		var date2=new Date(YearName2.options[YearName2.selectedIndex].value + "/" + MonthName2.options[MonthName2.selectedIndex].value + "/" + DayName2.options[DayName2.selectedIndex].value);
		
	}
	else if(arguments.length == 2)
	{
		
		date1 = str2dt(arguments[0].value);
		date2 = str2dt(arguments[1].value);
		
	}
	
	//alert(date2 + ': ' + arguments[1].value);
	//alert(date1 + ': ' + arguments[0].value);
	//alert(date2 >= date1);
	
	if (IsValidDate(arguments[0].value) == false) 
	{
		//alert("Please enter a valid date (MM/DD/YYYY) for " + arguments[0].value);
		return false;
	}
		
	if (IsValidDate(arguments[1].value) == false) 
	{
		//alert("Please enter a valid date (MM/DD/YYYY) for " + arguments[0].value);
		return false;
	}
	
	if(date2 >= date1)
	   return true;
	else
	   return false;
		   
}

//This Function compares two dates and return weather first date is greater than second date or not
function CompareDate2()
{

	//alert(arguments.length);
	if(arguments.length == 6) 
	{
		
		MonthName1=arguments[0].value;
		DayName1=arguments[1].value;
		YearName1=arguments[2].value;
		MonthName2=arguments[3].value;
		DayName2=arguments[4].value;
		YearName2=arguments[5].value;
		
		var date1=new Date(YearName1.options[YearName1.selectedIndex].value + "/" + MonthName1.options[MonthName1.selectedIndex].value + "/" + DayName1.options[DayName1.selectedIndex].value);
		var date2=new Date(YearName2.options[YearName2.selectedIndex].value + "/" + MonthName2.options[MonthName2.selectedIndex].value + "/" + DayName2.options[DayName2.selectedIndex].value);
		
	}
	else if(arguments.length == 2)
	{
		
		date1 = str2dt(arguments[0].value);
		date2 = str2dt(arguments[1].value);
		
	}
	
	//alert(date2 + ': ' + arguments[1].value);
	//alert(date1 + ': ' + arguments[0].value);
	//alert(date2 >= date1);
	
	if (date2 > date1)
	   return true;
	else
	   return false;
		   
}

// This Function validates date whether entered data is greater than or equal to current date

function ValidateAfterDate(MonthName,DayName,YearName)
{    
	var date1=new Date(YearName.options[YearName.selectedIndex].value + "/" + MonthName.options[MonthName.selectedIndex].value + "/" + DayName.options[DayName.selectedIndex].value);
	
	var CurrentDate=new Date();
	date1.setHours(CurrentDate.getHours()+3);
	date1.setMinutes(CurrentDate.getMinutes());
	
	if(date1 >= CurrentDate)
	   return true;
	else
	   return false; 
}

// This Function validates whether entered time is less than or equal to current time

function ValidateCurTime(MonthName,DayName,YearName,Hour,Minute)
{    
	
	var CurrentDate=new Date();
	var hours1,minutes1,hours2,minutes2;
	hours1=CurrentDate.getHours();
	minutes1=CurrentDate.getMinutes()+1;
	hours2=parseInt(Hour.options[Hour.selectedIndex].value);
	minutes2=parseInt(Minute.options[Minute.selectedIndex].value);
	
	if((hours1>=hours2) && (minutes1>minutes2))
		return true;
 	else
	{
		
		var date1=new Date(YearName.options[YearName.selectedIndex].value + "/" + MonthName.options[MonthName.selectedIndex].value + "/" + DayName.options[DayName.selectedIndex].value);
		//var date1=new Date(YearName.options[YearName.selectedIndex].value,MonthName.options[MonthName.selectedIndex].value,DayName.options[DayName.selectedIndex].value,hours2,minutes2);
		date1.setHours(hours2);
		date1.setMinutes(minutes2);
		var CurrentDate=new Date();
		if(date1<CurrentDate)
	   return true;
		else
	   return false;
	   
	}   
}

//This function expects date in the DD/MM/YYYY format
function IsValidDate (strDateTime) 
{
/* 
	\d ->		Matches a digit character. Equivalent to [0-9].  
	+ ->		Matches the preceding character one or more times. /zo+/ matches "zoo" but not "z."
	(pattern)	Matches pattern and remembers the match. The matched substring can be retrieved from the 
				result Array object elements [1]...[n] or the RegExp object's $1...$9 properties. 
				To match parentheses characters ( ), use "\(" or "\)". 
	^			Matches the beginning of input or line. 
	\			Marks the next character as special. 
				/n/ matches the character "n". The sequence /\n/ matches a linefeed or newline character.  
*/

	//var re_date = /^(\d+)\/(\d+)\/(\d+)/;
	var re_date = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; // requires 4 digit year
	

	var odate;
	var Datestr = new Array();
	var nYear,nMonth,nDay;
	
	//If the regular expression does not find the given pattern
	if (!re_date.exec(strDateTime))
	{
		return (false);
	}	
	else
	{
		/*
			RegExp.$5 holds year
			RegExp.$3 holds month
			RegExp.$1 holds day
		*/
		
		nYear=RegExp.$5;
		nMonth=RegExp.$1-1;
		nDay=RegExp.$3;
		
		odate = new Date (nYear, nMonth, nDay);
		
		/*
		alert(RegExp.$1 + ":" + RegExp.$2 + ":" + RegExp.$3 + ":" + RegExp.$4 + ":" + RegExp.$5 + ":" + RegExp.$6);
		alert(odate);
		
		alert(nYear);
		alert(nMonth);
		alert(nDay);
		*/
		
		if((nYear % 4 )==0)
			Datestr = [31,29,31,30,31,30,31,31,30,31,30,31,30,31];
		else
			Datestr = [31,28,31,30,31,30,31,31,30,31,30,31,30,31];
		
		if (nMonth+1 < 1 || nMonth+1 > 12) 
			return false;
			
		//alert(Datestr[nMonth]);
		
		if (nDay <= 0) 
			return false;	

		if(nDay > Datestr[nMonth])	
			return false;
		else
			return (true);
		
	}

}

/*	This function checks for valid time string.  */
function IsValidTime(sTimestring)
{
	var re_Time = /^(\d{1,2})\:(\d{1,2})\:(\d{1,2})\s(AM|am|pm|PM)/;
	var re_Time2 = /^(\d{1,2})\:(\d{1,2})\s(AM|am|pm|PM)/;
	var nHours;
	var nMinutes;
	var nSeconds;
	var bValid;
	
	sTimestring = sTimestring.toUpperCase();
	
	//If the regular expression does not find the given pattern
	if (!re_Time.exec(sTimestring))
	{
		if (!re_Time2.exec(sTimestring))
		{
			return (false);
		}
		bValid = true;
	}	
	else
		bValid = true;
	
	if (bValid)
	{
		/*
			RegExp.$1 holds Hours
			RegExp.$2 holds Minutes
			RegExp.$3 holds Seconds
		*/
		//alert(RegExp.$1 + ":" + RegExp.$2 + ":" + RegExp.$3 + ":" + RegExp.$4 + ":" + RegExp.$5 + ":" + RegExp.$6);
	
		nHours = RegExp.$1;
		nMinutes = RegExp.$2;
		nSeconds = RegExp.$3;
		
		/*
		alert(nHours);
		alert(nMinutes);
		alert(nSeconds);
		*/
		
		//Hours should in the range of 1 - 12.
		if(nHours < 1 || nHours > 12)
			return false;
		
		if(nMinutes < 0 || nMinutes > 59)
			return false;
		
		if(nSeconds < 0 || nSeconds > 59)
			return false;
			
		return true;
	}	
}

function ValidateDateTime(sDateTime)
{

	//Construction a regular expression for the format 1/1/2000 12:00:00
	var re_date = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})\s+(\d{1,2})\:(\d{1,2})\:(\d{1,2})\s(AM|am|pm|PM)/; // requires 4 digit year
	var syear;
	var sDate;
	var sTime;
	
	//If the format is not found then we return a false value.
	if (!re_date.exec(sDateTime))
		return false;
	else
	{
		//alert(RegExp.$1 + ":" + RegExp.$2 + ":" + RegExp.$3 + ":" + RegExp.$4 + ":" + RegExp.$5 + ":" + RegExp.$6 + ":" + RegExp.$7 + ":" + RegExp.$8 + ":" + RegExp.$9);
		nPos = new Number();
		sDate= new String();
		sTime= new String();
		syear = new String();
		
		//From the format value we extract the year part.	
		sYear = RegExp.$5;
		
		//Finds the position of year in the datetime string.
		nPos = sDateTime.indexOf(sYear);
		
		if(nPos != -1)
		{
			//Splitting the DateTime string into Time and Date parts.
			sTime = sDateTime.substring(nPos + 5,sDateTime.length);
			sDate = sDateTime.substring(0,nPos + 4);
			
			//alert(sTime);
			//alert(sDate);
			
			if(IsValidTime(sTime) && IsValidDate(sDate))
				return true;
			else
				return false;
			
		}
		else
			return false;
	}
	
}

function IsValidateDateTime(sDateTime)
{

	//Construction a regular expression for the format 1/1/2000 12:00:00
	var re_date = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})\s+(\d{1,2})\:(\d{1,2})\:(\d{1,2})\s(AM|am|pm|PM)/; // requires 4 digit year
	var re_date2 = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})\s/; // requires 4 digit year
	var re_date3 = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})\s+(\d{1,2})\:(\d{1,2})\s(AM|am|pm|PM)/; // requires 4 digit year
	
	var syear;
	var sDate;
	var sTime;
	var ValidFmt = 0;
	
	//If the format is not found then we return a false value.
	if (!re_date.exec(sDateTime) && !re_date3.exec(sDateTime))
	{
		if (!re_date2.exec(sDateTime))
		{
			return false;
		}
		else
			ValidFmt = 2;
	}
	else
		ValidFmt = 1;
	
		
	if (ValidFmt > 0)
	{
		//alert(RegExp.$1 + ":" + RegExp.$2 + ":" + RegExp.$3 + ":" + RegExp.$4 + ":" + RegExp.$5 + ":" + RegExp.$6 + ":" + RegExp.$7 + ":" + RegExp.$8 + ":" + RegExp.$9);
		nPos = new Number();
		sDate= new String();
		sTime= new String();
		syear = new String();
		
		//From the format value we extract the year part.	
		sYear = RegExp.$5;
		
		//Finds the position of year in the datetime string.
		nPos = sDateTime.indexOf(sYear);
		
		if(nPos != -1)
		{
			//Splitting the DateTime string into Time and Date parts.
			sTime = sDateTime.substring(nPos + 5,sDateTime.length);
			sDate = sDateTime.substring(0,nPos + 4);
			
			//alert(sTime);
			//alert(sDate);
			if (IsValidDate(sDate))
			{
				if (ValidFmt = 1)
				{
					return (IsValidTime(sTime));
				}		
				
				return true;
			}
				return false;
				
		}
		else
			return false;
	}
	
}

function CompareDateFromDateTime(oDate1,oDate2)
{	
var stDate1 = new String();
var EndDate2 = new String();

	stDate1 = GetDateFromDateTime(oDate1.value);
	EndDate2 = GetDateFromDateTime(oDate2.value);
	
	if(EndDate2 >= stDate1)
	   return true;
	else
	   return false;
	   
}

/*
function CheckForTimeDiff(oStDate,oEndDate)
{
var nHour1 = new Number();
var nHour2 = new Number();
var nDiff = new Number();
var stValue = new String();
var endValue = new String();

	var re_date = /^(\d+)\/(\d+)\/(\d+)\s+(\d+)\:(\d+)\:(\d+)/;
		
	//alert(oStDate.name);
	//alert(oEndDate.name);
	
	
	stValue = oStDate.value;
	endValue = oEndDate.value;
	
	if (ValidateDateTime(stValue)==false)
		return false;	
	
	if (ValidateDateTime(endValue)==false)
		return false;
		
	
	//alert(stValue);
	//alert(endValue);
	
	//If the format is not found then we return a false value.
	if (!re_date.exec(stValue))
	{
		nHour1 = -1;
	}
	else
	{
		//From the format value we extract the hour part.	
		nHour1 = RegExp.$4;	
	}
	
	
	
	//If the format is not found then we return a false value.
	if (!re_date.exec(endValue))
	{
		nHour2 = -1;
	}
	else
	{
		//From the format value we extract the hour part.	
		nHour2 = RegExp.$4;	
	}
	
	//nDiff = oStDate.name
	
	nDiff = 12
	//alert(nHour2);
	//alert(nHour1);
	
	if(nHour1 == -1 || nHour2 == -1)
		return false;
		
		
	if ( (nHour2-nHour1) > nDiff )
		return false;
	else
		return true;
	
}
*/

// This is the actual function called when a form is submitted 
// this function loops through the form controls and searches for strings parametes in control name and does the respective validate 
// For example "req" is searched and validated for empty fields

function Validate()
{
      
   if(arguments.length == 0) 
		var f=document.forms[0];
   else
		var f=document.forms[arguments[0]];
		 
   for(i=0; i<f.elements.length; ++i)
   {
	   	
       if(f.elements[i].name.indexOf("req")!=-1)
	      if(ValidateEmptyField(f.elements[i])==false)
		  {  
			   	
 		       if(reqErrorMessage)
 		          if(reqErrorMessage[i]) 
					alert(reqErrorMessage[i]);
				  else
				   	alert("Please Enter The Data In The Fields That Are Marked As Required"); 			 
			   else
   					alert("Please Enter The Data In The Fields That Are Marked As Required"); 			 
				
               f.elements[i].focus();
               return false;
		 }		
		 
			
	   if(f.elements[i].name.indexOf("EMail")!=-1)
          if(ValidateEmail(f.elements[i])==false)
		  {
           		alert("Please Enter A Valid E-mail Address");  
				f.elements[i].focus();
		        return false;
		  }		
       if(f.elements[i].name.indexOf("CurDate")!=-1)
	     
         if(ValidateCurDate(f.elements[i],f.elements[i+1],f.elements[i+2])==false)
          {
              alert("Please Select The Date That Is Less Than (OR) Equal To The Current Date");
			  f.elements[i].focus();
                return false;         
          } 
		
		if(f.elements[i].name.indexOf("_Time")!=-1)
	     
         if(f.elements[i].value.length > 0 && IsValidTime(f.elements[i].value)==false)
          {
              alert("The Time you entered '" + f.elements[i].value + "' is not a valid time.\n\tPlease enter a valid time.\nThe time should be entered in 12 hour format like (12:30:00 PM) ");
			  f.elements[i].focus();
                return false;         
          } 
      
        if(f.elements[i].name.indexOf("DateTime")!=-1)
	     
         if(f.elements[i].value.length > 0 && ValidateDateTime(f.elements[i].value) == false)
          {
              alert("Please enter a valid Date and time.\nThe Date and time should be entered in the format like (1/1/2004 12:30:00 PM) ");
			  f.elements[i].focus();
                return false;         
          } 
         if(f.elements[i].name.indexOf("DateTime1")!=-1)
	     
         if( f.elements[i].value.length > 0 && CompareDateFromDateTime(f.elements[i],f.elements[i+1]) == false)
          {
              alert("Please Select The Start DateTime That Is Less Than The End DateTime.");
			  f.elements[i].focus();
                return false;         
          }
         /*if(f.elements[i].name.indexOf("TDiff")!=-1)	//For Time Difference
	     
         if(CheckForTimeDiff(f.elements[i],f.elements[i+1]) == false)
          {
              alert("Please enter a valid Date and time.\nThe Date and time should be entered in the format like (1/1/2004 12:30:00 PM) ");
			  f.elements[i].focus();
                return false;         
          } 
		*/
		if(f.elements[i].name.indexOf("CurTime")!=-1)
	     
         if(ValidateCurTime(f.elements[i-3],f.elements[i-2],f.elements[i-1],f.elements[i],f.elements[i+1],f.elements[i+2])==false)
          {
              alert("Please Select The Time That Is Less Than (OR) Equal To The Current Time");
			  f.elements[i].focus();
                return false;         
          } 
	
	if(f.elements[i].name.indexOf("pnumeric")!=-1)
          if(ValidatePositiveNumeric(f.elements[i])==false)
          {
              alert("Please Enter A Valid Positive Numeric Value");
			  f.elements[i].focus();
                return false;         
          }	

	
       if(f.elements[i].name.indexOf("numeric")!=-1)
          if(ValidateNumeric(f.elements[i])==false)
          {
              alert("Please Enter A Valid Numeric Value");
			  f.elements[i].focus();
                return false;         
          }
        
        if(f.elements[i].name.indexOf("SSN")!=-1)
          if(isValidSSN(f.elements[i])==false)
			return false; 	        
           
        if(f.elements[i].name.indexOf("ValidDate")!=-1)
         if(ValidateDate(f.elements[i],f.elements[i+1],f.elements[i+2])==false)
          {
              alert("The Date You Have Selected Is Invalid. \n Please Select a Valid Date.");
			  f.elements[i].focus();
                return false;         
          }
          
        if(f.elements[i].name.indexOf("TxtValidateDate")!=-1)
        {
        //alert( f.elements[i].value.length);
        //alert(f.elements[i].value.length > 0 && ValidateDate(f.elements[i]) == false);
         if( f.elements[i].value.length > 0 && ValidateDate(f.elements[i]) == false)
          {
			
              alert("The date you have entered '" + f.elements[i].value + "' is not a valid date. \n Please enter a valid date.");
			  f.elements[i].focus();
                return false;         
          } 
        }
        
        if(f.elements[i].name.indexOf("TxtValidateDate1")!=-1)
        {
        //alert( f.elements[i].value.length);
        //alert(f.elements[i] + ' : ' + f.elements[i+1]);
         if( f.elements[i].value.length > 0 && CompareDate(f.elements[i],f.elements[i+1]) == false)
          {
              alert("Please Select The Start Date That Is Less Than The End Date.");
			  f.elements[i].focus();
                return false;         
          } 
        }
        if(f.elements[i].name.indexOf("ValidDate1")!=-1)
         if(CompareDate(f.elements[i],f.elements[i+1],f.elements[i+2],f.elements[i+3],f.elements[i+4],f.elements[i+5])==false)
          {
              alert("Please Select The Start Date That Is Less Than The End Date");
			  f.elements[i].focus();
                return false;         
          }     
        if(f.elements[i].name.indexOf("Password1")!=-1)
         if(ValidateReTypePassWord(f.elements[i],f.elements[i+1])==false)
          {
              alert("ReTyped PassWord Does Not Match With The Original Password \n Please Retype The Password");
			  f.elements[i+1].focus();
                return false;         
          }
          
   		if(f.elements[i].name.indexOf("ValidDateAfter")!=-1)
	     
         if(ValidateAfterDate(f.elements[i],f.elements[i+1],f.elements[i+2])==false)
          {
              alert("Please Select The Date That Is Greater Than (OR) Equal To The Current Date");
			  f.elements[i].focus();
                return false;         
          } 
        
        if(f.elements[i].name.indexOf("Diff20")!=-1)
        
         if( DateDiff20(f.elements[i+5], f.elements[i+2]) == false)
          {
              alert("Difference Between The Years Should Be Atleast 20");
			  f.elements[i].focus();
                return false;         
          }     
          
    
	}
	return true;
}




function DateDiff20(D1,D2)
{
	if ( (D1.options[D1.selectedIndex].value - D2.options[D2.selectedIndex].value) < 20) 

		return false;

	else

		return true;
		
}

function IsEmpty(FieldName)
{
var sValue;
	
	sValue = FieldName.value;
	sValue = Trim(sValue);
	
	if (sValue.length == 0)
	{
		FieldName.focus();
		return true;
	}
	else
		return false;
} 

// This function is used to validate whther Select box is selected or not

function IsSelect(ListName)
{	
  
	if(ListName.options[ListName.selectedIndex].value < 0)
		{
		//alert("Please Select From The List");
		return true;
		}
	else 
		return false;
}	

// This function is used to validate whther Multiple Select box is selected or not

function IsMultipleSelect(ListName)
{ 
  value=true;
  var iIndex = new Number();
  
 for(iIndex=0; iIndex<ListName.options.length; iIndex++)
 { 
  
   if(ListName.options[iIndex].selected==true)
		value=false;
 }		
			
  return value;			

}	


function LoadFrame(Url)
{
	
	parent.location.href = Url;
	return false;
}

function LoadUrl(Url)
{
	document.location.href = Url;
	return false;
}


function ConfirmAndLoadUrl(msg,Url)
{
	
	if (confirm(msg))
	{
		document.location.href = Url;
	
	}
	
	return false;
}

function LoadWindow()
{
var sUrl;
var nheight;
var nwidth;
var ntop;
var nleft;
var sOptions;
var stoolbar;
var m_hwind;

	if(arguments.length > 0)
		sUrl = arguments[0];
	
	//alert(arguments.length);
	//alert(nheight);
	
	stoolbar = "yes";
	
	if(arguments.length == 6)
	{
		nheight = arguments[1];
		nwidth = arguments[2];
		ntop = arguments[3];
		nleft = arguments[4];
		if(arguments[5]==true)
			stoolbar = "yes";
		else
			stoolbar = "no";
	}
	
	sOptions = "width=" + nwidth + ",height=" + nheight + ",status=no,scrollbars=yes,resizable=yes,toolbar=" + stoolbar + ",top=" + ntop + ",left=" + nleft + "";
	//alert(sOptions);
	//alert(Url);
	m_hwind = window.open(sUrl, "win",sOptions);
	return false;
}

//This function displays the given message to the browser.
function DisplayMessage()
{
	var str=" ";
	
	switch (arguments.length)
	{
		case 1:
			str = str + "<BR><BR><BR><BR><table align=center border=0 cellPadding=0 cellSpacing=1 width=75% bgcolor='#333333'>";
			str = str + "<tr ><td align=center class=tblHeadings>I N F O R M A T I O N</td></tr>";
			str = str + "<tr><td align=center class='tblContent'> <BR><BR>" + arguments[0] + "<BR><BR><BR><BR></td></tr>";
			str = str + "</table>";break;
	}
		
	document.write(str);
}

function round(number,X) 
{

X = ( !X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
//flashEnabled=false;

function ApplyFilter(sPagename)
{
	var sUrl = new String();
	var retvalue;
	var reg;
	
	if(isIE)
	{
		retvalue = window.showModalDialog(sPagename,"Customize Grid","center:yes;status:no;resizable:yes;help:no;dialogHeight:23;dialogWidth:37;");
	}
	else
	{
		retvalue = false;
		m_oCustomScreen = window.open (sPagename,"Preview","height=323,width=580,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=no")
	}
			
	if(retvalue)
	{
	
		sUrl = document.location.href;
			
		if (sUrl.indexOf("CustomGrid=") != -1)
		{
			if (sUrl.indexOf("CustomGrid=FALSE") != -1)
			{
				reg = /CustomGrid=FALSE/g;
				sUrl =  sUrl.replace(reg, "CustomGrid=TRUE");
			}
		}
		else
		{
			if(sUrl.indexOf("?") != -1)
			{
				sUrl =  sUrl + "&CustomGrid=TRUE"
			}
			else
			{
				sUrl =  sUrl + "?CustomGrid=TRUE"
			}
		}
				
		document.location.href= sUrl;
	
	}

	return false;
				
}


function onLinkClick(ofrm,sPage)
{
	ofrm.action = sPage;
	ofrm.submit();
	return false;
}

function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
	return"";
	}
	
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
	
} //End Function

function RTrim(VALUE)
{

var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";

	if(v_length < 0)
	{
		return "";
	}

var iTemp = v_length -1;

	while(iTemp > -1)
	{
		
		if(VALUE.charAt(iTemp) == w_space)
		{
		
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	
return strTemp;

} //End Function

function LTrim(VALUE)
{

var w_space = String.fromCharCode(32);

	if(v_length < 1)
	{
		return"";
	}

var v_length = VALUE.length;
var strTemp = "";
var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		
		iTemp = iTemp + 1;
		
	} //End While

	return strTemp;

} //End Function



function CloseCalendar()
{
	
	if (m_oCustomScreen)
	{
		m_oCustomScreen.close();
		m_oCustomScreen = null;
	}
	
	if (m_hwnd)
	{
		m_hwnd.close();
		m_hwnd = null;
	}

	if(bWinOpen = true)
	{
		if(vWinCal != 0) 
			vWinCal.close();
	}
	return false;
}
window.onunload = CloseCalendar;



// Print Functionality From Here

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(frame, arg) 
{
  if (frame == window) {
    printThis();
  } else {
    link = arg; // a global variable 
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

