/* =Helper Functions
----------------------------------------------- */
// Dreamweaver functions
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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// 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();
        };
    }
}

/* Add the ability to use getElementsByClassName, on top of getElementById and getElementsByTagName

The getElementsByClassName function has three parameters:
strClass:
    string containing the class(es) that you are looking for
strTag (optional, defaults to ‘*’):
    An optional tag name to narrow the search to specific tags e.g. ‘a’ for links.
objContElm (optional, defaults to document):
    An optional object container to search inside. Again this narrows the scope of the search

The following example will get all elements within the entire document that have a class of ‘one’.
    var myObjColl = getElementsByClassName('one');

The next example will get all ‘a’ elements (links) that have a class of ‘one’ and are found within the cont object which in these examples is an element with the id ‘container’.
    var cont = document.getElementById('container');
    var myObjColl = getElementsByClassName('one', 'a', cont);

This next example will get all ‘a’ elements (links) that have a class of ‘one’ AND ‘two’ and are found within the cont object.
    var cont = document.getElementById('container');
    var myObjColl = getElementsByClassName('one two', 'a', cont);

Finally this example will get all ’span’ elements that have a class of ‘one’ OR ‘two’ and are found within the cont object.
    var cont = document.getElementById('container');
    var myObjColl = getElementsByClassName('one|two', 'span', cont);
*/

function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;    
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();                              
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
  var arrClass = strClass.split(delim);    
  for (var i = 0, j = objColl.length; i < j; i++) {                         
    var arrObjClass = objColl[i].className.split(' ');   
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]); 
          break comparisonLoop;
        }
      }
    }
  }
  return arr; 
}

/* =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;
      };
    }
  }
}
// Add this function to the page's onload function.
addLoadEvent(windowFunctions);

/* =Disclaimers
----------------------------------------------- */
var mailConfirmText = "You have requested to send general comments, questions or suggestions via this unsecured email. However, we cannot address account-related or personal information through an unsecured email.\r\rFor your protection, please do not send any personal information (i.e. Social Security Numbers, account numbers, date of birth, etc.) If you have an issue regarding your account, please contact a customer service representative at 704-735-1104 or stop by one of our locations.";
var disclaimerText = "You are leaving Carolina Trust Bank\'s website.\r\rThis site you have chosen is independent from CTB. Please be advised that CTB makes no endorsements or recommendations of the web site or its content and disclaims any responsibility for actions or transactions on the site. CTB does not guarantee the accuracy, completeness, efficiency, or timeliness of the information contained therein.";

function mailConfirm(passedAddress) {
	if (confirm(mailConfirmText)) {
		window.location.href = passedAddress;
	}
}

function disclaimer(passedWebsite) {
	var oWin;
	if (confirm(disclaimerText)) {
		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();
}
// Add this function to the page's onload function.
addLoadEvent(focusOnLogin);


/* =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(navItem, action) {
  if (timeOut != null) {
		window.clearTimeout(timeOut);
	}
  timeOut = window.setTimeout('hideMenuObjects()',250);
}

function hideNav(navItem, action) {
  MM_showHideLayers(navItem,'',action);
}
function hideMenuObjects(){
	menuObj = document.getElementById("nav_main");
	menus = menuObj.getElementsByTagName("div");
	for ( n = 0; n < menus.length; n++) {
		menus[n].style.visibility = "hidden";
	}
}

/* =Matrix Functions
----------------------------------------------- */
// Hide all More info table rows when the page loads. This is done for compatibility with javascript disabled.
function hideMoreInfo() {
	if (!document.getElementsByTagName) { return false; }
	var moreInfoList, i;
	// Get all elements with the class name of moreInfo.
	var moreInfoList = getElementsByClassName('moreInfo');
	// Loop through the list of elments and change their display to none.
  for (i = 0; i < moreInfoList.length; i++) {
    if (moreInfoList[i].style.display !== "none") {
      moreInfoList[i].style.display = "none";
     }
   }
}
// Add this function to the page's onload function.
addLoadEvent(hideMoreInfo);

// Toggle the More info table rows within the matrix table.
function toggleMoreInfo(id) {
	// Can the browser handle this function?
	if (!document.getElementById) { return false; }
	// if the current More info row is currently hidden, then make it visible and change the link text.
	if (document.getElementById("moreInfo" + id).className == "hideMoreInfo") {
		document.getElementById("moreInfo" + id).className = "showMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "Hide&laquo;";
	} else {
		// Otherwise, hide it and change the link text back.
		document.getElementById("moreInfo" + id).className = "hideMoreInfo";
		document.getElementById("linkText" + id).innerHTML = "More&raquo;";
	}
}

/* =FAQ Functions
-------------------------------------------------- */
// Change the display of the current question/answer pair. You pass the current question and it's answer to this function.
function toggleFAQs(question,nextAnswer) {
	// If the answer is already showing, then make it hide and change the font style of the question by changing it's class name.
	if (nextAnswer.style.display == "" || nextAnswer.style.display == "block") {
		// Make the magic happen.
		nextAnswer.style.display = "none";
		question.className = "hide_question";
	} else {
		// If the answer is hidden, then make it show and change the font style of the question by changing it's class name.
		nextAnswer.style.display = "block";
		question.className = "";
	}
}

// Get the sibling of the current element. Imaginative name, huh?
function getNextElement(node) {
	// Check the nodeType. If it's an element (1), we're done! Then return the value.
	if (node.nodeType == 1) {
		return node;
	}
	// If it isn't an element, run again until we get an element.Then return the value.
	if (node.nextSibling) {
		return getNextElement(node.nextSibling);
	}
	return null;
}

// Initialize the FAQ show/hide code.
function initFAQs() {
	// Can the browser handle this function and does #faq_section exist?
	if (!document.getElementsByTagName || !document.getElementById || !document.getElementById("faq_section")) return false;
	// Declare the variables.
	var faqs, answers, i, questions, elem;
	faqs = document.getElementById("faq_section");
	// Change class name of all questions. This is done for compatibility with javascript disabled.
	questions = faqs.getElementsByTagName("dt");
	for (i=0; i<questions.length; i++) {
		questions[i].className = "hide_question";
	}
	// Change display to none for all answers. This is done for compatibility with javascript disabled.
	answers = faqs.getElementsByTagName("dd");
	for (i=0; i<answers.length; i++) {
		answers[i].style.display = "none";
	}
	// Loop through all questions and add an onclick event to make the magic happen.
	for (i=0; i<questions.length; i++) {
		questions[i].onclick = function() {
			nextAnswer = getNextElement(this.nextSibling);
			toggleFAQs(this,nextAnswer);
			return false;
		}
	}
}
// Add this function to the page's onload function.
addLoadEvent(initFAQs);

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 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');
}