/* --------------------------------------------------
Site:     Coppermark Bank (www.coppermarkbank.com)
Author:   Bryan Sullivan
Version:  July 18, 2007
-------------------------------------------------- */

/* =Onload Functions
-------------------------------------------------- */
function addLoadEvent(func) {
	var 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();
		};
	}
}

/* =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;
      };
    }
		if (links[i].className.match("changeState")) {
      links[i].onclick = function() {
				removeCookie();
				return false;
			};
    }
  }
}
addLoadEvent(windowFunctions);

/* =Disclaimers
----------------------------------------------- */
function mailConfirm(passedAddress) {
	if (confirm("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.) We cannot address account related or personal information through non-secure email. If you have an issue regarding your account, please contact us at 800-942-2930,  send your inquiry by using our web site Contact Us form or send a secure message via your Coppermark online banking message center. You may also visit one of our Coppermark banking locations.")) {
		window.location.href = passedAddress;
	}
}

function disclaimer(passedWebsite) {
	var oWin;
	if (confirm("You are leaving the Coppermark Bank web site. Please be advised that Coppermark Bank makes no endorsements or recommendations of the web site or its contents and disclaims any responsibility for actions or transactions on this site. Be aware that the privacy policy of the linked web site is not that of Coppermark Bank.")) {
		oWin = window.open(passedWebsite,"newWindow");
		if (oWin === null || typeof(oWin) === "undefined") {
			window.location.href = passedWebsite;
		} else {
			return true;
		}
	}
}

/* =Login Form Functions
----------------------------------------------- */
function focusOnLogin() {
	if (!document.getElementById || !document.getElementById("id")) { return false; }
	var username = document.getElementById("id");
	username.focus();
}
//addLoadEvent(focusOnLogin);


/* =Helpful Links Menu
----------------------------------------------- */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) { selObj.selectedIndex=0; }
}


/* =Show/Hide - Generic Functions
----------------------------------------------- */
function changeDisplayProperty(elem) {
	if (elem.style.display === "" || elem.style.display === "block") {
		elem.style.display = "none";
	} else {
		elem.style.display = "block";
	}
}
function getNextElement(node) {
	if (node.nodeType === 1) {
		return node;
	}
	if (node.nextSibling) {
		return getNextElement(node.nextSibling);
	}
	return null;
}

/* =Show/Hide - Secondary Pages, Toggle Style
----------------------------------------------- */
function createSecondaryShowHideEvent() {
	if (!document.getElementsByTagName || !document.getElementById || !document.getElementById("sub-content")) { return false; }
	var container, content, header, currentHeader, elem, i, j;
	container = document.getElementById("sub-content");
	content = container.getElementsByTagName("dd");
	for (i = 0; i < content.length; i++) {
		content[i].style.display = "none";
	}
	header = container.getElementsByTagName("dt");
	for (i = 0; i < header.length; i++) {
		currentHeader = header[i];
		currentHeader.onclick = function () {
			elem = getNextElement(this.nextSibling);
			if (elem.style.display === "" || elem.style.display === "block") {
				elem.style.display = "none";
				this.className = "";
			} else {
				elem.style.display = "block";
				this.className = "selected";
			}
			return false;
		};
	}
}

/* =Show/Hide - FAQs, Toggle Style
----------------------------------------------- */
function createFAQShowHideEvent () {
	if (!document.getElementsByTagName) { return false; }
	var container, content, header, elem, i, j, k;
	container = document.getElementsByTagName("dl");
	for (i=0; i < container.length; i++) {
		if (container[i].className.match("faq-container")) {
			content = container[i].getElementsByTagName("dd");
			header = container[i].getElementsByTagName("dt");
			for (j = 0; j < content.length; j++) {
				content[j].style.display = "none";
			}
			for (k = 0; k < header.length; k++) {
				header[k].onclick = function () {
					elem = getNextElement(this.nextSibling);
					if (elem.style.display === "" || elem.style.display === "block") {
						elem.style.display = "none";
						this.className = "";
					} else {
						elem.style.display = "block";
						this.className = "selected";
					}
					return false;
				};
			}
		}
	}
}

/* =Show/Hide - FAQs, Replacement Style
----------------------------------------------- */
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)!
	if (!document.getElementById) { return false; }
	var typeFlag, n;
	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 = "bulletPlusListMtxTd";
					break;
				default:
					document.getElementById("linkObject" + n).className = "bulletPlusListMtxTd";
			}
			document.getElementById("displayObject" + n).className = "hideObject";
		} else {
			document.getElementById("linkObject" + n).className = "hideObject";
			document.getElementById("displayObject" + n).className = "bulletListMtxTdNone";
		}
	}
	return;
}

function toggleShowAllVisibility(id) {
	if (!document.getElementById) { return false; }
	var linkObject, displayObject;
	linkObject = document.getElementById("linkObject" + id);
	displayObject = document.getElementById("displayObject" + id);
	if(linkObject.className === "bulletPlusListMtxTd") {
		linkObject.className = "hideObject";
		displayObject.className = "bulletListMtxTdNone";	
	} else {
		linkObject.className = "bulletPlusListMtxTd";
		displayObject.className = "hideObject";	
	}
	return;
}

/* =Show/Hide - Matrix
----------------------------------------------- */
function toggleMoreInfo(id) {
	if (!document.getElementById) { return false; }
	var objMoreInfo, objLinkText, objRowHighlight;
	objMoreInfo = document.getElementById("moreInfo" + id);
	if (objMoreInfo.className === "hide-info") {
		eval("objectFlag" + id + " = 1;");
		objMoreInfo.className = "show-info";
		objLinkText = document.getElementById("linkText" + id);
		objLinkText.innerHTML = "Hide&laquo;";
		objRowHighlight = document.getElementById("productRowHighlight" + id);
		objRowHighlight.style.background = "#F4F5F5";
	}
	else {
		eval("objectFlag" + id + " = 0;");
		objMoreInfo.className = "hide-info";
		objLinkText = document.getElementById("linkText" + id);
		objLinkText.innerHTML = "More&raquo;";
		objRowHighlight = document.getElementById("productRowHighlight" + id);
		objRowHighlight.style.background = "";
	}
}
/* =Show/Hide - Matrix (Blue)
----------------------------------------------- */
function toggleMoreInfoLite(id) {
	if (!document.getElementById) { return false; }
	var objMoreInfo, objLinkText, objRowHighlight;
	objMoreInfo = document.getElementById("moreInfo" + id);
	if (objMoreInfo.className === "hide-info") {
		eval("objectFlag" + id + " = 1;");
		objMoreInfo.className = "show-info";
		objLinkText = document.getElementById("linkText" + id);
		objLinkText.innerHTML = "Hide&laquo;";
	}
	else {
		eval("objectFlag" + id + " = 0;");
		objMoreInfo.className = "hide-info";
		objLinkText = document.getElementById("linkText" + id);
		objLinkText.innerHTML = "More&raquo;";
	}
}

/* =AJAX Functions
----------------------------------------------- */
var net=new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;
//net.ContentLoader=function(url,onload,onerror){
net.ContentLoader=function(url,onerror){
	this.url=url;
	this.req=null;
	//this.onload=onload;
	this.onerror=(onerror) ? onerror:this.defaultError;
	this.loadXMLDoc(url);
}
net.ContentLoader.prototype={
	loadXMLDoc:function(url){
		if (window.XMLHttpRequest){
			this.req=new XMLHttpRequest();
		} else if (window.ActiveXObject){
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.req){
			try{
				var loader=this;
				this.req.onreadystatechange=function(){
					loader.onReadyState.call(loader);
				}
				this.req.open('GET',url,true);
				this.req.send(null);
			}catch (err){
				this.onerror.call(this);
			}	
		}
	},
	onReadyState:function(){
		var req=this.req;
		var ready=req.readyState;
		if (ready==net.READY_STATE_COMPLETE) {
			var httpStatus=req.status;
			if(httpStatus==200 || httpStatus==0) {
				//successful
				//this.onload.call(this);
			}else {
				this.onerror.call(this);
			}
		}
	},
	defaultError:function(){
		/*
		alert("Error Retrieving Data!"
			+"\n\nurl: " +this.url
			+"\n\nreadyState: " +this.req.readyState
			+"\n\nstatus: " +this.req.status
			+"\n\nheaders: " +this.req.getAllResponseHeaders()); 
		
		alert("Error Retrieving Data!"
			+"\n\nurl: " +this.url
			+"\n\nreadyState: " +this.req.readyState); 
		*/
	}
}
function removeCookie(){
	createSession(0);
	window.location = 'default.cfm';
	//var objID = setTimeout("window.location = 'default.cfm';", 300);
}

/* =Flash Functions
----------------------------------------------- */
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
function evalLink(linkURL,linkTarget,disclaimerFlag,disclaimerText) {
	var regexp = /&quote;/g;
	disclaimerText = disclaimerText.replace(regexp,"\"");
	switch(linkTarget) {
		case 0: //Same window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) window.location = linkURL;
			}
			else window.location = linkURL;		
		break;
		case 1: // New Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) window.open(linkURL);
			}
			else window.open(linkURL);		
		break;
		case 2: // Popup Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) void myOpen(linkURL,500,500);
			}
			else void myOpen(linkURL,500,500);
		break;
	}
}
function evalCustomLink(linkURL,linkTarget,disclaimerFlag,disclaimerText) {
	var regexp = /&quote;/g;
	disclaimerText = disclaimerText.replace(regexp,"\"");
	switch(linkTarget) {
		case 0: //Same window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) window.location = linkURL;
			}
			else window.location = linkURL;		
		break;
		case 1: // New Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) window.open(linkURL);
			}
			else window.open(linkURL);		
		break;
		case 2: // Popup Window
			if(disclaimerFlag == 1) {
				if(confirm(disclaimerText)) void myOpen(linkURL,500,500);
			}
			else void myOpen(linkURL,500,500);
		break;
	}			
}
function myOpen(page,width,height) {
	 if (navigator.appName == 'Netscape') {
		  adjWidth = width+10;
		  adjHeight = height+10;
	 } else {
		  adjWidth = width;
		  adjHeight = height;
	 }
	 window.open(page,'windowName','width=' + adjWidth + ',height=' + adjHeight + ',toolbar=no,location=no,directories=no,resizable=yes,status=yes,menubar=yes,scrollbars=yes');
}
function processLink(targetSelect){
	eval(targetSelect[targetSelect.selectedIndex].value);
}