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

function popup(file,name,width,height) {
	x = (640 - width)/2, y = (480 - height)/2;
	if (screen) {
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	if (screen.availWidth > 1800) {
		x = ((screen.availWidth/2) - width)/2;
	}
	var newWindow = window.open(file,name,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars=auto,toolbar=no,menubar=no,status=no');
}

function getSelectValue(selObject){
	for(i=0;i<selObject.options.length;i++){
		if(selObject.options[i].selected == true){
			return selObject.options[i].value;
		}
	}
}

function evalStates(responseXML, ajax){
	var states = responseXML.documentElement.childNodes;
	if(states.length>1){
		$('statesText').style.display = "none";
		var stateSelect = $('stateSelect');
		removeChilds(stateSelect);
		for(var i=0; i<states.length; i++){
			var optionElement = $E('OPTION');
			insertNodeText(optionElement, unescape(states[i].firstChild.data).replace(/\+/g, " "));
			optionElement.setAttribute("value", states[i].attributes.getNamedItem("id").value);
			stateSelect.appendChild(optionElement);
		}
		if(is_ie){
			$('statesContainer').style.display = "block";
		}
		else{
			$('statesContainer').style.display = "table-row";
		}
		$('stateSelect').style.display = 'block';
	}
	else{
		$('statesContainer').style.display = "none";
	}
	ajax.stopCheck();
	
}

function getStates(firstElement){
	var ajax = new xAjax("register.php?page=register&action=get_states&first_el="+firstElement);
	ajax.startCheck();
	ajax.addRequest("cid="+getSelectValue($('countrySelect')), evalStates, ajax);
	$('statesText').style.display = "block";
	$('stateSelect').style.display = 'none';
}

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