﻿function makeCall(url,showFunc,params){
	new Ajax.Request(url, 
		{
			method:'post',
			parameters:params,
			onFailure: function(){ alert('无法链接服务器！') },  
	  		onSuccess: function(transport){
	        		var json = transport.responseText.evalJSON();
					showFunc(json);
	 			} 
	 	});
}
function makeFormCall(url,showFunc,formName){
	new Ajax.Request(url, 
		{
			method:'post',
			parameters:$(formName).serialize(true),
			onFailure: function(){ alert('无法链接服务器！') },  
	  		onSuccess: function(transport){
	        		var json = transport.responseText.evalJSON();
					showFunc(json);
	 			} 
	 	});
}

function contentUpdate(id, ele){
	var childs=$(id).childNodes;
	for(var i=0;i<childs.length;i++){
		childs[i].parentNode.removeChild(childs[i]);
	}
	$(id).appendChild(ele);
}



//========================================================================================================

//用于输出分页页码
/*
type: 显示类型(short|medium|full)
pageInfoObj : java的PageingObject对象
jsFunc : 点击链接时调用的function名字 例：jsFunc(curPage)
*/
function PageInfo(type, pageInfoObj,jsFunc){
	this.type=type;
	this.pageInfoObj=pageInfoObj;
	this.jsFunc = jsFunc;
	this.print=function(){
		var txt ='';
		if( this.type=='short' ){
			if ( (this.pageInfoObj.CurrentPage-1) <= 0 ){
				txt+="&lt;&lt;";
			}else{
				txt+="<a href=\"javascript:"+this.jsFunc+"("+(this.pageInfoObj.CurrentPage-1)+");\">&lt;&lt;</a>";
			}
						
			txt+="&nbsp;&nbsp;"+this.pageInfoObj.CurrentPage+'/'+this.pageInfoObj.TotalPage+"&nbsp;&nbsp;";
			
			if ( this.pageInfoObj.CurrentPage >= this.pageInfoObj.TotalPage ){
				txt+="&gt;&gt;";
			}else{
				txt+="<a href=\"javascript:"+jsFunc+"("+(this.pageInfoObj.CurrentPage+1)+");\">&gt;&gt;</a>";
			}
			return txt;
		}else if (this.type=='medium') {
			if ( (this.pageInfoObj.CurrentPage-1) <= 0 ){
				txt += "首页&nbsp;&nbsp;";
				txt += "上一页&nbsp;&nbsp;";
			}else{
				txt += "<a href=\"javascript:"+jsFunc+"(1);\">首页</a>&nbsp;&nbsp;";
				txt += "<a href=\"javascript:"+this.jsFunc+"("+(this.pageInfoObj.CurrentPage-1)+");\">上一页</a>&nbsp;&nbsp;";
			}
			
			if ( this.pageInfoObj.CurrentPage >= this.pageInfoObj.TotalPage ){
				txt += "下一页&nbsp;&nbsp;";
				txt += "尾页&nbsp;&nbsp;";
			}else{
				txt += "<a href=\"javascript:"+jsFunc+"("+(this.pageInfoObj.CurrentPage+1)+");\">下一页</a>&nbsp;&nbsp;";
				txt += "<a href=\"javascript:"+jsFunc+"("+(this.pageInfoObj.TotalPage)+");\">尾页</a>&nbsp;&nbsp;";
			}
			
			txt += "第"+this.pageInfoObj.CurrentPage+"页/共"+this.pageInfoObj.TotalPage+"页&nbsp;&nbsp;";
			return txt;
		}else{
			return "not support page info type: "+this.type;
		}
	}
}



//根据节点信息打印节点路径
function printTreePath(node,funcName){
	var split = "--&gt;";
	var txt = "";
	var nd = '';
	do{
		if ( nd == '' ){
			nd = node;
		}else{
			nd = nd.Childs[0];
		}
		txt+=split;
		txt+="<a href=\"javascript:"+funcName+"('"+nd.Id+"');\">";
		txt+=nd.Name;
		txt+="</a>";
	}while(nd.Childs)
	
	if ( txt=='' )
		return txt;
	else
		return txt.substring(split.length,txt.length);
}

