/* Generic Functions */

/*
function isValidEmail(s) {
  var temp = s.replace(/\s/g, "")
  return (temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{3}$/)) && 
    temp.charAt(0) != "." && !(temp.match(/\.\./))
}
*/

function isValidEmail(s) {
  var filter=/^(\w+(\-?\.?\w*)*)@[A-Za-z]\w+(\-?\.?\w*)*(\.[A-Za-z]{2,})+$/;
  return filter.test(s);
}

function toggleDisplay(elementID) {
  var element = document.getElementById(elementID);
  element.style.display = (element.style.display == "none") ? "" : "none";
  return false;
}

String.prototype.trim = function() {
  return this.replace(/^\s*|\s*$/g, "")
}

/* End Generic Functions */

/* Search Functions */

function searchTypeChanged(newType) {
  document.getElementById("modelField").style.display = (newType == "Model") ? "" : "none";
  document.getElementById("bodyTypeField").style.display = (newType == "Body") ? "" : "none";
}

var popupWindow;
function showPopup(href) {
  popupWindow = window.open(href, "image", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=850,height=580");
  popupWindow.focus();
  return false;
}

function relatedSearch(searchType, model, bodyType, priceRange) {
  document.getElementById("searchTypeField").value = searchType;
  document.getElementById("modelField").value = model;
  document.getElementById("bodyTypeField").value = bodyType;
  document.getElementById("priceRangeField").value = priceRange;
  document.getElementById("searchForm").submit();
  return false;
}

function navigate(type, model, bodyType, priceRange, offset) {
  document.getElementById("typeField").value = type;
  document.getElementById("modelField").value = model;
  document.getElementById("bodyTypeField").value = bodyType;
  document.getElementById("priceRangeField").value = priceRange;
  document.getElementById("offsetField").value = offset;
  document.getElementById("pageForm").submit();
  return false;
}

/* End Search Functions */