function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
     if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;
    return true;
}

//function to change page from option list
function gHideMenu() {
document.getElementById('content').style.width='950px';
document.getElementById('titleactive').style.width='950px';
document.getElementById('titlecrop-left').style.width='950px';
document.getElementById('menutogge').style.display='none';
document.getElementById('menuview').style.display='';
}
function gViewMenu() {
document.getElementById('content').style.width='590px';
document.getElementById('titleactive').style.width='590px';
document.getElementById('titlecrop-left').style.width='600px';
document.getElementById('menutogge').style.display='';
document.getElementById('menuview').style.display='none';
}

function linkURL(URL) {
	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;
	return true;
}
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}


//function to open pop up window
function winOpener(theURL, winName, scrollbars, resizable, width, height) {

	winFeatures = 'left=' + (screen.availWidth-10-width)/2 + ',top=' + (screen.availHeight-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar=0'
  	window.open(theURL, winName, winFeatures);
}

//function to open pop up window
function Openwindows(theURL, winName, scrollbars, resizable, width, height) {

	winFeatures = 'left=' + (screen.availWidth-10-width)/2 + ',top=' + (screen.availHeight-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar=0'
  	window.open(theURL, winName, winFeatures);
}

//Show drop down
function showDropDown(parentEle, dropDownEle, dropDownWidth, offSetRight){

	parentElement = document.getElementById(parentEle);
	dropDownElement = document.getElementById(dropDownEle)

	//position
	dropDownElement.style.left = (getOffsetLeft(parentElement) - offSetRight) + 'px';
	dropDownElement.style.top = (getOffsetTop(parentElement) + parentElement.offsetHeight + 3) + 'px';

	//width
	dropDownElement.style.width = dropDownWidth + 'px';

	//display
	hideDropDown();
	dropDownElement.style.visibility = 'visible';


	//Event Listener to hide drop down
	if(document.addEventListener){ // Mozilla, Netscape, Firefox
		document.addEventListener('mouseup', hideDropDown, false);
	} else { // IE
		document.onmouseup = hideDropDown;
	}
}

//Hide drop downs
function hideDropDown(){
	hide('div');
	hide('iframe');
	function hide(tag){
		var classElements = new Array();
		var els = document.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)dropDown(.*\)');

		for (i = 0, j = 0; i < elsLen; i++){
			if (pattern.test(els[i].className)){
				els[i].style.visibility='hidden';
				j++;
			}
		}
	}
}
//Top offset
function getOffsetTop(elm){
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

//Left offset
function getOffsetLeft(elm){
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

//AJAX
var xmlHttp;
var xmlHttpResponseID;

//create XMLHttpRequest object
function createXMLHttpRequest(){
	if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		if (! xmlHttp){
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
}

//XMLHttpRequest event handler
function XMLHttpResponse(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=='complete'){
		if (xmlHttp.status == 200){
			xmlHttpResponseID.innerHTML = xmlHttp.responseText;
		}else {
			xmlHttpResponseID.innerHTML = '<strong>Loading...</strong>';
		}

	}
}

//Get AJAX data
function getAjaxData(url, elementID){
	xmlHttpResponseID = document.getElementById(elementID);
//	xmlHttpResponseID.innerHTML = '<strong>Loading...</strong>';
	xmlHttpResponseID.innerHTML = '<img border="0" src="/forum/forum_images/spinner.gif"> Đang tải...';
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = XMLHttpResponse;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
var mikExp = /[$\\@\\\#%\^\&\!\*\(\)\[\]\+\.\,\<\>\?\:\;\Á\À\Ả\Ã\Ạ\Â\Ấ\Ầ\Ẩ\Ẫ\Ậ\Ă\Ắ\Ằ\Ẳ\Ẵ\Ặ\É\È\Ẻ\Ẽ\Ẹ\Ê\Ế\Ề\Ể\Ễ\Ệ\Í\Ì\Ỉ\Ĩ\Ị\Ý\Ỳ\Ỷ\Ỹ\Ỵ\Ó\Ò\Ỏ\Õ\Ọ\Ô\Ố\Ồ\Ổ\Ỗ\Ộ\Ơ\Ớ\Ờ\Ở\Ỡ\Ợ\Ú\Ù\Ủ\Ũ\Ụ\Ư\Ứ\Ừ\Ử\Ữ\Ự\Đ\á\à\ả\ã\ạ\â\ấ\ầ\ẩ\ẫ\ậ\ă\ắ\ằ\ẳ\ẵ\ặ\é\è\ẻ\ẽ\ẹ\ê\ế\ề\ể\ễ\ệ\í\ì\ỉ\ĩ\ị\ý\ỳ\ỷ\ỹ\ỵ\ó\ò\ỏ\õ\ọ\ô\ố\ồ\ổ\ỗ\ộ\ơ\ớ\ờ\ở\ỡ\ợ\ú\ù\ủ\ũ\ụ\ư\ứ\ử\ữ\ự\đ\'\"\/\{\}\`\~\=\|]/;
function dodacheck(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
if(lchar.search(mikExp) != -1) {
var tst = val.value.substring(0, (strLength) - 1);
val.value = tst;
   }
}


var mImgHeight = 0; //Max Height
var mImgWidth = 140; //Max Width
// Image Resize Onload
function IRO() {
      var myClass = document.getElementsByClassName('Resize');
      for (i = 0; i < myClass.length; i++) {
         var myTag = myClass[i].getElementsByTagName('img');
         for (i1 = 0; i1 < myTag.length; i1++) {
            if ((mImgHeight != 0 || mImgWidth != 0) && (myTag[i1].width > mImgWidth || myTag[i1].Height > mImgHeight)) {
               resize(myTag[i1]);
            }
         }
      }
}

function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}

	obj = fetch_object('collapseobj_' + objid);
	img = fetch_object('collapseimg_' + objid);
	cel = fetch_object('collapsecel_' + objid);

	if (!obj)
	{
		// nothing to collapse!
		if (img)
		{
			// hide the clicky image if there is one
			img.style.display = 'none';
		}
		return false;
	}

	if (obj.style.display == 'none')
	{
		obj.style.display = '';
		save_collapsed(objid, false);
		if (img)
		{
			img_re = new RegExp("_collapsed\\.png$");
			img.src = img.src.replace(img_re, '.png');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
			cel.className = cel.className.replace(cel_re, '$1');
		}
	}
	else
	{
		obj.style.display = 'none';
		save_collapsed(objid, true);
		if (img)
		{
			img_re = new RegExp("\\.png$");
			img.src = img.src.replace(img_re, '_collapsed.png');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)$");
			cel.className = cel.className.replace(cel_re, '$1_collapsed');
		}
	}
	return false;
}

/**
* Updates vbulletin_collapse cookie with collapse preferences
*
* @param	string	Unique ID for the collapse group
* @param	boolean	Add a cookie
*/
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie('vbulletin_collapse');
	var tmp = new Array();

	if (collapsed != null)
	{
		collapsed = collapsed.split('\n');

		for (var i in collapsed)
		{
			if (collapsed[i] != objid && collapsed[i] != '')
			{
				tmp[tmp.length] = collapsed[i];
			}
		}
	}

	if (addcollapsed)
	{
		tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie('vbulletin_collapse', tmp.join('\n'), expires);
}

function selectCode(id)
{
	// Get ID of code block
	//var e = a.parentNode.parentNode.getElementsByTagName('DIV')[2];
	var e = document.getElementById(id);

	// Not IE
	if (window.getSelection)
	{
		var s = window.getSelection();
		// Safari
		if (s.setBaseAndExtent)
		{
			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
		}
		// Firefox and Opera
		else
		{
			var r = document.createRange();
			r.selectNodeContents(e);
			s.removeAllRanges();
			s.addRange(r);
		}
	}
	// Some older browsers
	else if (document.getSelection)
	{
		var s = document.getSelection();
		var r = document.createRange();
		r.selectNodeContents(e);
		s.removeAllRanges();
		s.addRange(r);
	}
	// IE
	else if (document.selection)
	{
		var r = document.body.createTextRange();
		r.moveToElementText(e);
		r.select();
	}
}

var tt_size = 11;
var tt_lh = 24;
function ttsz_inc()
{
	if(tt_size>24) return;				
	tt_size+=2;
	tt_lh+=3;
	document.getElementById('article_container').style.fontSize = tt_size+'px';
	document.getElementById('article_container').style.lineHeight = tt_lh+'px';		    
}
function ttsz_dec()
{
	if(tt_size<10) return;		
	tt_size-=2;
	tt_lh-=3;
	document.getElementById('article_container').style.fontSize = tt_size+'px';
	document.getElementById('article_container').style.lineHeight = tt_lh+'px';
}


