/*
http://www.webrebuild.org/wtemplet/
Copyright By WebReBuild.org 2006-12-04
本WebReBuild Templet代码对互联网开源，转载或修改请保留原作者标注信息。
仅以此向进行着网站重构的同行致敬。
*/
var Browser={};
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

function RSS1(xmlurl){
	var RSSXML;
	RSS=xmlget(xmlurl)//取XML
	RSSXML=RSS.selectNodes("//item");
	RSSlength=RSSXML.length;
	adhtmlHttp = htmlget("templet1.htm").getCode("RSS列表");//取模版页
	blogheadtp = adhtmlHttp.getCode("RSS头部");//提取模版内容
	adHTML = blogheadtp.replace(/<-%logo%->/g,RSS.selectSingleNode("//image/url/text()").nodeValue).replace(/<-%title%->/g,RSS.selectSingleNode("//title/text()").nodeValue).replace(/<-%description%->/g,RSS.selectSingleNode("//description/text()").nodeValue).replace(/<-%link%->/g,RSS.selectSingleNode("//link/text()").nodeValue);
	adhtmlHttp=adhtmlHttp.inCode("RSS头部",adHTML);
	bloglooptp = adhtmlHttp.getCode("日志列表");//提取模版内容
	key=0;
	adHTML="";
	for (var i=0; i<RSSlength; i++){
		RSStype=RSSXML[i].selectSingleNode("category/text()").nodeValue 
		key++;
		templetetext = bloglooptp.replace(/<-%guid%->/g,RSSXML[i].selectSingleNode("guid/text()").nodeValue).replace(/<-%title%->/g,RSSXML[i].selectSingleNode("title/text()").nodeValue).replace(/<-%author%->/g,RSSXML[i].selectSingleNode("author/text()").nodeValue).replace(/<-%time%->/g,RSSXML[i].selectSingleNode("pubDate/text()").nodeValue).replace(/<-%description%->/g,RSSXML[i].selectSingleNode("description/text()").nodeValue);
		adHTML=adHTML+templetetext;
	}
	if (key==0) {
		adhtmlHttp=adhtmlHttp.inCode("日志列表","")
	}else{
		adhtmlHttp=adhtmlHttp.inCode("日志列表循环",adHTML);
	}
	document.getElementById("rss").innerHTML=adhtmlHttp;
	if (!Browser.isIE){
		document.getElementById("rss").innerHTML=htmlget("templet1.htm").getCode("样式表")+document.getElementById("rss").innerHTML;
	}else{
		CSShtml = htmlget("templet1.htm").getCode("样式表");
		CSShref=/href="(.*?)"/ig.exec(CSShtml);//By Puterjam 2006-12-04
		document.createStyleSheet(CSShref[1]);
	}
}

function RSS2(xmlurl){
	var RSSXML;
	RSS=xmlget(xmlurl)//取XML
	RSSXML=RSS.selectNodes("//item");
	RSSlength=RSSXML.length;
	adhtmlHttp = htmlget("templet2.htm").getCode("RSS列表");//取模版页
	blogheadtp = adhtmlHttp.getCode("RSS头部");//提取模版内容
	adHTML = blogheadtp.replace(/<-%logo%->/g,RSS.selectSingleNode("//image/url/text()").nodeValue).replace(/<-%title%->/g,RSS.selectSingleNode("//title/text()").nodeValue).replace(/<-%description%->/g,RSS.selectSingleNode("//description/text()").nodeValue).replace(/<-%link%->/g,RSS.selectSingleNode("//link/text()").nodeValue);
	adhtmlHttp=adhtmlHttp.inCode("RSS头部",adHTML);
	bloglooptp = adhtmlHttp.getCode("日志列表");//提取模版内容
	key=0;
	adHTML="";
	for (var i=0; i<RSSlength; i++){
		RSStype=RSSXML[i].selectSingleNode("category/text()").nodeValue 
		key++;
		templetetext = bloglooptp.replace(/<-%guid%->/g,RSSXML[i].selectSingleNode("guid/text()").nodeValue).replace(/<-%title%->/g,RSSXML[i].selectSingleNode("title/text()").nodeValue).replace(/<-%author%->/g,RSSXML[i].selectSingleNode("author/text()").nodeValue).replace(/<-%time%->/g,RSSXML[i].selectSingleNode("pubDate/text()").nodeValue).replace(/<-%description%->/g,RSSXML[i].selectSingleNode("description/text()").nodeValue);
		adHTML=adHTML+templetetext;
	}
	if (key==0) {
		adhtmlHttp=adhtmlHttp.inCode("日志列表","")
	}else{
		adhtmlHttp=adhtmlHttp.inCode("日志列表循环",adHTML);
	}
	document.getElementById("rss").innerHTML=adhtmlHttp;
	if (!Browser.isIE){
		document.getElementById("rss").innerHTML=htmlget("templet2.htm").getCode("样式表")+document.getElementById("rss").innerHTML;
	}else{
		CSShtml = htmlget("templet2.htm").getCode("样式表");
		CSShref=/href="(.*?)"/ig.exec(CSShtml);//By Puterjam 2006-12-04
		document.createStyleSheet(CSShref[1]);
	}
}

function parseXML(st){
//By EMU from Qzone
	if(Browser.isIE){
		var result = new ActiveXObject("microsoft.XMLDOM");
		result.loadXML(st);
	}else{
		var parser = new DOMParser();
		result = parser.parseFromString(st, "text/xml");
	}
	return result;
}

function xmlget(url){
//取XML函数
	if (window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET",url,false)
		xmlhttp.send(null);
	}else if (window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET",url,false)
		xmlhttp.send();
	}
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ 
		return xmlhttp.responseXML; 
	}else{ 
		return false;
	}	
}

function htmlget(url){
//取HTML函数
	if (window.XMLHttpRequest){
		htmlHttp = new XMLHttpRequest();
		htmlHttp.open("GET",url,false)
		htmlHttp.send(null);
	}else if (window.ActiveXObject){
		htmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		htmlHttp.open("GET",url,false)
		htmlHttp.send();
	}
	if (htmlHttp.readyState == 4 && htmlHttp.status == 200){ 
		return htmlHttp.responseText; 
	}else{ 
		return false;
	}
}

String.prototype.getCode=function getCode(tag){
//取HTML模版
	var templetHTML = this;
	templetHTML=templetHTML.replace(/[\t\n\r]/g,"");
	var re = new RegExp('\<!--[ \t]*' + tag + '开始--\>(.+?)\<!--[ \t]*' + tag + '结束--\>','ig');//By Newskyline 2006-12-01
	templetHTML = templetHTML.match(re,"$1");
	if(templetHTML==this){
		return '';
	}else{
		return RegExp.$1;
	}
}

String.prototype.inCode=function getCode(tag,str){
//替换HTML模版
	var templetHTML = this;
	templetHTML=templetHTML.replace(/[\t\n\r]/g,"");
	var re = new RegExp('\<!--[ \t]*' + tag + '开始--\>(.+?)\<!--[ \t]*' + tag + '结束--\>','ig');//By Newskyline 2006-12-01
	templetHTML = templetHTML.match(re,"$1");
	templetHTML=this.replace(RegExp.$1,str);
	if(templetHTML==this){
		return '';
	}else{
		return templetHTML;
	}
}

// check for XPath implementation Optimize By EMU
if(!Browser.isIE){
// prototying the Element
	Element.prototype.selectNodes = function(cXPathString){
		if(this.ownerDocument.selectNodes){
			return this.ownerDocument.selectNodes(cXPathString, this);
		}else{
			throw "For XML Elements Only";
		}
	}
// prototying the Element
	Element.prototype.selectSingleNode = function(cXPathString){
		if(this.ownerDocument.selectSingleNode){
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}else{
			throw "For XML Elements Only";
		}
	}
}
if(Browser.isFirefox){
// prototying the XMLDocument
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
		XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++){
			aResult[i] = aItems.snapshotItem(i);
		}
		return aResult;
	}
// check for XPath implementation
// prototying the XMLDocument
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 ){
			return xItems[0];
		}else{
			return null;
		}
	}
}
if(Browser.isOpera){
// prototying the Document
	Document.prototype.selectSingleNode = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 ){
			return xItems[0];
		}else{
			return null;
		}
	}
// prototying the Document
	Document.prototype.selectNodes = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
		XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++){
			aResult[i] = aItems.snapshotItem(i);
		}
		return aResult;
	}
}

String.prototype.Left = function(len){
	if(isNaN(len)||len==null){
		len = this.length;
	}else{
		if(parseInt(len)<0||parseInt(len)>this.length){
			len = this.length;
		}
	}	
	return this.substr(0,len);
}

String.prototype.Right = function(len){
	if(isNaN(len)||len==null){
		len = this.length;
	}else{
		if(parseInt(len)<0||parseInt(len)>this.length){
			len = this.length;
		}
	}	
	return this.substring(this.length-len,this.length);
}
