var theForm;
		
function InitWiz()
{
	theForm = document.Wiz;
	theForm.onSubmit=OnFormSubmit;
	if(document.getElementById('UserClicked').value!="" && document.getElementById('UserClicked').value!="flighthotel")
	{ 
		var srcType=document.getElementById('UserClicked').value;
		//alert(srcType);
		showItems(srcType);
	}
}		

function OnFormSubmit()
{	
		var theForm = document.Wiz;
		
		switch(theForm.GOTO.value)
		{
			case 'EXPFLTWIZ':
				SyncDestinations(theForm.ToAirport.value);
			break;
			case 'HOTSEARCH':
				SyncDestinations(theForm.CityName.value);
				break;
			case 'CARSEARCH':
				SyncDestinations(theForm.PickupLoc.value);
				break;
			case 'PACKAGEWIZ':
				SyncDestinations(theForm.DestName.value);
				break;
		}	
}
/*
window.onload=function(){
	//init();
	if(document.getElementById('UserClicked').value!="true") checkRadio('rfh', 'flighthotel');
}
*/

function impostaLocation(){
	
	//document.getElementById('altro').checked=true;
	//box = document.getElementById('ddlListaDestinazioni');
	//valore = box.options[box.selectedIndex].value;
	//document.getElementById('altro').value = valore;*/	
}

function setFocusAltro(){
	//document.getElementById('altro').checked=true;
}

function lostFocusAltro(){
	//document.getElementById('altro').checked=false;
	//document.getElementById('ddlListaDestinazioni').value= '';
}

function checkRadio(idItem, type) {
	document.getElementById('UserClicked').value=type;
	itemObj = document.getElementById(idItem);
	itemObj.checked = true;
	
	showItems(type);
}

function showObj(idItem) {
	document.getElementById(idItem).style.display = '';
}

function hideObj(idItem) {
	document.getElementById(idItem).style.display = 'none';
}

function showItems(type) {
	theForm=document.Wiz;
	var divObj = document.getElementsByTagName('div');
	for (var i=0;i<divObj.length;i++) {
		if (divObj[i].lang == 1) {
			divObj[i].style.display = 'none';
		}
	}
	
	SetRfrr(type);
	
	switch(type){
		
		case 'flight':
		case 'flightlink':
			theForm.GOTO.value = 'EXPFLTWIZ';
			showObj('dfrom');
			showObj('fdest');
			showObj('ldepart');
			showObj('fdate');
			showObj('ftime');
			showObj('lreturn');
			showObj('tdate');
			showObj('ttime');
			showObj('pax');
			ShowChildAges(theForm.NumChild.value);
			showObj('senpax');
			showObj('aduflight');
			theForm.NumAdult.value = theForm.NumAdultF.options[theForm.NumAdultF.selectedIndex].value;
			showObj('fopt');
			document.getElementById('rfo').checked = true;
			break;
		
		case 'hotel':
		case 'hotellink':
			theForm.GOTO.value = "HOTSEARCH"; theForm.SearchType.value = 'DESTINATION';
			showObj('hdest');
			showObj('ckindt');
			showObj('ckoutdt');
			showObj('aduflight');
			showObj('pax');
			showObj('senpax');
			ShowChildAges(theForm.NumChild.value);
			theForm.NumAdult.value = theForm.NumAdultF.options[theForm.NumAdultF.selectedIndex].value;
			showObj('hopt');			
			break;
			
		case 'car':
		case 'carlink':
			theForm.GOTO.value = 'CARSEARCH'; theForm.SearchType.value = 'AIRPORT';
			showObj('cdest');
			showObj('lcdepart');
			showObj('fdate');
			showObj('putime');
			showObj('cclass');
			showObj('lcreturn');
			showObj('tdate');
			showObj('dotime');
			showObj('cardisc');
			showObj('copt');
			break;
			
		case 'holiday':
		case 'holidaylink':
			theForm.GOTO.value = '3PPACKAGES';
			theForm.PackageType.value = 4;
			showObj('vacdest');
			showObj('vac_arrivo');
			showObj('vac_part');
			showObj('vacopt');
			break;
			
		case 'attraction':
		case 'attractionlink':
			theForm.GOTO.value = 'TSHOPSSEARCH';
			showObj('radiobuttonwiz');
			break;
			
		case "flighthotel":
		case "flighthotellink":
			theForm.GOTO.value = 'PACKAGEWIZ';
			theForm.NumAdult.value = theForm.NumAdultH.options[theForm.NumAdultH.selectedIndex].value;
			theForm.PackageType.value = 2;
			showObj('dfrom');
			showObj('pdest');
			showObj('ldepart');
			showObj('fdate');
			showObj('ftime');
			showObj('lreturn');
			showObj('tdate');
			showObj('ttime');
			showObj('pax');
			ShowChildAges(theForm.NumChild.value);
			showObj('senpax');
			showObj('aduhols');
			showObj('fhopt');
			break;
			
		case "flighthotelcar":
		case "flighthotelcarlink":
			theForm.GOTO.value = 'PACKAGEWIZ';
			theForm.NumAdult.value = theForm.NumAdultH.options[theForm.NumAdultH.selectedIndex].value;
			theForm.PackageType.value = 1;
			showObj('dfrom');
			showObj('fdest');
			showObj('ldepart');
			showObj('fdate');
			showObj('ftime');
			showObj('lreturn');
			showObj('tdate');
			showObj('ttime');
			showObj('pax');
			ShowChildAges(theForm.NumChild.value);
			showObj('senpax');
			showObj('aduhols');
			showObj('fhcopt');
			showObj('cardisc');
			break;
			
		case "flightcar":
		case "flightcarlink":
			theForm.GOTO.value = 'PACKAGEWIZ';
			theForm.NumAdult.value = theForm.NumAdultH.options[theForm.NumAdultH.selectedIndex].value;
			theForm.PackageType.value = 5;
			showObj('dfrom');
			showObj('fdest');
			showObj('ldepart');
			showObj('fdate');
			showObj('ftime');
			showObj('lreturn');
			showObj('tdate');
			showObj('ttime');
			showObj('pax');
			ShowChildAges(theForm.NumChild.value);
			showObj('senpax');
			showObj('aduhols');
			showObj('fcopt');
			showObj('cardisc');
			break;
				
	}
	
	if (type == "flightlink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=FLIGHTWIZ&eapid=" + theForm.EAPID.value + "&NoSubmit=1&DepAirpName=" + theForm.FrAirport.value + "&DestAirpName=" + theForm.ToAirport.value + "&DepDate=" + theForm.FromDate.value + "&ReturnDate=" + theForm.ToDate.value + "&shps=1&NumAdult=" + theForm.NumAdult.value; + "&NumChild=" + theForm.NumChild.options[theForm.NumChild.selectedIndex].value + "&NumSenior=" + theForm.NumSenior.options[theForm.NumSenior.selectedIndex].value + "&DepTime=" + theForm.ToTime.options[theForm.ToTime.selectedIndex].value + "&ReturnTime=" + theForm.FromTime.options[theForm.FromTime.selectedIndex].value;
	}else if (type == "hotellink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=HOTLAUNCH&eapid=" + theForm.EAPID.value + "&MoreOptions=1&NoSubmit=1&CityName=" + theForm.CityName.value + "&InDate=" + theForm.InDate.value + "&OutDate=" + theForm.OutDate.value + "&NumAdult=" + theForm.NumAdult.value + "&NumChild=" + theForm.NumChild.options[theForm.NumChild.selectedIndex].value + "&NumSenior=" + theForm.NumSenior.options[theForm.NumSenior.selectedIndex].value;
	}else if (type == "carlink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=CARWIZD&eapid=" + theForm.EAPID.value + "&PickupLoc=" + theForm.PickupLoc.value +  "&PickUpDate=" + theForm.FromDate.value + "&DropOffDate=" + theForm.ToDate.value + "&PickUpTime=" + theForm.PickUpTime.value + "&DropTime=" + theForm.DropTime.value + "&CarClass=" + theForm.Class.options[theForm.Class.selectedIndex].value;
	}else if (type == "holidaylink"){
		window.location.href = "http://packages.expediaitalia.it/vacation/default.aspx?affiliate=" + theForm.EAPID.value.replace("-8","") + "&trackingcode=HPWizMoreOptions";
	}else if (type == "flighthotellink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + theForm.EAPID.value + "&PackageType=2&NoSubmit=1&FrAirport=" + theForm.FrAirport.value + "&DestName=" + theForm.ToAirport.value + "&FromDate=" + theForm.FromDate.value + "&ToDate=" + theForm.ToDate.value + "&NumAdult=" + theForm.NumAdult.value + "&NumChild=" + theForm.NumChild.options[theForm.NumChild.selectedIndex].value + "&NumSenior=" + theForm.NumSenior.options[theForm.NumSenior.selectedIndex].value + "&ToTime=" + theForm.ToTime.options[theForm.ToTime.selectedIndex].value + "&FromTime=" + theForm.FromTime.options[theForm.FromTime.selectedIndex].value;
	}else if (type == "flighthotelcarlink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + theForm.EAPID.value + "&PackageType=1&NoSubmit=1&FrAirport=" + theForm.FrAirport.value + "&DestName=" + theForm.ToAirport.value + "&FromDate=" + theForm.FromDate.value + "&ToDate=" + theForm.ToDate.value + "&NumAdult=" + theForm.NumAdult.value + "&NumChild=" + theForm.NumChild.options[theForm.NumChild.selectedIndex].value + "&NumSenior=" + theForm.NumSenior.options[theForm.NumSenior.selectedIndex].value + "&ToTime=" + theForm.ToTime.options[theForm.ToTime.selectedIndex].value + "&FromTime=" + theForm.FromTime.options[theForm.FromTime.selectedIndex].value;
	}else if (type == "flightcarlink"){
		window.location.href = "/pubspec/scripts/eap.asp?GOTO=PKGLAUNCH&eapid=" + theForm.EAPID.value + "&PackageType=5&NoSubmit=1&FrAirport=" + theForm.FrAirport.value + "&DestName=" + theForm.DestName.value + "&FromDate=" + theForm.FromDate.value + "&ToDate=" + theForm.ToDate.value + "&NumAdult=" + theForm.NumAdult.value + "&NumChild=" + theForm.NumChild.options[theForm.NumChild.selectedIndex].value + "&NumSenior=" + theForm.NumSenior.options[theForm.NumSenior.selectedIndex].value + "&ToTime=" + theForm.ToTime.options[theForm.ToTime.selectedIndex].value + "&FromTime=" + theForm.FromTime.options[theForm.FromTime.selectedIndex].value;
	}
}

function SyncAdu(val){
	SetSelectValue(theForm.NumAdultF, val);
	SetSelectValue(theForm.NumAdultH, val);
	theForm.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 SyncDestinations(val){
	theForm = document.Wiz;
	theForm.ToAirport.value = val;
	theForm.DestName.value = val;
	theForm.CityName.value = val;
	theForm.PickupLoc.value = val;
}

function SyncRetDates(val){
	theForm = document.Wiz;
	theForm.OutDate.value = val;
	theForm.ToDate.value = val;
}

function SyncDepDates(val){
	theForm = document.Wiz;
	theForm.FromDate.value = val;
	theForm.InDate.value = val;
}

function ShowChildAges(val) {
	if (val == 0 || val == null) {
		hideObj('childages');
	} else {
		showObj('childages');
	}
	for(i=1;i<7;i++) {
		if (i <= val){
			showObj('tdChild'+ i);
		} else {
			hideObj('tdChild'+ i);
		}
	}
}

function SyncChildAges(){
	theForm = document.Wiz;
	theForm.Age1.value = theForm.child1Age.options[theForm.child1Age.selectedIndex].value;
	theForm.Age2.value = theForm.child2Age.options[theForm.child2Age.selectedIndex].value;
	theForm.Age3.value = theForm.child3Age.options[theForm.child3Age.selectedIndex].value;
	theForm.Age4.value = theForm.child4Age.options[theForm.child4Age.selectedIndex].value;
	theForm.Age5.value = theForm.child5Age.options[theForm.child5Age.selectedIndex].value;
	theForm.Age6.value = theForm.child6Age.options[theForm.child6Age.selectedIndex].value;
}

function SetRfrr(type)
{
	//theForm.lnkcid.value = "hpwiz_" + type;

	switch(type)
	{
		case "flight":
		case "flightlink":
			theForm.rfrr.value = theForm.FlightOnlyRFRR.value;
			break;
		case "hotel":
		case "hotellink":
			theForm.rfrr.value = theForm.HotelOnlyRFRR.value;
			break;
		case "car":
		case "carlink":
			theForm.rfrr.value = theForm.CarOnlyRFRR.value;
			break;
		case "flighthotel":
		case "flighthotellink":
			theForm.rfrr.value = theForm.FlightHotelRFRR.value;
			break;
		case "flighthotelcar":
		case "flighthotelcarlink":
			theForm.rfrr.value = theForm.FlightHotelCarRFRR.value;
			break;
		case "flightcar":
		case "flightcarlink":
			theForm.rfrr.value = theForm.FlightCarRFRR.value;
			break;
		case "attraction":
		case "attractionlink":
		    theForm.rfrr.value = theForm.AttractionRFRR.value;
			break;
		case "holiday":
		case "holidaylink":
		  theForm.rfrr.value = theForm.TourOperatorRFRR.value;
		break;
	}
}

/*
function checkform()
{
	alert(theForm.DestName.value);
	theForm = document.Wiz;
	theForm.DestName.value = theForm.ToAirport.value;
	
}
*/

