function linkURL(URL) {
	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;
	return true;
}
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);
}
function showDropDown(parentEle, dropDownEle, dropDownWidth, offSetRight){

	parentElement = document.getElementById(parentEle);
	dropDownElement = document.getElementById(dropDownEle)
	dropDownElement.style.left = (getOffsetLeft(parentElement) - offSetRight) + 'px';
	dropDownElement.style.top = (getOffsetTop(parentElement) + parentElement.offsetHeight + 3) + 'px';
	dropDownElement.style.width = dropDownWidth + 'px';
	hideDropDown();
	dropDownElement.style.visibility = 'visible';
	if(document.addEventListener){ // Mozilla, Netscape, Firefox
		document.addEventListener('mouseup', hideDropDown, false);
	} else { // IE
		document.onmouseup = hideDropDown;
	}
}
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++;
			}
		}
	}
}
function getOffsetTop(elm){
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}
function getOffsetLeft(elm){
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}
var xmlHttp;
var xmlHttpResponseID;
function createXMLHttpRequest(){
	if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		if (! xmlHttp){
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
}
function XMLHttpResponse(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=='complete'){
		if (xmlHttp.status == 200){
			xmlHttpResponseID.innerHTML = xmlHttp.responseText;
		}else {
			xmlHttpResponseID.innerHTML = '<strong>Lỗi khi kết nối đến server</strong>';
		}

	}
}
function getAjaxData(url, elementID){
	xmlHttpResponseID = document.getElementById(elementID);
	xmlHttpResponseID.innerHTML = '<img border="0" src="images/default/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;
}
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 isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

function GCC_hide_tool(hideThis, changeThis, setThis, exText, colText) {
	if(document.getElementById(hideThis).style.display == '') {
		document.getElementById(hideThis).style.display = 'none';
		if(document.getElementById(changeThis) != null)
			document.getElementById(changeThis).innerHTML = exText;
		document.getElementById(setThis).value = 'true';
	} else {
		document.getElementById(hideThis).style.display = '';
		if(document.getElementById(changeThis) != null)
			document.getElementById(changeThis).innerHTML = colText;
		document.getElementById(setThis).value = 'false';
	}
}

function GCC_hide_toolImage(hideThis, changeThis, setThis, expandUrl, collapseUrl, exText, colText) {
	if(document.getElementById(hideThis).style.display == '') {
		document.getElementById(hideThis).style.display = 'none';
		if(document.getElementById(changeThis) != null) {
			document.getElementById(changeThis).src = expandUrl;
			document.getElementById(changeThis).alt = exText;
		}
		document.getElementById(setThis).value = 'true';
	} else {
		document.getElementById(hideThis).style.display = '';
		if(document.getElementById(changeThis) != null) {
			document.getElementById(changeThis).src = collapseUrl;
			document.getElementById(changeThis).alt = colText;
		}
		document.getElementById(setThis).value = 'false';
	}
}

function CollapsablePanel_DoNothing() {}

//Popup full screen
winWidth = 800;
winheight = 600;

if (screen)
{
   winWidth = screen.width;
   winHeight = screen.height;
}
   

function popupWindowFull(win){
   
    newWindow = window.open(win,'newWin','toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+winWidth+',height='+winHeight+',left=0,top=0');
    newWindow.focus();
}

//Function to open link in main window
function openInMainWin(winLocation){
	window.opener.location.href = winLocation
	window.opener.focus();
	window.close();
}
