/* -*- mode: java -*- */

/*****************************************
 * Copyright (c) 2006, Emmett M. Pate, Jr.
 * emmett@epate.com
 *
 */

function validateLogin() {
 if (document.login.email.value=='') {
  alert('Please Enter your email address.');
  return false;
 }
 if (document.login.password.value=='') {
  alert('Please Enter your password.');
  return false;
 }
}

function setupForm() {
 var searchSettings = getCookie("aaaridx-ps");
 /* setSchools(document.ps.city); */
 fillForm(searchSettings);
}

function getCookie(name) {
 var start = document.cookie.indexOf(name+"=");
 var len = start+name.length+1;
 if ((!start) && (name != document.cookie.substring(0,name.length))) return '';
 if (start == -1) return '';
 var end = document.cookie.indexOf(";",len);
 if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
 }

function fillForm(str) {
 getValue(str, "city", document.ps.city, "select");
 getValue(str, "pt", document.ps.pt, "select");
 getValue(str, "nbh", document.ps.nbh, "text");
 getValue(str, "zip", document.ps.zip, "text");
 getValue(str, "br", document.ps.br, "select");
 getValue(str, "ba", document.ps.ba, "select");
 getValue(str, "sqft", document.ps.sqft, "select");
 getValue(str, "remarks", document.ps.remarks, "text");
 getValue(str, "min", document.ps.min, "select");
 getValue(str, "max", document.ps.max, "select");
 getValue(str, "mls", document.ps.mls, "text");
}

function getValue(string,elementName,object,elementType) {
 var startPos = string.indexOf(elementName + "&")
 if (startPos > -1) {
  startPos = startPos + elementName.length + 1;
  var endPos = string.indexOf("&",startPos);
  if (endPos == -1) endPos = string.length;

  var elementValue = unescape(string.substring(startPos,endPos));

  if (elementType == "text")     object.value = elementValue;
  if (elementType == "password") object.value = elementValue;
  if (elementType == "select") {
   for (var i=0; i<object.length; i++) {
    if (object[i].value == elementValue) object.selectedIndex = i;
   }
  }
  if (elementType == "checkbox") object.checked = onCheck(elementValue);
  if (elementType == "radio")    object[elementValue].checked = true;
 }
}

function getCookieValue(string,elementName) {
 var startPos = string.indexOf(elementName + "&")
 if (startPos > -1) {
  startPos = startPos + elementName.length + 1;
  var endPos = string.indexOf("&",startPos);
  if (endPos == -1) endPos = string.length;
  return unescape(string.substring(startPos,endPos));
 }
}

/*
function setSchools(t) {
 //alert(t.value);
 //alert(document.ps.hs.value);

 // enable all schools if City='Any' or '%'
 var hs = document.ps.hs;

 hs.options.length = 0;
 hs.options[ hs.options.length ] = new Option('Any', '%');
 for (i=0; i<schools.length-1; i++)
 {
  if (t.value == schools[i][0] || t.value == "%")
  {
   hs.options[ hs.options.length ] = new Option(schools[i][2], schools[i][1]);
  }
 }
}
*/

