/**
 * Contact page scripts
 *
 * Copyright 2006 Peter Chng unless otherwise noted.
 * Author attribution on other code given.
 */

/**
 * Called when the contact form submit button is pressed.  Only allows form 
 * submission if the contact form data is valid.  Note that this is only done 
 * for the sake of client-side usability, as the form data is also checked 
 * server side before processing. 
 */
function checkContactForm(e)
{
  var isValid = true;
  var errorMessage = "";
  
  // Contact form parameters.
  var cNameField    = document.getElementById("contact-name");
  var cEmailField   = document.getElementById("contact-email");
  var cSubjectField = document.getElementById("contact-subject");
  var cMessageField = document.getElementById("contact-message");
  
  if (!cNameField || !cEmailField || !cSubjectField || !cMessageField)
    return;
    
  var cName    = cNameField.value;
  var cEmail   = cEmailField.value;
  var cSubject = cSubjectField.value;
  var cMessage = cMessageField.value;
  
  if (trim(cName).length < 1) {
    isValid = false;
  }
  if (trim(cEmail).length < 1) {
    isValid = false;
  }
  if (trim(cSubject).length < 1) {
    isValid = false;
  }
  if (trim(cMessage).length < 1) {
    isValid = false;
  }
  
  if (!isValid) {
    alert("Please fill in all form fields properly before sending your message.");
    YAHOO.util.Event.stopEvent(e);
  }
}

// Contact form field client-side validation.
// Check for compatibility.
if (W3CDOM) {
  YAHOO.util.Event.addListener("contact-form", "submit", checkContactForm);
}
