function cm(){
	var frm = document.forms.contactus;	
	var res = false;
	if(frm.tfname.value == "")
		alert("Please enter your name.");
	else if(frm.tfinfo.value == "" || frm.tfinfo.value == null)
		alert("Enter your question or comment in the the text box.");
	else
		res =  validateEmail(frm.tfemail.value);
		
	return res;	
}

function qm(){
	var frm = document.forms.quickmail;	
	return validateEmail(frm.tfemail.value)
}

function validateEmail(email){
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)){
		alert("The e-mail address you entered is not correctly formatted.");
		return false;
	}
	return true;
}

function updateBasket(prodid,quantity, pageId, raceId, basketRaceId) {
	if(basketRaceId != raceId && basketRaceId != "")
	{
		alert("You already have ticket from a different race in your cart. You can only place tickets from the same race in your cart.");
		return;
	}
	if(IsNumeric(quantity)){
		if(parseInt(quantity) < 1 || parseInt(quantity) > 99){
			alert("Please fill in a number between the range of 1 and 99.");
			return;
		}
	}	
	if (prodid != "" && IsNumeric(quantity)) {
		document.location.href="submit.asp?pageid="+pageId+"&raceid="+raceId+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity;
	} else {
		alert("Please enter a numeric value.");
	}
}

function IsNumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function deleteBasket(prodid, pageId, raceId) {
	if (prodid != "" && prodid != "0") { 
		document.location.href="submit.asp?pageid="+pageId+"&raceid="+raceId+"&submitaction=deletebasket&prodid=" + prodid; 
	}
}

function submitbasket(){
	var frm = document.forms["basketoverview"];
	/*if (frm.countrylist.selectedIndex == 0){
		alert("Please select a country from the list.");
	}
	else{*/
		frm.submit();
	//}
}

function adjustGrandTotal() {
	var frm = document.forms.basketoverview;
	if (frm != null) {
		var tot = 1*frm.hiddentotalabsolutes.value + 1*(frm.hiddentotaladdonsabsolutesonce.value) + 1*(frm.hiddentotaladdonsrelatives.value)		
		for (var i=0; i<frm.length; i++) {
			if (frm[i].name.substr(0,15)=="hiddenoptional_") {
				var id = frm[i].name.substr(15)					
				var chk = eval("frm.check_" + id);
				var txt = document.getElementById("optional_"+id);
				if(chk.checked){
					tot += parseFloat(frm[i].value);
					txt.innerHTML = frm[i].value;
				}
				else{
					txt.innerHTML = 0;
				}
			}
		}					
		document.getElementById("displaygrandtotal").innerHTML = tot;
		frm.hiddengrandtotal.value = tot;
	}
}

function SetSearchParam()
{
            document.searchbox.url.value = 'http://travel.travelocity.com/hotel/HotelCobrand.do?searchMode=city&expr_path=Y&dateReturningMonth=' + document.searchbox.dateReturningMonth.options[document.searchbox.dateReturningMonth.selectedIndex].value + '&dateReturningDay=' + document.searchbox.dateReturningDay.options[document.searchbox.dateReturningDay.selectedIndex].value + '&dateLeavingMonth=' + document.searchbox.dateLeavingMonth.options[document.searchbox.dateLeavingMonth.selectedIndex].value + '&dateLeavingDay=' + document.searchbox.dateLeavingDay.options[document.searchbox.dateLeavingDay.selectedIndex].value + '&adults=' + document.searchbox.adults.options[document.searchbox.adults.selectedIndex].value + '&children=' + document.searchbox.children.options[document.searchbox.children.selectedIndex].value + '&cityCountryCode=' + document.searchbox.cityCountryCode.options[document.searchbox.cityCountryCode.selectedIndex].value + '&city=' + document.searchbox.city.value + '&state=' + document.searchbox.state.options[document.searchbox.state.selectedIndex].value;
}

