function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
	
	for(i=0;i<(a.length-2);i+=3)
			if ((x=MM_findObj(a[i]))!=null)
			{
				document.MM_sr[j++]=x; 
					if(!x.oSrc) 
						x.oSrc=x.src; 
						
						x.src=a[i+2];
			}
}


/* Banner Rotation Script */
function banner(imgSource,url,alt,chance) {
this.imgSource = imgSource;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function dispBanner() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + imgSource + "' WIDTH=120 HEIGHT=90 BORDER=0 HSPACE=8 VSPACE=1 ALT='" + alt + "'></A>");
}
banner.prototype.dispBanner = dispBanner;
banners = new Array();
                                                                                                                       
banners[0] = new banner("ads/120x90TrueCredit.gif",
                        "http://www.anrdoezrs.net/click-2148965-10432543 target='_blank'",
                        "True Credit !",
                        33);
banners[1] = new banner("ads/120x90TrueCredit.gif",
                        "http://www.anrdoezrs.net/click-2148965-10432543 target='_blank'",
                        "True Credit !",
                        33);

sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function randomBanner() {
chance_limit = 0;
randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
for (i = 0; i < banners.length; i++) {
chance_limit += banners[i].chance;
if (randomly_selected_chance <= chance_limit) {
document.write("<A HREF=" + banners[i].url + "><IMG SRC='" + banners[i].imgSource + "' WIDTH=120 HEIGHT=90 BORDER=0 vspace=3 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
      }
   }
}

/* END : Banner Rotation Script */

/* Clear value in Text item */
function ClearForm(){

	var form, elements, i, elm; 
	form = document.getElementById  ? document.getElementById(document.forms[0])  : document.forms[document.forms[0]]; 
    		
	if (document.getElementsByTagName)
	{
		elements = document.forms[0].getElementsByTagName('input');
		
		for( i=0, elm; elm=elements.item(i++); )
		{
			if (elm.getAttribute('type') == "text")
			{
				elm.value = '';
			}
		}
		
		elements = document.forms[0].getElementsByTagName('select');
		
		for( i=0, elm; elm=elements.item(i++); )
		{
			elm.options.selectedIndex=0;
		}
	}

/*
	var ObjEl = document.all;
	
	
	alert(document.layers);
	
	for(var i = 0 ; i < ObjEl.length ; ++i) {
		 if(ObjEl[i].type == "text" || ObjEl[i].type == "select" || ObjEl[i].type == "password") {
			ObjEl[i].value="";
		 }		
	}
	*/
	
	return ;
}	 

function PrintStatement(ctl, stmtdate, last4, width, height)
{
	window.open('PrintFriendly.aspx?userctl='+ ctl + '&stmtdate='+ stmtdate + '&last4=' + last4,'MyWindow2','toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',left=10,top=10');
}


//Auto Tab Functionality 
var isNS = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e)
{
	var keyCode = (isNS) ? e.which : e.keyCode; 
	var filter = (isNS) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}
	return true;
}

/* Auto Tab Ends  */

function NumNoDecimalAndDashes(e)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	return true;

	// alphas, numbers, Space & #
	else if ((("0123456789-").indexOf(keychar) > -1))
	return true;
	else
	return false;
}

function NumNoDecimal(e)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	return true;

	// alphas, numbers, Space & #
	else if ((("0123456789").indexOf(keychar) > -1))
	return true;
	else
	return false;
}

	function PostBackUpdateAccessInfo()
	{
		var validated = true;
		if (typeof(Page_ClientValidate) == 'function') 
			validated = Page_ClientValidate();
			
		if (validated)
		{
			__doPostBack('template$uc_BodyContent$ImgSubmit','');
		}
	}

	function OpenAccessInfoPopUp()
	{
		var validated = true;
		if (typeof(Page_ClientValidate) == 'function') 
			validated = Page_ClientValidate();
			
		if (validated)
		{
			window.open('UpdateAccessPopup.aspx','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=400,height=225,left=50,top=50');
		}
		
		return false;
	}
	
	function TermsOfUsePopUp()
	{		
		var ScrLeft = (screen.width-560) / 2;
		var ScrTop = (screen.height-420) / 2;
		
		var WinPop = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=435,left=10,top=10';		
		
		//WinPop =WinPop + 'left=' + ScrLeft +',top='+ ScrTop;
		
		window.open('PopWinTerms.aspx','MyWindow', WinPop);
	
	}
	
	
	function PopWin(PageName, screenheight, screenwidth)
	{
		var WinPop = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + screenwidth + ',height='+ screenheight;
		var ScrLeft = (screen.width-screenwidth) / 2;
		var ScrTop = (screen.height-screenheight) / 2;
		
		WinPop =WinPop + ',left=' + ScrLeft +',top='+ ScrTop;

		winname= window.open(PageName, 'MyWindow', WinPop);
	}

	function PopWinScroll(PageName, screenheight, screenwidth )
	{
		var WinPop = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width=' + screenwidth + ',height='+ screenheight;
		var ScrLeft = (screen.width-screenwidth) / 2;
		var ScrTop = (screen.height-screenheight) / 2;
		
		WinPop =WinPop + ',left=' + ScrLeft +',top='+ ScrTop;

		winname= window.open(PageName, 'MyWindow', WinPop);
	}
		
	function PopWin(PageName, screenheight, screenwidth, targetname)
	{
		var WinPop = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + screenwidth + ',height='+ screenheight;
		var ScrLeft = (screen.width-screenwidth) / 2;
		var ScrTop = (screen.height-screenheight) / 2;
		
		WinPop =WinPop + ',left=' + ScrLeft +',top='+ ScrTop;

		winname= window.open(PageName, targetname, WinPop);
	}
	
	function PopPage(PageName, screenwidth)
	{
		var WinPop = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + screenwidth;
		var ScrLeft = (screen.width-screenwidth) / 2;
		
		WinPop =WinPop + ',left=' + ScrLeft;

		winname= window.open(PageName, 'MyPage', WinPop);
	}										
	
	function PopTerms(PageName, screenheight, screenwidth)
	{
		var WinPop = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + screenwidth + ',height='+ screenheight;
		var ScrLeft = (screen.width-screenwidth) / 2;
		var ScrTop = (screen.height-screenheight) / 2;
		
		WinPop =WinPop + ',left=' + ScrLeft +',top='+ ScrTop;

		winname= window.open(PageName, 'MyWindow', WinPop);
	}
		
	function CompileCard()
	{
		var box1 = document.getElementById('template_uc_BodyContent_txtCard1').value;
		var box2 = document.getElementById('template_uc_BodyContent_txtCard2').value;
		var box3 = document.getElementById('template_uc_BodyContent_txtCard3').value;
		var box4 = document.getElementById('template_uc_BodyContent_txtCard4').value;
		var card = document.getElementById('template_uc_BodyContent_h_card');
		
		card.value = box1.toString() + box2.toString() + box3.toString() + box4.toString();
	}

	function CompilePhone()
	{
		var box1 = document.getElementById('template_uc_BodyContent_txtPhone1').value;
		var box2 = document.getElementById('template_uc_BodyContent_txtPhone2').value;
		var box3 = document.getElementById('template_uc_BodyContent_txtPhone3').value;		
		var Phone = document.getElementById('template_uc_BodyContent_h_phone');
		
		Phone.value = box1.toString() + box2.toString() + box3.toString();
	}	
	

	function CompileControl()
	{
		var strVal = '';
		var strHidCtrl;
		
		//No of Argument
		var args = CompileControl.arguments;
		
		//Hidden Control 
		strHidCtrl = args.length;
	
		for(i=0; i<args.length-1; i++)
		{
			strVal += document.getElementById(args[i]).value.toString();			
		}		
		
		document.getElementById(args[strHidCtrl-1]).value = strVal;		
	}
	
//To Disable double click event
function DisableDBClick(ctrl){
	document.getElementById(ctrl).onclick = new Function("return false;");
}


function ValidatePIN()
{
	if (!document.Form1.template_uc_BodyContent_ChkPrimary.checked)
		{
			alert('Please select the name you want to receive PIN.');
			document.Form1.template_uc_BodyContent_ChkPrimary.focus();
			return false;
		}
}	

function BillingCycle( p_Code, p_Desc )
{
	eval(document.getElementById("template_uc_BodyContent_h_code")).value= p_Code ;
	eval(document.getElementById("template_uc_BodyContent_h_desc")).value= p_Desc ;
	document.Form1.submit();	
}

function lite(obj) {
	if(document.all&&!window.opera) {
		obj.filters.blendTrans.apply(); 
		obj.filters.blendTrans.play(); 
	} 
}

//Form OnKeyDown event override
function keyDownOverride(objectName, e)
{
	var key;
	
	if(window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which
	}
	
	if (key == 13)
	{
		e.returnValue=false; 
		e.cancel = true;
		if(objectName != null)
		{
			obj = document.getElementById(objectName);
			obj.click();
		}
	}
}


function HideContent(d) 
{
	if( d.length < 1) 
	{ 
		return; 
	}
	document.getElementById(d).style.display = "none";
}

function ShowContent(d) 
{
	if(d.length < 1) 
	{ 
		return; 
	}
	
	document.getElementById(d).style.display = "block";
}

function ReverseContentDisplay(d) 
{
	if(d.length < 1) 
	{ 
		return; 
	}
	if(document.getElementById(d).style.display == "none") 
	{ 
		document.getElementById(d).style.display = "block"; 
	}
	else 
	{ 
		document.getElementById(d).style.display = "none"; 
	}
}

function toggleDraftDateMessageDiv(draftDateMessageID, draftDateID, accountDueDate, minimumAmountDue)
{
	var draftDateList = document.getElementById(draftDateID);
	var draftDateString = draftDateList.options[draftDateList.selectedIndex].text.split("/");
	var draftDate = new Date(draftDateString[2], draftDateString[0]-1, draftDateString[1]);
	
	var tempToday = new Date();
	var today = new Date(tempToday.getFullYear(), tempToday.getMonth(), tempToday.getDate());
	
	var message = document.getElementById(draftDateMessageID);
	
	var tempDate = accountDueDate.split("/");
	var acctDueDate = new Date(tempDate[2], tempDate[0]-1, tempDate[1]);
	
	if (today <= acctDueDate && draftDate >= acctDueDate && minimumAmountDue > 0)
	{
		message.className = 'OuterPop';
	}
	else
	{
		message.className = 'hiddenDiv';
	}	
}



/* To enable & diable tabs */
function toggle_visibility(id) 
{
    var e = document.getElementById(id);
    
    if(e.style.display == 'block')
        e.style.display = 'none'; 
    else
        e.style.display = 'block';     
}

function toggle_visibility_by_Type(bankType) 
{
    if ( bankType == 'Savings')
    {
		var e = document.getElementById('template_uc_BodyContent_SavingsAccount');			
		e.style.display = 'block';     
		
		var ei = document.getElementById('template_uc_BodyContent_SavingsAccountImg');			
		ei.style.display = 'block';		
		
		var e = document.getElementById('template_uc_BodyContent_CheckingAccount');			
		e.style.display = 'none';
		
		var ei = document.getElementById('template_uc_BodyContent_CheckingAccountImg');			
		ei.style.display = 'none';
		
		document.getElementById('template_uc_BodyContent_h_type').value = bankType;		
    }
    else
    {
		var e = document.getElementById('template_uc_BodyContent_CheckingAccount');			
		e.style.display = 'block';     
		
		var ei = document.getElementById('template_uc_BodyContent_CheckingAccountImg');			
		ei.style.display = 'block';
		
		var e = document.getElementById('template_uc_BodyContent_SavingsAccount');			
		e.style.display = 'none';     
		
		var ei = document.getElementById('template_uc_BodyContent_SavingsAccountImg');			
		ei.style.display = 'none';		
		
		document.getElementById('template_uc_BodyContent_h_type').value = bankType;
    }
}

function setBankType(ctrl, bankType )
{	
	document.getElementById(ctrl).value = bankType;		
}


function Hide(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}

function Show(d, sUrl) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";


	if ( (sUrl != null) && (sUrl.length > 0) )
	{
		document.getElementById("HrfSpeedBumpURL").href = sUrl;
	}
}


function HideSurveyItems(SelectValue, d, delimit) {
	if(d.length < 1) { 
		return; 
		}

		var SplitResult = d.split(',');

		for(i = 0; i < SplitResult.length; i++)
		{	
			if ( SelectValue == 'Yes' )			
				document.getElementById(SplitResult[i]).style.display = "";	
			else
				document.getElementById(SplitResult[i]).style.display = "none";				
		}
}

function showAlert(alertLoc,alertMsg) {
	var obj = document.getElementById(alertLoc);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	var msg = document.getElementById(alertMsg);
	msg.style.left = curleft + 16 + "px";
	msg.style.top = curtop + 4 + "px";
	msg.style.position = "absolute";
	msg.style.display = "block";
}
    
function hideAlert(alertMsg) { 
   document.getElementById(alertMsg).style.display = "none"; 
}


function $addEvent(element, name, wrapper) {
	if (element.addEventListener) {
		element.addEventListener(name, wrapper, false);
  } 
  else {
		element.attachEvent("on" + name, wrapper);
  }
}

function $createWrapper(instance, method) {
	return function() { return method.apply(instance, arguments); }
}

