function Form1Do(theForm) {

   if (!Form1Validate(theForm)) {
      return false;
   }

   var q = build_query_string(theForm);

   var url;

   if (theForm.buyer.checked) {
      url = 'submit.php5?' + q;
   } else {
      url = '/append.php?' + q + '&type=developer';
   }

   call_url(url);

   /* MSN conversion code + 2 * Google conversion code */
   if (false && theForm.buyer.checked) {
      call_url('http://10009.r.msn.com/?type=1&cp=1');
      call_url('http://www.googleadservices.com/pagead/conversion/1072011459/imp.gif?value=1&label=lead&script=0');
      call_url('http://www.googleadservices.com/pagead/conversion/1072011459/?label=Iqh2CNawPRDDsZb_Aw&script=0');
   }

   if (theForm.buyer.checked) {
      my_alert('Thank you', "Thank you for contacting CondominiumCentral.net!\n" +
                            "We have received your request for information about " + theForm.Property.value + "\n" +
                            "and one of our agents will contact you shortly.", true);
   } else {
      my_alert('Thank you', "Thank you for contacting CondominiumCentral.net!\n" +
                            "We will review your request\n" +
                            "and one of our customer service representatives will contact you shortly.", false);
   }
   return false;
}

function build_query_string(theForm) {
   var q = '';
   for (i = 0; i < theForm.elements.length; i++) {
      var name  = theForm.elements[i].name;
      var value = theForm.elements[i].value;
      var type  = theForm.elements[i].type;
      if (name == '') {
         continue;
      }
      if (type == 'radio' && !theForm.elements[i].checked) {
        continue;
      }
      if (q != '') {
         q = q + '&';
      }     
      q = q + name + '=' + escape(value);
   }
   return q;
}

function Form1Validate(theForm) {

  if (theForm.FullName.value == "") {
    my_alert('Error', 'Please enter your name');
    theForm.FullName.focus();
    return (false);
  }

  if (theForm.FullName.value.length < 4) {
    my_alert('Error', 'Please enter your name');
    theForm.FullName.focus();
    return (false);
  }

  if (theForm.FullName.value.indexOf(' ') < 1) {
    my_alert('Error', 'Please enter your name');
    theForm.FullName.focus();
    return (false);
  }
 
  if (theForm.FullName.value.length > 50) {
    my_alert('Error', 'Please enter your name');
    theForm.FullName.focus();
    return (false);
  }

  if (!is_valid_email(theForm.EmailAddress.value)) {
    my_alert('Error', "Please enter your email address");
    theForm.EmailAddress.focus();
    return (false);
  }

  if (theForm.EmailAddress.value.length > 50) {
    my_alert('Error', "Please enter your email address");
    theForm.EmailAddress.focus();
    return (false);
  }

  if (theForm.PhoneNumber.value.length < 10) {
    my_alert('Error', "Please enter your phone number");
    theForm.PhoneNumber.focus();
    return (false);
  }

  if (theForm.PhoneNumber.value.length > 30) {
    my_alert('Error', "Please enter your phone number");
    theForm.PhoneNumber.focus();
    return (false);
  }

  if (!theForm.buyer.checked && !theForm.developer.checked) {
    my_alert('Error', "Please select one of the options");
    theForm.WhoAmI.focus();
    return (false);
  }

  if (theForm.Property.value == "xx" && theForm.MyProperty.value == "") {
    my_alert('Error', "Please enter a property name");
    return (false);
  }

  return (true);
}
