function SyncDates(depDayObject, depMonthObject, arrDayObject, arrMonthObject, eventType){
        (eventType == "depart")? setOtherDates('departureDay', 'searchfrm') : setOtherDates('returnDay', 'searchfrm');
}
function carSyncDates(depDayObject, depMonthObject, arrDayObject, arrMonthObject, eventType){
        (eventType == "depart")? setOtherDates('departureDay', 'searchfrm') : setOtherDates('returnDay', 'searchfrm');
}

function setDays(month, day, year) {
if(month.constructor != Number) {
var date = month.options[month.selectedIndex].value;
var month = getMonth(date) - 1;
var year = getYear(date);
}
Date.DAYSINMONTH[1] = (year && !isLeapYear(year)) ? 28 : 29;
var index = day.length;
if(index == Date.DAYSINMONTH[month]) return;
else if(index < Date.DAYSINMONTH[month]) {
for(var i = index; i < Date.DAYSINMONTH[month]; i++) {
day[i] = new Option(i + 1);
}
}
else if(index > Date.DAYSINMONTH[month]) {
for(var i = index; i >= Date.DAYSINMONTH[month]; i--) {
day[i] = null;
}
}
if(day.selectedIndex > index) day.selectedIndex = 0;
}
function getDateArray(length) {
var arr = [];
var date = new Date();
var startYear = date.getFullYear();
var startMonth = date.getMonth();
for(var i = 0; i < 12; i++) {
var num = ((startMonth + i) >= Date.MONTHS.length) ? (startMonth + i) - Date.MONTHS.length : startMonth + i;
var year = ((startMonth + i) >= Date.MONTHS.length) ? startYear + 1 : startYear;
var month = (length) ? Date.MONTHS[num].substring(0, 3) : Date.MONTHS[num];
var value = String(num + 1);
if(value.length == 1) value = "0" + value;
arr[i] = [year + value, month + " " + year];
}
return arr;
}
function getMonth(date) {
return Number(date.substring(4, 6));
}
function getYear(date) {
return Number(date.substring(0, 4));
}
function isLeapYear(year) {
        return (year%4 ==0);
}
function isValidDate(type, startMonth, startDay, endMonth, endDay) {
var msg, start, end;
var now = new Date();
var valid = function(a, b, msg) {
//        alert(a + " > " + b + "\n" + (a.getTime() > b.getTime()))
if(a.getTime() > b.getTime()) {
alert(msg);
return false;
}
return true;
}
if(type == "creditcard") {
msg = "Your card valid from date must be before your card valid to date.";
start = getDate(startDay.options[startDay.selectedIndex].text, startMonth.selectedIndex, 0);
end = getDate(endDay.options[endDay.selectedIndex].text, endMonth.selectedIndex);
if(!valid(start, now, "Your card valid from date must be before the current date.")) return false;
now.setMonth(now.getMonth() - 1);
if(!valid(now, end, "Your card valid to date must be after the current date.")) return false;
}



else if(type == "departure") {
var sm = startMonth.options[startMonth.selectedIndex].value;
var month = (sm.length == 6) ? getMonth(sm) - 1 : sm - 1;
var year = (sm.length == 6) ? getYear(sm) : now.getFullYear();
var sDay = (startDay.type == "select-one") ? startDay.options[startDay.selectedIndex].text : startDay.value;
if(sDay > Date.DAYSINMONTH[month]) {
alert("There are only " + Date.DAYSINMONTH[month] + " days in " + Date.MONTHS[month]);
startDay.value = 1;
return false;
}


msg = "Your departure date must be before your return date.";
start = getDate(year, month, sDay);
if(!valid(now, start, "Your departure date must be after the current date.")) return false;
if(!endMonth) return true;
var em = endMonth.options[endMonth.selectedIndex].value;
month = (em.length == 6) ? getMonth(em) - 1 : em - 1;
year = (em.length == 6) ? getYear(em) : year;
var eDay = (endDay.type == "select-one") ? endDay.options[endDay.selectedIndex].text : endDay.value;
if(eDay > Date.DAYSINMONTH[month]) {
alert("There are only " + Date.DAYSINMONTH[month] + " days in " + Date.MONTHS[month]);
endDay.value = 1;
return false;
}
end = getDate(year, month, eDay);
}
else if (type == "switch") {
end = getDate(endDay.options[endDay.selectedIndex].text, endMonth.selectedIndex);
now.setMonth(now.getMonth() - 1);
if(!valid(now, end, "Your card valid to date must be after the current date.")) return false;
if (startDay.options[startDay.selectedIndex].text == "----" || startMonth.selectedIndex.text == "--") {
start = getDate(startDay.options[1].text, startMonth.options[1], 0) }
else {
start = getDate(startDay.options[startDay.selectedIndex].text, startMonth.selectedIndex, 0);
if(!valid(start, now, "Your card valid from date must be before the current date.")) return false;
}
}
return valid(start, end, msg);
}
function dateCompare(low, high, msg, field) {
if(low.getTime() > high.getTime()) {
alert(msg);
field.value = "";
field.focus();
}
}
function getDate(year, month, day) {
var d = new Date();
d.setDate(1);
if(typeof(year) != "undefined") d.setYear(year);
if(typeof(month) != "undefined") d.setMonth(month);
if(typeof(day) != "undefined") d.setDate(day);
return d;
}
if(!Date.MONTHS) {
Date.MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
Date.DAYSINMONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function setSelected(select, name, bool) {
for(var i = 0; i < select.options.length; i++) {
var text = (bool) ? select.options[i].value : select.options[i].text;
if(text == name) {
select.selectedIndex = i;
return;
}
}
}
function getSelected(select) {
return select.options[select.selectedIndex];
}
function deleteOptions(select) {
select.options.length = 0;
}
function writeOptions(select, arr) {
select.options.length = 0;
for(var i = 0; i < arr.length; i++) {
if(arr[i].constructor == Array) select.options[select.options.length] = new Option(arr[i][1], arr[i][0]);
else select.options[select.options.length] = new Option(arr[i]);
}
}

function onBook(event_msg,supplier_id,supplier_name,to_url)
{
        if(typeof(ROIID)+''!='undefined')
        {
                 TrackEvent(event_msg, 0);
        }

        document.write('<!--wr img---><IMG src="/general_click_history.php?area=car&supplier_id='+supplier_id+'&supplier_name='+supplier_name+'" border="0" height="10" width="10">');

    window.location = to_url;
}

function showSearchingAnimation() {
    if (currentLogoIndex == vendorsLogos.length) currentLogoIndex = 0;
    $("holdPageVendorLogo").src = vendorsLogos[currentLogoIndex++];
    $("plane2").src = $("plane2").src;
    setTimeout(showSearchingAnimation, 3500);
}

function sendme()
{
    err_msg = "";
    if(document.searchfrm.city.value == 0) { err_msg += "Please select a city.\n"; }
    if(err_msg) {
        alert(err_msg); return;
    }

    try {
        $("form_title").innerHTML = textSearching;
    } catch(e) {}
	
	Element.show("searching_page");
    Element.hide("page_show");
    $("bl_text2_block").style.height      = "620px";
	
    showSearchingAnimation();
    
    document.searchfrm.submit();

    if ($("spotlight_block"))       Element.hide("spotlight_block");
    if ($("seo_text_block"))        Element.hide("seo_text_block");
    
}
