// JavaScript Document
function goto(where,p1) {
	document.location.href=where;
}

//cambia lingua in corsa
function changeLang(idL,p1,p2,p3) {
	/*
	formo stringa da passare a pagina settaggio lingua
	document.location.pathname|idL
	*/
	with (document.form_front) {
		if (document.location.pathname=='/' || document.location.pathname=='') {
			setlang.value='/index.php|'+idL;
		} else {
			setlang.value=document.location.pathname+'|'+idL;
		}
		//alert(setlang.value);
		action='/lang/set.php';
		submit();
	}
}

//carica combo cittā dopo aver selezionato una nazione
function setCityCombo(idN,primoTxt,idC,p1) {
	var i=0;
	var i2=0;
	var selected;
	var f=document.form_front;
	with (f) {
		//cancello tutti elementi select citta
		for(i=0;i=idCitta.options.length;i++) {   idCitta.options[0] = null   };
		
		//se ho un testo da inserire sul prim o option
		if (primoTxt!='' && idN!='') {
			idCitta.options[i2]=new Option(primoTxt, '');
			i2++;
		}
		
		//scorro tutto vettore presenti in city.js 
		for(i=0;i<citiesXcountry.length;i++) {
			//inserisco quelli della naione corretta
			if (citiesXcountry[i].idNazione==idN) {
				idCitta.options[i2]=new Option(citiesXcountry[i].citta, citiesXcountry[i].idCitta);
				if (citiesXcountry[i].idCitta==idC) idCitta.selectedIndex=i2;
				i2++;
			}
		}
		
	}
}

//carica combo cittā dopo aver selezionato una nazione
function setCityCombo_joinus(idN,primoTxt,idC,p1) {
	var i=0;
	var i2=0;
	var selected;
	var f=document.form_front;
	with (f) {
		//cancello tutti elementi select citta
		for(i=0;i=idCitta_joinus.options.length;i++) {   idCitta_joinus.options[0] = null   };
		
		//se ho un testo da inserire sul prim o option
		if (primoTxt!='' && idN!='') {
			idCitta_joinus.options[i2]=new Option(primoTxt, '');
			i2++;
		}
		
		//scorro tutto vettore presenti in city.js 
		for(i=0;i<citiesXcountry.length;i++) {
			//inserisco quelli della naione corretta
			if (citiesXcountry[i].idNazione==idN) {
				idCitta_joinus.options[i2]=new Option(citiesXcountry[i].citta, citiesXcountry[i].idCitta);
				if (citiesXcountry[i].idCitta==idC) idCitta.selectedIndex=i2;
				i2++;
			}
		}
		
	}
}

//ricerca strutture
/*dataOggi= 2008-9-25*/
function search_in_site(dataOggi,p1,p2) {
	//alert('cerco si cerco');
	var strErr='';
	var arrDataOggi;
	with (document.form_front) {
		//citta
		setElementStyle('idCitta','input_ok','','');
		if (idCitta.options.length<=0 || idCitta.options[idCitta.selectedIndex].value=='') {
			strErr+=gbl_search_citta;
			setElementStyle('idCitta','input_ko','','');
		}
		//data arrivo
		setElementStyle('arrivo_d','space02','','');
		setElementStyle('arrivo_m','space02','','');
		setElementStyle('arrivo_y','space02','','');
		if (!checkDateFormat(arrivo_d.value,arrivo_m.value,arrivo_y.value,'','')) {
			strErr+=gbl_search_data;
			setElementStyle('arrivo_d','space02 input_ko','','');
			setElementStyle('arrivo_m','space02 input_ko','','');
			setElementStyle('arrivo_y','space02 input_ko','','');
		} else {
			arrDataOggi=dataOggi.split('-');
			//alert(arrDataOggi[0]+'-'+arrDataOggi[1]+'-'+arrDataOggi[2]);
			//alert(arrivo_y.value+'-'+arrivo_m.value+'-'+arrivo_d.value);
			if (!data1MINdata2(arrDataOggi[2],arrDataOggi[1],arrDataOggi[0],arrivo_d.value,arrivo_m.value,arrivo_y.value,'','','')) {
				strErr+=gbl_search_data;
				setElementStyle('arrivo_d','space02 input_ko','','');
				setElementStyle('arrivo_m','space02 input_ko','','');
				setElementStyle('arrivo_y','space02 input_ko','','');
			}
		}
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='/search/results.php';
			submit();
		}
		
	}

}

//ricerca x top destinations
function topdestinations_search(idC,p1,p2) {
	with (document.form_front) {
		//citta
		idCitta_top.value=idC;
		//alert(idCitta_top.value);
		action='/search/results.php';
		submit();
		
	}

}

//controllo form iscrizione
function joinus_checkForm(p1,p2) {
	//alert('cerco si cerco');
	var strErr='';
	
	var str_inside='';
	
	var arrDataOggi;
	with (document.form_front) {
		//struttura
		setElementStyle('struttura','input_ok','','');
		if (struttura.value=='') {
			strErr+=gbl_join_struttura;
			setElementStyle('struttura','input_ko','','');
		}
		//citta
		setElementStyle('tel','input_ok','','');
		if (tel.value=='') {
			strErr+=gbl_join_tel;
			setElementStyle('tel','input_ko','','');
		}
		//citta
		setElementStyle('idCitta_joinus','input_ok','','');
		if (idCitta_joinus.options.length<=0 || idCitta_joinus.options[idCitta_joinus.selectedIndex].value=='') {
			strErr+=gbl_join_citta;
			setElementStyle('idCitta_joinus','input_ko','','');
		}
		//email
		setElementStyle('email','input_ok','','');
		if (!checkEmailFormat(email.value)) {
			strErr+=gbl_join_email;
			setElementStyle('email','input_ko','','');
		}
		
		//username
		setElementStyle('username','input_ok','','');
		if (username.value=='') {
			strErr+=gbl_join_username;
			setElementStyle('username','input_ko','','');
		}
		
		//psw
		setElementStyle('psw','input_ok','','');
		if (psw.value=='' || psw.value!=psw_confirm.value || psw.value.length<5) {
			strErr+=gbl_join_psw;
			setElementStyle('psw','input_ko','','');
		} else {
			//controllo psw in db
			var parametri='psw='+psw.value;
			
			document.getElementById("aj_operation").innerHTML='';
			//getCode("checkPsw.php", 'aj_operation', parametri, "check_aj_operation_psw();","","","");
			str_inside=getCode_sincrono("checkPsw.php", 'aj_operation', parametri, "","","","");
			if (str_inside!='OK') strErr+=str_inside;
				
		}
		
		
		//contract
		setElementStyle('contract_txt','input_ok','','');
		if (!contract[0].checked) {
			strErr+=gbl_join_contract;
			setElementStyle('contract_txt','input_ko','','');
		}
		
		//privacy
		setElementStyle('privacy_txt','input_ok','','');
		if (!privacy[0].checked) {
			strErr+=gbl_join_privacy;
			setElementStyle('privacy_txt','input_ko','','');
		}
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='save.php';
			submit();
		}
		
	}

}

//vado a dettaglio testi
function viewText(idT,p1) {
	with (document.form_front) {
		testo.value=idT;
		//alert(setlang.value);
		action='/text/index.php';
		submit();
	}
}

//vado a adv with us che č particolare.. che č meglio
function goToAdv(idT,p1) {
	with (document.form_front) {
		testo.value=idT;
		//alert(setlang.value);
		action='/adv/index.php';
		submit();
	}
}


function booknow01(idS,p1,p2) {
	with (document.form_front) {
		booknow_idStruttura.value=idS;
		
		action='/search/details.php';
		submit();
	}
}

function preventivo(p1,p2,p3) {
	var parametri=formCollection(document.form_front);
	
	getCode("details_report.php", 'details_report', parametri, "","","","");
}

function metti_logo_fisso(p1,p2,p3) {
	// mette il logo fisso per evitare che buchi i layer grigio del filmato
	var parametri=formCollection(document.form_front);
	
	getCode("logo_fisso.php", 'header02', parametri, "","","","");
}

function unlock_card(p1,p2,p3) {
	var parametri=formCollection(document.form_front);
	
	getCode("prenotazione_box_creditcard.php", 'box_credit_card', parametri, "","","","");
}

function booknow02(p1,p2,p3) {
	with (document.form_front) {
		
		action='/store/shoppingcart.php';
		submit();
	}
}

function setAllType(what) {
	with (document.form_front) {
		if (what=='all') {
			if (idCategoria_all.checked) {
				//seleziono tutte
				for(i=0;i<idCategoria.length;i++) {
					idCategoria[i].checked=true;
				}
			} else {
				//deseleziono tutte 
				for(i=0;i<idCategoria.length;i++) {
					idCategoria[i].checked=false;
				}
			}
		} else {
			idCategoria_all.checked=false;
			
		}
	}
}

function riempi(p1,p2,p3) {
	document.form_front.nome.value='nome prova';
	document.form_front.cognome.value='cognome prova';
	document.form_front.idNazioneUtente.value='9';
	document.form_front.email.value='email@prova.it';
	document.form_front.tel.value='tel prova';
	
	document.form_front.card_number.value='1234567890123456';
	document.form_front.card_cvv2.value='123';
	document.form_front.card_holder_name.value='card_holder_name';

	document.form_front.card_expiry_month.value='9';
	document.form_front.card_expiry_year.value='2009';
	
	payment();	
}

function payment(p1,p2,p3) {
	var strErr='';
	with (document.form_front) {
		//nome
		setElementStyle('nome','input_ok','','');
		if (nome.value=='') {
			strErr+=gbl_shopping_nome;
			setElementStyle('nome','input_ko','','');
		}
		//cognome
		setElementStyle('cognome','input_ok','','');
		if (cognome.value=='') {
			strErr+=gbl_shopping_cognome;
			setElementStyle('cognome','input_ko','','');
		}
		//idNazione
		setElementStyle('idNazioneUtente','input_ok','','');
		if (idNazioneUtente.options[idNazioneUtente.selectedIndex].value=='') {
			strErr+=gbl_shopping_idNazione;
			setElementStyle('idNazioneUtente','input_ko','','');
		}
		//email
		setElementStyle('email','input_ok','','');
		if (!checkEmailFormat(email.value)) {
			strErr+=gbl_shopping_email;
			setElementStyle('email','input_ko','','');
		}		
		//tel
		setElementStyle('tel','input_ok','','');
		if (tel.value=='') {
			strErr+=gbl_shopping_tel;
			setElementStyle('tel','input_ko','','');
		}


		//card_number
		setElementStyle('card_number','input_ok','','');
		if (tel.value=='') {
			strErr+='Attention! Field \'Card Number\' required\n';
			setElementStyle('card_number','input_ko','','');
		}
		//card_cvv2
		setElementStyle('card_cvv2','input_ok','','');
		if (tel.value=='') {
			strErr+='Attention! Field \'Card CVV2\' required\n';
			setElementStyle('card_cvv2','input_ko','','');
		}
		//card_holder_name
		setElementStyle('card_holder_name','input_ok','','');
		if (tel.value=='') {
			strErr+='Attention! Field \'Card Holder Name\' required\n';
			setElementStyle('card_holder_name','input_ko','','');
		}
		//card_expiry_month
		setElementStyle('card_expiry_month','input_ok','','');
		if (tel.value=='') {
			strErr+='Attention! Field \'Card Expiry Month\' required\n';
			setElementStyle('card_expiry_month','input_ko','','');
		}
		//card_expiry_year
		setElementStyle('card_expiry_year','input_ok','','');
		if (tel.value=='') {
			strErr+='Attention! Field \'Card Expiry Year\' required\n';
			setElementStyle('card_expiry_year','input_ko','','');
		}
				
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='buy.php';
			submit();
		}
	}
}

function review_send(p1,p2,p3) {
	var strErr='';
	var msg=gbl_msg_review_send;
	with (document.form_front) {		
		if (window.confirm(msg)) {
			action='save.php';
			submit();
		}
	}
}

//naviga risultati ricerca strutture
function gall_nav(myPage, p1) {
	with (document.form_front) {
		page_gallery.value=myPage;
		
		var parametri=formCollection(document.form_front);
		getCode("gallery.php", 'gallery_box', parametri, "","","","");
	}
}

//naviga risultati 
function rev_nav(myPage, p1) {
	with (document.form_front) {
		page_rev.value=myPage;
		
		var parametri=formCollection(document.form_front);
		getCode("review.php", 'box_review', parametri, "","","","");
	}
}

function groupbooking(idS,p1,p2) {
	with (document.form_front) {
		booknow_idStruttura.value=idS;
		
		action='/search/groupbooking.php';
		submit();
	}
}

function groupbooking_request(dataOggi,p2,p3) {
	var strErr='';
	with (document.form_front) {
		//nome
		setElementStyle('nome','input_ok','','');
		if (nome.value=='') {
			strErr+=gbl_shopping_nome;
			setElementStyle('nome','input_ko','','');
		}
		//cognome
		setElementStyle('cognome','input_ok','','');
		if (cognome.value=='') {
			strErr+=gbl_shopping_cognome;
			setElementStyle('cognome','input_ko','','');
		}
		//idNazione
		setElementStyle('idNazioneUtente','input_ok','','');
		if (idNazioneUtente.options[idNazioneUtente.selectedIndex].value=='') {
			strErr+=gbl_shopping_idNazione;
			setElementStyle('idNazioneUtente','input_ko','','');
		}
		//email
		setElementStyle('email','input_ok','','');
		if (!checkEmailFormat(email.value)) {
			strErr+=gbl_shopping_email;
			setElementStyle('email','input_ko','','');
		}		
		//tel
		setElementStyle('tel','input_ok','','');
		if (tel.value=='') {
			strErr+=gbl_shopping_tel;
			setElementStyle('tel','input_ko','','');
		}
				
		//data arrivo
		setElementStyle('gb_arrivo_d','space02','','');
		setElementStyle('gb_arrivo_m','space02','','');
		setElementStyle('gb_arrivo_y','space02','','');
		if (!checkDateFormat(gb_arrivo_d.value,gb_arrivo_m.value,gb_arrivo_y.value,'','')) {
			strErr+=gbl_search_data;
			setElementStyle('gb_arrivo_d','space02 input_ko','','');
			setElementStyle('gb_arrivo_m','space02 input_ko','','');
			setElementStyle('gb_arrivo_y','space02 input_ko','','');
		} else {
			arrDataOggi=dataOggi.split('-');
			//alert(arrDataOggi[0]+'-'+arrDataOggi[1]+'-'+arrDataOggi[2]);
			//alert(arrivo_y.value+'-'+arrivo_m.value+'-'+arrivo_d.value);
			if (!data1MINdata2(arrDataOggi[2],arrDataOggi[1],arrDataOggi[0],gb_arrivo_d.value,gb_arrivo_m.value,gb_arrivo_y.value,'','','')) {
				strErr+=gbl_search_data;
				setElementStyle('gb_arrivo_d','space02 input_ko','','');
				setElementStyle('gb_arrivo_m','space02 input_ko','','');
				setElementStyle('gb_arrivo_y','space02 input_ko','','');
			}
		}
		//privacy
		setElementStyle('privacy_txt','input_ok','','');
		if (!privacy[0].checked) {
			strErr+=gbl_join_privacy;
			setElementStyle('privacy_txt','input_ko','','');
		}
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='groupbooking_send.php';
			submit();
		}
		
	}
}

function payment_groupbooking(p1,p2,p3) {
	var strErr='';
	with (document.form_front) {
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='/store/buygroup.php';
			submit();
		}
	}
}

function payment_adv(p1,p2,p3) {
	var strErr='';
	with (document.form_front) {
		
		if (strErr!='') {
			alert(strErr);
		} else {
			action='/store/buyadv.php';
			submit();
		}
	}
}

function adv_other(p1,p2,p3) {
	var strErr='';
	with (document.form_front) {
		
		action='adv_other.php';
		submit();
	}
}

function adv_hostels(p1,p2,p3) {
	var strErr='';
	with (document.form_front) {
		
		action='adv_property.php';
		submit();
	}
}

function check_comment_char(nChars) {
	with (document.form_front) {
		if (commento.value.length>nChars) {
			commento.value=commento.value.substring(0,nChars);
		}
	}
}

function viewPropertyDetails(idP,p1) {
	with (document.form_front) {
		booknow_idStruttura.value=idP;
		
		action='/search/details_property.php';
		submit();
	}
}

