// 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')
	 $('#navBar').rollovers();
	
	$('div.navMain ul li.parentMenu').DIMenus({columns:2});

	// Uncomment the following to make a search box automagically add and remove the default value of that field
	//    on focus and blur.
	// $('#searchField').searchField();

	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);
	}

	
	$('span.removeTags', $('.ratesWrap')).each(function () {
		var tag = $(this);
		if (tag.attr('className').match(/removeTags/gi)) {
			tag.html(tagRemove(tag.text()));
			tag.css('visibility', 'visible');
		}
	});

	$(".rateCol")
		.mouseover(function(){this.className="rateColHover";})
		.mouseout(function(){this.className="rateCol";});
		

	//easing equation, borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery/easing/
	$.easing.easeOutQuart = function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; };
	var $quickLinks = $('.quickLinks'); //the quickLinks container
	var $prev = $('#prev', $quickLinks); //prev button
	var $next = $('#next', $quickLinks); //next button
	$quickLinks.serialScroll({
		target:'#pane',
		items:'li',
		prev:'#prev',
		next:'#next',
		axis:'x',
		offset:-178, //when scrolling to photo, stop 178 before reaching it (from the left)
		start:1, //as we are centering it, start at the 2nd
		duration:2000,
		step: 4,
		force:true,
		stop:true,
		lock:false,
		cycle:true, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			$prev.add($next).show();
			if( pos == 0 )
				$prev.hide();
			else if( pos == $items.length-1 )
				$next.hide();
		}
	});

});

// 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 tagRemove(str)
{
	return str.replace(/\<(.*)\>/gi, " ")
		.replace(/\((.*)\)/gi, " ")
		.replace(/\&\#(\d*)\;/, " ");
}
function tagReplace(str)
{
	var result = (str == "") ? "&#160;" : str;
	return result.replace(/\(br\)/gi, "<br />")
					.replace(/\(sup\)/gi, "<sup>")
					.replace(/\(\/sup\)/gi, "</sup>")
					.replace(/\(large\)/gi, "<span class=\"ratesLarge\">")
					.replace(/\(\/large\)/gi, "</span>")
					.replace(/\(bold\)/gi, "<strong>")
					.replace(/\(\/bold\)/gi, "</strong>")
					.replace(/\(redtext\)/gi, "<span class=\"redtext\">")
					.replace(/\(\/redtext\)/gi, "</span>")
					.replace(/\(ital\)/gi, "<em>")
					.replace(/\(\/ital\)/gi, "</em>");
}

function sReplace(str)
{
	return tagReplace(str);
}

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=1,location=1,directories=1,status=1,menubar=1,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;
}

/************************************************************************************************************
* 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;
}*/

function displayThirdPartyAlert(msg,lk){
	
	findPos(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;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	} 
	while (obj = obj.offsetParent);
	}
	
		document.getElementById('ex_dis').style.marginTop = (curtop-300)+'px';
		window.scrollTo(0,curtop-300);
}

/************************************************************************************************************
* 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(7);
	// 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 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 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();
}

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

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


function changeTextSize(size){
	if(size == 'small'){
		document.getElementById('backcontent').style.fontSize = '7pt';
		anchors = document.getElementsByName('sNavAnchor');
		for(i=0; i<anchors.length; i++){
			anchors[i].style.fontSize = '7pt';
		}
		var cells = document.getElementsByTagName("td"); 
		for (var i = 0; i < cells.length; i++) { 
		    cells[i].style.fontSize='7pt'; 
		}
	}
	else if (size == 'medium'){
		document.getElementById('backcontent').style.fontSize = '9pt';
		anchors = document.getElementsByName('sNavAnchor');
		for(i=0; i<anchors.length; i++){
			anchors[i].style.fontSize = '9pt';
		}
		var cells = document.getElementsByTagName("td"); 
		for (var i = 0; i < cells.length; i++) { 
		    cells[i].style.fontSize='9pt'; 
		}
	}
	else if (size == 'large'){
		document.getElementById('backcontent').style.fontSize = '12pt';
		anchors = document.getElementsByName('sNavAnchor');
		for(i=0; i<anchors.length; i++){
			anchors[i].style.fontSize = '12pt';
		}
		var cells = document.getElementsByTagName("td"); 
		for (var i = 0; i < cells.length; i++) { 
		    cells[i].style.fontSize='12pt'; 
		}
	}
}

function showHide(element){
	if( document.getElementById(element).style.display == 'block' ){
		document.getElementById(element).style.display = 'none';
		document.getElementById(element).style.visibility = 'hidden';
	}	
	else{
		document.getElementById(element).style.display = 'block';
		document.getElementById(element).style.visibility = 'visible';
	}
}

function popUpTrustAcctDef()
{
	window.open(contextPath + '/fiFiles/static/documents/trust_account.html', 'trust_account', 'height=325,width=320,location=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no');
}
function popUpMinorAcctDef()
{
	window.open(contextPath + '/fiFiles/static/documents/minor_account.html', 'minor_account', 'height=175,width=320,location=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no');
}
function popUpPayOnDeathAcctDef()
{
	window.open(contextPath + '/fiFiles/static/documents/payondeath.html', 'payondeath_account', 'height=225,width=320,location=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no');
}
function popUpTransferMinorAcctDef()
{
	window.open(contextPath + '/fiFiles/static/documents/transfer_minor_account.html', 'transferminoracct_account', 'height=225,width=320,location=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no');
}

function billPayDemo()
{
	window.open('http://www.starone.org/bridge/GRP/checkfree_flash_demo/index.html','mvdemo1','scrollbars=no,menubar=no,status=no,width=800,height=590,left=0,top=0');
}


function showRates(box){
	
		$('#checkingbox').attr('class', 'hideRates');
		$('#checkingtab').attr('src', 'fiFiles/static/images/rnav_checking_off.gif');
		
		$('#savingsbox').attr('class', 'hideRates');
		$('#savingstab').attr('src', 'fiFiles/static/images/rnav_savings_off.gif');
		
		$('#autoloansbox').attr('class', 'hideRates');
		$('#autoloanstab').attr('src', 'fiFiles/static/images/rnav_autoloans_off.gif');
		
		$('#homeloansbox').attr('class', 'hideRates');
		$('#homeloanstab').attr('src', 'fiFiles/static/images/rnav_homeloans_off.gif');
		
		
		$('#creditcardsbox').attr('class', 'hideRates');
		$('#creditcardstab').attr('src', 'fiFiles/static/images/rnav_creditcards_off.gif');
		
		$('#'+box+'box').attr('class', 'showRates');
		$('#'+box+'tab').attr('src', 'fiFiles/static/images/rnav_'+box+'_on.gif');
}


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

function FindPosition(image_name){
    if(!document.images[image_name]){
        return null;
    }
    this.image_name = image_name;
    this.xPos = 500;
    this.yPos = 500;
    this.ref_image = document.images[image_name];
    this.getRealLeft = getRealLeft;
    this.getRealTop = getRealTop;
    this.getRealLeft();
    this.getRealTop();
}

function getRealLeft(move) {
   if(!move){
        move = 0;
    }
   if(document.layers){
     this.xPos = this.ref_image.x + move;    
     return this.xPos;
   }
	this.xPos = this.ref_image.offsetLeft;
	tempEl = this.ref_image.offsetParent;
  	while (tempEl != null) {
  		this.xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
    this.xPos = this.xPos + move;
	return this.xPos;
}

function getRealTop(move) {
    if(!move){
        move = 0;
    }
    if(document.layers){
     this.yPos = this.ref_image.y + move; 
     return this.yPos
   }
	this.yPos = this.ref_image.offsetTop;
	tempEl = this.ref_image.offsetParent;
	while (tempEl != null) {
  		this.yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
    this.yPos = this.yPos + move;
	return this.yPos;
}

function noLeadingZeros(input)
{
	if(input.value.charCodeAt(0)==48)
	{
		input.value= input.value.substr(1);
		alert('No Leading Zeros Allowed in Member Number');
	}
}

$(function () {
/*
	window.setTimeout(function () {
		var mainNav = $("div.navMain");
	
		var menu_timeout = null;
		var menu_thisItem = null;
		
		var current_menu = null;
	
		
		$("li.parentMenu").mouseover(function (e) {
			// This is the mouseover event
			
			window.clearTimeout(menu_timeout);
			if (current_menu) current_menu.hide();
	
			// .rollover img
			var name = $("img", this).attr("name").match(/([A-Za-z0-9]*)$/)[0];
			current_menu = $("#menu_"+name);
			current_menu.show();
		
		}).mouseout(function (e) {
			// This is the mouseout event
	
			menu_timeout = window.setTimeout(function() {
				if (current_menu) current_menu.hide();
			}, 100);
		
		}).each(function (i) {
			// .rollover img
			var item = $("img", this);
			var name = item.attr("name").match(/([A-Za-z0-9]*)$/)[0];
			
			var cur_yOffset = 31;
			
			var cur_xOffset = -3;
			if (name=='accounts') cur_xOffset = -102;
			if (name=='accountaccess') cur_xOffset = -184;
			if (name=='tools') cur_xOffset = -304;
			if (name=='join') cur_xOffset = -365;
			if (name=='locations') cur_xOffset = -180;
			if ($.browser.msie) {
				if (name=='applynow' || name=='locations') cur_yOffset = 4;
				else cur_yOffset = 29;
//				if (name=='tools') cur_xOffset+=3;
//				if (name=='join') cur_xOffset+=2;
				if (name=='applynow') cur_xOffset-=315;
				var pos = new FindPosition("img_"+name);
				$("#menu_"+name).css("top", pos.yPos+cur_yOffset).css("left", pos.xPos+cur_xOffset);
			}
			else {
				if (name=='applynow' || name=='locations') cur_yOffset = 4;
				var pos = item.offset();
				$("#menu_"+name).css("top", pos["top"]+cur_yOffset).css("left", pos["left"]+cur_xOffset);
			}
		});
		
		
		$("div.subMenu").mouseover(function(e) {
			// This is the mouseover event
	
			window.clearTimeout(menu_timeout);
	
		}).mouseout(function (e) {
			// This is the mouseout event
			
			menu_timeout = window.setTimeout(function() {
				if (current_menu) current_menu.hide();
			}, 100);
		
		});
		
		$("div.subMenu a").mouseout(function (e) {
			e.stopPropagation(); return false;
		}).click(function () {
			if (current_menu) current_menu.hide();
		});
		
	}, 500); */
	
	$(".rateCol")
		.mouseover(function(){this.className="rateColHover";})
		.mouseout(function(){this.className="rateCol";});
		
});