// Define themes
// [Ten filme]| Starting | Ending
var themes = Array();
themes[0]="themes/theme.css|5:00|10:00";
themes[1]="themes/theme1.css|10:01|16:00";
themes[2]="themes/theme2.css|16:01|19:00";

function chkTime(){
	//alert(themes.length);
	var tmp = '';
	var style_file = '';
	var curtime = new Date();
	var curr_hour = curtime.getHours();
	var curr_min = curtime.getMinutes();		
	for(i=0; i<themes.length; i++){
		tmp	= themes[i].split("|");			
		s_time = tmp[1].split(":");
		e_time = tmp[2].split(":");		
		if (((curr_hour>s_time[0])&&(curr_hour<e_time[0])) || ((curr_hour==s_time[0])&&(curr_min>s_time[1])) || ((curr_hour==e_time[0])&&(curr_min<e_time[1]))) {
			style_file = tmp[0];			
			//break;
		}
	}
	if (style_file=='') {
		style_file = "themes/theme3.css";
	}		
	createStyle(style_file);
}
function createStyle(style_file){
	if(document.createStyleSheet) {
		document.createStyleSheet(style_file);			
	} else {	
		url = window.location.href;
		ip_host = url.split("#");		
		var styles = "@import url(' "+ ip_host[0] + style_file +" ');";	
		var newSS=document.createElement('link');	
		newSS.rel='stylesheet';	
		newSS.href='data:text/css,'+escape(styles);	
		document.getElementsByTagName("head")[0].appendChild(newSS);			
	}
}
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;
}
var intValue = null;
var totalTimeout = 0;
var totalTimeout1 = 0;

function activeMenu(nameID, id, total, class_name, class_name1){
	var i=1;		
	document.getElementById(nameID+id).className = class_name;
	for (i=1; i<total+1; i++) {
		if (i!=id) {
			curID = nameID + i.toString();			
			document.getElementById(curID).className = class_name1;
		}
	}	
}
function defaultMenu(nameID, total, class_name){
	var i=1;
	for (i=1; i<total+1; i++) {		
		curID = nameID + i.toString();			
		document.getElementById(curID).className = class_name;		
	}	
}
//View module
function goMod(nameID, id, total, class_name, class_name1, url, elm) {
	//activeMenu(nameID, id, total, class_name, class_name1);
	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 "faq":
			activeMenu("fmenu");
			break;
		case "sitemap":
			activeMenu("smenu");
			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;
}

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]; 
}

//Reload page
function goPage(url, idelm, sts) {
	window.location.href = url;
	window.scrollTo(0,0);
	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), "ihdshow");
	JAJAX.load("ajax.php?f=left&pp=" + sss[0] + getPar(sss), "rblock");
	JAJAX.load("ajax.php?f=block_footer&pp=" + sss[0] + getPar(sss), "block_footer");
	JAJAX.load("ajax.php?f=banner&pp=" + sss[0] + getPar(sss), "bannershow");
	JAJAX.load("ajax.php?f=footer&pp=" + sss[0] + getPar(sss), "iftshow");
	JAJAX.load(page, idelm);	
	if (sss[2]=='home') {		
		loadSlide();
	} else
		clearTimeout(intValue);
}
function goLang(lang) {	
	JAJAX.load("ajax.php?f=setLang&Language="+lang,"iftshow");
	linktop = window.location.href;	
	if(linktop.indexOf("#") <= 0) 
		linktop = "#main/f/home";		
	var sss = getMod(linktop);
	if (sss[2]=='home') {		
		loadSlide();
	} else
		clearTimeout(intValue);
	window.location.href = "#" + sss[0] + "/" + sss[1] + "/" + sss[2].replace("_detail","");
	setTimeout('reLoad(0)', 500);
}
//View on submenu
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);
	if (sss[2]=='home') {		
		loadSlide();
	} else
		clearTimeout(intValue);
}
//View detail
function goText(url, idelm) {
	window.location.href = url;
	window.scrollTo(0,0);
	setUrl(url);
	page = decodeUrl(url);
	JAJAX.load(page, idelm);
	if (sss[2]=='home') {		
		loadSlide();
	} else
		clearTimeout(intValue);
	

}

function loadMenu(url, idelm, pos, idpos) {
	var top_hover = 'topmenu';
	var top_active = 'topmenu_hover';
	var top_total = 4;
	
	var left_hover = 'leftmenu';
	var left_active = 'leftmenu_hover';
	var left_total = 6;
	
	var bottom_hover = 'footermenu';
	var bottom_active = 'footermenu_hover';
	var bottom_total = 4;
	
	switch (pos){
		case 'topmenu':
			activeMenu(pos, idpos, top_total, top_active, top_hover);
			activeMenu('footermenu', idpos, bottom_total, bottom_active, bottom_hover);
			defaultMenu('leftmenu', left_total, 'leftmenu');			
			break;
		case 'leftmenu':
			activeMenu(pos, idpos, left_total, left_active, left_hover);
			defaultMenu('topmenu', top_total, 'topmenu');
			defaultMenu('footermenu', bottom_total, 'footermenu');
			break;
		case 'footermenu':
			activeMenu(pos, idpos, bottom_total, bottom_active, bottom_hover);
			activeMenu('topmenu', idpos, top_total, top_active, tophover);
			defaultMenu('leftmenu', left_total, 'leftmenu');
			break;	
	}
	window.location.href = url;
	page = decodeUrl(url);
	var sss = getMod(url);
	JAJAX.load("ajax.php?f=left&pp=" + sss[0] + getPar(sss), "lblock");
	JAJAX.load(page, idelm);
	if (sss[2]=='home') {
		loadSlide();
	} else
		clearTimeout(intValue);
}
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) {
			alert(ss[2]);
			goText('#'+ss[1],'fulltext');
			//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=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 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 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(sts) {
	linktop = window.location.href;
	if(linktop.indexOf("#") <= 0) 
		linktop = "#main/f/home";
	if(typeof(sts) == 'undefined')
		sts = 0;		
	goPage(linktop, "fulltext", sts);
	var sss = getMod(linktop);	
	if (sss[2]=='home') {		
		loadSlide();
	} else
		clearTimeout(intValue);		
	chkTime();
	JAJAX.load("ajax.php?f=header", "ihdshow");
	JAJAX.load("ajax.php?f=footer", "iftshow");	
}

loadlink = 0;
function initWeblink(){		
	if (document.getElementById('chromemenu123')) {
		cssdropdown.startchrome("chromemenu123");
	}  else
		if(loadlink < 10000) {
			setTimeout('initWeblink()', 1000);
			loadlink += 1000;
		}
}
var timeout=null;
function loadSlide(){		
		if (document.getElementById('bnpicture')) {
				getListSlide();	
				showSP();
		} else {
			if(totalTimeout < 10000) {
				timeout = setTimeout('loadSlide()', 1000);
				totalTimeout += 1000;
			}
		}
}
//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;
	intValue = 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));
}
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));
}
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));
}
function checkPost() {
	dml = document.frsup;
	if(dml.fullname.value == "") {
		alert(dml.m_fullname.value);
		dml.fullname.focus();
	} else 
	if ((dml.email.value=='')||(!isEmail(dml.email.value))) {
		alert(dml.m_email.value);
		dml.email.focus();
	} else 
	if(dml.phone.value != "" && !isTelephone(dml.phone.value)) {
		alert(dml.m_phone.value);
		dml.phone.focus();
	} else 
	if(dml.question.value == "") {
		alert(dml.m_question.value);
		dml.question.focus();
	} else {
		document.getElementById("waitsend").style.display = 'none';
			params = "&fullname=" + encodeURIComponent(dml.fullname.value);
			params += "&email=" + encodeURIComponent(dml.email.value);
			params += "&phone=" + encodeURIComponent(dml.phone.value);
			params += "&idsupporttype=" + encodeURIComponent(dml.idsupporttype.value);
			params += "&question=" + encodeURIComponent(dml.question.value);
			params += "&action=123";
			
			var options = {
				method : 'get',
				parameters : params,					
				onComplete: inReturn,
				onFailure: reportError
			};			
			new Ajax.Request('ajax.php?o=modules&n=support&f=support', options);
	}
}
function changeGroup() {
	idsupporttype = document.getElementById("supporttypeid").value;
	if(idsupporttype > 0)
		goText("#support/f/support/idtype/" + idsupporttype,'fulltext');
}
function stesfile(filename) {
var re_text = /\.txt|\.xml|\.zip/i;    
if (filename.search(re_text) == -1)
alert("File khong hop le!");
else
alert("File hop le!");
} //Kiem tra ten file tu javascript

function changeWebLink() {
	var weblink = document.getElementById('weblink').value;
	url = weblink.split("#");
	if(weblink != "")
		if(url[1] == "1")
			window.open(url[0]);
		else window.location.href = url[0];
}