﻿/* =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];}
}

// 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;
  oldonload = window.onload;
  if (typeof window.onload !== 'function') {
    window.onload = func;
  } else {
    window.onload = function () {
      oldonload();
      func();
    };
  }
}
function addUnLoadEvent(func) {
	var oldonload = window.onunload;
	if (typeof window.onunload !== 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			oldonunload();
			func();
		};
	}
}

/* =Create Jump Menus
----------------------------------------------- */
function initJumpMenus() {
	// Check to see if we can interact with the DOM
	if (!document.getElementById) { return false; }
	// Set the variables used in this funtion
	var selectElements, i, jumpmenu;
	// grab an array of all the select elements on the page
	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.match("(^|\\s)jumpmenu(\\s|$)") && 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
					window.location.href=this.options[this.selectedIndex].value;
				}
			}
		}
	}
}
// Run the initJumpMenus() function on page load
addLoadEvent(initJumpMenus);

/* =Put focus on the login form
-------------------------------------------------- */
function focusLoginForm(){
	// Check to see if we can interact with the DOM
	if(!document.getElementById) { return false; }
	if(document.getElementById("id")){
		document.getElementById("id").focus();
	}
}
// Run the focusLoginForm() function on page load
addLoadEvent(focusLoginForm);


/* =Preload navMain rollover images on page load
----------------------------------------------- */
function preloadAllImages() {
	MM_preloadImages('images/navMain/onlineBanking_f2.png','images/navMain/loanAccounts_f2.png','images/navMain/depositAccounts_f2.png','images/navMain/additionalServices_f2.png','images/onlineBanking/aboutUs_f2.png');
}
// Run the preloadAllImages() function on page load
addLoadEvent(preloadAllImages);

/* =Menu Functions
----------------------------------------------- */
// This makes the menus functions. Created by Project VII
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];}}}
}

// Reset the timer
var timeOut = null;

function navIn() {
	// If the timer has not been reset
	if (timeOut != null) {
		// Reset the timer
		window.clearTimeout(timeOut);
	}
}

function navTimer() {
	// Run the navIn() function to reset the timer
	navIn();
	// Run the hideMenuObjects() after a delay of 250ms
	timeOut = window.setTimeout('hideMenuObjects()',250);
}

function hideMenuObjects(){
	// Check to see if we can interact with the DOM & whether #navMain exists
	if (!document.getElementsByTagName || !document.getElementById("navMain")) { return false; }	
	// Set the variables used in this funtion
	var menuObj, menus, n;
	// Find the element with an ID of #navMain
	menuObj = document.getElementById("navMain");
	// Grab an array of all div elements within the #navMain element
	menus = menuObj.getElementsByTagName("div");
	// Loop through the div elements
	for ( n = 0; n < menus.length; n++) {
		// Hide all of those div elements
		menus[n].style.visibility = "hidden";
	}
}

/* =Window Functions
----------------------------------------------- */
function windowFunctions() {
	// Check to see if we can interact with the DOM
	if (!document.getElementsByTagName) { return false; }
	// Set all the variables for this function
	var links, i;
	// grab an array of all the links on the page
	links = document.getElementsByTagName("a");
	// Loop through all links
	for (i = 0; i < links.length; i++) {
		// If the class name is "extLink" it's an external link
		if (links[i].className.match("(^|\\s)extLink(\\s|$)")) {
			// Add an onclick event to the link
			links[i].onclick = function() {
				// Run the external link discliamer function
				disclaimer(this.href);
				// Stop the link from going through (The disclaimer function handles the rest)
				return false;
			};
		}
		// If the class name is "emailLink" it's an email link
		if (links[i].className.match("(^|\\s)emailLink(\\s|$)")) {
			// Add an onclick event to the link
			links[i].onclick = function() {
				// Run the email disclaimer function
				mailConfirm(this.href);
				// Stop the link from going through (The disclaimer function handles the rest)
				return false;
			};
		}
		// If the class name is "testBrowser" it's a link to our browser text page
		if (links[i].className.match("(^|\\s)testBrowser(\\s|$)")) {
			// Add an onclick event to the link
			links[i].onclick = function() {
				// Open a new window using the href attribute of the current link
				window.open(this.href,'securityAdvisor','scrollbars=yes,resizable=yes,width=400,height=450');
				// Stop the link from going through (The window.open method handles the rest)
				return false;
			};
		}
		// If the class name is "calcLink" it's a link to our calculator popup page
		if (links[i].className.match("(^|\\s)calcLink(\\s|$)")) {
			// Add an onclick event to the link
			links[i].onclick = function() {
				// Open a new window using the href attribute of the current link
				window.open(this.href,'calculators','scrollbars=yes,resizable=yes,width=640,height=480');
				// Stop the link from going through (The window.open method handles the rest)
				return false;
			};
		}
		// If the class name is "newWindow" it's a link to a new window
		if (links[i].className.match("(^|\\s)newWindow(\\s|$)")) {
			// Add an onclick event to the link
			links[i].onclick = function() {
				// Open a new window using the href attribute of the current link
				window.open(this.href);
				// Stop the link from going through (The window.open method handles the rest)
				return false;
			};
		}
	}
}
// Run the windowFunctions() function on page load
addLoadEvent(windowFunctions);

/* =Disclaimers
----------------------------------------------- */
var emailDisclaimer = "You are about to send information to Farmers & Merchants Bank 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. Therefore, you should assume that email is not secure. For your protection, please do not send any personal information (i.e., Social Security Number, Account Number, Date of Birth, PIN Number, etc.). If you have an account related concern, please contact one of our branch locations.";

var linkDisclaimer = "You are leaving the Farmers & Merchants Bank website. The site you have chosen is independent from Farmers & Merchants Bank. We do not control these sites and do not guarantee the accuracy, completeness, security or timeliness contained therein. Be aware the privacy policy of the linked website is not that of Farmers & Merchants.";

function mailConfirm(passedAddress) {
	// If the user clicks OK on the confirm dialog
	if (confirm(emailDisclaimer)) {
		// Set the location of the window to the passed address
		window.location.href = passedAddress;
	}
}

function disclaimer(passedWebsite) {
	// Set the variables used in this funtion
	var oWin;
	// If the user clicks OK on the confirm dialog
	if (confirm(linkDisclaimer)) {
		// Try to open a new window using the passed address
		oWin = window.open(passedWebsite,"newWindow");
		// Check to see if the new window was blocked by a popup blocker
		if (oWin === null || typeof(oWin) === "undefined") {
			// If the new window was blocked, set the location of the current window to the passed address
			window.location.href = passedWebsite;
		} else {
			// Otherwise, let the function continue
			return true;
		}
	}
}

/* =Show/Hide Functions
----------------------------------------------- */

//Product Matrix Show/Hide Code With Highlight.
function toggleMoreInfoHighlight(id) {
	if (document.getElementById("moreInfo" + id).className == "hideMoreInfo") {
		document.getElementById("moreInfo" + id).className = "showMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "&laquo;Hide";
		document.getElementById("productRowHighlight" + id).className = "rowHighlight";
	}
	else {
		document.getElementById("moreInfo" + id).className = "hideMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "More&raquo;";
		document.getElementById("productRowHighlight" + id).className = "";
	}
}

//FAQs Show All Code.
function toggleFaqVisibility(id) {
	if (document.getElementById("displayObject" + id).className == "faqAnswerHidden") {
		document.getElementById("displayObject" + id).className = "faqAnswer";
	} else {
		document.getElementById("displayObject" + id).className = "faqAnswerHidden";
	}
	return;
}

//FAQs Show/Hide Code.
function toggleFaqVisibilityAll(display,startRow,stopRow) {
	for (var n = startRow; n <= stopRow; n++) {
		if (display == "show") {
			document.getElementById("displayObject" + n).className = "faqAnswer";
		} else {
			document.getElementById("displayObject" + n).className = "faqAnswerHidden";
		}
	}
		return;
}

//Generic Show/Hide Code.
function showAll(status,startRow,stopRow) {
	//argument 4 is OPTIONAL - use this argument to specify different class names to be used
	//for each different class name add a 'case' statement to the switch statement below (be sure to end with break;)
	//THE DEFAULT IS ZERO (0)!
	var typeFlag = ((arguments.length>=4)?arguments[3]:0); //the array is zero-based
	for(n=startRow;n<=stopRow;n++) {
		if(status == 0) {
			switch(typeFlag) {
				case 0:
					document.getElementById("linkObject" + n).className = "bulletPlusListTd";
					break;
				default:
					document.getElementById("linkObject" + n).className = "bulletPlusListTd";
			}
			document.getElementById("displayObject" + n).className = "hideObject";
		} else {
			document.getElementById("linkObject" + n).className = "hideObject";
			document.getElementById("displayObject" + n).className = "bulletPlusListTd";
		}
	}
	return;
}

function toggleShowAllVisibility(id) {
	if(document.getElementById("linkObject" + id).className == "bulletPlusListTd") {
		document.getElementById("linkObject" + id).className = "hideObject";
		document.getElementById("displayObject" + id).className = "bulletPlusListTd";	
	} else {
		document.getElementById("linkObject" + id).className = "bulletPlusListTd";
		document.getElementById("displayObject" + id).className = "hideObject";	
	}
	return;
}

function toggleLocations(id,start,end) {
	for (var n = start; n <= end; n++) {
		document.getElementById("displayObject" + n).className = "hideObject";
	}
	document.getElementById("displayObject" + id).className = "matrixAlt";
	return;
}

/* =Print style helper
----------------------------------------------- */
// Hides page header graphics, displaying the alt text for the image instead
function getHeaderAlts() {
	// Check to see if we can interact with the DOM. Does #pageHeader exist?
	if (!document.getElementsByTagName || !document.getElementById("pageHeader")) { return false; }
	// Set all the variables for this function
	var headerContainer, headerContainer, headerImage, n, headerText, headerSpan, css, cssText;
	// Get #pageHeader div tag
	headerContainer = document.getElementById("pageHeader");
	// Get the first image inside #pageHeader div tag (should be only image)
	headerImage = headerContainer.getElementsByTagName("img")[0];
	// Get the first h1 tag inside #pageHeader div tag  (should be only h1 tag)
	headerTag = headerContainer.getElementsByTagName("h1")[0];
	// Get the alt attribute of the image and create a variable to contain it
	headerText = document.createTextNode(headerImage.alt);
	// Create a generic span tag
	headerSpan = document.createElement("span");
	// Append the span tag to the end of the h1 tag
	headerTag.appendChild(headerSpan);
	// Insert the alt attribute content into the span tag
	headerSpan.appendChild(headerText);
	// Create a generic style tag
	css = document.createElement('style');
	// The next 2 lines set up attributes for the style tag
	css.setAttribute('type', 'text/css');
	css.setAttribute('media', 'print');
	// Set the text to insert into the style tag
	cssText = "#pageHeader img {display: none;}";
	// Conditional code used to insert content into style tag (PS = IE sucks)
	if(css.styleSheet) {
		// IE does it this way
		css.styleSheet.cssText = cssText}
	else {
		// everyone else does it this way
		css.appendChild(document.createTextNode(cssText));
	}
	// Append the style tag to the end of the first head tag on the page (should be only 1 head tag per page)
	document.getElementsByTagName("head")[0].appendChild(css);
}
// Run the getHeaderAlts() function on page load
addLoadEvent(getHeaderAlts);


function evalLink(linkURL,linkTarget,disclaimerFlag) {
	var regexp = /&quote;/g;
	switch(linkTarget) {
		case 0: //Same window
			if(disclaimerFlag == 1) {
				if(confirm(linkDisclaimer)) window.location = linkURL;
			}
			else window.location = linkURL;		
		break;
		case 1: // New Window
			if(disclaimerFlag == 1) {
				if(confirm(linkDisclaimer)) { //window.open(linkURL);
					// Try to open a new window using the passed address
					oWin = window.open(linkURL,"newWindow");
					// Check to see if the new window was blocked by a popup blocker
					if (oWin === null || typeof(oWin) === "undefined") {
						// If the new window was blocked, set the location of the current window to the passed address
						window.location = linkURL;
					}
				}
			} else { //window.open(linkURL);
				// Try to open a new window using the passed address
				oWin = window.open(linkURL,"newWindow");
				// Check to see if the new window was blocked by a popup blocker
				if (oWin === null || typeof(oWin) === "undefined") {
					// If the new window was blocked, set the location of the current window to the passed address
					window.location = linkURL;
				}
			}
		break;
		case 2: // Popup Window
			if(disclaimerFlag == 1) {
				if(confirm(linkDisclaimer)) window.open(linkURL,'popup','scrollbars=yes,resizable=yes,width=640,height=480');
			}
			else window.open(linkURL,'popup','scrollbars=yes,resizable=yes,width=640,height=480');
		break;
	}
}
