
function onLoadRicerca(){
	document.getElementById('idPortoPartT').onchange=cambiaPortoArrivo;
	document.getElementById('dataPartenzaT').onchange=verificaMese;
	document.getElementById('mesePartenzaT').onchange=verificaData;
	document.getElementById('dataRitornoT').onchange=verificaMese;
	document.getElementById('meseRitornoT').onchange=verificaData;
}


function cambiaPortoArrivo(){
	var vPortoArrivo = document.getElementById('idPortoPartT').value;
	var idPortoDestinazione = '';
	
	if (document.getElementById('idDestinazione')!=null)
		idPortoDestinazione = document.getElementById('idDestinazione').value;
	
	if (vPortoArrivo == 'ALL')
		vPortoArrivo == 0;
	
	getComboAjax('divPortoArrivo','portiArrivoTw',vPortoArrivo,idPortoDestinazione,'idPortoArrivoT','',msgSeleziona	, languageCode);
}


function cercaTraghetti(){
	var dtCheck = true;
	if (alertWrongOnly(msgIdPortoPartT, document.getElementById('idPortoPartT').value == 'ALL') 
				|| alertWrongOnly(msgIdPortoArrivoT, document.getElementById('idPortoArrivoT').value == 'ALL') 
				|| (document.getElementById('mesePartenzaT').value == 'ALL' && (dtCheck = alertWrong(msgMesePartenzaT+msgDataPartenzaT, 'checkDate','dataPartenzaT',true)))
				|| (dtCheck && alertWrongOnly(msgMesePartenzaT+msgDataPartenzaT, document.getElementById('mesePartenzaT').value == 'ALL'))
				|| (document.getElementById('sistemazioneT')!=null && alertWrongOnly(msgSistemazioneT, document.getElementById('sistemazioneT').value == 'ALL'))
				){
					
		return false;
	}else{
		document.getElementById('sTraghetti').submit();
		
	}	
	
	
}
function verificaData(){
	if (document.getElementById('mesePartenzaT').value != 'ALL'){
		document.getElementById('dataPartenzaT').value = '';
	}
	if (document.getElementById('meseRitornoT').value != 'ALL'){
		document.getElementById('dataRitornoT').value = '';
	}
}

function verificaMese(){
	if (document.getElementById('dataPartenzaT').value != ''){
		document.getElementById('mesePartenzaT').value = 'ALL';
	}
	if (document.getElementById('dataRitornoT').value != ''){
		document.getElementById('meseRitornoT').value = 'ALL';
	}
}


function ordinaTraghetti(orderField){
	document.getElementById('orderBy').value=orderField;
	document.getElementById('sTraghetti').submit();
	
}

function prenotaCompagnia(linkPrenota){
	//if(linkPrenota.indexOf('http')==-1)
	//	linkPrenota = 'http://' + linkPrenota;
	location.href = linkPrenota;
	
}




function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		//alert(radioObj[i].checked + ' ' + radioObj[i].value);
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function prenotaAndRit(){
	//alert(document.getElementById('sistemazioneT').value);
	//alert(document.getElementById('prenotaAnd').value);
	//alert(document.getElementById('prenotaRit').value);
	
	//alert(document.sTraghetti.prenotaAnd.length);
	
	var traghettoAnd = getCheckedValue(document.sTraghetti.prenotaAnd);
	var traghettoRit = getCheckedValue(document.sTraghetti.prenotaRit);
	if (traghettoAnd!=""){
		//alert('tw_form_richiesta.php?idTraghettoT='+traghettoAnd+'&idTraghettoTRit='+traghettoRit+'&sistemazioneT='+document.getElementById('sistemazioneT').value);
		location.href = 'tw_form_richiesta.php?idTraghettoT='+traghettoAnd+'&idTraghettoTRit='+traghettoRit+'&sistemazioneT='+document.getElementById('sistemazioneT').value;
	}
	
	
	
	
}

