function checkNoFrame() { if (top.window.location.href != window.location.href) window.close(); }
function checkPsisWin() { if (window.top.name != "PSISWIN2") window.location.href = "exit.asp"; }

function getApplicationName()
{
	var strAppName = "InternetBanking";
	var strPath = window.location.pathname;
	var objRegExp = new RegExp("([a-z0-9\.]{1,})","ig");
	var strResult = objRegExp.exec(strPath);
	if (strResult != null && (strAppName.toLowerCase() != RegExp.$1.toLowerCase()))
		strAppName = RegExp.$1;
	return strAppName;
}

function setMsg(id, type, val, elt)
{
	var p = '<p class="' + ((type == 0) ? 'error' : (type == 1) ? 'success' : (type == 2) ? 'info' : 'warn') + '">' + val + '</p>';
	var e = document.getElementById(id);
	if (e)
	{
		e.innerHTML = '';
		e.innerHTML = p;
	}
	if (elt)
	{
		if (elt.select) elt.select();
		if (elt.focus) elt.focus();
	}
}

setMsg.Error = 0;
setMsg.Success = 1;
setMsg.Info = 2;
setMsg.Alert = 3;

function clearMsg(id)
{
	var e = document.getElementById(id);
	if (e) e.innerHTML = '';
}

function tblEvents( tblId)
{
	var oRows = document.getElementById(tblId).getElementsByTagName("tr");
	var i = oRows.length;
	while (--i)
	{
		var oRow = oRows[i];
		oRow.onmousedown = function(){if (this.getAttribute("id")) tblRow(tblId, this.getAttribute("id").substring( tblId.length));}
		var tds = oRow.getElementsByTagName('td');
		var j = tds.length;
		while (j--)
		{
			var c = tds[j];
			c.className += (c.className.length > 0 ? " " : "") + "tblDef";
		}
	}
}

function tblRow(tblId, value)
{
	var tblDef = "tblDef";
	var tblSel = "tblSel";
	var reDef = new RegExp(tblDef);
	var reSel = new RegExp(tblSel);
	var oRows = document.getElementById(tblId).getElementsByTagName("tr");
	var i = oRows.length;
	while (--i)
	{
		var oRow = oRows[i];
		var sel = (value == oRow.getAttribute("id").substring( tblId.length));
		var tds = oRow.getElementsByTagName('td');
		var j = tds.length;
		while (j--)
		{
			var c = tds[j];
			if (sel)
				c.className = c.className.replace( reDef, tblSel);
			else
				c.className = c.className.replace( reSel, tblDef);
		}
	}
	tblOnSelect(tblId, value);
}

function tblGetValue(tblId)
{
	var retVal = "";
	var reSel = /tblSel/;
	var oRows = document.getElementById(tblId).getElementsByTagName("tr");
	var i = oRows.length;
	while (--i && !retVal)
	{
		var oRow = oRows[i];
		if (reSel.test( oRow.getElementsByTagName('td')[0].className))
			retVal = oRow.getAttribute("id").substring( tblId.length);
	}
	return retVal;
}

function tblGetValueAP(tblId)
{
	var retVal = "";
	var reSel = /tblSel/;
	var oRows = document.getElementById(tblId).getElementsByTagName("tr");
	var i = oRows.length;
	while ((--i && i>=2) && !retVal)
	{
		var oRow = oRows[i];
		if (reSel.test( oRow.getElementsByTagName('td')[0].className))
			retVal = oRow.getAttribute("id").substring( tblId.length);
	}
	return retVal;
}

function tblOnSelect( tblId, value){/* empty function, override on page */}

function showHide()
{
	var link = document.getElementById("toggleInfo").getElementsByTagName("a")[0];
	var tipHelp = document.getElementById("tipHelp");
	var content = document.getElementById("content");
	if (/showHide=hide/.test( document.cookie))
	{
		link.className = "hidden";
		link.innerHTML = "show";
		tipHelp.className = "hideInfo";
		content.className = "hide";
	}
	else
	{
		link.className = "";
		link.innerHTML = "hide";
		tipHelp.className = "";
		content.className = "";
	}
}

function toggleShowHide()
{
	document.cookie = "showHide=" + (/showHide=hide;/.test( document.cookie) ? "show" : "hide") + ";path=/" + getApplicationName() + ";";
	showHide();
}

function toggle( section)
{
	document.getElementById("compExpNote").className = (section == "note") ? "expand" : "compress";
	document.getElementById("compExpHelp").className = (section == "hlp") ? "expand" : "compress";
	document.getElementById("compExpTip").className = (section == "tip") ? "expand" : "compress";
	var re = new RegExp( section);
	var elts = document.getElementById("tipHelp").getElementsByTagName("p");
	var i = elts.length;
	while (i--)
	{
		var e = elts[i];
		e.style.display = re.test( e.className) ? "block" : "none";
	}
}

function actionEnableAll( fEnable)
{
	var elts = document.getElementById("action").getElementsByTagName("a");
	var i = elts.length;
	while (i--)
		elts[i].className = fEnable ? "" : "disable";
}

function actionEnable( id, fEnable)
{
	var e = document.getElementById( id);
	if (e) e.className = fEnable ? "" : "disable";
}
function actionIsEnabled( id)
{
	var retVal = false;
	var e = document.getElementById( id);
	if (e) retVal = (e.className.length == 0);
	return retVal;
}

function btnEnable( id, fEnable)
{
	var e = document.getElementById(id);
	if (e) e.className = fEnable ? "" : "disable";
}

function frmEnableSubmit( id, fEnable)
{
	var e = document.getElementById(id);
	if (e) e.className = fEnable ? "" : "disable";
}

function frmIsSubmitEnabled( id)
{
	var retVal = false;
	var e = document.getElementById(id);
	if (e) retVal = (e.className.length == 0);
	return retVal;
}

function OpenWindow(url)
{
	var DisplaySettings = "fullscreen=0,toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes";
	var page = (url != null) ? url : "https://" + window.location.hostname  + "/" + getApplicationName() + "/t/blank.html";
	var w = window.open( page, "PSISWIN2", DisplaySettings);
	if (bMac) w.name = "PSISWIN2";
}

function onClickRegister()
{
	if (!bUnsupported)
	{
		window.status = "Opening secure window...";
		var url = "https://" + window.location.hostname + "/" + getApplicationName() + "/t/reg.asp";
		OpenWindow( url);
		window.status = "";
	}
}

function onClickCancel()
{
	if (!bUnsupported)
	{
		window.status = "Opening secure window...";
		var url = "https://" + window.location.hostname + "/" + getApplicationName() + "/t/canlogin.asp";
		OpenWindow( url);
		window.status = "";
	}
}

function onClickAccess()
{
	if (!bUnsupported)
	{
		window.status = "Opening secure window...";
		var url = "https://" + window.location.hostname + "/" + getApplicationName() + "/t/login.asp";
		OpenWindow( url);
		window.status = "";
	}
}

function expand(bExpand, eTitle, eText)
{
	if (!bNN4)
	{
		for (var i=1; eval('document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtext" + ' + i + ') != null'); i++)
		{
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtext" + ' + i + ').className = ' + ((bExpand) ? '"ddexpand";' : '"ddcompress";'));
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtitle" + ' + i + ').className = ' + ((bExpand) ? '"ddpntdwn";' : '"ddpntrht";'));
		}
		if ( eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("expand")'))
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("expand").innerHTML = ' + ((bExpand) ? '"<a href=\'#\' onClick=\'expand(false)\' class=\'ddpntdwn\'>Compress all topics</a>";' : '"<a href=\'#\' onClick=\'expand(true)\' class=\'ddpntrht\'>Expand all topics</a>";'));
		if ( eTitle && eText)
			dropDown( eTitle, eText);
	}
}


function dropDown(link)
{
	if(!document.layers)
	{
		if(eval('document.getElementById(\'' + link + 'txt\')') != null)
		{
			var hdimg = eval('document.getElementById(\'' + link + '\')');
			var ddtext = eval('document.getElementById(\'' + link + 'txt\')');
			if(ddtext.className == "ddtext")
			{
				hdimg.style.backgroundImage = "url('../i/dwnarrow.gif')";
				ddtext.className = "ddexpand";
			}
			else
			{
				hdimg.style.backgroundImage = "url('../i/rhtarrow.gif')";
				ddtext.className = "ddtext";
			}
			return false;
		}
	}
}



function expComp(expand)
{
	var re = /^(\w*)txt$/;
	var aDdElmnts = document.getElementsByTagName("dd");
	var oldClass = (expand) ? "ddtext" : "ddexpand";
	var newClass = (expand) ? "ddexpand" : "ddtext";
	var img = "url(../i/" + (expand ? "dwn" : "rht") + "arrow.gif)";
	for( var i = 0; i < aDdElmnts.length; i++)
	{
		var elmt = aDdElmnts[i];
		if( elmt.className == oldClass)
		{
			elmt.className = newClass;
			document.getElementById( re.exec( elmt.id)[1] ).style.backgroundImage = img;
		}
	}
	document.getElementById("expand").innerHTML = "<a href=\"#expand\" onclick=\"return expComp(" + (expand ? "false" : "true") + ");\"><span id=\"compExp\">&nbsp;</span>" + (expand ? "Compress" : "Expand") + " all topics</a>";
	document.getElementById("compExp").style.backgroundImage = img;
}


/**
The following 3 functions are temporary measures to ensure that the red rht/dwn arrows are not replaced by the new green square versions from the reskin 
these can be removed when the transactional pages are being developed.  hlp.asp secinfo.asp and tnc.asp and t_base.css need to be updated to reflect these changes as well  
*/

function expandt(bExpand, eTitle, eText)
{
	if (!bNN4)
	{
		for (var i=1; eval('document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtextt" + ' + i + ') != null'); i++)
		{
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtextt" + ' + i + ').className = ' + ((bExpand) ? '"ddexpandt";' : '"ddcompresst";'));
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("ddtitlet" + ' + i + ').className = ' + ((bExpand) ? '"ddpntdwnt";' : '"ddpntrhtt";'));
		}
		if ( eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("expandt")'))
			eval( 'document.' + ((strBrowser == "IE") ? 'all' : 'getElementById') + '("expandt").innerHTML = ' + ((bExpand) ? '"<a href=\'#\' onClick=\'expandt(false)\' class=\'ddpntdwnt\'>Compress all topics</a>";' : '"<a href=\'#\' onClick=\'expandt(true)\' class=\'ddpntrhtt\'>Expand all topics</a>";'));
		if ( eTitle && eText)
			dropDownt( eTitle, eText);
	}
}


function dropDownt(link)
{
	if(!document.layers)
	{
		if(eval('document.getElementById(\'' + link + 'txtt\')') != null)
		{
			var hdimg = eval('document.getElementById(\'' + link + '\')');
			var ddtextt = eval('document.getElementById(\'' + link + 'txtt\')');
			if(ddtextt.className == "ddtextt")
			{
				hdimg.style.backgroundImage = "url('../i/dwnarrowt.gif')";
				ddtextt.className = "ddexpandt";
			}
			else
			{
				hdimg.style.backgroundImage = "url('../i/rhtarrowt.gif')";
				ddtextt.className = "ddtextt";
			}
			return false;
		}
	}
}



function expCompt(expandt)
{
	var re = /^(\w*)txtt$/;
	var aDdElmnts = document.getElementsByTagName("dd");
	var oldClass = (expandt) ? "ddtextt" : "ddexpandt";
	var newClass = (expandt) ? "ddexpandt" : "ddtextt";
	var img = "url(../i/" + (expandt ? "dwn" : "rht") + "arrowt.gif)";
	for( var i = 0; i < aDdElmnts.length; i++)
	{
		var elmt = aDdElmnts[i];
		if( elmt.className == oldClass)
		{
			elmt.className = newClass;
			document.getElementById( re.exec( elmt.id)[1] ).style.backgroundImage = img;
		}
	}
	document.getElementById("expandt").innerHTML = "<a href=\"#expandt\" onclick=\"return expCompt(" + (expandt ? "false" : "true") + ");\"><span id=\"compExpt\">&nbsp;</span>" + (expandt ? "Compress" : "Expand") + " all topics</a>";
	document.getElementById("compExpt").style.backgroundImage = img;
}



function dropDownWhatsNew(link)
{//debugger;
	if(!document.layers)
	{
		if(eval('document.getElementById(\'' + link + 'txt\')') != null)
		{
			var hdimg = eval('document.getElementById(\'' + link + '\')');
			var ddtext = eval('document.getElementById(\'' + link + 'txt\')');
			if(ddtext.className == "ddtext")
			{	    			    
				hdimg.style.backgroundImage = "url('../i/dwnarrow.gif')";
				ddtext.className = "ddexpand";
				
				var parent = eval('document.getElementById(\'' + link + 'dt\')');
				var divArray = parent.getElementsByTagName("div");
                for (var i = 0; i<divArray.length; i++)
                {
                    if (divArray[i].className=="test1")
                        divArray[i].className = "test1block"; 
                }
			}
			else
			{
				hdimg.style.backgroundImage = "url(../i/rhtarrow.gif)";
				ddtext.className = "ddtext";
				var parent = eval('document.getElementById(\'' + link + 'dt\')');
				var divArray = parent.getElementsByTagName("div");
                for (var i = 0; i<divArray.length; i++)
                {
                    if (divArray[i].className=="test1block" )
                        divArray[i].className = "test1";
                }
			}
			return false;
		}
	}
}



function formatAmt(evt)
{
	var elt;
	evt = (evt) ? evt : window.event;
	if (evt)	elt = (evt.target) ? evt.target : evt.srcElement;
	var amt = elt.value;
	if (reAmt.test(amt))	elt.value = new Curr(amt).toMStr();
}

function formatDate(evt)
{
	var elt;
	evt = (evt) ? evt : window.event;
	if (evt)	elt = (evt.target) ? evt.target : evt.srcElement;
	var date = elt.value;
	if (reDate.exec(date) != null)
		elt.value = ((RegExp.$1.length == 1) ? "0" : "") + RegExp.$1 + "/" +
						 ((RegExp.$2.length == 1) ? "0" : "") + RegExp.$2 + "/" +
						 RegExp.$3;
}

function trapBspce(evt)
{
	if (!evt)
	{
		evt = window.event;
		var src = evt.srcElement;
		if (evt.keyCode == 8 && (!/^(text|password)$/.test(src.type) || src.className == "readOnly"))
			evt.returnValue = false;
	}
}

function initEstMenuItems()
{
	var mestext = document.getElementById("mestext");
	var mestchq = document.getElementById("mestchq");
	mestext.getElementsByTagName("a")[0].href = "javascript:void(est('etp'))";
	//mestchq.getElementsByTagName("a")[0].href = "javascript:void(est('estchq'))";
	actionEnable("estext", payeeCount < gMaxPayees);
	actionEnable("estchq", payeeCount < gMaxPayees);
	if (typeof(payeeCount) == "number" && payeeCount == gMaxPayees)
		mestext.className = "disabled";
}

/**
 * The $ function
 * For each string in the input arguments, returns an array containing the associated
 * dom element (getElementById). Non-string elements are copied to the output array
 * unchanged. If only one string is provided as input, will return the associated dom
 * element rather than an array.
 * @param {string, object} arglist One or more strings/elements
 * @return Returns either a single element or an array of elements
 */
function $()
{
  var elts = [], len = arguments.length;
  for (var i = 0; i < len; i++)
  {
    var elt = arguments[i];
    elts[i] = (typeof elt == 'string') ? document.getElementById( elt) : elt;
  }
  return (len == 1) ? elts[0] : elts;
}

/**
 * The setText function
 * This fuction checks to see if the innerText property is available (browser IE). 
 * If this property is availabel it uses it otherwise uses the textContent proerty (Firefox browser)
 * @sets the text value of the HTML element
 */
function setText(elt, text)
{
    //if(document.all)        //Firefox & other browsers
    if(typeof document.body.innerText == 'undefined')
        elt.textContent = text;
    else                      //IE
        elt.innerText = text;
}