var request; 

function Form3Do(theForm, project_name) {

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

   var q = build_query_string(theForm);

   var url = 'submit.php5?' + q;
   call_url(url);

   /* MSN conversion code + 2 * Google conversion code */
/*
   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');
*/

   my_alert('Thank you', "Thank you for contacting CondominiumCentral.net!\n" +
                         "We have received your request\n" +
                         "and one of our agents will contact you shortly.", true);

   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;
      if (name == '') {
         continue;
      }
      if (q != '') {
         q = q + '&';
      }     
      q = q + name + '=' + escape(value);
   }
   return q;
}

function Form3Validate(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);
  }
  return (true);
}
