﻿
var util = {
    isIE6: null,

    warningLinkHref: null,

    init: function() {
        util.isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

        //conditional clear for search input
        $("#siteSearch input").click(function(e) {
            if (this.value == "Search") {
                this.value = "";
            }
        });

        //conditional clear for locator input
        $("#locatorHome input, #locationHours input").click(function(e) {
            if (this.value == "Enter ZIP Code") {
                this.value = "";
            }
        });

        //open new windows
        $('.newWin').click(function(e) {
            var url = $(this).attr('href');
            javascript: window.open(url, '_blank', 'width=670, height=590,scrollbars=yes');
            e.preventDefault();
        });

        // add css classes to last items in dynamically generated lists
        $('dd:last-child').addClass('last');
        // $('#leftNav li:last-child').addClass('last');

        // display warning message in thickbox
        $("a").click(function(e) {
            util.warningLinkHref = this.href;
            if ((util.warningLinkHref.indexOf("fsb") == -1) && (util.warningLinkHref.indexOf("FSB") == -1) && (util.warningLinkHref.indexOf("mailto") == -1) && this.className != "noWarning" && util.warningLinkHref != "#" && util.warningLinkHref.indexOf("javascript") == -1) {
                tb_show('', 'warning.aspx?height=330&width=483&modal=true');
                $(".applet").css("visibility", "hidden");
                e.preventDefault();
            }
        });

    }
}

$(document).ready(function() {
    util.init();

    // Add enter key handling for the google search box site wide.
    $("#searchField").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            doSearch();
            return false;
        }
        else {
            return true;
        }
    });

    // Add enter key handling for the zipcode search box site wide.
    $("#theZIP").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            doLocationSearch();
            return false;
        }
        else {
            return true;
        }
    });
    
    
    
});


function doLogin() {
    var theURL = $('#onlineBankSelect').val();
    if (theURL == "") {
        alert("Please first select an account type from the dropdown menu to the left. Then click Log In.");
    }
    else {
        window.location = theURL;
    }
}
function doSearch() {
    if ($('#searchField').val() == "Search" || $('#searchField').val() == ""){
        $('#searchField').val("");
        $('#searchField').focus();
        return;
    }
    else {
         window.location = "searchResults.aspx?q=" + $('#searchField').val().replace(" ","+");
    }
}
function doLocationSearch() {
    if ($('#theZIP').val() == "" || $('#theZIP').val() == "Enter ZIP Code" || $('#theZIP').val().length < 5 || $('#theZIP').val().length > 5) {
        alert("Please enter a valid 5-digit ZIP code.");
        $('#theZIP').val("");
        $('#theZIP').focus();
    } else {
        theValue = $('#theZIP').val();
        if (theValue.substring(0, 1) == '0') {
            theValue = theValue.substring(1);
        }
        if (theValue != parseInt(theValue)) {
            alert("Please enter a valid 5-digit ZIP code.");
            $('#theZIP').val("");
            $('#theZIP').focus();
        }
        else window.location = "http://locations.thefsb.com/index.aspx?addTxt=" + $('#theZIP').val() + "&searchtype=all";
    }
}