﻿var txtBadCityArray=new Array(6);
		txtBadCityArray["ing"]=" City is a required entry.";
		txtBadCityArray["fra"]=" Ville est une entrée obligatoire.";
		txtBadCityArray["ted"]=" Die Stadt muss eingegeben werden.";
		txtBadCityArray["spa"]=" Es necesario introducir el nombre de la ciudad.";
		txtBadCityArray["ita"]=" È necessario indicare una città.";
		txtBadCityArray["nor"]=" By er et obligatorisk felt.";
		txtBadCityArray["pol"]=" Należy wprowadzić nazwę miasta";
		txtBadCityArray["jap"]=" 都市は必ず入力してください";
		txtBadCityArray["gre"]=" Απαιτείται η εισαγωγή πόλης ";
		txtBadCityArray["fin"]=" Kaupunki on annettava ";
		txtBadCityArray["cin"]=" 要求输入城市 ";
		txtBadCityArray["por"]=" A cidade é um campo de preenchimento obrigatório ";
		
function getElem(evt){
	var evt=(evt) ? evt : event;
	var elem=(evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	return elem;
}

function resetFreeSearch(wich){
	wich.form.ss.value="";
}
function resetFreeSearchTravit(wich){
	wich.form.search_txt.value="";
}

//input text
function focusOnFreeSearch(wich){
	for(var i=0; i<wich.form.city.length;i++){
		if(wich.form.city[i].value == "freeSearch")
			wich.form.city[i].checked=true;
	}
}
function focusOnFreeSearchTravit(wich){
	for(var i=0; i<wich.form.places.length;i++){
		if(wich.form.places[i].value == "freeSearch")
			wich.form.places[i].checked=true;
	}
}

//select
function changeSelectSearch(wich){
	for(var i=0; i<wich.form.city.length;i++){
		if(wich.form.city[i].value == "freeSearch")
			wich.form.city[i].checked=true;
	}
}

function writeCity(c){
	document.formHotels.city_field.value=c;
	return true
}

function validateForm(f,l,n){
	//cities	
	if(n==undefined){
		var opt;
		for (var i=0; i<f.city.length; i++) {
			if (f.city[i].checked) 
				opt=i;
		}
		
		if(f.city[opt].value=="freeSearch") 
			city=f.ss.value;
		else{
			city =f.city[opt].value;
			f.ss.value=city;
		}
		
		if(city=="" || city==undefined){
			alert(txtBadCityArray[l] );
			return false;
		}	
	}

	// dates
	assemblaDate(f,l);
}

function validateFormHotel(f,l){
	assemblaDate(f,l);
	return true;	
}

function assemblaDate(f,l){	
	d=new Date()
	mese=d.getMonth()+1;
	inM=f.mArrivo.value;
	inA=d.getFullYear();
	outM=f.mPartenza.value;
	outA=d.getFullYear();

	//checkin_monthday, checkin_year_month, checkout_monthday, checkout_year_month
	if(inM<mese) inA+=1;
	if(outM<mese) outA+=1;
		
	f.checkin_monthday.value=f.gArrivo.value;
	f.checkin_year_month.value=inA+"-"+inM;
	f.checkout_monthday.value=f.gPartenza.value;
	f.checkout_year_month.value=outA+"-"+outM;
}

// traveleurope.it
function checkFormTravel(f,l){

	var now=new Date();
	var mese=now.getMonth()+1;
	var mesearr=f.mArrivo.value;
	var annoarr=now.getFullYear();
	var mesepar=f.mPartenza.value;
	var annopar=now.getFullYear();
	var giornoarr=f.gArrivo.value;
	var giornopar=f.gPartenza.value;
	
	
	if(mesearr<mese) annoarr+=1
	if(mesepar<mese) annopar+=1
	
	if(giornoarr<10) giornoarr="0"+giornoarr;
	if(giornopar<10) giornopar="0"+giornopar;
	if(mesearr<10) mesearr="0"+mesearr;
	if(mesepar<10) mesepar="0"+mesepar;
	
	f.checkin.value=annoarr+mesearr+giornoarr;
	f.checkout.value=annopar+mesepar+giornopar;
	
	if(f.places){
		var opts=f.places;
		var opt;
		for(var i=0; i<opts.length; i++) {
			if(opts[i].checked) 
				opt=i;
		}
		
		if(opts[opt].value=="freeSearch") 
			f.place_id.value=0;
		else 
			f.place_id.value=opts[opt].value;
		//alert(f.idcity.value);	
		if(f.place_id.value=="" || f.place_id.value==undefined){
			alert(txtBadCityArray[l] );
			return false;
		}
	}
	return true;

}

	