	// JavaScript Document

	    function $_getID(id)
	    {
		    return document.getElementById(id);
	    }
		//读取xml文件类;
		var LoadXMLFile = function(){
            var dom;
            if(navigator.userAgent.indexOf("MSIE") > 0){
                dom = new ActiveXObject("Microsoft.XMLDOM");
                dom.async = false;
                dom.load("Handlelist.xml");
            }
            else if (document.implementation && document.implementation.createDocument) {
                var xmlhttp = new window.XMLHttpRequest();
                xmlhttp.open("GET", "Handlelist.xml", false);
                xmlhttp.send(null);
               dom = xmlhttp.responseXML;
            }else{
                xmlDom = null;
            }
            return dom;
        }
		
		//用于FF获取当前节点的文本内容函数;//兼容ff;
		function getText(oNode) {
			var sText = "";
			for (var i = 0; i < oNode.childNodes.length; i++) {
			   if (oNode.childNodes[i].hasChildNodes()) {
				   sText += getText(oNode.childNodes[i]);
			   } else {
				   sText += oNode.childNodes[i].nodeValue;
			   }
			}
			return sText;
		}
		function FrameRedirect(frameId, url)
		{
		    if (($_getID(frameId) != null) && (url != "#") && (url.length > 0))
		    {
		        window.frames[frameId].location.href = url;
		    }
		}
		//构建表格及填充表格类;
		var createtable = function(HandleNode){
			//HandleNode 为xml文档对象.
			var otable = document.createElement("table");
			var otablebody = document.createElement("tbody");
			otable.setAttribute("id","tree_menu");
			otable.setAttribute("cellSpacing","0");
			otable.setAttribute("cellPadding","0");
			otable.setAttribute("width","100%");
			otable.setAttribute("border","0");
			for (var b=0;b<HandleNode.length;b++){
				for (var a=0;a<HandleNode[b].childNodes.length;a++){
					var otableRow = document.createElement("tr");
					var otableCell = document.createElement("td");
					otableCell.setAttribute("class","treeview_unfocus");
					if(document.all){otableCell.setAttribute("className","treeview_unfocus");}
					if (a==0){
						if(document.all){otableCell.setAttribute("className","treeview_unfocus2");}else{otableCell.setAttribute("class","treeview_unfocus2");}
					}
					//alert(HandleNode[b].childNodes[a].childNodes.length);
					if(HandleNode[b].childNodes[a].childNodes.length != 0 || (navigator.userAgent.indexOf("MSIE") > 0))//兼容ff;
					{
						if (HandleNode[b].childNodes[a].getAttribute("url").toString() != ""){
							otableCell.innerHTML = "<img src=\"" + HandleNode[b].childNodes[a].getAttribute("icon").toString() + "\">" + "&nbsp;" + "<a onclick=\"FrameRedirect(\'Main\', \'" +  HandleNode[b].childNodes[a].getAttribute("url").toString() + "\');\" href=\"#\">" + HandleNode[b].childNodes[a].getAttribute("textnode").toString() + "<\/a>";
						}else{
							otableCell.innerHTML = "<img src=\"" + HandleNode[b].childNodes[a].getAttribute("icon").toString() + "\">" + "&nbsp;" + HandleNode[b].childNodes[a].getAttribute("textnode").toString();
						}
						otableCell.setAttribute("id","tree_menu" + (HandleNode[b].childNodes.length+1));
						otableRow.appendChild(otableCell);
						otablebody.appendChild(otableRow);

						if(HandleNode[b].childNodes[a].childNodes.length != 0){
								var otableRow2 = document.createElement("tr");
								var otableCell2 = document.createElement("td");
								var createDiv = document.createElement("div");
								var createUl = document.createElement("ul");
								for(var c=0;c<HandleNode[b].childNodes[a].childNodes.length;c++){
								if(getText(HandleNode[b].childNodes[a].childNodes[c]) != ""){ //兼容ff;
									var createLi = document.createElement("li");
									if(document.all){createDiv.setAttribute("className","BasicinfoShow");}else{createDiv.setAttribute("class","BasicinfoShow");}
									if(HandleNode[b].childNodes[a].childNodes[c].childNodes.length !=0){
									    if (HandleNode[b].childNodes[a].childNodes[c].getAttribute("target")==null)
										    createLi.innerHTML = "<a onclick=\"FrameRedirect(\'Main\', \'" + HandleNode[b].childNodes[a].childNodes[c].getAttribute("url").toString() + "\');\" href=\"#\"><img src=\"" + HandleNode[b].childNodes[a].childNodes[c].getAttribute("icon").toString() + "\">" + getText(HandleNode[b].childNodes[a].childNodes[c]) + "<\/a>"
										else
										    createLi.innerHTML = "<a href=\""+ HandleNode[b].childNodes[a].childNodes[c].getAttribute("url").toString() +"\" target=\""+ HandleNode[b].childNodes[a].childNodes[c].getAttribute("target").toString() +"\"><img src=\"" + HandleNode[b].childNodes[a].childNodes[c].getAttribute("icon").toString() + "\">" + getText(HandleNode[b].childNodes[a].childNodes[c]) + "<\/a>"
										createDiv.setAttribute("id","menulist" + (c+1));
									}
									createLi.onclick = function(){thisMenuStyleChange('tree_menu',this);};
									createUl.appendChild(createLi);
									createDiv.appendChild(createUl);
									otableCell2.appendChild(createDiv);
									otableRow2.appendChild(otableCell2);
									otablebody.appendChild(otableRow2);
								}
							}
						}
					}
				}
			}
			otable.appendChild(otablebody);
			return otable;
		}
		
		//构建子菜单项及填充类;
		function SelectMenu(menuItem, subMenuId)
        {
			if($_getID("leftList").style.display == 'none') $_getID("leftList").style.display = '';
			//判断是否已经实例化了LoadXMLFile类;
			if(typeof(XMLDom) == 'undefined'){
			try{
				var XMLDom = new LoadXMLFile();
			}catch (e){
				alert(e.message);}
			}
			//alert(subMenuId);
			var HandleNode = XMLDom.getElementsByTagName(subMenuId);
			try {
			    var createMenuListTable = new createtable(HandleNode); //实例化creattable类;
			    document.getElementById("LeftMenuList").innerHTML = "";
			    document.getElementById("LeftMenuList").appendChild(createMenuListTable); //添加动态生成的table节点到leftMenulist下面;
			} catch (e) {
			    alert(e.message);
			}

			switch (subMenuId.substr(7)) {
			    case "1":
			        FrameRedirect('Main', 'shop/SiteContent.aspx');
			        break;
			    case "2":
			        FrameRedirect('Main', 'productcatalog/ProductOnSales.aspx');
			        break;
			    case "3":
			        FrameRedirect('Main', 'Membership/ManageMembers.aspx');
			        break;
			    case "4":
			        FrameRedirect('Main', 'sales/ManageOrder.aspx');
			        break;
			    case "5":
			        FrameRedirect('Main', 'promote/EngagedPromoteSales.aspx');
			        break;
			    case "6":
			        FrameRedirect('Main', 'shop/AfficheList.aspx');
			        break;
			    case "7":
			        FrameRedirect('Main', 'Membership/ManageLeaveComments.aspx');
			        break;
			    case "8":
			        FrameRedirect('Main', 'shop/EmailToUser.aspx');
			        break;
			    case "9":
			        FrameRedirect('Main', 'sales/SaleTotalStatistics.aspx');
			        break;
			    case "10":
			        FrameRedirect('Main', 'service.aspx#1');
			        break;
			}
			
			//alert(subMenuId);
            if ($_getID("txtSelectedMenuId").value == menuItem.id)
                return;
            menuItem.className = "Current";
            if ($_getID("txtSelectedMenuId").value.length > 0)
                $_getID($_getID("txtSelectedMenuId").value).className = "";
            $_getID("txtSelectedMenuId").value = menuItem.id;
        }
        
        function MouseOver(menuItem)
        {
            if ($_getID("txtSelectedMenuId").value == menuItem.id)
                return;
            menuItem.className = "hover";
        }
        
        function MouseOut(menuItem)
        {
            if ($_getID("txtSelectedMenuId").value == menuItem.id)
                return;
            menuItem.className = "";
        }
        
        function SubmenuMouseOver(menuItem, subMenuId)
        {
            menuItem.className = "hover";
            if (subMenuId == '')
                return;
            var subMenu = $_getID(subMenuId);
            if (subMenu == null)
                return;
            var offsetTop = menuItem.offsetTop; 
            var offsetLeft = menuItem.offsetLeft; 
            var offsetWidth = menuItem.offsetWidth; 
            var offsetHeight = menuItem.offsetHeight; 
            while( menuItem = menuItem.offsetParent ) 
            { 
                offsetTop += menuItem.offsetTop; 
                offsetLeft += menuItem.offsetLeft; 
            }
            
            subMenu.style.left = offsetLeft + "px";
            subMenu.style.top = (offsetTop + offsetHeight - 3) + "px";
            subMenu.className = "porcelain2show"; 
        }
        
        function SubmenuMouseOut(menuItem)
        {
            menuItem.className = "";
        }

		function leftList(thisID,thisImgID)
		{
			thisID = $_getID(thisID);
			if (thisID.style.display == 'none')
			{
				thisID.style.display = '';
			}
			else
			{
				thisID.style.display = 'none';
			}
		}
		
		function callLeftTree(obj,submenuSum)
		{
			var submenuSumLayer = $_getID(submenuSum);
			if (submenuSumLayer.className == 'BasicinfoHide')
			{
				submenuSumList =$_getID('tree').getElementsByTagName('div').length + 1;
				submenuSumLayer.className = 'BasicinfoShow';
				for (i=1;i<submenuSumList ;i++ )
				{	
					var submenuSumthis = 'MenuList_' + i;
					if (submenuSum != submenuSumthis)
					{
						var submenuSumthis = $_getID(submenuSumthis);
						submenuSumthis.className = 'BasicinfoHide';
					}
				}
			}
			//Sub menu background change;
			var subMainMenuList = $_getID('tree_menu').getElementsByTagName('td').length + 1;
			var subMenuTD = $_getID(obj);
			subMenuTD.className = 'treeview_focus';
			for (i=1;i<subMainMenuList ;i++ )
			{	
				var submenuTDthis = 'tree_menu' + i;
				if (subMenuTD.id != submenuTDthis)
				{
					var submenuTDthis = $_getID(submenuTDthis);
					submenuTDthis.className = 'treeview_unfocus';
				}
			}
		}

		function thisMenuStyleChange(menuID,thisID)
		{
			var menuID = $_getID(menuID);
			//alert(menuID);
			
			var menuList = menuID.getElementsByTagName('li').length;
			var testList = menuID.getElementsByTagName('li');
			for (i=0;i<menuList ;i++ )
			{	
				testList[i].className = '';
			}
			thisID.className = 'selectThisItemsStyle';
		}
		
		//换肤.
        function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
        {
            var Days = 30; //此 cookie 将被保存 30 天
            var exp  = new Date();    //new Date("December 31, 9998");
            exp.setTime(exp.getTime() + Days*24*60*60*1000);
            document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
        }
        function getCookie(name)//取cookies函数        
        {
            var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
             if(arr != null) return unescape(arr[2]); 
             return null;
        }

        function MyMoodClass(thisMood)
        {
                if (thisMood.toString() == "Blue")
                {
                    $_getID("cssLink").href = "css/IFrame.css";
                    return;
                }
                $_getID("cssLink").href = "css/IFrame_" + thisMood.toString() + ".css";
        }
