function verificaEmail(posta){
	var c;
	var ok=0;
	for(i=0; i < posta.length; i++){
		c=posta.charAt(i);
		if(c == '@'){
			ok++;
		}
	}
	if (ok > 1){
		return false;
	}
	if(posta.indexOf('@', 0) == -1)
	{
		return false;
	}
	else if(posta.indexOf('@', 0) == 0 || posta.indexOf('@', 0) == posta.length-1)
	{
		return false;
	}
	else if(posta.indexOf('.', 0) == 0 || posta.indexOf('.', 0) == posta.length-1)
	{
		return false;
	}
	else if(posta.indexOf('.', 0) == -1)
	{
		return false;
	}
	return true;
}

function verifyform(){
	if (document.message.name.value == ''
	|| document.message.email.value == ''
	|| document.message.question.value == '') 
	{
		alert ("Please, fill all the fields.");
		return false;
	}
	if (!verificaEmail(document.message.email.value)){
		alert ("The email address seems to be invalid, please check it.");
		return false;
	}
	document.message.submit();
	return true;
}

function verifybooking(step,id){	// l'opzione "id"  usata solo se si ritorna allo step 1 dalla pagina di step 2
	if (step == 1){
		if (id != ''){
			str="booking.php?step=1&from_date="+document.booking.from_date.value+
			"&to_date="+document.booking.to_date.value+
			"&n_rooms="+document.booking.n_rooms.value+
			"&from_year="+document.booking.from_year.value+
			"&from_month="+document.booking.from_month.value+
			"&from_day="+document.booking.from_day.value+
			"&to_year="+document.booking.to_year.value+
			"&to_month="+document.booking.to_month.value+
			"&to_day="+document.booking.to_day.value+
			"&delete="+id;
		}else{
			if ((document.booking.from_day.value == document.booking.to_day.value)
				&& (document.booking.from_month.value == document.booking.to_month.value)
				&& (document.booking.from_year.value == document.booking.to_year.value)){
				alert ("Check In and Check Out dates are identical.");
				return false;
			}
			if (document.booking.from_day.value == ''
				|| document.booking.from_month.value == ''
				|| document.booking.from_year.value == ''){
				alert ("Please, complete the Check In date.");
				return false;
			}
			if (document.booking.to_day.value == ''
				|| document.booking.to_month.value == ''
				|| document.booking.to_year.value == ''){
				alert ("Please, complete the Check Out date.");
				return false;
			}
			if (parseInt(document.booking.from_year.value+document.booking.from_month.value+document.booking.from_day.value) > parseInt(document.booking.to_year.value+document.booking.to_month.value+document.booking.to_day.value)){
				alert ("Please, check the dates.");
				return false;
			}
			
			if (document.booking.n_rooms.value == ''){
				alert ("How many rooms do You need ?");
				document.booking.n_rooms.focus;
				return false;
			}
			str="booking.php?step=1"+
			"&from_date="+document.booking.from_year.value+
			"-"+document.booking.from_month.value+
			"-"+document.booking.from_day.value+
			"&to_date="+document.booking.to_year.value+
			"-"+document.booking.to_month.value+
			"-"+document.booking.to_day.value+
			"&n_rooms="+document.booking.n_rooms.value+
			"&from_year="+document.booking.from_year.value+
			"&from_month="+document.booking.from_month.value+
			"&from_day="+document.booking.from_day.value+
			"&to_year="+document.booking.to_year.value+
			"&to_month="+document.booking.to_month.value+
			"&to_day="+document.booking.to_day.value;
		}
		parent.location.href=str;
	}
	if (step == 2){
		str="booking.php?step=2&from_date="+document.booking.from_date.value+
		"&to_date="+document.booking.to_date.value+
		"&n_rooms="+document.booking.n_rooms.value+
		"&n_nights="+document.booking.n_nights.value+
		"&rate="+document.booking.rate.value+
		"&total="+document.booking.total.value+
		"&b_rooms="+document.booking.b_rooms.value;
		parent.location.href=str;
	}
	if (step == 3){
		if (document.booking.guest_name.value == ''){
			alert ("Please, write your name");
			document.booking.guest_name.focus;
			return false;
		}
		// Tutto ci˜ che  commentato  stato richiesto da loro
		/*
		if (document.booking.guest_street.value == ''){
			alert ("Please, write the name of the street where you live");
			document.booking.guest_street.focus;
			return false;
		}
		if (document.booking.guest_city.value == ''){
			alert ("Please, write the name of the city where you live");
			document.booking.guest_city.focus;
			return false;
		}
		if (document.booking.guest_province.value == ''){
			alert ("Please, write the province where you live");
			document.booking.guest_province.focus;
			return false;
		}
		if (document.booking.guest_postalcode.value == ''){
			alert ("Please, write the postal code of the city where you live");
			document.booking.guest_postalcode.focus;
			return false;
		}
		if (document.booking.guest_country.value == ''){
			alert ("Please, select the country where you live");
			document.booking.guest_country.focus;
			return false;
		}
		*/
		if (document.booking.guest_email.value == ''){
			alert ("Please, type your email address");
			document.booking.guest_email.focus;
			return false;
		}
		if (!verificaEmail(document.booking.guest_email.value)){
			alert ("The email address you typed seems not correct, please check it.");
			document.booking.guest_email.focus;
			return false;
		}
		if (document.booking.guest_email2.value == ''){
			alert ("Please, re-type your email address");
			document.booking.guest_email2.focus;
			return false;
		}
		if (!verificaEmail(document.booking.guest_email2.value)){
			alert ("The email address you re-typed seems not correct, please check it.");
			document.booking.guest_email2.focus;
			return false;
		}
		if (document.booking.guest_email.value != document.booking.guest_email2.value){
			alert ("The two email addresses are different, please check them");
			document.booking.guest_email.focus;
			return false;
		}
		if (document.booking.guest_telephone.value == '' && document.booking.guest_fax.value == ''){
			alert ("Please, write telephone and/or fax number");
			document.booking.guest_telephone.focus;
			return false;
		}
		/*
		if (!document.booking.guest_terms.checked){
			alert ("Please, read carefully the Terms and Conditions document");
			document.booking.guest_terms.focus;
			return false;
		}
		QUESTO E' STATO TOLTO SU LORO RICHIESTA
		if (!document.booking.guest_privacy.checked){
			alert ("Please, read carefully the Privacy Terms");
			document.booking.guest_privacy.focus;
			return false;
		}
		*/
		
		str="booking.php?step=3&from_date="+document.booking.from_date.value+
		"&to_date="+document.booking.to_date.value+
		"&n_rooms="+document.booking.n_rooms.value+
		"&n_nights="+document.booking.n_nights.value+
		"&rate="+document.booking.rate.value+
		"&total="+document.booking.total.value+
		"&b_rooms="+document.booking.b_rooms.value+
		"&guest_name="+document.booking.guest_name.value+
		"&guest_street="+document.booking.guest_street.value+
		"&guest_city="+document.booking.guest_city.value+
		"&guest_province="+document.booking.guest_province.value+
		"&guest_postalcode="+document.booking.guest_postalcode.value+
		"&guest_country="+document.booking.guest_country.value+
		"&guest_email="+document.booking.guest_email.value+
		"&guest_telephone="+document.booking.guest_telephone.value+
		"&guest_fax="+document.booking.guest_fax.value+
		"&guest_note="+document.booking.guest_note.value+
		//"&guest_privacy="+document.booking.guest_privacy.checked+
		"&lastid="+document.booking.lastid.value;
		parent.location.href=str;
	}
}

/*
function fixCost(){
	?action=<? echo $_REQUEST["action"]; ?>&pre=<? echo $cod_pre; ?>&voc=<? echo $row["prv_indice"]; ?>&data=<? echo str_pad($dd,2,"0",STR_PAD_LEFT)."-".str_pad($this_month,2,"0",STR_PAD_LEFT)."-".$this_year; ?>','<? echo $file_title; ?>','width=550,height=300,scrollbars');">
	str="dettaglio.php?action=prenotazioni&modifica=SI"


}
*/