﻿
var options = {
    target: '#contactform',
    url: 'SendMail/sendMail.ashx',
    success: function(msg) {
        if (msg == "FormSetup")
            document.location.href = "SendMail/FormSetup.aspx";
        showMessage("<h2>Contact Form Submitted!</h2>", msg);
    },
    error: function(msg) {
        showMessage("<h2>Failed to contact server.  Please send a mesage directly", msg);
    }
};

function showMessage(title, msg) {
    $('#ajaxwaiting').remove();
    $('#contactform').html("<div id='message'></div>");
    $('#message').html(title).hide();
    $('#message').append(msg).fadeIn('slow');
}

$(document).ready(function() {
    $("#frmContact").validate({
        submitHandler: function(form) {
            CreateWaitingLayer($('#contactform'));
            $(form).ajaxSubmit(options);
        } /* for html tables
            ,
                errorPlacement: function(error, element) {
                error.prepend("<br />");
                error.insertAfter(element);
            } */
    });
});

/* creates a layer on top of the form when ajax is called */

function CreateWaitingLayer(el) {
    el.prepend('<div id="ajaxwaiting">&nbsp;</div>');
    var target = $('#ajaxwaiting');
    target.css("width", el.width()).css("height", el.height()).css("left", 0).css("top", 0).show().css('z-index', 1);
    target.prepend('<div style="height: 40%; width: 1px" /><img src="images/contactform/ajax-loader.gif" />');
}


