/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

/*	Implement array.push for browsers which don't support it natively.
	Please remove this if it's already in other code */
if(Array.prototype.push == null){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){
			this[this.length] = arguments[i];
		};
		return this.length;
	};
};

/*	Event Cache uses an anonymous function to create a hidden scope chain.
	This is to prevent scoping issues. */
var EventCache = function(){
	var listEvents = [];
	
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){
			listEvents.push(arguments);
		},
	
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				
				/* From this point on we need the event names to be prefixed with 'on" */
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				
				item[0][item[1]] = null;
			};
		}
	};
}();

function openWindow(url, width, height) {

    var newWidth = width + 50;
    var newHeight = height + 50;

    var leftPos = window.screenLeft + (window.document.body.clientWidth - newWidth) / 2;
    var topPos = window.screenTop + (window.document.body.clientHeight - newHeight) / 2;

    var newWindow = window.open(url, 'popup_window', 'toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=yes,width=' + newWidth + ',height=' + newHeight + ',left=' + leftPos + ',top=' + topPos);
    newWindow.focus();

}

function confirm_delete(itemName)
{
	if (confirm('Are you sure you want to delete this ' + itemName + '?'))
	{
		return true;
	}
	else
	{
		return false;
	}

}

function showDisclaimer() {
	alert("If you use links provided on this website to other Internet sites and services, you acknowledge that Tarrant County Credit Union does not endorse those sites or services and will not be responsible or liable for their contents or any loss occasioned by any such content. Other Internet sites or services may have privacy policies or security that differ from the privacy policy or security of Tarrant County Credit Union.");
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		EventCache.add(elm, evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

function checkExternalLink(link) {

	internal = ['#', '/', '../', 'mailto', 'javascript', 'http://www.kscfcu.org', 'http://kscfcu.org', 'https://www.kscfcu.org', 'https://kscfcu.org', 'https://www.pcu.kscfcu.org/'];
	for (var i = 0; i < internal.length; i++) {
		if (link.indexOf(internal[i]) == 0) {
			return false;
		}
	}

	return true;

}

function externalLinks()
{

   if (!document.getElementsByTagName)
   {
       return;
   }

   var anchors = document.getElementsByTagName("a");

   for (var i=0; i<anchors.length; i++)
   {
       var anchor = anchors[i];

       if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || checkExternalLink(anchor.getAttribute("href"))))
       {
           anchor.setAttribute("href", "/redirect.html?site=" + anchor.getAttribute("href"));
					 anchor.target="_blank";
       }
   }
}

addEvent(window, 'load', externalLinks, false);