function sendMail(form) {
  if(typeof(window.tinyMCE) !== 'undefined') {
    tinyMCE.triggerSave(true,true);
  }
  var invalid = false;
  $$('#' + form.id + ' .validate').each(function(s) { if($F(s) == '') invalid = true; });
  if(!invalid) {
    new Ajax.Request('/includes/mail_process.php', {
    method: 'post',
    parameters: $(form).serialize(),
    onLoading: function() {
      $('notice').update('<img src="/images/ajax-loader.gif" />');
    },
    onSuccess: function(transport) {
      $('notice').update('<span class="notice">' + transport.responseText + 'Thank you for your email</span>');
      form.reset();
    }});
  } else {
    $('notice').update('<span class="notice">Please fill out all required fields</span>');
  }
}

function sendComment(form, noticenum, ajax) {
  var invalid = false;
  var noticenum = noticenum || '';
  var ajax = ajax || false;
  $$('#' + form.id + ' .validate').each(function(s) { if($F(s) == '') invalid = true; });
  if(!invalid) {
    new Ajax.Request('/includes/mail_process.php', {
      method: 'post',
      parameters: $(form).serialize(),
      onLoading: function() {
        $('notice'+noticenum).update('<img src="/images/ajax-loader.gif" />');
      },
      onSuccess: function(transport) {
        if(ajax) {
          $('comment-end'+noticenum).update(transport.responseText);
          $('commentnum'+noticenum).update(parseInt($('commentnum'+noticenum).innerHTML) + 1);
          $('notice'+noticenum).update('');
        } else {
          $('notice').update('');
          $$('#comments .remove-me').invoke('hide');
          $('comments').update($('comments').innerHTML + transport.responseText);
        }
        form.reset();
      },
      onFailure: function(transport) {
        alert("Failed: "+transport.responseText);
      }
    });
  } else {
    $('notice'+noticenum).update('<span class="notice">Please fill out the comment section</span>');
  }
}

function deleteComment(num) {
  if(confirm("Are you sure you want to delete this commment?")) {
    new Ajax.Request('/includes/mail_process.php', {
      method: 'post',
      parameters: 'id='+num+'&type=deleteComment',
      onSuccess: function(transport) { 
        $('comment'+num).fade();
      }
    });
  }
}

function validateCC(form) {
  var invalid = false;
  $$('#' + form.id + ' .validate').each(function(s) { if($F(s) == '') invalid = true; });
  if(!invalid) {
    return true;
  } else {
    $('notice').update('<span class="notice">Please fill out all required fields</span>');
    return false;
  }
}

function validate(form) {
  var invalid = false;
  $$('#' + form.id + ' .validate').each(function(s) { if(s.getValue() == '') invalid = true; });
  if(!invalid) {
    return true;
  } else {
    $('notice').update('<span class="notice">Please fill out all required fields</span>');
    return false;
  }
}
