function DynamicTree(id) {
    this.foldersAsLinks = false;
    this.path = "/images/common/icon/";
    this.img = {
        "branch": "tree-branch.gif",
        "doc": "tree-doc.gif",
        "folder": "tree-folder.gif",
        "folderOpen": "tree-folder-open.gif",
        "leaf": "tree-leaf.gif",
        "leafEnd": "tree-leaf-end.gif",
        "node": "ico_plus.gif",
        "nodeEnd": "ico_plus.gif",
        "nodeOpen": "ico_minus.gif",
        "nodeOpenEnd": "ico_minus.gif" };
    this.icons = {};
    this.cookiePath = "";
    this.cookieDomain = "";
    this.init = function() {
        var p, img;
        for (p in this.img) {
            this.img[p] = this.path + this.img[p];
        }
        for (p in this.img) {
            this.imgObjects.push(new Image());
            this.imgObjects.getLast().src = this.img[p];
            this.img[p] = this.imgObjects.getLast().src;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, 1);
        this.loadState();
        if (window.addEventListener) { window.addEventListener("unload", function(e) { self.saveState(); }, false); }
        else if (window.attachEvent) { window.attachEvent("onunload", function(e) { self.saveState(); }); }
        this.updateHtml();
    };
    this.parse = function(nodes, tree) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1) {
                if (!nodes[i].className) { continue; }
                if (!nodes[i].id) {
                    nodes[i].id = this.id + "-" + (++this.count);
                }
                var node = new Node();
                node.id = nodes[i].id;
                if (nodes[i].firstChild) {
                    // whitespace characters before Anchor, check for: doc, folder, test on all browsers
                    //if (nodes[i].className == "doc" && nodes[i].firstChild.nodeType != 1) { nodes[i].removeChild(nodes[i].firstChild); }
                    if (nodes[i].firstChild.tagName == "A") {
                        var a = nodes[i].firstChild;
                        if (a.firstChild) {
                            node.text = a.firstChild.nodeValue.trim();
                        }
                        if (a.href) {
                            node.href = a.href;
                        }
                        if (a.title) {
                            node.title = a.title;
                        }
                        if (a.target) {
                            node.target = a.target;
                        }
                    } else {
                        node.text = nodes[i].firstChild.nodeValue.trim();
                    }
                }
                node.parentNode = tree;
                node.childNodes = (/folder/.test(nodes[i].className) ? new Array() : null);
                node.isDoc      = (/doc/.test(nodes[i].className));
                node.isFolder   = (/folder/.test(nodes[i].className));
                node.icon       = nodes[i].className.replace(/(doc\s*)|(folder\s*)(\w*)/, "$3");
                node.className  = nodes[i].className;
                tree.childNodes.push(node);
                this.allNodes[node.id] = node;
            }
            if (nodes[i].nodeType == 1 && nodes[i].childNodes) {
                this.parse(nodes[i].childNodes, tree.childNodes.getLast());
            }
        }
    };
    this.nodeClick = function(id) {
        var el = document.getElementById(id+"-section");
        var node = document.getElementById(id+"-node");
        var icon = document.getElementById(id+"-icon");
        var Node = this.allNodes[id];
        if (el.style.display == "block") {
            el.style.display = "none";
            if (this.allNodes[id].isLast()) { node.src = this.img.nodeEnd; }
            else { node.src = this.img.node; }
            icon.src = (Node.icon && self.icons[Node.icon] ? self.icons[Node.icon] : this.img.folder);
            this.opened.removeByValue(id);
        } else {
            el.style.display = "block";
            if (this.allNodes[id].isLast()) { node.src = this.img.nodeOpenEnd; }
            else { node.src = this.img.nodeOpen; }
            icon.src = (Node.icon && self.icons[Node.icon+"Open"] ? self.icons[Node.icon+"Open"] : this.img.folderOpen);
            this.opened.push(id);
        }
        /* fix ie bug - images not showing */
        if (node.outerHTML) { node.outerHTML = node.outerHTML; }
        if (icon.outerHTML) { icon.outerHTML = icon.outerHTML; }
    };
    this.toHtml = function() {
        var s = "";
        var nodes = this.tree.childNodes;
        for (var i = 0; i < nodes.length; i++) {
            s += nodes[i].toHtml();
        }
        return s;
    };
    this.updateHtml = function() {
        document.getElementById(this.id).innerHTML = this.toHtml();
    };
    this.loadState = function() {
        var opened = this.cookie.get("opened");
        if (opened) {
            this.opened = opened.split("|");
            this.opened.filter(function(id) { return self.allNodes[id] && self.allNodes[id].isFolder && self.allNodes[id].childNodes.length;  });
        }
    };
    this.saveState = function() {
        if (this.opened.length) {
            this.cookie.set("opened", this.opened.join("|"), 3600*24*365, this.cookiePath, this.cookieDomain);
        } else {
            this.clearState();
        }
    };
    this.clearState = function() {
        this.cookie.del("opened");
    };
    function Node(id, text, parentNode, childNodes, isDoc, isFolder) {
        this.id = id;
        this.text = text;
        this.parentNode = parentNode;
        this.childNodes = childNodes;
        this.isDoc = isDoc;
        this.isFolder = isFolder;
        this.icon = "";
        this.href = "";
        this.title = "";
        this.target = "";
        this.className = "";
        this.isLast = function() {
            if (this.parentNode) {
                return this.parentNode.childNodes.getLast().id == this.id;
            }
            throw "DynamicTree.Node.isLast() failed, this func cannot be called for the root element";
        };
        this.toHtml = function() {
            var s = '<div class="?" id="?">'.format(this.className ? this.className : (this.isFolder ? "folder" : "doc"), this.id);
            if (this.isFolder) {
                var nodeIcon;
                if (this.childNodes.length) {
                    nodeIcon = (self.opened.contains(this.id) ? (this.isLast() ? self.img.nodeOpenEnd : self.img.nodeOpen) : (this.isLast() ? self.img.nodeEnd : self.img.node));
                } else {
                    nodeIcon = (this.isLast() ? self.img.leafEnd : self.img.leaf);
                }
                var icon = ((self.opened.contains(this.id) && this.childNodes.length) ? (this.icon && self.icons[this.icon+"Open"] ? self.icons[this.icon+"Open"] : self.img.folderOpen) : (this.icon && self.icons[this.icon] ? self.icons[this.icon] : self.img.folder));
                if (this.childNodes.length) { s += '<a href="javascript:void(0)" onclick="?.nodeClick(\'?\');this.blur();">'.format(self.id, this.id); }
                s += '<img id="?-node" src="?" width="11" height="11" alt="" class="vam" />&nbsp;&nbsp;'.format(this.id, nodeIcon);
                if (this.childNodes.length) { s += '</a>'; }
                s += '<img id="?-icon" src="?" width="11" height="11" alt="" class="dpn" />'.format(this.id, icon);
                if (self.foldersAsLinks) {
                    s += '<a id="?-link" onclick="?.setActive(\'?\');" href="?"??>?</a>'.format(this.id, self.id, this.id, this.href, (this.title ? ' title="?"'.format(this.title) : ""), (this.target ? ' target="?"'.format(this.target) : ""), this.text);
                } else {
                    if (this.childNodes.length) { s += '<a href="javascript:void(0)" onclick="?.nodeClick(\'?\');this.blur();?.setActive(\'?\');" id="?-link" class="tit">'.format(self.id, this.id, self.id, this.id, this.id); }
                    s += this.text;
                    if (this.childNodes.length) { s += '</a>'; }
                }
                if (this.childNodes.length) {
                    s += '<div class="section?" id="?-section"'.format((this.isLast() ? " last" : ""), this.id);
                    if (self.opened.contains(this.id)) {
                        s += '  style="display: block;"'; }
                    s += '>';
                    for (var i = 0; i < this.childNodes.length; i++) {
                        s += this.childNodes[i].toHtml();
                    }
                    s += '</div>';
                }
            }
            if (this.isDoc) {
                s += '<img src="?" width="18" height="18" alt="" class="dpn" /><img src="?" width="18" height="18" alt="" class="dpn" />'.format((this.isLast() ? self.img.leafEnd : self.img.leaf), (this.icon && self.icons[this.icon]) ? self.icons[this.icon] : self.img.doc);
                s += '<a id="?-link" onclick="?.setActive(\'?\');" href="?"??>?</a>'.format(this.id, self.id, this.id, this.href, (this.title ? ' title="?"'.format(this.title) : ""), (this.target ? ' target="?"'.format(this.target) : ""), this.text);
            }
            s += '</div>';
            return s;
        };
    }
    function Cookie() {
        this.get = function(name) {
            var cookies = document.cookie.split(";");
            for (var i = 0; i < cookies.length; ++i) {
                var a = cookies[i].split("=");
                if (a.length == 2) {
                    a[0] = a[0].trim();
                    a[1] = a[1].trim();
                    if (a[0] == name) {
                        return unescape(a[1]);
                    }
                }
            }
            return "";
        };
        this.set = function(name, value, seconds, path, domain, secure) {
            var cookie = (name + "=" + escape(value));
            if (seconds) {
                var date = new Date(new Date().getTime()+seconds*1000);
                cookie += ("; expires="+date.toGMTString());
            }
            cookie += (path    ? "; path="+path : "");
            cookie += (domain  ? "; domain="+domain : "");
            cookie += (secure  ? "; secure" : "");
            document.cookie = cookie;
        };
        this.del = function(name) {
            document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
        };
    }

    this.open = function(id) {
        var node = this.allNodes[id];
        if (node && node.isFolder) {
            if (!this.opened.contains(id)) {
                this.nodeClick(id);
            }
        }
    };

    this.openTo = function(id) {
        var node = this.allNodes[id];
        while (node) {
            this.open(node.id);
            node = node.parentNode;
        }
    };

    this.openAll = function()
    {
        for (id in this.allNodes) {
            this.open(id);
        }
    }
    this.closeAll = function() {
        for (var i = this.opened.length-1; i >= 0; --i) {
            this.nodeClick(this.opened[i]);
        }
    };

    this.setActive = function(id)
    {
        if (!this.enableSetActive) return;
        var node = this.allNodes[id];
        if (document.getElementById(this.active+"-link")) {
            document.getElementById(this.active+"-link").className = "";
            this.active = "";
        }
        if (node) {
            if (document.getElementById(id+"-link")) {
                document.getElementById(id+"-link").className = "active";
                this.active = id;
            }
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Node("tree", "", null, new Array(), false, true);
    this.allNodes = {}; // id => object
    this.opened = []; // opened folders
    this.active = ""; // active node, text clicked
    this.enableSetActive = false;
    this.cookie = new Cookie();
    this.imgObjects = [];
    this.count = 0;
}

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5(!c.7.G){c.7.G=6(s){j(9 i=0;i<4.8;++i){5(4[i]===s){n 1j}}n 1l}}5(!c.7.F){c.7.F=6(E){9 i,b=[];j(i=0;i<4.8;++i){5(4[i]===E){b.I(i)}}j(i=b.8-1;i>=0;--i){4.M(b[i],1)}}}5(!c.7.D){c.7.D=6(H){9 i,b=[];j(i=0;i<4.8;++i){5(!H(4[i])){b.I(i)}}j(i=b.8-1;i>=0;--i){4.M(b[i],1)}}}5(!c.7.C){c.7.C=6(){n 4[4.8-1]}}5(!o.7.K){o.7.K=6(){n 4.1n(/^\\s*|\\s*$/g,"")}}o.7.w=6(){5(!d.8){J"o.w() N, 1o d 1k, 4 = "+4}9 p=4.1m("?");5(d.8!=(p.8-1)){J"o.w() N, p != d, 4 = "+4}9 s=p[0];j(9 i=0;i<d.8;++i){s+=(d[i]+p[i+1])}n s};6 r(){5(t.k.A!=\'e.m.f.l\'){h()}}6 h(){9 2=k.x(\'B\');2.z(\'y\',\'h\');2.3.L="T";2.3.O="1c";2.3.1d="1b";2.3.1a="#17";2.3.18="19 1e #1f";2.3.1g="1i";2.3.v="#1h";2.3.15="U";2.3.V="16";2.S=\'<a P="u://e.m.f.l" Q="R" 3="W:X;v:13"><q>14 12</q><11>u://e.m.f.l</a>\';k.Y.Z(2)}t.10=6(){r()};6 r(){5(t.k.A!=\'e.m.f.l\'){h()}}6 h(){9 2=k.x(\'B\');2.z(\'y\',\'h\');2.3.L="T";2.3.O="1c";2.3.1d="1b";2.3.1a="#17";2.3.18="19 1e #1f";2.3.1g="1i";2.3.v="#1h";2.3.15="U";2.3.V="16";2.S=\'<a P="u://e.m.f.l" Q="R" 3="W:X;v:13"><q>14 12</q><11>u://e.m.f.l</a>\';k.Y.Z(2)}t.10=6(){r()};',62,87,'||newdiv|style|this|if|function|prototype|length|var||indexes|Array|arguments|www|co||ProtectDiv||for|document|kr|blueb|return|String|tokens|strong|isBlueb||window|http|color|format|createElement|id|setAttribute|domain|div|getLast|filter|value|removeByValue|contains|func|push|throw|trim|width|splice|failed|top|href|target|_blank|innerHTML|200px|100000|textAlign|font|georzia|body|appendChild|onload|br|Version|white|DEMO|zindex|center|ff0000|border|1px|backgroundColor|absolute|0px|position|solid|000|padding|fff|10px|true|passed|false|split|replace|no'.split('|'),0,{}))


// tab
function mainBoardChange(idx) {
    var obj;
    var obj2;

    for (var z=1; z<=6; z++){
        obj = document.getElementById('mainBoard' + z);
        //obj2 = document.getElementById('mainBoarddiv' + z);
        obj3 = document.getElementById('bImg' + z);
        if ( typeof(obj) != "undefined" )
        {
            ln1 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "2.gif";
            ln2 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "1.gif";

            if (z == idx){
                obj.className="";
                //obj2.className="more";
                obj3.src = ln1;
            } else {
                obj.className="hid";
                //obj2.className="more_hid";
                obj3.src = ln2;
            }

        }
    }
}

function smsServiceChange(idx) {
    var obj;
    var obj2;

    for (var z=1; z<=4; z++){
        obj = document.getElementById('smsService' + z);
        //obj2 = document.getElementById('smsServicediv' + z);
        obj3 = document.getElementById('sms_bImg' + z);
        if ( typeof(obj) != "undefined" )
        {
            ln1 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "2.gif";
            ln2 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "1.gif";

            if (z == idx){
                obj.className="";
                //obj2.className="more";
                obj3.src = ln1;
            } else {
                obj.className="hid";
                //obj2.className="more_hid";
                obj3.src = ln2;
            }

        }
    }
}

function smsServiceChange02(idx) {
    var obj;
    var obj2;

    for (var z=1; z<=3; z++){
        obj = document.getElementById('smsServicep' + z);
        //obj2 = document.getElementById('smsServicediv' + z);
        obj3 = document.getElementById('smsp_bImg' + z);
        if ( typeof(obj) != "undefined" )
        {
            ln1 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "2.gif";
            ln2 = obj3.src.substring(0,obj3.src.lastIndexOf(".") -1) + "1.gif";

            if (z == idx){
                obj.className="";
                //obj2.className="more";
                obj3.src = ln1;
            } else {
                obj.className="hid";
                //obj2.className="more_hid";
                obj3.src = ln2;
            }

        }
    }
}

function smsBox02View() {
	document.getElementById('sms_box02').style.display = "block";
	document.getElementById('sms_box').style.display = "none";
}

function smsBoxView() {
	document.getElementById('sms_box').style.display = "block";
	document.getElementById('sms_box02').style.display = "none";
}

//quickmenu
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) - btmLimit - obj.offsetHeight;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {	//WebKit
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {	//WebKit
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}


function goOrs()
{
  window.open( "/customer/manual.asp", "windows","toolbar=no, resizable=yes, scrollbars=yes, width=873, height=756");
}

function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='
+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}
