
function view(){
	/**
	*\u5916\u90E8\u5C5E\u6027\u63A5\u53E3\uFF1A\u89C6\u56FE\u548C\u6570\u636E\u683C\u5F0F
	**/	
	this.viewURL = "";					//\u89C6\u56FE\u8DEF\u5F84eg:"/webcyb/sheetstock.nsf/vwzzbyxiaoliang"		
	this.dataFormat="&outputformat=json&PreFormat";	//\u5C06\u89C6\u56FE\u4FE1\u606F\u8F93\u51FA\u4E3Ajson\u6570\u636E\uFF0C\u5E76\u4E14\u4F7F\u6570\u636E\u6210\u4E3A\u6587\u672C\u8F93\u51FA	
	
	/**
	*\u5916\u90E8\u5C5E\u6027\u63A5\u53E3\uFF1A\u5173\u4E8E\u5206\u9875
	**/	
	this.start=1;							//\u4ECE\u7B2C\u51E0\u6761\u5F00\u59CB\u663E\u793A\u4FE1\u606F
	this.count=10;							//\u6BCF\u9875\u663E\u793A\u6587\u672C\u6570\u76EE
	
	this.json="";
	/**
	*\u5916\u90E8\u5C5E\u6027\u63A5\u53E3\uFF1A\u5173\u4E8E\u6A21\u7248\u8BBE\u7F6E
	**/	
//\u6807\u9898\u8BBE\u7F6E
	this.titleTemplate=res["titleTemplate"];	//\u6807\u9898\u884C\u7684\u663E\u793A\u6A21\u677F\uFF0C\u4F7F\u7528$$viewTitleColume\u6765\u66FF\u6362
	//\u8868\u683C\u8BBE\u7F6E
	this.topTemplate=res["topTemplate"];		//\u8868\u683C\u7684\u5916\u90E8\u6807\u7B7E\uFF0C\u5177\u4F53\u683C\u5F0F\u5F85\u5B9A\u53EF\u4EE5\u4F7F\u7528table\u6216\u8005div\u7684\u65B9\u5F0F\u6765\u4F53\u4F1A,\u6807\u7B7E\u6682\u5B9A\u4E3A$$viewDetail
	//\u884C\u8BBE\u7F6E
	this.rowTemplateCount = 1;// 1 \u8868\u793A\u53EA\u6709\u4E00\u4E2A\u884C\u6A21\u677F\uFF1B2\u8868\u793A2\u4E2A\u884C\u6A21\u677F\uFF0C\u7B2C\u4E00\u884C\u4F7F\u7528\u884C\u6A21\u677F\u4E00\uFF0C\u5176\u4F59\u4F7F\u7528\u884C\u6A21\u677F\u4E8C
	this.rowTemplate=res["rowTemplate"];		//\u6BCF\u4E00\u884C\u7684\u7684\u6A21\u677F\uFF0C\u5EFA\u8BAE\u4F7F\u7528$$viewColumn$$\u6765\u8FDB\u884C\u66FF\u6362
	this.rowTemplate2 = res["rowTemplate"];//\u5F53rowTemplateCount =2 \u65F6\uFF0C\u7528\u4E8E\u6307\u5BFC\u7B2C\u4E00\u884C\u6A21\u677F\uFF0C\u5176\u4F59\u4F7F\u7528rowTemplate
	//\u5E95\u90E8\u8BBE\u7F6E
	this.bottomTemplate=res["bottomTemplate"];		//\u6BCF\u4E00\u884C\u7684\u7684\u5185\u5BB9$$viewColumn\u6765\u8FDB\u884C\u66FF\u6362
	//\u65E0\u5185\u5BB9\u6A21\u7248
	this.noContentTemplate = res["nocontent"];
	//\u6570\u636E\u52A0\u8F7D\u4E2D\u63D0\u793A		
	this.loadding=res["loadding"];
	/**
	*\u9875\u9762\u663E\u793A\u8BBE\u7F6E
	**/
	//\u6807\u9898\u8BBE\u7F6E
	this.showTitle=false;						//\u662F\u5426\u663E\u793A\u6807\u9898\u884C: false \u4E0D\u663E\u793A\uFF1B true\u663E\u793A	
			
	/**
	*\u5916\u90E8\u5C5E\u6027\u63A5\u53E3\uFF1A\u5173\u4E8E\u6807\u7B7E\u8BBE\u7F6E
	**/		
	this.targetDiv = "viewbody";				//\u89C6\u56FE\u4E2D\u5FC5\u987B\u4E14\u53EA\u80FD\u5305\u542B\u4E00\u4E2A<div id="$$viewbody"></div>\u7684html\u5185\u5BB9

	/**
	*\u5916\u90E8\u8F85\u52A9\u8F93\u51FA\u53C2\u6570\u63A5\u53E3\uFF1A\u4E3A\u8F93\u51FA\u90E8\u5206\u89C6\u56FE\u4E2D\u6570\u636E\uFF0C\u5B9A\u4E493\u4E2A\u5907\u7528\u53C2\u6570
	**/	
	this.outPar1 = "";
	this.outPar1value = new Array();
	this.outPar2 = "";
	this.outPar2value = new Array();
	this.outPar3 = "";
	this.outPar3value = new Array();
	/**
	*\u5916\u90E8\u8F85\u52A9\u8F93\u51FA\u53C2\u6570\u63A5\u53E3\uFF1A\u5728\u5916\u90E8\u8BBE\u7F6E\u6807\u8BB0\uFF0C\u5907\u7528\u53C2\u6570
	**/
	this.outParFlag = ""  
	/**
	*Private \u53D8\u91CF\uFF0C\u4EC5\u4F9B\u5BF9\u8C61\u5185\u90E8\u4F7F\u7528\u3002
	**/
	this.showURL = "";
	this.title="view";					//\u6682\u65F6\u6CA1\u6709\u4F7F\u7528\u7684\u60F3\u6CD5\uFF0C\u8003\u8651\u5C06\u6765\u4F7F\u7528document.title\u65B9\u6CD5\u6765\u8F93\u51FA\u9875\u9762\u6807\u9898
	this.total=0;								//\u89C6\u56FE\u4E2D\u7684\u6587\u6863\u603B\u6570
	this.category="";						//\u89C6\u56FE\u663E\u793A\u7C7B\uFF0C\u7A7A\u4E3A\u65E0\u5206\u7C7B,\u4F7F\u7528\u6765\u786E\u5B9A\u5206\u7C7BRestrictToCategory=category
	
	/**
	* \u5173\u4E8E\u5206\u9875
	**/
	//this.isPagination =	true;		//\u662F\u5426\u5206\u9875\uFF1Afalse \u4E0D\u5206\u9875\uFF1B true \u5206\u9875\u3002
	this.totalPage=0;						//\u8BE5\u89C6\u56FE\u7684\u603B\u9875\u6570
	this.curPage=1;							//\u5F53\u524D\u9875	
	
//\u5916\u90E8\u51FD\u6570\u63A5\u53E3\uFF1A\u521D\u5316\u89C6\u56FE
	this.init = function init(viewURL){	
		if("" == viewURL ) return -2;
		this.viewURL = viewURL;
		this.showURL = this.viewURL+this.dataFormat+"&start="+this.start+"&count="+this.count;		
		if ("" != this.category)
		{
			this.showURL += "&RestrictToCategory="+this.category;
		}
		load(this);
	};	
		
//\u52A0\u8F7D\u89C6\u56FE	
	this.showLoadingData=function (data)
	{

	var json=eval(data);
	this.json=data;
	this.total = data["@toplevelentries"];
	this.getCurPage();

	this.getTotalPage();
	//\u5148\u914D\u7F6E\u597D\u4FE1\u606F\uFF0C\u7136\u540E\u89E6\u53D1\u4E8B\u4EF6\uFF0C\u987A\u5E8F\u5F88\u91CD\u8981
	$(this).trigger("onload");//\u89E6\u53D1\u4E8B\u4EF6\uFF0C\u6587\u6863\u88AB\u88C5\u8F7D
	$("#"+this.targetDiv).empty();
	
	//\u5F53\u89C6\u56FE\u65E0\u6570\u636E\u65F6\uFF0C\u663E\u5185\u5BB9

	if( this.total == 0 || this.total==undefined)
	{
		$("#"+this.targetDiv).append(this.noContentTemplate); 
		this.total = 0
		$(this).trigger("postload_nocontent");//\u89E6\u53D1\u4E8B\u4EF6\uFF0C\u6570\u636E\u88AB\u586B\u5145\u5B8C\u6BD5\u540E					
		return ;	
	}
	else //\u5F53\u89C6\u56FE\u6709\u6570\u636E\u65F6
	{

		var rows=json.viewentry.length; //\u89C6\u56FE\u4E2D\u7684\u884C\u6570
		var cols=json.viewentry[0].entrydata.length; //\u89C6
		/**
		*\u8868\u606F\u9898\u3001\u6BCF\u884C\u4FE1\u5E95\u90E8\u4FE1\u606F
		**/
		
		//\u663E\u793A\u6807\u9898\u4FE1\u606F, \u672A\u5B8C\u6210\uFF0C\u9700\u8FDB\u884C\u5217\u540D\u66FF\u6362
		if(this.showTitle && rows >0)
		{
			var titleTemplate = this.titleTemplate;
			for(var j=1;j<=cols;j++)
			{				
				var target = "$$ViewColumn"+j+"$$";		
				//alert(data.viewentry[1].entrydata[j]["@name"])		
				titleTemplate = titleTemplate.replace(target,data.viewentry[1].entrydata[j]["@name"]);
			}
			$("#"+this.targetDiv).append(titleTemplate);						
		}
		//alert(this.topTemplate)
	
		if("" != this.topTemplate)
		{
			$("#"+this.targetDiv).append(this.topTemplate);		
		}	
		//alert($("#"+this.targetDiv).html())
			var rowTemplate = "";
		
		
		//\u663E\u793A\u6BCF\u884C\u4FE1\u606F
		for(var i=0;i<rows;i++)
		{
			var target = "";	
			if( i==0 && this.rowTemplateCount == 2 )	
				rowTemplate = this.rowTemplate2;
			else
				rowTemplate = this.rowTemplate;
			
			
			
			for(var j=0;j<cols;j++)
			{
				target = "$$ViewColumn"+j+"$$";	
				var index = rowTemplate.indexOf(target);
				while(index>=0)
				{
					
					rowTemplate = rowTemplate.replace(target,data.viewentry[i].entrydata[j].text[0]);
					index = rowTemplate.indexOf(target);
				}
				//\u4E3A\u8F85\u52A9\u8F93\u51FA\u53C2\u6570\u8D4B\u503C		
				index = this.outPar1.indexOf(target);
				if(index>=0)
					this.outPar1value.push(data.viewentry[i].entrydata[j].text[0]);
				index = this.outPar2.indexOf(target);
				if(index>=0)
					this.outPar2value.push(data.viewentry[i].entrydata[j].text[0]);
				index = this.outPar3.indexOf(target);
				if(index>=0)
					this.outPar3value.push(data.viewentry[i].entrydata[j].text[0]);
				
			}
			
			
			$("#"+this.targetDiv).append(rowTemplate);		
			//alert($("#"+this.targetDiv).html())	
		}	
		
		
					
		
		//\u663E\u793A\u90E8\u4FE1\u606F\uFF0Ceg: \u9875\u6570\u4FE1\u606F\u3001\u4E0B\u4E00\u9875\u6309\u94AE\u3001  more \u6309\u94AE\u7B49
		if("" != this.bottomTemplate )
		{
			$("#"+this.targetDiv).append(this.bottomTemplate);		
		}		
		
		
		//alert($("#"+this.targetDiv).html())
	}		
	
	
	$(this).trigger("postload");//\u89E6\u53D1\u4E8B\u4EF6\uFF0C\u6570\u636E\u88AB\u586B\u5145\u5B8C\u6BD5\u540E
	
	};
	
	//\u5916\u90E8\u51FD\u6570\u63A5\u53E3\uFF1A\u663E\u793A\u9875\u9762\u4E0B\u4E00\u9875\uFF1B\u5982\u5F53\u524D\u9875\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u9875\uFF0C\u8FD4\u56DE-1\u3002
	this.nextPage = function(){
//		alert("this.curPage:"+this.curPage+"  this.totalPage:"+this.totalPage());
		if (this.curPage== this.totalPage) {
			return -1;
   	}  
	this.curPage+=1;  	
    this.start = (this.curPage-1) * this.count + 1;   
    //alert("start:"+this.start);
    this.showURL = this.viewURL+this.dataFormat+"&start="+this.start+"&count="+this.count;
    if ("" != this.category)
		{
			this.showURL += "&RestrictToCategory="+this.category;
		}
    //alert(this.showURL);
    load(this); 	
	}
	
	//\u5916\u90E8\u51FD\u6570\u63A5\u663E\u793A\u9875\u4E00\u9875;\u5982\u5F53\u524D\u9875\u5DF2\u7ECF\u662F\u7B2C\u4E00\u9875\uFF0C\u8FD4\u56DE-1\u3002
	this.lastPage = function(){
		if (this.curPage== 1) {
			return -1;
   	}   	
	this.curPage-=1;
    this.start = (this.curPage-1)*this.count+1;    
		this.showURL = this.viewURL+this.dataFormat+"&start="+this.start+"&count="+this.count;
		if ("" != this.category)
		{
			this.showURL += "&RestrictToCategory="+this.category;
		}
    load(this);
	}
	//\u5916\u90E8\u51FD\u6570\u63A5\u53E3\uFF1A\u663E\u793A\u6307\u5B9A\u9875
	this.goToPage = function(pageNum){
	
		if(pageNum<=0 || pageNum > this.getTotalPage())
		
		{	return -1;alert("-1")}
		else 
		{
			
			this.start = parseInt(pageNum-1)*this.count + 1;			
			this.showURL = this.viewURL+this.dataFormat+"&start="+this.start+"&count="+this.count;
			if ("" != this.category)
			{
			this.showURL += "&RestrictToCategory="+this.category;
			}
			load(this);
		}
	}
	//\u5185\u90E8\u51FD\u6570\u63A5\u53E3\uFF1A\u8FD4\u56DE\u5F53\u524D\u9875\u6570
	this.getCurPage = function(){
		if (this.start < this.count) {		
			this.curPage=1;
    } else {
    	this.curPage = 	parseInt(this.start / this.count)+1
			this.curPage
		}
	}
	//\u5916\u90E8\u51FD\u6570\u63A5\u53E3\uFF1A\u603B\u9875\u6570
	this.getTotalPage = function(){		
		
		this.totalPage = parseInt(this.total / this.count);
    if (this.total%this.count != 0) {
			this.totalPage = this.totalPage + 1;
    }
    if(this.totalPage==0){  
    	this.totalPage=1;  
    }   	 	
	}	
	
	this.getOutPar1 = function(){
		
	}

}
//\u52A0\u8F7D\u89C6\u56FE
function load(obj){
		$("#"+obj.targetDiv).html(obj.loadding);
		$.ajax({
   		url :obj.showURL,
			type :'GET',
			dataType :'json',
			timeout :30000,
   		error:	function(msg){   	
     		return "Error:"+msg;
     	},
   		success: function(data){   			
     			obj.showLoadingData(data);	
   		}
		});
	};
