function lang_change(url,lang) {
	if(url.indexOf('?')<0)document.location = url+"?lang="+lang;
	else document.location = url+"&lang="+lang;
}
function cate_change(value) {
	var obj = document.getElementById('path_cate');
	if(obj)obj.innerHTML = ' &rArr;'+ value;
}
function setpanel(pn1,pn2){
	var obj = document.getElementById('left_panel');
	if(obj&&pn1)obj.style.display = ''
	else if(obj) obj.style.display = 'none'
	obj = document.getElementById('right_panel');
	if(obj&&pn2)obj.style.display = ''
	else if(obj) obj.style.display = 'none'	
}
function ModuleExpanse(id,imgPath){
	if (typeof(document.getElementById)=='undefined')return;
	Name = document.getElementById(id);
	if(!Name)return;
	var MItem=document.getElementById(Name.id+'_ex');
	var image=document.getElementById(Name.id+'_image');
	if(!MItem) return;
	if (MItem && MItem.style.display!=''){
		MItem.style.display='';
		if(image){
		image.src= imgPath+'/min.gif';
		image.title='Collapse!';
		image.alt='Collapse!';
		}
	}else{
		MItem.style.display='none';
		if(image){
		image.src= imgPath+'/max.gif';
		image.title='Expanse!';
		image.alt='Expanse!';
		}
	}
}
function switchpanel(pn) {
	if(!fDSp){return;}
	var objLeft = document.getElementById('left_panel');
	var objRight = document.getElementById('right_panel');
	//var Image
	switch (pn)	{
	case 0:
		if((objLeft&&(objLeft.style.display!=''))||(objRight&&(objRight.style.display!=''))){
			if(objLeft)objLeft.style.display = '';
			if(objRight)objRight.style.display = '';
		}else{
			if(objLeft)objLeft.style.display = 'none';
			if(objRight)objRight.style.display = 'none';
		}
		break;		
	case 1:
		if(objLeft){
			if (objLeft.style.display != '')objLeft.style.display = '';
			else objLeft.style.display = 'none';
		}
		break;
	case 2:
		if(objRight){
			if (objRight.style.display != '')objRight.style.display = '';
			else objRight.style.display = 'none';
		}		
		break;
	}
}
//COOKIES FUNCTION
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function setCookie(c_name, value, expDays){
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +value+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}
function getCookie(c_name,defValue){
	if (document.cookie.length>0){ 
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			alert('from getCookie: '+c_name+'='+document.cookie.substring(c_start,c_end))
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	if(typeof(defValue)!='undefined')return defValue
	return null
}
function SetParameter(pFile, pName, pVal){
	if ((cPost=pFile.indexOf('&'.concat(pName).concat('=')))==-1)cPost=pFile.indexOf('?'.concat(pName).concat('='));

	if (cPost >= 0)	{
		if ((pPost=pFile.indexOf('&', cPost + 1))==-1)		{
			pFile=pFile.substring(0, cPost + pName.length + 2).concat(pVal);
		}else		{
			pFile=pFile.substring(0, cPost + pName.length + 2).concat(pVal).concat(pFile.substr(pPost));
		}
	}	else	{
		if (pFile.indexOf('?')==-1)		{
			pFile=pFile.concat('?').concat(pName).concat('=').concat(pVal);
		}else	{
			pFile=pFile.concat('&').concat(pName).concat('=').concat(pVal);
		}
	}
	return pFile;
}
//DATETIME FUNCTION
function mygetDate(d){
	if(d <10){
		return '0'.concat(d);
	}else {
		return d;
	}
}
function str2dt (str_datetime) {
	var re_date = /^(\d+)\/(\d+)\/(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Không đúng định dạng ngày tháng: "+ str_datetime +". Hãy nhấn nút xóa, rồi chọn lại.");
	return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
}
function dt2dtstr (dt_datetime) {
	var temp = 0;
	temp = (dt_datetime.getMonth()+1);
	if(temp<10)temp="0"+temp;
	return (new String (
			mygetDate(dt_datetime.getDate())+"-"+temp+"-"+dt_datetime.getFullYear()+" "));
}
function getToday() {
	return dt2dtstr(new Date()) + dt2tmstr(new Date());
}
function dt2tmstr (dt_datetime) {
	return (new String (
			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}
/* send request */
function SendHttp(url, method, callback, data, urlencoded) {	
    var req;	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4) {// only if req shows "loaded"
			if (req.status < 400) (method=="POST") ? callback(req) : callback(req,data);// only if "OK"	
		}
		else{
			//alert("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
			//showLoading();	
			return;
		}
	}
	if (method=="POST") {
		req.open("POST", url, true);
		if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		req.send(data);
	} else {	
		req.open("GET", url, true);
		req.send(null);
	}	
	return req;
}
//END DATETIME FUNCTION
function isSure(theStr){
return confirm(theStr);
}
function isLogout(){
return confirm("Bạn có chắc chắn muốn ĐĂNG XUẤT khỏi hệ thống?");
}

function checkfeedback(theF){
if (theF.fb_name.value==""){
alert ("Ban chua nhap Ho va ten");
theF.fb_name.focus();
return (false);
}
if (theF.fb_add.value==""){
alert ("Ban chua nhap Dia chi");
theF.fb_add.focus();
return (false);
}
if (theF.fb_tel.value==""){
alert ("Ban chua nhap So dien thoai");
theF.fb_tel.focus();
return (false);
}
if (theF.fb_mail.value!=""){
if (theF.fb_mail.value.indexOf('@',0)==-1 || theF.fb_mail.value.indexOf('.')==-1){
	alert ("Ban nhap sai Dia chi Email.");
	theF.fb_mail.focus();
	return (false);
}}
if (theF.fb_title.value.length<5){
alert ("Xin cho biet ban Quan tam ve van de gi?");
theF.fb_title.focus();
return (false);
}
if (theF.fb_content.value.length<10){
alert ("Xin cho y kien dung dan.");
theF.fb_content.focus();
return (false);
}
if (theF.fb_content.value.length>4000){
alert ("Y kien toi da 4000 ky tu.");
theF.fb_content.focus();
return (false);
}

return (true);
}
function checkNull(msg,objInput,minChar){
	if(typeof(objInput)=='undefined')return false;
	if(minChar && Trim(objInput.value).length<minChar)return assSays(msg,objInput,false);
	if(Trim(objInput.value)=="")return assSays(msg,objInput,false);
	return true;
}
function assSays(msg,objFocus,ret){
	alert(msg);
	if(objFocus)objFocus.focus();
	return (ret);
}
function checkReg(f){
var msg="Không được để trống ở những ô có dấu (*)!\nVà xin bạn nhập thông tin thật sự của mình";
if(f.im_reseller.value==0){
if(!checkNull(msg,f.fullname)) return false;
if(!checkNull(msg,f.name)) return false;
if(!checkNull(msg,f.address)) return false;
if(CheckEmailAddress(f.email.value).length <2)return assSays("E-mail không hợp lệ!\nGõ chính xác e-mail của bạn để chúng tôi xác nhận thông tin",f.email,false);
if(!checkNull(msg,f.tel)) return false;
if(!checkNull(msg,f.fullname_contact)) return false;
if(!checkNull(msg,f.address_contact)) return false;
if(!checkNull(msg,f.tel_contact)) return false;
if(CheckEmailAddress(f.email_contact.value).length <2)return assSays("E-mail không hợp lệ!\nGõ chính xác e-mail của bạn để chúng tôi xác nhận thông tin",f.email_contact,false);
} else {
if(parseInt(f.selected_services.value)<1)return assSays("Hãy chọn dịch vụ muốn đăng ký!",null,false);
if(typeof(f.custom_service)!='undefined' && f._custom.checked && f.custom_service.style.display =='' && Trim(f.custom_service.value)=="")return assSays("Xin chọn dịch vụ muốn đăng ký.",f.custom_service,false);
}
if(!checkNull("Xin nhập vào mã xác nhận!\nMã xác nhận phải có độ dài đúng 5 kí tự.",f.verifycode,5))return false;
if(!f.agree.checked)return assSays("Xin đọc kĩ điều khoản!\nVà đồng ý với điều khoản bạn mới có thể tiếp tục đăng ký.",f.agree,false);
return true;
}


function maskKeyPress(e){
	var kCode = e.charCode;
	if(typeof(kCode) =='undefined')kCode = e.keyCode;
	if((kCode>=48&&kCode<=57)||kCode==8||kCode==9||kCode==0)return true;
	else return false;
	/*window.alert("Bạn chỉ được phép nhập số!");
	return false;}*/
}

function openWinreview(url) {
	popupWin = window.open(url,'new_page','width=460,height=350')
}

function openWindow2(url) {
 	popupWin = window.open(url,'new_page','width=450,height=150')
}

function openWindow(theURL, winName, scrollbars, resizable, width, height, menubar) {	
winFeatures = 'left=' + (screen.width-10-width)/2 + ',top=' + (screen.height-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar='+menubar;
window.open(theURL, winName,winFeatures );
}
function swap_objdiv(obj, hidden) {
	if(obj)obj= document.getElementById(obj)
	if(obj)obj.style.display = hidden;
}