/******* GLOBALS [BEGIN] *******/
var is_opera = /opera\/9/i.test(navigator.userAgent);
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);
/******* GLOBALS [END] *******/

function $(id){
	return document.getElementById(id);
}

function $E(tagName){
	return document.createElement(tagName);
}

function $R(url){
	document.location = url;
}

var Try = new Object({
	these: function() {
		var returnValue;
		for (var i = 0; i < arguments.length; i++) {
			var lambda = arguments[i];
			try {
				returnValue = lambda();
				break;
			} catch (e) {}
		}
		return returnValue;
	}
});

function insertNodeText(node, text, position){
	var textNode = document.createTextNode(text);
	if(!position){
		node.appendChild(textNode);
	}
	else if(position == -1){
		var newElement = node.cloneNode(true);
		removeChilds(node);
		node.appendChild(textNode);
		for(i=0;i<newElement.childNodes.length;i++){
			node.appendChild(newElement.childNodes[i]);
		}
	}
	else if(position == 1){
		removeChilds(node);
		node.appendChild(textNode);
	}
	else{
		return false;
	}

	return node;
}

function removeChilds(node){
	var child = new Array();
	for(i=0;i<node.childNodes.length;i++){
		child[i] = node.childNodes[i];
	}
	for(var i=0;i<child.length;i++){
		node.removeChild(child[i]);
	}
	return node;
}

function chatPopup(path, name, popupWidth, popupHeight){
	var conf = new Object({
		width : popupWidth,
		height : popupHeight,
		screenX : (640 - popupWidth)/2,
		screenY : (480 - popupHeight)/2,
		top : (480 - popupHeight)/2,
		left : (640 - popupWidth)/2,		
		toolbar : 'no',		
		menubar : 'no',		
		status : 'no'		
	});
	
	if(screen){
		conf.screenY = (screen.availHeight - popupHeight)/2;
		conf.top = (screen.availHeight - popupHeight)/2;
		conf.screenX = (screen.availWidth - popupWidth)/2;
		conf.left = (screen.availWidth - popupWidth)/2;
	}
	
	if(screen.availWidth > 1800){
		conf.screenX = ((screen.availWidth/2) - popupWidth)/2;
		conf.left = ((screen.availWidth/2) - popupWidth)/2;
	}
	
	var confString = "";
	for(key in conf){
		confString += key+"="+conf[key]+",";
	}
	confString = confString.substr(0, confString.length-1);
	
	var newWindow = window.open(path, name, confString);
	if(!newWindow){
		alert(TEXT_POPUP_BLOCKED);
		return false;
	}
	return true;
}