<!-- 
// Version 1.1
/*
2007.08.08
- add firefox detect
- add fix serach filter cannot show in firefox properly 
*/
// detect useragent (browser type)
var userAgent = navigator.userAgent.toLowerCase();
var isFireFox = false;
var isNav = false;
var isIE = false;
if ( userAgent.indexOf("firefox") > 0 ) isFireFox = true;
if ( userAgent.indexOf("netscape") > 0 ) isNav = true;
if ( userAgent.indexOf("microsoft") > 0 ) isIE = true;

var treectrl = new Array();
treectrl[0] = new Image();
treectrl[0].src = '/images/tree/plus_middle.gif';
treectrl[1] = new Image();
treectrl[1].src = '/images/tree/minus_middle.gif';
treectrl[2] = new Image();
treectrl[2].src = '/images/tree/plus_lower.gif';
treectrl[3] = new Image();
treectrl[3].src = '/images/tree/minus_lower.gif';

function ImageButton(elName,icoNum) {
    var el = $(elName);
    if ( el != null ) {
        el.set('opacity', 0.8)
            .setStyle('backgroundImage','url(/images/color/001_'+ icoNum +'.gif)')
            .addEvents( {
    		mouseenter: function(){
    		  this.set('opacity', 1.0);
    		},
    		mouseleave: function(){
    		  this.set('opacity', 0.8);
    		}
        });
    }
}

// put text content to tooltips
function fnShowTips(el) {
	if ( el != null ) {
		this.title = this.innerHTML;
	}
}

// put a message to status bar, and run from right to left
function fnFunMsg(msg) {
	window.status = msg; 
}

// turn off toolbars
function fnNoToolBar() {
	if ( isIE ) {
		alert(self.menubar);
		self.menubar.style.visibility = false;
		self.toolbar.style.visibility = false;
		self.locationbar.style.visibility = false;
		self.statusbar.style.visibility = false;
	} else {
		self.menubar.visible = false;
		self.toolbar.visible = false;
		self.locationbar.visible = false;
		self.statusbar.visible = false;
	}
}

// tree image plus/minus change
function fnFlip(obj) {
	if ( obj.src == treectrl[0].src ) {
		obj.src = treectrl[1].src;
		return false;
	} 
	if ( obj.src == treectrl[1].src ) {
		obj.src = treectrl[0].src;
		return true;
	} 
	if ( obj.src == treectrl[2].src ) {
		obj.src = treectrl[3].src;
		return false;		
	} 
	if ( obj.src == treectrl[3].src ) {
		obj.src = treectrl[2].src;
		return true;
	}
}

// Toggle tree plus/minus icon
function fnOpenTree(obj, target) {
	fnFlip(obj);
	fnExpandAll(target,true);
}

// Determine if the current key stroke is 'Enter' or not
// boolean IsEnter(void)
function IsEnter(oEvent) {
	
	oEvent = oEvent || window.event;
	if ( !oEvent ) return false;
  var iKeyCode = oEvent.keyCode;
    
	if ( iKeyCode == 13 ) {	
		return true;
	}	else {
		return false;
	}
}

// block right click
function fnBlockRightClick(e) {
	var szMessage = "Function disabled!";
	returnValue = false;
	if (isNav4 && e.which > 1) {
		alert(szMessage);
		return false;
	}
	else if (isIE4 && (event.button > 1)) 
	{	
		alert(szMessage);
		return false;
	}
}

// change browser url
function fnGoURL(targeturl) {
	window.location.href = targeturl;
}

// reload parent window
function fnReloadParent() {
	var	argv = arguments;
	var argc = arguments.length;
	
	if ( argc == 1 ) { 
		opener.location.href = argv[0];
	} else {
		opener.location.reload(true);
	}
}

// expand all div object inside given obj
function fnExpandAll(obj, option) {
	var item, szout = 'obj: '+ obj.all.tags('DIV').length +', ';
	for( var i = 0; i < obj.all.tags('DIV').length; i++ ) {
		item = obj.all.tags('DIV')(i);
	}
	
	if ( option == true ) {
		for( var i = 0; i < obj.all.tags('DIV').length; i++ ) {
			item = obj.all.tags('DIV')(i);
			fnToggle( item.id.replace('div_', 'tbl_') );
		}	
	}
}

// popup new window with no toolbar, menu bar, location, cannot resize
function fnNewWindow(targeturl,width,height) {
	var option = 'toolbar=no,menubar=no,location=no,resizable=yes,status=yes,scrollbars=yes';
	if ( height > 0 ) {
		option += ',height='+ height;
	}
	if ( width > 0 ) {
		option += ',width='+ width;
	}
	window.open(targeturl, '', option);
	return true;
}

// change background color with current color or transparent
function fnBgcolor() {
	if ( isIE == false ) return null;
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc == 0 ) { return null; }

	var obj, szColor = "", szOut = "";
	if ( argc == 1 ) {
		szColor = 'transparent';
	} else {
		szColor = argv[1];
	}
	obj = argv[0];
	obj.style.backgroundColor = szColor; 
}

// change background color with current color or transparent
function fnCWin() {
	if ( isIE == false ) return null;
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc == 0 ) { return null };

	var obj = argv[0];
	var bVisable = false;

	if ( argc == 2 ) {
		bVisable = argv[1];
	}
	
	if ( bVisable )	{
		obj.style.clip = 'rect(auto auto auto auto)';
		obj.style.zIndex = 1;
	} else {
		obj.style.clip = 'rect(0 18 20 0)';
		obj.style.zIndex = 0;
	}
}

// toggle border like button in / out
function btnToggle(obj) {
	if ( obj.style.borderStyle == 'inset' ) {
		obj.style.borderStyle = 'outset';
	} else {
		obj.style.borderStyle = 'inset';
	}
}

function fnToggle() {
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc == 0 ) { return null; }

	var obj = argv[0];
	var style_v, style_d;
	var szVisible = 'hidden', szDisplay = 'none';
	
	if ( isFireFox ) {
		style = document.getElementById(obj).style;
	} else if (isNav) {
		style = obj.style;
	} else if ( obj == "[object]") {
		style = obj.style;
	} else {
		style = GetObject(obj).style;
	}
	
	if ( argc == 2 ) {
		szVisible = argv[1];
	} else {
		if ( style.visibility == 'hidden' ) { szVisible = 'visible'; }
	}
	if ( szVisible == 'visible' ) { szDisplay = 'block'; }
	style.visibility = szVisible;
	style.display = szDisplay;
}

function fnMoveWin(obj) {
	var mousex = window.event.x < 0 ? 0 : window.event.x;
	var mousey = window.event.y < 0 ? 0 : window.event.y;
	obj.style.left = mousex;
	obj.style.top = mousey;
	
//	window.status = "(oX:"+ obj.style.left +", oY:"+  obj.style.pixelTop +"); "
//	window.status += "(mouse.x:"+ window.event.x +", mouse.y:"+  window.event.y +"); "
//	window.status += "(mouse.offsetX:"+ window.event.offsetX +", mouse.offsetY:"+  window.event.offsetY +"); "
//	window.status += "(mouse.screenX:"+ window.event.screenX +", mouse.screenY:"+  window.event.screenY +"); "
//	window.status += "X:"+ mousex +", Y:"+ mousey
}

function fnCreateObject(){
	var	argv = arguments;
	var argc = arguments.length;
	if ( isNav == true ) { return null; }
	if ( argc != 2 ) { return null; }
	var oRef = document.getElementById(argv[0]);
	var szTag = argv[1];
	var aElement = document.createElement(szTag);
	oRef.insertAdjacentElement("beforeEnd",aElement);
}

function fnAppendText() {
	var	argv = arguments;
	var argc = arguments.length;
	if ( isNav == true ) { return null; }
	if ( argc != 2 ) { return null; }
	var oRef = document.getElementById(argv[0]);
	var szText = argv[1];
	oRef.insertAdjacentHTML("beforeEnd",szText);	
}
/*------------------------------------------*/
function fnOpenWin(sUrl) {
	window.open( sUrl, '', '' );
}
/*------------------------------------------*/
function fnCloseWin() {
	window.opener.history.go(0);
	window.close();	
}

/*******************************************************************************************
Genreal Select Box Functions
*******************************************************************************************/
// add a single item to select box
function fnAddItem(target_obj_name, szText, szValue) {
	var oTarget = target_obj_name;	
	oTarget.length ++;
	oTarget[oTarget.length -1] = new Option(szText, szValue);	
}

// Add multiple items to select box
function fnAddItems(target_obj_name, source_obj_name) {
	var oTarget = target_obj_name;
	var oSoruce = soruce_obj_name;
	
	for ( var index = 0; index < oSource.length; index ++ ) {
		if ( oSource.options[index].selected == true ) {
			fnAddItem(oTarget, oSource.options[index].text, oSource.options[index].value);
			oSource.options[index].selected = false;
		}		
	}
}

// swap multiple items from source to target select box
function fnSwapItems() {
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc < 2 ) return false;
	var oTarget = argv[0];
	var oSource = argv[1];
	var bSort = true;
	if ( argc == 3 ) bSort = argv[2];

	for ( var index = 0; index < oSource.length; index ++ ) {
		if ( oSource.options[index].selected == true ) {
			var szValue = oSource.options[index].value;
			var szText  = oSource.options[index].text;
			fnAddItem(oTarget, szText, szValue);
		}
	}
	fnDelItem(oSource);
	if ( bSort == true ) fnSortItems(oTarget);
}

// delete an item from target select box
function fnDelItem(target_obj_name) {
	var oLast = target_obj_name;
	for ( i = oLast.length-1; i >=0 ; i-- ) {
		if ( oLast.options[i].selected == true ) { 
			if ( isNav ) {
				oLast.options[i] = null;
			} else {
				oLast.remove(i);
			}
		}
	}
}

// delete an item from target select box
function fnSortItems(target_obj_name) {
	var obj = target_obj_name;
	var iLastLength = obj.length;
		
	if ( iLastLength > 0 ) {
		for ( i = 0; i < iLastLength; i ++ ) {
			for ( j = i; j < iLastLength; j ++ ) {
				if ( obj.options[i].text > obj.options[j].text ) { 
					szText = obj.options[i].text;
					szValue = obj.options[i].value;
					obj.options[i].text = obj.options[j].text;
					obj.options[i].value = obj.options[j].value;
					obj.options[j].text = szText;
					obj.options[j].value = szValue;
				}
			}
		}
	}
}

// select all options of the object
function fnSelectAll(obj) {
	if ( obj ) {
		var len = obj.length;
		for (var i = 0; i < len; i++) {
			obj.options[i].selected = true;
		}
	}
}

function fnSelValue(obj) {
	return obj.options[obj.selectedIndex].value;
}
function fnSelText(obj) {
	return obj.options[obj.selectedIndex].text;
}

// this function will sync the select_object to specify index 
// when ref_select_obj's ref_index is reached. 
// If ref_select_obj not supplied, sync select_obj anyway.
// void fnSyncSelect( Object select_object_name, Integer sync_to_index [, Object ref_select_obj, Integer ref_index] )
function fnSyncSelect() { 
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc < 2 ) return false;
	var obj = argv[0];
	var index = argv[1];
	if ( argc == 4 ) {
		if ( argv[2].selectedIndex == argv[3] ) {
			obj.selectedIndex = index;
		}
	} else {
		obj.selectedIndex = index;
	}
}

// date combo box validate
function fnCalValidate() {
	var	argv = arguments;
	var argc = arguments.length;
	if ( argc < 1 ) { return null; }
	var objname = argv[0];
	var ofYear   = GetObject(objname + "_yy");
	var ofMonth  = GetObject(objname + "_mm");
	var ofDay    = GetObject(objname + "_dd");
	var intYear  = parseInt(ofYear.value,10);
	var intMonth = parseInt(ofMonth.value,10);
	var intDay   = parseInt(ofDay.value,10);
	var intLipYear = 0;
	if (( intYear % 4 ) == 0 && (( (intYear % 100) != 0 ) || ( (intYear % 400) == 0 ) )) {
		intLipYear = 1;
	}
	switch (intMonth) {
		case 2:
			if ( intDay > (28 + intLipYear) ) {
				ofMonth.selectedIndex = ofMonth.selectedIndex + 1;
				ofDay.selectedIndex = ofDay.selectedIndex - (28 + intLipYear);
			}
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if ( intDay > 30 ) {
				ofMonth.selectedIndex = ofMonth.selectedIndex + 1;
				ofDay.selectedIndex = ofDay.selectedIndex - 30;
			}
			break;
	}			
}

function fnSyncDate(sRef, sSyn) {
	var oRefDD = GetObject(sRef +"_dd");
	var oRefMM = GetObject(sRef +"_mm");
	var oRefYY = GetObject(sRef +"_yy");
	var oSynDD = GetObject(sSyn +"_dd");
	var oSynMM = GetObject(sSyn +"_mm");
	var oSynYY = GetObject(sSyn +"_yy");	
	oSynDD.selectedIndex = oRefDD.selectedIndex;
	oSynMM.selectedIndex = oRefMM.selectedIndex;
	oSynYY.selectedIndex = oRefYY.selectedIndex;
}

function fnSetDate(sRef, sSyn, sDate) {
	var oRefDD = GetObject(sRef +"_dd");
	var oRefMM = GetObject(sRef +"_mm");
	var oRefYY = GetObject(sRef +"_yy");
	oRefDD.selectedIndex = fnFindItemInt(oRefDD, parseInt(sDate.substr(6,2),10));
	oRefMM.selectedIndex = fnFindItemInt(oRefMM, parseInt(sDate.substr(4,2),10));
	oRefYY.selectedIndex = fnFindItemInt(oRefYY, parseInt(sDate.substr(0,4),10));
	fnSyncDate(sRef, sSyn);
}

function fnFindItemInt(oRef, nValue) {
	for ( var i=0; i < oRef.length; i ++ ) {
		if ( parseInt(oRef.options[i].value,10) == nValue ) {
			return i;	
		}
	}
	return oRef.selectedIndex;
}

function GetObject(target_name) {
	if (isNav) {
		return target_name;
	}
	return document.all.item(target_name);
}

// filesys - start //
function fnGetFileOld() {
	var argv = arguments;
	document.fmFile.action.value = "file";
	if ( argv[0] == -1 ) {
		document.fmFile.action.value = "zip";
	}
	document.fmFile.id.value = argv[0];
	document.fmFile.submit();
}

function fnGetFile() {
	var argv = arguments;
	var argc = arguments.length;
	if ( argc == 1 ) {
		var sUrl = "/filesys/download.asp?action=file&id="+ escape(argv[0]);
		fnNewWindow(sUrl,0,0);	
	}
}

function fnGetFileZip() {
	var argv = arguments;
	var argc = arguments.length;
	if ( argc == 2 ) {
		var sUrl = "/filesys/download.asp?action=zip&app="+ escape(argv[0]) +"&log="+ escape(argv[1]);
		fnNewWindow(sUrl,0,0);	
	}
}

function fnOpenUploadWin() {
	var argv = arguments;
	var argc = arguments.length;
	if ( argc == 2 ) {	
		var sUrl = "/filesys/download.asp?app="+ escape(argv[0]) +"&log="+ escape(argv[1]);
		fnNewWindow(sUrl,480,300);
	}
}
// filesys - end //

// password generator - start //
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	
	var charSet = extra;
	if (number == true) charSet += numberChars;
	if (lower == true) charSet += lowerChars;
	if (upper == true) charSet += upperChars;
	if (other == true) charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword() {
	var obj = document.getElementById("fPasswordGenerator");
	var passwordLength = 8;
	var first = new Array(false,true,false,false);
	var latter = new Array(true,true,false,false);
	var extraChars = "";
	
	if ( obj == "[object]" ) {	
		passwordLength = parseInt(obj.elements("passwordLength").value,10);
		first[0] = obj.elements("firstNumber").checked;
		first[1] = obj.elements("firstLower").checked;
		first[2] = obj.elements("firstUpper").checked;
		first[3] = obj.elements("firstOther").checked;
		latter[0] = obj.elements("latterNumber").checked;
		latter[1] = obj.elements("latterLower").checked;
		latter[2] = obj.elements("latterUpper").checked;
		latter[3] = obj.elements("latterOther").checked;	
		extraChars = obj.elements("extraChars").value;
	}
	var rc = "";
	if (passwordLength > 0) {
		rc = rc + getRandomChar(first[0], first[1], first[2], first[3], extraChars);
	}
	for (var idx = 1; idx < passwordLength; ++idx) {
		rc = rc + getRandomChar(latter[0], latter[1], latter[2], latter[3], extraChars);
	}
	return rc;
}
// password generator - end //

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
/* Modified to support Opera */
function addBookmark(title,url) {
	if ( url == "" ) {
		url = location.href;
	}
	title = title.replace("\\", " - ");
	if (window.sidebar) { // firefox 
		window.sidebar.addPanel(title, url, "");
	
	} else if (window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	
	} else if(document.all) { // ie
		window.external.AddFavorite(url, title);
	
	}
}
//------------------------------------------------------------------------------
// Loading tooltip
// <a class="tipz" href="xxx" title="tipTitle::tipText"">xxx</a>
function fnSetupTip() {	
	//store titles and text
	try {
		$$('a.tipz').each(function(element,index) {
			var content = element.get('title').split('::');
			element.store('tip:title', content[0]);
			element.store('tip:text', content[1]);
		});
		el = new Tips('.tipz', {
			className: 'tipz',
			fixed: true,
			hideDelay: 50,
			showDelay: 50
		});
	} catch (e) {
		alert('fnSetupTip()::'+ e);
	}
}
//-->