﻿

var holdstr = '';
var timeout

$(document).ready(function() {
    holdstr = $("#contact p").html();
    $("#email").blur();    //why is this here?  because IE doesn't follow the rules.  Bad IE
    $("#email").focus(function() {
        if ($("#email").val().length == 0 || $("#email").val() == "Your Email Address") {
            $("#email").attr("value", "");
        }

    });

    $("#email").blur(function() {
        if ($("#email").val().length == 0) {
            $("#email").val("Your Email Address");
        }
    });

    $(".submitButton").live("click", function(e) {
        if (e.button != 0) {
            // wasn't the left button - ignore
        } else {

            var sform = $("#theform").serialize();

            jQuery.post("scripts/echo/ui.aspx", sform, formOK);

        }
        return false;
    });

});

function formOK(r) {

    var ra = r.split("||");
    if (ra[0] == "OK") {
        $("#contact p").html(ra[1]);
        $("#email").val('');
        timeout = setTimeout('resetPage()', 4200);
        
    } else {
        $("#contact p").html(ra[1]);
        $("#email").focus();
        if (ra[0] == 'BYE') {
            timeout = setTimeout('byebye()', 2400);
        } else {
            timeout = setTimeout('resetPage()', 3600);
        }
    }
    return true;
}

function resetPage() {
    clearTimeout(timeout);
    $("#contact p").fadeTo(1200,0,swap);
}
function swap() {
    $("#contact p").html(holdstr);
    $("#contact p").fadeTo("slow", 1);
}
function byebye() { document.location = "http://en.wikipedia.org/wiki/E-mail_address" }