﻿/*
 * 实体类-
 * 主题列表
 */
function CliSearchItemList(){
	 CliBase.call();
	 this.fid;
	 this.pg;
	 this.num;
	 this.ItemArray = new Array();
	 this.totleNumber=0;
	 this.divId;
	this.arg="";
	this.SWord="";
	this.Spend_Time="";
 }
CliSearchItemList.prototype = new CliBase();
CliSearchItemList.__typeName = 'CliSearchItemList';
CliSearchItemList.__class = true;
CliSearchItemList.GETLIST="CliSearchItemListgetforum"
//this.dispatchEvent(new Event(CliSearchItemList.GETFORUM,""));
CliSearchItemList.prototype.getList = function (w,st,num,pg, d){
	//var url ="http://172.17.155.11/cgi-bin/q";
	var url ="/cgi-bin/q";
	var pars = "k="+w;
	if(st=="") st="10";
	if(document.location.host.indexOf('big5')>=0){
		st="11"
	}
	pars += '&t='+st;//搜索类型，官网是12
	if(num=="") num=10;
	pars += '&n='+num;
	pars += '&p='+pg;
	pars += '&d='+d;
	pars+='&r='+Math.random();
	var myAjax = new Ajax.Request(url,{method: "get",	parameters: pars,onSuccess: this.__onGet.bind(this),onFailure:this.GetFailured});
}
CliSearchItemList.prototype.GetFailured = function(originalRequest){
	//alert("error:读取cgi失败。")
}
CliSearchItemList.prototype.__onGet = function(originalRequest){
	//处理结果
	var xmlDoc = this.bulidXML(originalRequest.responseText);
	if(typeof(xmlDoc)=="string"){
		alert("错误代码："+xmlDoc)
		return 
	}
	
	var searchinfo = xmlDoc;
	
	//this.SWord = searchinfo.getElementsByTagName("SWord")[0].firstChild.nodeValue;
	
	this.totleNumber = searchinfo.getElementsByTagName("items")[0].firstChild.nodeValue;
	
	this.Spend_Time = this.getValueFromXML(searchinfo,"qt");
	this.num =this.getValueFromXML(searchinfo,"rows");
	if(this.num==null) {this.fillDIV(this.divId);this.dispatchEvent(new Event(CliSearchItemList.GETLIST,"")); return;}
	//this.num = searchinfo.getElementsByTagName("rows")[0].firstChild.nodeValue;
	this.pg = Number(searchinfo.getElementsByTagName("start")[0].firstChild.nodeValue)/Number(this.num);
	//
	var items = xmlDoc.getElementsByTagName("doc");
	for (i=0;i<items.length;i++){
		var ct = new CliSearchItem();
		ct.Ptitle=items[i].getElementsByTagName("title")[0].firstChild.nodeValue;
		var tmpurl ="";
		tmpurl =this.getValueFromXML(items[i],"articleid");
		ct.Purl ="/a/"+tmpurl.substring(0,8)+"/"+tmpurl.substring(8,tmpurl.length)+".htm";
		if(tmpurl==""){
			tmpurl =this.getValueFromXML(items[i],"reserve1");
			ct.Purl =tmpurl;
		}
		
		//ct.Psize=items[i].getElementsByTagName("Psize")[0].firstChild.nodeValue;;
		ct.Pdate=items[i].getElementsByTagName("time")[0].firstChild.nodeValue;;
		ct.Psite=items[i].getElementsByTagName("origin")[0].firstChild.nodeValue;;
		ct.Pcontent=items[i].getElementsByTagName("features")[0].firstChild.nodeValue;;
		//ct.Plan=items[i].getElementsByTagName("Plan")[0].firstChild.nodeValue;;
		this.ItemArray.push(ct);
	}
	this.fillDIV(this.divId);
	
}

CliSearchItemList.prototype.fillDIV = function(id){
	this.divId = id;
	var div = document.getElementById(id);
	var resultStr = this.doFill(this.getDivHTML(id));
	set_innerHTML(this.divId,resultStr);
	var t=setTimeout(function(){div.style.display = "";},400)
	this.dispatchEvent(new Event(CliSearchItemList.GETLIST,""));
}
CliSearchItemList.prototype.doFillHTML = function (html){
	return html;
}
CliSearchItemList.prototype.doFillRepeatHTML = function (html){
	//将修改完单一属性的html模板 开始修改repeat属性 
	var resultStr ="";
	if(this.ItemArray.length==0) return "";
	for(z=0;z<this.ItemArray.length;z++){
		var tmpCli = this.ItemArray[z];
		resultStr += tmpCli.doFill(html);
	}
	return this.getRepeatBeforeStr(html,CliSearchItem.__typeName) + resultStr+ this.getRepeatAfterStr(html,CliSearchItem.__typeName);
}
CliSearchItemList.prototype.doFill = function (html){
	var xLevel = CliSearchItemList.__typeName;
	return this.getRepeatStr(html,xLevel,this.doFillHTML.bind(this),this.doFillRepeatHTML.bind(this));

}/*  |xGv00|d057e1cf4b4c0e62717ffa27f5574475 */
