String.prototype.trim = function() 
{
	a = this.replace(/^\s+/, ''); 
	return a.replace(/\s+$/, '');
};
function $(idname){
	if (document.getElementById){ return document.getElementById(idname); } 
	else if (document.all) { return document.all[idname];} 
	else if (document.layers) {	return document.layers[idname];	}
	else { return null; }
};
function selfGetWinSize() 
{
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	return {h:windowHeight,w:windowWidth};
}
function parentGetWinSize() 
{
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = parent.self.innerWidth;
		windowHeight = parent.self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = parent.document.documentElement.clientWidth;
		windowHeight = parent.document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = parent.document.body.clientWidth;
		windowHeight = parent.document.body.clientHeight;
	}
	return {h:windowHeight,w:windowWidth};
}

function is_null(val){
	return (val == "" || val == null || val == "undefined");
};

var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;
var uniqnum_counter = (new Date).getTime();
var is_regexp = (window.RegExp) ? true : false;
var gidname = '';

function exist(s)
{
	return $(s)!=null;
}

function myInnerHTML(idname, html)
{
	if (exist(idname))
	{
		$(idname).innerHTML = html;
	}
}

function dialog()
{
	var titile = '台州人力操作页面提示';
	var width = $('dialogBox')==null?350:$('dialogBox').style.width.replace('px','');
	var height= $('dialogHeight')==null?120:$('dialogHeight').style.height.replace('px','');

	//var path = "http://image2.sina.com.cn/pfp/ask/images/zhishi/";
	var sFunc = '<input id="dialogOk" type="image" src="/Images/AjaxImg/OKbtn.gif" onclick="new dialog().reset();" />';
	var sClose = '<p style="border:0;padding:0;margin:0;"><input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="/Images/AjaxImg/v2_l_gb1.jpg" border="0" align="absmiddle" /></p>';
	var sBody='\
		<div id="dialogBodyBox" style="overflow:auto; zoom:1;">\
			<ul style="list-style: none;padding: 0px;margin: 0px;">\
				<li style="margin-top:'+height/3+'px;">\
					<div id="dialogMsgDiv" style="margin:0px auto;">\
						<div id="dialogMsg" style="font-size:14px;color:#118ab7;font-weight:bold;text-align:center;"></div>\
					</div>\
				</li>\
				<li id="dialogFunc" style="text-align:center; padding-top:10px;">' + sFunc + '</li>\
			</ul>\
		</div>\
		';

	var sBox='\
		<div id="dialogBox" style="border:1px solid #95a1b6;z-index:9999;width:'+width+'px;">\
			<ul style="list-style:none;padding: 0px;margin: 0px;background-color:#fff;">\
				<li>\
					<ul style="list-style:none;padding: 0px;margin: 0px;background:#95a1b6;height:27px;overflow:hidden;zoom:1;">\
						<li id="dialogBoxTitle" style="float:left;color:#fff;font-size:13px;font-weight:bold;padding-left:8px;padding-top:6px;"></li>\
						<li id="dialogClose" style="float:right;padding-right:8px;padding-top:6px;">\
								' + sClose + '\
						</li>\
					</ul>\
				</li>\
				<li id="dialogHeight" style="height:'+ height +'px;">\
					<div id="dialogBody" style="height:'+height+'px;margin:0;padding:0;"></div>\
				</li>\
			</ul>\
		</div>\
		<div id="dialogBoxShadow" style="display:none;z-index:9998;"></div>\
	';
	var sIfram = '\
		<iframe id="dialogIframBG" name="dialogIframBG" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0" scrolling="no" style="position:absolute;z-index:9997;display:none;"></iframe>\
	';
	
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;"></div>\
	';

	this.show = function()
	{
		this.middle('dialogBox');
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.top = $('dialogBox').style.top;
			$('dialogIframBG').style.left = $('dialogBox').style.left;
			$('dialogIframBG').style.width = $('dialogBox').offsetWidth;
			$('dialogIframBG').style.height = $('dialogBox').offsetHeight;
			$('dialogIframBG').style.display = 'block';
		}
		if (!is_opera) {
			this.shadow();
		}
	}

	this.reset = function()
	{
		this.close();
		_set_id_focus();
	}
	
	this.resets = function(parentobj, _sName)
	{
		this.close();
		try {parentobj._sName.submit();}catch (e){}
	}

	this.close = function()
	{
		if (window.removeEventListener) 
		{
			window.removeEventListener('resize', this.event_b, false);
			window.removeEventListener('scroll', this.event_b, false);
	    } 
	    else if (window.detachEvent) 
	    {
	    	try {
	        	window.detachEvent('onresize', this.event_b);
	        	window.detachEvent('onscroll', this.event_b);
	      	} catch (e) {}
	    }	    
		if ($('dialogIframBG')) {
			$('dialogIframBG').style.display = 'none';
		}
		$('dialogBox').style.display='none';
		$('dialogBoxBG').style.display='none';
		$('dialogBoxShadow').style.display = "none";
		myInnerHTML('dialogBody', sBody);				
	}
	this.html = function(_sHtml)
	{
		myInnerHTML('dialogBody', _sHtml);
		this.show();
	}

	this.init = function()
	{
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		if (!is_opera) {
			oDiv.innerHTML = sBG + sIfram + sBox;
		} else {
			oDiv.innerHTML = sBG + sBox;
		}
		document.body.appendChild(oDiv);
		$('dialogBoxBG').style.height = document.body.scrollHeight;		
	}

	this.button = function(_sId, _sFuc)
	{
		if($(_sId)) {
			$(_sId).style.display = '';
			if($(_sId).addEventListener) {
				if($(_sId).act) {
					$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);
				}
				$(_sId).act = _sFuc;
				//$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
				if ($(_sId).addEventListener) {
		             $(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
		
      	         }
	           else if ($(_sId).attachEvent) {
		             var r = $(_sId).attachEvent('on' + 'click', function(){eval(_sFuc)});
		        
	            }
	            else {
		        $(_sId)['on' + evType] = function(){eval(_sFuc)};
	             }
			} else {
				if($(_sId).act) {
					$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});
				}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}

	this.shadow = function()
	{
		var oDialog = $('dialogBox');
		this.event_b_show();
		if (window.attachEvent)
		{
			window.attachEvent('onresize', this.event_b);
			window.attachEvent('onscroll', this.event_b);
		}
		else
		{
			window.addEventListener('resize', this.event_b, false);
			window.addEventListener('scroll', this.event_b, false);
		}
	}
	
	this.event_b = function()
	{
		var oShadow = $('dialogBoxShadow');
		
		if (oShadow.style.display != "none")
		{		
			oShadow['style']['position'] = "absolute";
			oShadow['style']['display']	= "";		
			oShadow['style']['opacity']	= "0.2";
			oShadow['style']['-moz-opacity']= "0.2";
			oShadow['style']['filter'] = "alpha(opacity=20)";
			oShadow['style']['background']	= "#000";
			var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
			var sClientHeight = parent ? parent.document.body.scrollHeight : document.body.scrollHeight;
			//var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
			oShadow['style']['top'] = '0px';
			oShadow['style']['left'] = '0px';
			oShadow['style']['width'] = sClientWidth+"px";
			oShadow['style']['height'] = sClientHeight+"px";
			//oShadow['style']['height'] = (sClientHeight + sScrollTop)+"px";
		}
	}
	
	this.event_b_show = function(e)
	{
		var oShadow = $('dialogBoxShadow');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['display']	= "";		
		oShadow['style']['opacity']	= "0.2";
		oShadow['style']['-moz-opacity']= "0.2";
		oShadow['style']['filter'] = "alpha(opacity=20)";
		oShadow['style']['background']	= "#000";
		var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
		var sClientHeight = parent ? parent.document.body.scrollHeight : document.body.scrollHeight;
		//var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
		var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		oShadow['style']['top'] = '0px';
		oShadow['style']['left'] = '0px';
		oShadow['style']['width'] = sClientWidth+"px";
		oShadow['style']['height'] = sClientHeight+"px";
		//oShadow['style']['height'] = (sClientHeight + sScrollTop)+"px";
	}

	this.open = function(_sUrl, _sMode, _sClose)
	{		
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			var height=parseInt($('dialogHeight').style.height.substring(0,$('dialogHeight').style.height.length-2));
			//alert(height)
			var openIframe = "<iframe width='100%' style='height:"+height+"px;' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
	        //var openIframe = "<iframe width='100%' height='"+$('dialogHeight').style.height+"' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";		
			myInnerHTML('dialogBody', openIframe);
		}
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
	}

	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode)
	{
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop = -80 + (screen.height - _iHeight)/2;
		iTop = iTop > 0 ? iTop : (screen.height - _iHeight)/2;
		var sTop = (screen.height) ? iTop : 0;
		if(window.showModalDialog && _sMode == "m"){
			oWindow = window.showModalDialog(_sUrl,"","dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
		} else {
			oWindow = window.open(_sUrl, '', 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
			this.reset();
		}
	}

    this.event = function(_sMsg, _Reload)
	{
		myInnerHTML('dialogFunc', sFunc);
		myInnerHTML('dialogClose', sClose);
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
    	$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
        //$('dialogCancel').style.display = 'none';
        
        if(_Reload=="Y")
        {
            this.button('dialogOk', "window.location.href = window.location.href")
            //alert("yes")
        }
        else
        {
            this.button('dialogBoxClose', "")
            //alert("no")
        }
		this.show();
	}
//	this.event = function(_sMsg, _sOk, _sCancel, _sClose)
//	{
//		myInnerHTML('dialogFunc', sFunc);
//		myInnerHTML('dialogClose', sClose);
//		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
//		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};

//		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $('dialogOk').style.display = 'none';
//		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
//		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};

//		this.show();
//	}

	this.set = function(_oAttr, _sVal)
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(!is_null(_sVal)) {
			switch(_oAttr)
			{
				case 'title':
					myInnerHTML('dialogBoxTitle', _sVal);
					break;
				case 'width':
					oDialog.style.width = _sVal+'px';
					break;
				case 'height':				    
					oHeight.style.height = _sVal+'px';
					break;
			}
		}
		this.middle('dialogBox');
		
       
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}

	this.middle = function(_sId)
	{
		try {
			var aIframe = parent.document.getElementById("iframe_parent");
		} catch (e){}
		if (aIframe) {
			var sClientWidth = aIframe.offsetWidth;
			var sClientHeight = aIframe.offsetHeight;
			var sScrollTop = 0;
		} else {
			var sClientWidth = parent ? parentGetWinSize().w : selfGetWinSize().w;
			var sClientHeight = parent ? parentGetWinSize().h : selfGetWinSize().h;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		}
		var sleft = (document.body.clientWidth / 2) - ($(_sId).offsetWidth / 2);
		var iTop = -80 + (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		var sTop = iTop > 0 ? iTop : (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		sTop=sTop+50;
		$(_sId)['style']['display'] = '';
		$(_sId)['style']['position'] = "absolute";
		$(_sId).style.left = sleft+'px';
		$(_sId).style.top = sTop+'px';
      
	}
}

function _set_id_focus()
{
	if (!is_null(gidname)) {
		try {$(gidname).focus();}catch (e){}
	}
}
//打开一个ajax窗口
function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sClickNo, _sScroll)
{
	var oEdit = new dialog();
	oEdit.init('yes');
	
	oEdit.set('title', _sTitle ? _sTitle : "台州人力操作页面提示" );
	oEdit.set('width', _sWidth);
	oEdit.set('height', _sHeight);

	oEdit.open(_sUrl, _sScroll != "yes" ? 'no' : 'yes', _sClickNo);
}
