//-----------------------------------------------------------
function PropertySearch()
{
  var msg = "";
  var rooms, area;
  with (document.PropertySearch) {
    rooms = bedrooms.selectedIndex;
		if (document.PropertySearch.EndDate.value != "") {
      if (document.PropertySearch.StartDate.value == "")
    	  msg = "Please enter Date from and Date to." + "\n" + msg;			
    	if (!isvalid_date(document.forms[0].EndDate.value))
    	  msg = "Please enter Date to.\ Format is mm/dd/yyyy" + "\n" + msg;
    	else if (!greaterThanYesterday(document.forms[0].EndDate.value)) 				
				msg = "Please make sure the date you entered is correct.\nThe Date To must be greater than today\'s date\nand entered in the following format: mm/dd/yyyy eg " + writeToday() + "\n";
    }
    if (document.forms[0].StartDate.value != "") { 
		  if (!greaterThanYesterday(document.forms[0].StartDate.value) || !isvalid_date(document.forms[0].StartDate.value)){
			  msg = "Please make sure the date you entered is correct.\nThe Date From must be greater than today\'s date\nand entered in the following format: mm/dd/yyyy eg " + writeToday() + "\n";
		  }			
		}	
    area = select_area.selectedIndex;
    if (select_area.options[area].value == 0)
      msg = "Please select a location" + "\n" + msg;
    if (document.PropertySearch.select_area.options[area].value == 39)
      msg = "'Please select a location'" + "\n" + msg;
    if (compare_dates(StartDate.value, EndDate.value))
      msg = "Date from is after Date to. Please correct. " + "\n" + msg;	
    if (msg == "")
      document.PropertySearch.submit();
    else {
      alert(msg);
      return;
    }
  }
}
//------------------------------------------------------------------------------
function isvalid_date (date1) 
{
  var  items = date1.split("/");
  var	tempDate=new Date(items[2],items[0] - 1 ,items[1]);
	if ( (tempDate.getFullYear()==items[2]) &&
	     (tempDate.getMonth()==(items[0]-1)) &&	
	     (tempDate.getDate()==items[1]))
	return true;
  else
  return false;  	     
}
//------------------------------------------------------------------------------
function compare_dates(date1,date2){
   var 	error=false;
   var 	items1 = date1.split('/');
   var 	items2 = date2.split('/');
	
	tempDate1=new Date(items1[2],items1[0]-1,items1[1]);
	tempDate2=new Date(items2[2],items2[0]-1,items2[1]);
	dateUTC1=Date.parse(tempDate1);
	dateUTC2=Date.parse(tempDate2);
	if (dateUTC1 > dateUTC2 )
		return true;
	else 
		return false;
}
//------------------------------------------------------------------------------
function greaterThanYesterday(date1){
   var today = new Date();
   var items = date1.split("/");
   var tempDate=new Date(items[2],items[0]-1,items[1]);
   var oneday = 24*60*60*1000;
   	if(tempDate.getTime() > (today.getTime() - oneday))
   		return true;
      	else 
      		return false;
}
//------------------------------------------------------------------------------
function dateOffset(date1,offset){
   var  items = date1.split("-");
   var	tempDate=new Date(items[2],items[1]-1,items[0]);
   var tempOffset ;
   	if (offset!=0){
   		tempOffset = offset * 24*60*60*1000;
   	}
	else tempOffset = 0;
	return (tempDate.getTime() + tempOffset);
}
//------------------------------------------------------------------------------
function writeToday(){
	var today = new Date();
	var month = (today.getMonth() < 9) ? '0' + (today.getMonth() +1) : (today.getMonth()+1);
	return (month + '/'+ (today.getDate()<10 ? '0'+today.getDate() : today.getDate() ) +'/'+today.getYear());
}