var opts = new Array();
opts[0] = "fopt";
opts[1] = "hopt";
opts[2] = "copt";
opts[3] = "fhopt";
opts[4] = "fhcopt";
opts[5] = "fcopt";

var dests = new Array();
dests[0] = "fdest";
dests[1] = "hdest";
dests[2] = "cdest";
dests[3] = "pdest";

var deplbl = new Array();
deplbl[0] = "lcdepart";
deplbl[1] = "ldepart";

var retlbl = new Array();
retlbl[0] = "lcreturn";
retlbl[1] = "lreturn";

var retd = new Array();
retd[0] = "ckoutdt";
retd[1] = "tdate";

var fromd = new Array();
fromd[0] = "ckindt";
fromd[1] = "fdate";

var fromt = new Array();
fromt[0] = "ftime";
fromt[1] = "putime";

var rett = new Array();
rett[0] = "ttime";
rett[1] = "dotime";

var adus = new Array();
adus[0] = "aduflight";
adus[1] = "aduhols";

function SyncAdu(val){
	var d = document.Wiz;
	SetSelectValue(d.NumAdultF, val);
	SetSelectValue(d.NumAdultH, val);
	d.NumAdult.value = val;
}

function SetSelectValue(obj,val){if (obj != null){for (var i=0;i<obj.options.length;i++){if (obj.options[i].value == val){obj.selectedIndex = i; break;}}}}

function HandleWiz(type){
	var d = document.Wiz;
	switch(type){
		
		case "flight":
		case "flightlink":
			d.GOTO.value = "EXPFLTWIZ";
			ShowFromArray("fopt", opts);
			ShowFromArray("fdest", dests);
			ShowFromArray("ldepart", deplbl);
			ShowFromArray("aduflight", adus);
			d.NumAdult.value = d.NumAdultF.options[d.NumAdultF.selectedIndex].value;
			setChecked('rfo',true);
			ShowLayer("space");
			break;
		
		case "hotel":
		case "hotellink":
			d.GOTO.value = "HOTSEARCH"; d.SearchType.value = "DESTINATION";
			ShowFromArray("hopt", opts);
			ShowFromArray("hdest", dests);
			ShowFromArray("ckoutdt", retd); ShowFromArray("ckindt", fromd);
			ShowFromArray("", deplbl); ShowFromArray("", retlbl);
			ShowFromArray("", rett);ShowFromArray("", fromt);
			HideLayer("dfrom");HideLayer("ftime");HideLayer("putime");
			ShowFromArray("aduhols", adus);
			HideLayer("senpax");
			d.NumAdult.value = d.NumAdultH.options[d.NumAdultH.selectedIndex].value;
			setChecked('rho',true);
			ShowLayer("space");
			break;
		case "car":
		case "carlink":
			d.GOTO.value = "CARSEARCH"; d.SearchType.value = "AIRPORT";
			ShowFromArray("copt", opts);
			ShowFromArray("cdest", dests);
			ShowFromArray("lcdepart", deplbl);
			ShowFromArray("lcreturn", retlbl);
			ShowLayer("cclass");
			ShowLayer("cardisc");
			ShowFromArray("fdate", fromd);
			ShowFromArray("tdate", retd);
			ShowFromArray("dotime", rett);ShowFromArray("putime", fromt);
			HideLayer("dfrom");
			HideLayer("pax");
			setChecked('rco',true);
			break;
		case "flighthotel":
		case "flighthotellink":
			ShowFromArray("fhopt", opts);
			ShowFromArray("aduhols", adus);
			d.NumAdult.value = d.NumAdultH.options[d.NumAdultH.selectedIndex].value;
			d.PackageType.value = 2; // find out what this should be
			setChecked('rfh',true);
			ShowLayer("space");
			break;
		case "flighthotelcar":
		case "flighthotelcarlink":
			ShowFromArray("fhcopt", opts);
			ShowFromArray("aduhols", adus);
			d.NumAdult.value = d.NumAdultH.options[d.NumAdultH.selectedIndex].value;
			d.PackageType.value = 1; // find out what this should be
			setChecked('rfhc',true);
			break;
		case "flightcar":
		case "flightcarlink":
			ShowFromArray("fcopt", opts);
			ShowFromArray("aduhols", adus);
			d.NumAdult.value = d.NumAdultH.options[d.NumAdultH.selectedIndex].value;
			d.PackageType.value = 5; // find out what this should be
			setChecked('rfc',true);
			break;
	}
	
	if (type == "hotellink" || type == "hotel"){
		document.getElementById("returndets1").style.display = "none";
		document.getElementById("returndets2").style.display = "none";
	}else{
		document.getElementById("returndets1").style.display = "block";
		document.getElementById("returndets2").style.display = "block";
	}
	
	if (type != "car" && type != "carlink"){HideLayer("cclass"); ShowLayer("pax");}
	if (type == "flight" || type == "hotel" || type == "flighthotel" || type == "flightlink" || type == "hotellink" || type == "flighthotellink"){ShowLayer("space");}else{HideLayer("space");}
	
	if (type == "car" || type == "carlink" || type == "flightcar" || type == "flightcarlink" || type == "flighthotelcar" || type == "flighthotelcarlink"){ShowLayer("cardisc");}else{HideLayer("cardisc");}
	
	if (type == "flightcar" || type == "flightcarlink" || type == "flighthotel" || type == "flighthotellink" || type == "flighthotelcar" || type == "flighthotelcarlink" || type == "flight" || type == "flightlink"){
		if (type != "flight" && type != "flightlink"){
			d.GOTO.value = "PACKAGEWIZ";
			ShowFromArray("pdest", dests);
			ShowFromArray("ldepart", deplbl);
		}
		ShowFromArray("fdate", fromd);
		ShowFromArray("tdate", retd);
		ShowFromArray("lreturn", retlbl);
		ShowFromArray("ttime", rett);ShowFromArray("ftime", fromt);
		ShowLayer("dfrom");
		ShowLayer("senpax");
	}
	
	if (type == "flightlink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=FLIGHTWIZ&eapid=" + d.EAPID.value + "&NoSubmit=1&DepAirpName=" + d.FrAirport.value + "&DestAirpName=" + d.ToAirport.value + "&DepDate=" + d.FromDate.value + "&ReturnDate=" + d.ToDate.value + "&shps=1&NumAdult=" + d.NumAdult.value; + "&NumChild=" + d.NumChild.options[d.NumChild.selectedIndex].value + "&NumSenior=" + d.NumSenior.options[d.NumSenior.selectedIndex].value + "&DepTime=" + d.ToTime.options[d.ToTime.selectedIndex].value + "&ReturnTime=" + d.FromTime.options[d.FromTime.selectedIndex].value;
	}else if (type == "hotellink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=HOTLAUNCH&eapid=" + d.EAPID.value + "&MoreOptions=1&NoSubmit=1&CityName=" + d.CityName.value + "&InDate=" + d.InDate.value + "&OutDate=" + d.OutDate.value + "&NumAdult=" + d.NumAdult.value + "&NumChild=" + d.NumChild.options[d.NumChild.selectedIndex].value + "&NumSenior=" + d.NumSenior.options[d.NumSenior.selectedIndex].value;
	}else if (type == "carlink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=CARWIZD&eapid=" + d.EAPID.value + "&PickupLoc=" + d.PickupLoc.value +  "&PickUpDate=" + d.FromDate.value + "&DropOffDate=" + d.ToDate.value + "&PickUpTime=" + d.PickUpTime.value + "&DropTime=" + d.DropTime.value + "&CarClass=" + d.Class.options[d.Class.selectedIndex].value;
	}else if (type == "flighthotellink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + d.EAPID.value + "&PackageType=2&NoSubmit=1&FrAirport=" + d.FrAirport.value + "&DestName=" + d.ToAirport.value + "&FromDate=" + d.FromDate.value + "&ToDate=" + d.ToDate.value + "&NumAdult=" + d.NumAdult.value + "&NumChild=" + d.NumChild.options[d.NumChild.selectedIndex].value + "&NumSenior=" + d.NumSenior.options[d.NumSenior.selectedIndex].value + "&ToTime=" + d.ToTime.options[d.ToTime.selectedIndex].value + "&FromTime=" + d.FromTime.options[d.FromTime.selectedIndex].value;
	}else if (type == "flighthotelcarlink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + d.EAPID.value + "&PackageType=1&NoSubmit=1&FrAirport=" + d.FrAirport.value + "&DestName=" + d.ToAirport.value + "&FromDate=" + d.FromDate.value + "&ToDate=" + d.ToDate.value + "&NumAdult=" + d.NumAdult.value + "&NumChild=" + d.NumChild.options[d.NumChild.selectedIndex].value + "&NumSenior=" + d.NumSenior.options[d.NumSenior.selectedIndex].value + "&ToTime=" + d.ToTime.options[d.ToTime.selectedIndex].value + "&FromTime=" + d.FromTime.options[d.FromTime.selectedIndex].value;
	}else if (type == "flightcarlink"){
		window.location.href = "http://www.expedia.it/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + d.EAPID.value + "&PackageType=5&NoSubmit=1&FrAirport=" + d.FrAirport.value + "&DestName=" + d.DestName.value + "&FromDate=" + d.FromDate.value + "&ToDate=" + d.ToDate.value + "&NumAdult=" + d.NumAdult.value + "&NumChild=" + d.NumChild.options[d.NumChild.selectedIndex].value + "&NumSenior=" + d.NumSenior.options[d.NumSenior.selectedIndex].value + "&ToTime=" + d.ToTime.options[d.ToTime.selectedIndex].value + "&FromTime=" + d.FromTime.options[d.FromTime.selectedIndex].value;
	}
}

function SyncChildAges(){
	var d = document.Wiz;
	d.Age1.value = d.child1Age.options[d.child1Age.selectedIndex].value;
	d.Age2.value = d.child2Age.options[d.child2Age.selectedIndex].value;
	d.Age3.value = d.child3Age.options[d.child3Age.selectedIndex].value;
	d.Age4.value = d.child4Age.options[d.child4Age.selectedIndex].value;
	d.Age5.value = d.child5Age.options[d.child5Age.selectedIndex].value;
	d.Age6.value = d.child6Age.options[d.child6Age.selectedIndex].value;
}

function SyncDestinations(val){
	var d = document.Wiz;
	d.ToAirport.value = val;
	d.DestName.value = val;
	d.CityName.value = val;
	d.PickupLoc.value = val;
}

function SyncRetDates(val){
	var d = document.Wiz;
	d.OutDate.value = val;
	d.ToDate.value = val;
}

function SyncDepDates(val){
	var d = document.Wiz;
	d.FromDate.value = val;
	d.InDate.value = val;
}

function ShowFromArray(id, s){for(i=0;i<s.length;i++){if (id == s[i]){ShowLayer(s[i]);}else{HideLayer(s[i]);}}}

function ShowLayer(id){if (document.getElementById)document.getElementById(id).style.display = "block"; else document.all[id].style.display = "block";}

function HideLayer(id){if (document.getElementById)document.getElementById(id).style.display = "none"; else document.all[id].style.display = "none";}
/* Solo se bisogna visualizzare l'eta dei bambini */
function ShowChildAges(val){
	if (val == 0 || val == null){HideLayer("childages");}else{ShowLayer("childages");}
	for(i=1;i<7;i++){if (i <= val){ShowLayer("tdChild" + i);}else{HideLayer("tdChild" + i);}}
}

function setChecked(elementName,value){return(document.getElementById(elementName).checked = value);}

/******************* SCRIPT GLOBAL *******************/

function attivaVoli () {
	document.getElementById("fopt").style.display = "inline";
	document.getElementById("hopt").style.display = "none";
	document.getElementById("copt").style.display = "none";
	document.getElementById("fhopt").style.display = "none";
	
	document.frmExpedia.partenza.disabled=false;
	document.frmExpedia.partenza.value='';
	document.frmExpedia.GOTO.value = 'EXPFLTWIZ';
}
function attivaHotel () {
	document.getElementById("fopt").style.display = "none";
	document.getElementById("hopt").style.display = "inline";
	document.getElementById("copt").style.display = "none";
	document.getElementById("fhopt").style.display = "none";
	
	document.frmExpedia.partenza.value='Solo la destinazione';
	document.frmExpedia.partenza.disabled=true;
	document.frmExpedia.GOTO.value = 'HOTSEARCH';
}
function attivaViaggi () {
	document.getElementById("fopt").style.display = "none";
	document.getElementById("hopt").style.display = "none";
	document.getElementById("copt").style.display = "none";
	document.getElementById("fhopt").style.display = "inline";
	
	document.frmExpedia.partenza.disabled=false;
	document.frmExpedia.partenza.value='';
	document.frmExpedia.GOTO.value = 'PACKAGEWIZ';
}

function attivaAuto () {
	document.getElementById("fopt").style.display = "none";
	document.getElementById("hopt").style.display = "none";
	document.getElementById("copt").style.display = "inline";
	document.getElementById("fhopt").style.display = "none";
	
	document.frmExpedia.partenza.value='Solo la destinazione';
	document.frmExpedia.partenza.disabled=true;
	document.frmExpedia.GOTO.value = 'CARSEARCH';
}

function processaForm() {
        switch (document.frmExpedia.GOTO.value) {
        case 'HOTSEARCH':	// hotel
		document.frmExpedia.CityName.value = document.frmExpedia.destinazione.value;
		document.frmExpedia.InDate.value = document.frmExpedia.dataInizio.value;
		document.frmExpedia.OutDate.value = document.frmExpedia.dataFine.value;
		document.frmExpedia.NumChild.value = document.frmExpedia.NumInfant.value;
	break
        case 'PACKAGEWIZ':	// viaggi
		document.frmExpedia.FrAirport.value =  document.frmExpedia.partenza.value;
		document.frmExpedia.DestName.value = document.frmExpedia.destinazione.value;
		document.frmExpedia.FromDate.value = document.frmExpedia.dataInizio.value;
		document.frmExpedia.ToDate.value = document.frmExpedia.dataFine.value;
		document.frmExpedia.NumChild.value = document.frmExpedia.NumInfant.value;
	break
	case 'CARSEARCH': 	// auto
		document.frmExpedia.PickUpLoc.value =  document.frmExpedia.destinazione.value;
		document.frmExpedia.FromDate.value = document.frmExpedia.dataInizio.value;
		document.frmExpedia.ToDate.value = document.frmExpedia.dataFine.value;
		break
        default:		// voli
		document.frmExpedia.FrAirport.value =  document.frmExpedia.partenza.value;
		document.frmExpedia.ToAirport.value = document.frmExpedia.destinazione.value;
		document.frmExpedia.FromDate.value = document.frmExpedia.dataInizio.value;
		document.frmExpedia.ToDate.value = document.frmExpedia.dataFine.value;
        }
return true;
}