// JavaScript Document

// used by some leftNavs
function setMenu() {
	var cur = window.location.href;
	var curChoice;
	var tmp;
	var menuIdx = -1;
	var idx = -1;
	if ( cur.indexOf("m=") > -1) {
		curChoice = cur.substr(cur.lastIndexOf("m=")+2);
		document.getElementById(curChoice).innerHTML = '<img src="/mos/images/menutic.gif">';
		}
	}


// Returns a friendly-formatted date
function insertDate() {
	var dStr = "";
	var d = new Date();
	var wd = d.toLocaleString();
	wd = wd.substring(0, wd.indexOf(','));
	dStr = wd+", ";
	dStr += 1+d.getMonth();
	dStr += "/"+d.getDate();
	dStr += "/"+d.getFullYear();
	return dStr;
	}

// Returns a friendly-formatted time
function insertTime() {
	var t = new Date();
	var tStr = "";
	var t12;
	var tMark = "AM";
	var t00 = "0";
	t12 = t.getHours();
	if (t12 > 11) {
		if (t12 > 12)t12 -= 12;
		tMark = "PM";
		}
	else if (t12 == 0) t12 = 12;
	tStr = t12+":";
	if (t.getMinutes() < 10) tStr += t00;
	tStr += t.getMinutes();
	tStr += " "+tMark;
	return tStr;
	}

function popWin(URL, w, h) {
	aWindow = window.open(URL,'popwin','toolbar=no,status=no,menubar=no,width='+w+',height='+h+'');
	}

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

// 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;
	}
