
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE LOCATION: /2008_templates/scripts/global.js
DESCRIPTION: Globally used functions and variables
DATE of LAST EDIT: August 28, 2008 
CHANGE LOG: 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//Find the root folder of the current site and saves it to the sSiteRoot variable
var sSiteRoot = new String();
setPath();
function setPath() {
	var sLinkHref = document.getElementById("mainCSS").getAttribute("href");
	var sPathToRoot = sLinkHref.substring(0,sLinkHref.indexOf("2008_templates"));
	var sLocHref = location.href.substring(0,location.href.lastIndexOf("/")+1);
	sSiteRoot = sLocHref + sPathToRoot;
}


//Generic Cookie Code
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	//alert(name+"="+value+expires+"; path=/");
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==" ") c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

//========================================================================
/* Open external links or PDFs in a fixed size window positioned in the top left of screen - script written by Kris Clarke - GPEB
 *
 * This function opens the specified URL in a new browser window. The size and location of the window can be altered
 * by changing the code below. By specifying the size of the new browser window within this file, new windows will
 * open to a consistent size for any links that make use of this function.
 *
 * The number of child windows for each parent window is limited to one. When a user clicks on an external or PDF link
 * in the parent page a new window is opened. For any subsequent external or PDF link clicks from the parent page, where
 * the child window is still open, the page or PDF will be opened in the existing child window. This functionality keeps
 * new windows under control to limit confusion for the user.
 *
 * Note: "| 0" at the end of the var statements truncates the calculated values to integers.
 *
 * The syntax for calling this function in the in an html document is as follows:
 *
 * <a href="http://www.google.ca" target="_blank" onClick="openNewWindow(this.href); return false">Google Canada</a>
 */
//========================================================================
 
function openNewWindow(url) {
	var newWindowWidth = 780;
	var newWindowHeight = (screen.availHeight * 0.6) | 0;
	var newWindowLeftPos = 0;
	var newWindowTopPos = 0;
	var newWindowArgs = "toolbar=yes, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes";

	// For small screens use 100% window width.
	if(screen.availWidth < 780) {
		newWindowWidth = screen.availWidth;
	}

// Follow this branch if: A child window object (newWin) does not exist nor has one been created since the parent window was opened.		
	if(typeof(newWin) != "object") {
		newWindowArgs = newWindowArgs + ", width=" + newWindowWidth + ", height=" + newWindowHeight + ", left=" + newWindowLeftPos + ", top=" + newWindowTopPos;
		newWin = window.open(url, "_blank", newWindowArgs);
		/*alert(newWindowArgs); //shows values of 'newWindowArgs' for testing purposes*/
	}

	// Follow this branch if: A child window object (newWin) does exist or has been created since the parent window was opened.
	else {
		// Follow this sub-branch if: A child window is currently open.
		if(!newWin.closed) {
			newWin.location.href=url;
		}
		// Follow this sub-branch if: A child window is not currently open.
		else {
			newWindowArgs = newWindowArgs + ", width=" + newWindowWidth + ", height=" + newWindowHeight + ", left=" + newWindowLeftPos + ", top=" + newWindowTopPos;
			newWin = window.open(url, "_blank", newWindowArgs);
			/*alert(newWindowArgs); //shows values of 'newWindowArgs' for testing purposes*/
		}
	}
	newWin.focus();
}
//-->