///////////////////////////////////////////////////////////////////////
//                                                                   //
//     JavaScripts Function For Input Forms Validations				 //
//                                                                   //
///////////////////////////////////////////////////////////////////////
<!-- Hide from non-JavaScript browsers
            
function strltrim() {
    return this.replace(/^\s+/,'');
}

function strrtrim() {
    return this.replace(/\s+$/,'');
}
function strtrim() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
                    
// End hiding --> 
        
function IsNull(fldName,ErrMsg) {
	// To check whether the field value is empty or not 
			var str = fldName.value;
			str = str.trim();
			if (str=="") {
				SetColor(fldName)
				ErrorMsg(fldName,ErrMsg);
				return true;
			}
	}
	function IsEmail(fldName,ErrMsg) {
// To check whether the value is a valid Email Address

	var theString = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890._-@"
	
		var fldValue = fldName.value;
		var fldLength = fldValue.length;
		var li_Check = 0
		var liCount;
		
		for (liCount = 0; liCount < fldLength; liCount ++ ) {
			// Search through string's characters one by one.
			var fldChar = fldValue.charAt(liCount);
			if (theString.indexOf(fldChar) == -1 ) {
				ErrorMsg(fldName,ErrMsg);
				return true;
			}
			else {
				// To check the number of times the @ or . is there in the value
				var s_fldChar = fldValue.substring(liCount,liCount+1);
				if ((s_fldChar == "@") || (s_fldChar == ".")) {
					li_Check = li_Check + 1;
				}
			}
		}
		if (li_Check < 2) {
			// If @ or . total count is greater than 2 
			ErrorMsg(fldName,ErrMsg);
			return true;
		}
	}
	
	function SetColor(fldName) {
	// To set a different color to the form field 
	//when Error Found in validation

		if (fldName.style) {
			//fldName.style.backgroundcolor = "#FFCC99";
			fldName.style.background = "#A5D9EC";
		} 	
	}
	function ErrorMsg(fldName,ErrMsg) {
	// To show Error Messages Encountered in the form validation
		
			alert(ErrMsg);
			SetColor(fldName);
			fldName.focus();
	}
function IsSelect(fldName,ErrMsg){
// To check whether the Index of the select options is not zerp

		var fldValue = fldName.selectedIndex;
		
		if (fldValue == 0) {
			ErrorMsg(fldName,ErrMsg)
			return true;
		}
}

	
	function vaidateinput() {
		if (IsNull(document.signup.fname,"Please enter your name.")) {
			return false;
		}
		if (IsNull(document.signup.femail,"Please enter your E-mail address.") ||
			IsEmail(document.signup.femail,"Sorry ! The E-mail address entered is invalid. Please enter again.")) {
			return false;
		}
		if (IsNull(document.signup.city,"Please enter your city.")) {
			return false;
		}
	}
	

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function vaidateTourInput() {
	if (IsSelect(document.booknow.Adults,"Please select an option in Number of Adults.")) {
		return false;
	}
	if (IsSelect(document.booknow.Youths,"Please select an option in Number of Youths.")) {
		return false;
	}
	if (IsSelect(document.booknow.Children,"Please select an option in Number of Children.")) {
		return false;
	}	
	if (IsNull(document.booknow.location,"Please enter your preferred pick-up location.")) {
		return false;
	}
	if (IsNull(document.booknow.FirstName,"Please enter your Name.")) {
		return false;
	}
	if (IsNull(document.booknow.Address,"Please enter your Address.")) {
		return false;
	}
	if (IsNull(document.booknow.City,"Please enter your City.")) {
		return false;
	}
	if (IsNull(document.booknow.email,"Please enter your E-mail address.") ||
		IsEmail(document.booknow.email,"Sorry ! The E-mail address entered is invalid. Please enter again.")) {
		return false;
	}

}