//####### GLOBAL VARIABLES ########
var fiDomainName = "www.centralbankutah.com";
var fiName="Central Bank Utah";
//###################################

var uri = document.location.href;

var domain = { name:"centralbankutah", tld:"com" };
var domExp = new RegExp(domain.name+"\."+domain.tld);
var newUri = false;

function secureRedirect() {
	if(/skynet.diginsite.com/.test(uri)) {
		return;
	}
	if(!domExp.test(uri)){
		uri = uri.replace(/^(http|https)\:\/\/(www\.)?(\w*\.)+(org|com|net)/,'$1://$2'+domain.name+'.'+domain.tld);
		newUri = true;
	}
	if (newUri) document.location.replace(uri);



	var redir = false;
	if (window.secure)
	{	

	if(/^http:/.test(uri))
	{
		uri = uri.replace(/^http/,'https');
		redir = true;
	}

	if(!/^https:\/\/www\./.test(uri))
	{
		uri = uri.replace(/^https:\/\//,'https://www.');
		redir = true;
	}
	}

	else
	{
	if(/^https:/.test(uri))
	{
		uri = uri.replace(/^https/,'http');
		redir = true;
	}

	if(!/^http:\/\/www\./.test(uri))
	{
		uri = uri.replace(/^http:\/\//,'https://www.');
		redir = true;
	}
	};

	if (redir) document.location.replace(uri);
}

secureRedirect();


//Add rates to page & url

var appurl = "";
var count = 0;
var index = 0;
function show(rate,dynamic){
	switch(count){
		case 0:
		appurl +="&"+index+"term="+encode(rate);
		break;
		case 1:
		appurl +="&"+index+"rate="+encode(rate);
		break; 
		case 2:
		appurl +="&"+index+"apy="+encode(rate);
		index++;
		break;
	}
	if(rate != "_" && !dynamic){
		document.open('text/html','replace');
		document.write(rate);
		document.close();
		count == 2 ? count = 0 : count++;
	}
	else{
		count == 2 ? count = 0 : count++;
		return rate;
	}
	
	return;
}

function encode(string){
    var new_string = "";
    for(i=0;i<string.length;i++){
     if(string.charAt(i)==" "){        
         new_string += "_";    
     }
	 else if(string.charAt(i)=="%"){        
         new_string += "";    
     }
     else{
        new_string += string.charAt(i);
     }
    }  
    return new_string;
}

var fiName = "Central Bank";

/************************************************************************************************************
* This function is used in the onclick of the a tag to display the external site warning. 
* @param msg - Integer specifying the which message to display.
* @param lk - The a link object
* Usage: <a href="http://wwww.mysite.com" onclick="return displayThirdPartyAlert(1,this);">My Site</a>
**************************************************************************************************************/
function displayThirdPartyAlert(msg,lk){
	var description = lk.innerHTML;
	if(description.indexOf('alt="') != -1){
		var x = description.indexOf('alt="')+5;
		var temp = description.substring(x);
		description = temp.substring(0,temp.indexOf("\""));
	}
	showWarning(lk.href, description, lk.target, msg)
	return false;
}

/************************************************************************************************************
* This function is used in the href of the a tag to display the external site warning. 
* @param lk - The url of the site to be opened
* @param desc - The description of the site to be opened, i.e. the name of the site.
* @param target - Allows for the window to opened in a new window
* @param msg - Integer specifying the which message to display.
* Usage: <a href="javascript:showWarning('http://wwww.mysite.com');">My Site</a>
**************************************************************************************************************/

function showWarning(lk, desc, target, msg){
	desc = (desc) ? desc : "Third Party Site";
	target = (target) ? target : "_blank";
	msg = (msg) ? msg : 0;
	
	var messages = new Array(6);
	// Standard 3rd Party Warning
	messages[0] = messages[1] = '<h2 style="text-align:center">Third Party Site Disclaimer</h2><p>By accessing the noted link you will be leaving '+fiName+'\'s website and entering a website hosted by another party. '+fiName+' has not approved this as a reliable partner site. Please be advised that you will no longer be subject to, or under the protection of, the privacy and security policies of '+fiName+'\'s website. We encourage you to read and evaluate the privacy and security policies of the site you are entering, which may be different than those of '+fiName+'.</p>';
	// Standard Partner Warning
	messages[2] = '<h2 style="text-align:center">Partner Site Disclaimer</h2><p>By accessing the noted link you will be leaving our website and entering a partner 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 and evaluate the privacy and security policies of the site which you are entering, which may be different than those of ours.</p>';
	// Standard Affiliate Warning
	messages[3] = '<h2 style="text-align:center">Affiliate Site Disclaimer</h2><p>By accessing the noted link you will be leaving our website and entering an affiliate site located 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 and evaluate the privacy and security policies of the site which you are entering, which may be different than those of ours.</p>';
	// Customize if requested
	messages[4] = messages[0];
	// Standard mailto: Insecure Warning
	messages[5] = '<h2 style="text-align:center">Email Disclaimer</h2><p>This is <strong>NOT</strong> a secured e-mail transmission. Please <strong>do not send personal/financial information</strong> via this method.</p>';

	var content = new Array();
	var index = 0;
	content[index++] = messages[msg];
	content[index++] = '<div style="margin-top:1em;text-align:center"><a href="'+lk+'"'+(target?' target="'+target+'"':'')+' onclick="$(\'#ex_dis\').hide()">Continue</a>&#160;&#160;<a href="#" onclick="$(\'#ex_dis\').hide();return false;">Decline</a></div>';	
	$("#ex_dis").html(content.join("")).show();
	scrollTo(0,0);
}

document.write('<!-- The hidden div for 3rd party popups --><div id="ex_dis" style="display:none">blank</div>');
