// Planet Ranger Global JavaScript Functions 0611071724

// Global vars

	var siteDomainLocal = "www.planetranger.localhost";
	var siteDomainSite = "www.planetranger.com";
	var errorScriptLoc = "/site/cgi-bin/general/show_error.cgi";
	
	// redirect to www domain
	var theHost = window.location.hostname;
	var thePath = window.location.pathname;
	var theSearch = window.location.search;
	if (theHost == 'planetranger.com')
	{
		location.replace('http://' + siteDomainSite + thePath + theSearch);
	}

// _PR_start_export_code_

	var exportFlag = true;
	
	var thisBrowser = "microsoft";
	if (navigator.appName.search(/netscape/i) != -1)
	{
		thisBrowser="netscape";
	}
	else if (navigator.appName.search(/AppleWebKit/i) != -1)
	{
		thisBrowser="safari";
	}
	else if (navigator.appName.search(/firefox/i) != -1)
	{
		thisBrowser="firefox";
	}
	var PRwindowObj;
	var undefined;
	PRwindowOpenCall = false;
	
// Window functions

	// Open a new window - broswer independant-ish
	function PRopenWindow(myTitle, myUrl, myWidth, myHeight, xPos, yPos, myFeatures)
	{
		if (myUrl == '#')
		{
			return false;
		}
		PRwindowOpenCall = true;
		if (myWidth > screen.availWidth)
		{
			myWidth = screen.availWidth;
		}
		if (myHeight > screen.availHeight)
		{
			myHeight = screen.availHeight;
		}
		myFeatures = myFeatures + ", height=" + myHeight + ", width=" + myWidth;
		
		if (thisBrowser == "netscape")
		{
			myFeatures = myFeatures + ", screenX=" + xPos + ", screenY=" + yPos;
		}
		else
		{
			myFeatures = myFeatures + ", left=" + xPos + ", top=" + yPos;
		}
			
		PRwindowObj = window.open(myUrl, myTitle, myFeatures);
		if (PRwindowObj)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	// Open a help window
	
	function PRopenHelpWindow(address)
	{
		var newWidth = 400;
		var newHeight = 500;
		var xPos = 50;
		var yPos = 15;
	
		var winFeatures = "resizable=yes, scrollbars=yes, toolbar=no, channelmode=no, menubar=no, location=no";
		return PRopenWindow("Help", address, newWidth, newHeight, xPos, yPos, winFeatures);
	}

	// GL functions and code
	function newImage(arg) {
		if (document.images) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}
	}
	userAgent = window.navigator.userAgent;
	browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
	mustInitImg = true;
	function initImgID() {var di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}
	function findElement(n,ly) {
		var d = document;
		if (browserVers < 4)		return d[n];
		if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
		var cd = ly ? ly.document : d;
		var elem = cd[n];
		if (!elem) {
			for (var i=0;i<cd.layers.length;i++) {
				elem = findElement(n,cd.layers[i]);
				if (elem) return elem;
			}
		}
		return elem;
	}
	function changeImagesArray(array) {
		if (preloadFlag == true) {
			var d = document; var img;
			for (i=0;i<array.length;i+=2) {
				img = null; var n = array[i];
				if (d.images) {
					if (d.layers) {img = findElement(n,0);}
					else {img = d.images[n];}
				}
				if (!img && d.getElementById) {img = d.getElementById(n);}
				if (!img && d.getElementsByName) {
					var elms = d.getElementsByName(n);
					if (elms) {
						for (j=0;j<elms.length;j++) {
							if (elms[j].src) {img = elms[j]; break;}
						}
					}
				}
				if (img) {img.src = array[i+1];}
			}
		}
	}
	function changeImages() {
		changeImagesArray(changeImages.arguments);
	}

// _PR_end_export_code_
	exportFlag = false;
	
// Path Interpretation functions

	function GetUserFromPath()
	{
		// Function to extract the username from the path
		// returns username
		// returns "_none_" on fail
		var theHost = window.location.hostname;
		var thePath = window.location.pathname;
		
		// check hostname is correct
		if ((theHost == siteDomainLocal) || (theHost == siteDomainSite))
		{
			var pathItems = thePath.split("/")
			var theUsername = pathItems[1];
			theUsername = theUsername.toLowerCase();
			// validate local
			var illegals = theUsername;
			illegals = illegals.replace(/[a-zA-Z_0-9\&\-]+/, "");
			if ((illegals.length > 0) || (theUsername.length < 3))
			{
				return "_none_";
			}
			else
			{
				return theUsername;
			}
		}
		else
		{
			return "_none_";
		}
	}

// Cookie Functions

	// Cookie class constructor
	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 store function
	Cookie.prototype.store = function ()
	{    
		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]);
		}
	
		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 Load function
	Cookie.prototype.load = function()
	{ 
	
		var allcookies = this.$document.cookie;
		if (allcookies == "") return false;
	
		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);
	
		var a = cookieval.split('+');    // Break it into array of name/value pairs.
		for(var i=0; i < a.length; i++)  // Break each pair into an array.
			a[i] = a[i].split('|');
	
		for(var i = 0; i < a.length; i++) {
			this[a[i][0]] = unescape(a[i][1]);
		}
	
		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;
	}

// Setup Functions

	// Check that Browser is compatible
	
	function browserOkay()
	{
		if ((navigator.cookieEnabled) || (document.cookie == ""))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

// Get cookies or create
// See if we can
var cookieFlag = 0;
var PRtest = new Cookie(document, "PRtest", null, "/", theHost);
PRtest.testval = 1;
if (!PRtest.load())
{
	PRtest.store();
}
if (document.cookie.indexOf('PRtest') != -1)
{
	cookieFlag = 1;
}

var PRcookie = new Cookie(document, "PRsession", null, "/", theHost);
PRcookie.load();

var PRenv = new Cookie(document, "PRenv", null, "/", theHost);
PRenv.load();