﻿function SearchHotel() {
    if (trim(document.getElementById("hotel_destination").value).length == 0) {
        alert("Inserire una destinazione");
        return false;
    } else {
        if((document.getElementById("hotel_checkin").value == "gg/mm/aaaa") ||
            (document.getElementById("hotel_checkout").value == "gg/mm/aaaa")) {
            if((document.getElementById("hotel_checkin").value == "gg/mm/aaaa") &&
                (document.getElementById("hotel_checkout").value == "gg/mm/aaaa")) {
                alert("Selezionare Check In e Check Out");
                return false;
            } else {
                if(document.getElementById("hotel_checkin").value == "gg/mm/aaaa") {
                    alert("Selezionare Check In");
                    return false;
                } else {
                    if(document.getElementById("hotel_checkout").value == "gg/mm/aaaa") {
                        alert("Selezionare Check Out");
                        return false;
                    }
                }
            }
        } else {
            var str1 = document.getElementById("hotel_checkin").value;
            var str2 = document.getElementById("hotel_checkout").value;
            var date1 = new Date(str1.substring(6,10), str1.substring(3,5)-1, str1.substring(0,2));
            var date2 = new Date(str2.substring(6,10), str2.substring(3,5)-1, str2.substring(0,2));
            str1 = str1.substring(6,10) + str1.substring(3,5) + str1.substring(0,2);
            str2 = str2.substring(6,10) + str2.substring(3,5) + str2.substring(0,2);
            if (date2<date1) {
                alert("Attenzione! Check In è maggiore di Check Out");
                return false;
            } else {
                document.location = "/controlli/encrhtl.ashx?dest=" + trim(document.getElementById("hotel_destination").value) + "&cat=" + document.getElementById("hotel_categories").value + "&checkin=" + str1 + "&checkout=" + str2;
            }
        }
    }
}

function trim(arg) {
    re=/\s+$|^\s+/g;
    return arg.replace(re,"");
}
