//
// This script enables the inline contact form.
//

$(document).ready(function() {
    $('#contactForm').ajaxForm({
        'target':        '#alert',
        'beforeSubmit':  showRequest,
        'success':       showResponse
    });

    $('#copperlanding_contactform_form').ajaxForm({
        'target':        '#copperlanding_contactform_alert',
        'beforeSubmit':  CopperLanding_showRequest,
        'success':       CopperLanding_showResponse });
    $('#copperlanding_contactform_reset').click(function () {
      $('#copperlanding_contactform_reset').hide('fast');
      $('#copperlanding_contactform_message').hide('fast');
      $('#copperlanding_contactform_form').show('fast');
    });
});

function CopperLanding_showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
    $('#copperlanding_contactform_alert').text('Submitting....');
    $('#copperlanding_contactform_reset').hide();
    $('#copperlanding_contactform_message').show('fast');
    $('#copperlanding_contactform_form').hide('fast');
    return true;
}

function CopperLanding_showResponse(responseText, statusText)  {
    $('#copperlanding_contactform_reset').show('fast');
}

function showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
    return true;
}

function showResponse(responseText, statusText)  {  
} 

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};
