function ShowMenuSP(divid,tongso,idhientai)
	{
		var i;
		var idnow = $('#menuid_'+idhientai); 
		for(i=0;i<=tongso;i++)
			{
				if(i==idhientai)
					{
						if(idnow.css('display') == 'none') 	idnow.css("display","table");
						else								idnow.css("display","none");
					}
				else
					{
						$('#menuid_'+i).css("display","none");	
					}		
			}
	}
function ShowMenuTin(divid,tongso,idhientai)
	{
		var i;
		var idnow = $('#menutin_'+idhientai); 
		for(i=0;i<=tongso;i++)
			{
				if(i==idhientai)
					{
						if(idnow.css('display') == 'none') 	idnow.css("display","table");
						else								idnow.css("display","none");
					}
				else
					{
						$('#menutin_'+i).css("display","none");
					}		
			}
	}	
function Clik()
	{
		if($('#thiet_lap_nang_cao').is(':checked')) $("#nangcap_sp").show();
		else										$("#nangcap_sp").hide();
	}
function ConfigO_SP(boxid)
	{
		if($('#'+boxid).val()==1) 
			{
				var iz;
				for(iz=1; iz<=7;iz++) { $("#op_sp"+iz).css("display","table-row"); }
			}
		else
			{
				var ik;
				for(ik=1; ik<=7;ik++) { $("#op_sp"+ik).css("display","none"); }	
			}
	}	
function ConfigO_Tin(boxid)
	{
		if($('#'+boxid).val()==1) 
			{
				var iz;
				for(iz=1; iz<=6;iz++) { $("#op_tin"+iz).css("display","table-row"); }
			}
		else
			{
				var ik;
				for(ik=1; ik<=6;ik++) { $("#op_tin"+ik).css("display","none"); }	
			}
	}		
function checkinput(NOWTIC)
	{
		$('#num2word').text(Num2Word(NOWTIC));
	}
function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}	
function CheckValueIn(byid,byvalu,byprice,bymoney,byword)
	{		
		var aMax 	 = document.getElementById([byid]).value;
		var aSoluong = document.getElementById([byvalu]).value;
		var aGia 	 = document.getElementById([byprice]).innerHTML;
		var aTien 	 = document.getElementById([bymoney]).innerHTML;
		
		var tempMAX = parseInt(aMax);
		var tempVAX = parseInt(aSoluong);
		var tempGAX = parseInt(aGia);
		var tempTIX = parseInt(aTien);
		
		if(tempVAX > tempMAX) 
			{
				alert('Giá trị không được lớn hơn '+tempMAX);	
				document.getElementById([byvalu]).value	= tempMAX;
			}
		if(tempVAX < 1) 
			{
				alert('Giá trị không được nhỏ hơn 1');	
				document.getElementById([byvalu]).value	= 1;
			}
		NOWTIC = 	tempGAX * document.getElementById([byvalu]).value;
		document.getElementById([bymoney]).innerHTML = 	NOWTIC; //addCommas(NOWTIC)
		//document.getElementById([byword]).innerHTML = '<i>'+Num2Word(NOWTIC)+'</i>';
		
		var TOTO  = 	document.getElementById('maxvalue').value;
		var mySum = 0;
		for(c=1;c<TOTO;c++)
			{
				myVa	= document.getElementById(['fullmoney'+c]).innerHTML;
				mySum	+= parseInt(myVa);
			}
		document.getElementById('ttmoney').innerHTML = 	addCommas(mySum)
		document.getElementById('tt2word').innerHTML = '<i>'+Num2Word(mySum)+'</i>';
	}		
function numbersonly(e, decimal) 
	{
		var key;
		var keychar;
		if (window.event) {
		   key = window.event.keyCode;
		}
		else if (e) {
		   key = e.which;
		}
		else {
		   return true;
		}
		keychar = String.fromCharCode(key);
		////
		
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
		   return true;
		}
		else if ((("0123456789").indexOf(keychar) > -1)) {
		   return true;
		}
		else if (decimal && (keychar == ".")) { 
		  return true;
		}
		else return false;
	}
function Num2Word(num,fmt) 
	{
		num = Math.round(num).toString(); // round value
		if (num == 0) return 'chưa thiết lập giá bán hoặc giá bán là thương lượng'; // if number given is 0, return and exit
	//_ locals
		// word numbers
		var wnums = [
		['trăm','ngàn','triệu','tỷ','ngàn tỷ','ngàn ngàn tỷ'],
		['một','nhất','mười','',' '],
		['hai','thứ hai','hai mươi',0,0],
		['ba','ba','ba mươi',0,0],
		['bốn','bốn','bốn mươi',0,0],
		['năm','lăm','năm mươi',0,0],
		['sáu','sáu','sáu mươi',0,0],
		['bảy','bảy','bảy mươi',0,0],
		['tám','tám','tám mươi',0,0],
		['chín','chín','chín mươi',0,0],
		['mười',],
		['mười một','hai mốt'],
		['mười hai','hai mươi hai'],
		['mười ba',],
		['mười bốn','bốn mươi'],
		['mười lăm',],
		['mười sáu',],
		['mười bảy',],
		['mười tám',],
		['mười chín',]
		];
	
		// digits outside triplets
		var dot = (num.length % 3) ? num.length % 3 : 3;
		var sets = Math.ceil(num.length/3);
		var rslt = '';	
		for (var i = 0; i < sets; i++) 
		{ // for each set of triplets
			var subt = num.substring((!i) ? 0 : dot + (i - 1) * 3,(!i) ? dot : dot + i * 3);
			if (subt != 0) 
			{ // if value of set is not 0...
				var hdec = (subt.length > 2) ? subt.charAt(0) : 0; // get hundreds digit
				var ddec = subt.substring(Math.max(subt.length - 2,0),subt.length); // get double digits
				var odec = subt.charAt(subt.length - 1); // get one's digit
				// hundreds digit
				if (hdec != 0) rslt += ' ' + wnums[hdec][0] + ' trăm ' + ((fmt && ddec == 0) ? ' ' : '');
				// add double digit
				if (ddec < 20 && 9 < ddec) 
				{ // if less than 20...
					// add double digit word
					rslt += ' ' + ((fmt) ? ((wnums[ddec][1]) ? wnums[ddec][1] : wnums[ddec][0] + ' ') : wnums[ddec][0]);
				} 
				else 
				{ // otherwise, add words for each digit...
					// add "and" for last set without a tens digits
					if ((0 < hdec || 1 < sets) && i + 1 == sets && 0 < ddec && ddec < 10) rslt += 'và ';
					// tens digit
					if (19 < ddec) rslt += wnums[ddec.charAt(0)][(wnums[ddec.charAt(0)][2]) ? 2 : 0] + ((i + 1 == sets && odec == 0 && fmt) ? 'tieth' : ' ') + ((0 < odec) ? ' ' : ' ');
					// one's digit
					if (0 < odec) rslt += wnums[odec][(i + 1 == sets && fmt) ? 1 : 0];
				}
				// add place for set
				if (i + 1 < sets) rslt += ' ' + wnums[0][sets - i - 1] + ' '; // if not last set, add place
			} 
			else if (i + 1 == sets && fmt) 
			{ // otherwise, if this set is zero, is the last set of the loop, and the format (fmt) is cardinal
				rslt += ' '; // add cardinal "th"
			}
		}
	//_ return result
		var str1='mươi  năm';
		var str2='mươi lăm';
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		str1='mươi  một';
		str2='mươi mốt';
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		rslt=rslt.replace(str1,str2);
		//alert(rslt);
		return rslt+' đồng';
	}		
////////
function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}
////////
function hidden() {document.body.style.overflow='hidden';}
function unhidden() {document.body.style.overflow='';}
function SetFontFormat(goCmd,fName)
	{
		doFonts(fName,goCmd);
	}
function HiddenDropDown(obj_move)
	{
		document.getElementById([obj_move]).style.display 		= 'none';
	}
function ShowDropDown(obj_here,obj_move,rw,rh,R,C)
	{
		setLyr(obj_here,obj_move,rw,rh);
		document.getElementById([obj_move]).style.width 		= R;
		document.getElementById([obj_move]).style.height 		= C;
		document.getElementById([obj_move]).style.display 		= '';
	}
function setLyr(obj_here,obj_move,rw,rh)
	{
		var newX = findPosX(obj_here)+ rw;
		var newY = findPosY(obj_here)- rh;
		document.getElementById([obj_move]).style.top 			= newY + 'px';
		document.getElementById([obj_move]).style.left 			= newX + 'px';
	}
function findPosX(obj_here) 
	{
		obj = document.getElementById([obj_here]);
		var curleft = 0;
		if(obj.offsetParent)
			while(1) 
			{
			  curleft += obj.offsetLeft;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.x) 
			curleft += obj.x;
		return curleft;
	}
function findPosY(obj_here)
	{
		obj = document.getElementById([obj_here]);
		var curtop = 0;
		if(obj.offsetParent)
			while(1)
			{
			  curtop += obj.offsetTop;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.y)
			curtop += obj.y;	
		return curtop;
	}
function CreateBookmarkLink() 
	{ 
		var title = "Hệ thống kinh doanh 1ty.vn";   
		var url = "http://www.1ty.vn/";  
		if (window.sidebar) 
			{ 
				window.sidebar.addPanel(title, url,"");	
			} 
		else if( window.external ) 
			{ 
				window.external.AddFavorite( url, title); 
			}	
		else if(window.opera && window.print) 
			{ 
				return true; 
			} 
	}
function MoveBottom()
	{
		var objDiv=document.getElementById('AlwayOnBot');
		var o_H = objDiv.clientHeight;
		if (document.all)
			{
				objDiv.style.top=(document.body.scrollTop+parseInt((document.body.clientHeight-o_H)))+"px";
			}
		else 
			{
				objDiv.style.top=(document.body.scrollTop+parseInt((document.body.clientHeight-o_H)))+"px";
			}
	}
function changegamelist(num)
	{
		var i ;
		for(i=1;i<=12;i++)
		{
			if(i==num)
			{
				if(document.getElementById("buttd"+i)!=null)
				{
						document.getElementById("buttd"+i).className = "list-bg-title1";
						document.getElementById("divgame").innerHTML = document.getElementById("divgame"+i).innerHTML;
				}
			}
			else
			{
				if(document.getElementById("buttd"+i)!=null)
				{
						document.getElementById("buttd"+i).className = "list-bg-title2";
				}
			}
		}
	
	}

	function ChangTabsHome(num)
	{
		var i ;
		for(i=1;i<=4;i++)
		{
			if(i==num)
			{
				document.getElementById("scriptbuttd"+i).className = "color_2";
				document.getElementById("divscript").innerHTML = document.getElementById("divscript"+i).innerHTML;				
			}
			else
			{
				document.getElementById("scriptbuttd"+i).className = "color_1";
			}
		}
	
	}

  function change3(num)
	{
		var i ;
		for(i=1;i<=4;i++)
		{
			if(i==num) document.getElementById("m_divscript").innerHTML = document.getElementById("m_divscript"+i).innerHTML;				
		}
	
	}
	
  function change2(num)
	{
		var i ;
		for(i=1;i<=2;i++)
		{
			if(i==num)
			{
				document.getElementById("scriptbuttd"+i).className = "center-script-bg-title1";
				document.getElementById("divscript").innerHTML = document.getElementById("divscript"+i).innerHTML;				
			}
			else
			{
				document.getElementById("scriptbuttd"+i).className = "center-script-bg-title2";
			}
		}
	
	}
	
	function change(num,numcount)
	{
		var i ;
		for(i=1;i<=numcount;i++)
		{
			if(i==num)
			{
				document.getElementById("buttdv"+i).className = "page-bg-menu3";
			}
			else
			{
				document.getElementById("buttdv"+i).className = "page-bg-menu4";
			}
		}
	
	}
	
	function ShowGameDiv(isshow)
	{
		var divobj = document.getElementById("divgamelist");
		if(isshow)
			divobj.style.display = "";
		else
			divobj.style.display = "none";
	}
	function updatepage(id)
	{
		id 				= id.trim();
		var namecom		= 'newcomm';
		name = namecom.concat(id);
		loadContent('/ajax/vcomment.php/'+id+'/', name,1);
	}
function ShowMe(id)
	{
		var myid = document.getElementById(id);
		myid.style.display = '';
	}
function CloseMe(id)
	{
		var myid = document.getElementById(id);
		myid.style.display = 'none';
	}
function DongUngDung(id)
	{
		var ungdung = document.getElementById(id);
		var bgr 	= document.getElementById('backgr');
		ungdung.style.display = 'none';
		bgr.style.display = 'none';
		unhidden();
	}
function UngDung(id)
	{
		hidden();
		var ungdung = document.getElementById(id);
		var bgr 	= document.getElementById('backgr');
		setLyr(id,'backgr',-800,900);
		ungdung.style.display = '';
		bgr.style.display = '';
		ShowOne('thucthiungdung');
		loadContent('/ungdung.php', id,1);
	}
function showout()
	{
		document.getElementById("loadingdiv").style.display = 'none';
	}
function showone()
	{
		document.getElementById("loadingdiv").style.display = '';
		ShowDiv('loadingdiv');
		setTimeout("ShowDiv('loadingdiv')",100);
	}	
function ShowDiv(id)
	{
		var CPW_show = document.getElementById('loadingdiv');
		var o_W = CPW_show.clientWidth;
		var o_H = CPW_show.clientHeight;
		CPW_show.style.left=(document.body.scrollLeft+parseInt((document.body.clientWidth-o_W)/2))+"px";
		CPW_show.style.top=(document.body.scrollTop+parseInt((document.body.clientHeight-o_H)/2))+"px";
	}
function FormatListAffiche()
{
   	 var obj1 = document.getElementById("divaffiche");
	   var obj1str = getValue(obj1);
	   if(obj1str.length > 150)
	   {
	   	 obj1str = obj1str.substring(0,150) + "¡­¡­";
		   setValue(obj1,obj1str);
	   }	  
}

 function getValue(e)
{
	if(navigator.appName.indexOf("Explorer") > -1)
	{
    	return e.innerText;
	} 
	else
	{
    	return e.textContent;
	}
}
function setValue(e,str)
{
	if(navigator.appName.indexOf("Explorer") > -1)
	{
    	e.innerText = str;
	} 
	else
	{
    	e.textContent = str;
	}
}

function setHomepage()
	{
	if (document.all)
		{
			document.body.style.behavior='url(#default#homepage)';
			document.body.setHomePage('http://www.1ty.vn/');
		}
	else if (window.sidebar)
		{
			if(window.netscape)
				{
				try
					{  
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
					}  
				catch(e)  
					{  
							alert("Trình duyệt của bạn hiện tại chưa hỗ trợ chức năng này, để hỗ trợ bạn gõ about:config vào thanh địa chỉ\n tìm đến dòngsigned.applets.codebase_principal_support click vào để chuyển nó trành TRUE");  
					}
				}
			
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage','http://www.1ty.vn/');
				
		}
	}
function QuickBox()

		{

			var o = $('#quick_box'); 

			if (o.css('display') == 'none') {

				o.show();

				//a.hide();

			} else {

				o.hide();

				//a.show();

			}

		}	
function RegForm()
{
	with (document.TheFormX)
	{		
			if (hovaten.value=="")
			{
					alert("Xin vui lòng nhập vào họ tên người liên hệ!");
					hovaten.focus();
					return false;
			}
			if (diachi.value=="")
			{
					alert("Xin vui lòng nhập vào địa chỉ người liên hệ!");
					diachi.focus();
					return false;
			}
			if (email.value=="")
			{
					alert("Hãy nhập vào địa chỉ Email mà bạn đang sử dụng");
					email.focus();
					return false;
			}
			else
			{
					if(email.value.indexOf("@")<0||email.value.indexOf(".")<0)
					{
							alert("Địa chỉ email phải đúng cú pháp, ví dụ: info@1ty.vn!");
							email.focus();
							return false;
					}
			}
			if (dienthoai.value=="")
			{
					alert("Xin vui lòng nhập vào số điện thoại để chủ eShop liên lạc với bạn nhanh nhất!");
					dienthoai.focus();
					return false;
			}

		}

	return true;

}	

function Check_Shopping_Cart()
{
	with (document.TheFormX)
	{		
			if (tendaydu.value=="")
			{
					alert("Xin vui lòng nhập vào họ tên người liên hệ!");
					tendaydu.focus();
					return false;
			}
			if (email.value=="")
			{
					alert("Hãy nhập vào địa chỉ Email mà bạn đang sử dụng");
					email.focus();
					return false;
			}
			else
			{
					if(email.value.indexOf("@")<0||email.value.indexOf(".")<0)
					{
							alert("Địa chỉ email phải đúng cú pháp, ví dụ: info@1ty.vn!");
							email.focus();
							return false;
					}
			}
			if (diachi.value=="")
			{
					alert("Xin vui lòng nhập vào địa chỉ liên lạc của bạn!");
					diachi.focus();
					return false;
			}
			if (dienthoai.value=="")
			{
					alert("Xin vui lòng nhập vào số điện thoại để chủ eShop liên lạc với bạn nhanh nhất!");
					dienthoai.focus();
					return false;
			}

		}

	return true;

}		
