/* =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 = window.onload;
  if (typeof window.onload !== 'function') {
    window.onload = func;
  } else {
    window.onload = function () {
      oldonload();
      func();
    };
  }
}

/* =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("mainNav");
	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() {
				linkConfirm(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 = "This email message may not be protected by a secure server.  Community Bank cannot address account-related or personal information via unsecured email. Please do not disclose any personal information (i.e. Social Security numbers, account numbers, ATM or EZ Check card numbers, dates of birth) in your email correspondence. For account-related questions, please use our secure Contact Us Form, phone or visit your local Community Bank branch, or call 877-636-7492. We will gladly assist you.";

var linkDisclaimer = "By clicking on this link, you leave the Community Bank web site and enter a web site created, operated, maintained and owned by another business. The privacy policies and security standards of the Web site you are entering are not those of Community Bank. Be advised that Community Bank makes no endorsements or recommendations of this site, nor can we guarantee the accuracy, completeness or timeliness of the information provided.";

function mailConfirm(passedAddress) {
	if (confirm(emailDisclaimer)) {
		window.location.href = passedAddress;
	}
}

function linkConfirm(passedWebsite) {
	var oWin;
	if (confirm(linkDisclaimer)) {
		oWin = window.open(passedWebsite,"newWindow");
		if (oWin === null || typeof(oWin) === "undefined") {
			window.location.href = passedWebsite;
		} else {
			return true;
		}
	}
}

//eval link function
function evalLink(linkURL,linkTarget,disclaimerFlag) {
  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);
			}
			else window.open(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;
	}
}

/* =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;
}