//use to add any custom javascripts to this site

/////////////////////////////////////////////////////////////
// the following three functions are used as default functions
// for setting over and out mouseover states for top nav
/////////////////////////////////////////////////////////////
    function menuOver(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("On." + strFileType) == -1) {
            img.src = img.src.replace("." + strFileType, "Over." + strFileType)
        }
    }
    function menuOut(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("Over." + strFileType) != -1) {
            img.src = img.src.replace("Over." + strFileType, "." + strFileType)
        }
    }

    function getFileType(strFileName){
        strFileType = ""
        arrParts = strFileName.split(".")
        strFileType = arrParts[arrParts.length-1]
        return strFileType
       
    }

 //function: is alphanumeric
    function characterCheck(str) {
        var regex = /[a-zA-z]/;
        if (str.match(regex)) {
            return true;
        } else {
            return false;
        }
    }
// function: do search
    function doSearch(e, elemId, searchId) {
        var elem = document.getElementById(elemId);
        var evt = (e) ? e : window.event;
        var intKey = (evt.which) ? evt.which : evt.keyCode;
        var search = document.getElementById(searchId).value;

        search = search.replace("\????", "");
        search = search.replace("\???", "");
        search = search.replace("\??", "");
        search = search.replace("\?", "");
        

        //alert(search);
        //if ((search != "") && (alphaNumericCheck(search))) {
        if ((search != "") && (characterCheck(search))) {

            document.location.href = '/search.aspx?st=' + search;
        }
        else {
            alert("Please submit a valid search");
        }
        return false;
    }    
    
// function: add rollover for SmartWebs buttons (handles GIFs and PNGs)
function addSWBtnRollovers() {
    //alert("images # " + document.images.length);
    for (i = 0; i < document.images.length; i++) {
        //if button is a smartwebs button

        if (document.images[i].src.indexOf('swbtn_') > 0) {
            //if button is a png
            //alert("src: " + document.images[i].src);
            imgSrc = document.images[i].src
            //alert(imgSrc)
            arrParts = imgSrc.split(".")
            ext = arrParts[arrParts.length - 1]
            //alert(ext)
            if (ext == "gif") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'gif'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'gif'); };
            }
            if (ext == "png") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'png'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'png'); };
            }
            if (ext == "jpg") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'jpg'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'jpg'); };
            }
        }
        
        //while we're in here check uploadImages directories and make sure there are no staging urls floating around
       
            var theSource = document.images[i].src.toLowerCase()

            if (theSource.indexOf('uploadimages') > 0) {
                arrParts = theSource.split("/")
                theSource = theSource.replace(arrParts[0] + "//" + arrParts[2],"")
                document.images[i].src = theSource
            }
    }
}
// function: swap the rollover buttons
function swapSWButtons(img, ext) {
    thisSrc = img.src
    if (thisSrc.indexOf("Over") > 0) {
        thisSrc = thisSrc.replace("Over." + ext, "." + ext)
        img.src = thisSrc
    } else {
        thisSrc = thisSrc.replace("." + ext, "Over." + ext)
        img.src = thisSrc
    }
}
function init() {

    addSWBtnRollovers(); //add swbutton rollovers

    
}
window.onload = init;
/////////////////////////////////////////////////////////////
// END
/////////////////////////////////////////////////////////////

// function: force enter click
function forceClick(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {
        elem.click();
        return false;
    }
    return true;
}

function searchSite() {
    
    if (document.getElementById("siteSearchBox")){
        if (document.getElementById("siteSearchBox").value != ""){
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBox").value) + "&ustype=0"
        }
    }
}

//function checkLinksForDisclaimer() {
    //var blnToolTips = false;
    //if (document.links) {
        //for (i = 0; i < document.links.length; i++) {
        //    var el = document.links[i]
        //    var theClass = el.className
        //    if (theClass) {
       //         if (theClass.toLowerCase() == "sw_disclaimer") {
        //            var url = el.href

                    //document.links[i].href="#"
                    //el.href = "javascript:showDisclaimer('" + escape(url) + "');"
        //            el.title = "<h1>Header.</h1><br>Message.... "

       //             blnToolTips = true

      //          }
     //          if (theClass.toLowerCase() == "sw_disclaimerexternal") {
     //               var url = el.href
                    //alert(el.target)
                    //document.links[i].href="#"
                    //el.href = "javascript:showDisclaimer('" + escape(url) + "');"
     //               el.title = "<h1>Disclaimer header</h1><br> Disclaimer text here.... text here.... text here.... text here.... text here.... text here...."

    //                blnToolTips = true
    //            }
    //        }

    //    }
    //}
    //if (blnToolTips) {
$(document).ready(function () {

    // External Link warning dialog
    $("a.sw_disclaimerexternal").easyTooltip
    (
        { content: "<h1>Attention:</h1>By accessing this link you will be leaving our website and entering a different site which is hosted by another party. Please be advised that you will no longer be subject to, or under the protection of, the privacy and security policies of our website. We encourage you to read the privacy and security policies of the site which you are entering, as they may be different than ours.<br /><a href='' target='_blank' class='acceptLink'>Accept</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' class='declineLink'>Decline</a>" }
    );

    // Hide NCUA link within Investing & Planning section

    var urlString = window.location.href;
    //alert(urlString);

    if (urlString.indexOf('investing-and-planning') >= 0) {
        $('#ncuaLink').hide();
    }

});
    //}
//}
