var arrResize = new Array("59316","3740")
var wnd = null;
var iPopupHeight = 320, iPopupWidth = 500;
var features = "height=" + iPopupHeight + ",width=" + iPopupWidth + ",channelmode=no,dependent=no,directories=no,fullscreen=0,location=0,menubar=no,resizable=no,scrollbars=0,status=1,toolbar=0,top=" + getYPosition(iPopupHeight) + ",left=" + getXPosition(iPopupWidth);
var featuresWithResize = "height=" + iPopupHeight + ",width=" + iPopupWidth + ",channelmode=no,dependent=no,directories=no,fullscreen=0,location=0,menubar=no,resizable=yes,scrollbars=1,status=1,toolbar=0,top=" + getYPosition(iPopupHeight) + ",left=" + getXPosition(iPopupWidth);
function openNewWindow(params){
var blnResize = false;
	for(var i = 0;i < arrResize.length; i++){	
		if(params.indexOf(arrResize[i]) >= 0){
			blnResize = true;
			i = arrResize.length;			
		}
	}
	var strTmpProperty = blnResize ? featuresWithResize :features;
	if(params){
		if((wnd!=null)&&(!wnd.closed)){
			wnd.close();
		}
		wnd=window.open(params,"RateWindow",strTmpProperty);
	}else{
		return;
}
}

function getXPosition(iWndWidth){
	var iX = 0;
	var iW = parseInt(screen.width);
	iWndWidth = ((iWndWidth == null) || (iWndWidth < 0 )) ? 0 : iWndWidth;
	if(iW > iWndWidth)	
		iX = Math.ceil((iW - iWndWidth) / 2);
	
	return iX;
}
function getYPosition(iWndHeight) {
	var iY = 0;
	var iH = parseInt(screen.height) - 24;	
	iWndHeight = ((iWndHeight == null) || (iWndHeight < 0 )) ? 0 : iWndHeight;
	if(iH > iWndHeight)
		iY = Math.ceil((iH - iWndHeight) / 2);	
		
	return iY;	
}


function Menu_openPopup(popupUrl, popupWidth, popupHeight) {
	var windowWidth  = null;
	var windowHeight = null;
	var windowLeft   = null;
	var windowTop    = null;
	var strFeatures  = '';
	
	if (navigator.userAgent.match(/gecko/i)) {
		windowWidth  = window.innerWidth;
		windowHeight = window.innerHeight;
		windowLeft   = screenX;
		windowTop    = screenY;
	} else {
		windowWidth  = document.body.offsetWidth;
		windowHeight = document.body.offsetHeight;
		windowLeft   = window.screenLeft;
		windowTop    = window.screenTop;
	}
	
	var popupLeft = parseInt(windowLeft + windowWidth/2 - popupWidth/2);
	var popupTop  = parseInt(windowTop + windowHeight/2 - popupHeight/2);
	
	if (popupWidth && popupHeight) {
		strFeatures = 'left=' + popupLeft + ',top=' + popupTop + ',width=' + popupWidth + ',height=' + popupHeight + ',scrollbars=1,resizable=0,toolbar=0,status=1,menubar=0';
	}
	
	window.open(popupUrl, 'soXes_popup', strFeatures);
}

function setNewLocale(){
	f = document.forms["form_locale"];
	if(window.location.search == ""){
		f.action = "index.php";
	}
	f.submit();
}

function changeNewsCategory(url){
	window.location = url;
}

function showNews(num){
	var loc = window.location;
	var prefix = (String(loc).indexOf("?") > -1 ? "&" : "?");
	window.location = loc + prefix + "news_id=" + num;
}

function returnToAllNews(newsNum){
	var loc = String(window.location);
	loc = loc.replace("&news_id=" + newsNum, "");
	loc = loc.replace("?news_id=" + newsNum, "");
	window.location = loc;
}

function showHiddenMenuItem(num){
	var a = window.location.href;
	var str = a.replace(/(active=m_)(\d+)/, "$1" + num);
	window.location = str;
}

//
//	onload handling
//
var _onload = new Array;

window.onload = function()
{
	for (var i = 0; i < _onload.length; i++)
	{
		_onload[i].call(this);
	}
};

//
//	marquee handling
//
var marquee = new Array;

_onload.push(function()
{
	for (var i = 0; i < marquee.length; i++)
	{
		marquee[i].start();
	}
});

//
//	'Esc' handling for popups
//
document.onkeypress = function(event)
{
	event = event || window.event;

	if (top.opener && event.keyCode == 27)
	{
		top.close();
	}
}

//
//	email decryption
//

function documentClick(event) {
	event = event || window.event;
	
	var srcElement = event.target || event.srcElement;
	var string, code, res = '';
	
	while (srcElement && srcElement.tagName != 'A') {
		srcElement = srcElement.parentNode;
	}
	if (!srcElement) {
		return true;
	}
	
	var match = srcElement.href.match(/^mailto:(.+)/);
	
	if (!match) {
		return true;
	}
	string = unescape(match[1]);
	
	for (var i = 0; i < string.length; i++) {
		code = string.charCodeAt(i);
		if (code >= 8364) {
			code = 128;
		}
		res += String.fromCharCode(code - (3));
	}
	window.location = "mailto:" + res;
	
	srcElement.returnValue = true;
	
	if (event.cancelable) {
		event.preventDefault();
	}
	
	return false;	
}

if (is.ie) {
	document.attachEvent("onclick", documentClick);
} else {
	document.addEventListener('click', documentClick, false);
}

function preSubmit(event)
{
	event = event || window.event;

	var srcElement = event.target || event.srcElement;

	//
	//	Netscape trick
	//
	form = srcElement.form || srcElement;

	var elem, error;

	//
	//	check (checkbox|radio)group
	//
	var checkGroup = function(name)
	{
		var options = form.elements[name];
		var error = true;

		for (var i = 0; i < options.length; i++)
		{
			error &= !options[i].checked;
		}

		return error;
	}
	
	//
	//	walk through form elements
	//
	for (i = 0; i < form.length; i++)
	{
		elem  = form.elements[i];
		value = elem.value;

		//
		//	skip non-required fields
		//
		if (!elem.getAttribute("required"))
		{
			continue;
		}

		switch (elem.type)
		{
			case "checkbox":
			error = elem.name.match(/\[\]$/) ? checkGroup(elem.name) : !elem.checked;
			break;

			case "select-one":
			error = elem.selectedIndex == 0;
			break;

			case "radio":
			error = checkGroup(elem.name);
			break;

			case "submit":
			error = false;
			break;

			default:
			error = !value.match(/\S/);
		}
		

		if (error)
		{
			alert(messageCommon);
			elem.focus();
			return false;
		}

		//
		//	validate "email" fields
		//
		if (elem.className == "email" && !elem.value.match(/^[a-z0-9\.\-_\+]+@[a-z0-9\-_]+\.([a-z0-9\-_]+\.)*?[a-z]+$/i))
		{
			alert(messageEmail);
			elem.focus();
			return false;
		}
	}

	return true;
}

/*document.attachEvent("onclick", function(event){

event = event || window.event;

	var srcElement = event.target || event.srcElement;

	var string,  code, res = "";

	while (srcElement && srcElement.tagName != "A")
	{
		srcElement = srcElement.parentElement;
	}
	if (!srcElement) return true;

	var match = srcElement.href.match(/^mailto:(.+)/);
	if (!match) return true;
	string = match[1];
	for (var i = 0; i < string.length; i++){
		code = string.charCodeAt(i);
		if (code >= 8364) {code = 128}
		res += String.fromCharCode(code - (3));
	}
	window.location = "mailto:" + res;

	srcElement.returnValue = true;

	if (event.cancelable)
	{
		event.preventDefault();
	}

	return false;
});*/
