﻿/* =Helper Functions
----------------------------------------------- */
// Dreamweaver functions
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];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}


// Help Javascript get style info from stylesheet (usually only understands inline styles)
function getStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

// Print function
function printCheck() {
	if (window.print) {
		window.print();
	} else { 
		alert("Your browser does not support this print function. Please hit CTRL-P if you are using windows, or APPLE/ALT-P if using a Mac.");
	}
}

// Non-destructive way to add new functions to the window.onload event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload !== 'function') {
    window.onload = func;
  } else {
    window.onload = function () {
      oldonload();
      func();
    };
  }
}

/* =Put focus on the login form
-------------------------------------------------- */
function focusLoginForm(){
   if(document.getElementById("id")){
      document.getElementById("id").focus();
   }
}
addLoadEvent(focusLoginForm);

/* =Jump Menu Script (Unobtrusive)
-------------------------------------------------- */
function initJumpMenus() {
	// Check to see if we can interact with the DOM
	if (!document.getElementById) { return false; }
	// grab an array of all the select elements on the page
	var selectElements = document.getElementsByTagName("select");
	// Loop through all select elements
	for( i = 0; i < selectElements.length; i++ ) {
		// Check for the class and make sure the element has an ID
		if( selectElements[i].className == "jumpmenu" && document.getElementById(selectElements[i].id) != "" ) {
			// Get the select element's id
			jumpmenu = document.getElementById(selectElements[i].id);
			// Add an onchange event to the select menu
			jumpmenu.onchange = function() {
				// Make sure the selected index isn't blank
				if( this.options[this.selectedIndex].value != '' ) {
					// Redirect to the URL contained in the selected index's value
					location.href=this.options[this.selectedIndex].value;
				}
			}
		}
	}
}
addLoadEvent(initJumpMenus);

/* =Menu Functions
----------------------------------------------- */
function P7_autoLayers() { //v1.5 by PVII
 var g,b,k,f,u,k,j,args=P7_autoLayers.arguments,a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}

var timeOut = null;

function navIn() {
	if (timeOut != null) {
		window.clearTimeout(timeOut);
	}
}

function navTimer() {
	if (timeOut != null) {
		window.clearTimeout(timeOut);
	}
	timeOut = window.setTimeout('hideMenuObjects()',250);
}

function hideNav(navItem, action) {
	MM_showHideLayers(navItem,'',action);
}
function hideMenuObjects(){
	menuObj = document.getElementById("navMain");
	menus = menuObj.getElementsByTagName("div");
	for ( n = 0; n < menus.length; n++) {
		menus[n].style.visibility = "hidden";
	}
}

/* =Window Functions
----------------------------------------------- */
function windowFunctions() {
	if (!document.getElementsByTagName) { return false; }
	var links, i;
	links = document.getElementsByTagName("a");
	for (i = 0; i < links.length; i++) {
		if (links[i].className.match("(^| )extLink( |$)")) {
			links[i].onclick = function() {
				disclaimer(this.href);
				return false;
			};
		}
		if (links[i].className.match("(^| )emailLink( |$)")) {
			links[i].onclick = function() {
				mailConfirm(this.href);
				return false;
			};
		}
		if (links[i].className.match("(^| )testBrowser( |$)")) {
			links[i].onclick = function() {
				window.open(this.href,'securityAdvisor','scrollbars=yes,resizable=yes,width=400,height=450');
				return false;
			};
		}
		if (links[i].className.match("(^| )calcLink( |$)")) {
			links[i].onclick = function() {
				window.open(this.href,'calculators','scrollbars=yes,resizable=yes,width=640,height=480');
				return false;
			};
		}
		if (links[i].className.match("(^| )newWindow( |$)")) {
			links[i].onclick = function() {
				window.open(this.href);
				return false;
			};
		}
	}
}
addLoadEvent(windowFunctions);

/* =Disclaimers
----------------------------------------------- */
var emailDisclaimer = "You are about to send information over the internet that may not be transmitted in an encrypted or secure form. It might be possible for others to see what you are sending. For your protection, please do not send any personal information (i.e. Social Security Number, account number, date of birth, etc.)\n\nClick OK to continue or Cancel to stay where you are.";

var linkDisclaimer = "You are leaving the Whidbey Island Bank web site.\n\nWhidbey Island Bank makes no endorsements or recommendations of the web site your are about to visit, or its contents, and disclaims any responsibility for actions or transactions on that site. Be aware that the privacy policy of the web site your are about to visit is not that of Whidbey Island Bank.\n\nClick OK to continue or Cancel to stay where you are.";


function mailConfirm(passedAddress) {
	if (confirm(emailDisclaimer)) {
		window.location.href = passedAddress;
	}
}

function disclaimer(passedWebsite) {
	var oWin;
	if (confirm(linkDisclaimer)) {
		oWin = window.open(passedWebsite,"newWindow");
		if (oWin === null || typeof(oWin) === "undefined") {
			window.location.href = passedWebsite;
		} else {
			return true;
		}
	}
}

/* =Locations Functions
----------------------------------------------- */
function hideAllLocations() {
	// check to see if we can interact with the DOM
	if (!document.getElementsByTagName || !document.getElementById) { return false; }
	// set variables
	var locationsContainer, locations, photoContainer, locationsPhoto, headquarters;
	// hide all div tags inside the locations container - effectively hiding all locations information
	locationsContainer = document.getElementById("locationsContainer");
	locations = locationsContainer.getElementsByTagName("div");
	for (i = 0; i < locations.length; i++) {
		locations[i].style.display = "none";
	}
	// set the location photo to hide
	locationsPhoto = document.getElementById("locationsPhoto");
	locationsPhoto.style.display = "none";
	// we've hidden all div tags inside the locations container, 
	// but we want the headquarters info to show at all times. So we set it to show again.
	headquarters = document.getElementById("headquarters");
	headquarters.style.display = "block";
}

function showLocation(locationID, locationName) {
	// check to see if we can interact with the DOM
	if (!document.getElementsByTagName || !document.getElementById) { return false; }
	// set variables
	var locationsContainer, photoContainer, locationsPhoto;
	// run hideAllLocations function so no locations show on page load
	hideAllLocations();
	// show the location passed to this function
	locationsContainer = document.getElementById(locationID);
	locationsContainer.style.display = "block";
	// change the src of the location photo to match the current location
	locationsPhoto = document.getElementById("locationsPhoto");
	locationsPhoto.style.display = "none";
	locationsPhoto.src = "images/locations/" + removeSpaces(locationName) + ".jpg";
	locationsPhoto.alt = locationName;
	// don't forget to set the location photo to show
	locationsPhoto.style.display = "block";
}

/* =Employment Opportunities Show Hide Function
----------------------------------------------- */
function toggleShowHide(id) {
	if(document.getElementById("linkObject" + id).className == "showTableCell") {
		document.getElementById("linkObject" + id).className = "hideObject";
		document.getElementById("displayObject" + id).className = "showTableCell";	
	} else {
		document.getElementById("linkObject" + id).className = "showTableCell";
		document.getElementById("displayObject" + id).className = "hideObject";	
	}
	return;
}
