function cm(){
	var frm = document.forms.contactus;	
	var res = false;
	if(frm.tfname.value == "")
		alert("Per favore inserisca il suo nome.");
	else if(frm.tfinfo.value == "" || frm.tfinfo.value == null)
		alert("Potete effettuare domande o chiedere chiarimenti nello spazio ad esso dedicato.");
	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("L'indirizzo email che avete inserito non e' corretto.");
		return false;
	}
	return true;
}

function updateBasket(prodid,quantity, pageId, raceId, basketRaceId) {
	if(basketRaceId != raceId && basketRaceId != "")
	{
		alert("Avete gia' effettuato un ordine per una gara differente, potete acquistare altri biglietti solo per la stessa gara. Se volete creare un ordine per una nuova gara, e' necessario che effettuiate un nuovo ordine.");
		return;
	}
	if(IsNumeric(quantity)){
		if(parseInt(quantity) < 1 || parseInt(quantity) > 99){
			alert("Per favore inserite un numero compreso tra 1 e 99.");
			return;
		}
	}
	if (prodid != "" && IsNumeric(quantity)) {
		document.location.href="submit.asp?pageid="+pageId+"&raceid="+raceId+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity;
	} else {
		alert("Inserisca la quantita' di biglietti desiderata con un valore numerico.");
	}
}

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;
}