/* ----------------------
   Scripts
---------------------- */

/* Auto Highlight Main Menu */
function extractPageName(hrefString) {
	var arr = hrefString.split('/');
	arr = arr[arr.length-2].split('/');
	return arr[arr.length-1].toLowerCase();	
}
function setActiveMenu(arr, crtPage) {
	for( var i=0; i<arr.length; i++ ) {
		if(extractPageName(arr[i].href) == crtPage) {
			if ( arr[i].parentNode.className == "level1ST" ) {
				//arr[i].className = "level1STselected";
				arr[i].parentNode.className = "level1STselected";
			}
			if ( arr[i].parentNode.className == "level2ST" ) {
				//arr[i].className = "level2STcurrent";
				arr[i].parentNode.className = "level2STselected";
			}
			if ( arr[i].parentNode.className == "level3ST" ) {
				//arr[i].className = "level3STselected";
				arr[i].parentNode.className = "level3STselected";
			}
		}
	}
}
function hightlightCurrentMenu() {
	if( document.location.href ) {
		hrefString = document.location.href;
	} else {
		hrefString = document.location;
	}
	if ( document.getElementById("nav") != null )  {
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));
	}
}
	

function popUp(URL, popWidth, popHeight, popLeft, popTop, autoCenter, fullScreen) {
	day = new Date();
	id = day.getTime();
	if (autoCenter == 1) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	
	if (fullScreen == 1) {
		// Open in Full Screen window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+(screen.width-10)+",height="+(screen.height-26)+",left=0,top=0');");
	} else {
		// Open in normal window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
	}
}

function toggleDiv( element, showhide ) {
	var e = document.getElementById(element);
	if ( e ) {
		switch ( showhide ) {
			case "true":
				e.style.display = 'inline';
				break;

			case "false":
				e.style.display = 'none';
				break;

			case "default":
				e.style.display = ((e.style.display != 'inline') ? 'inline' : 'none');
				break;
		}
	}
}


// Make sure that textBox only contain number
function checkNumber(textBox) {
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	textBox.value = trim(textBox.value);
	/*if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

