﻿// redirect external links thru speed bump
function speedBump() {
        
    // only if the page is not exit page
	if (String(window.location).toLowerCase().indexOf('speedBump.aspx')<0) {
        
        // 
        
        // string of valid hosts
		var validHosts=""+
		
			"172.22.15.252|"+
			"172.22.15.231|"+
			"172.22.15.232|"+
			"10.120.2.225|"+
			"172.22.15.220|"+
			"63.207.225.220|"+
			"172.22.120.5|"+
            "172.22.120.6|"+
			"tcbkstg1|"+
			"tcbk.com|"+
			"tcbkstg1.trico.tcbsh|"+
			"tricountiesbank.com|"+
			"online.tcbk.com|"+
			"ecash.tcbk.com|"+
			"tcalc.com|"+
			"billpaysite.com|"+
			"businessbillpay-e.com|"+
			"localhost|"+
			"dbankcontact@tcbk.com|"+
			"perfectchecking.com|"+
			"tricountiesbank.mortgagewebcenter.com|"+
			"util|"+
			"secure.andera.com|"+
			"gotcb.mobi|"+
			"testcredisphere"+	
		    ";";
		    
        // regex for valid host search
		var validHostsReg=new RegExp(validHosts, "i");
        // loop through links on page
		for(var x=0; x<=(document.links.length-1);x++){
		
            // default all links as external
			var offSiteURL=true;
			
            // if link hostname property is empty then the link is internal
			if ((document.links[x].hostname=="") || (document.links[x].href.toLowerCase().substr(0,11)=="javascript:"))
			{
			    offSiteURL=false;
			}		
			else
			{				    
			    // assign hostname from link
			    var linkHost=document.links[x].hostname.toLowerCase();
			    
			    // if the link hostname is in the list of valid hosts set link as internal
			    if (linkHost.search(validHostsReg)>=0) offSiteURL=false;
                
                // if the link is to an email address then set link as external
//			    if (document.links[x].href.toLowerCase().substr(0,7)=="mailto:")
//			    {
//			      offSiteURL=true;
//			    }
//                if (document.links[x].href.toLowerCase().indexOf("mailto:") != -1)
//			    {
//			      offSiteURL=true;
//			    }
		         // Added by Laurie 1/23/07 to allow for internal mailto 
			    if (linkHost.search(validHostsReg)>=0 && document.links[x].href.toLowerCase().substr(0,7)=="mailto:") offSiteURL=false;

                // if link is external
			    if (offSiteURL == true) {
			      	        
			        // store link for speed bump
			        var link = document.links[x].href;
			        
			        document.links[x].href = "";
			        
			        // redirect to speed bump
				    //document.links[x].href = location.hostname + "/speedBump.aspx?link=" + escape(link);
					document.links[x].href = "/speedBump.aspx?link=" + escape(link);
			    }
			}			
		}
	}
}

// execute speed bump when page loads in client
window.onload=speedBump;