﻿jQuery.datepicker.updateDatepicker=jQuery.datepicker._updateDatepicker;
jQuery.datepicker._updateDatepicker=function(param){	
	jQuery.datepicker.updateDatepicker(param);
	var calendar=$(".ui-datepicker-calendar");
	var buttonpane=$(".ui-datepicker-buttonpane");
	if(!param.inserted)
	{
		param.inserted=true;
		
		
		if(param.settings.useTime==true)
		{
			//初始化时间
			var dateString=param.input.val();
			var date=new Date();
			if(dateString!="")
				date=jQuery.dateFormat(dateString,param.settings.dateFormatOld);
					
			var strHtml="<div class='ui-datepicker-buttonpane ui-widget-content'>";
			strHtml+="<table border='0' cellspacing='2' cellpadding='0'><tr><td>";
			strHtml+="<select id='datepicker_hour' class='time_select'>";		
			for(var i=0;i<24;i++)
				strHtml+="<option value='"+(i<10?("0"+i):i)+"' "+(date.getHours()==i?"selected":"")+">"+(i<10?("0"+i):i)+"</option>";
			strHtml+="</select>:";
			strHtml+="<select id='datepicker_minute' class='time_select'>";
			for(var i=0;i<60;i++)
				strHtml+="<option value='"+(i<10?("0"+i):i)+"' "+(date.getMinutes()==i?"selected":"")+">"+(i<10?("0"+i):i)+"</option>";
			strHtml+="</select>:";
			strHtml+="<select id='datepicker_second' class='time_select'>";
			for(var i=0;i<60;i++)
				strHtml+="<option value='"+(i<10?("0"+i):i)+"' "+(date.getSeconds()==i?"selected":"")+">"+(i<10?("0"+i):i)+"</option>";
			strHtml+="</select>";
			strHtml+="</td><td>";
			strHtml+="<button type='button' id='datepicker_now' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all'>Now</button>";
			strHtml+="</td></tr></table>";
			strHtml+="</div>";
			
			param.time=$(strHtml);	
			
			calendar.after(param.time);
		}
				
		param.clearBtn=$("<button type='button' class='ui-state-default ui-corner-all'>清除</button>");
		param.clearBtn.appendTo(buttonpane);		
		
	}
	param.clearBtn.appendTo(buttonpane);
	param.clearBtn.click(function(){
		param.input.val("");
	});
	param.clearBtn.mouseover(function(){
		$(this).addClass("ui-state-hover");
	});
	param.clearBtn.mouseleave(function(){
		$(this).removeClass("ui-state-hover");
	});
	if(param.settings.useTime==true)
	{
		calendar.after(param.time);
		param.time.find(".time_select").change(function(){
			param.settings.resetDateTime(param.selectedYear+"-"+(param.selectedMonth+1)+"-"+param.selectedDay,param);
		});	
		param.time.find("#datepicker_now").click(function(){
			param.time.find("#datepicker_hour").val(jQuery.formatDate("hh"));
			param.time.find("#datepicker_minute").val(jQuery.formatDate("mm"));
			param.time.find("#datepicker_second").val(jQuery.formatDate("ss"));
			param.settings.resetDateTime(param.selectedYear+"-"+(param.selectedMonth+1)+"-"+param.selectedDay,param);
		})
	}
}
$.datepicker.regional['zh-CN'] = { 
        clearText: '清除', 
        clearStatus: '清除已选日期', 
        closeText: '确定', 
        closeStatus: '不改变当前选择', 
        prevText: '<上月', 
        prevStatus: '显示上月', 
        prevBigText: '<<', 
        prevBigStatus: '显示上一年', 
        nextText: '下月>', 
        nextStatus: '显示下月', 
        nextBigText: '>>', 
        nextBigStatus: '显示下一年', 
        currentText: '今天', 
        currentStatus: '显示本月', 
        monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'], 
        monthNamesShort: ['一','二','三','四','五','六', '七','八','九','十','十一','十二'], 
        monthStatus: '选择月份', 
        yearStatus: '选择年份', 
        weekHeader: '周', 
        weekStatus: '年内周次', 
        dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], 
        dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'], 
        dayNamesMin: ['日','一','二','三','四','五','六'], 
        dayStatus: '设置 DD 为一周起始', 
        dateStatus: '选择 m月 d日, DD', 
        dateFormat: 'yy-mm-dd', 
        firstDay: 1, 
        initStatus: '请选择日期', 
        isRTL: false}; 
$.datepicker.setDefaults($.datepicker.regional['zh-CN']); 

/**
* 基于jquery及jquery ui开发的后台常用js
* 作者：飞啊飘啊
* 主页：http://work.feiapiaoa.com
* 日期：2010年12月
* QQ:27375334
**/

/**
* 树控件
**/
$.fn.extend({
	datepickerEx:jQuery.fn.datepicker,
	datepicker:function(params){
		params.dateFormatOld=params.dateFormat||"yyyy-MM-dd";
		params.dateFormat="yy-mm-dd";
		var onSelectOld=params.onSelect;
		params.onSelect=function(dateText, inst){
			jQuery.datepicker.hideDatepicker=jQuery.datepicker._hideDatepicker;
			jQuery.datepicker._hideDatepicker=function(){
				this._updateDatepicker(inst);
				jQuery.datepicker._hideDatepicker=jQuery.datepicker.hideDatepicker;
			}
			params.resetDateTime(dateText, inst);
		}
		params.resetDateTime=function(dateText, inst){
			if(onSelectOld)
				onSelectOld(dateText,inst);
			var dates=dateText.split("-");
			var date;			
			if(inst.settings.useTime==true)	
			{
				date=new Date(
					Number(dates[0]),
					Number(dates[1])-1,
					Number(dates[2]),
					Number($("#datepicker_hour").val()),
					Number($("#datepicker_minute").val()),
					Number($("#datepicker_second").val())
				);
			}
			else
				date=new Date(
					Number(dates[0]),
					Number(dates[1])-1,
					Number(dates[2])
				);
			var strDate=jQuery.formatDate(params.dateFormatOld,date);
			inst.input.val(strDate);
		}
		params.showAnim=false;
		return this.datepickerEx(params);
	},
	/**
	* 多个tab切换的iframe
	**/
	browser:function(params){
		if($("#browser-css").length==0)
		{
			var css="<style id='browser-css'>";	
			css+=".browser-hearder{height:28px;width:100%;overflow:hidden;}";
			css+=".browser-more{margin:0px;padding:0px;height:35px;width:50px;float:left;}";
			css+=".browser-more li{width:16px;height:16px;list-style:none;float:left;margin:9px 2px;cursor:pointer;}";
			css+=".browser-tabs{height:28px;overflow:hidden;float:left;}";
			css+=".browser-td{padding:0px 5px}";				
			css+=".browser-bodyer{overflow:hidden; width:100%; height:100%; border:0px;}";
			css+=".browser-button{height:25px;font-size:12px;white-space:nowrap; padding:0px 5px 0px 10px; cursor:pointer;}";
			css+=".browser-menu{display:none;position: absolute;list-style:none; padding:0px; margin:0px; width:100px;}";
			css+=".browser-menu li{margin:1px; padding:5px 10px; cursor:default;}";
			css+="</style>";
			$(css).appendTo("head");		
		}
				
		this.css("overflow","hidden");
		
		if(params)
			this.refresh=params.refresh;
		
		var pThis=this;
		
		var thisId=this.attr("id");	
		
		this.hearder=$("<div id='"+thisId+"-hearder' class='browser-hearder'></div>");
		this.hearder.appendTo(this);
				
		this.tabs=$("<div id='"+thisId+"-tabs' class='browser-tabs'><table border=\"0\" cellspacing=\"2\" cellpadding=\"0\"><tr id='"+thisId+"-tr'></tr></table></div>");
		this.tabs.appendTo(this.hearder);
		
		this.more=$("<ul class='ui-widget ui-helper-clearfix browser-more'><li class='ui-state-default ui-corner-all'><span class='ui-icon ui-icon-triangle-1-w'></span></li><li class='ui-state-default ui-corner-all'><span class='ui-icon ui-icon-triangle-1-e'></span></li></ul>");
		this.more.appendTo(this.hearder);
		
		this.tr=$("#"+thisId+"-tr");
		
		this.bodyer=$("<div id='"+thisId+"-bodyer' class='browser-bodyer ui-widget-content'></div>");
		this.bodyer.appendTo(this);
		
		
		/******************创建一个关闭其它功能***********************/
		this.contextMenu=$("<ul class='browser-menu ui-widget-content'></ul>");
		this.contextMenu.closer=$("<li>关闭</li>");
		this.contextMenu.closer.click(
			function(){
				if(pThis.current)
					pThis.current.close();
				pThis.contextMenu.hide();
			}
		);
		this.contextMenu.closer.appendTo(this.contextMenu);
		this.contextMenu.closerOther=$("<li>关闭其它</li>");
		this.contextMenu.closerOther.click(
			function(){
				for(var o in pThis.hrefs)
				{
					if(pThis.hrefs[o]!=pThis.current)
						pThis.hrefs[o].close();
				}
				pThis.contextMenu.hide();
			}
		);
		this.contextMenu.closerOther.appendTo(this.contextMenu);
		this.contextMenu.closerAll=$("<li>关闭所有</li>");
		this.contextMenu.closerAll.click(
			function(){
				for(var o in pThis.hrefs){
						pThis.hrefs[o].close();
				}
				pThis.contextMenu.hide();
			}
		);
		this.contextMenu.closerAll.appendTo(this.contextMenu);
		this.contextMenu.appendTo($("#"+thisId+"-tabs"));
		this.contextMenu.find("li").mouseover(
			function(){
				$(this).addClass("ui-state-active");				
			}
		);
		this.contextMenu.find("li").mouseout(
			function(){
				$(this).removeClass("ui-state-active");
			}
		);
		this.contextMenu.mouseleave(
				function(){
					pThis.contextMenu.hide();
		});
		$("#"+thisId+"-tabs").mouseleave(
				function(){
					pThis.contextMenu.hide();
		});
		this.contextMenu.find("li").addClass("ui-state-default");			
		this.onContextMenu=function(contextButton){			
			pThis.contextMenu.css("z-index",$.zindex());
			var offset=contextButton.position();
			pThis.contextMenu.css("left",offset.left-8);
			pThis.contextMenu.css("top",offset.top+contextButton.height()-2);
			pThis.contextMenu.show();
		}	
		/******************over***********************/
		
		this.left=this.more.find(".ui-icon-triangle-1-w");
		this.right=this.more.find(".ui-icon-triangle-1-e");		
		this.toLeft=function(){			
			pThis.tabs.scrollLeft(pThis.tabs.scrollLeft()-50);
		}
		this.toRight=function(){
			pThis.tabs.scrollLeft(pThis.tabs.scrollLeft()+50);
		}		
		this.left.click(this.toLeft);
		this.right.click(this.toRight);		
		
		this.onResize=function(){
			pThis.tabs.width(pThis.width()-pThis.more.width());
			pThis.bodyer.height(pThis.height()-pThis.tabs.height());
			pThis.bodyer.width(pThis.width());
		}
		
		this.resize(this.onResize);
		$(document).resize(this.onResize); 
		$(window).resize(this.onResize);
			
		this.hrefs=[];
		
		this.href=function(url,title){
			if(url.indexOf("#")==0)
				return;
			var flag=url; 
			if(url.indexOf("?")!=-1)
			   flag=url.substring(0,url.indexOf("?"));			
			if(this.hrefs[flag]){
				this.hrefs[flag].active();
				return;
			}
			var newHref=this.hrefs[flag]=new Object();
			newHref.flag=flag;
			newHref.url=url;
			newHref.title=title;
			newHref.td=$("<td class='ui-state-default ui-corner-top ui-state-active browser-td'></td>");
			newHref.td.get(0).onwer=newHref;
			newHref.td.appendTo(this.tr);			
			newHref.table=$("<table border='0' cellspacing='0' cellpadding='0'><tr><td class='browser-button'>"+title+"</td><td><span class=\"ui-icon ui-icon-close\"></span></td></tr></table>");
			newHref.button=newHref.table.find(".browser-button");
			newHref.icon=newHref.table.find(".ui-icon");			
			newHref.table.appendTo(newHref.td);
			newHref.iframe=$("<iframe id='browser' src='#' scrolling='yes' width='100%' height='100%' frameborder='0' style='width:100%;height:100%; display:none;'></iframe>");
			newHref.iframe.appendTo(this.bodyer);
						
			newHref.button.get(0).oncontextmenu=
				function(){
					newHref.active();
					pThis.onContextMenu(newHref.button);
					return false;
				};
			document.oncontextmenu=function(e){return false;} 
			
			newHref.active=function(){
				if(pThis.current){
					pThis.current.td.removeClass("ui-state-active");
					pThis.current.iframe.hide();
				}
				pThis.current=newHref;
				pThis.current.td.addClass("ui-state-active");
				pThis.current.iframe.show();
				
				if(pThis.refresh)
					newHref.open();
			}
			newHref.close=function(){
				
				delete pThis.hrefs[newHref.flag];
				
				if(pThis.current==newHref){
					if(newHref.td.prev().length>0)
						newHref.td.prev().get(0).onwer.active();
					else if(newHref.td.next().length>0)
						newHref.td.next().get(0).onwer.active();
				}
				
				newHref.td.remove();
				newHref.iframe.remove();
			}
			newHref.open=function(){
				var tUrl=pThis.current.url;
				tUrl=tUrl+(tUrl.indexOf("?")>-1 ? "&" : "?") +"mm="+ Math.random();//防止缓存，在网址后面加随数		
				pThis.current.iframe.get(0).src=tUrl;
			}
			
			newHref.button.click(newHref.active);
			newHref.icon.click(newHref.close);
			
			newHref.active();
			newHref.open();
		};
				
		this.onResize();
		
		return this;
	},
	/**
	* 树控件
	**/
    tree:function(value){
		if($("#tree-css").length==0)
		{
			var css="<style id='tree-css'>";
			css+=".tree-item{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}";
			css+=".tree-item td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}";
			css+="</style>";
			$(css).appendTo("head");
		}
		if(!value)
			value=new Object();
		value.text=value.text||"";
		value.href=value.href||"#";
		if(!this.desp)
		{
			this.desp=0;
			this.expand=true;
		}
		var branches=$("<div class='ui-corner-all ui-helper-clearfix ui-helper-reset'></div>");
		branches.desp=this.desp+1;
		branches.expand=value.expand;
		branches.onwer=this;
		branches.params=value;
		var leaf=branches.leaf=$("<div class='ui-helper-clearfix ui-helper-reset ui-button-text tree-item' style='height:25px;'><table cellspacing='0' cellpadding='0'><tr><td><span class='ui-icon ui-icon-document c-left' style='margin:3px;'></span></td><td><a class='c-left' href=\""+value.href+"\">"+value.text+"</a></td></tr></table></div>");
		leaf.branches=branches;
		leaf.eq(0).css("margin-left",(branches.desp-1)*10);
		leaf.find("span").click(function(){
			branches.expand=!branches.expand;
			if(branches.expand)
				branches.show();
			else
				branches.hide();
			leaf.find("span").removeClass("ui-icon-triangle-1-s");
			leaf.find("span").removeClass("ui-icon-triangle-1-e");
			leaf.find("span").addClass(branches.expand?"ui-icon-triangle-1-s":"ui-icon-triangle-1-e");
		});
		leaf.css("line-height","25px");
		leaf.appendTo(this);
		branches.appendTo(this);
		branches.hide();
		if(this.expand==true)
			this.show();
		else
			this.hide();
		if(this.leaf){
			this.leaf.find("span").removeClass("ui-icon-document");
			this.leaf.find("span").addClass(this.expand==true?"ui-icon-triangle-1-s":"ui-icon-triangle-1-e");
		}
		return branches;
    },	
	/**
	* 表格控件（兼树形表格）
	**/
	grid:function(params){
		if($("#grid-css").length==0)
		{
			var css="<style id='grid-css'>";
			css+=".grid-head{width:100%; height:30px; overflow:hidden;}";
			css+=".grid-head-table{border:0px;}";
			css+=".grid-head-tr{border:0px;}";
			css+=".grid-head-td{text-align:center;}";
			css+=".grid-head-div{overflow:hidden; text-align:center}";			
			css+=".grid-body{width:100%;overflow:auto;}";
			css+=".grid-body-table{}";
			css+=".grid-body-tr{border:0px;}";
			css+=".grid-body-td{text-align:center; height:30px; line-height:30px;}";
			css+=".grid-body-div{overflow:hidden; text-align:center}";
			css+=".grid-body-span{width:auto;overflow:hidden;white-space:nowrap;}";
			css+=".grid-body-span .ui-icon{display:none;}";
			css+=".grid-fill-div{overflow:hidden;height:1px;}";
			css+=".ui-icon-none{background-image:none;background-position:1000px; background-repeat:no-repeat;}";
			css+=".ui-icon-define{margin-top:5px}";			
			css+="</style>";
			$(css).appendTo("head");
		}
		var id=this.get(0).id;
		var headDiv=this.headDiv=$("<div id='"+id+"-head' class='grid-head'></div>");
		this.html("");
		this.css("overflow:hidden;");
		headDiv.appendTo(this);
		var headTable=$("<table id='"+id+"-head-table' class='grid-head-table' width='100%' height='100%' border='0' cellspacing='1' cellpadding='0'><tr class='ui-state-default grid-head-tr'><td class='end grid-head-td' width='*'><div  calss='grid-head-div' style='width:22px;'>&nbsp;</div></td></tr></table>");
		headTable.appendTo(headDiv);
		this.header=headTable.find("tr");
		this.nodeAt=params.nodeAt?params.nodeAt:0;
		this.widths=[];
		var allWidth=0;
		for(var i=0;i<params.column.length;i++)
		{
			var td=$("<td class='grid-head-td'></td>");
			td.insertBefore(this.header.find(".end"));
			td.css("width",params.column[i][1]);
			var div=$("<div class='grid-head-div'><div>");
			div.html(params.column[i][0]);
			div.css("width",params.column[i][1]);
			div.appendTo(td);
			this.widths[i]=params.column[i][1];
			allWidth+=this.widths[i];
		}
		
		var bodyDiv=$("<div id='"+id+"-body' class='grid-body'></div>");
		bodyDiv.appendTo(this);
		bodyDiv.scroll(function(){
			$("#"+id+"-head").scrollLeft($("#"+id+"-body").scrollLeft());
		});
		bodyDiv.css("height",this.height()-headDiv.height());
		var bodyTable=$("<table id='"+id+"-body-table' class='grid-body-table ui-widget-content' width='100%' border='0' cellspacing='1' cellpadding='0'></table>");
		bodyTable.appendTo(bodyDiv);
		var fillDiv=$("<div class='grid-fill-div'></div>");
		fillDiv.width(allWidth);
		fillDiv.appendTo(bodyDiv);
		
		/*************************添加表格特效*******************************/
		{
			var oddColor=$(".grid-body-table").css("background-color");
			var evenColor=$.tinyColor(oddColor,10);
			var borderColor=$.tinyColor(oddColor,30);
			var focusColor=$.tinyColor(oddColor,5);
			var focusBorderColor=$.tinyColor(oddColor,60);
			
			headTable.css("background-color",borderColor);	
			bodyTable.css("background-color",borderColor);
			bodyTable.css("background-image","none");
			bodyTable.css("border","0px");
			
			if($("#table-even-td-css").length==0)
			{
				var css="<style id='table-even-td-css'>";
				css+=".grid-body-table tr td{border-style:solid;border-width:1px 0 1px 0;background-color:"+oddColor+";border-color:"+oddColor+";}";
				css+=".grid-body-table .odd td{background-color:"+oddColor+";border-color:"+oddColor+";}";
				css+=".grid-body-table .even td{background-color:"+evenColor+";border-color:"+evenColor+";}";
				css+=".grid-body-table .focus td{background-color:"+focusColor+";border-color:"+focusBorderColor+";}";
				css+="</style>";
				$(css).appendTo("head");
			}
		}
		$(function(){
			$(".grid-body-table tr").removeClass("even");
			$(".grid-body-table tr").removeClass("odd");
			
			$(".grid-body-table tr:even").addClass("even");
			$(".grid-body-table tr:even").data("even",true);			
			$(".grid-body-table tr:odd").addClass("odd");
			$(".grid-body-table tr:odd").data("odd",true);
			
			$(".grid-body-table tr").mouseenter(
				function(){
					$(this).addClass("focus");
					$(this).removeClass("even");
					$(this).removeClass("odd");
			});
			$(".grid-body-table tr").mouseleave(
				function(){
					$(this).removeClass("focus");
					if($(this).data("even")==true)
						$(this).addClass("even");
					if($(this).data("odd")==true)
						$(this).addClass("odd");
			})
		});
		/*************************添加表格特效结束****************************/
		
		var pThis=this;
		
		this.onResize=function(){
			bodyDiv.height(pThis.height()-pThis.headDiv.height());			
		}
		this.resize(this.onResize);
		$(document).resize(this.onResize); 
		$(window).resize(this.onResize);
		
		var gridTable=this;
		this.add=function(datas,onwer){
			
			var tr=$("<tr class='grid-body-tr'><td class='end grid-body-td' width='*'>&nbsp;</td></tr>");
						
			tr.add=function(datas){
				//当如果调用到此时，表示该控件是个树形控件
				if($("#grid-tree-css").length==0)
				{
					var css="<style id='grid-tree-css'>";
					css+=".grid-tree-div{text-align:left;}";
					css+=".grid-tree-div .grid-body-span{text-align:left;}";
					css+=".grid-tree-div .ui-icon{display:block; cursor:pointer;}";					
					css+="</style>";
					$(css).appendTo("head");
				}
				return gridTable.add(datas,this);
			};
			
			//更新图标
			tr.Icon=function(){
				this.icon.removeClass("ui-icon-triangle-1-s");
				this.icon.removeClass("ui-icon-triangle-1-e");
				this.icon.removeClass("ui-icon-none");
				if(this.childs.length==0){
					this.icon.addClass("ui-icon-none");
				}
				else{
					this.icon.addClass(this.expand?"ui-icon-triangle-1-s":"ui-icon-triangle-1-e");
				}
			}
			
			//展开收缩
			tr.OnExpand=function(bShow){
				this.expand=bShow;
				this.Icon();
				for(var i=0;i<this.childs.length;i++){
					if(bShow)
						this.childs[i].show();
					else
						this.childs[i].hide();
					if(!this.expand)
						this.childs[i].OnExpand(false);
				}
			}
			
			tr.expand=datas.expand;
			var temp=onwer;
			while(temp){//往上级连查找是否有关闭的节点
				if(!temp.expand)
					tr.expand=false;
				temp=temp.onwer;
			}
			tr.childs=[];
			tr.tds=[];
			tr.divs=[];
			tr.spans=[];
			for(var i=0;i<datas.data.length;i++)
			{
				var td=tr.tds[tr.tds.length]=$("<td class='grid-body-td'></td>");				
				td.insertBefore(tr.find(".end"));
				td.css("width",this.widths[i]);
				
				var div=tr.divs[tr.divs.length]=$("<div class='grid-body-div'><div>");
				if(i==gridTable.nodeAt){
					div.addClass("grid-tree-div");
				}
				div.html("");
				div.appendTo(td);
				div.css("width",this.widths[i]);
				
				var span=tr.spans[tr.spans.length]=$("<div class='grid-body-span'><div>");
				span.html(datas.data[i]);
				span.appendTo(div);
				
				if(i==gridTable.nodeAt){
					var icon=tr.icon=$("<span class='ui-icon ui-icon-none ui-icon-define' style='float:left;backgroud-image:none;'></span>");
					icon.html("");
					icon.prependTo(span);
					icon.onwer=tr;
					icon.click(function(){						
						tr.expand=!tr.expand;
						tr.OnExpand(tr.expand);	
					})
					
				}
			}			
			
			tr.children("td").css("background-color",bodyTable.oldBackgroundColor);			
			
			if(onwer)
			{
				tr.onwer=onwer;
				if(onwer.lastNode)
				{
					var last=onwer.lastNode;
					while(last.lastNode)
						last=last.lastNode;
					tr.insertAfter(last);
				}
				else
					tr.insertAfter(onwer);
				onwer.lastNode=tr;
				onwer.childs[onwer.childs.length]=tr;
				tr.desp=onwer.desp+1;
												
				tr.spans[gridTable.nodeAt].css("padding-left",(tr.desp*20));				
				
				
				//如果上级是关闭的，刚不显示
				if(!onwer.expand)
					tr.hide();
				
				onwer.Icon();
			}
			else
			{
				tr.appendTo(bodyTable);	
				tr.desp=0;
			}
			tr.Icon();
			
			return tr;
		}
				
		var gridId=this;
		this.OnResize=function(){
			//$("#"+id+"-body").hide();
			setTimeout(function(){
				$("#"+id+"-body").height($(gridId).height()-$("#"+id+"-head").height());
				//$("#"+id+"-body").show();				
			},1);
		}		
		
		this.OnResize();
		
		$(window).resize(this.OnResize); 
		
		this.OnResize();
		
		return this;
	}
	/**
	* 验证FORM的并提示
	**/
	,form:function(items){
		var formId=this.attr("id");
		if($("#"+formId+"_error").get(0))
			$("#"+formId+"_error").remove();
		var errors=[];
		for(var o in items)
		{
			try{
				var el=$("#"+o).get(0);				
				if(!el)
					continue;
				el.value=jQuery.trim(el.value);
				var strError=items[o]($("#"+o).get(0));
				$("#"+o).next(".input-warn").remove();
				if(strError){
					errors[errors.length]=strError;
					$("<span class='ui-icon ui-icon-notice input-warn' style='display:inline-block;'></span>").insertAfter($("#"+o));
				}
			}catch(e){
			}
		}
		if(errors.length>0)
		{
			$("<div id='"+formId+"_error' class='ui-state-error' style='padding:5px;line-height:20px; margin:10px auto;'><span id='"+formId+"_details'></span></div>").insertBefore(this);
			$("#"+formId+"_details").html(errors[0]);
			if(errors.length>1)
			{
				var more=$("<span class='ui-icon ui-icon-plus c-left'></span>").prependTo($("#"+formId+"_error"));			
				more.attr("title","显示全部");
				more.click(function(){
					var strAll="";
					for(var o in errors)
					{
						strAll+="<li>"+errors[o]+"</li>";
					}
					$("#"+formId+"_error").html("<ul>"+strAll+"</ul>");
				});
			}
			return false;
		}
		else
			return true;
	}
	/**
	* jquery dialog拦截
	**/
	,$dialog:$.prototype.dialog
	,dialog:function(param){
		if(this.length!=1){
			this.remove();			
			return $.debug("数据请求失败,不能创建对话框 $(?).dialog must be only one of object");
		}
		this.appendTo("body");
		
		
		var wh=$(window).height()-60;
		var ww=$(window).width()-20;
		
		param=param||[];
		
		param.bgiframe=true;
		
		param.width=this.width();
				
		if(this.height()>wh || (param.height && parseInt(param.height)>wh))
			param.height=wh;
		if(this.width()>ww || (param.width && parseInt(param.width)>ww))
			param.width=ww;
		
		var iclose=param.close;
		param.close=function(){
			this.iclose=iclose;
			if(this.iclose)
				this.iclose();
			$(this).remove();
		}	
		
		var owh=$(window).height();
		
		var d = this.$dialog(param);
		
		if(d.height()>(wh-60))
			d.height(wh-40);
			
		$(".dialog_iframe").remove();
			
		var iframe=$("<iframe class='dialog_iframe' border='0' width='100%' height='100%'></iframe>");
		
		iframe.fadeTo("fast",0);
			
		iframe.appendTo($(".ui-widget-overlay"));
			
		return d;
	}
	/*透明化ie6下的png*/
	,pngFix:function(settings) {

		// Settings
		settings = jQuery.extend({
			blankgif: 'blank.gif'
		}, settings);
	
		var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	
		if (jQuery.browser.msie && (ie55 || ie6)) {
	
			//fix images with png-source
			jQuery(this).find("img[src$=.png]").each(function() {
	
				jQuery(this).attr('width',jQuery(this).width());
				jQuery(this).attr('height',jQuery(this).height());
	
				var prevStyle = '';
				var strNewHTML = '';
				var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
				var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
				var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
				var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
				var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
				var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
				if (this.style.border) {
					prevStyle += 'border:'+this.style.border+';';
					this.style.border = '';
				}
				if (this.style.padding) {
					prevStyle += 'padding:'+this.style.padding+';';
					this.style.padding = '';
				}
				if (this.style.margin) {
					prevStyle += 'margin:'+this.style.margin+';';
					this.style.margin = '';
				}
				var imgStyle = (this.style.cssText);
	
				strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
				strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
				strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
				strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
				strNewHTML += imgStyle+'"></span>';
				if (prevStyle != ''){
					strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
				}
	
				jQuery(this).hide();
				jQuery(this).after(strNewHTML);
	
			});
	
			// fix css background pngs
			jQuery(this).find("*").each(function(){
				var bgIMG = jQuery(this).css('background-image');
				if(bgIMG.indexOf(".png")!=-1){
					var iebg = bgIMG.split('url("')[1].split('")')[0];
					jQuery(this).css('background-image', 'none');
					jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
				}
			});
			
			//fix input with png-source
			jQuery(this).find("input[src$=.png]").each(function() {
				var bgIMG = jQuery(this).attr('src');
				jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
			jQuery(this).attr('src', settings.blankgif)
			});
		
		}
	},
	/*
	* 为对象编号输入框添加智能查询
	*/
	relation:function(){
		var pThis=$(this);
		if(pThis.data("Init-Relation")==true)
			return false;
		pThis.data("Init-Relation",true);
		pThis.autocomplete({
			  source:function(request, response ) {
					 $.ajax({
						url:pThis.attr("url"),
						cache: false,
						dataType:"json",
						data:{term:request.term},
						success:response
					});
			  },
			  select: function( event, ui ) {
					$(this).val(ui.item.id);
					return false;
			  },
			  minChars:1,
			  matchSubset:true,
			  cacheLength:1
	   });
	   pThis.blur(function(){
			$(this).val($(this).val().replace(/[^\d]/g,''));
	   });
	}
});

$.extend({
	include:function(url){
		document.write($.ajax({url:url,cache: false,async: false}).responseText);		
	},
	debug:function(message){
		
	},	
	/**
	* 加载并显示图片(默认大小500*500)
	**/
	thumb:function(params){	
		var img = new Image();
		img.src = params.url;
		img.callback=function(){
			
			params.width=params.width||500;
			params.height=params.height||500;
			
			var ow=this.width;
			var oh=this.height;
			
			var iw=ow/params.width;//宽倍
			var ih=oh/params.height;//高倍
			
			var again=iw>ih?iw:ih;
			
			var nw=ow;
			var nh=ow;
			
			if(again>1){
				this.width=ow/again;
				this.height=oh/again;
			}
			
			var div=$("<div></div>");
			
			div.css("width",this.width+30);
			div.css("height",this.height+50);
			
			$(this).appendTo(div);
			
			div.dialog({width:this.width+30,height:this.height+50,title:"查看图片",modal:true});
						
		}
		if(img.complete){ // 如果图片已经存在于浏览器缓存，直接调用回调函数
			img.callback();
		}
		else
		{
			img.onload = function(){ //图片下载完毕时异步调用callback函数。
				img.callback();
			};
		}
	},
	/**
	* 上传文件
	**/
	upload:function(params){
		if($("#upload-css").length==0)
		{
			var css="<style id='upload-css'>";
			css+="</style>";
			$(css).appendTo("head");
		}
		if(!params || !params.uploadUrl)
			return $.tips("未指定上传文件的路径");
		if( !params.callback)
			return $.tips("未指定上传文件回调函数[callback]");	
		var strDescribe="";
		if(params.describe)
			strDescribe="<br/><br/>描述：<input type=\"text\" maxlength=\"24\" size=\"24\" id=\"imgDescribe\" name=\"imgDescribe\">";
		var dlgHtml="<form action=\""+params.uploadUrl+"\" id=\"uploadForm\" name=\"uploadForm\" method=\"post\" enctype=\"multipart/form-data\" target=\"uploadIframe\" style=\"width:420px; height:60px; margin:0px; padding:20px 20px;\"><iframe name=\"uploadIframe\" id=\"uploadIframe\" style=\"display:none;\"></iframe>文件：<input type=\"file\" id=\"imgFile\" name=\"imgFile\" style=\"width:250px;\" />"+strDescribe+"</form>";		
		$(dlgHtml).dialog({
			title:"上传文件",
			modal: true,			
			buttons: {
				"确定":function(){
					var pThis=this;
					$("#uploadIframe").load(function(){
						var jsonString=$("#uploadIframe").contents().find("body").html();						
						var json=$.parseJSON(jsonString);
						if(!json)
							return;
						if(json.error==1)
							return $.tips(json.message);
						
						if($("#imgDescribe").get(0))
							params.callback(json.url+"#"+$("#imgDescribe").val());
						else
							params.callback(json.url);
						$(pThis).dialog("close");
				    });
					var fileName=$.trim($("#imgFile").val());
					if(fileName=="")
						return $.tips("请选择上传的文件");
					var fileTypes=[];
					fileTypes["img"]=/^gif|jpg|jpeg|png|bmp|swf$/g;					
					var fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();	
					if(params.type && params.type == "img" ){//图片类型
						if(!fileTypes["img"].test(fileExt))
							return $.tips("文件格式不正确");
					}
					$("#uploadForm").submit();
				},
				"取消": function() {
					$(this).dialog( "close" );
				}
			}
		});
	},
	/**
	* 显示一个time的提示框
	**/
	tips:function(content,time){
		if(!document.body)
		{
			return alert(content);
		}
		if($("#tips-css").length==0)
		{
			var css="<style id='tips-css'>";
			css+=".lazy3q-tips{width:250px;position:absolute;padding:8px;line-height:20px;display:none;border-width:3px;}";
			css+=".lazy3q-tips .ui-icon-close{float:right;cursor:pointer;}";
			css+=".lazy3q-tips-content{clear:both;}";
			css+="</style>";
			$(css).appendTo("head");
		}		
		var div=$("<div class='ui-state-error lazy3q-tips'><span class='lazy3q-tips-content'></span></div>");
		var closer=$("<span class='ui-icon ui-icon-close'></span>");
		closer.prependTo(div);
		closer.click(function(){
			div.remove();
		});
		div.find(".lazy3q-tips-content").html(content);
		div.appendTo("body");		
		div.css("left",(($(window).width())/2-(parseInt(div.width())/2))+"px");	
		div.css("top",(($(window).height())/2-(parseInt(div.height())/2)+$(document).scrollTop())+"px");
		div.fadeIn("fast");
		setTimeout(function(){
			if(!div.mousein)
			{
				div.fadeOut(1000,function(){
					$(this).remove();							
				});	
			}	
			div.mouseout(function(){
				div.stop();
				div.fadeOut(1000,function(){
					$(this).remove();							
				});
			});
		},time?time:1000);
		div.mouseout(function(){
			div.mousein=false;
		});
		div.mouseover(function(){
			div.mousein=true;
			div.stop();
			div.fadeTo("fast",1);
		});		
		div.css("z-index",$.zindex());
	}	
	/**
	* 取最大的zIndex
	**/
	,zindex:function(){
		if(!window.zindex)
			window.zindex=0xaaaa;
		return window.zindex++;		
	}
	/**
	* 弹出对话框
	**/
	,dialog:function(param)
	{		
		var object=$("<table cellpadding='5' cellspacing='5'><tr><td></td></tr></table>");
		if(param)
			object.find("td").html(param.html);
		return object.dialog(param);
	},/**
	获取当前日期时间星期
	格式
	YYYY/yyyy/YY/yy 表示年份   
	MM/M 月份   
	W/w 星期   
	dd/DD/d/D 日期   
	hh/HH/h/H 时间   
	mm/m 分钟   
	ss/SS/s/S 秒
	**/
    formatDate: function(strFormat,date) {
		var dDate=date?date:new Date();
		var str = strFormat;    
		var Week = ['日','一','二','三','四','五','六'];   
	   
		str=str.replace(/yyyy|YYYY/,dDate.getFullYear());    
		str=str.replace(/yy|YY/,(dDate.getYear() % 100)>9?(dDate.getYear() % 100).toString():'0' + (dDate.getYear() % 100));    
	   
		str=str.replace(/MM/,dDate.getMonth()>8?(dDate.getMonth()+1):'0' + (dDate.getMonth()+1));    
		str=str.replace(/M/g,dDate.getMonth()+1);    
	   
		str=str.replace(/w|W/g,Week[dDate.getDay()]);    
	   
		str=str.replace(/dd|DD/,dDate.getDate()>9?dDate.getDate().toString():'0' + dDate.getDate());    
		str=str.replace(/d|D/g,dDate.getDate());    
	   
		str=str.replace(/hh|HH/,dDate.getHours()>9?dDate.getHours().toString():'0' + dDate.getHours());    
		str=str.replace(/h|H/g,dDate.getHours());    
		str=str.replace(/mm/,dDate.getMinutes()>9?dDate.getMinutes().toString():'0' + dDate.getMinutes());    
		str=str.replace(/m/g,dDate.getMinutes());    
	   
		str=str.replace(/ss|SS/,dDate.getSeconds()>9?dDate.getSeconds().toString():'0' + dDate.getSeconds());    
		str=str.replace(/s|S/g,dDate.getSeconds());    
	   
		return str;
	},
	dateFormat:function(string,format){//将字符串转换成日期时间，有默认格式
		if(format == null) format = 'yyyy-MM-dd hh:mm:ss';
		var compare = {'y+' : 'y','M+' : 'M','d+' : 'd','h+' : 'h','m+' : 'm','s+' : 's'};
		var result = {'y' : '','M' : '','d' : '','h' : '00','m' : '00','s' : '00'};
		var tmp = format;
		for (var k in compare) {		
			if (new RegExp('(' + k + ')').test(format))
				 result[compare[k]] = string.substring(tmp.indexOf(RegExp.$1), tmp.indexOf(RegExp.$1) +RegExp.$1.length);
		}
		return new Date(result['y'], result['M'] - 1, result['d'], result['h'], result['m'], result['s']);
	},
	cookie:function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			var path = options.path ? '; path=' + options.path : '';
			var domain = options.domain ? '; domain=' + options.domain : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	},
	/*
	* 微调颜色
	*/
	tinyColor:function(color,ratio){
		//把数字转成2位16进制
		var f=function(i){
			if(i>255)
				i=255;
			if(i<0)
				i=0;
			var c=i.toString(16);
			return c.length==1?("0"+c):c;
		};
		if(color.indexOf("#")==0){
			color=(color.charAt(0)=="#") ? color.substring(1,7) : color;
			var r=parseInt(color.substring(0,2),16);
			var g=parseInt(color.substring(2,4),16);
			var b=parseInt(color.substring(4,6),16);
			r=r>128?(r-ratio):(r+ratio);
			g=g>128?(g-ratio):(g+ratio);
			b=b>128?(b-ratio):(b+ratio);			
			return "#"+f(r)+f(g)+f(b);
		}else if(color.indexOf("rgb")==0){
			var ds = color.split(/\D+/);
			var r=parseInt(ds[1]);
			var g=parseInt(ds[2]);
			var b=parseInt(ds[3]);
			r=r>128?(r-ratio):(r+ratio);
			g=g>128?(g-ratio):(g+ratio);
			b=b>128?(b-ratio):(b+ratio);
			return "#"+f(r)+f(g)+f(b);
		}
	}
})

$(function() {	
		   
	$(".common-button").button();
	$(".common-button").css("height","30px");
	$(".common-button").css("font-size","12px");	
	
	if($(".common-table thead") && $(".common-table thead").get(0))
	{
		$( ".common-table thead td" ).resizable({ disabled: false , minHeight:18, maxHeight:18 });
	}	
		   
	if($(".common-table tbody") && $(".common-table tbody").get(0))
	{
		$(".common-table tbody td:empty").html("&nbsp;");
		var oddColor=$(".common-table").css("background-color");
		var evenColor=$.tinyColor(oddColor,10);
		var borderColor=$.tinyColor(oddColor,30);
		var focusColor=$.tinyColor(oddColor,5);
		var focusBorderColor=$.tinyColor(oddColor,60);
		
		$(".common-table tbody").css("background-color",evenColor);	
		$(".common-table").css("background-color",borderColor);
		$(".common-table").css("background-image","none");
		$(".common-table").css("border","0px");
		
		if($("#table-even-td-css").length==0)
		{
			var css="<style id='table-even-td-css'>";
			css+=".common-table tbody tr td{border-style:solid;border-width:1px 0 1px 0;}";
			css+=".common-table .odd td{background-color:"+oddColor+";border-color:"+oddColor+";}";
			css+=".common-table .even td{background-color:"+evenColor+";border-color:"+evenColor+";}";
			css+=".common-table .focus td{background-color:"+focusColor+";border-color:"+focusBorderColor+";}";
			css+="</style>";
			$(css).appendTo("head");
		}
		
		$(".common-table tbody tr:even").addClass("even");
		$(".common-table tbody tr:even").data("even",true);
		
		$(".common-table tbody tr:odd").addClass("odd");
		$(".common-table tbody tr:odd").data("odd",true);
		
		$(".common-table tbody tr").mouseenter(
			function(){
				$(this).addClass("focus");
				$(this).removeClass("even");
				$(this).removeClass("odd");
		});
		$(".common-table tbody tr").mouseleave(
			function(){
				$(this).removeClass("focus");
				if($(this).data("even")==true)
					$(this).addClass("even");
				if($(this).data("odd")==true)
					$(this).addClass("odd");
		})
	
	}
	
});

$(function(){
	/*查询页列表中自动显示到关联查询*/
	$(".query-flag").parent().mouseover(function(){												 
			if($("#query-flag-css").length==0)
			{
				var css="<style id='query-flag-css'>";
				css+="#query-flag-tips{position:absolute;padding:3px;}";
				css+="#query-flag-tips .ui-icon{float:left;}";
				css+="</style>";
				$(css).appendTo("head");
				window.queryFlagTips=$("<div id='query-flag-tips' class='ui-widget-content'><span class='ui-icon ui-icon-search'></span><a href='#'></a></div>");
				window.queryFlagTips.appendTo("body");
				window.queryFlagTips.css("z-index",$.zindex());
				window.queryFlagTips.mouseleave(function(){
					$(this).hide();
				});
				window.queryFlagTips.mouseover(function(){
					if(window.queryFlagTime)
						clearInterval(window.queryFlagTime);
					window.queryFlagTime=null;
				});
			}
			window.queryFlagTips.show();			
			var qf=$(this).find(".query-flag");			
			window.queryFlagTips.find("a").attr("href","?"+qf.attr("name")+"="+qf.attr("value"));
			window.queryFlagTips.find("a").html(qf.attr("value"));
			var offset=$(this).offset();
			window.queryFlagTips.css("left",offset.left);	
			window.queryFlagTips.css("top",offset.top+$(this).height());
			if(window.queryFlagTime)
						clearInterval(window.queryFlagTime);
			window.queryFlagTime=null;
			window.queryFlagTime=setTimeout(function(){
				window.queryFlagTips.hide();
			},1000);
	});
	

	if($("#query-relation-css").length==0)
	{
		var css="<style id='query-relation-css'>";
		css+=".ui-autocomplete .ui-menu-item{white-space:nowrap;}";
		css+="</style>";
		$(css).appendTo("head");
	}

	$(".query-relation").one("focus",function(){
		$(this).relation();
	});

})

