function submitsearchform(a, b) {
    var c = new Date();
    var d = c.getDate();
    var e = c.getMonth();
    var f = c.getFullYear();
    var g = new Date(f, e, d, 0, 0, 0);
    var h = a.arriveeday[a.arriveeday.selectedIndex].value;
    var i = a.arriveemonth[a.arriveemonth.selectedIndex].value;
    var j = a.departday[a.departday.selectedIndex].value;
    var k = a.departmonth[a.departmonth.selectedIndex].value;
    if ((i - 1) < e) {
        var l = (f + 1)
    } else {
        var l = f
    }
    if ((k - 1) < e) {
        var m = (f + 1)
    } else {
        var m = f
    }
    var n = new Date(l, (i - 1), h, 0, 0, 0);
    var o = new Date(m, (k - 1), j, 0, 0, 0);
    if (a.arriveeday.selectedIndex == 0) {
        alert("Please select arrival day from the drop down box");
        a.arriveeday.focus()
    } else if (a.arriveemonth.selectedIndex == 0) {
        alert("Please select arrival month from the drop down box");
        a.arriveemonth.focus()
    } else if (checkValidDate(i, h, l)) {
        alert("The date selected is incorrect for the selected month");
        a.arriveeday.focus()
    } else if (n.getTime() < g.getTime()) {
        alert("The arrival date selected has to be greater than or equal to the current date");
        a.arriveeday.focus()
    } else if (a.departday.selectedIndex == 0) {
        alert("Please select departure day from the drop down box");
        a.departday.focus()
    } else if (a.departmonth.selectedIndex == 0) {
        alert("Please select departure month from the drop down box");
        a.departmonth.focus()
    } else if (checkValidDate(k, j, m)) {
        alert("The date selected is incorrect for the selected month");
        a.departday.focus()
    } else if (o.getTime() <= n.getTime()) {
        alert("The departure date selected has to be greater than the arrival date ");
        a.departday.focus()
    } else if (days_between(n, o) > 10) {
        if (confirm("Your date selection indicates a  " + days_between(n, o) + "  nights stay, do you confirm this?")) {
            a.submit()
        }
    } else {
        a.submit()
    }
}
$(document).ready(function () {
    $("#arrival_date").datepicker({
        showOn: 'button',
        buttonImage: 'img/cal.gif',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: "m/d/yy",
		onSelect: setArrDate,
        minDate: new Date()
    });
    $("#departure_date").datepicker({
        showOn: 'button',
        buttonImage: 'img/cal.gif',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: "m/d/yy",
        onSelect: setDepDate,
        minDate: new Date()
    });

});

function setArrDate(a){
	arrDate = a.split("/");
	$('#arriveeday').val(arrDate[1]);
	$('#arriveemonth').val(arrDate[0]);

	setDepDateFromArrival();
}

function setDepDate(a){
	depDate = a.split("/");
	$('#departday').val(depDate[1]);
	$('#departmonth').val(depDate[0]);
}

function setDepDateDateChange(a){
	depDate = a.split("/");
	newMonth	=	parseInt(depDate[0])+1;
	$('#departday').val(depDate[1]);
	$('#departmonth').val(newMonth);
}
