/***
 * This page contains all the common javascript used to validate the data
 * it is used for common validation
 * @author     		MediTab Software Inc. 
 * @copyright  		1997-2005 The MediTab Software Inc.
**/
	
	/***
	 * Variable declaration for alert nessage, alert fields, field style and fields focus
	**/
	var strAlertMessage			=	"";	
	var strAlertfield;
	var strStyle				=	"";
	var strFocus				=	"";
	var strReOneOrMoreDigits 	= 	/[\d+]/;
	var strReNoDigits 			= 	/[^\d]/gi;
	var selcount				=	0;
	var itercount				=	0;

	/***
	 * This function is used to check for the empty fields
	 * It Will display tne message if the mendatory filed is Null
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @return		true/false		Bollean
	**/
	function checkBlank(FIELD_NAME,MESSAGE)
	{
		// If value is null then alert message...
		// Call Trim function to trim the value
		if(Trim(FIELD_NAME.value) == '')
		{
			strAlertMessage+="\nPlease enter value for "+MESSAGE+".";
			if(FIELD_NAME.type!='textarea')
			{
				setStyle(FIELD_NAME);
			}
			return true;
		}
		else
		{	
			if(FIELD_NAME.type!='textarea')
			{
				resetStyle(FIELD_NAME);			
			}
			return false;	
		}
	}

	/***
	 * This function is used to check for the alphabatic values for the field
	 * It Will display tne message if the field value is not alphabetic
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkAlpha(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		
		// Regular expression for alphabetic validation...
		if(FIELD_NAME.value.search(/^[A-Za-z]*$/))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}

	/***
	 * This function is used to check for the date validation for the field
	 * It Will display tne message if the field value is not proper date format
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkDate(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Call isDate function to validate Date...
			if(!isDate(FIELD_NAME.value))
			{
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
		}
		resetStyle(FIELD_NAME);
		return true;
	}

	/***
	 * This function is used to compare date
	 * It  Will compare start date & end date. if start date>end date then it will give alert message
	 * @param  		START_DATE 		String		Sart Date
	 * @param  		END_DATE 		String		End Date
	 * @param 		MESSAGE_START	String 		Lable of start date
	 * @param 		MESSAGE_END		String 		lable of end date
	 * @return		true/false		Bollean
	**/
	function dateCompare(START_DATE,END_DATE,MESSAGE_START,MESSAGE_END)
	{
		// If both start date & end date are not null then...
		sadate	=	Array();
		eadate	=	Array();
		sadate	=	START_DATE.value.split("-");
		eadate	=	END_DATE.value.split("-");
	
		sdate	=	new Date(sadate[2],sadate[0]-1,sadate[1]);
		edate	=	new Date(eadate[2],eadate[0]-1,eadate[1]);
	
		// Compare both start date & end date. if start date is greater then end date then alert message...
		if(sdate>edate)	
		{
			alert(MESSAGE_END+" can not be less than "+MESSAGE_START+".");
			fldname=END_DATE;
			setStyle(END_DATE);
			eval(strStyle);
			END_DATE.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	/***
	 * This function is used to check for future date
	 * It Will compare date with cureeent date
	 * @param  		CURRENT_DATE	String		current date
	 * @param 		FIELD_DATE		String 		Date to be compared
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @return		true/false		Bollean
	**/
	function checkFutureDate(CURRENT_DATE,FIELD_DATE,MESSAGE)
	{
		// If both Current date & date to be compared are not null then...
		sadate	=	Array();
		cdate	=	Array();
		sadate	=	FIELD_DATE.value.split("-");
		cadate	=	CURRENT_DATE.value.split("-");
		sdate	=	new Date(sadate[2],sadate[0]-1,sadate[1]);
		cdate	=	new Date(cadate[2],cadate[0]-1,cadate[1]);
	
		// Compare both current date & field date. if field date date is greater then current date then alert message...
		if(sdate>cdate)	
		{
			alert(MESSAGE+' Can not be future date.');
			fldname=FIELD_DATE;
			setStyle(FIELD_DATE);
			eval(strStyle);
			FIELD_DATE.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	/***
	 * This function is used to check for integer value of the field
	 * It Will check for numeric value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkInteger(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		// Regular expression for numeric validation...
		if(FIELD_NAME.value.search(/^[0-9]*$/))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for float value of the field
	 * It Will check for float value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param 		CHARNO			Integer		floating point position
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkFloat(FIELD_NAME,MESSAGE,CHARNO,REQUIRED)
	{
		// Get the validation string...
		var stringsearch="/^[0-9]+(\.)?[0-9]{0,"+CHARNO+"}$/";
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		if(FIELD_NAME.value.search(eval(stringsearch)))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for decimal value of the field
	 * It Will check for decimal value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkDecimal(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		if(isNaN(FIELD_NAME.value))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for valid zip value of the field
	 * It Will check for zip code. Zip code can be of 5 or 9 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkZip(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		// valid zip should contain 5 or 9 digits...
		if(FIELD_NAME.value!="")
		{
			// Regular expression for zip code validation...
			if(FIELD_NAME.value.search(/^\d\d\d\d\d(\d\d\d\d)?$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}
	
	/***
	 * This function is used to check for valid Phone number value of the field
	 * It Will check for phone number. Phone number can be greater then 10 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkPhone(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// It will allow 0 to 9 and x or X on 11th position
			// Regular expression for phone number validation...
			if(FIELD_NAME.value.search(/^[0-9]{10}[0-9Xx]?[0-9]{0,3}$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}

	/***
	 * This function is used to check for valid fax number value of the field
	 * It Will check for fax number. Fax Number can be of 10 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkFax(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Regular expression for fax number validation...
			if(FIELD_NAME.value.search(/^[0-9]{10}$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
			
		}
		else
		{	
				resetStyle(FIELD_NAME);			
				return true;	
		}
	}

	/***
	 * This function is used to check for valid email value of the field
	 * It Will check For Valid Email.
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkEmail(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Regular expression for email validation...
			if(FIELD_NAME.value.search(/^[\w-\.]+@[\w-\.]+\.\w+$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{
				return true;
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);
			return true;	
		}
	}

	/***
	 * Date validation functions
	 * Main function name is: isDate
	**/

	/***
	 * DHTML date validation script. 
	**/
	// Declaring valid date character, minimum year and maximum year

	var dtCh= "-";
	var minYear=1900;
	var maxYear=2100;
	
	/***
	 * This function is used to check for the integer values
	 * It will check all the characters are numbers or not...
	 * @param		s 				String
	 * @return		true/false		Boolean		
	**/
	function isInteger(s)
	{
		var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	/***
	 * This function is used to strip characters
	 * @param		s 				String
	 * @param		bag				String
	 * @return		returnString	String	
	**/
	function stripCharsInBag(s, bag)
	{
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	/***
	 * This function is used to check number of days in february
	 * @param		year 			Integer
	 * @return		days			Integer	
	**/
	function daysInFebruary (year)
	{
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}


	/***
	 * This function makes day Array...
	 * if month = 2(feb)  	then days = 29
	 * if mont = 4,6,9,11 	then days=30
	 * else 				days=31
	 * @param		n		integer		month
	 * @reurn		this	integer		number of days
	**/
	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
	}
	
	/***
	 * This function is used to check date format
	 * It will check whether date format is correct or not
	 * @param 		dtStr			String		Date to be checked
	 * @return 		true/false		Boolean		
	**/
	function isDate(dtStr)
	{
		var daysInMonth 	= 	DaysArray(12)
		var pos1			=	dtStr.indexOf(dtCh)
		var pos2			=	dtStr.indexOf(dtCh,pos1+1)
		var strMonth		=	dtStr.substring(0,pos1)
		var strDay			=	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)
		{
			// If two "-" are not there in date then date is invalid...
			strAlertMessage+="\nInvalid date.The date format should be : mm-dd-yyyy";
			return false
		}
		if (strMonth.length<1 || month<1 || month>12)
		{
			// Checking for month format...
			strAlertMessage+="\nPlease enter a valid month";
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			// Checking for day format...
			strAlertMessage+="\nPlease enter a valid day";
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		{
			// Checking for Year Format...
			strAlertMessage+="\nPlease enter a valid 4 digit year between "+minYear+" and "+maxYear;
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{
			// Check whether it is integer or not...
			strAlertMessage+="\nPlease enter a valid date";
			return false
		}
		return true
	}

	/***
	 * This function is used to format date
	 * It Will convert date in specific format.
	 * @param 		DATE			String		Date to be formated
	 * @param		DATE_FORMAT		String		Date Format
	 * @return 		FDate			String		Formated date
	**/
	function formatDate(DATE,DATE_FORMAT)
	{
		FDate			=	DATE.split('-');	
		FirstFC			=	DATE_FORMAT.substr(0,1);
		SecondFC		=	DATE_FORMAT.substr(2,1);
		ThirdFC			=	DATE_FORMAT.substr(4,1);
		AddChr			=	DATE_FORMAT.substr(1,1);	
		var MONTH_NAMES	=	new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		if(FirstFC=='Y' || FirstFC=='y')
		{
			// Check For First Place For Year...
			if(FirstFC=='Y')
			{
				FirstFC=FDate[0];	
			}
			else
			{
				FirstFC=FDate[0].substr(2,2);
			}
		}
		else if(FirstFC=='M' || FirstFC=='m')
		{
			// Check For First Place For Month...
			if(FirstFC=='M')	
			{
				FirstFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				FirstFC=FDate[1];	
			}
		}
		else
		{
			FirstFC=FDate[2];
		}
		if(SecondFC=='Y' || SecondFC=='y')
		{
			// Check For Second Place For Year...
			if(SecondFC=='Y')
			{
				SecondFC=FDate[0];	
			}
			else
			{
				SecondFC=FDate[0].substr(2,2);
			}
		}
		else if(SecondFC=='M' || SecondFC=='m')
		{	
			// Check For Second Place For Month...
			if(SecondFC=='M')	
			{
				SecondFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				SecondFC=FDate[1];	
			}
		}
		else
		{
			SecondFC=FDate[2];	
		}
		if(ThirdFC=='Y' || ThirdFC=='y')
		{
			// Check For Third Place For Year...
			if(ThirdFC=='Y')
			{
				ThirdFC=FDate[0];	
			}
			else
			{
				ThirdFC=FDate[0].substr(2,2);
			}
		}
		else if(ThirdFC=='M' || ThirdFC=='m')
		{
			// Check For Third Place For Month...
			if(ThirdFC=='M')	
			{
				ThirdFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				ThirdFC=FDate[1];	
			}
		}
		else
		{
			ThirdFC=FDate[2];	
		}
		FDate=FirstFC+AddChr+SecondFC+AddChr+ThirdFC;
		return FDate;
	}

	/***
	 * This function is used to Select & Deselect All Checkboxes
	 * @param 		CHECKBOX_ARRAY	String		Field name
	 * @param		CHECKALL		String		Field name
	 * @return 		Void
	**/
	function checkAll(CHECKBOX_ARRAY,CHECKALL) 
	{
		var name=document.getElementsByName(CHECKBOX_ARRAY);
		var field = name.length;
		for (i = 0; i < field; i++) 
		{
			var str=eval(name[i]);
			str.checked=document.getElementById(CHECKALL).checked;
		}
	}

	/***
	 * This function is used to check for selected Check box.
	 * It will alert message if all the checkboxws are deselected
	 * @param 		FIELD_NAME		String		Name of the field
	 * @return 		true/false		Boolean
	**/
	function checkSelect(FIELD_NAME)
	{
		var field=document.getElementsByName(FIELD_NAME);
		var chkselect = false;
		for(var i=0;i<field.length;i++)
		{
			var str=eval(field[i]);
			if(str.checked)
			{
				chkselect=true;
				break;
			}
		}
		if(chkselect == false)
		{
			strAlertMessage+="\nPlease select atleast one checkbox.";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);
			return true;
		}
	}

	/***
	 * This function is used for Convert string in Uppercase.
	 * @param 		objId			String		Name of the field
	 * @return 		objId			String		Value of field in uppercase
	**/
	function ftoupper(objId)
	{
		sId = objId.value
		objId.value = sId.toUpperCase() ;
	}

	/***
	 * This function is used for Convert string in Lowercase.
	 * @param 		objId			String		Name of the field
	 * @return 		objId			String		Value of field in lowercase
	**/
	function ftolower(objId)
	{
		sId = objId.value
		objId.value = sId.toLowerCase() ;
	}

	/***
	 * This function is used to trim the string
	 * It will remove spaces from the string
	 * @param 		str				String		Value of the field
	 * @return 		substr			String		string without space
	**/
	function Trim(str)
	{ 
	 	lenstr = str.length
	 	substr = str
	 	for (i=0;i<lenstr;i++)
	 	{
			c = str.charAt(i);	
			if(c == ' ' || c == '\n'  || c == '\r')
				substr = str.substring(i+1,str.length)
			else
				break   
		}
	 	lenstr = substr.length
	 	str = substr 
	 	for (i=lenstr-1;i=0;i--)
		{
			c = str.charAt(i);
			if (c == ' '||c == '\n'||c == '\r')
				substr = str.substring(0,i-1)		
			else
				break   
		}   
	 	return substr	
	}

	/***
	 * This function will check for the valid url
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkURL(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value != "")
		{
			// Regular expression for url validation
			if(FIELD_NAME.value.search(/^((www.)|(((http)(s)?\:\/\/)(www.)?))[\w\/\-\._\-\~?&=:]+\w+$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				if(FIELD_NAME.type!='textarea')
				{
					setStyle(FIELD_NAME);
				}
				return true;
			}
			else
			{	
				if(FIELD_NAME.type!='textarea')
				{
					resetStyle(FIELD_NAME);			
				}
				return false;	
			}
		}
		else
		{	
			if(FIELD_NAME.type!='textarea')
			{
				resetStyle(FIELD_NAME);			
			}
			return false;	
		}
	}

	/***
	 * This function is used to check value for selectbox.
	 * It will alert message if all the value of select box is blank
	 * @param 		FIELD_NAME		String		Name of the field
	 * @return 		true/false		Boolean
	**/
	function checkSelectBox(FIELD_NAME,MESSAGE)
	{
		// If value is null then alert message...
		if(FIELD_NAME.value == '')
		{
			strAlertMessage+="\nPlease select atleast one value for "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return true;
		}
		else
		{
			resetStyle(FIELD_NAME);
			return false;
		}
	}

	/***
	 * This function is used to compare two numbers
	 * @param 		NUMBER1		Integer		Name of First field
	 * @param		NUMBER2		Integer		Name if Second Field
	 * @param		MESSAGE1	String		First Message To BE displayed
	 * @param		MESSAGE2	String		Second Message To BE Displayed
	**/
	function numberCompare(NUMBER1,NUMBER2,MESSAGE1,MESSAGE2)
	{
		if(NUMBER1.value > NUMBER2.value)
		{
			strAlertMessage+="\n"+MESSAGE1+" is greater than "+MESSAGE2;
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		return true;
	}

	/***
	 * This function will Check For at least one Checked Check Box
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkMultiSelectBox(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Boolean flag for the check box...
		var blncflag	=	false;					
		var i			=	0;
		var fldname		=	"";
	
		if(FIELD_NAME.length!=undefined)	
		{
			// If multiple check boxes
			for(i=0;i<FIELD_NAME.length && blncflag==false;i++)
			{	
				fldname=FIELD_NAME[i];
				if(FIELD_NAME[i].checked)
				{	
					blncflag=true;	
				}
			}
		}
		else								
		{	// If single check box...	
			fldname=FIELD_NAME;
			if(FIELD_NAME.checked)
			{	
				blncflag=true;	
			}
		}
		if(blncflag==false)
		{	
			if(strAlertfield!=fldname.name || strAlertfield=="")
			{
				if(strAlertfield=="")
				{
					strAlertfield=fldname.name;
				}
				strAlertMessage+="\nPlease select the " + MESSAGE+" ";								
				setStyle(fldname);
			}
			if(strAlertfield!="" && strAlertfield!=fldname.name)
			{
				strAlertfield=fldname.name;
			}
			return false;
		}
		else
		{	
			resetStyle(fldname);		
			return true;	
		}
	}
	
	/***
	 * This function will Check For at least one selected Select Box
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkMultiDropDownBox(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Boolean flag for the select box...
		var blncflag	=	false;					
		var i			=	0;
		var fldname		=	"";
		var maxcount	=	document.getElementsByName(FIELD_NAME.name).length;
		itercount		=	itercount+1;
		
		// If multiple options or not
		if(FIELD_NAME.length!=undefined)	
		{
			for(i=0;i<FIELD_NAME.length && blncflag==false;i++)
			{	
				fldname=FIELD_NAME[i];
				// If a non null option has been selected...
				if(fldname.selected && fldname.value!="")
				{
					selcount=selcount+1;
					blncflag=true;
				}
			}
		}
		else								
		{	
			fldname=FIELD_NAME;
			if(FIELD_NAME.selected)
			{	
				blncflag=true;	
			}
		}
	
		// If no select boxes of the select array have been set then set the alert message...
		if(blncflag==false && selcount==0 && itercount==maxcount)
		{
			if(alertfield!=fldname.name || alertfield=="")
			{
				if(alertfield=="")
				{
					fldname=FIELD_NAME;
					alertfield=fldname.name;
				}
				// If none of array of select boxes have been set...
				if(selcount==0 && itercount==maxcount)
				{
					selcount=selcount+1;
					alertMessage+="\nPlease select the " + MESSAGE+" ";								
				}
			}

			// If none of array of select boxes have been set...
			if(selcount==0 && itercount==maxcount)
			{
				return false;
			}
			else
			{
				return true;	
			}
		}
		else
		{				
			return true;	
		}
	}
	
	/***
	 * This function will Check For at Valid File Types and required files
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @param		EXTENSIONS		String		file extensions
	 * @return		true/false		Bollean
	**/
	function checkFileName(FIELD_NAME,MESSAGE,REQUIRED,EXTENSIONS)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value != '' && EXTENSIONS!='')
		{
			// The array of valid file types...
			var arrfiletypes=new Array();	
			// Get the valid file types in the array...
			arrfiletypes=EXTENSIONS.split(',');
			// This boolean flag indicates a valid file type...
			var blnvalidflag=false;	
			// Separate filename and the extension...
			var arrfilename=new Array();		
			// Get the file extension in an array...
			arrfilename=FIELD_NAME.value.split('.');	
			// Check the file extension validity...
			if(arrfilename.length>1)
			{
				// Check the file extension validity...
				for(var c=0;c<arrfiletypes.length && blnvalidflag==false;c++) 
				{
					var strMainExt=arrfilename[1].toUpperCase();
					var strExt=arrfiletypes[c].toUpperCase();
					if(strMainExt==strExt)
					{
						// File type is valid so set the flag...
						blnvalidflag=true;					
						break;
					}
				}
			}
			else
			{
				// File type is not valid so set the flag...	
				blnvalidflag=false;					
			}
			if(blnvalidflag == false)					
			{
				// File is not a valid file type...
				strAlertMessage+="\nPlease select a valid "+MESSAGE+" of following types "+EXTENSIONS;
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else										
			{	
				// File is valid...
				resetStyle(fldname);				
				return true;	
			}
		}
	}

	/***
	 * This function will set style for the control
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @return		Void
	**/
	function setStyle(FIELD_NAME)
	{
		if(FIELD_NAME!=undefined)
		{
			if(navigator.appName=="Netscape")
			{
				if(strFocus=="")
				{
					if(document.getElementById(FIELD_NAME.id)!=undefined)
					{
						strFocus="document.getElementById('"+FIELD_NAME.id +"').focus();";
					}
					else if(document.getElementsByName(FIELD_NAME.name)!=undefined)
					{
						if(document.getElementsByName(FIELD_NAME.name).length>1)
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"')[0].focus();";
						}
						else
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"').focus();";	
						}
					}
				}
				// Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name +"').className='err';\n";			
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByName('"+FIELD_NAME.name + "').className='err';\n";					
				}
			}
			else
			{
				if(strFocus=="")
				{
					if(document.getElementById(FIELD_NAME.id)!=undefined)
					{
						strFocus="document.getElementById('"+FIELD_NAME.id +"').focus();";
					}
					else if(document.getElementsByName(FIELD_NAME.name)!=undefined)
					{
						if(document.getElementsByName(FIELD_NAME.name).length>1)
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"')[0].focus();";
						}
						else
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"').focus();";	
						}

					}
				}			
			    // Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name + "').className='err';\n";
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByName('"+FIELD_NAME.name + "').className='err';\n";	
				}
			}
		}
	}

	/***
	 * This function will reset style for the control
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @return		Void
	**/
	function resetStyle(FIELD_NAME)
	{
		if(FIELD_NAME!=undefined)
		{
			if(navigator.appName=="Netscape")
			{
	
				// Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name +"').className='comn-input';\n";			
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByTagName('"+FIELD_NAME.name + "').className='comn-input';\n";					
				}
			}
			else
			{
				// Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name + "').className='comn-input';\n";
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByTagName('"+FIELD_NAME.name + "').className='comn-input';\n";	
				}
			}
		}
	}

	/***
	 * This function will open the popup window
	 * @param  		url 		String		url of the popup page
	 * @param		width		Integer		width of the popup window
	 * @param		height		Integer		height of the popup window
	 * @param		resizable	Integer		(0,1) value to set whether popup is resizable or not
	 * @return		false		Boolean
	**/
	function popup(url,width,height,resize)
	{
		leftPosition=(screen.width)?(screen.width-width)/2:100;
		topPosition=(screen.height)?(screen.height-height)/2:100;
		testwindow=window.open(url+"&width="+width+"&height="+height, "preview", 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable='+resize+',width='+width+',height='+height+',left='+leftPosition+',top = '+topPosition+'');
		return false;
	}
	
	/***
	 * This function will set Max Length on Set Focus.
	 * This function pass text box value and string format like data format("##-##-####")
	 * @param  		strTextBox 		String		Name of the field
	 * @param		strFormat		String		format
	 * @return		Void
	**/
	function onFocusMask(strTextBox,strFormat) 
	{
		var strVal = strTextBox.value;
		if(strVal.length == 0 || strVal == null) 
		{
			var i = strFormat.indexOf('#');
			strTextBox.value = strFormat.substring(0,i);
		}
		setCaretAtEnd(strTextBox);
		// set just in case.
		strTextBox.maxlength = strFormat.length;
	}
	
	/***
	 * This function will pass blank value when no digit founds.
	 * @param  		strTextBox 		String		Name of the field
	 * @return		Void
	**/
	function onBlurMask(strTextBox) 
	{
		var strVal = strTextBox.value;
		// if no digits....nada entered.....blank it.
		if(strReOneOrMoreDigits.test(strVal) == false) 
		{
			strTextBox.value = '';
		}
	}

	/***
	 * This function will pass all the value to Masking function get Mask Value
	 * @param  		strTextBox 		String		Name of the field
	 * @param		strEvt			String		"EVENT" for events property 
	 * @param		strFormat		String		Maks Format like ("##-##-####")
	 * @return		Void
	**/
	function doMask(strTextBox,strEvt,strFormat) 
	{
		var keyCode = strEvt.which ?strEvt.which : strEvt.keyCode;
		
		// Enter, backspace, delete and tab keys are allowed thru
		if(keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 46)
			return true;
		
		// KeyCodes so that it can be used
		var keyCharacter = cleanKeyCode(keyCode);
		
		// Grab the strTextBox value and the mask
		var strVal = strTextBox.value;
		var mask = strFormat;
		
		// Simple Regex to check if key is a digit
		if(strReOneOrMoreDigits.test(keyCharacter) == false)
			return false;
		
		// Get value minus any masking by removing all non-numerics
		strVal = strVal.replace(strReNoDigits,'');			
		
		// Mask it...val holds the existing TextBox.value + the current keystroke
		strTextBox.value = MaskValue(strVal,mask);
		setCaretAtEnd(strTextBox);
		return false;
	}

	/***
	 * This function will return Mask Formated value to DoMask Function.
	 * @param  		strValue 		String		Text box value
	 * @param		strMask			String		Maks Format 
	 * @return		retVal			String		Mask Formated value
	**/
	function MaskValue(strValue,strMask) 
	{
		var retVal = strMask;
		var strVal = strValue;
		
		// Loop thru mask and replace #'s with current value one at a time
		for(var i=0;i<strVal.length;i++) 
		{
			retVal = retVal.replace(/#/i, strVal.charAt(i));
		}
		retVal = retVal.replace(/#/gi, "");
		return retVal;
	}

	/***
	 * This function will Return Formated String Key Code
	 * @param  		intKey 		Integer		int Key Code Genrated By Event Property.
	 * @return		intKey		String		Formated String Key Code
	**/
	function cleanKeyCode(intKey)
	{
		switch(intKey)
		{
			case 96: return "0"; break;
			case 97: return "1"; break;
			case 98: return "2"; break;
			case 99: return "3"; break;
			case 100: return "4"; break;
			case 101: return "5"; break;
			case 102: return "6"; break;
			case 103: return "7"; break;
			case 104: return "8"; break;
			case 105: return "9"; break;
			default: return String.fromCharCode(intKey); break;
		}
	}

	/***
	 * This function will set value Charcter at the End.
	 * @param  		strField 		String		field value
	 * @return		Void
	**/
	function setCaretAtEnd (strField) 
	{
	  if (strField.createTextRange) 
	  {
		var strRange = strField.createTextRange();
		strRange.moveStart('character', strField.value.length);
		strRange.collapse();
		strRange.select();
	  }
	}
	
/**
Function will return the absolute top position of div id or td id........better use td id
*/
function getAbsoluteTop(strObjectId) 
{
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	objDiv	=	document.getElementById(strObjectId)
	
	// Get top position from the parent object
	intTop	=	objDiv.offsetTop           
	
	while(objDiv.offsetParent!=null) 
	{ 
		// Parse the parent hierarchy up to the document element
		oParent = objDiv.offsetParent  // Get parent object reference
		intTop += oParent.offsetTop // Add parent top position
		objDiv = oParent
	}
	// Return top position
	return intTop
}
