function initDisambig() {
	// Disambig Events. Loaded inlined to avoid waiting for the onload event
	var airDisamb = $S('select.w_PickupAirportDisambig');
	var placeDisamb = $S('select.w_PickupPlaceDisambig');
	var drofOffDisamb = $S('select.w_DropoffAirportDisambig');
	var getAirDisambValue, getPlaceDisambValue, getDropDisambValue;
	
	if(airDisamb != "") {
	    airDisamb.action({onclick: function(){
	        airDisamb.each(function(element){getAirDisambValue = element.options[element.selectedIndex].text;});
	        $('w_Dest').getElementsByTagName('input')[0].value = getAirDisambValue;
	        }
	    });
	}
	if(placeDisamb != "") {
	    placeDisamb.action({onclick: function(){
	        placeDisamb.each(function(element){getPlaceDisambValue = element.options[element.selectedIndex].text;});
	        $('w_Dest').getElementsByTagName('input')[0].value = getPlaceDisambValue;
	        }
	    });
	}
    if(drofOffDisamb != "") {
        drofOffDisamb.action({onclick: function(){
	        drofOffDisamb.each(function(element){getDropDisambValue = element.options[element.selectedIndex].text;});
            $('w_DropOff_Location_Input')[0].value = getDropDisambValue;
            }
        });
    }
}
function initWizEvent(serverYear){
    addLoadEvent(checkSpecialEquipmentOptions);
    addLoadEvent(updateDatesInvalidErrorMessage);
    
    var PickUpLocationErrorMes = $('w_PickUpLocationErrorMes');
    var PickupLocationErrorDiv = $('w_PickupLocationErrorDiv');
    var Drop_Location = $('w_Drop_Location');
    var Radius = $('w_Radius');
    var AirportFieldset = $('w_AirportFieldset');
    var AddressFieldset = $('w_AddressFieldset');
    var PickLocAirportLbl = $('w_PickLocAirportLbl');
    var PickLocPlaceLbl = $('w_PickLocPlaceLbl');
    var PickupAirportDisambig = $S('select.w_PickupAirportDisambig');
    var PickupPlaceDisambig = $S('select.w_PickupPlaceDisambig');
    var DropoffAirportDisambig = $S('select.w_DropoffAirportDisambig');
    var ClassRadio = $('w_Class').getElementsByTagName('input');
    var RatePanel = $S('div.w_RatePanel');
    var DiscountPanel = $S('div.w_DiscountPanel');
    var LeftHandPanel = $S('div.LeftHandPanel');
    var RightHandPanel = $S('div.RightHandPanel');
    var FromDate = $S('#w_FromDate').getElementsByTagName('input');
    var ToDate = $S('#w_ToDate').getElementsByTagName('input');
    
    // Top Radio Buttons Events
    $S('#w_Step01-a').getElementsByTagName('input').action({
        onclick: function() {
            var choice=this.value;
            if(PickUpLocationErrorMes) PickUpLocationErrorMes.style.display = "none";
            if(PickupLocationErrorDiv) PickupLocationErrorDiv.className = 'e_PassOK';
            if(Drop_Location) Drop_Location.style.display = (choice == 'w_Pickup1') ? 'block':'none';
            if(Radius) Radius.style.display = (choice != 'w_Pickup1') ? 'block':'none';
            if(AirportFieldset) AirportFieldset.style.display = (choice != 'w_Pickup3') ? 'block':'none';
            if(AddressFieldset) AddressFieldset.style.display = (choice == 'w_Pickup3') ? 'block':'none';
            if(PickLocAirportLbl) PickLocAirportLbl.style.display = (choice == 'w_Pickup1') ? 'block':'none';
            if(PickLocPlaceLbl) PickLocPlaceLbl.style.display = (choice == 'w_Pickup2') ? 'block':'none';
            if(PickupAirportDisambig != "") PickupAirportDisambig.each(function(element){element.style.display = (choice == 'w_Pickup1') ? 'block':'none';});
            if(PickupPlaceDisambig != "") PickupPlaceDisambig.each(function(element){element.style.display = (choice == 'w_Pickup2') ? 'block':'none';});
            if(DropoffAirportDisambig != "") DropoffAirportDisambig.each(function(element){element.style.display = (choice == 'w_Pickup1') ? 'block':'none';});
        }
    });
    
    // Checkboxes "My drop-off location is different from pick-up location" Event
    if(Drop_Location) $('w_Drop-off_Checkbox').getElementsByTagName('input').action({onclick: function(element){$('w_Drop-off_Location').style.display = (element.checked) ? "block":"none";}});
	
	// Class Radio's Events
	if(ClassRadio.length != 0){
	    var Inputs = ClassRadio.length;
	    $S('#w_Class').getElementsByTagName('input').action({
	        onclick: function(){
	            if(this.value == 1) uncheckClassRadio(Inputs,ClassRadio);
	            else uncheckFirstRadio(ClassRadio)
	        }
	    });
	    $S('#w_Class').getElementsByTagName('select').action({
	        onchange: function(){
	            ClassRadio[0].checked = true;
	            uncheckClassRadio(Inputs,ClassRadio)
	        }
	    });
	}
	
	// Discount Radio Buttons Events
	if(RatePanel != ""){
	    RatePanel.getElementsByTagName('input').action({
	        onclick: function(){
	            $('w_Vendor_Option01').style.display = (this.value == 'w_Rate1') ? 'block':'none';
	            $('w_Vendor_Option02').style.display = (this.value == 'w_Rate2') ? 'block':'none';
	            $('w_Vendor_Option03').style.display = (this.value == 'w_Rate3') ? 'block':'none';
	        }
	    });
	}
    
    // Discount Select Events
    if(DiscountPanel != ""){
        $('w_Vendor_Option02').getElementsByTagName('select').action({onchange: UpdateDiscount(2)});
        $('w_Vendor_Option03').getElementsByTagName('select').action({onchange: UpdateDiscount(3)});
    }
    
    //left and right-hand equipment are mutually exclusive
    if(LeftHandPanel != "" && RightHandPanel != ""){
        LeftHandPanel.action({onclick: function(){RightHandPanel.getElementsByTagName('input').checked = false;}});
        RightHandPanel.action({onclick: function(){LeftHandPanel.getElementsByTagName('input').checked = false;}});
    }

    //If server side date errors were returned on postback, clear them when the user selects one of the date textboxes
    FromDate.action({
        onblur: function() {
            if($('CalFrame').style.visibility == 'hidden') {
			    disableServerSideDateErrors(); 
			    checkDatesFromDate();
            }
        }
    });
    ToDate.action({
        onblur: function() {
            if($('CalFrame').style.visibility == 'hidden') {
			    disableServerSideDateErrors(); 
			    checkDates();
            }
        }
    });                                                                                       

    //from date - validation and automatically set 'to' date        
    FromDate.action({onchange: checkDatesFromDate});
    ToDate.action({onchange: checkDates});
   
    // Check If options are checked to avoid seeing them on postback
    $S('#w_Step05').getElementsByTagName('input').each(function(element){if(element.type == 'checkbox' && element.checked) WizShowOptions});
    
    //assign checkSpecialEquipmentOptions function to each special equipment option (disables extra options if more than 3 are selected)
    $S('span.w_Special_Option').getElementsByTagName('input').each(function(element){element.onclick = checkSpecialEquipmentOptions});
    
    // More Options Link Event
    $S('#w_MoreLink').getElementsByTagName('a').action({onclick: WizShowOptions});
}

// Check / Uncheck Car Class radio's (DE)
function uncheckClassRadio(inputs,ClassRadio){
    for (var i=1; i<inputs; i++) ClassRadio[i].checked = false;
}
function uncheckFirstRadio(ClassRadio){
    ClassRadio[0].checked = false;
}

// Update Vendor Discount Cards
function UpdateDiscount(type){
    $('w_Vendor_Code0' + type).style.display = (this.options[0].selected) ? 'none':'block';
    for(i=0; i<this.options.length; i++) Element.hide('w_Vendor_Code0' + type + '_' + i);
    if(this.selectedIndex.value != "") Element.show('w_Vendor_Code0' + type + '_' + this.options[this.selectedIndex].value);
}

//handler on clicking a special equipment option
function checkSpecialEquipmentOptions() {
    var Special_Option = $S('span.w_Special_Option').getElementsByTagName('input');
    var selectedOptionCount = 0;
    Special_Option.each(function(optionInput){selectedOptionCount = selectedOptionCount + (optionInput.checked ? 1 : 0)});
    var doDisableBoxes = (selectedOptionCount > 2);    
    Special_Option.each(function(optionInput){optionInput.disabled = (!optionInput.checked && doDisableBoxes)});
}

// Toggle Options
function WizShowOptions(){
    $('w_Step05').style.display='block';
    $('w_MoreLink').style.display='none'; 
}

function checkDatesFromDate() {
	checkDates();
	adjustToDate();
}

function getLocalDateFormat() {
	var fmtDate = $('FMT_DATE');
	if((fmtDate == null) || (fmtDate.title == null)) return null;
	else return fmtDate.title.toLowerCase();
}

function checkDates() {
	var localDateFormat = getLocalDateFormat();
	var fromDate
	$S('input.w_FromDate_input').each(function(input){fromDate = input.value});
	var toDate
	$S('input.w_ToDate_input').each(function(input){toDate = input.value});
	var dt1, dt2;
	if(fromDate != localDateFormat) dt1 = GetInputDate(fromDate);
	else dt1 = fromDate;
	if(toDate != localDateFormat) dt2 = GetInputDate(toDate);
	else dt2 = toDate;
    if (!((dt1 == null) || (dt2 == null))) validateDates(true);
	else validateDates(false);
}

function adjustToDate() {
    var dt1, dt2;
	var localDateFormat = getLocalDateFormat();
	var fromDate
	$S('input.w_FromDate_input').each(function(input){fromDate = input.value});
	var toDate
	$S('input.w_ToDate_input').each(function(input){toDate = input.value});
	//if any date is still set to the local default; e.g. 'dd/mm/yy' we make no adjustments
	if(fromDate == localDateFormat) return;	
    dt1 = GetInputDate(fromDate);
    if (null==dt1) {
        validateDates(false);
        return;
    }
    validateDates(true);
    dt1 = new Date(dt1.valueOf() + 1000 * 3600 * 24 * 1);
    dt2 = GetInputDate(toDate);
	if (null!=dt2) {
        if (dt2 <= dt1) dt2 = null;
    }
    if (null==dt2) {CalDateSet($S('input.w_ToDate_input'),dt1.getDate(),dt1.getMonth()+1,dt1.getFullYear(),true);}
}

//make all server side errors coming from either qscript or handled from code-behind invisible
function disableServerSideDateErrors() {
    Element.hide('w_DropOffDateErrorDiv');
    Element.hide('w_PickupDateErrorDiv');
    Element.hide('w_DateRangeErrorDiv');
}

//make the client side error messsage invisible
function disableClientSideDateError() {    
    $('w_TravelDatesPass').className = 'e_PassOK';
    Element.hide('w_DatesErrorDiv');
}

function enableClientSideDateError() {
    $('w_TravelDatesPass').className = 'e_PassKO';
    Element.show('w_DatesErrorDiv');
}

//displays valid or invalid date boxes
function validateDates(isValid) {
	disableServerSideDateErrors();   
    if (isValid) disableClientSideDateError();
    else enableClientSideDateError();
}

//updates DatesInvalidError message with the date format and data sample;
function updateDatesInvalidErrorMessage() {
	date = new Date();
	var d = '31';
	var m = '12';
	var y = date.getUTCFullYear();
	var ds = GetDateSep();
	var fmt = GetDateFmt();
	if(fmt == "mmddyy") var sample = m+ds+d+ds+y;
	else if(fmt == "ddmmyy") var sample = d+ds+m+ds+y;
	else var sample = y+ds+m+ds+d;
	var errorLayer;
	$S('#w_DatesErrorDiv').getElementsByTagName('span').each(function(span){errorLayer = span;});
	var errorText = errorLayer.innerHTML;
	errorText = errorText.replace('{dateFormat}', getLocalDateFormat());
	errorText = errorText.replace('{dateSample}', sample);
	errorLayer.innerHTML = errorText;
}

document.write('<link href="/daily/shared/products/cars/wizards/NoScript.css" media="screen" rel="stylesheet" type="text/css" />');