function activeMenu(acm) {

	var mn = Array("hmenu", "amenu", "nmenu", "mmenu", "lmenu", "rmenu", "cmenu");

	var len = mn.length;

	for(i = 0; i < len; i++) {

		if(acm == mn[i]) {

			document.getElementById(acm + "li").className = 'selectedli';

			document.getElementById(acm + "lifoo").className = 'selectedli';

		} else {

			document.getElementById(mn[i] + "li").className = '';

			document.getElementById(mn[i] + "lifoo").className = '';

		}

	}

}

//View module

function goMod(acm, url, elm) {

	activeMenu(acm);

	goPage(url, elm);

}

function getMod(url) {

	s = url;

	var ss = s.split("#");

	return ss[1].split("/");

}

//Set 

function setMod(url) {

	var sss = getMod(url);

	switch(sss[0]) {

		case "main":

			activeMenu("hmenu");

			break;

		case "about":

			activeMenu("amenu");

			break;

		case "news":

			activeMenu("nmenu");

			break;

		case "article":

			activeMenu("mmenu");

			break;

		case "partner":

			activeMenu("lmenu");

			break;

		case "jobs":

			activeMenu("rmenu");

			break;

		case "contact":

			activeMenu("cmenu");

			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;

}

//Get param

function getPar(ar) {

	rt = "";

	if(ar.length > 3) {

		for (i=3; i<ar.length; i+=2)

			rt += '&'+ar[i]+'='+ar[i+1];

	}

	return rt;

}

//Reload page

function goPage(url, idelm) {

	window.location.href = url;

	page = decodeUrl(url);

	var sss = getMod(url);

	ajax_loadData("ajax.php?f=left&pp=" + sss[0] + getPar(sss), "lblock");

	ajax_loadData(page, idelm);

}

//View on submenu

function goMenu(url, idelm) {

	window.location.href = url;

	page = decodeUrl(url);

	var sss = getMod(url);

	ajax_loadData("ajax.php?d=blocks&f=menu&n=" + sss[0] + getPar(sss), "mnblock");

	ajax_loadData(page, idelm);

}

//View detail

function goText(url, idelm) {

	window.location.href = url;

	page = decodeUrl(url);

	ajax_loadData(page, idelm);

}

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;

				ajax_loadData("ajax.php?o=modules&n=" + ss[1] + page, idelm);

			}

		}

	}

}

function goIn(hre) {

	if(document.forms[hre].elements['username'].value == "") {

		alert(document.forms[hre].elements['m_username'].value);

		document.forms[hre].elements['username'].focus();

	} else {

		document.forms[hre].elements['sigin'].disabled = true;

		params = "&username=" + document.forms[hre].elements['username'].value;

		params += "&password=" + document.forms[hre].elements['password'].value;

		params += "&action=123";

		var options = {

			method : 'get',

			parameters : params,					

			onComplete: inReturn,

			onFailure: reportError

		};

		new Ajax.Request('ajax.php' + document.forms[hre].elements['url_action'].value, options);

	}

}

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 _iH(kys) {

	return document.getElementById(kys).innerHTML;

}

function _vL(kys) {

	return document.getElementById(kys).value;

}

function _fC(kys) {

	document.getElementById(kys).focus();

}

function viewInfo(linkmr, wt, ht) {

	if(wt > 1000) wt = 1000;

	ht += 140; if(ht > 700) ht = 700;

	OWEdit(linkmr, wt, ht);

}

function selected(cal, date) {

	cal.sel.value = date;

	if (cal.dateClicked) cal.callCloseHandler();

}

function closeHandler(cal) {

	cal.hide();

	cal.destroy();

	calendar = null;

}

function showCalendar(id, format, showsTime) {

	var el = document.getElementById(id);

	if (calendar != null) 

		calendar.hide();

	else {

		var cal = new Calendar(true, null, selected, closeHandler);

		cal.weekNumbers = true;

		if (typeof showsTime == "string") {

			cal.showsTime = true;

			cal.time24 = (showsTime == "24");

		}

		calendar = cal;

		cal.setRange(1900, 2070);

		cal.create();

	}

	calendar.setDateFormat(format);

	calendar.parseDate(el.value);

	calendar.sel = el;

	calendar.showAtElement(el.nextSibling, "Br");

	return false;

}

function testCode(fl, id) {

	AJAX_LoadElement("ajax.php?o=modules&n=file_download&f=test&cd=" + fl.value + "&fid=" + id, "ctest_" + id);

}

function testCodePass(id, vl) {

	AJAX_LoadElement("ajax.php?o=modules&n=partner&f=test&vl=" + vl + "&cd=" + _vL("codestudent") + "&ps=" + _vL("passstudent"), id);

}

function viewPoint(id) {

	if(_vL("codestudent") == "") {

		alert(_vL("m_codestudenttxt"));

		_fC("codestudent");

	} else

	if(_vL("passstudent") == "") {

		alert(_vL("m_passstudenttxt"));

		_fC("passstudent");

	} else

	if(_iH("m_codestudent") != "" || _iH("m_passstudent") != "") {

		alert(_vL("m_codepasserr"));

		_fC("codestudent");

	} else

		ajax_loadData("ajax.php?o=modules&n=partner&f=partner_view&cd=" + _vL("codestudent") + "&ps=" + _vL("passstudent"), id);

}

function sendPostData(idf,idd) {

	lst = _vL("listtestid_" + idf);

	var lk = lst.split(",");

	stp = 0;

	for (i = 0; (i < lk.length && stp == 0); i++) {
		if(_vL("fldn_" + lk[i]) == "") {

			alert(_vL("mss1_" + lk[i]));

			_fC("fldn_" + lk[i]);

			stp = 1;

		}else {

			if(document.getElementById("conf_" + lk[i]) != null) {

				akv = _vL("conf_" + lk[i]);

				switch(akv) {//Kiem tra tu khoa bat buoc (Vi du: Bat buoc phai nhap Ho ten, Email hoac So dien thoai)

					case "chkb":
						//lbox = _vL("lbox_" + lk[i]);

						//alert("aaaa");

						break;

					case "radio":						
						if(_vL("fldn_" + lk[i]) != ""){						

							var checkBoxArr;

							checkBoxArr = getSelectedCheckbox(document.forms['frpostdata_' + idf].elements["fldn_" + lk[i]]);

							if(checkBoxArr.length == 0) {

								alert(_vL("mss1_" + lk[i]));	

								stp = 1;

							}

						}

						break;					

					case "conf":

						if(_iH("ctest_" + lk[i]) != "") {

							alert(_vL("mss2_" + lk[i]));

							_fC("fldn_" + lk[i]);

							stp = 1;

						}

						break;

					case "file":

						break;

					case "date":

						break;

					case "time":

						break;

					case "mail":

						if(!isEmail(_vL("fldn_" + lk[i]))) {

							alert(_vL("mss2_" + lk[i]));

							_fC("fldn_" + lk[i]);

							stp = 1;

						}

						break;

					case "tel":

						if(!isTelephone(_vL("fldn_" + lk[i]))) {

							alert(_vL("mss2_" + lk[i]));

							_fC("fldn_" + lk[i]);

							stp = 1;

						}

						break;

				}

			}

		}

	}

	if(i == lk.length && stp != 1) {

		lsf = _vL("listid_" + idf);

		var lf = lsf.split(",");

		var idradio;

		params = "&idform=" + idf + "&iddownload=" + idd + "&snt=123";		

		for (ii = 0; ii < lf.length; ii++) {

			idradio = _gCV(document.forms['frpostdata_' + idf].elements["fldn_" + lf[ii]]);

			if(idradio > 0)

				params += "&fldn_" + lf[ii] + "=" + idradio;
			
			//alert(idradio);

			else	params += "&fldn_" + lf[ii] + "=" + encodeURIComponent(_vL("fldn_" + lf[ii]));		

		}

		//alert(params);

		var options = {

			method : 'get',

			parameters : params,					

			onComplete: doneShowProposal,

			onFailure: reportError

		};

		waitingLoading("contact");

		new Ajax.Request('ajax.php?o=modules&n=file_download&f=form', options);

	}

}

function doneShowProposal(request) {

		var content = request.responseText;

		var divid = $("contact");

		if(!divid || content == "false")

			reportError(request);

		else 

			echoLayer('contact', content);

}		

function reportError(request){

	alert('msg_loading_error');

}	



function testDateOfSearch(view) {

	date = _vL("finddate");

	if(date.length < 2) 

		date = "0" + date;

	month = _vL("findmonth");

	if(month.length < 2) 

		month = "0" + month;

	year = _vL("findyear");

	url = _vL("findurl");

	if(!kiemtrangay(date, month)) {

		alert("Date invalid, please select date again!");

		return;

	} else {

		page = url;

		page += "/ketqua/" + year + "-" + month + "-" + date;

		if(date == "00")

			page += "/ketqua/" + year + "-" + month + "-";

		goText(page, view);

	}

}

function openWeblink() {

	link = _vL("weblinkurl");

	if(link != "") 

		window.open(link);

}

function searchOnFocus(field) {

	if(field.value == _vL('lblsearch'))

		field.value = '';

}

function searchOnBlur(field){

	if(field.value == '')

		field.value = _vL('lblsearch');

}



function replacetxt(src, sold, snew) {

	var pos = 0;

	while((pos = src.indexOf(sold, pos)) >= 0) {

		src = src.substring(0, pos) + snew  + src.substring(pos + sold.length);

		pos += snew.length;

	}

	return src;

}

function onCheckFind(lv) {

	fr = document.forms["ffind"];

	text = fr.keyword.value;

	if(_vL('lblsearch') != text) {

		text = replacetxt(text, " ", "");

		if(text == "") {

			alert(_vL('msgsearch') + '!');

			fr.keyword.focus();

			return false;

		} else

		if(text.length < 3) {

			alert(_vL('msgkeyword') + '!');

			fr.keyword.focus();

			return false;

		} else {

			if(lv == 0) {

				params = "&keyword=" + encodeURIComponent(fr.keyword.value);

				params += "&action=123";

				var options = {

					method : 'get',

					parameters : params,					

					onComplete: inReturn,

					onFailure: reportError

				};

				new Ajax.Request('ajax.php?o=modules&n=search&f=search', options);

				return false;

			} else {

				text1 = encodeURIComponent(fr.keyword.value);

				urlpage = "http://www.google.com.vn/search?hl=vi&q=" + text1;

				wopen = window.open(urlpage);

				wopen.focus();	

			}

		}

	}

}

function onCheckFindW(lv) {

	onCheckFind(lv)

}

function shareOnFocus(field) {

	if(field.value == _vL('lblshare'))

		field.value = '';

}

function shareOnBlur(field){

	if(field.value == '')

		field.value = _vL('lblshare');

}

function onShareWebsite() {

	fr = document.forms["sharewebsite"];

	text = fr.mailsend.value;

	if(fr.lblshare.value != text) {

		text = replacetxt(text, " ", "");

		if(text == "") {

			alert(fr.m_email.value);

			fr.mailsend.focus();

		} else

		if(!isEmail(text)) {

			alert(fr.m_erroremail.value);

			fr.mailsend.focus();

		} else {

			document.getElementById("waitsend").style.display = 'none';

			params = "&mailsend=" + text;

			params += "&action=123";

			var options = {

				method : 'get',

				parameters : params,					

				onComplete: inReturn,

				onFailure: reportError

			};

			new Ajax.Request('ajax.php?o=modules&n=contact&f=share', options);

		}

	}

}

function reLoad() {

	ajax_loadData("ajax.php?f=header", "ihdshow");

	ajax_loadData("ajax.php?f=footer", "iftshow");

	linktop = window.location.href;

	if(linktop.indexOf("#") <= 0) 

		linktop = "#main/f/home";

	goPage(linktop, "fulltext");

	setTimeout('setMod("' + linktop + '")', 3000);

	setTimeout('getListSlide()', 3000);

	setTimeout('getListI()', 3000);

	setTimeout('showSP()', 4000);

	setTimeout('showP00()', 4000);

	setTimeout('showP01()', 4000);

	setTimeout('showP02()', 4000);

	setTimeout('showP03()', 4000);

}

//Slide

var preLoadP = Array();

var preLoadI = Array();

var spbnr = 4000;

runP = 0;

runP00 = 0;

runP01 = 0;

runP02 = 0;

runP03 = 0;

function getListSlide() {

	npuc = _vL("_numpictureslide");

	for(ii = 0; ii < npuc; ii++) {

		preLoadP[ii] = new Image();

		preLoadP[ii].src = _vL("_pictureno" + ii);

		preLoadP[ii].title = _vL("_titlepictureno" + ii);

	}

}

function showSP() {	

	if(preLoadP.length <= 0)

		return;

	if(document.all) {

		document.images.bnpicture.style.filter="revealTrans(duration=1)";

		document.images.bnpicture.style.filter="revealTrans(transition = 12)";

		document.images.bnpicture.filters.revealTrans.apply();

	}

	document.images.bnpicture.src = preLoadP[runP].src;

	document.images.bnpicture.title = preLoadP[runP].title;

	if(document.all)

		document.images.bnpicture.filters.revealTrans.Play();

	

	runP++;

	if(runP > (preLoadP.length - 1)) 

		runP = 0;

	setTimeout('showSP()', spbnr);

}

function getListI() {

	ni = _vL("_numimageslide");

	for(ii = 0; ii < ni; ii++) {

		preLoadI[ii] = new Image();

		preLoadI[ii].src = _vL("_imageno" + ii);

		preLoadI[ii].title = _vL("_titleimageno" + ii);

	}

	if(ni > 2)

		runP01 = 2;

	if(ni > 4)

		runP02 = 4;

	if(ni > 6)

		runP03 = 6;

}

function showP00() {	

	if(preLoadI.length <= 0)

		return;

	if(document.all) {

		document.images.picture00.style.filter="revealTrans(duration=0)";

		document.images.picture00.style.filter="revealTrans(transition = 6)";

		document.images.picture00.filters.revealTrans.apply();

	}

	document.images.picture00.src = preLoadI[runP00].src;

	document.images.picture00.title = preLoadI[runP00].title;

	if(document.all)

		document.images.picture00.filters.revealTrans.Play();

	

	runP00++;

	if(runP00 > (preLoadI.length - 1)) 

		runP00 = 0;

	setTimeout('showP00()', spbnr);

}

function showP01() {	

	if(preLoadI.length <= 0)

		return;

	if(document.all) {

		document.images.picture01.style.filter="revealTrans(duration=1)";

		document.images.picture01.style.filter="revealTrans(transition = 4)";

		document.images.picture01.filters.revealTrans.apply();

	}

	document.images.picture01.src = preLoadI[runP01].src;

	document.images.picture01.title = preLoadI[runP01].title;

	if(document.all)

		document.images.picture01.filters.revealTrans.Play();

	

	runP01++;

	if(runP01 > (preLoadI.length - 1)) 

		runP01 = 0;

	setTimeout('showP01()', (spbnr + 400));

}

function showP02() {	

	if(preLoadI.length <= 0)

		return;

	if(document.all) {

		document.images.picture02.style.filter="revealTrans(duration=0)";

		document.images.picture02.style.filter="revealTrans(transition = 5)";

		document.images.picture02.filters.revealTrans.apply();

	}

	document.images.picture02.src = preLoadI[runP02].src;

	document.images.picture02.title = preLoadI[runP02].title;

	if(document.all)

		document.images.picture02.filters.revealTrans.Play();

	

	runP02++;

	if(runP02 > (preLoadI.length - 1)) 

		runP02 = 0;

	setTimeout('showP02()', (spbnr + 800));

}

function showP03() {	

	if(preLoadI.length <= 0)

		return;

	if(document.all) {

		document.images.picture03.style.filter="revealTrans(duration=1)";

		document.images.picture03.style.filter="revealTrans(transition = 7)";

		document.images.picture03.filters.revealTrans.apply();

	}

	document.images.picture03.src = preLoadI[runP03].src;

	document.images.picture03.title = preLoadI[runP03].title;

	if(document.all)

		document.images.picture03.filters.revealTrans.Play();

	

	runP03++;

	if(runP03 > (preLoadI.length - 1)) 

		runP03 = 0;

	setTimeout('showP03()', (spbnr + 1200));

}