// JavaScript Document

function getURLParam(strParamName){
	var strReturn = "";
	var tmp = window.location.href;
	var strHref = tmp.replace(/#/ig,""); // added
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			 	}
			}
		}
		return unescape(strReturn);
	} 

function stripAnchors(str) {
	str.replace(/"#"/g,"");
	alert(str);
	return str;
	}

function setBody(theClass) {
	document.body.className = theClass;
	}

var curPage, maxPage;
function doPage(dir) {
	document.getElementById("page"+curPage).style.display = "none";
	if (dir) {
		curPage++;
		}
	else {
		curPage--;
		}
	document.getElementById("page"+curPage).style.display = "inline";
	curPage == maxPage ? showNext(0) : showNext(1);
	curPage == 0 ? showPrev(0) : showPrev(1);
	}

function showPrev(dir) {
	dir ? document.getElementById("prev").style.display = "block" : document.getElementById("prev").style.display = "none";
	}

function showNext(dir) {
	dir ? document.getElementById("next").style.display = "block" : document.getElementById("next").style.display = "none";
	}

function newWindow(myURL, myname, w, h, useScroll) {

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+useScroll+',resizable=no'
	win = window.open(myURL, myname, winprops);
	}

//================================

// Derived from Example 16-1, JavaScript: The Definitive Guide by David Flanagan.
// Copyright 2002 O'Reilly & Associates." 

// The constructor function: creates a cookie object for the specified // document, with a specified name and optional attributes.
// Arguments:
//   document: The Document object that the cookie is stored for. Required.
//   name:     A string that specifies a name for the cookie. Required.
//   hours:    An optional number that specifies the number of hours from now
//             that the cookie should expire.
//   path:     An optional string that specifies the cookie path attribute.
//   domain:   An optional string that specifies the cookie domain attribute.
//   secure:   An optional Boolean value that, if true, requests a secure cookie.
//

function Cookie(document, name, hours, path, domain, secure) {

	// All the predefined properties of this object begin with '$'
	// to distinguish them from other properties which are the values to
	// be stored in the cookie.
	this.$document = document;
	this.$name = name;
	if (hours)
		this.$expiration = new Date((new Date()).getTime() + hours*3600000);
	else this.$expiration = null;
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null;
	if (secure) this.$secure = true; else this.$secure = false;
	}


Cookie.prototype.store = function () {

	// Grab current properties. use = and & for var seps. escape all values

	var cookieval = "";
	for(var prop in this) {
	// Ignore properties with names that begin with '$' and also methods.
	if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) continue;
	if (cookieval != "") cookieval += '&';
	cookieval += prop + ':' + escape(this[prop]);
	}
	
	// Rebuild, combining old and new values
	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration) cookie += '; expires=' + this.$expiration.toGMTString();
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	if (this.$secure) cookie += '; secure';
	
	this.$document.cookie = cookie;
	}


Cookie.prototype.load = function() { 

	// First, get a list of all cookies that pertain to this document.
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;
	
	// Now extract just the named cookie from that list.
	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;   // Cookie not defined for this page.
	start += this.$name.length + 1;  // Skip name and equals sign.
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);
	
	// Grab the individual values
	var a = cookieval.split('&');
	for(var i=0; i < a.length; i++) a[i] = a[i].split(':');
	
	// Move values to JS Object
	for(var i = 0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
		}
	
	// We're done, so return the success code.
	return true;
	}

// This function is the remove() method of the Cookie object.
Cookie.prototype.remove = function() {

	var cookie;
	cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	
	this.$document.cookie = cookie;
	}

