var ua = navigator.userAgent.toLowerCase();
var isStrict = document.compatMode == "CSS1Compat",
	isOpera = ua.indexOf("opera") > -1,
	isSafari = (/webkit|khtml/).test(ua),
	isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
	isIE = !isOpera && ua.indexOf("msie") > -1,
	isIE8 = isIE && ua.indexOf("msie 8") > -1,
	isIE7 = isIE && ua.indexOf("msie 7") > -1,
	isIE6 = isIE && !isIE8 && !isIE7 && ua.indexOf("msie 6") > -1,
	isGecko = !isSafari && ua.indexOf("gecko") > -1,
	isGecko3 = !isSafari && ua.indexOf("rv:1.9") > -1;
function getXY(el)
{
	var p, pe, b, scroll, bd = (document.body || document.documentElement);
	el = $(el);

	if(el == bd){
		return [0, 0];
	}

	if (el.getBoundingClientRect) {
		b = el.getBoundingClientRect();
		return [b.left + getScrollLeft()- document.documentElement.clientLeft, b.top + getScrollTop() - document.documentElement.clientTop];
	}
	
	var x = 0, y = 0;

	p = el;

	var hasAbsolute = el.style.position == "absolute";

	while (p) {
		x += p.offsetLeft;
		y += p.offsetTop;

		if (!hasAbsolute && el.style.position == "absolute") {
			hasAbsolute = true;
		}

		if (isGecko) {
			pe = p;

			var bt = parseInt(pe.style.borderTopWidth, 10) || 0;
			var bl = parseInt(pe.style.borderLeftWidth, 10) || 0;

			x += bl;
			y += bt;

			if (p != el && pe.style.overflow != 'visible') {
				x += bl;
				y += bt;
			}
		}
		p = p.offsetParent;
	}

	if (isSafari && hasAbsolute) {
		x -= bd.offsetLeft;
		y -= bd.offsetTop;
	}

	if (isGecko && !hasAbsolute) {
		var dbd =bd;
		x += parseInt(dbd.style.borderLeftWidth, 10) || 0;
		y += parseInt(dbd.style.borderTopWidth, 10) || 0;
	}

	p = el.parentNode;
	while (p && p != bd) {
		if (!isOpera || (p.tagName != 'TR' && p.style.display != "inline")) {
			x -= p.scrollLeft;
			y -= p.scrollTop;
		}
		p = p.parentNode;
	}
	return [x, y];
}
function getEvent(evnt)
{
	return evnt||window.event;
}
function getEventSrc(evnt)
{
	evnt=getEvent(evnt);
	return evnt.srcElement||evnt.target||document;
}
function getScrollLeft()
{
	return document.documentElement.scrollLeft || document.body.scrollLeft;
}
function getScrollTop()
{
	return document.documentElement.scrollTop || document.body.scrollTop;
}
function getScrollWidth()
{
	return document.documentElement.scrollWidth || document.body.scrollWidth;
}
function getScrollHeight()
{
	return document.documentElement.scrollHeight || document.body.scrollHeight;
}
function getClientWidth()
{
	return document.documentElement.clientWidth || document.body.clientWidth;
}
function getClientHeight()
{
	return document.documentElement.clientHeight || document.body.clientHeight;
}
function inArray(el,arr)
{
	for(var i=0;i<arr.length;i++)
	{
		if(arr[i]===el)
		{
			return i;
		}
	}
	return -1;
}
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}
function $(s)
{
	if(typeof(s)=="string")
	{
		/*
		var _class=s.match(/^\.(\S+)$/);
		var _id=s.match(/^#(\S+)$/);
		var es=document.getElementsByTagName('*');
		var result=[],index=0;
		if(_class)
		{
			var className=_class[1];
			for(var i=0;i<es.length;i++)
			{
				if(es[i].className==className)
				{
					result[index++]=es[i];
				}
			}
			return result;
		}
		else if(_id)
		{
			var id=_id[1];
			for(var i=0;i<es.length;i++)
			{
				if(es[i].id==id)
				{
					result[index++]=es[i];
				}
			}
			return result;
		}
		*/
		return document.getElementById(s);
	}
	else if(typeof(s)=="object")
	{
		return s;
	}
	else
	{
		return document;
	}
}
function setStyle(elem,style)
{
	for(var key in style)
	{
		elem.style[key]=style[key];
	}
}
function show(id)
{
	$(id).style.display="block";
}
function hide(id)
{
	$(id).style.display="none";
}
function showTip(evnt,id)
{
	evnt=getEvent(evnt);
	show(id);
	var ofstX=getScrollLeft();
	var ofstY=getScrollTop();
	$(id).style.left=evnt.clientX-$(id).offsetWidth/2+ofstX+2+'px';
	$(id).style.top=evnt.clientY+ofstY+20+'px';
}
function hideTip(evnt,id)
{
	hide(id);
}
function hasClass(el,className)
{
	el=$(el);
	if(!el.className)
	{
		return false;
	}
	return (inArray(className,el.className.split(/\s+/))>-1);
}
function addClass(el,className)
{
	el=$(el);
	if(!hasClass(el,className))
	{
		el.className+=(el.className?' ':'')+className;
	}
}
function removeClass(el,className)
{
	el=$(el);
	if(hasClass(el,className))
	{
		el.className=trim(el.className.replace(className,''));
	}
}
function changeClass(el,className)
{
	$(el).className=className;
}
var scrollTimer=null;
function initScroll()
{
	scrollTimer=setInterval("scrollWindow()",50);
}
function clearScroll()
{
	clearInterval(scrollTimer);
}
function scrollWindow()
{
	var curPos=getScrollTop();
	window.scrollTo(0,++curPos);
	if(curPos != getScrollTop())
	{
		clearScroll();
	}
}
/*
document.ondblclick=initScroll;
document.onmousedown=clearScroll;
*/
function _addEvent(el,evnt,fun)
{
	try
	{
		if(window.attachEvent)
		{
			return el.attachEvent("on"+evnt,fun);
		}
		else if(window.addEventListener)
		{
			return el.addEventListener(evnt,fun,false);
		}
	}
	catch(e){}
}
function _removeEvent(el,evnt,fun)
{
	try
	{
		if(window.detachEvent)
		{
			return el.detachEvent('on'+evnt,fun);
		}
		else if(window.removeEventListener)
		{
			return el.removeEventListener(evnt,fun,false);
		}
	}
	catch(e){}
}
function setCookie(key,val,ttl,path,domain)
{
	var arr=[];
	arr.push(key+'='+escape(val));
	if(ttl)
	{
		var date=new Date();
		date.setTime(date.getTime()+ttl);
		arr.push('expires='+date.toGMTString());
	}
	if(path)
	{
		arr.push('path='+path);
	}
	if(domain && domain!='localhost')
	{
		arr.push('domain='+domain);
	}
	document.cookie=arr.join('; ')+';';
}
function getCookie(key)
{
	var arr=document.cookie.split("; ");
	for(var i=0;i<arr.length;i++)
	{
		var pair=arr[i].split("=");
		if(key==pair[0])
		{
			return unescape(pair[1]);
		}
	}
	return null;
}
function addFlash(movie,width,height,wmode,flashVars,ele)
{
	var allowScriptAccess="sameDomain";
	var classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	var codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0";
	var pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
	var type="application/x-shockwave-flash";
	var quality="high";
	var menu="false";
	var wmode=wmode?"transparent":"opaque";
	var str='';
	str+='<object classid="'+classid+'" codebase="'+codebase+'" width="'+width+'" height="'+height+'">';
	str+='<param name="allowScriptAccess" value="'+allowScriptAccess+'" />';
	str+='<param name="movie" value="'+movie+'" />';
	str+='<param name="quality" value="'+quality+'" />';
	str+='<param name="wmode" value="'+wmode+'" />';
	str+='<param name="menu" value="'+menu+'" />';
	str+='<param name="flashVars" value="'+flashVars+'" />';
	str+='<embed src="'+movie+'" allowScriptAccess="'+allowScriptAccess+' quality="'+quality+'" pluginspage="'+pluginspage+'" type="'+type+'" width="'+width+'" height="'+height+'" wmode="'+wmode+'" menu="'+menu+'" flashVars="'+flashVars+'"></embed>';
	str+='</object>';
	if(ele)
	{
		$(ele).innerHTML=str;
	}
	else
	{
		document.write(str);
	}
}
function ApplyFilters(id)
{
	var obj=$(id);
	obj.filters[0].apply();
	obj.filters[0].play();
}
function AddFavorite(url,title)
{
	if(window.external)
	{
		window.external.addFavorite(url,title);
	}
	else if(window.sidebar)
	{
		window.sidebar.addPanel(title,url,'');
	}
}
function Copy(str)
{
	if(window.clipboardData)
	{
		window.clipboardData.setData('Text',str);
		alert("复制成功，请贴粘发送！");
	}
}
function MaxWindow()
{
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth,screen.availHeight);
}
function CloseWindow(auto)
{
	if(typeof(auto)=='undefined')
	{
		window.close();
	}
	else
	{
		window.opener=null;
		window.open('','_self','');
		window.close();
	}
}
function FixPNG()
{
	var es = document.getElementsByTagName('*');
	var src;
	for(var i = 0; i < es.length; i++)
	{
		if(es[i].tagName=='IMG' && /\.png$/i.test(es[i].src))
		{
			src=es[i].src;
			es[i].style.width = es[i].offsetWidth;
			es[i].style.height = es[i].offsetHeight;
			es[i].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '",sizingMethod="scale")';
			es[i].src='/images/transparent.gif';
		}
		else if(/\.png/i.test(es[i].style.backgroundImage))
		{
			src=es[i].style.backgroundImage.match(/^url[("']+(.*\.png[^\)"']*)[\)"']+[^\)]*$/i);
			if(!src)
			{
				continue;
			}
			src=src[1];
			es[i].style.width = es[i].offsetWidth;
			es[i].style.height = es[i].offsetHeight;
			es[i].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '",sizingMethod="scale")';
			es[i].style.backgroundImage='url(/images/transparent.gif)';
		}
	}
}
if(isIE6){_addEvent(window,'load',FixPNG)};
function LoadScript(src)
{
	var el=document.createElement('script');
	el.type='text/javascript';
	el.src=src;
	document.getElementsByTagName('head')[0].appendChild(el);
}
function SetInnerHTML(el,html)
{
	el=$(el);
	html=html.replace(/<!--[\s\S]*?-->/g,'');
	var hasScript=/<script[^>]*>([\s\S]+?)?<\/script>/i.test(html);
	if(hasScript)
	{
		if(isIE && false)
		{
			html='<div style="display:none">IE hack</div>'+html;
			html=html.replace(/<script([^>]*)>/gi,'<script$1 defer="defer">');
			el.innerHTML=html;
			el.removeChild(el.firstChild);
		}
		else if(isGecko)
		{
			var obj=document.createElement(el.tagName);
			obj.id=el.id;
			obj.className=el.className;
			obj.innerHTML=html;
			el.parentNode.replaceChild(obj,el);
		}
		else
		{
			while(true)
			{
				var script=html.match(/<script[^>]*>([\s\S]+?)<\/script>/i);
				if(!script)
				{
					break;
				}
				window.eval(script[1]);
				html=html.replace(/<script[^>]*>([\s\S]+?)<\/script>/i,'');
			}
			el.innerHTML=html;
		}
	}
	else
	{
		el.innerHTML=html;
	}
}
function GetRequestString(frm)
{
	frm=$(frm);
	var e;
	var arr=[];
	for(var i=0;i<frm.length;++i)
	{
		e=frm[i];
		if(!e.name || e.disabled)
		{
			continue;
		}
		if(e.type=='select-one')
		{
			arr.push(encodeURIComponent(e.name)+'='+encodeURIComponent(e.options[e.selectedIndex].value));
		}
		else if(e.type=='select-multiple')
		{
			for(var j=0;j<e.length;++j)
			{
				if(e.options[j].selected)
				{
					arr.push(encodeURIComponent(e.name)+'='+encodeURIComponent(e.options[j].value));
				}
			}
		}
		else if(e.type=='checkbox' || e.type=='radio')
		{
			if(e.checked)
			{
				arr.push(encodeURIComponent(e.name)+'='+encodeURIComponent(e.value));
			}
		}
		else if(typeof(e.value)!='undefined')
		{
			arr.push(encodeURIComponent(e.name)+'='+encodeURIComponent(e.value));
		}
	}
	return arr.join('&');
}
function Ajax(id,url,callback,method,data,async,frm)
{
	var xhr=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	if(!xhr)
	{
		return false;
	}
	xhr.onreadystatechange=function()
	{
		if(xhr.readyState==4)
		{
			hide('LoadingPanel');
			if(xhr.status==200)
			{
				if(typeof(callback)=='function')
				{
					callback(id,xhr,frm);
				}
				else
				{
					/*deal with responseText when includes script*/
					SetInnerHTML(id,xhr.responseText);
				}
			}
		}
		else if(xhr.readyState==1)
		{
			var obj=$('LoadingPanel');
			if(!obj)
			{
				var obj=document.createElement('DIV');
				obj.id='LoadingPanel';
				obj.innerHTML='<img src="/images/loading.gif" /><br />数据加载中...';
				document.body.appendChild(obj);
				if(!isIE6)
				{
					obj.backgroundImage='/images/loading_panel_bg.png';
				}
			}
			var ofstY=getScrollTop();
			var ofstX=getScrollLeft();
			show('LoadingPanel');
			obj.style.left=(document.documentElement.clientWidth-obj.offsetWidth)/2+ofstX+"px";
			obj.style.top=(document.documentElement.clientHeight-obj.offsetHeight)/2+ofstY+"px";
		}
	}
	method=method=='POST'?'POST':'GET';
	async=async==false?false:true;
	xhr.open(method,url,async);
	data=data?data:null;
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xhr.send(data);
}
function AjaxSubmitCallback(id,xhr,frm)
{
	if(/^\{/.test(xhr.responseText))
	{
		try
		{
			eval('var result='+xhr.responseText);
		}
		catch(e)
		{
			alert(xhr.responseText);
			return;
		}
	}
	else
	{
		SetInnerHTML(id,xhr.responseText);
		return;
	}
	if(result.url)
	{
		window.location.replace(result.url);
		return;
	}
	if(result.msg)
	{
		if(result.id)
		{
			Dlg.Show({info:result.msg,focusEle:$(result.id)});
		}
		else
		{
			Dlg.Show({info:result.msg});
		}
	}
	if(result.reset)
	{
		$(frm).reset();
	}
	if(result.refresh)
	{
		Ajax(id,result.refresh);
	}
	if(result.callback)
	{
		eval(result.callback+'()');
	}
}
function DoAjaxSubmit(frm,id,callback)
{
	frm=$(frm);
	var data=GetRequestString(frm);
	var action=frm.action;
	var method=frm.method;
	if(method.toUpperCase()=='GET')
	{
		if(action=='' || action.indexOf('?')==-1)
		{
			action+='?';
		}
		else if(!/\?$|&$/.test(action))
		{
			action+='&';
		}
		action+=data;
		data=null;
	}
	else
	{
		method='POST';
	}
	if(typeof(callback)!='function')
	{
		callback=AjaxSubmitCallback;
	}
	Ajax(id,action,callback,method,data,true,frm);
	return false;
}
var Confirm=(function(){
	var _id='ConfirmPanel';
	var _callback;
	var _isCallback;
	var _msg;
	var inner;
	return inner={
		Show:function(el,isCallback,msg)
		{
			el=$(el);
			_callback=el.href;
			_isCallback=isCallback;
			_msg=msg?msg:'您确定要删除吗？';
			var obj=$(_id);
			if(!obj)
			{
				obj=document.createElement('DIV');
				obj.id=_id;
				document.body.appendChild(obj);
			}
			obj.innerHTML='<div class="main"><div class="msg">'+_msg+'</div><a href="javascript:Confirm.Ok()">确定</a><a href="javascript:Confirm.Cancel()">取消</a></div>';
			
			var left=getXY(el)[0];
			var top=getXY(el)[1];
			show(_id);
			left+=el.offsetWidth/2-obj.offsetWidth/2;
			top-=obj.offsetHeight;
			left=left<0?4:left;
			top=top<0?4:top;
			
			obj.style.left=left+'px';
			obj.style.top=top+'px';
			_addEvent(window.document,'keyup',inner.KeyUp);
			return false;		
		},
		Hide:function()
		{
			_removeEvent(window.document,'keyup',inner.KeyUp);
			hide(_id);
		},
		Ok:function()
		{
			inner.Hide();
			if(_isCallback)
			{
				eval(_callback);
			}
			else
			{
				window.location=_callback;
			}
		},
		Cancel:function()
		{
			inner.Hide();
		},
		KeyUp:function(evnt)
		{
			evnt=getEvent(evnt);
			if(evnt.keyCode==27)
			{
				inner.Cancel();
			}
		}
	}
})();
var MsgBox=(function(){
	var _id='MsgBoxPanel';
	var inner;
	return inner={
		Show:function(msg,ms)
		{
			var obj=$(_id);
			if(!obj)
			{
				var obj=document.createElement('DIV');
				obj.id=_id;
				document.body.appendChild(obj);
			}
			obj.innerHTML=msg;
			var ofstY=getScrollTop();
			var ofstX=getScrollLeft();
			show(_id);
			obj.style.left=(document.documentElement.clientWidth-obj.offsetWidth)/2+ofstX+"px";
			obj.style.top=(document.documentElement.clientHeight-obj.offsetHeight)/2+ofstY+"px";
			if(ms)
			{
				setTimeout(MsgBox.Hide,ms);
			}
		},
		Hide:function()
		{
			hide(_id);
		}
	}
})();
var ChooseBox=(function(){
	var _id='ChooseBox';
	var _hasShow;
	var inner;
	return inner={
		Show:function(el,html,width)
		{
			el=$(el);
			var obj=$(_id);
			if(!obj)
			{
				obj=document.createElement('DIV');
				obj.id=_id;
				obj.onclick=function(evnt){var evnt=getEvent(evnt);if(evnt.stopPropagation){evnt.stopPropagation();}else{evnt.cancelBubble=true;}};
				document.body.appendChild(obj);
			}
			obj.style.width=(width+20)+'px';
			obj.innerHTML='<div id="ChooseBoxContent"><ul>'+html+'<div class="clear"></div></ul></div';
			$('ChooseBoxContent').style.width=width+'px';
			Drag.Apply(obj,obj);
			_hasShow=false;
			show(_id);
			var left=getXY(el)[0]+el.offsetWidth/2-$(_id).offsetWidth/2;
			var top=getXY(el)[1]+el.offsetHeight;
			obj.style.left=left+'px';
			obj.style.top=top+'px';
			_addEvent(window.document,'keyup',inner.KeyUp);
			_addEvent(window.document,'mousemove',inner.SetFlag);
			_addEvent(window.document,'click',inner.HideByCondition);
		},
		KeyUp:function()
		{
			inner.Hide();
		},
		SetFlag:function(flag)
		{
			_hasShow=true;
		},
		HideByCondition:function(evnt)
		{
			if(!_hasShow)
			{
				return;
			}
			inner.Hide();
		},
		Hide:function()
		{
			_removeEvent(window.document,'keyup',inner.KeyUp);
			_removeEvent(window.document,'mousemove',inner.SetFlag);
			_removeEvent(window.document,'click',inner.HideByCondition);
			hide(_id);
			_hasShow=false;
		}
	}
})();
var Cover=(function(){
	var _id='Cover';
	var inner;
	return inner={
		Show:function()
		{
			var c=$(_id);
			if(!c)
			{
				c=document.createElement('DIV');
				c.id=_id;
				document.body.appendChild(c);
				c.oncontextmenu=function(){return false;};
			}
			show(c);
			c.style.left=0;
			c.style.top=0;
			c.style.width=getScrollWidth()+"px";
			c.style.height=Math.max(getScrollHeight(),document.documentElement.clientHeight)+"px";
		},
		Refresh:function()
		{
			inner.Show();
		},
		Hide:function()
		{
			if($(_id))
			{
				hide(_id);
			}
		}
	}
})();
var Drag=(function(){
	var _temp={};
	var inner;
	return inner={
		Apply:function(dragHead,dragBody)
		{
			dragHead=$(dragHead);
			dragHead.style.cursor='move';
			dragHead.parent=$(dragBody);
			dragHead.parent.style.position='absolute';
			dragHead.onmousedown=Drag.Start;
		},
		Start:function(evnt)
		{
			var dragHead=_temp=this;
			var src=getEventSrc(evnt);
			if(src.id && dragHead.id && src.id!=dragHead.id)
			{
				return;
			}
			evnt=getEvent(evnt);
			dragHead.ofstX=evnt.clientX-dragHead.parent.offsetLeft+getScrollLeft();
			dragHead.ofstY=evnt.clientY-dragHead.parent.offsetTop+getScrollTop();
			_addEvent(window.document,'mousemove',Drag.Move);
			_addEvent(window.document,'mouseup',Drag.End);
		},
		Move:function(evnt)
		{
			dragHead=_temp;
			evnt=getEvent(evnt);
			var left=evnt.clientX-dragHead.ofstX+getScrollLeft();
			var top=evnt.clientY-dragHead.ofstY+getScrollTop();
			dragHead.parent.style.left=left+'px';
			dragHead.parent.style.top=top+'px';
		},
		End:function()
		{
			_removeEvent(window.document,'mousemove',Drag.Move);
			_removeEvent(window.document,'mouseup',Drag.End);
		}
	}
})();
var Dlg={
	Create:function()
	{
		if($("Dialog")) return;
		
		var h=document.createElement("DIV");
		h.id="Dashed";
		var d=document.createElement("DIV");
		d.id="Dialog";		
		d.innerHTML='<div id="DlgHeader">'+
					'<div id="DlgTitle" alt="移动" title="移动">&nbsp;</div>'+
					'<div id="DlgClose" alt="关闭" title="关闭" onclick="Dlg.Hide()">&nbsp;</div>'+
					'</div>'+
					'<div id="DlgBody">'+
					'<div id="DlgInfo">&nbsp;</div>'+
					'<div id="DlgIframe"><iframe id="Frame" name="Frame" width="100%" height="0" frameborder="0" scrolling="no" src="about:blank"></iframe></div>'+
					'<div id="DlgButton"><button id="OK" onclick="Dlg.Hide()" title="确定">确定</button></div>'+
					'</div>'+
					'<div id="DlgFooter"><div id="DlgResize" title="点击调整大小"></div></div>';
		
		Dlg.h=h;
		Dlg.d=d;

		document.body.appendChild(d);
		document.body.appendChild(h);

		_addEvent(window,"resize",Dlg.SetCenter);
		_addEvent(window,"scroll",Dlg.Scroll);
		_addEvent($("DlgTitle"),"mousedown",Dlg.MoveInit);
		_addEvent($("DlgResize"),"mousedown",Dlg.se_ResizeInit);
		_addEvent(window.document,"keyup",Dlg.KeyUp);
		d.oncontextmenu=function(){return false;};
	},
	SetCenter:function()
	{
		var d	=Dlg.d;
		var st	=getScrollTop();
		var sl =getScrollLeft();
		Dlg.ofstHS=st;
		Dlg.ofstVS=sl;
		var left=(document.documentElement.clientWidth-d.offsetWidth)/2+sl;
		var top	=(document.documentElement.clientHeight-d.offsetHeight)/2+st;
		d.style.left	=left+"px";
		d.style.top		=top+"px";
	},
	Scroll:function()
	{
		var d=Dlg.d;
		var st=getScrollTop();
		var sl=getScrollLeft();
		if(sl!=Dlg.ofstVS)
		{
			d.style.left=(parseInt(d.style.left,10)+sl-Dlg.ofstVS)+"px";
			Dlg.ofstVS=sl;
		}
		if(st!=Dlg.ofstHS)
		{
			d.style.top=(parseInt(d.style.top,10)+st-Dlg.ofstHS)+"px";
			Dlg.ofstHS=st;
		}
	},
	se_ResizeInit:function(evnt)
	{
		var h=Dlg.h;
		var d=Dlg.d;
		show(h);
		h.style.cursor="se-resize";
		h.style.width	=(parseInt(d.offsetWidth,10)+2)+"px";
		h.style.height	=(parseInt(d.offsetHeight,10)+2)+"px";
		h.style.left	=(parseInt(d.offsetLeft,10)-2)+"px";
		h.style.top		=(parseInt(d.offsetTop,10)-2)+"px";
		evnt=getEvent(evnt);
		Dlg.ofstX=evnt.clientX-parseInt(h.style.width,10);
		Dlg.ofstY=evnt.clientY-parseInt(h.style.height,10);
		_addEvent(window.document,"mousemove",Dlg.se_ResizeStart);
		_addEvent(window.document,"mouseup",Dlg.se_ResizeEnd);
	},
	se_ResizeStart:function(evnt)
	{
		var h=Dlg.h;
		evnt=getEvent(evnt);
		try
		{
			h.style.width=evnt.clientX-Dlg.ofstX+'px';
			h.style.height=evnt.clientY-Dlg.ofstY+'px';
		}
		catch(e){}
	},
	se_ResizeEnd:function(evnt)
	{
		Cover.Refresh();
		var h=Dlg.h;
		var d=Dlg.d;
		/*set width of Dialog*/
		var dw=parseInt(h.style.width,10)-4;
		if(dw<200) dw=200;
		d.style.width=dw+"px";
		/*set height of DlgInfor or|and Frame*/
		i=$("DlgInfo");
		f=$("DlgIframe");
		var v=0;
		if(i.style.display.toLowerCase().indexOf("block")!=-1)
		{
			v++;
		}
		if(f.style.display.toLowerCase().indexOf("block")!=-1)
		{
			v++;
		}
		var incH=parseInt(h.offsetHeight)-parseInt(d.offsetHeight,10)-4;
		if(v>0 && i.style.display.toLowerCase().indexOf("block")!=-1)
		{
			var ih=parseInt(i.offsetHeight,10)+incH/v;
			if(ih<0)
			{
				ih=0;
			}
			i.style.height=ih+"px";
		}
		if(v>0 && f.style.display.toLowerCase().indexOf("block")!=-1)
		{
			var fh=parseInt(f.offsetHeight,10)+incH/v;
			if(fh<40)
			{
				fh=40;
			}
			$("Frame").style.height=fh+"px";
		}
		$("DlgTitle").style.width=(parseInt($("Dialog").style.width,10)-26)+"px";
		hide(h);
		_removeEvent(window.document,"mousemove",Dlg.se_ResizeStart);
		_removeEvent(window.document,"mouseup",Dlg.se_ResizeEnd);
	},
	MoveInit:function(evnt)
	{
		var h=Dlg.h;
		var d=Dlg.d;
		show(h);
		h.style.cursor="move";
		h.style.width	=(parseInt(d.offsetWidth,10)+2)+"px";
		h.style.height	=(parseInt(d.offsetHeight,10)+2)+"px";
		h.style.left	=(parseInt(d.offsetLeft,10)-2)+"px";
		h.style.top		=(parseInt(d.offsetTop,10)-2)+"px";
		evnt=getEvent(evnt);
		Dlg.ofstX2=evnt.clientX-parseInt(h.style.left,10);
		Dlg.ofstY2=evnt.clientY-parseInt(h.style.top,10);
		_addEvent(window.document,"mousemove",Dlg.MoveStart);
		_addEvent(window.document,"mouseup",Dlg.MoveEnd);
	},
	MoveStart:function(evnt)
	{
		evnt=getEvent(evnt);
		var h=Dlg.h;
		var left=Math.min(Math.max(evnt.clientX-Dlg.ofstX2,getScrollLeft()),document.documentElement.clientWidth+getScrollLeft()-h.offsetWidth);
		var top=Math.min(Math.max(evnt.clientY-Dlg.ofstY2,getScrollTop()),document.documentElement.clientHeight+getScrollTop()-h.offsetHeight);
		h.style.left=left+"px";
		h.style.top=top+"px";
	},
	MoveEnd:function(evnt)
	{
		Cover.Refresh();
		var h=Dlg.h;
		var d=Dlg.d;
		hide(h);
//		var left=parseInt(d.style.left,10);
//		var top=parseInt(d.style.top,10);
//		var width=parseInt(d.clientWidth,10);
//		var height=parseInt(d.clientHeight,10);
//		var left2=parseInt(h.style.left,10)+2;
//		var top2=parseInt(h.style.top,10)+2;
//		Animate.Apply(d,left,top,width,height,left2,top2,width,height,80,50,12,5);
		d.style.left=(parseInt(h.style.left,10)+2)+"px";
		d.style.top=(parseInt(h.style.top,10)+2)+"px";
		_removeEvent(window.document,"mousemove",Dlg.MoveStart);
		_removeEvent(window.document,"mouseup",Dlg.MoveEnd);
	},
	KeyUp:function(evnt)
	{
		evnt=getEvent(evnt);
		var keycode=evnt.keyCode;
		if(keycode==27)
		{
			Dlg.Hide();
		}
	},
	Hide:function()
	{
		try
		{
			hide("Dashed");
			hide("Dialog");
			Cover.Hide();
			Dlg.focusEle.focus();
		}
		catch(e){}
	},
	Config:function(conf)
	{
		if(!conf) return;
		if(conf.title)
		{
			$("DlgTitle").innerHTML=conf.title;
		}
		else
		{
			$("DlgTitle").innerHTML="提示";
		}
		if(conf.url)
		{
			try
			{
				$("Frame").src=conf.url;
			}
			catch(e)
			{
				try
				{
					document.frames["Frame"].location=conf.url;
				}
				catch(e){}
			}
			var ch	= conf.height||40;
			$("Frame").style.height=ch+"px";
			show("DlgIframe");
		}
		else
		{
			hide("DlgIframe");
		}
		if(conf.info)
		{
			$("DlgInfo").innerHTML=conf.info;
			show("DlgInfo");
		}
		else
		{
			$("DlgInfo").innerHTML="";
			hide("DlgInfo");
		}
		if(conf.focusEle)
		{
			this.focusEle=$(conf.focusEle);
		}
		if(conf.align)
		{
			if(inArray(conf.align,Array('left','right','center','justify'))!=-1)
			{
				$("DlgInfo").style.textAlign=conf.align;
			}
		}
		if(conf.hideButton)
		{
			hide("DlgButton");
		}
		else
		{
			show("DlgButton");
		}
		if(conf.hideResize)
		{
			hide("DlgResize");
		}
		else
		{
			show("DlgResize");
		}
		if(conf.hideCover)
		{
			this.hideCover=true;
		}
		else
		{
			this.hideCover=false;
		}
		var cw	= conf.width||300;
		var d	= Dlg.d;
//		if(d.style.width)
//		{
//			cw=parseInt(d.style.width,10);
//		}
		d.style.width=cw+"px";
		var tw=cw-26;
		$("DlgTitle").style.width=tw+"px";
	},
	Show:function(conf)
	{
		this.Create();
		this.Config(conf);
		if(this.hideCover)
		{
			Cover.Hide();
		}
		else
		{
			Cover.Show();
		}
		show("Dialog");
		this.SetCenter();
		try
		{		
			$("OK").focus();
		}
		catch(e){}
	}
};
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Written by LXL 2008-05-01
//(c) 2008 LXL All Rights Reserved
//Version:1.1
//Usage:Dlg.Show({[title:string][,info:string][,url:string][,focusEle:id or object][,align:string][,width:number][,height:number][,hideButton:bool][,hideResize:bool][,hideCover]});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
var FloatImage=(function(){
	var _items=[];
	var _delta;
	var _delay;
	var inner;
	return inner={
		AddItem:function(el)
		{
			_items.push($(el));
		},
		Move:function()
		{
			for(var i=0;i<_items.length;i++)
			{
				var obj=_items[i];
				var offset=Math.ceil(((getClientHeight()-obj.offsetHeight)/2+getScrollTop()-obj.offsetTop)*_delta);
				if(offset!=0)
				{
					obj.style.top=obj.offsetTop+offset+"px";
				}
			}
		},
		Start:function(delay,delta)
		{
			_delay=delay || 25;
			_delta=delta || 0.1;
			setInterval('FloatImage.Move()',_delay);
		}
	}
})();
var Marquee=(function(){
	var _items=[];
	var _delay=25;
	var _step=1;
	var inner;
	return inner={
		AddItem:function(el,direction,width,height,maxCount,wait)
		{
			el=$(el);
			direction=direction.toUpperCase();
			el.style.overflow='hidden';			
			el.style.whiteSpace='nowrap';		
			var obj={};
			obj.scrollWidth=el.scrollWidth;
			obj.scrollHeight=el.scrollHeight;
			obj.marqueeWidth=width;
			obj.marqueeHeight=height;
			obj.object=el;
			obj.stopMarquee=false;
			obj.direction=direction;
			obj.maxCount=maxCount;
			obj.wait=wait?wait:1500;
			obj.count=0;
			_items.push(obj);
			var index=_items.length-1;
			el.onmouseover=function(){inner.Pause(index);};
			el.onmouseout=function(){inner.Continue(index);};
			el.innerHTML+=el.innerHTML;
			if(direction=='RIGHT')
			{
				el.scrollLeft=_items[index].scrollWidth;
			}
			if(direction=='DOWN')
			{
				el.scrollTop=_items[index].scrollHeight;
				/*IE下面需设置2次，才能得到正确的scrollTop*/
				el.scrollTop=_items[index].scrollHeight;
			}
		},
		Start:function()
		{
			setInterval('Marquee.Run()',_delay);
		},
		Run:function()
		{
			for(var i=0;i<_items.length;i++)
			{
				if(_items[i].maxCount && _items[i].wait && _items[i].count>=_items[i].maxCount)
				{
					_items[i].count=0;
					inner.Pause(i);
					setTimeout(function(){inner.Continue(i)},_items[i].wait);
					return;
				}
				inner.Marquee(_items[i]);
			}
		},
		Marquee:function(el)
		{
			if(el.stopMarquee)
			{
				return;
			}
			if(el.maxCount && el.wait)
			{
				el.count++;
			}
			if(el.direction=='LEFT')
			{
				el.preLeft=el.object.scrollLeft;
				el.object.scrollLeft+=_step;
				if(el.preLeft==el.object.scrollLeft)
				{
					el.object.scrollLeft=el.scrollWidth-el.marqueeWidth+_step;
				}
			}
			else if(el.direction=='RIGHT')
			{
				el.preLeft=el.object.scrollLeft;
				el.object.scrollLeft-=_step;
				if(el.preLeft==el.object.scrollLeft)
				{
					el.object.scrollLeft=el.scrollWidth-_step;
				}
			}
			else if(el.direction=='UP')
			{
				el.preTop=el.object.scrollTop;
				el.object.scrollTop+=_step;
				if(el.preTop==el.object.scrollTop)
				{
					el.object.scrollTop=el.scrollHeight-el.marqueeHeight+_step;
				}
			}
			else if(el.direction=='DOWN')
			{
				el.preTop=el.object.scrollTop;
				el.object.scrollTop-=_step;
				if(el.preTop==el.object.scrollTop)
				{
					el.object.scrollTop=el.scrollHeight-_step;
				}
			}
		},
		Pause:function(index)
		{
			_items[index].stopMarquee=true;
		},
		Continue:function(index)
		{
			_items[index].stopMarquee=false;
		}
	}
})();
function SetOpacity(el,value)
{
	el=$(el);
	el.style.filter='alpha(opacity='+value+')';
	el.style.opacity=value/100;
}
function SetPos(el,left,top)
{
	el=$(el);
	el.style.left=left+'px';
	el.style.top=top+'px';
}
function SetSize(el,width,height)
{
	el=$(el);
	el.style.width=width+'px';
	el.style.height=height+'px';
}
var Animate=(function(){
	var _item={};
	var inner;
	return inner={
		Apply:function(el,left1,top1,width1,height1,left2,top2,width2,height2,opacity1,opacity2,step,delay)
		{
			el=$(el);
			hide(el);
			el.style.position='absolute';
			el.style.left=left1+'px';
			el.style.top=top1+'px';
			el.style.width=width1+'px';
			el.style.height=height1+'px';
			_item.object=el;
			_item.left=left1;
			_item.top=top1;
			_item.width=width1;
			_item.height=height1;
			_item.opacity=opacity1;
			_item.step=step;
			_item.delay=delay;
			_item.leftInc=(left2-left1)/step;
			_item.topInc=(top2-top1)/step;
			_item.widthInc=(width2-width1)/step;
			_item.heightInc=(height2-height1)/step;
			_item.opacityInc=(opacity2-opacity1)/step;
			show(el);
			_item.timer=setInterval(function(){inner.Play();},delay);
		},
		Play:function()
		{
			_item.step--;
			if(_item.step<0)
			{
				inner.Stop();
				SetOpacity(_item.object,100);
				return;
			}
			SetPos(_item.object,_item.left+=_item.leftInc,_item.top+=_item.topInc);
			SetSize(_item.object,_item.width+=_item.widthInc,_item.height+=_item.heightInc);
			SetOpacity(_item.object,_item.opacity+=_item.opacityInc);
		},
		Stop:function()
		{
			clearTimeout(_item.timer);
		}
	}	
})();
var Calendar=(function(){
	var _el;
	var _y;
	var _m;
	var _d;
	var _s;
	var _yStart;
	var _yEnd;
	var inner;
	function AddPrefix(n)
	{
		return n<10?'0'+n:n;
	}
	return inner={
		Init:function(yStart,yEnd)
		{
			var obj=new Date();
			_y=obj.getFullYear();
			_m=obj.getMonth()+1;
			_d=obj.getDate();
			_yStart=1900;
			_yEnd=_y;
			if(_el && _el.value)
			{
				var m=_el.value.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/);
				if(m)
				{
					_y=m[1];
					_m=m[2];
					_d=m[3];
				}
			}
		},
		Show:function(el,yStart,yEnd)
		{
			_el=$(el);
			inner.Init(yStart,yEnd);
			if(!_s)
			{
				inner.Create();
			}
			ChooseBox.Show(_el,_s,226);
			inner.Update();
		},
		Create:function()
		{
			var w='日|一|二|三|四|五|六'.split('|');
			var s='';
			s+='<div id="Calendar">';
			s+='<div id="CalendarHeader"><button type="button" class="small" onclick="Calendar.IncMonth(-1)">＜</button><select id="CalendarYear" onchange="Calendar.ChangeYear(this.selectedIndex)">';
			for(var i=_yStart;i<=_yEnd;i++)
			{
				s+='<option value="'+i+'">'+i+'年</option>';
			}
			s+='</select><select id="CalendarMonth" onchange="Calendar.ChangeMonth(this.selectedIndex)">';
			for(var i=1;i<=12;i++)
			{
				s+='<option value="'+i+'">'+i+'月</option>';
			}
			s+='</select><button type="button" class="small" onclick="Calendar.IncMonth(1)">＞</button></div>';
			s+='<div id="CalendarBody">';
			s+='<table width="100%" border="0" cellpadding="0" cellspacing="2"><tr>';
			for(var i=0;i<w.length;i++)
			{
				s+='<th>'+w[i]+'</th>';
			}
			for(var i=0;i<6;i++)
			{
				s+='<tr>';
				for(var j=0;j<7;j++)
				{
					s+='<td></td>';
				}
				s+='</tr>';
			}
			s+='</tr></table>';
			s+='</div>';
			s+='<div id="CalendarFooter"><button type="button" onclick="Calendar.GoToday()">转到今日</button></div>';
			s+='</div>';
			_s=s;
		},
		Update:function()
		{
			var obj=new Date(_y,_m,0);
			var maxDate=obj.getDate();
			obj=new Date(_y,_m-1,0);
			var weekday=obj.getDay()+1;
			var preMaxDate=obj.getDate();
			obj=new Date();
			var curYear=obj.getFullYear();
			var curMonth=obj.getMonth()+1;
			var curDay=obj.getDate();
			var els=$('Calendar').getElementsByTagName('td');
			if(_y==_yStart && _m==1)
			{
				for(var i=0;i<weekday;i++)
				{
					els[i].innerHTML='';
					els[i].onclick=null;
				}
			}
			else
			{
				for(var i=0;i<weekday;i++)
				{
					els[i].className='grey';
					els[i].innerHTML=preMaxDate-weekday+i+1;
					els[i].onclick=function(){Calendar.IncMonthSetDay(-1,this.innerHTML);Calendar.SetDate();};
				}
			}
			for(var i=weekday;i<weekday+maxDate;i++)
			{
				if(i-weekday+1==curDay && _m==curMonth && _y==curYear)
				{
					els[i].className='today';
				}
				else if(i%7==0)
				{
					els[i].className='sun';
				}
				else if(i%7==6)
				{
					els[i].className='sat';
				}
				else
				{
					els[i].className='';
				}
				els[i].innerHTML=i-weekday+1;
				els[i].onclick=function(){Calendar.IncMonthSetDay(0,this.innerHTML);Calendar.SetDate();};
			}
			if(_y==_yEnd && _m==12)
			{
				for(var i=weekday+maxDate;i<els.length;i++)
				{
					els[i].innerHTML='';
					els[i].onclick=null;
				}
			}
			else
			{
				for(var i=weekday+maxDate;i<els.length;i++)
				{
					els[i].className='grey';
					els[i].innerHTML=i-weekday-maxDate+1;
					els[i].onclick=function(){Calendar.IncMonthSetDay(1,this.innerHTML);Calendar.SetDate();};
				}
			}
			$('CalendarYear').selectedIndex=_y-_yStart;
			$('CalendarMonth').selectedIndex=_m-1;
		},
		ChangeYear:function(yi)
		{
			_y=_yStart+yi
			inner.Update();
		},
		ChangeMonth:function(mi)
		{
			_m=1+mi;
			inner.Update();
		},
		IncMonth:function(mi)
		{
			if((_y==_yStart && _m==1 && mi==-1) || (_y==_yEnd && _m==12 && mi==1))
			{
				return;
			}
			_m=parseInt(_m,10)+parseInt(mi,10);
			if(_m<1)
			{
				_m=12;
				_y--;
			}
			else if(_m>12)
			{
				_m=1;
				_y++;
			}
			inner.Update();
		},
		IncMonthSetDay:function(mi,d)
		{
			_m=parseInt(_m,10)+parseInt(mi,10);
			
			if(_m<1)
			{
				_m=12;
				_y--;
			}
			else if(_m>12)
			{
				_m=1;
				_y++;
			}
			_d=d;
			inner.Update();
		},
		GoToday:function()
		{
			var obj=new Date();
			_y=obj.getFullYear();
			_m=obj.getMonth()+1;
			_d=obj.getDate();
			inner.Update();
		},
		SetDate:function()
		{
			_el.value=_y+'-'+AddPrefix(_m)+'-'+AddPrefix(_d);
			ChooseBox.Hide();
		}
	}
})();
var ImageMagnifier=(function(){
	var smallImageContainer;
	var smallImage;
	var smallPreview;
	var bigImage;
	var bigPreview;
	var scale;
	var previewBorderWidth;
	var inner;
	return inner={
		Apply:function(_smallImageContainer,_scale,_previewBorderWidth){
			smallImageContainer=$(_smallImageContainer);
			setStyle(smallImageContainer,{
				cursor:'crosshair'
			});
			smallImage=smallImageContainer.getElementsByTagName('img')[0];
			scale=_scale || 3;
			previewBorderWidth=_previewBorderWidth || 1;
			// 创建小图预览框
			smallPreview=document.createElement('div');
			setStyle(smallPreview,{
				display:'none',
				position:'absolute',
				zIndex:1000,
				width:Math.floor(smallImage.clientWidth/scale)+'px',
				height:Math.floor(smallImage.clientHeight/scale)+'px',
				border:previewBorderWidth+'px solid #ddd',
				background:'#888',
				filter:'alpha(opacity=50)',
				opacity:'0.5'
			});
			smallImageContainer.appendChild(smallPreview);
			// 创建大图预览框
			bigPreview=document.createElement('div');
			setStyle(bigPreview,{
				display:'none',
				position:'absolute',
				zIndex:1000,
				left:getXY(smallImageContainer)[0]+smallImageContainer.offsetWidth+6+'px',
				top:getXY(smallImage)[1]-previewBorderWidth+'px',
				width:smallImage.clientWidth+'px',
				height:smallImage.clientHeight+'px',
				border:previewBorderWidth+'px solid #ddd',
				overflow:'hidden'
			});
			document.body.appendChild(bigPreview);
			// 创建大图
			bigImage=document.createElement('img');
			bigImage.src=smallImage.src,
			setStyle(bigImage,{
				position:'absolute',
				width:smallImage.clientWidth*scale+'px',
				height:smallImage.clientHeight*scale+'px'
			});
			bigPreview.appendChild(bigImage);
			
			smallImageContainer.onmouseover=inner.MouseOver;
		},
		MouseOver:function(evnt)
		{
			inner.MouseMove(evnt);
			smallImageContainer.onmousemove=inner.MouseMove;
			smallImageContainer.onmouseout=inner.MouseOut;
		},
		MouseMove:function(evnt){
			evnt=getEvent(evnt);
			
			setStyle(smallPreview,{
				display:'block'
			});
			setStyle(smallPreview,{
				left:Math.min(Math.max(getScrollLeft()+evnt.clientX-Math.floor(smallPreview.clientWidth/2),getXY(smallImage)[0]),getXY(smallImage)[0]+smallImage.clientWidth-smallPreview.clientWidth)-previewBorderWidth+'px',
				top:Math.min(Math.max(getScrollTop()+evnt.clientY-Math.floor(smallPreview.clientHeight/2),getXY(smallImage)[1]),getXY(smallImage)[1]+smallImage.clientHeight-smallPreview.clientHeight)-previewBorderWidth+'px'
			});
			setStyle(bigPreview,{
				display:'block'
			});
			setStyle(bigImage,{
				left:Math.max(-bigImage.clientWidth+bigPreview.clientWidth,-(parseInt(smallPreview.style.left,10)+previewBorderWidth-getXY(smallImage)[0])*scale)+'px',
				top:Math.max(-bigImage.clientHeight+bigPreview.clientHeight,-(parseInt(smallPreview.style.top,10)+previewBorderWidth-getXY(smallImage)[1])*scale)+'px'
			});
		},
		MouseOut:function(){
			setStyle(smallPreview,{
				display:'none'
			});
			setStyle(bigPreview,{
				display:'none'
			});
		}
	}
})();
