var liveDomain = 'apcifcu';
function getDomain(s)
{
	//if has http, strip
	if (s.indexOf('http://') == 0)
	{
		s = s.substring( 7 )
	}
	else if (s.indexOf('https://') == 0)
	{
		s = s.substring( 8 )
	}
	
	if ( s.indexOf('/') > -1)
	{
		s = s.substring(0, s.indexOf('/') );
	}
	
	var a = s.split('.');
	a.unshift(s);
	return a;
}
function wireExternalLinks()
{
	//on domready loop through a tags
    var a = document.getElementsByTagName('a');
    var i = 0;
    var len = a.length;
    var href;
	var domain;
	var thisDomain = getDomain(window.location.href);
    for(i=0; i<len; i++)
    {
		//external must have http and not be current domain
        href = a[i].href;
		if (href.indexOf('http://') == 0 || href.indexOf('https://') == 0)
		{
			if ( isNotSameDomain( getDomain(href), thisDomain) )
			{
				listen('click', a[i], onClickExternalLink);
			}
		}
    }
}
function isNotSameDomain(d1, d2)
{
	return (d1[0] != d2[0] && d1[2] != d2[2] && d1[2] != liveDomain)
}
function onClickExternalLink(e)
{
	var proceed = window.confirm("Please be advised that you are leaving the APCI Federal Credit Union site to access information through a third party provider. APCI Federal Credit Union assumes no liability for this website content, products, privacy policies, security, external links, nor for any third party content residing on www.apcifcu.com. APCI Federal Credit Union makes no warranty or representations as to the accuracy, reliability or quality of this service. These links are provided as a convenience only. Please review the privacy statement of the website before you provide any personal or confidential information.");
	
	if (!proceed)
	{
		if (e.preventDefault) 
		{
			//alert('ep');
			e.preventDefault();
		}
		if (e.stopPropagation) 
		{
			//alert('esp');
			e.stopPropagation();
		}
	}
	return proceed;

}
function listen(evnt, elem, func) 
{
	if (elem.addEventListener) // W3C DOM
	{
		elem.addEventListener(evnt,func,false);
	}
	else if (elem.attachEvent) 
	{ // IE DOM
		var r = elem.attachEvent("on"+evnt, func);
		return r;
	}
	else window.alert('browser is not supported');

}
//
function preventSecondaryClickOnLogo()
{
	//find logo
	
	//on domready loop through a tags
    var imgs = document.getElementsByTagName('img');
    var i = 0;
    var len = imgs.length;
    var src;
	
    for(i=0; i<len; i++)
    {
		//external must have http and not be current domain
        src = imgs[i].src;
		if (src.indexOf('apci/home_top') > -1 )
		{
			preventSecondaryClick(imgs[i]);
		}
    }
}

function preventSecondaryClick(el)
{
	if (document.layers) 
	{
		el.captureEvents(Event.MOUSEDOWN); //?
		//el.onmousedown=clickNS;
		listen('mousedown', el, clickNS);
	}
	else
	{
		//el.onmouseup = clickNS;
		listen('mousedown', el, clickNS);
		//el.oncontextmenu = clickIE;
		listen('contextmenu', el, clickIE);
	}

	el.oncontextmenu = new Function("return false");
}
function onContextMenuLogo()
{
	if (document.all) {return false;}
	return false;
}
function onDownLogo(e)
{

	if (document.all) {return false;}
	if (e.button == 2)
	{
		
		if (e.preventDefault) 
		{
			//alert('ep');
			e.preventDefault();
		}
		if (e.stopPropagation) 
		{
			//alert('esp');
			e.stopPropagation();
		}
		return false;
	}
}

function clickIE() 
{
	if (document.all) {return false;}
}
function clickNS(e) 
{
	if (document.layers || (document.getElementById && !document.all) ) 
	{
		if (e.which==2 || e.which==3) 
		{
			return false;
		}
	}
}


DomReady.ready( wireExternalLinks );
DomReady.ready( preventSecondaryClickOnLogo );
