// stuff inside here will run when the DOM is ready
// onload replacement
$(function(){
	// Uncomment and Optimize the selector below for rollover images. 
	// Should select the ID of the element containing the nav w/ rollover images.
	// HINT: You can add more image containers by separating IDs with a space, just like in CSS: $('#navBar1 #navBar2')
	$('.pNav').rollovers();
	
	// Uncomment the following to make a search box automagically add and remove the default value of that field
	//    on focus and blur.
	// $('#searchField').searchField();

	//fix for IE6 security warning when doing a site search on a secure page
	/*temp=navigator.appVersion.split('MSIE');
	ieVer=parseInt(temp[1]);
	var isIE6=(ieVer == 6)?1:0;
	if(isIE6) {
		ie6Loc = $('.searchForm').attr('action');
		ie6Loc = ie6Loc.replace( /https/, 'http' );
		$('.searchForm').attr('action', ie6Loc);
	}*/
	
	// Back-to-top button generator ; use <attr name="noBackToTop" value="true" /> in navigation.xml to disable
	

	// This turns on the DIMenus plugin, modify the selector to suit your template needs
	if(cfg_menu_system=="dimenus") $('div.nav ul li.parentMenu').DIMenus({columns:2});
	
		
	$('a.quickInfo').click(
		function(){
		        if($.alertTimeout)clearTimeout($.alertTimeout);
		        $('#quick:hidden').animate({opacity:'show'},'slow');
		},
		function() {
			$.alertTimeout = setTimeout(function(){
			$('#quick:visible').animate({opacity:'hide'},'slow');
		},300);
	});
	
	$('#quick').hover(
		function(){
			if($.alertTimeout)clearTimeout($.alertTimeout);
			$('#quick:hidden').animate({opacity:'show'},'slow');
		},
		function() {
			$.alertTimeout = setTimeout(function(){
			$('#quick:visible').animate({opacity:'hide'},'slow');
		},300);
	});
	
	$('a.quickInfo2').click(
		function(){
		        if($.alertTimeout)clearTimeout($.alertTimeout);
		        $('#quick2:hidden').animate({opacity:'show'},'slow');
		},
		function() {
			$.alertTimeout = setTimeout(function(){
			$('#quick2:visible').animate({opacity:'hide'},'slow');
		},300);
	});
	
	$('#quick2').hover(
		function(){
			if($.alertTimeout)clearTimeout($.alertTimeout);
			$('#quick2:hidden').animate({opacity:'show'},'slow');
		},
		function() {
			$.alertTimeout = setTimeout(function(){
			$('#quick2:visible').animate({opacity:'hide'},'slow');
		},300);
	});
	
	
	/*if ($.cookie('loginState') == 'florida') {
		changeState('.personal', 'florida');
		changeState('.business', 'florida');
		$(".rememberMe input[type='checkbox']", $('.personal')).attr('checked', true);
		$(".rememberMe input[type='checkbox']", $('.business')).attr('checked', true);
		$(".loginOptions input[type='radio'][value='florida']", $('.personal')).attr('checked', true);
		$(".loginOptions input[type='radio'][value='florida']", $('.business')).attr('checked', true);
	} else {
		changeState('.personal', 'illinois');
		changeState('.business', 'illinois');
		$(".loginOptions input[type='radio'][value='illinois']", $('.personal')).attr('checked', true);
		$(".loginOptions input[type='radio'][value='illinois']", $('.business')).attr('checked', true);
	}*/
	
	
});



// pdf link detection and click event now handled here with .live()
// no need to place in the page onload
$("a[href$='.pdf']").live("click", function() {
	var $this = $(this);
	var linkOnclick = $this.attr('onclick');
	if (linkOnclick){
		linkOnclick = linkOnclick.toString();
		if (linkOnclick.indexOf("displayThirdPartyAlert")>-1)
		{
			return false;
		}
	}
	if (this.target=='_blank') this.target='';
	openPDF($this.attr('href'));
	return false;
});

// for Cool Menus
if(window.event + "" == "undefined") event = null;
function showMenu(){return false};
oM = {mout:function(){return false;}};

function target_blank(url){
    tmp = window.open(url);
    tmp = null;
}

function wcInternalPopup(url, height, width, opts){
	var wide = parseInt(width);
	var tall = parseInt(height);
    var halfwide = (wide/2);
    var halftall = (tall/2);
    var pWidth = (((parseInt(screen.width) / 2)) - halfwide);
    var pHeight = (((parseInt(screen.height) / 2)) - halftall);
    var features = opts || 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1';
	features += ',width='+wide+',height='+tall+',top='+pHeight+',left='+pWidth;
    window.open(url,'internalpopup',features);
}

function wcPopup(url, height, width, disclaimer){
	var disclaimer = parseInt(disclaimer);
	var wide = parseInt(width);
	var tall = parseInt(height);
	var halfwide = (wide/2);
	var halftall = (tall/2);
	var pWidth = (((parseInt(screen.width) / 2)) - halfwide);
	var pHeight = (((parseInt(screen.height) / 2)) - halftall);
	var features = 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width='+wide+',height='+tall+',top='+pHeight+',left='+pWidth;
	if (disclaimer)
		showWarning("javascript:void(window.open('"+url+"','externalpopup','"+features+"'))", url, false, disclaimer)
	else
		window.open(url,'externalpopup',features);
}

function openDisc(page){
	var pWidth = (((parseInt(screen.width) / 2)) - 300)
	var pHeight = (((parseInt(screen.height) / 2)) - 400)
	bWindow = window.open(page,'discwin',"scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,width=600,height=600,top=" + pHeight + ",left=" + pWidth);
	bWindow = null;
}

/*
 * Opens a PDF in a second window
 * Params:
 *  pdfname - either a full path to the pdf -or- the filename of the pdf in 'documents' folder of fiFiles
 *  isFullPath - DEPRECATED :: set this to true if you do not want the 'documents' folder path prepended to the pdf name
 *  fullscreen - set this to true if you want the new window to fill the user's screen instead of opening at 780 x 580
 * Usage:
 *  openPDF('filename.pdf')
 *  openPDF('//www.domain.com/pdfs/filename.pdf', true)
 *  etc...
 */
function openPDF(pdfname, fullscreen)
{
	pdfname = /^http/.test(pdfname) ? pdfname : RegExp(fiDir+'/documents/').test(pdfname) ? pdfname : fiDir+'/documents/'+pdfname;
	width = fullscreen ? screen.width : 780;
	height = fullscreen ? screen.height : 580;
	var domExp = new RegExp("^(http|https)\:\/\/(www\.)?(\w*\.)+(org|com|net|gov)"),
		domain = pdfname.match(domExp);
	if (domain && document.location.href.indexOf(domain[2]+domain[3]+domain[4]) == -1) {
		wcPopup(pdfname, height, width);
	} else {
		wcInternalPopup(pdfname, height, width);
	}
} // openPDF()


/************************************************************************************************************
* 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";
	if(cfg_tpw_new_window=="true")target = (target) ? target : "_blank";
	msg = (msg) ? msg : 0;
	lk = (lk.substring(0,1)=="/" && !(lk.substring(0,8)=="/mstinc/"))? contextPath + lk: lk; // for local pages

	var messages = new Array(6);
	// Standard 3rd Party Warning
	messages[0] = messages[1] = '<h2 style="text-align:center">Third Party Site Disclaimer</h2><p>This is a link to a third-party or affiliate site as described in our Security Statement. Note that the third party\'s or affiliate\'s privacy policy and security practices may differ from '+fiName+'. '+fiName+' assumes no responsibility nor does it control, endorse or guarantee any aspect of your use of the linked site.</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>This is a link to a third-party or affiliate site as described in our Security Statement. Note that the third party\'s or affiliate\'s privacy policy and security practices may differ from '+fiName+'. '+fiName+' assumes no responsibility nor does it control, endorse or guarantee any aspect of your use of the linked site.</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);
}

function showContact() {
	
	var messages = new Array(1);
	
	messages[0] = '<p align="center"> To apply or for more information, contact us at <a href="mailto:businessaccess@busey.com" onclick="return displayThirdPartyAlert(5, this);">businessaccess@busey.com</a> or 1-800-67BUSEY (1-800-672-8739) and select option 2.</p>';
	
	var content = new Array();
	var index=0;
	
	content[index++] = messages[0];
	content[index++] = '<div style="margin-top:1em;text-align:center"><a href="#" onclick="$(\'#ex_dis\').hide();return false;">Okay</a></div>';	
	
	$("#ex_dis").html(content.join("")).show();
	scrollTo(0,0);
}


function getUrl(){
	var url = document.location.href;
	var urlstart = url.indexOf("newUrl=") + 7;
	var urlToReturn = url.substring(urlstart);
	return urlToReturn;
}

function linkRates() {
	
	for (var i = 0; i < document.getElementById("dropdown").length; i++) {
		if(document.getElementById("dropdown").value == "Online Interest Rates") {
			location = "/home/personal/interest/online"
		}
		
		else if(document.getElementById("dropdown").value == "Champaign") {
			location = "/home/personal/interest/champaign"
		}
		
		else if(document.getElementById("dropdown").value == "Ford") {
			location = "/home/personal/interest/ford"
		}	
		
		else if(document.getElementById("dropdown").value == "Florida") {
			location = "/home/personal/interest/florida"
		}	
		
		else if(document.getElementById("dropdown").value == "Livingston") {
			location = "/home/personal/interest/livingston"
		}	
		
		else if(document.getElementById("dropdown").value == "Macon") {
			location = "/home/personal/interest/macon"
		}	
		
		else if(document.getElementById("dropdown").value == "McLean") {
			location = "/home/personal/interest/mclean"
		}	
		
		else if(document.getElementById("dropdown").value == "Shelby") {
			location = "/home/personal/interest/shelby"
		}					
				
		else if(document.getElementById("dropdown").value == "Peoria") {
			location = "/home/personal/interest/peoria"
		}					

		else if(document.getElementById("dropdown").value == "Tazewell") {
			location = "/home/personal/interest/tazewell"
		}					

	}	
}


function linkLenders() {
	
	for (var i = 0; i < document.getElementById("dropdown").length; i++) {
		if(document.getElementById("dropdown").value == "Champaign/Ford County") {
			location = "/home/mortgage/meet/champaign"
		}
		
		else if(document.getElementById("dropdown").value == "McLean County") {
			location = "/home/mortgage/meet/mclean"
		}	
		
		else if(document.getElementById("dropdown").value == "Peoria Tri-County") {
			location = "/home/mortgage/meet/peoria"
		}	
		
		else if(document.getElementById("dropdown").value == "Macon/Shelby County") {
			location = "/home/mortgage/meet/macon"
		}	
		
		else if(document.getElementById("dropdown").value == "Indianapolis") {
			location = "/home/mortgage/meet/indianapolis"
		}	
		
		else if(document.getElementById("dropdown").value == "Florida") {
			location = "/home/mortgage/meet/florida"
		}	
	}	
}

function linkLending() {
	
	for (var i = 0; i < document.getElementById("dropdown").length; i++) {
		if(document.getElementById("dropdown").value == "Florida") {
			location = "/home/business/lending/florida"
		}
		
		else if(document.getElementById("dropdown").value == "Illinois") {
			location = "/home/business/lending/illinois"
		}	
		
		else if(document.getElementById("dropdown").value == "Indiana") {
			location = "/home/business/lending/indiana"
		}	
	}	
}

function changeLogins(stuffToShow, callback) {
	$('.loginAreaWrap').add('.loginBBWrap').hide();
	$(stuffToShow.join(',')).show();
	if (callback) callback.call();
}

function changeState(state) {
	$.cookie('loginState', state);
	document.location.replace(document.location.href);
}

function setRememberCookie(value) {
	var state = $.cookie('loginState');
	if (value) {
		$.cookie('loginState', state, {expires: 1000});
		$.cookie('rememberState', 'true', {expires: 1000});
	} else {
		$.cookie('loginState', state);
		$.cookie('rememberState', '');
	}
}


// Array, String, and Date functions
// plus rollover and searchField jQuery plugins
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('w.V.1i=5(b){e c=w.1j({K:\'1k\',W:\'1l\'},b);8 2.L(5(){e a=2;a.D=c;w(\'1m,1n[1o="1p"]\',2).M(\'[m*="\'+a.D.K+\'."]\').L(5(){n=2;n.N=x X();n.O=x X();n.O.m=n.m;n.N.m=n.m.E(x 1q(a.D.K+"\\.([a-z]{3,4})$",\'i\'),a.D.W+".$1")}).1r(5(){2.m=2.N.m},5(){2.m=2.O.m})})};w.V.1s=5(){8 2.L(5(){e a=w(2);j(2.F&&2.F.h&&!2.o.h){a.1t(2.F);a.1u(\'F\')}j(2.o.h){2.P=2.o;a.1v(5(){j(2.o==2.P)2.o=\'\'}).1w(5(){j(!2.o.h)2.o=2.P})}})};l.Y=[\'1x\',\'1y\',\'1z\',\'1A\',\'1B\',\'1C\',\'1D\'];l.Z=[\'1E\',\'1F\',\'1G\',\'1H\',\'1I\',\'1J\',\'1K\'];l.10=[\'1L\',\'1M\',\'1N\',\'1O\',\'11\',\'1P\',\'1Q\',\'1R\',\'1S\',\'1T\',\'1U\',\'1V\'];l.12=[\'1W\',\'1X\',\'1Y\',\'1Z\',\'11\',\'20\',\'21\',\'22\',\'23\',\'24\',\'25\',\'26\'];(5(){5 9(a,b){j(!l.k[a]){l.k[a]=b}};9("13",5(){e y=2.Q();8(y%4==0&&y%27!=0)||y%2a==0});9("14",5(){8 2.G()==0||2.G()==6});9("2b",5(){8!2.14()});9("2c",5(){8[q,(2.13()?29:28),q,A,q,A,q,q,A,q,A,q][2.H()]});9("2d",5(a){8 a?l.Z[2.G()]:l.Y[2.G()]});9("2e",5(a){8 a?l.12[2.H()]:l.10[2.H()]});9("15",5(){e a=x l("1/1/"+2.Q());8 16.2f((2.17()-a.17())/2g)});9("2h",5(){8 16.2i(2.15()/7)});9("2j",5(a){2.18(0);2.19(a);8 2});9("2k",5(a){2.2l(2.Q()+a);8 2});9("2m",5(a){e b=2.I();2.18(2.H()+a);j(b>2.I())2.1a(-2.I());8 2});9("1a",5(a){2.19(2.I()+a);8 2});9("2n",5(a){2.2o(2.2p()+a);8 2});9("2q",5(a){2.2r(2.2s()+a);8 2});9("2t",5(a){2.2u(2.2v()+a);8 2})})();(5(){5 9(a,b){j(!R.k[a]){R.k[a]=b}};9("2w",5(a,b){b=b||B;u(e i=0;i<2.h;i++)a.C(b,2[i],i,2)});9("2x",5(a,b){b=b||B;u(e i=0;i<2.h;i++)j(!a.C(b,2[i],i,2))8 S;8 1b});9("2y",5(a,b){b=b||B;u(e i=0;i<2.h;i++)j(a.C(b,2[i],i,2))8 1b;8 S});9("2z",5(a,b){b=b||B;e r=[];u(e i=0;i<2.h;i++)r[r.h]=a.C(b,2[i],i,2);8 r});9("M",5(a,b){b=b||B;e r=[];u(e i=0;i<2.h;i++)j(a.C(b,2[i],i,2))r[r.h]=2[i];8 r});9("1c",5(a,b){u(e i=b||0;i<2.h;i++)j(2[i]===a)8 i;8-1});9("2A",5(){8 2.M(5(a,b,c){8 c.1c(a)>=b})})})();(5(){5 9(a,b){j(!1d.k[a]){1d.k[a]=b}}9("2B",5(){8 2.E(/(^\\s+|\\s+$)/g,"")});9("2C",5(){8 2.E(/[-2D]([a-z])/2E,5(z,b){8 b.2F()})});9("2G",5(a,b){e b=b||0;j(b<0||b>2.h)8 S;8 2.1e(b,b+a.h)==a});9("2H",5(a){8 2.1e(2.h-a.h)==a});9("2I",5(a,b){a=a||A;b=b===2J?"...":b;8 2.h>a?2.1f(0,a-b.h)+b:2});9("2K",5(){8 2.E(/<\\/?[^>]+>/2L,\'\')})})();T.k.J=5(a,b){2.k[a]=b;8 2};T.J(\'2M\',5(b){e d={},p=(2.k=x b());2.J(\'1g\',5 1g(a){j(!(a 2N d)){d[a]=0}e f,r,t=d[a],v=b.k;j(t){2O(t){v=v.2P.k;t-=1}f=v[a]}2Q{f=p[a];j(f==2[a]){f=v[a]}}d[a]+=1;r=f.1h(2,R.k.1f.1h(U,[1]));d[a]-=1;8 r});8 2});T.J(\'2R\',5(a){u(e i=1;i<U.h;i+=1){e b=U[i];2.k[b]=a.k[b]}8 2});',62,178,'||this|||function|||return|add|||||var|||length||if|prototype|Date|src|el|value||31||||for||jQuery|new|||30|window|call|opts|replace|title|getDay|getMonth|getDate|method|off|each|filter|overObj|outObj|defaultValue|getFullYear|Array|false|Function|arguments|fn|on|Image|dayNames|abbrDayNames|monthNames|May|abbrMonthNames|isLeapYear|isWeekend|getDayOfYear|Math|getTime|setMonth|setDate|addDays|true|indexOf|String|substring|slice|uber|apply|rollovers|extend|_off|_on|img|input|type|image|RegExp|hover|searchField|val|removeAttr|focus|blur|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sun|Mon|Tue|Wed|Thu|Fri|Sat|January|February|March|April|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Oct|Nov|Dec|100|||400|isWeekDay|getDaysInMonth|getDayName|getMonthName|floor|86400000|getWeekOfYear|ceil|setDayOfYear|addYears|setFullYear|addMonths|addHours|setHours|getHours|addMinutes|setMinutes|getMinutes|addSeconds|setSeconds|getSeconds|forEach|every|some|map|unique|trim|camelize|_|ig|toUpperCase|startsWith|endsWith|truncate|undefined|stripTags|gi|inherits|in|while|constructor|else|swiss'.split('|'),0,{}))

