/*	---------------------------------------------------------------------	
	FUNCTION NAME: externalLinks

	PURPOSE: Finds any <A> tag and looks to see if it has a rel="external".
	If so, it adds the "target" attribute with a value of "_blank".  In
	this way, you have valid XHTML code.
---------------------------------------------------------------------	*/
/* AUDIT 20101006 BK: global use */
function externalLinks() {
 if (document.getElementsByTagName) {
		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") {
				anchor.target = "_blank";
			}
		}
		
		//	Also need to get areas from an image map
		var anchors = document.getElementsByTagName("area");
		for (var i = 0; i < anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
		}
	}
}

/*	---------------------------------------------------------------------
	FUNCTION NAME: addLoadEvent
	
	PURPOSE: Allows for multiple statements with for simulated onload
	events.  Should replace window.onload events, but will catch one
	provided window.onload appears before this.
---------------------------------------------------------------------	*/
/* AUDIT 20101006 BK: specific use:

books/choir-boats.php
books/tel-aviv-dossier.php
includes/common/header.php
includes/order-form-header.php
scripts/all-pages.js

*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

/*	---------------------------------------------------------------------
FUNCTION NAME: setRightPanelImgs
	
PURPOSE: Sets up rollover events in the left side navigation to change
the background image of div#right-panel by setting its class.
---------------------------------------------------------------------	*/
/* AUDIT 20101006 BK: not in use */
function setRightPanelImgs() {
 if(document.getElementById && document.getElementById('side-nav')) {
    var linksArray = document.getElementById('side-nav').getElementsByTagName("a");
    for (var i = linksArray.length - 1; i > -1; i--) {
        linksArray[i].onmouseover = function() {
            document.getElementById('right-panel').className = "rightPane-" + this.className;
        }
        linksArray[i].onmouseout = function() {
            document.getElementById('right-panel').className = "rightPane-no-img";
        }
    }
 }
}


/*	---------------------------------------------------------------------
	FUNCTION NAME: preLoadNav
	
	PURPOSE: Standard preloader -- send absolute URL of the iamges and
	the function does the rest.
---------------------------------------------------------------------	*/
/* AUDIT 20101006 BK: rollover preloads:

/books/choir-boats.php:120:  pr
/includes/order-form-header.php

*/
function preLoadNav() {
	var preLoadHolder = new Array(arguments.length);
	for (var i = 0; i < arguments.length; i++) {
		preLoadHolder[i] = new Image();
		preLoadHolder[i].src = arguments[i];
	}
}

/* AUDIT 20101006 BK: not in use.  Variant on /books/horror-story.php */
function popUp(sURL, theWidth, theHeight) {
	var aURL = sURL.split("/");
	var tempWinName = aURL[aURL.length-1];
	
	var aWinName = tempWinName.split("-");
	var sWinName;
	for (var a = 0; a < aWinName.length; a++) {
		sWinName += aWinName[a];
	}
	
	sWinName = sWinName.substring(0,sWinName.indexOf("."));

	var winHeight = theHeight;
	var winWidth = theWidth;

	var iPageWidth, iPageHeight;
	if (self.innerHeight) {
		iPageWidth = self.innerWidth;
		iPageHeight = self.innerHeight;
	}
	else if (document.all && document.getElementById) {
		iPageWidth = screen.availWidth;
		iPageHeight = screen.availHeight;
	}
	else if (document.body) {
		iPageWidth = document.body.clientWidth;
		iPageHeight = document.body.clientHeight;
	}
	leftSideOfPopup = (iPageWidth - winWidth)/2;
	topSideOfPopup = (iPageHeight - winHeight)/2;
	features = "toolbar=0,width=" + winWidth + ",height=" + winHeight + ",status=0,scrollbars=0,resize=0,menubar=0,location=0,directories=0,screenX=" + leftSideOfPopup + ",left=" + leftSideOfPopup + ",screenY=" + topSideOfPopup + ",top=" + topSideOfPopup;    <!-- One line and no spaces  -->
	theWindow = window.open(sURL, sWinName, features); 
	theWindow.focus();
}

