//document.onselectstart=new Function('return false');
//document.oncontextmenu=new Function("alert('Copyright by Cyclo');return false")
// define a few variables that are required
var vbmenu_usepopups = true;
var ignorequotechars = 0;


// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));

// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;


// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = "std";
}
else if (document.all)
{
	vbDOMtype = "ie4";
}
else if (document.layers)
{
	vbDOMtype = "ns4";
}




// function to open a generic window
function openWindow(url, width, height)
{
	var dimensions = "";
	if (width)
	{
		dimensions += ",width=" + width;
	}
	if (height)
	{
		dimensions += ",height=" + height;
	}

	window.open(url, "hf_popup", "statusbar=no,menubar=no,toolbar=no,scrollbars=no,resizable=no,left=150,top=150"+ dimensions);
	return false;
}



// function to do a single-line conditional
function iif(condition, trueval, falseval)
{
	return condition ? trueval : falseval;
}


// function to search an array for a value
function in_array(ineedle, haystack, caseinsensitive)
{
	var needle = new String(ineedle);

	if (caseinsensitive)
	{
		needle = needle.toLowerCase();
		for (i in haystack)
		{
			if (haystack[i].toLowerCase() == needle)
			{
				return i;
			}
		}
	}
	else
	{
		for (i in haystack)
		{
			if (haystack[i] == needle)
			{
				return i;
			}
		}
	}
	return -1;
}

function js_toggle_all(formobj, formtype, option, exclude, setto)
{
	for (var i =0; i < formobj.elements.length; i++)
	{
		var elm = formobj.elements[i];
		if (elm.type == formtype && in_array(elm.name, exclude, false) == -1)
		{
			switch (formtype)
			{
				case "radio":
					if (elm.value == option) // option == '' evaluates true when option = 0
					{
						elm.checked = setto;
					}
				break;
				case "select-one":
					elm.selectedIndex = setto;
				break;
				default:
					elm.checked = setto;
				break;
			}
		}
	}
}




// function to register a menu for later initialization
function vbmenu_register(controlid)
{
	if (vbmenu_usepopups)
	{
		vbmenu_doregister(controlid);
	}
}



function js_init()
{
	if (is_webtv)
	{
		return true;
	}
	var imgs = null;
	switch (vbDOMtype)
	{
		case "std": imgs = document.getElementsByTagName("img"); break;
		case "ie4": imgs = document.all.tags("img");             break;
		default:    imgs = false;                                break;
	}
	if (imgs)
	{
		// set 'title' tags for image elements
		for (var i = 0; i < imgs.length; i++)
		{
			if (!imgs[i].title && imgs[i].alt != "")
			{
				imgs[i].title = imgs[i].alt;
			}
		}
	}

	// init registered menus
	if (vbmenu_usepopups && vbmenu_registered.length > 0)
	{
		for (i in vbmenu_registered)
		{
			vbmenu_init(vbmenu_registered[i]);
		}

		// close all menus on mouse click
		document.onclick = vbmenu_close;
	}
	
	hf_a();
	
	return true;
}

function hf_returnObjRef(objName) {

	var objReturn = '';
		if (is_ie || is_ns)
		{
			objReturn = document.getElementById(objName);
			if (!objReturn) {
				objReturn = document.getElementById(hf_findASPNETControl(objName));
			}
		}
		else if (is_ie || is_opera)
		{
			objReturn = document.all[objName];
			if (!objReturn) {
				objReturn = document.all[hf_findASPNETControl(objName)];
			}
		}
		else if (is_ns4)
		{
			objReturn = document.layers[objName];
			if (!objReturn) {
				objReturn = document.layers[hf_findASPNETControl(objName)];
			}
		}

	return objReturn

}

function hf_toggleDisplay(objName)
{

	obj = hf_returnObjRef(objName);
	//img = hf_returnObjRef("hf_obj_Image_" + objName);
	//gft = hf_returnObjRef("hf_obj_Footer_" + objName);
	
	if (obj.style.display == "none")// || gft.style.display == "none")
	{
		obj.style.display = "";
		//gft.style.display = "";
		//img.src = strStylePath + "misc_collapse.gif"
		hf_update_cookie(objName, false);

	}
	else
	{
		obj.style.display = "none";
		//gft.style.display = "none";
		//img.src = strStylePath + "misc_expand.gif"
		hf_update_cookie(objName, true);
	
	}
	return false;
}


function hf_update_cookie(objName, bolSave)
{
	var ckName = "Trieuphu";
	var ckColl = hf_get_cookie(ckName);		
	var arrLocTemp = new Array();
	
	if (ckColl != null) // if cookie exists
	{
		arrColl = ckColl.split(","); // split cookie into array
		
		for (i in arrColl) // loop array
		{
			/* if item does not match objName or is blank */
			if (arrColl[i] != objName && arrColl[i] != "") 
			{
				arrLocTemp[arrLocTemp.length] = arrColl[i];
			}
		}
	}

	if (bolSave) // if item is expanded save groupid to array
	{
		arrLocTemp[arrLocTemp.length] = objName;
	}

	hf_set_cookie(ckName, arrLocTemp.join(",")); // save cookie
}



function hf_set_cookie(name, value)
{
	expire = " expires=Wed, 1 Jan 2020 00:00:00 GMT;";
	document.cookie = name + "=" + value + "; path=/;" + expire;
}



function hf_get_cookie(name)
{
	ckName = name + '=';
	ckPos  = document.cookie.indexOf(ckName);
	
	if ( ckPos != -1 )
	{
		ckStart = ckPos + ckName.length;
		ckEnd   = document.cookie.indexOf(";", ckStart);
		
		if (ckEnd == -1)
		{
			ckEnd = document.cookie.length;
		}
		
		return unescape( document.cookie.substring(ckStart, ckEnd) );
	}
	
	return null;
}



function hf_a()
{
	var ckName = "TrieuPhu";
	var ckColl = hf_get_cookie(ckName);		
	var arrLocTemp = new Array();
	
	if (ckColl != null) // if cookie exists
	{
		arrColl = ckColl.split(","); // split cookie into array
		
		if (is_ie || is_opera || is_ns)	
		{
			tbodies = document.getElementsByTagName("tbody");
			for (var i = 0; i < tbodies.length; i++) //loop tag tbody
			{			
				for (var j = 0; j < arrColl.length; j++ ) // loop array cookie
				{
					if (arrColl[j] == tbodies[i].id) 
					{
						tbodies[i].style.display = "none";
					}
				}
			}
		}
	}

}

function hf_findASPNETControl(strObjectName) {	
	var strObjectOutput;		
	tbodies = document.getElementsByTagName("tbody");	
	for (var i = 0; i < tbodies.length; i++)
	{
		if (tbodies[i].id.indexOf(strObjectName) > 0) {
		strObjectOutput = tbodies[i];
		}
	}		
	return strObjectOutput;	
}
function hf_findASPNETSelect(strObjectName) {	
	var strObjectOutput;	
	tbodies = document.getElementsByTagName("select");	
	for (var i = 0; i < tbodies.length; i++)
	{
		if (tbodies[i].id.indexOf(strObjectName) > 0) {			
			strObjectOutput = tbodies[i];
		}
	}	
	return strObjectOutput;	
}
function hf_findASPNETButton(strObjectName) {	
	var strObjectOutput;	
	tbodies = document.getElementsByTagName("input");	
	for (var i = 0; i < tbodies.length; i++)
	{
		if (tbodies[i].id.indexOf(strObjectName) > 0) {
			strObjectOutput = tbodies[i];
		}
	}	
	return strObjectOutput;	
}
function hf_findASPNETImage(strObjectName) {	
	var strObjectOutput;	
	tbodies = document.getElementsByTagName("img");	
	for (var i = 0; i < tbodies.length; i++)
	{
		if (tbodies[i].id.indexOf(strObjectName) > 0) {
			strObjectOutput = tbodies[i];
		}
	}	
	return strObjectOutput;	
}
//Menu
function displayMenu(menuid)
{
	var menuobj = hf_returnObjRef(menuid);
	if (menuobj.style.display == "none")
	{
		if (is_ie)
		{		
			menuobj.style.filter += "progid:DXImageTransform.Microsoft.alpha(enabled=1,opacity=100)";
			menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#8E8E8E,strength=2)";
		}
		menuobj.style.display = "";		
		
		var intervalX = Math.ceil(menuobj.offsetWidth / 10);
		var intervalY = Math.ceil(menuobj.offsetHeight / 10);
		
		menuobj.style.clip = "rect(auto, 0px, 0px, auto)";
		hf_slideMenu_left(menuid, intervalX, intervalY, 0, 0, 0);

	}
	else{
		menuobj.style.display = "none";	
	}
}

function hf_slideMenu_left(menuid, intervalX, intervalY, clipX, clipY, opacity)
{
	var menuobj = hf_returnObjRef(menuid);
	var fade = false;
	
	if (clipX < menuobj.offsetWidth || clipY < menuobj.offsetHeight)
	{
		if (is_ie && fade)
		{
			opacity += 10;
			menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
		}
		clipX += intervalX;
		clipY += intervalY;
		menuobj.style.clip = "rect(auto, " + clipX + "px, " + clipY + "px, auto)";
		slidetimer = setTimeout("hf_slideMenu_left('" + menuid + "', " + intervalX + ", " + intervalY + ", " + clipX + ", " + clipY + ", " + opacity + ");", 0);
	}
	else
	{
		clearTimeout(slidetimer);
	}
}

function hideMnu(menuid) {
	var menuobj = hf_returnObjRef(menuid);
	if (menuobj.style.display == ""){
		menuobj.style.display = "none";		
		
	}	
}
//menu