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);
}
		
/* 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 (!validDate(oForm.startDate.value)) {
		alert("Oops! The date you provided for a check-in was invalid.  Please provide a valid date in the following format [mm/dd/yy].");			
		return(false);
    }else if (!validDate(oForm.endDate.value)) {
		alert("Oops! The date you provided for a check-out was invalid.  Please provide a valid date in the following format [mm/dd/yy].");	
		return(false);
    }else if(startDate > endDate){
		alert("Oops! Your checkout date is a date that preceeds your checkin date.");			
		return(false);
    }
	
    if ((oForm.searchClass[1].checked) && ((startDate+fiveDays) >= endDate)){
		myPrompt = confirm("Most Vacation Condos require a 5 night minimum stay. \n You may not find as much availability with the dates \n you are searching. Would you like to continue?");
		return(myPrompt);
    }
    submit(oForm);
}

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


function validDate(value){
//assumes a format of MM/dd/yyyy or MM/dd/yy

	flag = false;	
    aValue = value.split("/");
    iValue = aValue[2] + aValue[0] + aValue[1];

	if (Number(iValue)>0) {
		if (aValue[0].length>=1 && aValue[0].length<=2 ) {
			if (aValue[1].length>=1 && aValue[1].length<=2 ) {
				if (aValue[2].length==2 || aValue[2].length==4) {
					flag=true;
				}
			}
			
		}
	}
	return flag;
}