<script language="javascript"><!--
function ClearValue(field, strCheck)
	{
		if(field.value == strCheck)
		field.value = "";				
	}
function Repopulate(field, strCheck)
	{
		if(field.value == "")
		field.value = strCheck;
	}
function reset() {
	document.search.T1.value="";
	document.search.dfrom.value="";
	document.search.dto.value="";
	document.search.pfrom.value="";
	document.search.pto.value="";
	document.search.T1.focus();
	}
	
function IsValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}	
function check_form() {
  var error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";
  var error_found = false;
  var error_field;
  var T1 = document.search.T1.value;
  var dfrom = document.search.dfrom.value;
  var dto = document.search.dto.value;
  var pfrom = document.search.pfrom.value;
  var pto = document.search.pto.value;
  var pfrom_float;
  var pto_float;
  var date_err_msg;

  if ( ((T1 == '') || (T1.length < 1)) && ((dfrom == '') || (dfrom == '') || (dfrom.length < 1)) && ((dto == '') || (dto == '') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) ) {
    error_message = error_message + "* At least one of the fields in the search form must be entered.\n";
    error_field = document.search.T1;
    error_found = true;
  }

  if ((dfrom.length > 0) && (dfrom != '')) {
    if (!IsValidDate(dfrom)) {
      error_message = error_message + "* Invalid From Date.\n";
      error_field = document.search.dfrom;
      error_found = true;
    }
  }

  if ((dto.length > 0) && (dto != 'mm/dd/yyyy')) {
    if (!IsValidDate(dto, 'mm/dd/yyyy')) {
      error_message = error_message + "* Invalid To Date.\n";
      error_field = document.search.dto;
      error_found = true;
    }
  }

  if ((dfrom.length > 0) && (dfrom != 'mm/dd/yyyy') && (IsValidDate(dfrom, 'mm/dd/yyyy')) && (dto.length > 0) && (dto != 'mm/dd/yyyy') && (IsValidDate(dto, 'mm/dd/yyyy'))) {
    if (!CheckDateRange(document.search.dfrom, document.search.dto)) {
      error_message = error_message + "* To Date must be greater than or equal to From Date.\n";
      error_field = document.search.dto;
      error_found = true;
    }
  }

  if (pfrom.length > 0) {
    pfrom_float = parseFloat(pfrom);
    if (isNaN(pfrom_float)) {
      error_message = error_message + "* Price From must be a number.\n";
      error_field = document.search.pfrom;
      error_found = true;
    }
  } else {
    pfrom_float = 0;
  }

  if (pto.length > 0) {
    pto_float = parseFloat(pto);
    if (isNaN(pto_float)) {
      error_message = error_message + "* Price To must be a number.\n";
      error_field = document.search.pto;
      error_found = true;
    }
  } else {
    pto_float = 0;
  }

  if ( (pfrom.length > 0) && (pto.length > 0) ) {
    if ( (!isNaN(pfrom_float)) && (!isNaN(pto_float)) && (pto_float < pfrom_float) ) {
      error_message = error_message + "* Price To must be greater than or equal to Price From.\n";
      error_field = document.search.pto;
      error_found = true;
    }
  }

  if (error_found == true) {
    alert(error_message);
    error_field.focus();
    return false;
  } else {
    //document.search.dfrom.value = DateFormat(document.search.dfrom.value, "mm/dd/yyyy");
	//document.search.dto.value = DateFormat(document.search.dto.value, "mm/dd/yyyy");
    return true;
  }
}
//--></script>