/****************************************
*
* www.johnkeller.com
*
* dom_tools.js
* created by John Keller
*
* Copyright (c) 2002, 2004
* No portion of this code may be used or redistributed without
* the express written permission of the author (John Keller).
*
* Info:
* document object model abstraction toolkit, with a couple of cookie functions
*
****************************************/


// browser detection variables
var _dom = (document.getElementById ? true : false);
var _dom2 = (window.getComputedStyle ? true : false);
var _ie = (document.all ? true : false);
var _mac = (navigator.appVersion.indexOf("Mac") != -1);

var _ie4 = (_ie && !_dom);
var _ie5 = (_ie && !_dom2);
var _ie4mac = (_ie4 && _mac);
var _ns4 = (document.layers ? true : false);

// returns a div element for a given id
function _div(id) {
	if (_dom) {
		return document.getElementById(id);
	} else if (_ie) {
		return document.all[id];
	} else if (_ns4) {
		return document.layers[id];
	}
}

// returns a style string for a given property
function _style(div, property) {
	var style = "";

	if (_ie) {
		var parts = property.split("-");
		property = parts[0];
		for (var i = 1; i < parts.length; i++) {
			property += parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1);
		}
		if (property == "float") {
			property = "cssFloat";
		}
		style = eval("div.currentStyle." + property);
	} else {
		style = window.getComputedStyle(div, null).getPropertyValue(property);
	}

	return style;
}

// returns cookie for given name
function _cookie(name) {
	var cookieValue, search;

	cookieValue = null;
	search = name + "=";

	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}

	return cookieValue;
}

// sets cookie, with optional
//  - expiration date (null means the cookie expires with the browser session)
//  - domain
//  - path (null means whole domain)
function _setCookie(name, value, expire, domain, path) {
	document.cookie = name + "=" + escape(value)
		+ ((domain) ? "; domain=" + domain : "")
		+ "; path=" + ((path) ? path : "/")
		+ ((expire) ? "; expires=" + expire.toGMTString() : "");
}

// removes cookie
function _unsetCookie(name, domain, path) {
	if (_cookie(name)) {
		_setCookie(name, "", new Date(0), domain, path);
	}
}
