//<!--
// This function will validate a form
function validateHVForm(theform)
{
  pass = 1; //assume everything is ok
  msg = "The following problems where found in trying to submit this form:\n\n";

  //make sure required fields are not empty
  if (theform.name.value == "")
  {
    msg = msg + "- Name cannot be empty\n";
    pass = 0;
  }
  if (theform.phone.value == "")
  {
    msg = msg + "- Phone number cannot be empty\n";
    pass = 0;
  }
  if (theform.address.value == "")
  {
    msg = msg + "- Address cannot be empty\n";
    pass = 0;
  }
  if (theform.city.value == "")
  {
    msg = msg + "- City cannot be empty\n";
    pass = 0;
  }
  if (valButton(theform.workingwith) == null)
  {
    msg = msg + "- Please tell me if you are working with another Realtor\n";
    pass = 0;
  }
  if (pass == 1)
  {
    return true;
  }
  else
  {
    alert(msg);
    return false;
  }
}

function validateContactForm(theform)
{
  pass = 1; //assume everything is ok
  msg = "The following problems where found in trying to submit this form:\n\n";

  //make sure required fields are not empty
  if (theform.name.value == "")
  {
    msg = msg + "- Name cannot be empty\n";
    pass = 0;
  }
  if (theform.phone.value == "")
  {
    msg = msg + "- Phone number cannot be empty\n";
    pass = 0;
  }
  if (theform.message.value == "")
  {
    msg = msg + "- Message cannot be empty\n";
    pass = 0;
  }
  if (pass == 1)
  {
    return true;
  }
  else
  {
    alert(msg);
    return false;
  }
}


function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphaNum(string) {
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return false;
    else
        return true;
}

function isName(string) {
    if (string.search(/^[A-Za-z-]+\s[A-Za-z-]+$/) != -1)
        return true;
    else
        return false;
}

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return null;
}

//-->

