function performSearch() {
    var i;
    var theForm = document.offerSearchForm;
    var searchUrl = theForm.action + "?";

    // process dates
    if(theForm.when[1].checked) {
        // check-in date
        searchUrl += "&ciDate=" + theForm.ciDate.value;
        searchUrl += "&coDate=" + theForm.coDate.value;
    }

    // process places
    if(theForm.where.selectedIndex == 1) {
        // destinations
        for (i=0; i<theForm.destinationID.length; i++) {
            if (theForm.destinationID[i].checked) {
                searchUrl += "&destinationID=" + theForm.destinationID[i].value;
            }
        }
    }
    else if(theForm.where.selectedIndex == 2) {
        // hotels
        for (i=0; i<theForm.propertyID.length; i++) {
            if (theForm.propertyID[i].checked) {
                searchUrl += "&propertyID=" + theForm.propertyID[i].value;
            }
        }
    }

    // process interests
    for (i=0; i<theForm.interest.length; i++) {
        if (theForm.interest[i].checked) {
            searchUrl += "&interest=" + theForm.interest[i].value;
        }
    }

    if(theForm.passion != null) {
        for (i=0; i<theForm.passion.length; i++) {
            if (theForm.passion[i].checked) {
                searchUrl += "&passion=" + theForm.passion[i].value;
            }
        }
    }

    document.location = searchUrl;

    return false;
}

function checkSearchDates(form, event) {
    var formObj = form;
    if (event.type == "focus")   {
        if(formObj.ciDate.hasFocus == "true")    {
            var checkIn = new validDate(formObj.ciDate);
            if (  !checkIn.valid ) { formObj.ciDate.value="";}
        }
        if(formObj.coDate.hasFocus == "true")    {
            var checkOut = new validDate(formObj.coDate);
            if (  !checkOut.valid ) { formObj.coDate.value="";}
        }
    }
    if (event.type == "blur")   {
        if(formObj.ciDate.hasFocus == "false")    {
            var checkOut = new validDate(formObj.coDate);
            var checkIn = new validDate(formObj.ciDate);
            if ( checkIn.valid ) {
                checkIn.setField();
                if (checkOut.valid ) { before = (checkIn.diffDate(checkOut.d) <= 0);}
                if ( (! (checkOut.valid)) || before) {
                    checkOut.setD(checkIn.d);
                    checkOut.nextDay();
                    checkOut.setField();
                }
            } else {
                formObj.ciDate.value=dateFormatString;
            }
        }
        if(formObj.coDate.hasFocus == "false")    {
            var checkOut = new validDate(formObj.coDate);
            if ( checkOut.valid ) { checkOut.setField(); } else {formObj.coDate.value=dateFormatString;}
        }
    }
}

// updates the WHERE area
function updateWhere() {
    var destCheckboxes = document.getElementById("destinationCheckboxes");
    var hotelCheckboxes = document.getElementById("hotelCheckboxes");

    switch(document.offerSearchForm.where.selectedIndex) {
        case 0:
            destCheckboxes.style.display = "none";
            hotelCheckboxes.style.display = "none";
            break;

        case 1:
            destCheckboxes.style.display = "block";
            hotelCheckboxes.style.display = "none";
            break;

        case 2:
            destCheckboxes.style.display = "none";
            hotelCheckboxes.style.display = "block";
    }
}

// (de)select all checkboxes given the section id
function setSectionCheckboxes(sectionId, checked) {
    var sectionDiv = document.getElementById(sectionId);
    if(sectionDiv != null) {
        setCheckboxes(sectionDiv, checked);
    }
}

function showSecondaryNav(tabID) {
    document.getElementById('destinationsTab').className = "";
    document.getElementById('hotelsTab').className = "";

    document.getElementById('destinationsTabDiv').style.display = "none";
    document.getElementById('hotelsTabDiv').style.display = "none";

    document.getElementById(tabID).className = "locked";
    document.getElementById(tabID+'Div').style.display = "block";
}

function hilteSpan(elementId,action){
    var container = document.getElementById(elementId);

    if (action == "off" && container.className != "locked") container.style.backgroundImage = "url('/whotels/images/site/common/hoverHiliteOff.gif')";
    else if (action == "on") container.style.backgroundImage = "url('/whotels/images/site/common/hoverHilite.gif')";
}
