if(!this.Shark){
	Shark={};
}
Shark.Wicket={
	getX:function(e){
		var x = 0;                // Start with 0
	    while(e) {                // Start at element e
	        x += e.offsetLeft;    // Add in the offset
	        e = e.offsetParent;   // And move up to the offsetParent
	    }
	    return x;                 // Return the total offsetLeft
	},
	getY:function (element) {
	    var y = 0;
	    for(var e = element; e; e = e.offsetParent) // Iterate the offsetParents
	        y += e.offsetTop;                       // Add up offsetTop values
		    for(e = element.parentNode; e && e != document.body; e = e.parentNode)
	        if (e.scrollTop) y -= e.scrollTop;  // subtract scrollbar values
	
	    return y;
	},
	
	/**
	 * 关闭弹出层
	 * @param {Element} popup
	 */
	ClosePopup :function(popup){
		var filterLayer = document.getElementById("__bodybg_");
		if(filterLayer!=null){
			filterLayer.style.display="none";			
		}
		popup.style.display="none";
	},
	removepop:function(){
		var parent =document.getElementById("__bodybg_");
		if(parent != undefined){
			document.body.removeChild(parent);
		}
	},
	

	/**
	 * 创建一个滤镜层
	 * @param {Element} popupDiv
	 */
	CreateFilterLayer:function(popup){
	 	var bodyBack =popup.element;
		bodyBack.style.position = "absolute";
		bodyBack.style.width = "100%";
		bodyBack.style.height = (this.getPageSize()[1] +  'px');
		bodyBack.style.zIndex =popup.z;
		bodyBack.style.top = 0;
		bodyBack.style.left = 0;
		bodyBack.style.filter = "alpha(opacity=20)";
		bodyBack.style.opacity = 0.2;
		bodyBack.style.background = "#000000";
	},
	
	
	
	/**
	 * 创建一个滤镜层
	 * @param {Element} popupDiv
	 */
	 filter:0.2,
	CreateBackLayer:function(popupDiv){
		//创建弹出背景层
	
	 	var bodyBack = document.getElementById("__bodybg_");
	 	
		if(bodyBack != null){
			bodyBack.style.display="";
			return ;
		}
		bodyBack = document.createElement("div");
		bodyBack.setAttribute("id","__bodybg_")
		bodyBack.style.position = "absolute";
		bodyBack.style.width = "100%";
		bodyBack.style.height = (this.getPageSize()[1] + 35 + 'px');
		bodyBack.style.zIndex = 97;
		bodyBack.style.top = 0;
		bodyBack.style.left = 0;
		bodyBack.style.filter = "alpha(opacity="+(this.filter * 100)+")";
		bodyBack.style.opacity = this.filter;
		bodyBack.style.background = "#000000";
		
		this._insertAfter(popupDiv,popupDiv);//执行函数insertAfter()
		this._insertAfter(bodyBack,popupDiv);//执行函数insertAfter()
		
	},
	
	_insertAfter: function (newElement,targetElement){//插入
		var parent = targetElement.parentNode;
			if(parent.lastChild == targetElement){
				parent.appendChild(newElement);
		}
		else{
			parent.insertBefore(newElement,targetElement.nextSibling);
		}
	},
	
	/**
	 * 弹出一个居中的DIV层
	 * @param {} popup
	 */
	PopupWindowWithCenter:function(popup){
		var popupDiv=popup.div;	
		popupDiv.style.position = "absolute";
		popupDiv.style.zIndex = popup.zIndex==undefined? 99:popup.zIndex;
		var arrayPageSize = this.getPageSize();//调用getPageSize()函数
		var arrayPageScroll = this.getPageScroll();//调用getPageScroll()函数
		var arrayConSize=this.getConSize(popupDiv)
		
		var top = arrayPageScroll[1] + (arrayPageSize[3] - arrayConSize[1]) / 2-50 + 'px';
		var left= (arrayPageSize[0] - arrayConSize[0]) / 2 -30 + 'px';
		
		popupDiv.style.top = top;
		popupDiv.style.left =left;
		
	},
	
	/**
	 * 获取内容层内容原始尺寸
	 * @param {String} containerId
	 * @return {Array} array[0]是宽度
	 * 					array[1]是高度
	 */
	getConSize:function (container){
		var arrayConSize=null;

		if(this._containerSize!=null){
			arrayConSize =[this._containerSize.width,this._containerSize.height];
		}else{
			arrayConSize=[container.offsetWidth,container.offsetHeight];
		}

		//arrayConSize=[container.offsetWidth,container.offsetHeight];
	
		return arrayConSize;
	},
	
	_containerSize:null,
	
	/**
	 * 设定容器大小
	 * @param {Object} size 参数形式如下:	
	 * 		{	"width":100,
	 * 			"height":100	
	 *  	}	
	 */
	setContainerSize:function(size){
		this._containerSize =size;
	},
	
	/**
	 * 获取滚动条的高度
	 * @return {Array} array[0]是空
	 * 					array[1]是高度
	 */
	getPageScroll: function (){
			var yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
			} else if (document.body) {
				yScroll = document.body.scrollTop;
			}
			arrayPageScroll = new Array('',yScroll)
			
			return arrayPageScroll;
		},
		
	/**
	 * 获取网页大小
	 * @return {Array} array[0]是pageWidth
	 * 					array[1]是pageHeight
	 * 					array[2]是windowWidth
	 * 					array[3]是windowHeight
	 * 
	 * 
	 * 
	 */					
	getPageSize : function (){
			var xScroll,yScroll;
			if (window.innerHeight && window.scrollMaxY){
				xScroll = document.body.scrollWidth;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){
				sScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
		
			var windowWidth,windowHeight;
			// var pageHeight,pageWidth;
			if (self.innerHeight) {
				windowWidth = self.innerWidth;
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			
			var pageWidth,pageHeight
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			if((xScroll < windowWidth ) || xScroll == null) {
				pageWidth = windowWidth;
			} else {
				pageWidth = xScroll;
				
			}
		
				arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
			return arrayPageSize;
	}
};
Shark.IdentifyingCode={
	zoomA:function(ele){
		ele = Shark.$(ele);
		ele.width =102;
		ele.height =38;
	},
	zoomD:function(ele){
		ele = Shark.$(ele);
		ele.width =98;
		ele.height =20;
	}
}




function Tooltip(tipWidth) {
	if(tipWidth==null){
		tipWidth=120;
	}
	if(tipWidth>0){
		tipWidth+="px";
	}
	var temp = document.getElementById("__tooltip__");
	if(temp==null){
    	this.tooltip = document.createElement("div"); 
   		this.tooltip.setAttribute("id","__tooltip__");
		this.tooltip.style.cssText=" color:#000000;background-color:#FFFF99; position:absolute; border:solid 1px #FF6600; width:"+tipWidth+"; padding: 5px;filter:Alpha(Opacity=100);opacity:1";
	}else{
		this.tooltip =temp;
	}
}
Tooltip.prototype.show = function(text, x, y,isAutoHidden,background) {
    this.tooltip.innerHTML = text;
    this.tooltip.style.left = x + "px";
    this.tooltip.style.top = y + "px";
	if(background!=null){
		this.tooltip.style.backgroundColor=background;
	}else{
		this.tooltip.style.backgroundColor="#FFFF99";
	}
	
	this.tooltip.style.filter = "Alpha(Opacity=100)";
    this.tooltip.style.opacity = 1;
    Tooltip.filterValue=100;
    var temp = document.getElementById("__tooltip__");
    if (  this.tooltip.parentNode != document.body && temp==null ){
        document.body.appendChild(this.tooltip);
    }else{
    		temp.style.display="block";
    }
    if(isAutoHidden==false){
    	return ;
    }else{
    	setTimeout("Tooltip.autoHidden()",3000);
    }
};

Tooltip.filterValue=100;
Tooltip.hidden=function(){
	var tooltipEle = document.getElementById("__tooltip__");
	tooltipEle.style.display="none";
}
Tooltip.autoHidden=function(){
	var tooltipEle = document.getElementById("__tooltip__");
   tooltipEle.style.filter = "Alpha(Opacity=" + Tooltip.filterValue + ")";
   tooltipEle.style.opacity = Tooltip.filterValue/100;
   Tooltip.filterValue=Tooltip.filterValue-1;
	if(Tooltip.filterValue<=0){
		tooltipEle.style.display="none";
		return ;
	}else{
		setTimeout("Tooltip.autoHidden()",10);
	}
}




Shark.Window = {
	confirmHandl:null,
	_Z : Shark.Constant.Layer.ZINDEX,
	CloseWindow	:function(){
		var parent =document.getElementById("__AlertWidow__");
		if(parent != undefined){
			document.body.removeChild(parent);
			document.body.removeChild(document.getElementById("__AlertFilterWidow__"));
		}
	},
	
	exception:function(errorCode,errorString){
		var str="<table width='100%' height='120px' border='0px' align='center' cellpadding='0' cellspacing='0' ><tr><td height='30px' align='center' valign='center' style='color:red' colspan='2'><font style='font-size:14px; font-weight:bold'>程序运行时错误</font></td></tr><tr><td width='70px'  height='20px' align='right' class='gray_666'>错误编码：</td><td align='left' class='gray_666'>";
		str+=errorCode;
		str+="</td></tr><tr><td width='70px' valign='top'  align='right' class='gray_666'>错误信息：</td><td align='left' valign='top' class='gray_666'>";
		str+=errorString;
		str+="</td></tr></table>";
		Shark.Window.AlertWindow({"width":300,"height":160,"mesage":str});
	},
	
	error:function(mess){
		Shark.Window.baseWindow({
			"color":"red",
			"title":mess.title==null?"错误提示":mess.title,
			"info":mess.info==null?mess:mess.info
		})
	},
	info:function(mess,event){
		Shark.Window.baseWindow({
			"color":"green",
			"title": mess.title==null?"信息提示":mess.title,
			"info":mess.info==null?mess:mess.info
		},event)
	},
	baseWindow:function(mess,event){
		var title=mess.title==null?"信息提示":mess.title;
		var str = "<table width='100%' height='80px' border='0px' cellpadding='0' cellspacing='0' ><tr><td align='center' height='30' valign='center' style='color:"+mess.color+"'  ><font style='font-size:14px; font-weight:bold'>"+mess.title+"</font></td></tr><tr><td  align='center' class='gray_666'>";
		str +=mess.info;
		str +="</td></tr></table>";		
		Shark.Window.AlertWindow({"width":270,"height":130,"mesage":str},event);	
	},
	AlertWindow:function( layer,event ){
		Shark.Window.createWindow(layer,1,event);
	},
	customWindow:function( layer ){
		Shark.Window.createWindow(layer,3,null);
	},
	confirmWindow:function( layer ,event){
		Shark.Window.createWindow(layer,2,event);
	},
	confirmEventWindow:function( layer ,event){
		Shark.Window.createWindow(layer,2,event);
	},
	
	createWindow:function( layer ,type ,event ){
			Shark.Window.confirmHandl=event;
			var parent =document.getElementById("__AlertWidow__");
			if(parent == undefined){
				Shark.Window.CloseWindow();
			
			}
				parent = document.createElement("div");
				parent.setAttribute("id","__AlertWidow__");
				parent.style.cssText="display:;z-index:101;position:absolute;"
				parent.style.width =layer.width;
				parent.style.height =layer.height;
				document.body.appendChild(parent);
				
				Shark.Wicket.setContainerSize({"width":layer.width,"height":layer.height});
				Shark.Wicket.PopupWindowWithCenter({"div" : parent,"zIndex":this._Z });
							
				var background=document.createElement("div");
				background.style.cssText="width:"+ layer.width+"px;height:"+layer.height +"px;top:0px;left:0px;" +
								"position:absolute;background-color:#FFFFFF;z-index:"+this._Z +"; border:solid 1px #FF6600;";
				parent.appendChild(background);
				var hatching = document.createElement("div");
				hatching.style.cssText="width:"+ layer.width+"px;height:"+layer.height +"px;top:4px;left:4px;" +
								"position:absolute;background-color:#FFC199;z-index:"+(this._Z -1)+"; opacity:1; filter:alpha(opacity=100);"
				parent.appendChild(hatching);
				background.innerHTML =Shark.Window._table(layer,type);
				var  filter = document.createElement("div");
				filter.setAttribute("id","__AlertFilterWidow__");
				Shark.Wicket.CreateFilterLayer({"element":filter,"z": (this._Z-2) });
				document.body.appendChild(filter);
			
	},
	confirmEvent:function(){
		if(Shark.Window.confirmHandl!=null){
			var ev = Shark.Window.confirmHandl;
			if(ev.begin !=null){
				var bool = ev.begin();
				if(bool){
					if(ev.end != null){
						ev.end();
					}		
				}else{
					return ;
				}	
			}
			if(ev.begin ==null&& ev.end == null){
				Shark.Window.confirmHandl();
			}
			Shark.Window.confirmHandl=null;
		}
		Shark.Window.CloseWindow();
	},
	_table:function(layer ,type){

	var table ="<table border=0  cellpadding=0 cellspacing=0 width="+layer.width +"px height="+layer.height+"px><tr>" ;
		switch(type){
			case 1:
				table +="<td  height="+(layer.height - 50)+"px valign=top ><div id=__AlertWindow__>"+layer.mesage+"</div></td></tr>" ;
				table+="<tr><td align=center height=50px>" +
							"<input name=\"image\" type=\"image\" onclick=\"Shark.Window.confirmEvent()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/sure_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/></td>"
				table +="</tr></table>";
				return table;
			case 2:
				table +="<td colspan=2 height="+(layer.height - 50)+"px valign=top ><div id=__AlertWindow__>"+layer.mesage+"</div></td></tr>" ;
				table+="<tr><td align=right height=50px>" +
						"<input name=\"image\" type=\"image\" onclick=\"Shark.Window.confirmEvent()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/sure_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/>&nbsp;</td>"+
						"<td>&nbsp;&nbsp;<input name=\"image\" type=\"image\" onclick=\"Shark.Window.CloseWindow()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/cancel_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/cancel_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/cancel_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/></td>";	
				table +="</tr></table>";
				return table;
				
			case 3:
				table +="<td  height="+(layer.height - 50)+"px valign=top ><div id=__AlertWindow__>"+layer.mesage+"</div></td></tr>" ;

				
				table +="</table>";
				return table;
				
				break;	
				
		}
		/*
			if(type ==1){
				table +="<td  height="+(layer.height - 50)+"px valign=top ><div id=__AlertWindow__>"+layer.mesage+"</div></td></tr>" ;
				table+="<tr><td align=center height=50px>" +
							"<input name=\"image\" type=\"image\" onclick=\"Shark.Window.confirmEvent()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/sure_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/></td>"
				table +="</tr></table>";
				return table;
			}else{
				table +="<td colspan=2 height="+(layer.height - 50)+"px valign=top ><div id=__AlertWindow__>"+layer.mesage+"</div></td></tr>" ;
				table+="<tr><td align=right height=50px>" +
						"<input name=\"image\" type=\"image\" onclick=\"Shark.Window.confirmEvent()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/sure_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/sure_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/>&nbsp;&nbsp;</td>"+
						"<td>&nbsp;&nbsp;<input name=\"image\" type=\"image\" onclick=\"Shark.Window.CloseWindow()\" onmousemove=\"this.src='"+Shark.Constant.WebRoot+"images/cancel_btn_1.gif'\" onmouseout=\"this.src='"+Shark.Constant.WebRoot+"images/cancel_btn.gif'\"  src=\""+Shark.Constant.WebRoot+"images/cancel_btn.gif\" width=\"44px\" height=\"22px\" border=\"0\"/></td>";	
				table +="</tr></table>";
				return table;	
			}		
		}
		*/
		
	}
}
Shark.EffectPage={
	pageEvent:null,
	bindHandl:function(pageNumber){
		Shark.EffectPage.pageEvent(pageNumber);
		return false;
	},
	pagebarHtml:function(page,event){
		Shark.EffectPage.pageEvent =event;
	
		var html = new StringBuffer();
		var size = page.size();
		var current=page.current();
		
		html.append("<ul>\n");
		if(current != size){
			html.append(this.nextPagebar());
		}
		if(size <=9){
			for(var i = size ; i >= 1;i-- ){	
				if(i == page.current(current)){
					html.append(this.currentPagebar(current));
				}else{
					html.append(this.numPagebar(i));
				}
			}
		}else{
			for(var i = size ; i >= 1;i-- ){
				switch(i){
					case  current:
						html.append(this.currentPagebar(current));
						break;
					case  1:
					case  size:
					case  current +1:
					case  current +2:
					case  current -1:
					case  current -2:
						html.append(this.numPagebar(i));
						break ;
					case  current +3:
					case  current -3:
						html.append(this.pointPabebar());
						break ;
				}
			}
		}
		if(current!=1){
			html.append(this.prevPagerbar());
		}
		html.append("</ul>");
		return html.toString();
	},

	currentPagebar:function(num){
		return "<li class=\"pagebarCurrent\">"+num+"</li>\n" ;
	},
	numPagebar:function(num){
		 return "<li><a  style=\"cursor: pointer;\" onclick=\"Shark.EffectPage.bindHandl("+ num +")\">"+ num +"</a></li>\n";
	},
	pointPabebar:function(){
		return "<li class=\"page_ponit\">&#8230;</li>\n";
	},
	nextPagebar:function(){
		return  "<li style=\"width:61px;\"><a style=\"cursor: pointer;\" onclick=\"Shark.EffectPage.bindHandl('N')\">下一页<img src=\""+Shark.Constant.WebRoot+"images/page_next.gif\" border=\"0\" align=\"absmiddle\" style=\"padding-left:3px;\"/></a></li>";
	},
	prevPagerbar:function(){
		return "<li style=\"width:61px;\"><a style=\"cursor: pointer;\"  onclick=\"Shark.EffectPage.bindHandl('P')\"><img src=\""+Shark.Constant.WebRoot+"images/page_pre.gif\" border=\"0\" align=\"absmiddle\" style=\"padding-right:3px;\"/>上一页</a></li>"
	}
}

Shark.Page =Shark.Core.extend({
		_length:0,	//一共有多少条记录
		_current:1,	//当前页
		_pageCount: Shark.Constant.PAGE_COUNT,//一页记录数量
		_sizePage:0,//一共有多少页
		$construct: function(length){
        	this._length = length;
        	this._sizePage  = Math.floor(length /  this._pageCount);
        	var tem= length %  this._pageCount;
        	this._sizePage  = tem > 0 ? this._sizePage + 1 : this._sizePage;
    	},
    	pageCount:function(pageCount){
    		this._pageCount = pageCount;
    		this._sizePage  = Math.floor(this._length /  this._pageCount);
    		var tem= this._length %  this._pageCount;
        	this._sizePage  = tem > 0 ? this._sizePage + 1 : this._sizePage;
    		return this._pageCount;
    	},
    	number:function(num){
    		var m = num > this._sizePage ? num: this._sizePage;
    		m = num <1? 1: num;
    		this._current=m;
    		return m;
    	},
    	totalNum:function(){
    		return this._length;
    	},
		size:function(){
			return this._sizePage;
		},
		current:function(){
			return this._current;
		},
		next:function(){
			var temp =this._current+1;
			temp = temp >= this._sizePage ? this._sizePage :temp;
			this._current = temp	
			return temp;
		},
		prev:function(){
			var temp = this._current - 1;
			temp =  temp < 1 ? 1 : temp;
			this._current = temp;
			return temp;
		},
		first:function(){
			this._current=1;
			return 1; 
		},
		end:function(){
			return this._sizePage;
		}
});



