Event.observe(window, 'load', function() {
  var h = window.location.href.split("#");
  if(h.length && h[1] == "contact") {
    $$('embed').each(function(i) { i.style.visibility='hidden' });
    new Ulanguzi.Effects.ModalAppear('contactFormContainerContainer');
  }
});

function registerUser() {
  if($('first_name').value == "")
  {
    alert("Please enter your first name.");
    $('first_name').focus();
    return false;
  }
    
  if($('last_name').value == "")
  {
    alert("Please enter your last name.");
    $('last_name').focus();
    return false;
  }
  
  if($('email').value == "")
  {
    alert("Please enter your email.");
    $('email').focus();
    return false;
  }
  
  if(!$("address").value) {
    alert("Please enter your address.");
    $("address").focus();
    return false;
  }
  
  if(!$("city").value) {
    alert("Please enter your city.");
    $("city").focus();
    return false;
  }
  
  if(!$("state").selectedIndex) {
    alert("Please enter your state.");
    $("state").focus();
    return false;
  }
  
  if(!$("unit_type").selectedIndex) {
    alert("Please enter your preferred suite type.");
    $("unit_type").focus();
    return false;
  }
  
  if(!$("preferred_comm").selectedIndex) {
    alert("Please enter your preferred method of communication.");
    $("preferred_comm").focus();
    return false;
  }
  
  if(!$("comments").value) {
    alert("Please enter your comments.");
    $("comments").focus();
    return false;
  }
  
  if($('zip').value == "")
  {
    alert("Please enter your zip code.");
    $('zip').focus();
    return false;
  } 
  
  if($('phone').value == "")
  {
    alert("Please enter your phone number.");
    $('phone').focus();
    return false;
  }
  
  var params = 'email=' + $('email').value;
  params = params + '&first_name=' + $('first_name').value;
  params = params + '&last_name=' + $('last_name').value;
  params = params + '&address=' + $('address').value;
  params = params + '&address2=' + $('address2').value;
  params = params + '&city=' + $('city').value;
  params = params + '&state=' + $('state').value;
  params = params + '&zip=' + $('zip').value;
  params = params + '&phone=' + $('phone').value;
  params = params + '&comments=' + $('comments').value;
  params = params + '&unit_type=' + $('unit_type').options[$('unit_type').selectedIndex].value;
  params = params + '&contact_me=' + $('contact_me_yes').checked;  
  params = params + '&realtor=' + $('realtor_yes').checked;
  params = params + '&receive_emails=' + $('receive_emails_yes').checked;
  params = params + '&comments=' + $('comments').value;
  params = params + '&preferred_comm=' + $('preferred_comm').value;
  params = params + '&heard_about=' + $('heard_about').options[$('heard_about').selectedIndex].value;
  params = params + '&other=' + $('other').value;
  
  if($('other').value) {
    params = params + ', ' + $('other').value;
  }

  var ajax = new Ajax.Updater(
    'contactForm',
    '/lib/php/contact-process.php',
    {
      method: 'post',
      parameters: params
    }
  );
  urchinTracker('/lib/php/contact-process.php');
  return false;
}