function activeMenu(acm) {
	var mn = Array("mhome", "mabout", "marticle", "mnews", "mcontact");
	var len = mn.length;
	for(i = 0; i < len; i++) {
		if(acm == mn[i]) 
			document.getElementById(acm).className = 'menuover';
		else
			document.getElementById(mn[i]).className = 'menunorm';
	}
}
function goMod(url, elm, acm) {
	//activeMenu(acm);
	goPage(url, elm);
}
function getMod(url) {
	s = url;
	var ss = s.split("#");
	return ss[1].split("/");
}
function setMod(url) {
	var sss = getMod(url);
	switch(sss[0]) {
		case "main":
			activeMenu("mhome");
			break;
		case "about":
		case "news":
		case "article":
		case "contact":
			activeMenu("m" + sss[0]);
			break;
		default:
			activeMenu("");
			break;
	}
}
function decodeUrl(url) {
	var sss = getMod(url);
	page = "ajax.php";
	if (sss.length>1) {
		def = "?o=modules&n=" + sss[0];
		for (i=1; i<sss.length; i+=2)
			if (i==1)
				page += def + '&'+sss[i]+'='+sss[i+1];
			else 
				page += '&'+sss[i]+'='+sss[i+1];
	}
	return page;
}
function getPar(ar) {
	rt = "";
	if(ar.length > 3) {
		for (i=3; i<ar.length; i+=2)
			rt += '&'+ar[i]+'='+ar[i+1];
	}
	return rt;
}
function setUrl(url) {
	if (document.getElementById("ifr").contentDocument)
		ioj = document.getElementById("ifr").contentDocument;
	else
		ioj = document.frames['ifr'];
	ioj.location = "main.html?" + (url.split("#"))[1]; 
}
function goPage(url, idelm, sts) {
	window.location.href = url;
	if(typeof(sts) == 'undefined')
		sts = 0;
	if(sts == 0)
		setUrl(url);
	page = decodeUrl(url);
	var sss = getMod(url);
	JAJAX.load("ajax.php?f=header&pp=" + sss[0] + getPar(sss), "headerid");
	JAJAX.load("ajax.php?f=left&pp=" + sss[0] + getPar(sss), "lblock");
	JAJAX.load(page, idelm);
	initMenuMain();
	tileSlider.initevent();
	JTabs.init();
}
function goMenu(url, idelm) {
	window.location.href = url;
	setUrl(url);
	page = decodeUrl(url);
	var sss = getMod(url);
	JAJAX.load("ajax.php?d=blocks&f=menu&n=" + sss[0] + getPar(sss), "mnblock");
	JAJAX.load(page, idelm);
	tileSlider.initevent();
	JTabs.init();
}

function goPro(url, idelm) {
	window.location.href = url;
	setUrl(url);
	page = decodeUrl(url);
	var sss = getMod(url);
	JAJAX.load("ajax.php?d=blocks&f=menu&n=" + sss[0] + getPar(sss), "mnblock");
	JAJAX.load("ajax.php?o=modules&f=detail&n=" + sss[0] + getPar(sss), "content_pro");
	JTabs.init();
}

function goText(url, idelm) {
	window.location.href = url;
	setUrl(url);
	page = decodeUrl(url);
	JAJAX.load(page, idelm);
	var sss = getMod(url);
}
function goInfo(op) {
	if(document.getElementById("leftrate"))
		JAJAX.load("ajax.php?d=blocks&f=rate&op=" + op, "leftrate");
}
function goLoad(url) {
	goPage(url, "fulltext", 0);
	//setTimeout('setMod("' + url + '")', 1000);
}
function reLoad(sts) {
	linktop = window.location.href;
	if(linktop.indexOf("#") <= 0) 
		linktop = "#main/f/home";
	if(typeof(sts) == 'undefined')
		sts = 0;
	goPage(linktop, "fulltext", sts);
	//setTimeout('setMod("' + linktop + '")', 1000);
}

function langGo(lng) {
	JAJAX.commit("ajax.php?Language=" + lng, {'onComplete': langTo});
}
function langTo(val) {
	linktop = window.location.href;
	ss = linktop.split("#");
	url = ss[0];
	if(url.indexOf("index.php") > 0)
		url = url.substring(0, (url.length - 9));
	else
		url = url + "index.php";
	if(linktop.indexOf("#") <= 0) 
		linktop = url + "#main/f/home";
	else
		linktop = url + "#" + ss[1];
	window.location.href = linktop;
	//var sss = getMod(linktop);
	//goPage(linktop, "fulltext", 1);
	//setTimeout('setMod("' + linktop + '")', 1000);
}
function openWeblink() {
	link = _vL("weblinkurl");
	if(link != "") 
		window.open(link);
}

var mmenu_main = 0;
function initMenuMain() { 
	if(document.getElementById('myjquerymenu')) {
		jquerycssmenu.buildmenu("myjquerymenu", arrowimages);
		mmenu_main = 0;
	} else {
		if(mmenu_main < 10000) {
			setTimeout('initMenuMain()', 1000);
			mmenu_main += 1000;
		} else
			mmenu_main = 0;
	}
}

/*-----------Member---------*/
function goUrl(url, idelm) {
	var ss = getMod(url);
	if (ss.length > 2) {
		page = "";
		for (i=2; i<ss.length; i+=2)
			page += '&' + ss[i] + '=' + ss[i+1];
		if(ss[0] == 1) 
			window.location.href = "manage.php?o=admin&n=" + ss[1] + page;
		else {
			if(ss[3] == "signout") {
				var options = {
					method : 'get',
					parameters : '',					
					onComplete: inReturn,
					onFailure: reportError
				};
				new Ajax.Request("ajax.php?o=modules&n=" + ss[1] + page, options);
			} else {
				window.location.href = url;
				JAJAX.load("ajax.php?o=modules&n=" + ss[1] + page, idelm);
			}
		}
	}
}

function inReturn(request) {
	var vl = request.responseText;
	if(vl != "") {
		var ss = vl.split("#");
		if(ss[0] == 1) {
			echoLayer('m_sign', ss[1]);
			document.forms['leftLogins'].elements['sigin'].disabled = false;
		} else
		if(ss[0] == 2 || ss[0] == 3) {
			goPage(window.location.href, 'fulltext');
		} else
		if(ss[0] == 5) {
			alert(ss[1]);
			document.getElementById("waitsend").style.display = '';
		} else
		if(ss[0] == 4) {
			goPage("#" + ss[1], 'fulltext');
			setMod("#" + ss[1]);
		} else {
			window.location.href = "#article/f/article";
			echoLayer('signblock', vl);
		}
	}
}

function reportError(request){
	alert('msg_loading_error');
}	

function goIn(o) {
	if(o.elements['username'].value == "") {
		alert(o.elements['m_username'].value);
		o.elements['username'].focus();
	} else {
		o.elements['sigin'].disabled = true;
		params = "&username=" + o.elements['username'].value;
		params += "&password=" + o.elements['password'].value;
		params += "&action=123";
		var options = {
			method : 'get',
			parameters : params,					
			onComplete: inReturn,
			onFailure: reportError
		};
		new Ajax.Request('ajax.php' + o.elements['url_action'].value, options);
	}
	return false;
}
/*-----------Member---------*/

JTabs = {
	counter: 0,
	init:function() {
		if(document.getElementById('tabs')) {	
			$('#tabs').tabs();
			$('#dialog_link, ul#icons li').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); }
			);		
			this.counter = 0;				
		} else {
			if(this.counter < 10000) {
				setTimeout('JTabs.init()', 1000);
				this.counter += 1000;
			} else
			{
				this.counter = 0;	
				addScript('scripts/ajaxpost.js');
			}
		}
	}
}

function addScript(JSfileName) {
	var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.src = JSfileName;
	document.body.appendChild(js);
}

function slidehome(id) {
	var layer1 = document.getElementById('slide_1');
	var layer2 = document.getElementById('slide_2');
	var layer3 = document.getElementById('slide_3');
	if (id=='1')
	{
		layer1.style.display='';
		layer2.style.display='none';
		layer3.style.display='none';
	}
	else
		if (id=='2')
		{
			layer1.style.display='none';
			layer2.style.display='';
			layer3.style.display='none';
		}
		else
			if (id=='3')
			{
				layer1.style.display='none';
				layer2.style.display='none';
				layer3.style.display='';
			}
}

