﻿var theForm;
var formProcessorURL = "";
var moreOptURL3PP = "";
var g_Validation;
var g_errControler
var errMessageContainerId = "";
var currDateFormat = expediaNS.cx.wizard.DATEFORMAT.EU;
var errReqFields = "";
var errRetDate = "";
var errRetFlightDate = "";
var maxRoomNumber = 1;
var maxChildPerRoom = 1;
var showHotelSenior = false;
var flightIconUrl = "http://media.expedia.com/media/content/expit/graphics/home/1024/wiz/wizard_message_flighticon.gif";
var carIconUrl = "http://media.expedia.com/media/content/expit/graphics/home/1024/wiz/wizard_message_caricon.gif";
var hotelIconUrl = "http://media.expedia.com/media/content/expit/graphics/home/1024/wiz/wizard_message_hotelicon.gif";
var attractionIconUrl = "http://media.expedia.com/media/content/shared/graphics/home/1024/wiz/attraction.gif";
var packagesIconUrl = "http://media.expedia.com/media/content/shared/graphics/home/1024/wiz/package.gif";

function InitWiz()
{
	theForm = document.Wiz;
	theForm.onSubmit=OnFormSubmit;
	
	InitValidation();
	
	if(document.getElementById('UserClicked').value!="" && document.getElementById('UserClicked').value!="flighthotel")
	{ 
		var srcType=document.getElementById('UserClicked').value;
		showItems(srcType);
	}
	
	InitRooms();
	
	//Hide all error message
    g_Validation.reset();
    
	//Show the right product panel in the bottom which is selected by product radio button
	ShowSelectedPruduct();
}

//Show the right product panel in the bottom which is selected by product radio button
function ShowSelectedPruduct()
{
    var rButtons = ['rfo', 'rho', 'rco', 'srch2', 'srch1', 'rfh', 'rfhc', 'rfc', 'rhc'];
    
    for (var i=0; i<rButtons.length; i++) 
    {
        var button = document.getElementById(rButtons[i]);
        
        if (button != null && button.checked == true)
        {
            //Simulate click to call onclick event
            button.click();
            break;
        }
    } 
}

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;
		}	
		//SyncTimes();
}

function checkRadio(idItem, type) {

	document.getElementById('UserClicked').value=type;
	itemObj = document.getElementById(idItem);
	itemObj.checked = true;
	
	var idItemObject = document.getElementById(idItem+"Label");
	
	if (idItemObject != null)
	{
	    for (i=0; i< document.getElementById("productsContainer").getElementsByTagName("label").length; i++)
	    {
                document.getElementById("productsContainer").getElementsByTagName("label")[i].style.fontWeight = "normal";
	    }
	    idItemObject.style.fontWeight = "bold";
    }
	
	showItems(type);
}

function resetRadioButton(id)
{
document.getElementById(id + 'Label').style.fontWeight = 'normal';
}


function showObj(idItem) {
	document.getElementById(idItem).style.display = '';
}

function setToVisible(idItem){
    document.getElementById(idItem).style.visibility = 'visible';
}

function hideObj(idItem) {
	document.getElementById(idItem).style.display = 'none';
}

function setToHidden(idItem){
    document.getElementById(idItem).style.visibility = 'hidden';
}

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';
		}
	}
	
    g_Validation.reset();
    
    RegisterValidations(type);
	
	SetRfrr(type);
	
	SetRoomSelectionVisibility(false);	
	
	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');
            ShowSeniorNumber();
			InitChildAges('NoRoom');
			showObj('adultSelOne');
			theForm.NumAdult.value = theForm.NumAdultF.options[theForm.NumAdultF.selectedIndex].value;
			showObj('fopt');
			document.getElementById('rfo').checked = true;
			break;
		
		case 'hotel':
		case 'hotellink':
		    SetRoomSelectionVisibility(true);
			theForm.GOTO.value = "HOTSEARCH"; theForm.SearchType.value = 'DESTINATION';
			showObj('hdest');
			showObj('ckindt');
			showObj('ckoutdt');
			showObj('adultSelOne');
			showObj('pax');
			if (showHotelSenior)
			{
                ShowSeniorNumber();
			}
			InitChildAges('MoreRooms');
			theForm.NumAdult.value = theForm.NumAdultH.options[theForm.NumAdultH.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');
			InitChildAges('Hidden');
			break;
			
		case 'holiday':
		case 'holidaylink':
			theForm.GOTO.value = '3PPACKAGES';
			theForm.PackageType.value = 4;
			showObj('vacdest');
			showObj('vac_arrivo');
			showObj('vac_part');
			showObj('vacopt');
			InitChildAges('Hidden');
			break;
			
		case 'attraction':
		case 'attractionlink':
			theForm.GOTO.value = 'TSHOPSSEARCH';
			showObj('radiobuttonwiz');
			InitChildAges('Hidden');
			break;
			
		case "flighthotel":
		case "flighthotellink":
		    SetRoomSelectionVisibility(true);
			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');
			showObj('SeniorNumberTitle');
	        ShowSeniorNumber();
			InitChildAges('MoreRooms');
			showObj('aduhols');
			showObj('fhopt');
			break;
			
		case "flighthotelcar":
		case "flighthotelcarlink":
		    SetRoomSelectionVisibility(true);
			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');
            ShowSeniorNumber();
			InitChildAges('MoreRooms');
			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');
            ShowSeniorNumber();
			InitChildAges('NoRoom');
			showObj('aduhols');
			showObj('fcopt');
			showObj('cardisc');
			break;
		case "hotelcar":
		case "hotelcarlink":
		    SetRoomSelectionVisibility(true);
		    theForm.GOTO.value = 'PACKAGEWIZ';
		    theForm.PackageType.value = 3;
		    showObj('cdest');
			showObj('lcdepart');
			showObj('fdate');
			showObj('putime');
			showObj('cclass');
			showObj('lcreturn');
			showObj('tdate');
			showObj('dotime');
			showObj('pax');
			showObj('cardisc');
		    if (showHotelSenior)
			{
                ShowSeniorNumber();
			}
			InitChildAges('MoreRooms');
			showObj('aduhols');
			theForm.NumAdult.value = theForm.NumAdultH.options[theForm.NumAdultH.selectedIndex].value;
		    break;		
	}
	
	ShowInfants();
	
	if (type == "flightlink"){
		window.location.href = formProcessorURL + "?GOTO=FLIGHTWIZ&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.ToTimeFlight.options[theForm.ToTimeFlight.selectedIndex].value + "&ReturnTime=" + theForm.FromTimeFlight.options[theForm.FromTimeFlight.selectedIndex].value;
	}else if (type == "hotellink"){
		window.location.href = formProcessorURL + "?GOTO=HOTLAUNCH&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 = formProcessorURL + "?GOTO=CARWIZD&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 = moreOptURL3PP + "?affiliate=" + theForm.EAPID.value.replace("-8","") + "&trackingcode=HPWizMoreOptions";
	}else if (type == "flighthotellink"){
		window.location.href = formProcessorURL + "?GOTO=PKGLAUNCH&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.ToTimeFlight.options[theForm.ToTimeFlight.selectedIndex].value + "&FromTime=" + theForm.FromTimeFlight.options[theForm.FromTimeFlight.selectedIndex].value;
	}else if (type == "flighthotelcarlink"){
		window.location.href = formProcessorURL + "?GOTO=PKGLAUNCH&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.ToTimeFlight.options[theForm.ToTimeFlight.selectedIndex].value + "&FromTime=" + theForm.FromTimeFlight.options[theForm.FromTimeFlight.selectedIndex].value;
	}else if (type == "flightcarlink"){
		window.location.href = formProcessorURL + "?GOTO=PKGLAUNCH&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.ToTimeFlight.options[theForm.ToTimeFlight.selectedIndex].value + "&FromTime=" + theForm.FromTimeFlight.options[theForm.FromTimeFlight.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 SyncTimes(){
    theForm = document.Wiz;
    if (theForm.GOTO.value == 'PACKAGEWIZ' && 
        theForm.PackageType.value == 3)
    {
        theForm.FromTime.value = theForm.PickUpTime.options[theForm.PickUpTime.selectedIndex].value;
        theForm.ToTime.value = theForm.DropTime.options[theForm.DropTime.selectedIndex].value;
    }
    else
    {
        theForm.FromTime.value = theForm.FromTimeFlight.options[theForm.FromTimeFlight.selectedIndex].value;
        theForm.ToTime.value = theForm.ToTimeFlight.options[theForm.ToTimeFlight.selectedIndex].value;
    }
}

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 SetInfants()
{   
    if(document.Wiz.InfantInSeatNo.checked)
    {
        var numberofInfants = 0;
        var chidAgeFields = [document.Wiz.Age1, document.Wiz.Age2, document.Wiz.Age3, document.Wiz.Age4, document.Wiz.Age5, document.Wiz.Age6]
        
        for(var i = 0;i < chidAgeFields.length; i++)
        {
            var age = chidAgeFields[i].value;
            if (age != "" && age < 2)
            {
                numberofInfants++;
            }
        }
        
        document.Wiz.NumChild.value = document.Wiz.NumChild.value - numberofInfants;
        document.Wiz.NumInfant.value = numberofInfants;
    }
}

function SetRfrr(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 GetSelectedNumberOfRooms()
{
    var roomNumSelect = document.getElementById('NumRoom');
    if (roomNumSelect != null)
    {
        return roomNumSelect.options[roomNumSelect.selectedIndex].value;
    }
    else
    {
        return 1;
    }
}

function GetSelectedNumberOfChild(roomNumber)
{
    var childNumberSelect = document.getElementById((roomNumber == 1) ? 'NumChild' : 'NumChild'+roomNumber);
    if (childNumberSelect != null)
    {    
        return childNumberSelect.options[childNumberSelect.selectedIndex].value;
    }
    else
    {
        return 0;
    }
}

function ShowSeniorNumber()
{
    showObj('SeniorNumberTitle');
    for (i=1; i<=maxRoomNumber; i++)
    {
        showObj('SeniorNumber'+i);
    }
}

//Rooms
function InitRooms()
{
    ShowRooms(GetSelectedNumberOfRooms());
}

function ShowRooms(selectedValue)
{
    for (i=1; i<=maxRoomNumber; i++)
    {
        if (i<=selectedValue)
        {
            showObj('RoomPanel'+i);
        }
        else
        {
            hideObj('RoomPanel'+i);
        }
    }
    
    ShowChildAgePanels(selectedValue);
}

function SetRoomSelectionVisibility(visible)
{
    if (visible)
    {
        showObj('roomSelectorPanel');
        showObj('roomSelectorPanelTitle');
        showObj('RoomNumPanel1');
    }
    else
    {
        hideObj('roomSelectorPanel');
        hideObj('roomSelectorPanelTitle');
        hideObj('RoomNumPanel1');
    }
    
    for (var roomNum = 2; roomNum<=maxRoomNumber; roomNum++)
    {
        if (visible)
        {
            InitRooms();
        }
        else
        {
            hideObj('RoomPanel'+roomNum);
        }
    }
}

//ChildAges
function InitChildAges(type)
{
    switch(type)
    {
        case'Hidden':
            hideObj('childages');
            break;
        case'NoRoom':
            hideObj('roomChildAgePanelTitle1');        
            ShowChildAgePanels(1);
            showObj('childages');
            break;
        case'MoreRooms':
            showObj('roomChildAgePanelTitle1');
            ShowChildAgePanels(GetSelectedNumberOfRooms());
            showObj('childages');
            break;
    }
}

function ShowChildAgePanels(numOfRooms)
{
    for(i=1; i<=maxRoomNumber; i++)
    {
        if (numOfRooms >= i)
        {
            ShowChildAgePanel(i);            
        }
        else
        {
            HideChildAgePanel(i);
        }
    }
}

function ShowChildAgePanel(panelNumber)
{
    ShowChildAgesDescription();

    var childNumber = GetSelectedNumberOfChild(panelNumber);
    if (childNumber > 0)
    {
        ShowChildAges(panelNumber, childNumber)
        showObj('roomChildAgePanel'+panelNumber);
    }
    else
    {
        hideObj('roomChildAgePanel'+panelNumber);
    }
}

function HideChildAgePanel(panelNumber)
{
    hideObj('roomChildAgePanel'+panelNumber);
}

function ShowChildAges(roomNum, val) {
    if (roomNum == 0 || roomNum == null || val == null)
    {
        return;
    }
    else
    {        
        for(numChild=1; numChild<=maxChildPerRoom; numChild++)
        {
            if (val >= numChild)
            {
                showObj('tdRm'+roomNum+'Child'+numChild);
            }
            else
            {
                hideObj('tdRm'+roomNum+'Child'+numChild);
            }
        }        
    }
}

function ShowChildAgesDescription()
{
    var mustShown = false;
    var childNumberSelect;
    for (var i = 1; i <= maxRoomNumber; i++)
    {
        if (GetSelectedNumberOfChild(i) > 0)
        {
            mustShown = true;
            break;
        }
    }
    
    if (mustShown)
    {
        showObj('childAgesDescription');
    }
    else
    {
        hideObj('childAgesDescription');
    }
}

//Validation
function InitValidation()
{
    g_Validation = new expediaNS.cx.wizard.VValidationAgent();
    g_errControler = new expediaNS.cx.wizard.VErrorController("errorMessagesContainer");
    g_Validation.setErrorController(g_errControler);
    g_Validation.setDateFormat(currDateFormat);
}

function Validate()
{
	SyncTimes();
  isValid = g_Validation.validate();
  if(isValid)
  {
    return true;
  }
  return false;
}

function RegisterValidations(type)
{
	switch(type){
		
		case 'flight':
		case 'flightlink':
		    var eltOrigin  = new expediaNS.cx.wizard.VElement( "FrAirport", "FrAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    var eltDestination  = new expediaNS.cx.wizard.VElement( "ToAirport", "ToAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltOrigin, eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));
		    
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "FromDate", "FromDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "ToDate", "ToDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterOrEqualStartDate, errRetFlightDate));
			break;
		
		case 'hotel':
		case 'hotellink':
			var eltDestination  = new expediaNS.cx.wizard.VElement( "CityName", "CityNameLabel", expediaNS.cx.wizard.FIELDTYPE.any);
			g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));
			
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "InDate", "InDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "OutDate", "OutDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterStartDate, errRetDate));			
			break;
			
		case 'car':
		case 'carlink':
			var eltDestination  = new expediaNS.cx.wizard.VElement( "PickupLoc", "PickupLocLabel", expediaNS.cx.wizard.FIELDTYPE.any);
			g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));	        
	        
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "FromDate", "FromDateCarLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "ToDate", "ToDateCarLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterStartDate, errRetDate));
			break;
			
		case 'holiday':
		case 'holidaylink':
			var eltDestination  = new expediaNS.cx.wizard.VElement( "exp_IT3PP_LeavingFrom", "exp_IT3PP_LeavingFromLabel", expediaNS.cx.wizard.FIELDTYPE.any);
			g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));

	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "VacFromDate", "VacFromDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
			break;
			
		case 'attraction':
		case 'attractionlink':
			var eltDestination  = new expediaNS.cx.wizard.VElement( "locationname", "locationnameLabel", expediaNS.cx.wizard.FIELDTYPE.any);
			g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));	        
	        
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "StartDate", "StartDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "EndDate", "EndDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterStartDate, errRetDate));		    

			break;
			
		case "flighthotel":
		case "flighthotellink":
		    var eltOrigin  = new expediaNS.cx.wizard.VElement( "FrAirport", "FrAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    var eltDestination  = new expediaNS.cx.wizard.VElement( "DestName", "DestNameLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltOrigin, eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));
		    
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "FromDate", "FromDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "ToDate", "ToDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterStartDate, errRetFlightDate));
			break;
			
		case "flighthotelcar":
		case "flighthotelcarlink":
		    var eltOrigin  = new expediaNS.cx.wizard.VElement( "FrAirport", "FrAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    var eltDestination  = new expediaNS.cx.wizard.VElement( "ToAirport", "ToAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltOrigin, eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));
		    
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "FromDate", "FromDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "ToDate", "ToDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterStartDate, errRetFlightDate));
			break;
			
		case "flightcar":
		case "flightcarlink":
		    var eltOrigin  = new expediaNS.cx.wizard.VElement( "FrAirport", "FrAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    var eltDestination  = new expediaNS.cx.wizard.VElement( "ToAirport", "ToAirportLabel", expediaNS.cx.wizard.FIELDTYPE.any);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(1, new Array(eltOrigin, eltDestination ), expediaNS.cx.wizard.VALIDATIONTYPE.isOrigNotEmpty, errReqFields));
		    
	        var eltDateFrom  = new expediaNS.cx.wizard.VElement( "FromDate", "FromDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    var eltDateTo  = new expediaNS.cx.wizard.VElement( "ToDate", "ToDateLabel", expediaNS.cx.wizard.FIELDTYPE.date);
		    g_Validation.register(new expediaNS.cx.wizard.VValidation(2, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.areDatesValid, errReqFields));
            g_Validation.register(new expediaNS.cx.wizard.VValidation(3, new Array(eltDateFrom, eltDateTo ), expediaNS.cx.wizard.VALIDATIONTYPE.isEndDateAfterOrEqualStartDate, errRetFlightDate));
			break;				
	}
}

//Infants
function ShowInfants()
{   
    var mustShow = false;
    var selNumChild;
    var selNumRoom;
    
    if (theForm.GOTO.value == 'EXPFLTWIZ')//Only Flight-Show infants
    {
        selNumRoom = 1;
    }
    else if (theForm.GOTO.value == 'PACKAGEWIZ' &&
             theForm.PackageType.value != 3)//Packages-Show infants
    {
        selNumRoom = GetSelectedNumberOfRooms();
    }
    else//Hide infants
    {
        selNumRoom = 0;
    }
    
    for (roomNum = 1; roomNum<=selNumRoom; roomNum++)
    {
        selNumChild =  GetSelectedNumberOfChild(roomNum);
        
        for (childNum = 1; childNum<=selNumChild; childNum++)
        {
            var childAgeSel = document.getElementById(((roomNum >= 2) ? 'Rm' + roomNum : '') + 'Child' + childNum + 'Age');
            if (childAgeSel.options[childAgeSel.selectedIndex].value < 2)
            {
                mustShow = true;
                break;
            }
        }
        
        if (mustShow)
        {
            break;
        }
    }
    
    if (mustShow)
    {
        showObj('InfantsContainer');
    }
    else
    {
        hideObj('InfantsContainer');
    }
}



function wizardMessageText(message,imagePath)
{
document.getElementById("wizardMessageText").innerHTML = message;
document.getElementById("WizardMessageIcon").src = imagePath;
}