String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

/*
xmlDom: 
browse: 浏览器相关函数
*/
//定义全局变量-------------------------------
var ObjPasswordType = null;
var ObjPostSource = null;
var ObjPostStr1 = null;
var ObjPostStr2 = null;
var selectTab = 0;

var browser;
var xmlDom;

if (browser == null)
    browser = new browserdetect;

if (xmlDom == null) {
  xmlDom = createDomDoc();
 //   xmlDom.setProperty("SelectionLanguage", "XPath");
}

addEvent(window, "load", MyOnLoad);

//=======================

//示例: addEvent(window, "load", MyOnLoad);
function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    if (elm.attachEvent) return elm.attachEvent('on' + evType, fn);
    elm['on' + evType] = fn;
    return false;
}

function browserdetect() {
    var agent = navigator.userAgent.toLowerCase();
    this.isIE = agent.indexOf("msie") > -1;
    this.ieVer = this.isIE ? /msie\s(\d\.\d)/.exec(agent)[1] : 0;
    this.isMoz = agent.indexOf('firefox') != -1;
    this.isSafari = agent.indexOf('safari') != -1;
    this.quirksMode = this.isIE && (!document.compatMode || document.compatMode.indexOf("BackCompat") > -1);
    this.isOp = 'opera' in window;
    this.isWebKit = agent.indexOf('webkit') != -1;
    if (this.isIE) {
        this.get_style = function(obj, prop) {
            if (!(prop in obj.currentStyle)) return "";
            var matches = /^([\d.]+)(\w*)/.exec(obj.currentStyle[prop]);
            if (!matches) return obj.currentStyle[prop];
            if (matches[1] == 0) return '0';
            // now convert to pixels if necessary
            if (matches[2] && matches[2] !== 'px') {
                var style = obj.style.left;
                var rtStyle = obj.runtimeStyle.left;
                obj.runtimeStyle.left = obj.currentStyle.left;
                obj.style.left = matches[1] + matches[2];
                matches[0] = obj.style.pixelLeft;
                obj.style.left = style;
                obj.runtimeStyle.left = rtStyle;
            }
            return matches[0];
        };
    }
    else {
        this.get_style = function(obj, prop) {
            prop = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
            return document.defaultView.getComputedStyle(obj, '').getPropertyValue(prop);
        };
    }
}

function createDomDoc() {
    var _domDoc
    if (!window.DOMParser && window.ActiveXObject) {
        var signatures = ['MSXML2.DOMDocument.6.0', "Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "Msxml2.DOMDocument", "Microsoft.XmlDom"];
        for (var i = 0; i < signatures.length; i++) { try { _domDoc = new ActiveXObject(signatures[i]); return _domDoc; } catch (e) { } }
    }
    else {// Mozilla browsers have a DOMParser
        try {
            if (_domDoc == null && document.implementation && document.implementation.createDocument) {
                _domDoc = document.implementation.createDocument("", "", null);
                return _domDoc;
            }
        } catch (ex) { }
    }
}


function GetObj(o) {
    var o = document.getElementById(o) ? document.getElementById(o) : o;
    return o;
}


//-----------------------    
function WriteEheEdit(EdtName) {
    str = "<object classid=\"clsid:767A7AE2-33EA-4887-A176-154707F6C7D7\" id=\"" + EdtName + "\" width=\"176\" height=\"21\" tabindex = \"5\"></object>";
    document.writeln(str);
}


function IsInstalledEheEdit() {
    var aliedit = null;
    str = "";
    try {

        aliedit = new ActiveXObject("EheEdit.EditX");
        aliedit.InStr = 'Test';
        str = aliedit.InStr;
    } catch (er) { };
    return str == "OKTest" ? true : false;
}

//-------------------------------------------



function reinitIframe() {
    var iframe = document.getElementById("work");
    try {
        var bHeight = iframe.contentWindow.document.body.scrollHeight;
        var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
        var height = Math.max(bHeight, dHeight);
        iframe.height = height + "px";
    }
    catch (ex) { }
}


function visible(Obj, b) {
    if (b) { Obj.style.visibility = "visible"; Obj.style.display = "block"; }
    else { Obj.style.visibility = "hidden"; Obj.style.display = "none"; }
}


//==================================== UTF-8 Base64编解码================================================
// 用法
//解码 utf8to16(base64decode(str))
//编码 base64encode(utf16to8(str));
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        /* c1 */
        do {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c1 == -1);
        if (c1 == -1) break;
        /* c2 */
        do {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c2 == -1);
        if (c2 == -1) break;
        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
        /* c3 */
        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if (c3 == 61) return out;
            c3 = base64DecodeChars[c3];
        } while (i < len && c3 == -1);
        if (c3 == -1) break;
        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
        /* c4 */
        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if (c4 == 61) return out;
            c4 = base64DecodeChars[c4];
        } while (i < len && c4 == -1);
        if (c4 == -1) break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}

//将16位Unicode转为UTF8
function utf16to8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        }
        else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
        else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}
//将UTF8转为16位Unicode
function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while (i < len) {
        c = str.charCodeAt(i++);
        switch (c >> 4) {
            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                // 0xxxxxxx
                out += str.charAt(i - 1);
                break;
            case 12: case 13:
                // 110x xxxx   10xx xxxx
                char2 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
                break;
            case 14:
                // 1110 xxxx  10xx xxxx  10xx xxxx
                char2 = str.charCodeAt(i++);
                char3 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x0F) << 12) |
					   ((char2 & 0x3F) << 6) |
					   ((char3 & 0x3F) << 0));
                break;
        }
    }
    return out;
}
//Utf8Base64
function Utf8Base64Encode(str) {
    return base64encode(utf16to8(str));
}
function Utf8Base64Decode(str) {
    return utf8to16(base64decode(str));
}




var msgbox_scripts = document.getElementsByTagName("script"); 
var msgbox_path = msgbox_scripts.item(msgbox_scripts.length-1).getAttribute('src').replace('\\', '/');
msgbox_path = msgbox_path.substring(0, msgbox_path.lastIndexOf('/')+1);

var CMSMsgBox = function(oWidth, oHeight, oSkin, oTitle){
	this.Id = 'msgbox_'+Math.random().toString().replace('\.', '_');
	/*
	 * 位置
	 * =================
	 * ===== 1 2 3 =====
	 * ===== 4 5 6 =====
	 * ===== 7 8 9 =====
	 * =================
	 */
	this.Position = 5;

	this.Skin = oSkin || 'default';
	this.Width = oWidth || 500;
	this.Height = oHeight || 260;
	
	this.Title = oTitle || 'CMSDream:';
	this.Value = '';
	this.Float = true;
	this.Mask = false;
	this.Drag = true;
	this.Return = false;
	this.BoxDiv = null;
};

CMSMsgBox.prototype.show = function(){
	if(this.$(this.Id))return false;
	this.Return = true;
	this.BoxDiv = this.createDiv(document.body, 'div', 'block', this.Id, 'msgbox_main_div');	
	if(this.Mask)this.createMask();	
	this.showBox();
};

CMSMsgBox.prototype.showBox = function(){
	var self = this;
	var div = new Array();
	
	div['box'] = this.createDiv(this.BoxDiv, 'div', 'block', this.Id+'bgcolor_div', 'msgbox_box msgbox_box_'+this.Skin);
	if(this.Width)div['box'].style.width = this.Width+'px';
	if(this.Height && this.Skin != 'loading')div['box'].style.height = this.Height+'px';
	
	div['title'] = this.createDiv(div['box'], 'div', null, null, 'msgbox_title');

	/* =====================================
	 * 拖曳效果
	 *=====================================**/
	if(this.Drag){
		div['move'] = this.createDiv(this.BoxDiv, 'div', 'none', null, 'msgbox_move_div');		
		div['title'].style.cursor = 'move';
		div['title'].onmousedown = function(e){
			var X = document.all ? event.clientX : e.pageX;
			var Y = document.all ? event.clientY : e.pageY;
			var T = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
			var cLeft = div['code'].offsetLeft + div['box'].offsetLeft;
			var cTop = div['code'].offsetTop + div['box'].offsetTop - T;
			if((X > cLeft && X < (cLeft + div['code'].offsetWidth)) && (Y > cTop && Y < (cTop + div['code'].offsetHeight)))
			return;
			this.style.zIndex += 10;	
			this.setAttribute('MD', '1');
			this.setAttribute('XCX', parseInt(X - div['box'].offsetLeft).toString());
			this.setAttribute('XCY', parseInt(Y - div['box'].offsetTop).toString());
			div['move'].style.width = parseInt(div['box'].offsetWidth-10) + 'px';
			div['move'].style.height = parseInt(div['box'].offsetHeight - 10) + 'px';
			div['move'].style.left = div['box'].offsetLeft + 'px';
			div['move'].style.top = div['box'].offsetTop + 'px';
			div['move'].style.display = 'block';
		};

		function document_mousemove(e){
			if(div['title'].getAttribute('MD')!='1')return;
			var XCX = div['title'].getAttribute('XCX');
			var XCY = div['title'].getAttribute('XCY');
			var X = document.all ? event.clientX : e.pageX;
			var Y = document.all ? event.clientY : e.pageY;
			div['move'].style.left = parseInt(X - XCX) + 'px';
			div['move'].style.top = parseInt(Y - XCY) + 'px';
		}

		function document_mouseup(e){
			if(div['title'].getAttribute('MD')!='1')return;
			div['title'].setAttribute('MD', '0');
			div['title'].setAttribute('XCX', '0');
			div['title'].setAttribute('XCY', '0');
			div['box'].style.left = div['move'].offsetLeft + 'px';
			div['box'].style.top = div['move'].offsetTop + 'px';
			if(self.IsObject(div['mask'])){
				div['mask'].style.left = div['move'].offsetLeft + 'px';
				div['mask'].style.top = div['move'].offsetTop + 'px';
			}	
			div['move'].style.display = 'none';
		}

		if(document.addEventListener){
			document.addEventListener('mousemove', document_mousemove, false);
			document.addEventListener('mouseup', document_mouseup, false);
		}else{
			document.attachEvent('onmousemove', document_mousemove);
			document.attachEvent('onmouseup', document_mouseup);
		}
	}
	div['span'] = this.createDiv(div['title'], 'span', 'block', this.Id+'_msgTitle');
	div['span'].innerHTML = this.Title;

	/* =====================================
	 * 关闭按钮
	 *=====================================**/
	div['code'] = this.createDiv(div['title'], 'code', 'block');
	div['code'].setAttribute('title', 'close');
	div['code'].style.position = 'relative';
	div['code'].innerHTML = "close";
	div['code'].onclick = function(){self.close();};
	
	/* =====================================
	 * 文本区域
	 *=====================================**/
	div['text'] = this.createDiv(div['box'], 'div', 'block', this.Id+'_msgContent', 'msgbox_content');
	div['value'] = this.createDiv(div['text'], 'div', 'block', this.Id+'_msgValue', 'msgbox_container');
	div['clear'] = this.createDiv(div['text'], 'div', 'block', null, 'msgbox_clear');
	if(this.Height && this.Skin != 'loading'){
		div['value'].style.height = (div['box'].offsetHeight - div['title'].offsetHeight - 16) + 'px';
		div['value'].style.overflowY = 'auto';
	}
	div['value'].innerHTML = this.Value;

	/* =====================================
	 * 创建一个iframe档住select 
	 *=====================================**/
	if(document.all && !this.Mask){
		div['mask'] = this.createDiv(this.BoxDiv, 'iframe', 'block', null, 'msgbox_frame');
		div['mask'].style.width = div['box'].offsetWidth+'px';
		div['mask'].style.height = div['box'].offsetHeight+'px';
	}	
	
	
	mDiv_Float();	
	if(this.Float){
		if(window.addEventListener){
			window.addEventListener('resize', mDiv_Float, false);
			window.addEventListener('scroll', mDiv_Float, false);
		}else{
			window.attachEvent('onresize', mDiv_Float);
			window.attachEvent('onscroll', mDiv_Float);
		}
	}

	/* =====================================
	 * 漂浮效果
	 *=====================================**/
	function mDiv_Float(){
		var t = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
		var h = document.documentElement.clientHeight ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : document.body.clientHeight;
		var w = document.documentElement.clientWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
		
		switch(self.Position){
			case 1:  {var l = 1;var r = t + 1;break;}
			case 2:  {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = t + 1;break;}
			case 3:  {var l = parseInt(w-div['box'].offsetWidth-1);var r = t + 1;break;}
			case 4:  {var l = 1;var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
			case 5:  {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
			case 6:  {var l = parseInt(w-div['box'].offsetWidth-1);var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
			case 7:  {var l = 1;var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
			case 8:  {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
			case 9:  {var l = parseInt(w-div['box'].offsetWidth-1);var r = parseInt(t+(h-div['box'].offsetHeight-1));break;}
			default: {var l = parseInt((w/2)-(div['box'].offsetWidth/2));var r = parseInt(t+((h/2)-(div['box'].offsetHeight/2)));break;}
		}
		
		div['box'].style.left = l+'px';
		div['box'].style.top = r+'px';
		if(document.all && !self.Mask){
			div['mask'].style.left = l+'px';
			div['mask'].style.top = r+'px';
		}
	}
};

/* 蒙板 */
CMSMsgBox.prototype.createMask = function(){
	var self = this;
	var div = new Array(1);
	if(document.all)
	div['mask_ifr'] = this.createDiv(this.BoxDiv, 'iframe', 'block', null, 'msgbox_mask_frame');
	div['mask_div'] = this.createDiv(this.BoxDiv, 'div', 'block', null, 'msgbox_mask_div');
	
	function window_onresize(){
		var h = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);		
		var w = document.all ? Math.min(document.documentElement.scrollWidth, document.body.scrollWidth) : 
				Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
		
		div['mask_div'].style.width = w + 'px';
		div['mask_div'].style.height = h + 'px';
		if(document.all){
			div['mask_ifr'].style.width = div['mask_div'].offsetWidth + 'px';
			div['mask_ifr'].style.height = div['mask_div'].offsetHeight + 'px';
		}
	}
	
	if(window.addEventListener){
		window.addEventListener('scroll', window_onresize, false);
		window.addEventListener('resize', window_onresize, false);
	}else{
		window.attachEvent('onscroll', window_onresize);
		window.attachEvent('onresize', window_onresize);
	}
	if(this.Skin=='loading')div['mask_div'].ondblclick = function(){self.close();};
	window_onresize();
};

/* 创建一个元素  */
CMSMsgBox.prototype.createDiv = function(iParent, element, display, id, clsname){
	var ii = document.createElement(element);
	if(typeof(display)=='string')ii.style.display = display;
	if(typeof(clsname)=='string')ii.className = clsname;
	if(typeof(id)=='string')ii.setAttribute('id', id);
	iParent.appendChild(ii);
	return ii;
};

/* 关闭 */
CMSMsgBox.prototype.close = function(){	
	if(this.IsObject(this.BoxDiv) && this.BoxDiv.parentNode){
		this.BoxDiv.parentNode.removeChild(this.BoxDiv);
	}
};

CMSMsgBox.prototype.$ = function(o){
	return document.getElementById(o);
};

CMSMsgBox.prototype.IsObject = function(o){
	return typeof(o)!='undefined' && o!=null;
};

CMSMsgBox.prototype.setBackgroundColor=function(iColor){
	if(!this.$(this.Id+'bgcolor_div'))return;
	this.$(this.Id+'bgcolor_div').style.backgroundColor = iColor;
};

CMSMsgBox.prototype.setColor=function(iColor){
	if(!this.$(this.Id+'_msgValue'))return;
	this.$(this.Id+'_msgValue').style.color = iColor;
};

CMSMsgBox.prototype.setValue=function(iValue){
	if(!this.$(this.Id+'_msgValue'))return;
	this.$(this.Id+'_msgValue').innerHTML = iValue;
};

CMSMsgBox.prototype.setTitle=function(iTitle){
	if(!this.$(this.Id+'_msgTitle'))return;
	this.$(this.Id+'_msgTitle').innerHTML = iTitle;
};


function visible(Obj, b) {
    if (b) { Obj.style.visibility = "visible"; Obj.style.display = "block"; }
    else { Obj.style.visibility = "hidden"; Obj.style.display = "none"; }
}

function MyOnLoad() {
    if (Mode == 1) {      
    	 for (k = 0; k < Page_PWT.length; k++) {     	    	      	  
    	 	if (Page_PWT[k] == PasswordType) selectTab = k;
    	}
    	
    	if (PasswordType == "02")
    	{    		
    		tabclick(0);
    	}
    		
    	ObjTabSafe = document.getElementById("tab2");
    	if ((ObjTabSafe.style.display == "block") || (ObjTabSafe.style.display == ""))
    	{      		
    		visible(ObjTabSafe, IsInstalledEheEdit());
    	}
    }
    if (Mode == 2) {
        GetDirAppList(1);        
        if (AppList.length == 0) {
            //alert("该用户无可用的应用程序！");
            //location.href = "va.dsp?cmd=Logout";                        
            //return;
        }
        document.getElementById("CNLTreeMenu3").innerHTML = createTree(DirList, "");
        MyCNLTreeMenu = new CNLTreeMenu("CNLTreeMenu3", "li");

        MyCNLTreeMenu.InitCss("Opened", "Closed", "Child", "../Res/css/skin3/s.gif");
        ShowDirList(null, "-");
        MyCNLTreeMenu.ExpandNode(0, SetNodeFocus);
    }

    document.getElementById("OldMode").value = Mode;
    ObjPostSource = document.getElementById("PostSource");
    ObjPostStr1 = document.getElementById("PostStr1");
    ObjPostStr2 = document.getElementById("PostStr2");
    ObjPasswordType = document.getElementById("PasswordType");

    if (Mode == 1) {
        visible(document.getElementById("menu"), false);
     }
    else if (Mode == 2) {
        visible(document.getElementById("menu"), true);        
        visible(document.getElementById("dvAppList"), true); 
    }

    if (ErrorStr != "") setTimeout("alert(ErrorStr)", 300);
}


function ShowAbout(){
   S = "关于";
    if (Lang  == "CHT") 
    {
        S = "關於";
    } 
    if (Lang  == "ENU") 
    {
       S = "About";
    } 
    box1 = new CMSMsgBox("520","320", "", S);
    box1.Mask = true;
    box1.Value = '<img  src="../Res/Img/about_Dlg_' + Lang + '.jpg"  style="width: 480px; height: 266px" />';	        
    box1.show();
}
              
function Mysubmit() {
	  try 
	  {	  	
	    ObjPasswordType = document.getElementById("PasswordType");	    
      ObjPasswordType.value = Page_PWT[selectTab];
	    var Obj1;
	    var Obj2; 
	    if (Mode == 1) {
	    	  if (selectTab == 0)  	  
	    	  {
	          Obj1 = document.getElementById("Edt_TUsername");    	  	
	          Obj2 = document.getElementById("Edt_TPassword") ;
	  	  	}
	    	  if (selectTab == 1)  	  
	    	  {
	          Obj1 = document.getElementById("Edt_DUsername");    	  	
	          Obj2 = document.getElementById("Edt_DPassword") ;
	  	  	}
	    	  if (selectTab == 2)  	  
	    	  {
	          Obj1 = document.getElementById("Edt_SUsername");    	  	
	          Obj2 = document.getElementById("Edt_SUsername") ;
	  	  	}
	        
	        if (Obj1.value.trim() == "") {
	            Obj1.focus();
	            S = "请输入用户名";
	            if (Lang  == "CHT") 
	            {
	                S = "請輸入用戶名";
	            } 
	            if (Lang  == "ENU") 
	            {
	               S = "Please enter your user name";
	            } 
	               
	            alert(S);
	            return false;
	        }
	
	        if (Obj2.value.trim() == "") {
	            Obj2.focus();
	            S = "请输入密码";
	            if (Lang  == "CHT") 
	            {
	                S = "請輸入用密碼";
	            } 
	            if (Lang  == "ENU") 
	            {
	               S = "Please type user password";
	            } 
	            alert(S);
	            return false;
	        }
	        ObjPostSource.value = "Login";
	        ObjPostStr1.value = Obj1.value.trim();
	        if (selectTab == 0) {
	            ObjPostStr2.value = base64encode(utf16to8(Obj2.value.trim())); 	            
	        }    
	        if (selectTab == 1) {
	            ObjPostStr2.value = base64encode(utf16to8(Obj2.value.trim())); 	            
	        }            
	        if (selectTab == 2) {
	            ObjPostStr2.value = Obj2.value;	        		
	        }
	        Obj1.value = "";
	        Obj2.value = "";
	    }
	    else return false;
	    return true;
	  }
		catch(e)
	  {
	  	return false;
	  }
}


//ID, Name Path Icon url
function GetDirAppList(path) {
    for (i = 0; i < AppList.length; i++) {
        pPath = AppList[i][path];
        if (pPath == "/") continue;
        dirs1 = pPath.split("/");
        s = "";
        for (k in dirs1) {
            if (k == 0) continue;
            s = s + "/" + dirs1[k];
            b = 0;
            for (m in DirList) {
                if (s == DirList[m]) {
                    b = 1;
                    break;
                }
            }
            if (b == 0) {
                DirList[DirList.length] = s
            }
        }
    }
}

function SetNodeFocus(obj) {
    if (SelectNode != null) {
        SelectNode.className = obj.className;
    }
    SelectNode = obj;
    SelectNode.className = "Select";
    if (!browser.isMoz) {
        if (SelectNode.offsetTop > MyCNLTreeMenu.scrollTop + MyCNLTreeMenu.clientHeight) MyCNLTreeMenu.scrollTop = SelectNode.offsetTop + 100;
        if (SelectNode.offsetTop < MyCNLTreeMenu.scrollTop) MyCNLTreeMenu.scrollTop = SelectNode.offsetTop - 100;
    }
}


function FindNodes(sID, IsFID, AllNodes) {
    var ret = new Array();
    idName = IsFID == 1 ? "FID" : "PID";
    for (j = 0; j < AllNodes.length; j++) {
        id = AllNodes[j].getAttribute(idName)
        if (sID == id)
            ret[ret.length] = AllNodes[j];
    }
    return ret;
}

function ShowDirList(obj, sPID, isdb) {
    if (sPID == null) {
        sPID = obj.parentNode.getAttribute("FID");
        MyCNLTreeMenu.CollapseNode(obj.parentNode.getAttribute("Num"));
    }

    NodeList = FindNodes(sPID, 0, MyCNLTreeMenu.AllNodes);
    str1 = "";

    if (isdb == 1) {
        32
        Node1 = FindNodes(sPID, 1, MyCNLTreeMenu.AllNodes)[0];
        if (Node1 != null) {
            m = Node1.getAttribute("Num");
            MyCNLTreeMenu.ExpandNode(m, SetNodeFocus);
            if (obj.getAttribute("IsUpDir") != 1) {
                PNode = FindNodes(Node1.getAttribute("PID"), 1, MyCNLTreeMenu.AllNodes)[0];
                if (PNode != null) {
                    m = PNode.getAttribute("Num");
                    MyCNLTreeMenu.ExpandNode(m);
                }
            }
        }
    }
    else {
        if (obj != null) {
            SetNodeFocus(obj)
        }
    }

    if (sPID != "-") {
        Nodes = FindNodes(sPID, 1, MyCNLTreeMenu.AllNodes);
        //str1 = str1 + "<div class=\"App\"><a href=\"###\" IsUpDir=\"1\" onclick='ShowDirList(this, \"" + Nodes[0].getAttribute("PID") + "\", 1)'><img src=\"../Res/Img/Dir2.png\" style=\"margin-bottom:5px;width: 32px; height: 32px\" /><br />..</a></div>";
        str1 = str1 + "<div class=\"iconView\"><a href=\"###\" class=\"iconLink folderLink\" IsUpDir=\"1\" onclick='ShowDirList(this, \"" + Nodes[0].getAttribute("PID") + "\", 1)'><img src=\"../Res/Img/Dir2.png\" width=\"32\" height=\"32\" /><br /><span>..</span></a></div>";
        
    }

    for (k = 0; k < NodeList.length; k++) {
       // str1 = str1 + "<div class=\"App\"><a href=\"###\" onclick='ShowDirList(this, \"" + NodeList[k].getAttribute("FID") + "\", 1)'><img src=\"../Res/Img/Dir.png\" style=\"margin-bottom:5px;width: 32px; height: 32px\" /><br />" + NodeList[k].getAttribute("Value") + "</a></div>";
       str1 = str1 + "<div class=\"iconView\"><a href=\"###\" class=\"iconLink folderLink\" onclick='ShowDirList(this, \"" + NodeList[k].getAttribute("FID") + "\", 1)' title=\""+NodeList[k].getAttribute("Value")+"\"><img src=\"../Res/Img/Dir.png\" width=\"32\" height=\"32\" alt=\""+NodeList[k].getAttribute("Value")+"\" /><br /><span>" + NodeList[k].getAttribute("Value") + "</span></a></div>";
    }


    for (m = 0; m < AppList.length; m++) {
        s = ArrayToStr(AppList[m][1].split("/"));
        if (sPID == s) {
        	if (AppList[m][4] == 60) {
            //str1 = str1 + "<div class=\"App\" ><a href=\"" + AppList[m][3] + "\" target=\"_blank\"><img src=\"../AppIcon/" + AppList[m][2] + "\" style=\"margin-bottom:5px;width: 32px; height: 32px\" /><br />" + AppList[m][0] + "</a></div>";
            str1 = str1 + "<div class=\"iconView\" ><a href=\"" + AppList[m][3] + "\" class=\"iconLink folderLink\" title=title=\""+AppList[m][0]+"\" target=\"_blank\"><img src=\"../AppIcon/" + AppList[m][2] + "\" width=\"32\" height=\"32\" alt=\""+AppList[m][0]+"\" /><br /><span>" + AppList[m][0] + "</span></a></div>";
          }
          else{
          	//str1 = str1 + "<div class=\"App\" ><a href=\"" + getAppUrl(m) + "\" ><img src=\"../AppIcon/" + AppList[m][2] + "\" style=\"margin-bottom:5px;width: 32px; height: 32px\" /><br />" + AppList[m][0] + "</a></div>";
          	str1 = str1 + "<div class=\"iconView\" ><a href=\"" + getAppUrl(m) + "\" title=\""+AppList[m][0]+"\" class=\"iconLink folderLink\" ><img src=\"../AppIcon/" + AppList[m][2] + "\" width=\"32\" height=\"32\" alt=\""+AppList[m][0]+"\" /><br /><span>" + AppList[m][0] + "</span></a></div>";
          	
          }
        }
    }
    document.getElementById("Desktop").innerHTML = str1;
}

function tabclick(n) {
    if (selectTab == n) return;           
    visible(document.getElementById("page" + selectTab), false);
    visible(document.getElementById('page' + n), true);
    if (n == 0) {
        document.getElementById("tabcontent").style.backgroundColor = "#fff";
        document.getElementById("tabcontent").style.color = "#000";
    }
    else
    if (n == 1)
    {
        document.getElementById("tabcontent").style.backgroundColor = "#FFF6D5";
        document.getElementById("tabcontent").style.color = "#763509"
    	}
    else {
        document.getElementById("tabcontent").style.backgroundColor = "#C4E0EC";
        document.getElementById("tabcontent").style.color = "#763509"
    }
      
    selectTab = n;   
}
//----------------------------

//=================Tree相关函数=======
function GetObj(o) {
    var o = document.getElementById(o) ? document.getElementById(o) : o;
    return o;
}


function ExCls(o, a, b, n, HasFocus) {
    var o = GetObj(o);
    for (i = 0; i < n; i++) { o = o.parentNode; }
    o.className = o.className == a ? b : a;
    if (o.className == b) {
        if ((HasFocus == 1)) {
            ShowDirList(o.childNodes[1])
        }
    }
}

function IsAncestor(Ancestor) {
    if (SelectNode == null) return 0;
    if (SelectNode.parentNode == null) return 0;
    node = SelectNode.parentNode;
    id1 = Ancestor.getAttribute("FID");
    while (node != null) {
        if (node.parentNode == null) return 0;
        if (node.parentNode.tagName != "LI") {
            node = node.parentNode;
            continue;
        }
        id2 = node.parentNode.getAttribute("FID");
        if (id2 == id1) return 1;
        if (id2 != id1) {
            node = node.parentNode;
        }
    }
    return 0;
}

function CNLTreeMenu(id, TagName0) {
    this.id = id;
    this.TagName0 = TagName0 == "" ? "li" : TagName0;
    this.AllNodes = GetObj(this.id).getElementsByTagName(TagName0);

    this.InitCss = function(ClassName_Open, ClassName_Close, ClassName_Leaf, ImgUrl) {
         S = "展开/折叠";
         if (Lang  == "CHT") 
         {
            S = "展開/折疊";
         } 
         if (Lang  == "ENU") 
         {
           S = "Expand/Collapse";
         } 
        this.ClassName_Open = ClassName_Open;
        this.ClassName_Close = ClassName_Close;
        this.ClassName_Leaf = ClassName_Leaf;
        this.ImgUrl = ImgUrl || "css/skin3/s.gif";
        this.ImgBlankA = "<img src=\"" + this.ImgUrl + "\" class=\"s\" onclick=\"ExCls(this,'" + ClassName_Open + "','" + ClassName_Close + "',1,  IsAncestor(this.parentNode));\" alt=\""+S+"\" />";
        this.ImgBlankB = "<img src=\"" + this.ImgUrl + "\" class=\"s\" />";
        for (i = 0; i < this.AllNodes.length; i++) {
            this.AllNodes[i].className == "" ? this.AllNodes[i].className = ClassName_Close : "";
            this.AllNodes[i].innerHTML = (this.AllNodes[i].className == ClassName_Leaf ? this.ImgBlankB : this.ImgBlankA) + this.AllNodes[i].innerHTML;
        }
    }

    this.SetNodes = function(n) {
        var sClsName = n == 0 ? this.ClassName_Open : this.ClassName_Close;
        for (i = 0; i < this.AllNodes.length; i++) {
            this.AllNodes[i].className == this.ClassName_Leaf ? "" : this.AllNodes[i].className = sClsName;
        }
    }

    this.ExpandNode = function(n, Call_SelectNode) {
        if (this.AllNodes.length <= n) return;
        if (this.AllNodes[n].className == this.ClassName_Leaf) {
            if (Call_SelectNode != null) {
                Call_SelectNode(this.AllNodes[n].childNodes[1]);
            }
            return;
        }

        this.AllNodes[n].className = this.ClassName_Open;
        if (Call_SelectNode != null)
            Call_SelectNode(this.AllNodes[n].childNodes[1]);
    }

    this.CollapseNode = function(n) {
        if (this.AllNodes.length <= n) return;
        if (this.AllNodes[n].className == this.ClassName_Leaf) return;
        this.AllNodes[n].className = this.ClassName_Close;
    }
}

function serializeXml(oNode) {
    var oSerializer = new XMLSerializer();
    return oSerializer.serializeToString(oNode);
}

function ArrayToStr(vlist, split) {
    s = "";
    split = "";
    if (split == "") split = "-";
    for (k in vlist) {
        if (k == 0) continue;
        s = s + split + vlist[k];
    }
    return s;
}

function createTree(DirList, TopText) {
    var Tree;
    var list = DirList.sort();

    TopText = TopText == "" ? TreeRootName : TopText;
    TextNode = xmlDom.createTextNode(TopText);

    Tree = xmlDom.createElement("ul");

    TopNode = xmlDom.createElement("li");
    TopNode.setAttribute("FID", "-");
    TopNode.setAttribute("Value", TopText);

    Node1 = xmlDom.createElement("A");
    Node1.setAttribute("href", "###");
    Node1.setAttribute("onclick", "ShowDirList(this, \'-\');");


    Node1.appendChild(TextNode);
    TopNode.appendChild(Node1);
    Tree.appendChild(TopNode);

    for (k in list) {
        dir = list[k].split("/");

        Node = xmlDom.createElement("li");
        Node.setAttribute("FID", ArrayToStr(dir));
        Node.setAttribute("Value", dir[dir.length - 1]);


        NodeA = xmlDom.createElement("A");
        NodeA.setAttribute("href", "###");
        NodeA.setAttribute("onclick", "ShowDirList(this, \'" + Node.getAttribute("FID") + "\');");

        TextNode = xmlDom.createTextNode(dir[dir.length - 1]);
        NodeA.appendChild(TextNode);

        sPNode = ArrayToStr(dir.slice(0, dir.length - 1));
        if (sPNode == "") sPNode = "-";
        Node.setAttribute("PID", sPNode);


        Node.appendChild(NodeA);

        var PNode = null;
        NodeList = Tree.getElementsByTagName("li");
        for (m = 0; m < NodeList.length; m++) {
            if (NodeList[m].getAttribute("FID") == sPNode) {
                PNode = NodeList[m];
                break;
            }
        }

        if (PNode == null) {
            PNode = TopNode;
        }
        else {
            if (PNode.childNodes.length <= 2) {
                uNode = xmlDom.createElement("ul");
                PNode.appendChild(uNode);
                PNode = uNode;
            }
            else
                PNode = PNode.childNodes[2];
        }
        PNode.appendChild(Node);

    }

    NodeList = Tree.getElementsByTagName("li");
    for (k = 0; k < NodeList.length; k++) {
        Node = NodeList[k];
        Node.setAttribute("Num", k.toString(10));
        if (Node.childNodes.length < 2) {
            Node.setAttribute("Class", "Child");
        }
    }
    
   
	var s = "";    
	try {
	   s = serializeXml(Tree);
	}
	catch(e)
	{
	 try
	  {
        s = Tree.xml; 
      }      
      catch(e){ s = "";}
     }
     return s;     

}




