/* Scott Borys | deezine.ca  */
/* scott@deezine.ca          */
/* March 2010                */

/* Contact Form */

$(document).ready( function() {
    $("input").attr("disabled",false);
    $("textarea").attr("disabled",false);    
});
function contact(mode) {
    // if using w/o www, need to change url
    if (!mode) {
        var mode = "send";    
    }
    var requestString = $("#contact").serialize()+"&mode="+mode;     
    var contactEmail = "natasha@canpressco.ca";
    $("#contactReplace").replaceWith("<div id='contactReplace'>sending...</div>");
    $("#errorMessage").empty();
    $.ajax({  
        type: "POST",  
        url: "deezine/functions.php",  
        data: requestString, 
        success: function(text) {
            if ( "true" == text ) {
                $("#contactReplace").html("Your email has been successfully delivered.  Thanks!");
                $("#contact input").attr("disabled", true).css({ 'border-color' : '#fff', 'background-color' : "#fff"});
                $("#contact textarea").attr("disabled", true).css({ 'border-color' : '#fff', 'background-color' : "#fff"});
                return true;                
            } else if ( "false" == text) {
                $("#contactReplace").replaceWith("<button id='contactReplace' onclick='javascript:contact(\""+mode+"\");'>Request Quote</button><div id='errorMessage' style='margin-left: 150px;'>Your email was not delivered.  Please fill in required (*) input boxes.</div>");     
                return false;
            } else {
                return false;
            }
        },
        error: function() {
            $("#contactReplace").html("Your email was not delivered.  Please email <a href='mailto:"+contactEmail+"'>"+contactEmail+"</a>.");          
            return false;
        }  
    });      
}
