/* Removes extraneous array[0] from message scroller array */
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

function iWantTo_nav(){
	sel = document.getElementById('iwantto');
	trgt = sel.options[sel.selectedIndex].value;
	window.location = trgt;
}

/* for Payline page */
function showDemoWindow()
{
    newWindow = window.open("http://www.paylinefinancial.com/cc/PaylineRelayClient.aspx?clientDirectory=bvcu","Converter","scrollbars,height=220,width=380,left=300,top=200");
}


/* for Online Forms */
function cuanytimeOpen(){
	window.open('https://www1.cuanytime.com/onlinebanking/controller?command=loginScreen&cuNumber=021','win2');
	window.open('/message.htm','win3','scrollbars=0,resizable=0,width=300,height=250');
}

function popAgreement(){
 window.open('/RRSPagreement.htm','window2','scrollbars=1,resizable=1,width=500,height=300');
}

function twoWindows(x) {
	if(x=="loan"){
		window.open('https://www.bowvalleycu.com/secure/loanApp.php','window2');
		window.open('/legal_Security.htm','window3','width=440,height=400,scrollbars=yes');
				}
	else if(x=="gener"){
		window.open('https://www.bowvalleycu.com/secure/loanApp.php','window4');
		window.open('/secInq.html','window5','width=440,height=400,scrollbars=yes');
				}
			}


/* ############################# */

function init(){
/*
	document.getElementById('popup_1').FadeState = -2;
	document.getElementById('popup_2').FadeState = -2;
	document.getElementById('popup_3').FadeState = -2;
	document.getElementById('popup_4').FadeState = -2;
	
	document.getElementById('popup_1').style.display="none";
	document.getElementById('popup_2').style.display="none";
	document.getElementById('popup_3').style.display="none";
	document.getElementById('popup_4').style.display="none";
	*/
	if(window.setChart)
		setChart();
	
	//for( var x = 0; x < MWJScrollers.length; x++ ) { rotMsg( 0, 0, x ); }
}

function top_navigation_open(id){
	if(document.getElementById(id).style.display == "block")
		return;
	top_navigation_close();
	//if(id == 'popup_5' || id == 'popup_6' || id == 'popup_7')
		//return;
	if(document.getElementById(id) && document.getElementById(id).FadeState != 2){
		fast_nav_close();
		if(document.getElementById(id).style.display=="none"){
				document.getElementById(id).style.display="block";
		}
		fade(id);
	}
}

function top_navigation_close(){
	
	for(i=1;document.getElementById("popup_" + i);i++){
		this_popup = "popup_" + i;
		this_el = document.getElementById(this_popup);
		if(!this_el)
			return;
		else if(this_el && this_el.style.display == "block"){
			fade(this_popup, 2);
			sub_nav_on = 0;
		}
	}
}

function fast_nav_close(){
	
	for(i=1;document.getElementById("popup_" + i);i++){
		this_popup2 = "popup_" + i;
		if(!document.getElementById(this_popup2))
			return;
		else if(document.getElementById(this_popup2) && document.getElementById(this_popup2).style.display == "block"){
			document.getElementById(this_popup2).style.display="none";
			sub_nav_on = 0;
		}
	}
}


var TimeToFade = 500.0;

function fade(eid, act)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
    
   if(act)
   	element.FadeState = act;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}



function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    if(element.FadeState == -2)
    	element.style.display="none";
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
