// CODE NEEDS TO BE REFACTORED - TOO MUCH REDUNDANCY

// SET CURRENT DATE AND DISPLAY IT FOR ELEMENTS WITH ID "dynamic_date"
// Current date and time
var now = new Date();

// Array of day names
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array of month names
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Number of the current day in the month
var dayNumber = ((now.getDate()<10) ? "0" : "") + now.getDate();

// Today's date in Day, Month ##, #### format
var today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + dayNumber + ", " + getFourDigitYear(now.getYear());

// Get four digit year
function getFourDigitYear(year){
	return (year < 1000) ? year + 1900 : year;
}

function setDate() {
   if(document.getElementById && document.createTextNode){
      var date = document.getElementById('dynamic_date');
      if(date) {
         var dateText = date.firstChild;
         if(dateText.nodeType==3){
            dateText.nodeValue=today;
         }
         if(dateText.nodeType==1){
		 date.removeChild(date.firstChild);
		 var dateString = document.createTextNode(today);
		 date.appendChild(dateString);
         }
      }
   }
}



// DISPLAY RANDOM SECURITY TIP
function StringArray (n) {
  this.length = n;
  for (var i =1; i <= n; i++) {this[i] = ' ';}
}

var tip = new StringArray(6);
tip[0] = 'Change your online banking login password on a regular basis.';
tip[1] = 'Make your password at least 6 characters in length and a combination of numbers and letters.';
tip[2] = 'Change your session timeout in User Options to a time that meets your needs.';
tip[3] = 'Balance your account on a regular basis.  Online Banking makes it easy!';
tip[4] = 'ASB will never ask for personal information via an email.  If you should receive an email that appears to be from ASB asking for this information, please do not respond to the email but contact us immediately at 201-444-7100.';
tip[5] = 'Never reveal your password to anyone or leave your password anywhere that someone else can obtain and use it.  If you feel that your password has been compromised contact our Online Banking Department immediately at 201-444-7100 for assistance.';

function randomTip() {
var core = Math.floor(Math.random() * tip.length);


if(document.getElementById && document.createTextNode){
      var securityTip = document.getElementById('tip');
      if(securityTip) {
         var tipText = securityTip.firstChild;
         if(tipText.nodeType==3){
            tipText.nodeValue=tip[core];
         }
         if(tipText.nodeType==1){
		 securityTip.removeChild(securityTip.firstChild);
		 var tipString = document.createTextNode(tip[core]);
		 securityTip.appendChild(dateString);
         }
      }
   }

}


// POPUP NEW WINDOWS
function doPopups() {
  if (!document.getElementsByTagName) return true;

  var links = document.getElementsByTagName("a");

  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("external")) {
      links[i].onclick = function() {
			var agree = confirm("We have provided links to resources that we hope will be helpful to you.\nThe website you are about to link to is not controlled by Atlantic Stewardship Bank and\n different terms of use and privacy policy will apply. By proceeding, you agree and\n understand that Atlantic Stewardship Bank is not responsible for this site\n you are about to access.\n\nContinue to requested website?");
			if (agree) {
				var winpop = window.open(this.href,"win","width=500px,height=400px,toolbar,location,status,scrollbars,menubar,resizable");
				winpop.focus();
				return false;
			}
			else {return false;}
      }
    }
  }
  return false;
}

// FEATURE ROTATOR
var Features = new Array();

Features[0] = new Array(4)
Features[0][0] = "Take control of your finances. Apply Today!";
Features[0][1] = "https://www.asbnow.com/onlineserv/HB/Login.cgi?runmode=REGISTRATION";
Features[0][2] = "apply1";

Features[1] = new Array(4)
Features[1][0] = "Take control of your finances. Apply Today!";
Features[1][1] = "http://www.asbnow.com/site/apply.html";
Features[1][2] = "apply2";

Features[2] = new Array(4)
Features[2][0] = "Online Banking...quick as a click!";
Features[2][1] = "https://www.asbnow.com/onlineserv/HB/Login.cgi?runmode=REGISTRATION";
Features[2][2] = "apply3";

Features[3] = new Array(4)
Features[3][0] = "Take control of your finances. Apply Today!";
Features[3][1] = "http://www.asbnow.com/site/apply.html";
Features[3][2] = "apply4";

var F = Features.length;
var whichFeature=Math.round(Math.random()*(F-1));
function getRandomFeature(){return whichFeature;}

function createStyledElement(tag, parent,indx) {
	if(parent.hasChildNodes()) {
		parent.removeChild(parent.firstChild);
	}


	var el  = document.createElement(tag);
	var txt = Features[indx][0];
	var url = Features[indx][1];
	var ss  = Features[indx][2];

	el.className = ss;
	el.setAttribute('href',url);
	//if(css) for(var s in css) el.style[s]=css[s];
	parent.appendChild(el);
	el.appendChild(document.createTextNode(txt));
	el.appendChild(document.createElement('span'));
    }

// FOCUS FIELD eg. LOGIN
function focusField(formId, fieldId){
	if (document.forms[formId]) {
		if (document.forms[formId].elements[fieldId]) {
			document.forms[formId].elements[fieldId].focus();
		}
		else {return false;}
	}
	else {return false;}
	return false;
}

// INITIALIZE FUNCTIONS
window.onload=function() {
	setDate();
	randomTip();
	doPopups();
	createStyledElement("a",document.getElementById("featured"), getRandomFeature());
	focusField("Login","userNumber");
}

function includeFlash(){
	//do nothing
}

// SNL HOME PAGE
outsideURL = "";
function showWinsnl(URL,URL2)
{
outsideURL=URL2;
var pWidth = ((parseInt(screen.width) - 400) / 2); 
var pHeight = ((parseInt(screen.height) - 300) / 2);
newwin = window.open(URL,"newwin","width=240,height=200,left="+pWidth+",top="+pHeight+"");
}