//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 showOver(el){
            //get extension
            arrParts = el.src.split(".")
            ext = arrParts[arrParts.length-1]
            if (el.src.indexOf("On." + ext) == -1){
                el.src = el.src.replace("." + ext, "Over." + ext)
            }
        }
        function showOut(el){
            //get extension
            arrParts = el.src.split(".")
            ext = arrParts[arrParts.length-1]
            el.src = el.src.replace("Over." + ext, "." + ext)
        }

    function getFileType(strFileName){
        strFileType = ""
        arrParts = strFileName.split(".")
        strFileType = arrParts[arrParts.length-1]
        return strFileType
       
    }

// 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'); };
            }
        }
    }
}
// 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

    checkLinksForDisclaimer(); //check to see if any hyperlinks require a disclaimer
    
}
window.onload = init;

function searchSite() {
    
    if (document.getElementById("siteSearchBox")){
        if (document.getElementById("siteSearchBox").value != ""){
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBox").value) + "&ustype=0"
        }
    }
}
function searchSite404() {

    if (document.getElementById("siteSearchBoxF")) {
        if (document.getElementById("siteSearchBoxF").value != "") {
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBoxF").value) + "&ustype=0"
        }
    }
}





function locateFromHome() {
    var sAdd = document.getElementById("sAdd");

    if (sAdd.value == "" || sAdd.value == "Enter zip or city, state") {
        alert("Please enter a valid address");
        return false;
    }
    
    var latitude = 0;
    var longitude = 0;

        geocoder = new google.maps.Geocoder();

        var address = sAdd.value;
        var radius = 10;
        if (sAdd) {
            if (geocoder && sAdd.value != "") {

                geocoder.geocode({ 'address': address }, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {




                        latitude = results[0].geometry.location.lat();
                        longitude = results[0].geometry.location.lng();
                      
                        location.href = "/locator/default.aspx?lat=" + latitude + "&lng=" + longitude + "&sAdd=" + encodeURIComponent(sAdd.value) + "&rad=10&l0=true&l1=false&l2=false&l3=false&l4=false&l5=false";

                    } else {
                        alert("We could not find that address. Please try again\nGoogle Geocoding Error:" + status);
                    }
                });
            } else {
                alert("We could not find that address. Please try again\nGoogle Geocoding Error:" + status);
            }

       }

    




    
  
}

function forcelocateFromHomeClick(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {

        locateFromHome()
        return false;
    }

    return true;
}

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) {
      
        searchSite();
        return false;
    }

    return true;
}

function forceClickF(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {

        searchSite404();
        return false;
    }

    return true;
}


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>You are leaving the Rockland Trust Web Site.</h1><br>Rockland Trust does not control or warrant the content of any external web site. We advise you to explore the security and privacy information of any linked site. "

                    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>Content will be added from an external Web site.</h1><br> Rockland Trust does not control or guarantee the informational content being added from this external Web site and makes no warranty, express or implied, regarding its accuracy or content."

                    blnToolTips = true
                }
            }
            
        }
    }
    if (blnToolTips){
        $("a").easyTooltip();
    }
}

function setUpToolTips(){
//	$(document).ready(function(){	
//		$("a").easyTooltip();
//	});
}
function showDisclaimer(url) {
    if (confirm("You are about to leave the Rockland Trust website.\n Do you wish to continue?")) {
        window.open(url)
    }
}

function clearMe(val) {
    
    if (val.toString().toLowerCase() == "search") {
        if (document.getElementById("siteSearchBox")) {
            document.getElementById("siteSearchBox").value = "";
        }
    }
}
/////////////////////////////////////////////////////////////
// END
/////////////////////////////////////////////////////////////