/* $Id: common.js 8338 2006-10-24 17:56:54Z ddamstra $ */
/* Site Framework:  Molly 1.2 */

/* add your functions to be called on page load here */
function pageInit() {
    //initLeftMenu();
    //startclock();
    addLinkDisclosure();
}

/*
   son of suckerfish menu script from:
http://www.htmldog.com/articles/suckerfish/dropdowns/
 */

sfHover = function() {
    var sfEls = document.getElementById("nav-secondary").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {
	    this.className+=" sfhover";
	    //this.style.zIndex=9999; //this line added to force flyout to be above relatively positioned stuff in IE
	}
	sfEls[i].onmouseout=function() {
	    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	    //this.style.zIndex=1; // I am beging to wonder if IE can do anything correctly
	}
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* CU*@Home Login Checks */
function loginCheck()
{
    document.login.target='_top';
    if (document.login['LoginName'].value=='' || document.login['LoginPin'].value=='')
    {alert("You need to add your username and password to log in."); return false;}
    else
    {return true;}
}

/*PopUp Functions*/
function popUp(windowLocate, winWidth, winHeight, winOptions)
{
    var poppedWin=window.open(windowLocate, "popUpWin", "scrollbars, resizable, width="+winWidth+", height="+winHeight);
    poppedWin.moveTo(((screen.width/2)-(winWidth/2)),((screen.height/2)-(winHeight/2)));
    poppedWin.focus();
}

function popUpLink(winWidth, winHeight)
{
    var poppedWin=window.open('', "popUpWin", "scrollbars, resizable, width="+winWidth+", height="+winHeight);
    with(poppedWin.document) {
	write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r\n');
	write('<html>\r\n<head>\r\n');
	write('<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">\r\n');
	write('<title>Leaving the Site</title>\r\n');
	write('<style>\r\n\tbody {margin:0; background-color:#fff; color:#000; font: .95em verdana, sans-serif;}\r\n\th1 {background-color:#0a76a8; color:#fff; margin:0 0 10px; border-bottom:2px solid #000; padding:5px 10px; font-size:1.75em;}\r\n\t#popupcontent {margin:0 10px;}\r\n\t#popupcontent p {margin:0 0 .75em;}\r\n\t.fineprint {border-top:1px solid #000; padding: .5em 0 0; font-size:85%; font-style:italic;}\r\n</style>\r\n');
	write('<sc'+'ript type="text/javascript">\r\nfunction selfDestruct() {\r\n\tvar dieWindow=setTimeout(\'this.close()\', 15000);\r\n}\r\n</sc'+'ript>\r\n');
	write('</head>\r\n');
	write('<body onLoad="selfDestruct()" id="popup" onblur="this.focus();">\r\n');
	write('<h1>Now Leaving this Site</h1>\r\n');
	write('<div id="popupcontent">\r\n');

	write('<p>You are leaving the Port City Federal Credit Union Web site.  The Web site you have selected is an external one located on another server.  The Port City Federal Credit Union has no responsibility for any external Web site.  It neither endorses the information, content, presentation, or accuracy nor makes any warranty, express or implied, regarding any external site.  Thank you for visiting the Port City Federal Credit Union Web site.</p>\r\n');

	write('<p class="fineprint">This window will close itself after 15 seconds.  We\'re sorry for the inconvenience.</p>\r\n');
	write('</div>\r\n');		
	write('</body>\r\n</html>\r\n');
	close();
    }
    poppedWin.moveTo(((screen.width/2)-(winWidth/2)),((screen.height/2)-(winHeight/2)));
    poppedWin.focus();
}



/* These functions adds a disclosure to all off site links */
var links;
var areas;	    // Added as they use image maps extensively
var linkDisclosure =	"You are leaving the Port City Federal Credit Union Web site.  The Web site you have selected is an external one located on another server.  The Port City Federal Credit Union has no responsibility for any external Web site.  It neither endorses the information, content, presentation, or accuracy nor makes any warranty, express or implied, regarding any external site.  Thank you for visiting the Port City Federal Credit Union Web site.";

function addLinkDisclosure () {
    if(!document.getElementsByTagName || !document.domain) return false; // exit if we can't do it

    var offSite = new Array;				    // For our links that lead off site
    var domain = document.domain;				// The domain of the current document
    domain = domain.replace('www.', '');		    // To make things consistant take out "www."
    var domainRegex = new RegExp(domain+"|mailto|cuanswers\.com|itsme247\.com|cuathome\.org", "i");	    // Cuz vars in /regexes/ can be sticky
    links = document.getElementsByTagName('A');		    // An array of all our page link objects
    areas = document.getElementsByTagName('area');

    for(var i=0; i<links.length; i++) {
	if(!links[i].href.match(domainRegex)) {
	    offSite.push(links[i].href);
	    links[i].target = "_blank";
	    links[i].onclick = function () {
		return window.confirm(linkDisclosure);
	    }
	}
    }

    for(var i=0; i<areas.length; i++) {
	if(!areas[i].href.match(domainRegex)) {
	    areas[i].target = "_blank";
	    areas[i].onclick = function () {
		return window.confirm(linkDisclosure);
	    }
	}
    }
}

//window.onload=addLinkDisclosure; // Only one function to run so direct assignment is ok

