// something to do with Yahoo partnership -- blair
if (document.cookie.indexOf("ref=yahoo") > 0 || document.referrer.indexOf("yahoo.com") > 0 || window.location.search.indexOf("force=yahoo") > 0) {
    $("#yahooPartner").show();
    document.cookie = "ref=yahoo; path=/";
}

function clearForm (id, value) {
   if ($(id).val() == value) {
        $(id).val('');
   };
}

function validateEmail(email) {

    $(".error").hide();

    var hasError = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

    if( (email == '') || (email == 'your email address')) {
        //alert('error!');
        $("#newsLetterBtn").after('<div class="error">You forgot to enter the email address.</span>');
        hasError = true;
    } else if(!emailReg.test(email)) {
        $("#newsLetterBtn").after('<div class="error">Please enter a valid email address</span>');
        hasError = true;
    }
    //alert(hasError);
    return false;
}

// jquery for newsletter form submit
$(document).ready(function(){
    $("#newsLetterBtn").click(function() { // clicking on the newsletter button
        // we should validate the email address
        var emailAdd = $("#newsletter_input").val();
        validateEmail(emailAdd);
        emailAdd = "email=" + emailAdd;
        //alert(emailAdd);
        //alert(emailAdd);
        $.ajax( {
            type: "POST",
            url: "/processNewsletter.php",
            //this is where the email is loaded
            data: emailAdd,
            success: function(msg) {
                if (msg != "There was an error processing your request.") {
                    $("#newsLetterDiv").replaceWith("<div class='emailSuccess'>" + msg + "</div>");
                } else {
                    $("#newsLetterBtn").after("<div class='error'>" + msg + "</div>");
                }
            }
        });
        //$("#newsLetterDiv").replaceWith("<div id='loadingGif'></div>");  // loading gif until something comes back

        return false;
    });
});
