			
function ValidateForm(formObj){			
	var FoundBlank = false;
	var spn; 
	for (var i=0;i < formObj.length;i++){
		fldObj = formObj.elements[i];

	if (fldObj.disabled==false)
		{
			if(fldObj.id=='required')
			{
				switch(fldObj.type)
				{
					case 'text':
						fldObj.style.border='1px solid #aaaaaa';
						if(fldObj.value.trim() == '')
						{
							fldObj.style.borderColor='yellow';
							FoundBlank = true;
						}	
						break    
					case 'select-one':
						spn = document.getElementById('spn' + fldObj.name);
						if(fldObj.selectedIndex==0){
							spn.style.border='1px solid yellow';
							
							if (navigator.appName != "Microsoft Internet Explorer")
								spn.style.padding = '3px 0px 3px 0px';

							FoundBlank = true;							
						}
						else
							spn.style.border="";						
						break
				}
			}
		}
	}
	
	if (FoundBlank) {
		ShowErrorMessage('Fields in yellow are required.'); 
		return false;
	}
	else
	{
		return true;
	}

}	

function ShowErrorMessage(errMessage)
{
	var html= "";
		
	html+="<table border='1' align='center' width='97%' cellspacing='0' cellpadding='0' bordercolor='#FFFF00'>";
	html+="<tr align='left' valign='top'>";
	html+="<td colspan='3' height='35px' class='hdr' valign='middle' align='center'>"
	html+= errMessage;
	html+="</td></tr></table><br>";
	
	document.getElementById("ErrorMessage").innerHTML=html;
	document.getElementById("ErrorMessage").style.visibility="Visible";
}

function HideErrorMessage()
{

	document.getElementById("ErrorMessage").innerHTML='';
	if (document.getElementById("ErrorMessage").style.visibility=="Visible")
		document.getElementById("ErrorMessage").style.visibility="hidden";
}



function ValidateDate(DateTxtBox)
{
	if(DateTxtBox.value != '' ){
		if (isDate(DateTxtBox.value) == false){
			alert('Date must be in the format mm/dd/yyyy.');
			DateTxtBox.value = '';
			DateTxtBox.focus();						
			return false;
		}
	}	
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
} 
return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var 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){
		//alert("The date format should be: mm/dd/yyyy \nfor the departure date")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month for the departure date")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day of the month\nfor the departure date")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+" \nfor the departure date")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date \nfor the departure date")
		return false
	}
return true
}


/* Validation Functions */

String.prototype.trim = function()
{
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

/*String.prototype.isDate = function()
{
	var re=/^((0?\d)|(1[0-2]))(\\|\/|-)((0?\d)|([1-2]\d)|(3[0-1]))(\\|\/|-)(\d{2}|\d{4})$/;
	return re.test(this);
}*/

String.prototype.isTime = function()
{
	var re=/^(((0?[1-9]|1[0-2])(:|\.)[0-5]\d((:|\.)[0-5]\d)?( )?(([aA]|[pP])[mM]))|((0?\d|1\d|2[0-3])(:|\.)[0-5]\d((:|\.)[0-5]\d)?))$/;
	return re.test(this);
}

String.prototype.isDateTime = function()
{
	var re=/^((0?\d)|(1[0-2]))(\\|\/|-)((0?\d)|([1-2]\d)|(3[0-1]))(\\|\/|-)(\d{2}|\d{4})( )(((0?[1-9]|1[0-2])(:|\.)[0-5]\d((:|\.)[0-5]\d)?( )?(([aA]|[pP])[mM]))|((0?\d|1\d|2[0-3])(:|\.)[0-5]\d((:|\.)[0-5]\d)?))$/;
	
	if (this.isDate()) return true;
	if (this.isTime()) return true;
	if (re.test(this)) return true;
	return false;
}

/*Replaced Array.indexOf function with exists(array, val)*/

function IsInteger(val)
{
	if (val=='') return true;
	if (isNaN(parseFloat(val))) return false;
	if (parseInt(val) < parseFloat(val)) return false;
	if (val.lastIndexOf(".")==val.length-1) return false;
	return true;
}

function IsDouble(val)
{
	if (val=='') return true;
	if (isNaN(parseFloat(val))) return false;
	if (val.lastIndexOf(".")==val.length-1) return false;
	return true;
}


//*******************Number Validation Starts Here**************************

function checkKeyPressForInteger(control, oEvent){

		var keyCode;
		if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			keyCode = oEvent.keyCode; 
		}
		else if(oEvent.which)
		{	// for Netscape and Mozilla
			keyCode = oEvent.which;
		}
		
				
		//Minus is allowed only as first char
		if (keyCode == 45){
			oEvent.returnValue = false;
			return false;
		}

		//only 0..9,-,backspace and non-keycode chars(del, arrows, ...)
		if((keyCode < 48 || keyCode > 57) && (keyCode != 45) && (keyCode != 8) && (keyCode != 0)) {
			oEvent.returnValue = false;
			return false;
		}
}


//*******************Number Validation Ends Here**************************



//*******************Decimal Validation Starts Here**************************
var err_Decimal='Decimal input error';
var err_Decimal_General='Entered value is not a valid decimal number';

function checkKeyPressForDecimal(control, oEvent) 
{
	var value = control.value;
	var keyCode;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		keyCode = oEvent.keyCode; 
	}
	else if(oEvent.which)
	{	// for Netscape and Mozilla
		keyCode = oEvent.which;
	}
	
	var decimalSeparator = ".";
	var sepCode = decimalSeparator.charCodeAt(0);	

	//Decimal point is not allowed as first char
	if ((value.length == 0) && (keyCode == sepCode))	{
		oEvent.returnValue = false;
		return false;
	}
	//If a decimal point exists
	if ((value.indexOf(decimalSeparator) != -1) && (keyCode == sepCode)) {
		oEvent.returnValue = false;
		return false;
	}
	
	//Minus is allowed only as first char
	//if ((value.length > 0) && (keyCode == 45)) {
	//	oEvent.returnValue = false;
	//	return false;
	//}
	//alert(keyCode)
	
	
	if(value.length>7)
	{
		if((keyCode < 48 || keyCode > 57))
		{
			oEvent.returnValue = false;
			return false;
		}
	}
	
	//only 0..9,-,backspace and non-keycode chars(del, arrows, ...)
	if ((keyCode < 48 || keyCode > 57) && (keyCode != 8) && (keyCode != 0) && keyCode != sepCode) {
		oEvent.returnValue = false;
		return false;
	}
}


//******************* format to Currency

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}