/*document.onclick = function(event)
{
var elem = event.srcElement;

if (!elem || event.srcElement.tagName != "A") continue;

var href = elem.href;

alert(href);
}

function mailto(string)
{
var n, res = "";

for (var i = 0; i < string.length; i++)
{
n = string.charCodeAt(i);

if (n >= 8364) {n = 128}

res += String.fromCharCode(res - (3));
}

window.location = "mailto:" + res;

return res;
}
*/
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 ? "&" : "?");
	//alert(String(loc).indexOf("?"));
	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 doSearch(){
	var sStr = document.getElementById("searchInp").value;
	if(sStr == "" || sStr == " "){
		return;
	}
	var sSelect = document.getElementById("sSelect");
	sSelect = sSelect.options[sSelect.selectedIndex].value;
	while(sStr.indexOf("&") > -1){
		sStr = sStr.replace("&", "");
	}
	var loc = String(window.location);
	if(loc.indexOf("search") > 0){
		loc = loc.substr(0, loc.indexOf("search")-1);
	}
	var prefix = (String(loc).indexOf("?") > -1 ? "&" : "?");
	if(loc.indexOf("index.php") < 0){
		prefix = "index.php" + prefix;
	}
	window.location = loc + prefix + "search=" + sStr + "&sSelect=" + sSelect;
}

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


document.onclick = function(event){
	var elem, string,  code, res = "";
	event = event || window.event;

	elem = event.srcElement;

	while (elem && elem.tagName != "A")
	{
		elem = elem.parentElement;
	}

	if (!elem) return true;

	var match = elem.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;
	return false;
}
