// Shawn Hill
// early 2003

mOpenDelay=50
mCloseDelay=200
//menuTopOffset=21
//menuLeftOffset=-3
function goAway(){
	return confirm('You are about to leave the Alliance Bank web site. \n Alliance Bank does not control the content of the site you are about to view. \n Click "OK" to continue.')
}
function demoOnlineBanking(){
	with(document.forms.loginForm){
		UserName1.value='allbk4'
		UserPassword1.value='ibanking'
		clearit()
		submit()
	}		
}
// Each menu will have an id, classname, triggerLinkID, then an array of text, link
menus =[
	["productMenu","mLayer","ctrlProductMenu",
		[
			["Personal Accounts","paccounts.html"],
			["Business Accounts","baccounts.html"],
			["Personal Loans","ploans.html"],
			["Business Loans","bloans.html"]						
		]	
	],
	["bankingMenu","mLayer","ctrlBankingMenu",
		[
			["Login","http://alliancebankkansas.com/login.html"],
			["Demo","http://alliancebankkansas.com/login.html"],
			["Sign Up","https://server112.cey-ebanking.com/CLKPCB/101114798/form-enrollment.asp"],
			["Help","help.html"]						
		]
	]
]

capEnv=document.getElementById&&document.createElement&&document.createTextNode
mTicking=initd=false
var openMenu,openSub,mTimeId
m=[]

function oW(dest){
	nWin = window.open(dest,'aWin')
	nWin.focus()
}
function menuInit(){
  if(capEnv){
  	if(document.getElementById(menus[0][0])==null){
		for(v=0; v<menus.length; v++)addMenu(menus[v])
		if(menus.length>0)openMenu=menus[0][0]
		initd=true
	}
 }
}
function addMenu(fM){
	mN=fM[0]
	m[mN]=document.createElement("div")
	m[mN].id=mN
	m[mN].className=fM[1]
	mKids=fM[3]
	for(k=0;k<mKids.length;k++){
		gL=document.createElement("a")
		gL.href=mKids[k][1]
		gL.appendChild(document.createTextNode(mKids[k][0]))
		// bottom link doesn't get border-bottom
		if(k==(mKids.length-1))gL.style.borderBottom='none'
		m[mN].appendChild(gL)
	}			
	m[mN].onmouseover=stopMTimer
	m[mN].onmouseout=closeMenu
	m[mN].style.display="none"
	// get the link that triggers this menu
	trg = document.getElementById(fM[2])
	if(trg){
		trg.onmouseover = materialize
		trg.onmouseout = closeMenu
		trg.menu = mN
		m[mN].trig = trg
		mov(m[mN])
		document.body.insertBefore(m[mN],document.body.firstChild)
	}
}
function materialize(){
	if(capEnv&&initd){
		stopMTimer()
		startMTimer("showMenu('"+this.menu+"')",mOpenDelay)
	}
}
function closeMenu(){
	stopMTimer()
	startMTimer('cM()',mCloseDelay)
}
function cM(){
	vis(openMenu,false)
}
function showMenu(fm){
	vis(openMenu,false)
	openMenu=fm
	vis(fm,true)
}
function startMTimer(fn,dur){
	mTicking=true
	mTimeId=setTimeout(fn,dur)
}
function stopMTimer(){
	if(mTicking){
		mTicking=false
		clearTimeout(mTimeId)
	}
}
function vis(fm,okay){
	m[fm].style.display=(okay?'block':'none')
}
function mov(fm){
	fm.style.left=findPosX(fm.trig)
	fm.style.top=findPosY(fm.trig)
}
function resetPos(){
	for(v=0; v<menus.length; v++){
		mov(m[menus[v][0]])
	}
}
/*
 Thanks to Peter Paul Koch, a scripting revolutionary
 for the following 2 functions.
 Original code can be found at http://www.xs4all.nl/~ppk/js/
*/ 
function findPosX(obj){
	var curleft=0
	while(obj.offsetParent){
		curleft+=obj.offsetLeft
		obj=obj.offsetParent
	}
	return curleft
}
function findPosY(obj){
	var curtop=0
	while(obj.offsetParent){
		curtop+=obj.offsetTop
		obj=obj.offsetParent
	}
	return curtop
}
window.onload=menuInit
window.onresize = resetPos
window.onunload = cM