_stopactivemn = 0;
function activeMenu(acm) {
	if(document.getElementById(acm + "li")) {
		var mn = Array("hmenu", "amenu", "ymenu", "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 = '';
			}
		}
	} else {
		if(_stopactivemn < 10000) {
			setTimeout('activeMenu("' + acm + '")', 1000);
			_stopactivemn += 1000;
		}
	}
}
//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 "study":
			activeMenu("ymenu");
			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;
}
//Load page random
function goRan(url, elm) {
	if(url != "javascript:nullUrl();") {
		setMod(url);
		goPage(url, elm);
	}
}
//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 langGo(lng) {
	var options = {
		method : 'get',
		parameters : '',					
		onComplete: langTo,
		onFailure: reportError
	};
	new Ajax.Request("ajax.php?Language=" + lng, options);
}
function langTo(val) {
	/*linktop = window.location.href;
	if(linktop.indexOf("#") <= 0) 
		linktop = "#main/f/home";
	var sss = getMod(linktop);
	ajax_loadData("ajax.php?f=header&pp=" + sss[0] + getPar(sss), "headerid");
	ajax_loadData("ajax.php?f=footer&pp=" + sss[0] + getPar(sss), "footerid");
	setTimeout('goPage("' + linktop + '", "fulltext", 0)', 300);
	setTimeout('setMod("' + linktop + '")', 1000);*/
	reLoad();
}
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;
}
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] == 7) {
			alert(ss[1]);
			document.getElementById("waitsend").style.display = 'none';
			document.getElementById("sendpostid").disabled = false;
			document.forms["pscomnent"].reset();
		} 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=contact&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) {
	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) {
					case "chkb":
						//lbox = _vL("lbox_" + lk[i]);
						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(",");
		params = "&idform=" + idf + "&snt=123";
		for (ii = 0; ii < lf.length; ii++)
			params += "&fldn_" + lf[ii] + "=" + encodeURIComponent(_vL("fldn_" + lf[ii]));
		var options = {
			method : 'get',
			parameters : params,					
			onComplete: doneShowProposal,
			onFailure: reportError
		};
		waitingLoading("contact");
		new Ajax.Request('ajax.php?o=modules&n=contact&f=contact', 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");
	setMod(linktop);
	initSldMain();
	initSld4Pic();
}
//Slide
var preLoadP = Array();
var preLoadI = Array();
var preLoadU = 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);
}
var _stopslidemain = 0;
function initSldMain() {
	if(document.getElementById('_numpictureslide') && document.getElementById('bnpicture')) {
		getListSlide();
		showSP();
	} else {
		if(_stopslidemain < 10000) {
			setTimeout('initSldMain()', 1000);
			_stopslidemain += 1000;
		}
	}
}
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);
		preLoadU[ii] = _vL("_urlto" + ii);
	}
	if(ni > 2)
		runP01 = 2;
	if(ni > 4)
		runP02 = 4;
	if(ni > 6)
		runP03 = 6;
}
var _stopslide4pics = 0;
function initSld4Pic() {
	if(document.getElementById('_numimageslide') && document.getElementById('picture00')) {
		getListI();
		showP00();
		showP01();
		showP02();
		showP03();
	} else {
		if(_stopslide4pics < 10000) {
			setTimeout('initSld4Pic()', 1000);
			_stopslide4pics += 1000;
		}
	}
}
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;
	for(ilink = 0; ilink < document.links.length; ilink++)
		if(document.links[ilink].name == 'url00')
			document.links[ilink].href = preLoadU[runP00];
	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;
	for(ilink = 0; ilink < document.links.length; ilink++)
		if(document.links[ilink].name == 'url01')
			document.links[ilink].href = preLoadU[runP01];
	if(document.all)
		document.images.picture01.filters.revealTrans.Play();
	
	runP01++;
	if(runP01 > (preLoadI.length - 1)) 
		runP01 = 0;
	setTimeout('showP01()', (spbnr));
}
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;
	for(ilink = 0; ilink < document.links.length; ilink++)
		if(document.links[ilink].name == 'url02')
			document.links[ilink].href = preLoadU[runP02];
	if(document.all)
		document.images.picture02.filters.revealTrans.Play();
	
	runP02++;
	if(runP02 > (preLoadI.length - 1)) 
		runP02 = 0;
	setTimeout('showP02()', (spbnr));
}
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;
	for(ilink = 0; ilink < document.links.length; ilink++)
		if(document.links[ilink].name == 'url03')
			document.links[ilink].href = preLoadU[runP03];
	if(document.all)
		document.images.picture03.filters.revealTrans.Play();
	
	runP03++;
	if(runP03 > (preLoadI.length - 1)) 
		runP03 = 0;
	setTimeout('showP03()', (spbnr));
}
function forceMaxLength(o){  
	var maxLength = parseInt(o.getAttribute('maxlength'));  
	if(o.value.length > maxLength)
		o.value = o.value.substring(0, maxLength);  
	document.getElementById('ncharleft').innerHTML = maxLength - o.value.length;
}  
function insertEmoticon(s) {
	o = document.forms["pscomnent"].note;
	insertAtCursor(o, s)
}
function insertAtCursor(myField, myValue) { 
	if (document.selection) { //IE support 
		myField.focus(); 
		sel = document.selection.createRange(); 
		sel.text = myValue; 
	} else //Mozilla/Firefox/Netscape 7+ support 
		if(myField.selectionStart || myField.selectionStart == '0') { 
			var startPos = myField.selectionStart; 
			var endPos = myField.selectionEnd; 
			myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length); 
		} else { 
			myField.value += myValue; 
		} 
} 
function loadTab(item) {
	if(item == 1) {
		document.getElementById('commentlist').style.display = "none";
		document.getElementById('commentpost').style.display = "";
		document.getElementById('tabitem1').className = 'tab1';
		document.getElementById('tabitem0').className = 'tab0';
		document.getElementById('tabicon1').style.display = "";
		document.getElementById('tabicon0').style.display = "none";
	} else {
		document.getElementById('commentlist').style.display = "";
		document.getElementById('commentpost').style.display = "none";
		document.getElementById('tabitem1').className = 'tab0';
		document.getElementById('tabitem0').className = 'tab1';
		document.getElementById('tabicon1').style.display = "none";
		document.getElementById('tabicon0').style.display = "";
		var studyid = document.forms["pscomnent"].studyid.value;
		ajax_loadData("ajax.php?o=modules&n=study&f=study_comment&studyid=" + studyid, "commentlist");
	}
}
function postCommnet(studyid) {
	o = document.forms["pscomnent"];
	if(o.fullname.value == "") {
		alert(o.m_fullname.value);
		o.fullname.focus();
	} else
	if(o.phone.value != "" && !isTelephone(o.phone.value)) {
		alert(o.m_errorphone.value);
		o.phone.focus();
	} else
	if(o.email.value == "") {
		alert(o.m_email.value);
		o.email.focus();
	} else
	if(!isEmail(o.email.value)) {
		alert(o.m_erroremail.value);
		o.email.focus();
	} else 
	if(o.note.value == "") {
		alert(o.m_content.value);
		o.note.focus();
	} else {
		document.getElementById("sendpostid").disabled = true;
		document.getElementById("waitsend").style.display = '';
		params = "&studyid=" + studyid;
		params += "&fullname=" + encodeURIComponent(o.fullname.value);
		params += "&address=" + encodeURIComponent(o.address.value);
		params += "&phone=" + o.phone.value;
		params += "&email=" + o.email.value;
		params += "&note=" + encodeURIComponent(o.note.value);
		params += "&action=123";
		var options = {
			method : 'get',
			parameters : params,					
			onComplete: inReturn,
			onFailure: reportError
		};
		new Ajax.Request('ajax.php?o=modules&n=study&f=comment', options);
	}
}
