////////////////////////////////////////////////////////////////////////////////
var browserType = 'unknown';
if (navigator.userAgent.match(/Opera/)) {
	browserType = 'opera';
} else if (navigator.userAgent.match(/MSIE/)) {
	browserType = 'ie';
} else if (navigator.userAgent.match(/Mozilla/)) {
	browserType = 'ns';
}

////////////////////////////////////////////////////////////////////////////////

function domGet(id)
{
	if (typeof(id) == 'object') {
		return id;
	} else {
		return document.getElementById(id);
	}
}

function domGetChild(obj, id)
{
	for (var i=0; i<obj.childNodes.length; i++) {
		var n = obj.childNodes[i];
		if (n.nodeType != 1) continue;
		if (n.id == id) return n;
		var r = domGetChild(n, id);
		if (r != false) return r;
	}
	return false;
}

function domGetBody()
{
	var tmp = document.getElementsByTagName('BODY');
	return tmp[0];
}

function domGetOffset(obj)
{
	obj = domGet(obj);
	var offset = { x:0, y:0 };
	if (obj.offsetX) return { x:obj.offsetX, y:obj.offsetY };
	while (obj) {
		offset.x += obj.offsetLeft;
		offset.y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return offset;
}

function domFireEvent(obj, name)
{
	if (browserType == 'ns') {
//		var evnt = createEventObject(); //obj.ownerDocument.createEventObject();
//		evnt.initEvent(name.slice(2), false, false);
//		obj.dispatchEvent(evnt);
/*
		if (!event) event = obj.ownerDocument.createEventObject();
		event.initEvent(name.slice(2), false, false);
		obj.dispatchEvent(event);
*/		
		if (typeof(obj[name]) == 'function') {
			obj[name]();
		} else if (obj.getAttribute(name)) {
			eval(obj.getAttribute(name));
		}
	} else {
		obj.fireEvent(name, window.event);
	}
}

function domAttachEvent(obj, name, handler)
{
	if (browserType == 'ns') {
		obj.addEventListener(name.slice(2), handler, false);
	} else {
		obj.attachEvent(name, handler);
	}
}

function domDetachEvent(obj, name, handler)
{
	if (browserType == 'ns') {
		obj.removeEventListener(name.slice(2), handler, false);
	} else {
		obj.removeEvent(name, handler);
	}
}

function domOnLoad(handler)
{
	domAttachEvent(window, 'onload', handler);
}

function domEventGetCoords()
{
	if (window.event) {
		return { x:window.event.clientX, y:window.event.clientY };
	} else {
		return { x:window.nsevent.pageX, y:window.nsevent.pageY };
	}
}

function domEventGetTarget()
{
	if (window.event) {
		return window.event.srcElement;
	} else {
		return window.nsevent.target;
	}
}

function domEventPreventDefault()
{
	if (window.event) { 
		window.event.returnValue = false; 
	} else {
		window.nsevent.preventDefault();
	}
}

function domEventCancelBubble()
{
	if (window.event) { 
		window.event.cancelBubble = true; 
	} else {
		window.nsevent.stopPropagation();
	}
}

function domGetParent(obj, tagName)
{
	if (!tagName) {
		while (obj && obj.nodeType && obj.nodeType != 1) obj = obj.parentNode;
	} else {
		while (obj && obj.tagName && obj.tagName.toLowerCase() != tagName.toLowerCase()) obj = obj.parentNode;
	}
	return obj;
}

function domGetPrevious(obj, tagName)
{
	obj = domGet(obj);
	while (true) {
		if (obj.nodeType == 1) {
			if (typeof(tagName) == 'object') {
				for (var i=0; i<tagName.length; i++) if (tagName[i].toLowerCase() == obj.tagName.toLowerCase()) return obj;
			} else if (typeof(tagName) == 'string') {
				if (tagName.toLowerCase() == obj.tagName.toLowerCase()) return obj;
			} else {
				return obj;
			}
		}
		if (obj.previousSibling) {
			obj = obj.previousSibling;
		} else if (obj.parentNode) {
			obj = obj.parentNode;
		} else {
			return null;
		}
	}
}

function domGetNext(obj, tagName)
{
	obj = domGet(obj);
	while (true) {
		if (obj.nodeType == 1) {
			if (typeof(tagName) == 'object') {
				for (var i=0; i<tagName.length; i++) if (tagName[i].toLowerCase() == obj.tagName.toLowerCase()) return obj;
			} else if (typeof(tagName) == 'string') {
				if (tagName.toLowerCase() == obj.tagName.toLowerCase()) return obj;
			} else {
				return obj;
			}
		}
		if (obj.nextSibling) {
			obj = obj.nextSibling;
		} else if (obj.parentNode) {
			obj = obj.parentNode;
		} else {
			return null;
		}
	}
}

function domSetAlpha(obj, alpha)
{
	obj = domGet(obj);
	if (document.addEventListener) {
		obj.style.MozOpacity = parseInt(alpha)/100;
	} else {
		obj.style.filter = 'alpha(opacity='+parseInt(alpha)+', finishopacity=0, style=0)';
	}
}

function domRemove(obj)
{
	obj = domGet(obj);
	obj.parentNode.removeChild(obj);
}

if (browserType == 'ns') {
	document.addEventListener('mousedown', function(e) { window.nsevent=e; }, true);
	document.addEventListener('mouseup', function(e) { window.nsevent=e; }, true);
	document.addEventListener('mousemove', function(e) { window.nsevent=e; }, true);
	document.addEventListener('click', function(e) { window.nsevent=e; }, true);
	document.addEventListener('keyup', function(e) { window.nsevent=e; }, true);
	document.addEventListener('keydown', function(e) { window.nsevent=e; }, true);
	document.addEventListener('keypressed', function(e) { window.nsevent=e; }, true);
	document.addEventListener('blur', function(e) { window.nsevent=e; }, true);
	document.addEventListener('focus', function(e) { window.nsevent=e; }, true);
}


////////////////////////////////////////////////////////////////////////////////

function popup(width, height, name)
{
	var a = domGetParent(domEventGetTarget(), 'A');
	if (a) {
		if (!name) name = '';
		window.open(a.href, name, 'width='+width+',height='+height+',menubar=no,location=no,status=yes,toolbar=no');
		domEventPreventDefault();
		domEventCancelBubble();
		return false;
	}
}

////////////////////////////////////////////////////////////////////////////////
