﻿var a_mo=0;
function Processor()
{
	attachEv();
	var objsend;
	objsend=new Object();
	yw_msgread('xmb/data/data.xml',true,objsend,yw_Processmsg);
}


function GetHrefParam(n,m)
	{
		var intLoca=location.href.indexOf("?");
		if(intLoca==-1)
			return false;
		var strParam=location.href.substr(intLoca+n);
		if (m==0)
		{
			var arrParam=strParam.split("&");
			return arrParam;
		}else if (m==1)
		{
			return strParam;
		}
}

//
function getPValue(s)
{
	var ParamList=GetHrefParam(1,0);
	if(!ParamList)
		return false;
	for (var i=0;i<ParamList.length;i++)
	{
		if(ParamList[i].indexOf(s)!=-1)
		{
			return ParamList[i].replace(s+"=","");
		}
		else
			false
	}
}


function gotopage(v)
{
	if(location.href.indexOf("?")!=-1)
	{	
		var pn="pn="+getPValue("pn");
		if(location.href.indexOf(pn)!=-1)
			location.href=location.href.replace("pn="+getPValue("pn"),"pn="+v);
		else
			location.href=location.href+"&pn="+v;
	}
	else
		location.href="?pn="+v;
}
//--------tree--------//
function outspread(n)
{
	var node=findnode(n).nextSibling;
	if(node!=null)
		if(node.style.display=="none")
			node.style.display="inline";
		else
			node.style.display="none";
		changeImg(n);
}
//
function changeImg(n)
{
	if(n.src.indexOf("outspread.gif")!=-1)
		n.src=n.src.replace("outspread.gif","shrink.gif");
	else if(n.src.indexOf("shrink.gif")!=-1)
		n.src=n.src.replace("shrink.gif","outspread.gif");
}
//
function findnode(node)
{
	while(node!=null)
	{
		if(node.parentElement.tagName.toLowerCase()=="div"||node.parentElement.tagName.toLowerCase()=="span")
			{return node.parentElement;}
		if(node.parentElement!=null)
			{node=node.parentElement;}
		else
			return null;
	}	
}
//
function outspreadNode(strid)
{
	
}
//--------menu--------//
var M=new Menu();

function Menu()
{
	this.ActiveMenu=null;
	this.MenuList=new Array();
	this.GetMenu=function(xmb,dstyle,level,styleid)
	{
		var styleid=styleid;
		var isExist=false;
		var ml=this.MenuList.length;
		if(ml>0)
		{
			for(var i=0;i<ml;i++)
			{
				if(this.MenuList[i].m.xmbid==xmb.xmbid)
				{
					ml=i;
					isExist=true;
					break;
				}

			}
		}
		if(!isExist)
		{
			this.MenuList[ml]=new submenu();
			this.MenuList[ml].m=xmb;
			this.MenuList[ml].pm=this.GetParentMenu(xmb.xmbpid);
			this.MenuList[ml].sm=this.GetMenuObj(xmb.xmbid);
			if(dstyle=="0")
			{
				if(level==1)
				{
					this.MenuList[ml].left=gety(xmb);
					this.MenuList[ml].top=getx(xmb)+xmb.offsetHeight;
				}
				if(level==2)
				{
					this.MenuList[ml].left=gety(xmb)+xmb.offsetWidth;
					this.MenuList[ml].top=getx(xmb);
				}
			}
			if(dstyle=="1")
			{
				this.MenuList[ml].left=gety(xmb)+xmb.offsetWidth;
				this.MenuList[ml].top=getx(xmb);
			}
		}
		this.MenuList[ml].s(styleid);
		if(this.ActiveMenu!=null&&this.MenuList[ml].sm!=this.ActiveMenu.sm&&this.IsActive(this.MenuList[ml].pm))
			this.ActiveMenu.sm.style.display="none";
		if(this.ActiveMenu!=null&&this.MenuList[ml].sm!=this.ActiveMenu.sm&&this.MenuList[ml].pm==null)
			this.HiddenActive(this.ActiveMenu);
		this.ActiveMenu=this.MenuList[ml];
	}
	//
	this.HiddenActive=function (am)
	{
		while(am!=null)
		{
			if(am!=null)
				am.sm.style.display="none";
			if(am.pm!=null)
				am=am.pm;
			else
				return;			
		}	
	}
	//
	this.IsActive=function(o)
	{
		if(o==null)
			return true;
		else if(o.sm!=this.ActiveMenu.sm)
			return true;
		else if(o.sm==this.ActiveMenu.sm)
			return false;			
	}
	//
	this.GetMenuObj=function(id)
	{
		if(id!=null&&id!="")
		{
			var obj=document.getElementById(id);
			if(obj.tagName.toLowerCase()=="div"||obj.tagName.toLowerCase()=="span")
				return obj;
			else
				return null;		
		}else
			return null;
	}
	//
	this.GetParentMenu=function(xid)
	{
		var PM=null;
		var IsEx=false;
		var l=this.MenuList.length;
		if(l>0)
		{
			for (var n=0;n<l;n++)
			{
				if(this.MenuList[n].m.xmbid==xid)
				{
					IsEx=true;
					PM=this.MenuList[n];
					break;
				}
			}

			if(IsEx)
				return PM;
			else
				return null;				
		}else
			return null;
	}

}

function submenu()
{
	this.pm=null;
	this.m=null;
	this.sm=null;
	this.left=null;
	this.top=null;
	this.style=1;
	this.s=function(styleid)
	{
		if(this.m!=null)
		{
			/*
			this.sm.style.position="absolute";
			this.sm.style.top=this.top;
			this.sm.style.left=this.left;
			this.sm.style.display="inline";
			*/
			this.m.styleid=styleid;
			this.style=this.m.styleid;
 
			switch(this.style)
			{
				case 1:
					this.alpha();
					break;
				default:
					this.alpha();
					break;
			}
		}
	}

	this.alpha=function()//1
	{
		this.sm.style.width="";
		this.sm.style.height="";
		this.sm.style.backgroundImage="";
		this.sm.style.position="absolute";
		this.sm.style.top=this.top;
		this.sm.style.left=this.left;
		this.sm.innerHTML= this.sm.innerHTML.replace("<DIV id=idParentDiv>","");
		this.sm.innerHTML=this.sm.innerHTML.replace("<DIV id=idDiv1>","");
		this.sm.innerHTML=this.sm.innerHTML.replace("<DIV id=idDiv2>","");
		this.sm.innerHTML=this.sm.innerHTML.replace("</DIV>","");
		this.sm.innerHTML=this.sm.innerHTML.replace("<DIV>","");
		this.sm.innerHTML=this.sm.innerHTML.replace("<DIV id=idDiv1 style=\"DISPLAY: none\">","");
		this.sm.innerHTML=this.sm.innerHTML.replace("<DIV id=idDiv2 style=\"DISPLAY: inline\">","");
		this.sm.innerHTML="	<div id=\"idParentDiv\"><div id=\"idDiv1\"></div><div id=\"idDiv2\" >"+this.sm.innerHTML+"</div></div>";
 
		var oParentDiv;
		this.rdl_doInit=function(e)
		{
			oParentDiv=e.all("idParentDiv");
			this.rdl_play();
		}


		this.rdl_play=function()
		{
			with (oParentDiv)
			{
				if (children[0].style.display=="none") children[1].style.display="inline";
				else children[1].style.display="none";
				filters[0].Apply();
				if (children[0].style.display=="none") children[0].style.display="inline";else children[0].style.display="none";
				if (children[1].style.display=="none") children[1].style.display="inline";else children[1].style.display="none";
				filters[0].play();
			}
		}
		 this.rdl_doInit(this.sm);
		 this.sm.style.display="inline";
	}
 
    this.Blinds=function()
	{

		this.sm.style.backgroundImage="";
		this.sm.style.position="absolute";
		this.sm.style.top=this.top;
		this.sm.style.left=this.left;
		this.sm.style.display="inline";
		this.sm.style.filters[0].paly();
	}
}
 


function getx(o)
	{
		var lx=o.offsetTop;
		while(o=o.offsetParent)
		{
			lx+=o.offsetTop;
		}
		return lx;
}

function gety(o)
	{
		var ly=o.offsetLeft;
		while(o=o.offsetParent)
		{
			ly+=o.offsetLeft;
		}
		return ly;
}


function HiddenMenu(o)
{
	var cuObj=null;
	if(M.ActiveMenu==null)
		return;

	cuObj=GetCuMenu(o)
	if(cuObj!=null)
		return;
	else
	{
		M.ActiveMenu.sm.style.display="none";
		if(M.ActiveMenu.pm!=null)
			M.ActiveMenu=M.ActiveMenu.pm;
	}
}
//
function GetCuMenu(o)
{
	while(o!=null)
	{
		if((o.tagName.toLowerCase()=="div"||o.tagName.toLowerCase()=="span")&&o.className.toLowerCase()=="xmbmenu")
			return o;
		if(o.parentElement!=null)
			o=o.parentElement;

		else
			return null;
	}
}
//
function attachEv()
{
	document.body.attachEvent('onmouseover',Function('HiddenMenu(window.event.srcElement)'));
	document.body.attachEvent('onclick',Function('M.HiddenActive(M.ActiveMenu)'));
}


 
 	function yw_msgread(url,bAsync,msgobj,pfunction)
	{
		obj=new ActiveXObject("Microsoft.XMLHTTP")
		if(obj)
		{
			if(bAsync)
			{
				msgobj.object=obj;
				msgobj.object.onreadystatechange=function()
				{
					if(msgobj.object.readyState==4)
					{
						if (msgobj.object.status==200&&pfunction!=null)
						{
							var sResult=msgobj.object.responseText;
							if(sResult!=null&&sResult!="")
								pfunction(sResult);
						}
						msgobj.object=null;
					}
				}
				msgobj.object.open("GET",url,bAsync);
				msgobj.object.send();
				msgobj.time=new Date();
				return true;
				
			}
			else
			{
				obj.open("GET",url,bAsync);
				obj.send();
				if(pfunction!=null)
					pfunction(obj.responseText);
				return true;				
			}
	    }
	    else
			return false;
	}

	function Object()
	{
		this.object=null;
		this.time=null;
		
		return this;
	}

	function yw_Processmsg(s)
	{
	var oXmlDataa = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
			oXmlDataa.loadXML(s);
	var oXslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
	var oXsltDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	oXsltDoc.async = false;
	oXsltDoc.load('xmb/xslt/Main.xsl');
 
 	oXslt.stylesheet = oXsltDoc;
	var oXsltProc = oXslt.createProcessor();
	oXsltProc.input =  oXmlDataa
	var componentlist = document.getElementsByTagName('moveage_component');
	var components=new Array();

	if(componentlist.length!=0)
	{
		for (var i=0;i<componentlist.length;i++)
		{
			if(typeof(componentlist[i].xmb_mode)=="undefined")
				components[components.length]=componentlist[i];
			else if(componentlist[i].xmb_mode=="dynamic"||componentlist[i].xmb_mode=="")
				components[components.length]=componentlist[i];
		}
	}
 
	for (var n=0;n<components.length;n++)
	{
		oXsltProc.reset();
		oXsltProc.addParameter('type',components[n].xmb_type);
		if(components[n].id!=null)
			oXsltProc.addParameter('id',components[n].id);
		if(components[n].xmb_datafld!=null)
			oXsltProc.addParameter('datafld',components[n].xmb_datafld);
		if(components[n].xmb_dataitem!=null)
			oXsltProc.addParameter('dataitem',components[n].xmb_dataitem);
		if(components[n].xmb_template!=null)
			oXsltProc.addParameter('template',components[n].xmb_template);
		if(components[n].xmb_dataid!="")
		{
			oXsltProc.addParameter('dataid',components[n].xmb_dataid);
		}
		else
		{
			if(getPValue("dataid"))
			{
				oXsltProc.addParameter('dataid',getPValue("dataid"));
			}
			else
			{
				if(components[n].xmb_defaultid!="")
					oXsltProc.addParameter('dataid',components[n].xmb_defaultid);
			}
		}
		if(getPValue("dataid"))
			oXsltProc.addParameter('treeid',getPValue("dataid"));
		if(components[n].xmb_direct!=null)
			oXsltProc.addParameter('direct',components[n].xmb_direct);
		if(components[n].xmb_style!=null)
			oXsltProc.addParameter('style',components[n].xmb_style);
		if(components[n].xmb_width!=null)
			oXsltProc.addParameter('width',components[n].xmb_width);
		if(components[n].xmb_height!=null)
			oXsltProc.addParameter('height',components[n].xmb_height);
		if(components[n].xmb_cols!=null)
			oXsltProc.addParameter('cols',components[n].xmb_cols);
		if(components[n].xmb_rows!=null)
			oXsltProc.addParameter('rows',components[n].xmb_rows);
		if(components[n].xmb_pagemode!=null)
			oXsltProc.addParameter('pagemode',components[n].xmb_pagemode);
		if(components[n].xmb_morelink!=null)
			oXsltProc.addParameter('morelink',components[n].xmb_morelink);
		if(components[n].xmb_search!=null)
			oXsltProc.addParameter('search',components[n].xmb_search);			
		if(components[n].xmb_sort!=null)
			oXsltProc.addParameter('sort',components[n].xmb_sort);			
		if(components[n].xmb_action!=null)
			oXsltProc.addParameter('action',components[n].xmb_action);			
		if(getPValue("pn"))
			oXsltProc.addParameter('pn',getPValue("pn"));
		if(getPValue("ActiveNode"))
			oXsltProc.addParameter('ActiveNode',getPValue("ActiveNode"));
		if(getPValue("key"))
			oXsltProc.addParameter('key',unescape(getPValue("key")));
		oXsltProc.transform();
		components[n].parentNode.innerHTML = oXsltProc.output;
	}
}

function searcher()
{
	var k="";
	var d="";
	var f=document.getElementById("searchform");
	var l=f.action;
	if(f.kw)
		k=f.kw.value;
	if(f.dataid)
		d=f.dataid.value;
	if(k!="")
		location.href=l+"?key="+escape(k)+"&dataid="+d;
}
