var whichDate;	
var baseUrl = "http://www.hotel.us/";

/* launch calendar popup */
function datePicker(dateField){
    whichDate = dateField;
    popUp(baseUrl + 'calendar.mdlx?disabled=true',500,180,false);
}

			
/* Set datefield - called by calendar popup */
function setDateOfListener(newDate){
    dateListener = newDate;

    if (whichDate=="startDate"){
        document.forms["search"].startDate.value=newDate;
    }else{
        document.forms["search"].endDate.value=newDate;			
    }
}
			
/* search form validation */
function searchValidate(oForm){

    var startDate = new Date(oForm.startDate.value).getTime();
    var endDate = new Date(oForm.endDate.value).getTime();
	var fiveDays = 86400000*5;

    if(oForm.startDate.value==""){oForm.startDate.value=getShortDate(7);}
    if(oForm.endDate.value==""){oForm.startDate.value=getShortDate(9);}
    if (oForm.city.value==""){
        alert("Oops! You must specify a city or a town to search.");
        return(false);
    }else if(startDate > endDate){
        alert("Oops! Your checkout date is a date that preceeds your checkin date.");			
        return(false);
    }
	
    submit(oForm);
}

function submit(oForm){
	oForm.action="http://www.hotel.us/searchResults.mdlx";
	oForm.submit();
}

