﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Mzx.GetHtml");

Mzx.GetHtml.IGetHtmlBase = function() {}
Mzx.GetHtml.IGetHtmlBase.Prototype = {
	set_d : function(value){},
	getUrl: function(){}
}
Mzx.GetHtml.IGetHtmlBase.registerInterface("Mzx.GetHtml.IGetHtmlBase");



Mzx.GetHtml.GetHtmlBase = function() {
	this.d = 0;
	this.isLoad = false;
	Mzx.GetHtml.GetHtmlBase.initializeBase(this);
}

Mzx.GetHtml.GetHtmlBase.prototype =
{
    set_d: function (value) {
        this.d = value;
    },

    getUrl: function () {
        return "";
    },

    writeTo: function () {
        this.isLoad = true;
        var url = this.getUrl();
        if (this.d != 0)
            url += "&d=" + this.d;
        webRequest = new Sys.Net.WebRequest();
        webRequest.set_url(url);
        webRequest.set_httpVerb("GET");

        displayElement = $get(this.loadid);
        if (displayElement != null) {
            if (document.all)
                displayElement.innerHTML = "<img src='" + g_Mzx_ApplicationPath + "/Images/spinner.gif' border=0><span style='font-size:13px'>正在装载...</span>";
            else
            // Firefox 
                displayElement.innerHTML = "<img src='" + g_Mzx_ApplicationPath + "/Images/spinner.gif' border=0><span style='font-size:13px'>正在装载...</span>";
        }


        webRequest.add_completed(function (executor, eventArgs) {
            if (executor.get_responseAvailable()) {
                var elementId = executor.getResponseHeader("loadid");
                if (elementId != "") {
                    displayElement = $get(elementId);
                    if (displayElement != null) {
                        var xml = executor.get_xml();
                        if (xml != null) {
                            var htmlAttribute = xml.documentElement.attributes.getNamedItem("html");
                            if (htmlAttribute != null) {
                                if (document.all)
                                    displayElement.innerHTML = HTMLDecode(htmlAttribute.value);
                                else
                                // Firefox
                                    displayElement.innerHTML = HTMLDecode(htmlAttribute.value);

                                if (typeof AMprocessNode != "undefined")
                                    AMprocessNode(displayElement);

                            }

                            var titleAttribute = xml.documentElement.attributes.getNamedItem("title");
                            if (titleAttribute != null && titleAttribute.value != "" && titleAttribute.value.indexOf(" - [") < 0) {
                                if (document.title == null || document.title.indexOf(" - [") < 0)
                                    document.title = titleAttribute.value + " - [" + document.title + "]";
                            }
                        }
                        else {
                            var resposeData = executor.get_responseData();
                            if (resposeData != null) {
                                var i1 = resposeData.indexOf('html="');
                                var i2 = resposeData.indexOf('"', i1 + 6);
                                if (i1 > 0 && i1 < i2) {
                                    var _html = resposeData.substring(i1 + 6, i2);
                                    _html = XMLDecode(_html);
                                    _html=HTMLDecode(_html);
                                    if (document.all)
                                        displayElement.innerHTML = _html;
                                    else
                                    // Firefox
                                        displayElement.innerHTML = _html;
                                }

                                i1 = resposeData.indexOf('title="');
                                i2 = resposeData.indexOf('"', i1 + 7);
                                if (i1 > 0 && i1 < i2) {
                                    var titleVale = resposeData.substring(i1 + 7, i2);
                                    if (titleVale != null && titleVale != "" && titleVale.indexOf(" - [") < 0) {
                                        if (document.title == null || document.title.indexOf(" - [") < 0)
                                            document.title = titleVale + " - [" + document.title + "]";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
        webRequest.invoke();
    }

}
Mzx.GetHtml.GetHtmlBase.registerClass("Mzx.GetHtml.GetHtmlBase",null, Mzx.GetHtml.IGetHtmlBase);



//// ========================================================
//// 登录对象////
//// ========================================================
Mzx.GetHtml.GetLogin = function() {
	Mzx.GetHtml.GetLogin.initializeBase(this);

	this.src = g_Mzx_ApplicationPath + '/WebShow/WebLogin.ashx';
	this.name = '';
	this.sitename = '';
	this.returnurl = '';
	this.linkcss = '';
	this.literalhtml = '';
	this.loadid = '';
}

Mzx.GetHtml.GetLogin.prototype =
{
	set_d: function(value) {
		this.d = value;
	},

	getUrl: function() {
		var serializer = Sys.Serialization.JavaScriptSerializer;

		var url = this.src +
			'?name=' + this.name +
			'&sitename=' + encodeURIComponent(this.sitename) +
			'&returnurl=' + encodeURIComponent(this.returnurl) +
			'&linkcss=' + encodeURIComponent(this.linkcss) +
			'&literalhtml=' + encodeURIComponent(this.literalhtml) +
			'&loadid=' + this.loadid;
		return url;
	}

}

Mzx.GetHtml.GetLogin.registerClass("Mzx.GetHtml.GetLogin", Mzx.GetHtml.GetHtmlBase, Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 列表显示[留言簿式]////
//// ========================================================
Mzx.GetHtml.GetListDetailPage = function()
{
	Mzx.GetHtml.GetListDetailPage.initializeBase(this);
	
	this.src=g_Mzx_ApplicationPath+'/WebShow/WebListDetail.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.dockid=0;
	this.row=0;
	this.col=0;
	this.table=0;
	this.titleclass='';
	this.tableclass='';
	this.recordclass=''
	this.authorclass='';
	this.contentclass='';
	this.pageclass='';
	this.discussurl='';
	this.key='';
	this.page=1;
	this.pagesize=0;
}

Mzx.GetHtml.GetListDetailPage.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&loadid='+this.loadid+
			'&dockid='+this.dockid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&titleclass='+this.titleclass+
			'&tableclass='+this.tableclass+
			'&recordclass='+this.recordclass+
			'&authorclass='+this.authorclass+
			'&contentclass='+this.contentclass+
			'&pageclass='+this.pageclass+
			'&discussurl='+encodeURIComponent(this.discussurl)+
			'&key='+encodeURIComponent(this.key)+
			'&page='+this.page+
			'&pagesize='+this.pagesize;

		return url;
	}

}

Mzx.GetHtml.GetListDetailPage.registerClass("Mzx.GetHtml.GetListDetailPage",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 图象显示对象////
//// ========================================================
Mzx.GetHtml.GetListImg = function()
{
	Mzx.GetHtml.GetListImg.initializeBase(this);
	
	this.src=g_Mzx_ApplicationPath+'/WebShow/WebListImage.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.width=0;
	this.txtlen=0;
	this.row=0;
	this.col=0;
	this.table=0;
	this.tableclass='';
	this.classname='';
	this.linkurl='';
	this.itemtag='';
	this.itemimg='';
	this.page=1;
	this.pagesize=0;
	this.headtextlen=0;
	this.imgwidth=0;
	this.ImgHeight=0;
	this.imgtableclass='';
	this.imgclass='';
	this.headclass='';
	this.textclass='';
	this.showPage=0;
}

Mzx.GetHtml.GetListImg.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&loadid='+this.loadid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&itemclass=' + this.classname +
			'&tableclass='+this.tableclass+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&width='+this.width+
			'&txtlen='+this.txtlen+
			'&page='+this.page+
			'&pagesize='+this.pagesize+
			'&showPage='+this.showPage+
			'&headtextlen='+this.headtextlen+
			'&imgwidth='+this.imgwidth+
			'&ImgHeight='+this.ImgHeight+
			'&imgclass='+this.imgclass+
			'&imgtableclass='+this.imgtableclass+
			'&headclass='+this.headclass+
			'&textclass='+this.textclass+
			'&linkurl='+encodeURIComponent(this.linkurl)+
			'&itemtag='+encodeURIComponent(this.itemtag)+
			'&itemimg='+encodeURIComponent(this.itemimg);

		return url;
	}

}

Mzx.GetHtml.GetListImg.registerClass("Mzx.GetHtml.GetListImg",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 列表对象////
//// ========================================================
Mzx.GetHtml.GetList = function()
{
	Mzx.GetHtml.GetList.initializeBase(this);
	
	this.src=g_Mzx_ApplicationPath+'/WebShow/WebList.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.showgroup=0;
	this.showdate=0;
	this.showeditor=0;
	this.key='';
	this.width=0;
	this.txtlen=0;
	this.row=0;
	this.col=0;
	this.table=0;
	this.tableclass='';
	this.classname='';
	this.pageclass='';
	this.linkurl='';
	this.itemtag='';
	this.itemimg='';
	this.page=1;
	this.pagesize=0;
}

Mzx.GetHtml.GetList.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&loadid='+this.loadid+
			'&dockid='+this.dockid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&itemclass=' + this.classname +
			'&tableclass='+this.tableclass+
			'&pageclass='+this.pageclass+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&showgroup='+this.showgroup+
			'&showdate='+this.showdate+
			'&showeditor='+this.showeditor+
			'&key='+encodeURIComponent(this.key)+
			'&width='+this.width+
			'&txtlen='+this.txtlen+
			'&page='+this.page+
			'&pagesize='+this.pagesize+
			'&linkurl='+encodeURIComponent(this.linkurl)+
			'&itemtag='+encodeURIComponent(this.itemtag)+
			'&itemimg='+encodeURIComponent(this.itemimg);

		return url;
	}

}

Mzx.GetHtml.GetList.registerClass("Mzx.GetHtml.GetList",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 列表分页显示对象////
//// ========================================================
Mzx.GetHtml.GetListPage = function() {
	Mzx.GetHtml.GetListPage.initializeBase(this);

	this.src = g_Mzx_ApplicationPath + '/WebShow/WebListList.ashx';
	this.name = '';
	this.tocId = 0;
	this.tocLb = 0;
	this.lb = 1;
	this.loadid = '';
	this.id = 0;
	this.showgroup = 0;
	this.showdate = 0;
	this.showeditor = 0;
	this.key = '';
	this.width = 0;
	this.txtlen = 0;
	this.row = 0;
	this.col = 0;
	this.table = 0;
	this.tableclass = '';
	this.classname = '';
	this.pageclass = '';
	this.classhead = '';
	this.linkurl = '';
	this.itemtag = '';
	this.itemimg = '';
	this.page = 1;
	this.pagesize = 0;
	this.showDescription = 0;
}

Mzx.GetHtml.GetListPage.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&loadid='+this.loadid+
			'&dockid='+this.dockid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&itemclass=' + this.classname +
			'&tableclass='+this.tableclass+
			'&pageclass='+this.pageclass+
			'&classhead=' + this.classhead +
			'&tocId=' + this.tocId +
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&showgroup='+this.showgroup+
			'&showdate='+this.showdate+
			'&showeditor='+this.showeditor+
			'&key='+encodeURIComponent(this.key)+
			'&width='+this.width+
			'&txtlen='+this.txtlen+
			'&page='+this.page+
			'&pagesize='+this.pagesize+
			'&showDescription='+this.showDescription+
			'&linkurl='+encodeURIComponent(this.linkurl)+
			'&itemtag='+encodeURIComponent(this.itemtag)+
			'&itemimg='+encodeURIComponent(this.itemimg);

		return url;
	}

}

Mzx.GetHtml.GetListPage.registerClass("Mzx.GetHtml.GetListPage",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);



//// ========================================================
//// 资源库列表分页显示对象////
//// ========================================================
Mzx.GetHtml.GetResListPage = function()
{
	Mzx.GetHtml.GetResListPage.initializeBase(this);

	this.src=g_Mzx_ApplicationPath+'/WebShow/WebRecListPage.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.showgroup=0;
	this.showdate=0;
	this.showeditor=0;
	this.key='';
	this.width=0;
	this.txtlen=0;
	this.row=0;
	this.col=0;
	this.table=0;
	this.tableclass='';
	this.classname='';
	this.pageclass='';
	this.linkurl='';
	this.itemtag='';
	this.itemimg='';
	this.page=1;
	this.pagesize=0;
}

Mzx.GetHtml.GetResListPage.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&loadid='+this.loadid+
			'&dockid='+this.dockid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&itemclass=' + this.classname +
			'&tableclass='+this.tableclass+
			'&pageclass='+this.pageclass+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&showgroup='+this.showgroup+
			'&showdate='+this.showdate+
			'&showeditor='+this.showeditor+
			'&key='+encodeURIComponent(this.key)+
			'&width='+this.width+
			'&txtlen='+this.txtlen+
			'&page='+this.page+
			'&pagesize='+this.pagesize+
			'&linkurl='+encodeURIComponent(this.linkurl)+
			'&itemtag='+encodeURIComponent(this.itemtag)+
			'&itemimg='+encodeURIComponent(this.itemimg);

		return url;
	}

}

Mzx.GetHtml.GetResListPage.registerClass("Mzx.GetHtml.GetResListPage",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 文档对象////
//// ========================================================
Mzx.GetHtml.GetDocument = function()
{
	Mzx.GetHtml.GetDocument.initializeBase(this);
	
	this.src=g_Mzx_ApplicationPath+'/WebShow/WebDoc.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.discussurl='';
	this.discussurlclass='';
	this.showfooter=0;
	this.showdiscuss=0;
	this.classhead='';
	this.classfoot='';
	this.classfile='';
}

Mzx.GetHtml.GetDocument.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&loadid='+this.loadid+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&discussurl='+encodeURIComponent(this.discussurl)+
			'&discussurlclass='+this.discussurlclass+
			'&showfooter='+this.showfooter+
			'&showdiscuss='+this.showdiscuss+
			'&classhead='+this.classhead+
			'&classfoot='+this.classfoot+
			'&classfile='+encodeURIComponent(this.classfile);

		return url;
	}

}

Mzx.GetHtml.GetDocument.registerClass("Mzx.GetHtml.GetDocument",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 讨论对象////
//// ========================================================
Mzx.GetHtml.GetDiscussPage = function()
{
	Mzx.GetHtml.GetDiscussPage.initializeBase(this);
	
	this.src=g_Mzx_ApplicationPath+'/WebShow/WebDiscuss.ashx';
	this.name='';
	this.tocId=0;
	this.tocLb=0;
	this.lb=1;
	this.loadid='';
	this.id=0;
	this.row=0;
	this.col=0;
	this.table=0;
	this.titleclass='';
	this.tableclass='';
	this.discussclass=''
	this.authorclass='';
	this.contentclass='';
	this.pageclass='';
	this.page=1;
	this.pagesize=0;
}

Mzx.GetHtml.GetDiscussPage.prototype= 
{
	set_d : function(value)
	{
		this.d=value;
	},

	getUrl : function()
	{
		var serializer = Sys.Serialization.JavaScriptSerializer;
		
		var url = this.src+
			'?id='+this.id+
			'&name='+this.name+
			'&tocId='+this.tocId+
			'&tocLb='+this.tocLb+
			'&lb='+this.lb+
			'&loadid='+this.loadid+
			'&row='+this.row+
			'&col='+this.col+
			'&table='+this.table+
			'&titleclass='+this.titleclass+
			'&tableclass='+this.tableclass+
			'&discussclass='+this.discussclass+
			'&authorclass='+this.authorclass+
			'&contentclass='+this.contentclass+
			'&pageclass='+this.pageclass+
			'&page='+this.page+
			'&pagesize='+this.pagesize;

		return url;
	}

}

Mzx.GetHtml.GetDiscussPage.registerClass("Mzx.GetHtml.GetDiscussPage",Mzx.GetHtml.GetHtmlBase,Mzx.GetHtml.IGetHtmlBase);


//// ========================================================
//// 获取网址提供的参数////
//// ========================================================
function GetUrlPara(varName)
{
	var url=document.location.href;
	var i=url.toLowerCase().indexOf(varName.toLowerCase()+'=');
	if(i>0)
	{
		var i1=url.indexOf("&",i);
		if(i1>0)
		{
			return url.substring(i+varName.length+1,i1);
		}
		else
		{
			return url.substring(i+varName.length+1,url.length);
		}
	}
	return '';
}


//// ==============================================
//// 搜索函数,t指分页类别(1.图象分页显示,2.音乐列表,3.搜索,4.区域搜索)////
//// ==============================================
function Mzx_SiteSearch(keyId,id,type)
{
	var serializer = Sys.Serialization.JavaScriptSerializer;

	var textElement = $get(keyId);
	if(textElement!=null)
	{
		var key=textElement.value;
		key=encodeURIComponent(key);
		
		if(arguments.length>2)
		{
			var radioElement = $get(type);
			if(radioElement!=null)
			{
				if(radioElement.checked)
				{
					var url="SearchResult.aspx?t=3&id="+id+"&key="+key;
					window.open(url);
				}
				else
				{
					var url="SearchResult.aspx?t=4&id="+id+"&key="+key;
					window.open(url);
				}
			}
			else
			{
				var url="SearchResult.aspx?t=3&id="+id+"&key="+key;
				window.open(url);
			}
		}
		else
		{
			var url="SearchResult.aspx?t=3&id="+id+"&key="+key;
			window.open(url);
		}
	}

}



//// =============================================
//// 获取页面内容////
//// ============================================
function Mzx_GetHtmlFrom(tocid,toclb)
{
	try
	{
		var fs;
		switch(toclb)
		{
			case 0:
				fs="_GetCustomTocHtml"+tocid;
				break;
			case 1:
			case 2:
				fs="_GetSystemHtml"+tocid;
				break;
			case 100:       ////资源库列表
				fs="_GetTocHtml"+tocid;
				break;
			case 101:       ////资源库分页列表
				fs="_GetResListPageHtml";
				break;
		}
		var obj=eval(fs);
		if(typeof(obj)=="object")
		{
			var d=Math.random();
			obj.set_d(d);
			obj.writeTo();
		}
	}
	catch(e){}
}


//========================================================
////装载页////
//========================================================
function LoadPage(page,obj)
{
	obj.page=page;
	obj.writeTo();

}


//======================================================
////添加文档////
//======================================================
function Mzx_AddDoc(tocid,toclb)
{
	if(tocid=="" || toclb!=0)
	{
		alert("您要选择自建主题，才能添加文档!");
		return;
	}
	
	var d=new Date();
	var url="SpaceManager/AddDoc.aspx?id="+tocid+"&lb="+toclb+"&d="+d.getMilliseconds();
	sFeatures='dialogHeight:520px;dialogWidth:500px;center:Yes;help:yes;resizable:no;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	if(retArr!=null)
	{
		Mzx_GetHtmlFrom(tocid,parseInt(toclb));
	}
	
}


//======================================================
////修改文档////
//======================================================
function Mzx_EditDoc(docId,tocid,toclb,siteName)
{
	var d=new Date();
	var url="SpaceManager/AddDoc.aspx?docId="+docId+"&&d="+d.getMilliseconds();
	if(arguments.length==4)
	{
		////资源库中的列表
		url=g_Mzx_ApplicationPath+"/"+siteName+"/SpaceManager/AddDoc.aspx?docId="+docId+"&&d="+d.getMilliseconds();
	}

	sFeatures='dialogHeight:520px;dialogWidth:500px;center:Yes;help:yes;resizable:no;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	if(retArr!=null)
	{
		Mzx_GetHtmlFrom(tocid,parseInt(toclb));
	}
}

//======================================================
////删除文档////
//======================================================
function Mzx_DeleteDoc(docId,tocid,toclb,siteName)
{
	var d=new Date();
	var url="SpaceManager/DeleteDoc.aspx?docId="+docId+"&&d="+d.getMilliseconds();
	if(arguments.length==4)
	{
		////资源库中的列表
		url=g_Mzx_ApplicationPath+"/"+siteName+"/SpaceManager/DeleteDoc.aspx?docId="+docId+"&&d="+d.getMilliseconds();
	}
	sFeatures='dialogHeight:250px;dialogWidth:350px;center:Yes;help:yes;resizable:no;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	if(retArr!=null)
	{
		Mzx_GetHtmlFrom(tocid,parseInt(toclb));
	}
	
}


//======================================================
////删除回复////
//======================================================
function Mzx_DeleteDicuss(disId,tocid,toclb)
{
	var d=new Date();
	var url="SpaceManager/DeleteDicuss.aspx?disId="+disId+"&&d="+d.getMilliseconds();
	sFeatures='dialogHeight:200px;dialogWidth:300px;center:Yes;help:yes;resizable:no;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	if(retArr!=null)
	{
		Mzx_GetHtmlFrom(tocid,parseInt(toclb));
	}
	
}


//======================================================
////添加或修改主题////
//======================================================
function Mzx_AddAndChangeToc(tocid,toclb,ptocid,PageName,dockid)
{
	var t=0;        ////系统主题分页显示时的属性(在设计模式时暂时没有用到)，1图象， 2音乐，3搜索////
	if(GetUrlPara('t')!='')
		t=GetUrlPara('t');
	
	switch(toclb)
	{
		case 0:
			var d=new Date();
			var url="SpaceManager/AddAndChangeToc.aspx?PageName="+PageName+"&id="+tocid+"&lb="+toclb+"&d="+d.getMilliseconds();
			sFeatures='dialogHeight:560px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
			retArr=window.showModalDialog(url,window,sFeatures);
			
			if(retArr!=null)
			{
				if(retArr==1)
					WebPersonSpace.WebServices.Toc.GetDockToc(dockid,toclb,tocid,t,Mzx_getDockTocSucceeded);
				else
					window.location.replace(window.location.pathname+"?type=0&layout=0&design=1&d="+d.getMilliseconds());
					
			}
			
			break;
		case 1:		////系统主题////
		case 2: 	////系统主题////
			var id = ptocid;
			switch (id) {
				case 1:
				case 2:
				case 3:
				case 5:
				case 6:
				case 8:
				case 9:
				case 71:
				case 72:
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc1.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:380px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 7: 	//主题列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc7.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:400px;dialogWidth:560px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 10: //站内搜索
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc10.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:300px;dialogWidth:480px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);

					break;
				case 11: //用户登录
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc11.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:250px;dialogWidth:480px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						window.location.replace(window.location.pathname + "?type=0&layout=0&design=1&d=" + d.getMilliseconds());

					break;
				case 12: 	//图片列表显示
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc12.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:540px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 13: 	//音乐列表显示
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc13.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:520px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 14: 	//图片轮换
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc14.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:400px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 54: 	//资源目录中图片轮换
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc54.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:400px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 50:       //资源目录中最新更新文档
				case 51:       //资源目录中推荐精彩文档
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc50.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 52:        //资源库列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc51.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 53:        //个人站点列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc53.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
	            case 533:        //个人站点列表[各单位]
	                var d = new Date();
	                var url = "SpaceManager/AddAndChangeToc53_3.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
	                sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
	                retArr = window.showModalDialog(url, window, sFeatures);
	                if (retArr != null)
	                    WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
	                break;
	            case 531:        //个人站点列表[区县]
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc53_1.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 532:        //子站点列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc53_2.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 61:        //学校列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc61.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 62:        //各学校资源库列表
				case 63:        //各学校个人站点列表
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc62.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 64:        //各学校最新更新文档
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc64.aspx?lb=1&PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:420px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 100:
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc100.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:450px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 101:
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc101.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:450px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
				case 102:
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc102.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:450px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null) {
						if (window.location.pathname.indexOf("Doc.aspx") > 0)
							window.location.replace(window.location.pathname + "?lb=" + GetUrlPara('lb') + "&id=" + GetUrlPara('id') + "&d=" + d.getMilliseconds());
						else
							WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					}
					break;
				case 103:
					var d = new Date();
					var url = "SpaceManager/AddAndChangeToc103.aspx?PageName=" + PageName + "&id=" + tocid + "&ptocid=" + ptocid + "&d=" + d.getMilliseconds();
					sFeatures = 'dialogHeight:450px;dialogWidth:530px;center:Yes;help:yes;resizable:no;status:no;'
					retArr = window.showModalDialog(url, window, sFeatures);
					if (retArr != null)
						WebPersonSpace.WebServices.Toc.GetDockToc(dockid, toclb, tocid, t, Mzx_getDockTocSucceeded);
					break;
			}
			break;
	}
}



//======================================================
////参照某主题样式////
//======================================================
function Mzx_TocStyleLikeTo(tocid,toclb,ptocid,PageName,dockid)
{
	var t=0;        ////系统主题分页显示时的属性(在设计模式时暂时没有用到)，1图象， 2音乐，3搜索////
	if(GetUrlPara('t')!='')
		t=GetUrlPara('t');

	var d=new Date();
	var url="SpaceManager/TocStyleLikeTo.aspx?PageName="+PageName+"&dockid="+dockid+"&lb="+toclb+"&d="+d.getMilliseconds();
	sFeatures='dialogHeight:450px;dialogWidth:380px;center:Yes;help:yes;resizable:no;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	
	if(retArr!=null)
	{
		WebPersonSpace.WebServices.Toc.GetDockToc(dockid,toclb,tocid,t,Mzx_getDockTocSucceeded);
	}

}




//======================================================
////获取主题属性////
//======================================================
function Mzx_getDockTocSucceeded(result)
{
	var headTable=$get(String.format("Dock{0}_divDock_DockHeaderTable_{0}",result.DockId));
	if(headTable!=null)
		headTable.className=result.HeadClassName;

	var contentTable=$get(String.format("Dock{0}_divDock_ContentTable_{0}",result.DockId));
	if(contentTable!=null)
		contentTable.className=result.ContentClassName;

	var headCell=$get("HeadCell_"+result.DockId);
	if(headCell!=null)
		headCell.innerHTML=result.HeadHtml;

	var contentCell=$get("ContentCell_"+result.DockId);
	if(contentCell!=null)
		contentCell.innerHTML=result.ContentHtml;
		
	var dockElement = $get(String.format("Dock{0}_divDock",result.DockId));
	if(dockElement!=null)
	{
		var styleNames=result.TocStyles.Name.split(',');
		for(var i=0;i<styleNames.length;i++)
		{
			var styleName1=styleNames[i];
			if(styleName1.indexOf("_")>0)
			{
				var styleName=styleName1.substring(0,styleName1.indexOf("_"));
				var styleName2=styleName+"_Default";
				
				if(result.TocStyles[styleNames[i]]=="")
				{
					Mzx_ReplaceElementClassName(dockElement,styleName1,styleName2);
				}
				else
				{
					Mzx_SetStyleSheet("."+styleName1,result.TocStyles[styleNames[i]]);
					Mzx_ReplaceElementClassName(dockElement,styleName2,styleName1);
				}
			}
		}
	}
	
	var moreButtom=$get("MoreButtom_"+result.DockId);
	var moreTop=$get("MoreTop_"+result.DockId);
	var moreHeadButtom=$get("MoreHeadButtom_"+result.DockId);
	var moreLink=$get("MoreLink_"+result.DockId);
	if(moreLink!=null)
	{
		if(result.MoreHtml!="")
			moreLink.innerHTML=result.MoreHtml;

		var moreHTML=moreLink.outerHTML;
		if(moreButtom!=null && moreButtom.innerHTML!='')
		{   
			moreHTML=moreButtom.innerHTML;
			moreButtom.innerHTML='';
		}
		if(moreTop!=null && moreTop.innerHTML!='')
		{
			moreHTML=moreTop.innerHTML;
			moreTop.innerHTML='';
		}
		if(moreHeadButtom!=null && moreHeadButtom.innerHTML!='')
		{
			moreHTML=moreHeadButtom.innerHTML;
			moreHeadButtom.innerHTML='';
		}
		
		moreLink.removeNode(true);
		if(result.MoreInHead)
		{
			if(headTable.className!=null && headTable.className.indexOf('DockHeaderNoContent')>=0)
			{
				if(moreHeadButtom!=null)
				{
					moreHeadButtom.innerHTML=moreHTML;
				}
			}
			else
			{
				if(moreTop!=null)
				{
					moreTop.innerHTML=moreHTML;
				}
			}
		}
		else
		{
			if(headTable.className!=null && headTable.className.indexOf('DockHeaderNoContent')>=0)
			{
				if(moreHeadButtom!=null)
				{
					moreHeadButtom.innerHTML=moreHTML;
				}
				else
				{
					if(moreButtom!=null)
					{
						moreButtom.innerHTML=moreHTML;
					}
				}
			}
			else
			{
				if(moreButtom!=null)
				{
					moreButtom.innerHTML=moreHTML;
				}
			}
		}
	}
	
	eval(result.HtmlClientScript);
	//Mzx_GetHtmlFrom(result.TocId,result.TocLb);
}



//======================================================
////更改容器中的所有子对象的样式////
//======================================================
function Mzx_ReplaceElementClassName(element,oldClassName,newClassName)
{
	if(element.attributes==null)return;
	if(Sys.UI.DomElement.containsCssClass(element, oldClassName))
	{
		Sys.UI.DomElement.removeCssClass(element, oldClassName);
		Sys.UI.DomElement.addCssClass(element, newClassName);
	}
	
	if(element.childNodes.length>0)
	{
		for(var i=0;i<element.childNodes.length;i++)
		{
			Mzx_ReplaceElementClassName(element.childNodes[i],oldClassName,newClassName);
		}
	}
}

//======================================================
////设置样式表的rule////
//======================================================
function Mzx_SetStyleSheet(ruleName,cssText)
{
	var isExist = false;
	for(var i=0;i<document.styleSheets.length;i++)
	{
		var rules = document.styleSheets[i].rules;
		for(var j=0;j<rules.length;j++)
		{
			var oRule=document.styleSheets[i].rules[j];
			if(oRule.selectorText==ruleName)
			{
				isExist =true;
				oRule.style.setAttribute("cssText",cssText);
				break;
			}
		}
		if(isExist)break;
	}
	
	if(!isExist)
	{
		document.styleSheets[0].addRule(ruleName,cssText);
	}
}



//======================================================
////添加或修改主题////
//======================================================
function Mzx_ManagerDoc(tocid,toclb)
{
	var d=new Date();
	var url="SpaceManager/ManagerDoc.aspx?id="+tocid+"&lb="+toclb+"&d="+d.getMilliseconds();
	sFeatures='dialogHeight:620px;dialogWidth:680px;center:Yes;help:yes;resizable:yes;status:no;'
	retArr=window.showModalDialog(url,window,sFeatures);
	
	if(retArr!=null)
	{
		Mzx_GetHtmlFrom(tocid,parseInt(toclb));
	}
}



//======================================================
////弹出菜单内容///
//======================================================
var __menuPilot_t = null;
var __menuPilot_activeId = null;
var __menuPilot_waitingForId = null;
var __menuPilot_isActiveMenu = false;
var __menuPilot_parents = null;
function __menuPilot_activateLabel(o, appearAfter)
{  
	if (__menuPilot_activeId != o.id) 
		__menuPilot_clearNow();  
	if (__menuPilot_t != null) 
		clearTimeout(__menuPilot_t);  
	__menuPilot_waitingForId = o.id;  
	__menuPilot_t = setTimeout(__menuPilot_activateLabelLater, appearAfter);
}
function __menuPilot_activateLabelLater()
{  
	//alert(__menuPilot_waitingForId);
	document.getElementById(__menuPilot_waitingForId + 'down').style.display = '';  
	__menuPilot_activeId = __menuPilot_waitingForId;
}
function __menuPilot_deactivateLabel(o)
{  
	if(o==null)return;
	document.getElementById(o.id + 'down').style.display = 'none';
}
function __menuPilot_activateMenu(o)
{ 
	__menuPilot_parents = new Array();  
	var node = o.parentNode.parentNode;  
	var i = 0;  
	while (node.parentNode)   
	{  
		if (node.style.position != '')    
		{    
			__menuPilot_parents[i++] = node.style.zIndex;    
			node.style.zIndex = 100000;    
		}  
		node = node.parentNode;  
	}  
	__menuPilot_secureMenuShow(o.parentNode.parentNode.id, true);  
	__menuPilot_isActiveMenu = true;  
	__menuPilot_hold();
}
function __menuPilot_deactivateMenu(o)
{  
	if(o==null)return;
	__menuPilot_secureMenuShow(o.parentNode.parentNode.id, false);  
	if (__menuPilot_parents == null) 
		return;  
	var node = o.parentNode.parentNode;  
	var i = 0;  
	while (node.parentNode)   
	{  
		if (node.style.position != '')    
		{    
			node.style.zIndex = __menuPilot_parents[i++];    
		}  
		node = node.parentNode;  
	}
}
function __menuPilot_secureMenuShow(parentId, visible)
{  
	var sp = document.getElementById(parentId + 'menu');  
	var iframe = document.getElementById(parentId + 'if');  
	if (visible) 
	{    
		sp.style.display = '';    
		iframe.style.width = sp.clientWidth + 'px';    
		iframe.style.height = sp.clientHeight + 'px';    
		iframe.style.top = sp.style.top;    
		iframe.style.left = sp.style.left;    
		iframe.style.zIndex = sp.style.zIndex - 1;    
		iframe.style.display = '';  
	}  
	else  
	{    
		sp.style.display = 'none';    
		iframe.style.display = 'none';  
	}
}
function __menuPilot_clearAll(disappearAfter)
{  
	if (__menuPilot_t != null) 
		clearTimeout(__menuPilot_t);  
	__menuPilot_t = setTimeout(__menuPilot_clearNow, disappearAfter);
}
function __menuPilot_hold()
{  
	clearTimeout(__menuPilot_t);
}
function __menuPilot_clearNow()
{  
	var id = __menuPilot_activeId;  
	if (id == null) 
		return;  
	__menuPilot_deactivateLabel(document.getElementById(id));  
	__menuPilot_deactivateMenu(document.getElementById(id + 'menu'));  
	__menuPilot_activeId = null;  
	__menuPilot_isActiveMenu = false;
}


function HTMLEncode(strHTML) {
	var div = document.createElement('div');
	div.innerText = strHTML;
	return div.innerHTML;
}


function HTMLDecode(strEncodeHTML) {
	var div = document.createElement('div');
	div.innerHTML = strEncodeHTML;
	return div.innerText;
}


function XMLDecode(s) {
	var out = "";
	if (s == null) return;

	var l = s.length;
	for (var i = 0; i < l; i++) {
		var ch = s.charAt(i);
		if (ch == '&') {
			var semicolonIndex = s.indexOf(';', i + 1);
			if (semicolonIndex > 0) {
				var entity = s.substring(i + 1, semicolonIndex);
				if (entity.length > 1 && entity.charAt(0) == '#') {
					if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
						ch = String.fromCharCode(eval('0' + entity.substring(1)));
					else
						ch = String.fromCharCode(eval(entity.substring(1)));
				}
				else {
					switch (entity) {
						case 'quot': ch = String.fromCharCode(0x0022); break;
						case 'amp': ch = String.fromCharCode(0x0026); break;
						case 'lt': ch = String.fromCharCode(0x003c); break;
						case 'gt': ch = String.fromCharCode(0x003e); break;
						case 'nbsp': ch = String.fromCharCode(0x00a0); break;
						case 'iexcl': ch = String.fromCharCode(0x00a1); break;
						case 'cent': ch = String.fromCharCode(0x00a2); break;
						case 'pound': ch = String.fromCharCode(0x00a3); break;
						case 'curren': ch = String.fromCharCode(0x00a4); break;
						case 'yen': ch = String.fromCharCode(0x00a5); break;
						case 'brvbar': ch = String.fromCharCode(0x00a6); break;
						case 'sect': ch = String.fromCharCode(0x00a7); break;
						case 'uml': ch = String.fromCharCode(0x00a8); break;
						case 'copy': ch = String.fromCharCode(0x00a9); break;
						case 'ordf': ch = String.fromCharCode(0x00aa); break;
						case 'laquo': ch = String.fromCharCode(0x00ab); break;
						case 'not': ch = String.fromCharCode(0x00ac); break;
						case 'shy': ch = String.fromCharCode(0x00ad); break;
						case 'reg': ch = String.fromCharCode(0x00ae); break;
						case 'macr': ch = String.fromCharCode(0x00af); break;
						case 'deg': ch = String.fromCharCode(0x00b0); break;
						case 'plusmn': ch = String.fromCharCode(0x00b1); break;
						case 'sup2': ch = String.fromCharCode(0x00b2); break;
						case 'sup3': ch = String.fromCharCode(0x00b3); break;
						case 'acute': ch = String.fromCharCode(0x00b4); break;
						case 'micro': ch = String.fromCharCode(0x00b5); break;
						case 'para': ch = String.fromCharCode(0x00b6); break;
						case 'middot': ch = String.fromCharCode(0x00b7); break;
						case 'cedil': ch = String.fromCharCode(0x00b8); break;
						case 'sup1': ch = String.fromCharCode(0x00b9); break;
						case 'ordm': ch = String.fromCharCode(0x00ba); break;
						case 'raquo': ch = String.fromCharCode(0x00bb); break;
						case 'frac14': ch = String.fromCharCode(0x00bc); break;
						case 'frac12': ch = String.fromCharCode(0x00bd); break;
						case 'frac34': ch = String.fromCharCode(0x00be); break;
						case 'iquest': ch = String.fromCharCode(0x00bf); break;
						case 'Agrave': ch = String.fromCharCode(0x00c0); break;
						case 'Aacute': ch = String.fromCharCode(0x00c1); break;
						case 'Acirc': ch = String.fromCharCode(0x00c2); break;
						case 'Atilde': ch = String.fromCharCode(0x00c3); break;
						case 'Auml': ch = String.fromCharCode(0x00c4); break;
						case 'Aring': ch = String.fromCharCode(0x00c5); break;
						case 'AElig': ch = String.fromCharCode(0x00c6); break;
						case 'Ccedil': ch = String.fromCharCode(0x00c7); break;
						case 'Egrave': ch = String.fromCharCode(0x00c8); break;
						case 'Eacute': ch = String.fromCharCode(0x00c9); break;
						case 'Ecirc': ch = String.fromCharCode(0x00ca); break;
						case 'Euml': ch = String.fromCharCode(0x00cb); break;
						case 'Igrave': ch = String.fromCharCode(0x00cc); break;
						case 'Iacute': ch = String.fromCharCode(0x00cd); break;
						case 'Icirc': ch = String.fromCharCode(0x00ce); break;
						case 'Iuml': ch = String.fromCharCode(0x00cf); break;
						case 'ETH': ch = String.fromCharCode(0x00d0); break;
						case 'Ntilde': ch = String.fromCharCode(0x00d1); break;
						case 'Ograve': ch = String.fromCharCode(0x00d2); break;
						case 'Oacute': ch = String.fromCharCode(0x00d3); break;
						case 'Ocirc': ch = String.fromCharCode(0x00d4); break;
						case 'Otilde': ch = String.fromCharCode(0x00d5); break;
						case 'Ouml': ch = String.fromCharCode(0x00d6); break;
						case 'times': ch = String.fromCharCode(0x00d7); break;
						case 'Oslash': ch = String.fromCharCode(0x00d8); break;
						case 'Ugrave': ch = String.fromCharCode(0x00d9); break;
						case 'Uacute': ch = String.fromCharCode(0x00da); break;
						case 'Ucirc': ch = String.fromCharCode(0x00db); break;
						case 'Uuml': ch = String.fromCharCode(0x00dc); break;
						case 'Yacute': ch = String.fromCharCode(0x00dd); break;
						case 'THORN': ch = String.fromCharCode(0x00de); break;
						case 'szlig': ch = String.fromCharCode(0x00df); break;
						case 'agrave': ch = String.fromCharCode(0x00e0); break;
						case 'aacute': ch = String.fromCharCode(0x00e1); break;
						case 'acirc': ch = String.fromCharCode(0x00e2); break;
						case 'atilde': ch = String.fromCharCode(0x00e3); break;
						case 'auml': ch = String.fromCharCode(0x00e4); break;
						case 'aring': ch = String.fromCharCode(0x00e5); break;
						case 'aelig': ch = String.fromCharCode(0x00e6); break;
						case 'ccedil': ch = String.fromCharCode(0x00e7); break;
						case 'egrave': ch = String.fromCharCode(0x00e8); break;
						case 'eacute': ch = String.fromCharCode(0x00e9); break;
						case 'ecirc': ch = String.fromCharCode(0x00ea); break;
						case 'euml': ch = String.fromCharCode(0x00eb); break;
						case 'igrave': ch = String.fromCharCode(0x00ec); break;
						case 'iacute': ch = String.fromCharCode(0x00ed); break;
						case 'icirc': ch = String.fromCharCode(0x00ee); break;
						case 'iuml': ch = String.fromCharCode(0x00ef); break;
						case 'eth': ch = String.fromCharCode(0x00f0); break;
						case 'ntilde': ch = String.fromCharCode(0x00f1); break;
						case 'ograve': ch = String.fromCharCode(0x00f2); break;
						case 'oacute': ch = String.fromCharCode(0x00f3); break;
						case 'ocirc': ch = String.fromCharCode(0x00f4); break;
						case 'otilde': ch = String.fromCharCode(0x00f5); break;
						case 'ouml': ch = String.fromCharCode(0x00f6); break;
						case 'divide': ch = String.fromCharCode(0x00f7); break;
						case 'oslash': ch = String.fromCharCode(0x00f8); break;
						case 'ugrave': ch = String.fromCharCode(0x00f9); break;
						case 'uacute': ch = String.fromCharCode(0x00fa); break;
						case 'ucirc': ch = String.fromCharCode(0x00fb); break;
						case 'uuml': ch = String.fromCharCode(0x00fc); break;
						case 'yacute': ch = String.fromCharCode(0x00fd); break;
						case 'thorn': ch = String.fromCharCode(0x00fe); break;
						case 'yuml': ch = String.fromCharCode(0x00ff); break;
						case 'OElig': ch = String.fromCharCode(0x0152); break;
						case 'oelig': ch = String.fromCharCode(0x0153); break;
						case 'Scaron': ch = String.fromCharCode(0x0160); break;
						case 'scaron': ch = String.fromCharCode(0x0161); break;
						case 'Yuml': ch = String.fromCharCode(0x0178); break;
						case 'fnof': ch = String.fromCharCode(0x0192); break;
						case 'circ': ch = String.fromCharCode(0x02c6); break;
						case 'tilde': ch = String.fromCharCode(0x02dc); break;
						case 'Alpha': ch = String.fromCharCode(0x0391); break;
						case 'Beta': ch = String.fromCharCode(0x0392); break;
						case 'Gamma': ch = String.fromCharCode(0x0393); break;
						case 'Delta': ch = String.fromCharCode(0x0394); break;
						case 'Epsilon': ch = String.fromCharCode(0x0395); break;
						case 'Zeta': ch = String.fromCharCode(0x0396); break;
						case 'Eta': ch = String.fromCharCode(0x0397); break;
						case 'Theta': ch = String.fromCharCode(0x0398); break;
						case 'Iota': ch = String.fromCharCode(0x0399); break;
						case 'Kappa': ch = String.fromCharCode(0x039a); break;
						case 'Lambda': ch = String.fromCharCode(0x039b); break;
						case 'Mu': ch = String.fromCharCode(0x039c); break;
						case 'Nu': ch = String.fromCharCode(0x039d); break;
						case 'Xi': ch = String.fromCharCode(0x039e); break;
						case 'Omicron': ch = String.fromCharCode(0x039f); break;
						case 'Pi': ch = String.fromCharCode(0x03a0); break;
						case ' Rho ': ch = String.fromCharCode(0x03a1); break;
						case 'Sigma': ch = String.fromCharCode(0x03a3); break;
						case 'Tau': ch = String.fromCharCode(0x03a4); break;
						case 'Upsilon': ch = String.fromCharCode(0x03a5); break;
						case 'Phi': ch = String.fromCharCode(0x03a6); break;
						case 'Chi': ch = String.fromCharCode(0x03a7); break;
						case 'Psi': ch = String.fromCharCode(0x03a8); break;
						case 'Omega': ch = String.fromCharCode(0x03a9); break;
						case 'alpha': ch = String.fromCharCode(0x03b1); break;
						case 'beta': ch = String.fromCharCode(0x03b2); break;
						case 'gamma': ch = String.fromCharCode(0x03b3); break;
						case 'delta': ch = String.fromCharCode(0x03b4); break;
						case 'epsilon': ch = String.fromCharCode(0x03b5); break;
						case 'zeta': ch = String.fromCharCode(0x03b6); break;
						case 'eta': ch = String.fromCharCode(0x03b7); break;
						case 'theta': ch = String.fromCharCode(0x03b8); break;
						case 'iota': ch = String.fromCharCode(0x03b9); break;
						case 'kappa': ch = String.fromCharCode(0x03ba); break;
						case 'lambda': ch = String.fromCharCode(0x03bb); break;
						case 'mu': ch = String.fromCharCode(0x03bc); break;
						case 'nu': ch = String.fromCharCode(0x03bd); break;
						case 'xi': ch = String.fromCharCode(0x03be); break;
						case 'omicron': ch = String.fromCharCode(0x03bf); break;
						case 'pi': ch = String.fromCharCode(0x03c0); break;
						case 'rho': ch = String.fromCharCode(0x03c1); break;
						case 'sigmaf': ch = String.fromCharCode(0x03c2); break;
						case 'sigma': ch = String.fromCharCode(0x03c3); break;
						case 'tau': ch = String.fromCharCode(0x03c4); break;
						case 'upsilon': ch = String.fromCharCode(0x03c5); break;
						case 'phi': ch = String.fromCharCode(0x03c6); break;
						case 'chi': ch = String.fromCharCode(0x03c7); break;
						case 'psi': ch = String.fromCharCode(0x03c8); break;
						case 'omega': ch = String.fromCharCode(0x03c9); break;
						case 'thetasym': ch = String.fromCharCode(0x03d1); break;
						case 'upsih': ch = String.fromCharCode(0x03d2); break;
						case 'piv': ch = String.fromCharCode(0x03d6); break;
						case 'ensp': ch = String.fromCharCode(0x2002); break;
						case 'emsp': ch = String.fromCharCode(0x2003); break;
						case 'thinsp': ch = String.fromCharCode(0x2009); break;
						case 'zwnj': ch = String.fromCharCode(0x200c); break;
						case 'zwj': ch = String.fromCharCode(0x200d); break;
						case 'lrm': ch = String.fromCharCode(0x200e); break;
						case 'rlm': ch = String.fromCharCode(0x200f); break;
						case 'ndash': ch = String.fromCharCode(0x2013); break;
						case 'mdash': ch = String.fromCharCode(0x2014); break;
						case 'lsquo': ch = String.fromCharCode(0x2018); break;
						case 'rsquo': ch = String.fromCharCode(0x2019); break;
						case 'sbquo': ch = String.fromCharCode(0x201a); break;
						case 'ldquo': ch = String.fromCharCode(0x201c); break;
						case 'rdquo': ch = String.fromCharCode(0x201d); break;
						case 'bdquo': ch = String.fromCharCode(0x201e); break;
						case 'dagger': ch = String.fromCharCode(0x2020); break;
						case 'Dagger': ch = String.fromCharCode(0x2021); break;
						case 'bull': ch = String.fromCharCode(0x2022); break;
						case 'hellip': ch = String.fromCharCode(0x2026); break;
						case 'permil': ch = String.fromCharCode(0x2030); break;
						case 'prime': ch = String.fromCharCode(0x2032); break;
						case 'Prime': ch = String.fromCharCode(0x2033); break;
						case 'lsaquo': ch = String.fromCharCode(0x2039); break;
						case 'rsaquo': ch = String.fromCharCode(0x203a); break;
						case 'oline': ch = String.fromCharCode(0x203e); break;
						case 'frasl': ch = String.fromCharCode(0x2044); break;
						case 'euro': ch = String.fromCharCode(0x20ac); break;
						case 'image': ch = String.fromCharCode(0x2111); break;
						case 'weierp': ch = String.fromCharCode(0x2118); break;
						case 'real': ch = String.fromCharCode(0x211c); break;
						case 'trade': ch = String.fromCharCode(0x2122); break;
						case 'alefsym': ch = String.fromCharCode(0x2135); break;
						case 'larr': ch = String.fromCharCode(0x2190); break;
						case 'uarr': ch = String.fromCharCode(0x2191); break;
						case 'rarr': ch = String.fromCharCode(0x2192); break;
						case 'darr': ch = String.fromCharCode(0x2193); break;
						case 'harr': ch = String.fromCharCode(0x2194); break;
						case 'crarr': ch = String.fromCharCode(0x21b5); break;
						case 'lArr': ch = String.fromCharCode(0x21d0); break;
						case 'uArr': ch = String.fromCharCode(0x21d1); break;
						case 'rArr': ch = String.fromCharCode(0x21d2); break;
						case 'dArr': ch = String.fromCharCode(0x21d3); break;
						case 'hArr': ch = String.fromCharCode(0x21d4); break;
						case 'forall': ch = String.fromCharCode(0x2200); break;
						case 'part': ch = String.fromCharCode(0x2202); break;
						case 'exist': ch = String.fromCharCode(0x2203); break;
						case 'empty': ch = String.fromCharCode(0x2205); break;
						case 'nabla': ch = String.fromCharCode(0x2207); break;
						case 'isin': ch = String.fromCharCode(0x2208); break;
						case 'notin': ch = String.fromCharCode(0x2209); break;
						case 'ni': ch = String.fromCharCode(0x220b); break;
						case 'prod': ch = String.fromCharCode(0x220f); break;
						case 'sum': ch = String.fromCharCode(0x2211); break;
						case 'minus': ch = String.fromCharCode(0x2212); break;
						case 'lowast': ch = String.fromCharCode(0x2217); break;
						case 'radic': ch = String.fromCharCode(0x221a); break;
						case 'prop': ch = String.fromCharCode(0x221d); break;
						case 'infin': ch = String.fromCharCode(0x221e); break;
						case 'ang': ch = String.fromCharCode(0x2220); break;
						case 'and': ch = String.fromCharCode(0x2227); break;
						case 'or': ch = String.fromCharCode(0x2228); break;
						case 'cap': ch = String.fromCharCode(0x2229); break;
						case 'cup': ch = String.fromCharCode(0x222a); break;
						case 'int': ch = String.fromCharCode(0x222b); break;
						case 'there4': ch = String.fromCharCode(0x2234); break;
						case 'sim': ch = String.fromCharCode(0x223c); break;
						case 'cong': ch = String.fromCharCode(0x2245); break;
						case 'asymp': ch = String.fromCharCode(0x2248); break;
						case 'ne': ch = String.fromCharCode(0x2260); break;
						case 'equiv': ch = String.fromCharCode(0x2261); break;
						case 'le': ch = String.fromCharCode(0x2264); break;
						case 'ge': ch = String.fromCharCode(0x2265); break;
						case 'sub': ch = String.fromCharCode(0x2282); break;
						case 'sup': ch = String.fromCharCode(0x2283); break;
						case 'nsub': ch = String.fromCharCode(0x2284); break;
						case 'sube': ch = String.fromCharCode(0x2286); break;
						case 'supe': ch = String.fromCharCode(0x2287); break;
						case 'oplus': ch = String.fromCharCode(0x2295); break;
						case 'otimes': ch = String.fromCharCode(0x2297); break;
						case 'perp': ch = String.fromCharCode(0x22a5); break;
						case 'sdot': ch = String.fromCharCode(0x22c5); break;
						case 'lceil': ch = String.fromCharCode(0x2308); break;
						case 'rceil': ch = String.fromCharCode(0x2309); break;
						case 'lfloor': ch = String.fromCharCode(0x230a); break;
						case 'rfloor': ch = String.fromCharCode(0x230b); break;
						case 'lang': ch = String.fromCharCode(0x2329); break;
						case 'rang': ch = String.fromCharCode(0x232a); break;
						case 'loz': ch = String.fromCharCode(0x25ca); break;
						case 'spades': ch = String.fromCharCode(0x2660); break;
						case 'clubs': ch = String.fromCharCode(0x2663); break;
						case 'hearts': ch = String.fromCharCode(0x2665); break;
						case 'diams': ch = String.fromCharCode(0x2666); break;
						default: ch = ''; break;
					}
				}
				i = semicolonIndex;
			}
		}
		out += ch;
	}
	return out;
} 
