//Copyright Steve Holt 2005  - contact via http://www.clockbeat.com

/*
If you wish to use this code in your own web site you must:
	Contact Steve (see above) and let him know where you are using it and how
	Provide a link on your site back to http://www.clockbeat.com
	Leave all these comments in place
	Not modify the code (contact Steve if you want to do that)
*/

function getOuterHTML(el) {
	if (el.outerHTML)
		return el.outerHTML;
	var result = "<" + el.tagName + " ";
	for (var i = 0; i < el.attributes.length; i++) {
		var att = el.attributes[i];
		result += att.name + "=\"" + att.value + "\" ";
	}
	if (el.hasChildNodes()) {
		result += ">" + el.innerHTML + "</" + el.tagName + ">";
	} else {
		result += "/>";
	}
	return result;
}

function report(str) {
	return;
	var parts = str.toString().split('\n');
	for (var i = 0; i < parts.length; i++) {
		document.body.appendChild(document.createTextNode(parts[i]));
		document.body.appendChild(document.createElement("BR"));
	}
}

function addEvent(el, name, func) {
	if (el.addEventListener) {
		el.addEventListener(name, func, false);
	} else {
		el.detachEvent("on" + name, func);
		el.attachEvent("on" + name, func);
	}
}

function findParentByTagName(element, tagName)
{
	if (element.parentNode == null) {
		return null;
	}
	if (element.parentNode.tagName == tagName.toUpperCase()) {
		return element.parentNode;
	} else {
		return findParentByTagName(element.parentNode, tagName);
	}
}

function findParentByClass(element, className)
{
	var re = new RegExp("\\b" + className + "\\b");
	if (element.parentNode == null) {
		return null;
	}
	if (element.parentNode.className.match(re)) {
		return element.parentNode;
	} else {
		return findParentByClass(element.parentNode, className);
	}
}

function rgb(r, g, b) {
	var colar = new Object();
	colar["R"] = parseInt(r);
	colar["G"] = parseInt(g);
	colar["B"] = parseInt(b);
	return colar;
}

function modifyColor(color, type, change) {
	if (color == "")
		return;
	var colar = new Object();
	if (color.substr(0, 1) == "#") {
		colar["R"] = parseint(color.substr(1, 2), 16);
		colar["G"] = parseint(color.substr(3, 2), 16);
		colar["B"] = parseint(color.substr(5, 2), 16);
	}
	if (color.substr(0, 4) == "rgb(") {
		colar = eval(color);
	}
	if (type == "bright") {
		if (change > 0) {
			colar["R"] += Math.floor(((255 - colar["R"]) * change) / 100);
			colar["G"] += Math.floor(((255 - colar["G"]) * change) / 100);
			colar["B"] += Math.floor(((255 - colar["B"]) * change) / 100);
		} else {
			colar["R"] += Math.floor((colar["R"] * change) / 100);
			colar["G"] += Math.floor((colar["G"] * change) / 100);
			colar["B"] += Math.floor((colar["B"] * change) / 100);
		}
	} else if (type == "sat") {
		var lowest = "R";
		if (colar["G"] < colar[lowest])
			lowest = "G";
		if (colar["B"] < colar[lowest])
			lowest = "B";
		colar[lowest] -= Math.floor((colar[lowest] * change) / 100);
	}
	return "rgb(" + colar["R"] + "," + colar["G"] + "," + colar["B"] + ");";
}

function makeElement(type, parent, text, id, style, events) {
		var el = document.createElement(type);
		parent.appendChild(el);
		if (text) {
			if (el.textContent != null)
				el.textContent = text;
			else
				el.innerText = text;
		}
		if (id)
			el.id = id;
		if (style)
			el.style.cssText = style;
		if (events)
			for (var e in events) {
				var newfunc = stringToEvent(events[e]);
				el[e] = newfunc;
			}
		return el;
	}

function stringToEvent(evString) {
	return eval(((window.event) ? "function x() { " : "function x(event) { ") + evString + "};x;");
}

//addEvent(window, "load", applyScripts);



