function navOver(imgTag) {
    var theImage = imgTag;
    if (theImage.src.indexOf("_off.") != -1) {
        theImage.src = theImage.src.replace("_off.", "_on.");
    }
    else {
        theImage.src = theImage.src.replace("_on.", "_off.");
    }
}

function pageLoad() {
    $('.footerNewsletter .txt, .sidebarNewsletter .txt').each(function () {
        if ($(this).val() == "")
            $(this).prev('label').show();
    });
    $('.footerNewsletter .txt, .sidebarNewsletter .txt').focus(function () {
        $(this).prev('label').hide();
    });
    $('.footerNewsletter .txt, .sidebarNewsletter .txt').blur(function () {
        if ($(this).val() == "")
            $(this).prev('label').show();
    });
}

$(function () {
    //this is for the newsletter labels, for accessibility to pass
    pageLoad();
    //subnav
    $("ul.nav li").mouseover(function () {
        $("ul.nav li ul").hide();
        $(this).children("ul").show();
    });
    $("ul.nav li").mouseout(function () {
        $(this).children("ul").hide();
    });
    //subsub nav
    $("ul.nav2 li").mouseover(function () {
        $("ul.nav2 li ul").hide();
        $(this).children("ul").show();
    });
    $("ul.nav2 li").mouseout(function () {
        $(this).children("ul").hide();
    });
});

function newsletterSignup() {
    // Test fields
    var strRegex = "/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
    valid = true;

    if ($('#txtNLFirstName').val() == "") {
        $('#txtNLFirstName').parent(".inputC").addClass("inputCError");
        valid = false;
    }
    else {
        $('#txtNLFirstName').parent(".inputC").removeClass("inputCError");
        valid = true;
    }

    if ($('#txtNLEmail').val() == "") {
        valid = false;
        $('#txtNLEmail').parent(".inputC").addClass("inputCError");
    }
    else if (($('#txtNLEmail').val() == "") || !(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test($('#txtNLEmail').val()))) {
        valid = false;
        $('#txtNLEmail').parent(".inputC").addClass("inputCError");
    }
    else {
        $('#txtNLEmail').parent(".inputC").removeClass("inputCError");
        valid = true;
    }
    if (valid) {
        jQuery.post("/base/newsletterSignup/signup.aspx", {
            txtFirstName: $('#txtNLFirstName').val(),
            txtEmail: $('#txtNLEmail').val()
        },
        function (data) {
            if (data != "False") {
                $('#signupNewsletterError').html("<p>Thank you for signing up to the Terrex Seismic newsletter.</p>");
                $('#nlSignUpForm').hide();
            }
            else {
                $('#signupNewsletterError').html("<p><span class='errorTxt'>Sorry, an error has occurred. Please try again later.</span></p>");
            }
        });
    }
    else {
        $('#signupNewsletterError').html("<p><span class='errorTxt'>Please fill in the required fields highlighted below.</span></p>");
    }
}

function secondNewsletterSignup() {
    // Test fields
    var strRegex = "/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
    valid = true;

    if ($('#txtSideNLFirstName').val() == "") {
        $('#txtSideNLFirstName').parent(".inputC").addClass("inputCError");
        valid = false;
    }
    else {
        $('#txtSideNLFirstName').parent(".inputC").removeClass("inputCError");
        valid = true;
    }

    if ($('#txtSideNLEmail').val() == "") {
        valid = false;
        $('#txtSideNLEmail').parent(".inputC").addClass("inputCError");
    }
    else if (($('#txtSideNLEmail').val() == "") || !(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test($('#txtSideNLEmail').val()))) {
        valid = false;
        $('#txtSideNLEmail').parent(".inputC").addClass("inputCError");
    }
    else {
        $('#txtSideNLEmail').parent(".inputC").removeClass("inputCError");
        valid = true;
    }
    if (valid) {
        jQuery.post("/base/newsletterSignupSidebar/signup.aspx", {
            txtFirstName: $('#txtSideNLFirstName').val(),
            txtEmail: $('#txtSideNLEmail').val()
        },
        function (data) {
            if (data != "False") {
                $('#signupNewsletterErrorSide').html("<p>Thank you for signing up to the Terrex Seismic newsletter.</p>");
                $('#nlSignUpFormSide').hide();
            }
            else {
                $('#signupNewsletterErrorSide').html("<p><span class='errorTxt'>Sorry, an error has occurred. Please try again later.</span></p>");
            }
        });
    }
    else {
        $('#signupNewsletterErrorSide').html("<p><span class='errorTxt'>Please fill in the required fields highlighted below.</span></p>");
    }
}
