//建于06-11-07  万会
//继承，来自己于prototype.js
Object.extend = function(destination, source) 
{
  for (property in source) 
  {
    destination[property] = source[property];
  }
  return destination;
}

var Class = {
  Create: function() {
    return function() {
      this.Initialize.apply(this, arguments);
    }
  }
}

//HTML节点，来自己于prototype.js
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

//得到xml的文档对象
function XmlDocument(XmlPath)
{
	var xmlDocNew;
	if(window.ActiveXObject)
		xmlDocNew=new ActiveXObject("Microsoft.XMLDOM");
	else if (document.implementation && document.implementation.createDocument)
		xmlDocNew=document.implementation.createDocument('','doc',null);
	xmlDocNew.async=false;
	xmlDocNew.load(XmlPath);
	return xmlDocNew;
}

//返回xmlHTTP xx为异步还是同步，如果是true，xml.onreadystatechange = funcMyHandler;
function CreateXmlHttp(HttpMethod,urls,xx)
{
	var xml;
	if(window.ActiveXObject)
  		xml = new ActiveXObject("Microsoft.XMLHTTP");
	else if (typeof XMLHttpRequest!='undefined')
 	 		xml = new XMLHttpRequest();
	xml.open(HttpMethod,urls,xx);
	return xml;
}


function SetCookie(str,values){
		
	var Then = new Date();
	Then.setTime(Then.getTime() + 3600*24*265*1000 );
	document.cookie = str+"="+encodeURI(values);
	
} 


function GetCookie(str)
{
	
	re = new RegExp(str+"=([^;]*)");
	if(document.cookie=='')return '';
	var tem1=document.cookie.match(re); 
	if(tem1)
	return decodeURI(tem1[1]);
	else return '';
}

//是不是IE
function IsIE(){
	return /MSIE/.test(navigator.userAgent);
}
//是不是IE7
function IsIE7(){
	return /MSIE 7/.test(navigator.userAgent);
}
//处理下拉框问题
var HSelect=
{
	isHidden:false,
	Hidden:function()
	{
		if(this.isHidden || IsIE7())return;
		var sel=document.getElementsByTagName("Select");
		var input,v='';
		for(var i=0;i<sel.length;i++)
		{
			v=(sel[i].selectedIndex>=0) ? sel[i].options[sel[i].selectedIndex].text  : ' ';
			input=createElement('input',{'type':'text','class':'selectReplace'},{'width':sel[i].clientWidth-8+'px'});
			input.value=v;
			sel[i].parentNode.insertBefore(input,sel[i]);
			sel[i].style.display="none"; 
		}
		this.isHidden=true;
		AddEventListener(document,"mousedown",this.Show);
	},
	Show:function()
	{
		HSelect.isHidden=false;
		var sel=document.getElementsByTagName("Select");
		for(var i=0;i<sel.length;i++)
		{
			sel[i].parentNode.removeChild(sel[i].previousSibling);
			sel[i].style.display=""; 
		}
		RemoveEventListener(document,"mousedown",HSelect.Show);
	}
}
/*****************************************
函数名称：formatFloat
函数说明：截取小数点后两位数?
传入参数：进行转换的数?
返回：转换后的?
*****************************************/
function formatFloat(value)
{ 
 value = Math.round(parseFloat(value)*100)/100;
 if(value.toString().indexOf(".")<0)
  value = value.toString()+".00";
 return value;
}


//选择
function FocusSelect(tid)
{
		document.getElementById(tid).focus();
		document.getElementById(tid).select();
}


function _GET(str)
{
	re = new RegExp(str+"=([^&]*)");
	var getstr=window.location.search.match(re);
	if(getstr)
	return decodeURI(getstr[1]);
	else return '';
}





Object.extend(String.prototype, {
	//返回一个把所有的HTML或XML标记都移除的字符串。
  stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  },
	//返回一个把所有的script都移除的字符串。
  stripScripts: function() {
    return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  },
	//返回一个包含在string中找到的所有<script>的数组。
  extractScripts: function() {
    var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
    var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
    return (this.match(matchAll) || []).map(function(scriptTag) {
      return (scriptTag.match(matchOne) || ['', ''])[1];
    });
  },
	//执行在string中找到的所有<script>。
  evalScripts: function() {
    return this.extractScripts().map(eval);
  },


	//把querystring分割才一个用parameter name做index的联合Array，更像一个hash。
  toQueryParams: function() {
    var pairs = this.match(/^\??(.*)$/)[1].split('&');
    return pairs.inject({}, function(params, pairString) {
      var pair = pairString.split('=');
      params[pair[0]] = pair[1];
      return params;
    });
  },
  len:function()
	{
		return this.replace(/[^\x00-\xff]/g,"aa").length;
	},
	trim:function()
	{
		 return  this.replace(/(^\s*)|(\s*$)/g,  "");
	}
});






//添加事件监听
function AddEventListener(el,eventName,fun){
	if(IsIE())el.attachEvent('on'+eventName,fun);
	else el.addEventListener(eventName,fun,false);			
}
//删除事件监听
function RemoveEventListener(el,eventName,fun){
	if(IsIE())el.detachEvent('on'+eventName,fun);
	else el.removeEventListener(eventName,fun,false);
}
//获取坐标X
function GetLeft(el){	
	var left=el.offsetLeft;
	while(el=el.offsetParent){
		left+=el.offsetLeft;
	}
	return left;
}
//获取坐标Y
function GetTop(el){	
	var top=el.offsetTop;
	while(el=el.offsetParent){
		top+=el.offsetTop;
	}
	return top;
}



//获取事件
function SearchEvent(){
	var _caller=SearchEvent.caller;
	while(_caller){
		var arg=_caller.arguments[0];
		if(arg){		
			if(arg.constructor.toString().toLowerCase().indexOf('event')>-1){
				return arg;
			}			
		}
		_caller=_caller.caller;
	}
	return null;
}






//标签名，属性，样式，内容
function createElement(tagName, attribute, style, word) { 
    var e = document.createElement(tagName); 
    if (attribute) { 
        for (var k in attribute) { 
            if (k == 'class') e.className = attribute[k]; 
            else if (k == 'id') e.id = attribute[k]; 
            else e.setAttribute(k, attribute[k]); 
        } 
    } 
    if (style) { for (var k in style) e.style[k] = style[k]; } 
    if (word) { e.innerHTML=word; } 
    return e; 
} 


//查看ID的Option是否存在v的值 
function ISExistOption(id,v)
{
	var option=document.getElementById(id).options;
	for(var i=0;i<option.length;i++)
	{
		if(option[i].value==v)return true;
		}
		return false;
}
//删除Option所有
function DelAllOption(id,begin)
{
	if(begin==null)begin=0;
	var option=document.getElementById(id).options;
	var l=option.length;
	for(var i=begin;i<l;i++)
	{
		option[i]=null;
		i--;
		l--;
		}
}
	
// 删除SELECT的一个节点
function DelOption(id)
{
	var option=document.getElementById(id).options;
	var l=option.length;
	for(var i=0;i<l;i++)
	{
		if(option[i].selected)
		{
			option[i]=null;
			i--;
			l--;
			}
		}
}



function OptionEdit(id,v,t)
{
	var obj=document.getElementById(id).options[document.getElementById(id).selectedIndex];
	if(v!=null)obj.value=v;
	if(t!=null)obj.text=t;
}
	
function OptionAdd(bID,eID)
{
	var b=document.getElementById(bID).options;
	var e=document.getElementById(eID).options;
	for(var i=0;i<test.length;i++)
	{
		if(test[i].selected)
		{
			if(!ISExistOption(eID,b[i].value))e[audits.length]=new Option(b[i].text,b[i].value);
			}
		}
}

function GetOptionData(id)
{
	var option=document.getElementById(id).options;
	var re="";
	for(var i=0;i<option.length;i++)
	{
		if(option[i].value.split(',').length>1)
		{
			alert('有符号“,”存在，请删除！');
			return;
			}
		re+=option[i].value+",";
		}

	return re;
}



//传回国历 y年某m+1月的天数
function solarDays(y,m) {

	var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   if(m==1)
      return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28)
   else
      return(solarMonth[m])
}




function NextPage(objSelf,url,func)
{
	this.obj=objSelf;
	this.url=url;
	this.func=func;
	}
NextPage.prototype.AllPage=0;//总页数
NextPage.prototype.CurrPage=0;//当前页码
NextPage.prototype.PageSize=15;//单页数

NextPage.prototype.begin=function(pIndex,data)
{
	
	if(data)
	{
		this.data=data;
		this.data+='&PageSize='+this.PageSize;
		this.data+='&allCount=1';
	}
	
	switch(pIndex)
	{
		case -1://最后一页
		pIndex=this.AllPage;
		break;
		case -2://上一页
		pIndex=this.CurrPage-1;
		break;
		case -3://下一页
		pIndex=this.CurrPage+1;
		break;
		case undefined://空值回到首页
		pIndex=this.CurrPage;
		break;
	}
	if(pIndex<1 || (pIndex>this.AllPage && this.AllPage>0))return;//防止翻页翻过头

	this.CurrPage=pIndex;//设置当前页

	var d=this.data+'&PageIndex='+ pIndex;
	Msg.Show('   <img src="../system/loading.gif" align="absmiddle" />正在获取数据中');
	xmlHttp=CreateXmlHttp("POST",this.url,true);
	xmlHttp.setRequestHeader("Content-Length",d.length);  
	xmlHttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	obj=this;
	xmlHttp.onreadystatechange = function(){obj.end(obj);};
	xmlHttp.send(d);
}

NextPage.prototype.end=function(o)
{
	if(xmlHttp.readyState!=4)return;
	
	var re=xmlHttp.status;
	switch(re)
	{
		case 711:
		parent.OpenWin.Login();
		Msg.Close();
		return;
		case 712:
		Msg.timeClose(xmlHttp.responseText,3);
		return;
	}

	var node=xmlHttp.responseXML;
	if(node.getElementsByTagName("Total")[0])
		o.AllPage=Math.ceil(node.getElementsByTagName("Total")[0].childNodes[0].data/o.PageSize);

	var getValue=function(id,i)
	{
		return (node.getElementsByTagName(id)[i].childNodes[0]) ? node.getElementsByTagName(id)[i].childNodes[0].data :'无';
	}
	
	var re=/￡/ig ;
	re.multiline = true;
	
	eval(this.func);

	var iner='';
	for(var i=1;i<=o.AllPage;i++)
		iner+='<a href="#"  '+(o.CurrPage==i ? 'style="font-weight:bold"' : '')+' onclick="'+o.obj+'.begin('+i+');">'+i+'</a> ';
	document.getElementById('Onces_'+o.id).innerHTML=iner;
	
	Msg.Close();
}
NextPage.prototype.Link=function(id)
{
	this.id=id;
	return '<a href="#" onclick="'+this.obj+'.begin(1);">首页</a> <a href="#" onclick="'+this.obj+'.begin(-2);">上一页</a> <span id="Onces_'+id+'"></span> <a href="#" onclick="'+this.obj+'.begin(-3);">下一页</a> <a href="#" onclick="'+this.obj+'.begin(-1);">尾页</a>';
}

 











function setTitle(v,a)
{
	if(a!=null)v=document.title +a;
	document.title =v;
	//document.getElementById('ContentTitle').innerHTML=v;
}




/*键盘监听
			KeyBoard.AddEventListener("x",function(){alert('test');},{altKey:true});
			KeyBoard.BeginListener();
*/
var KeyBoard={
	ListenerCollection:new Object(),
	AddEventListener:function(keyCode,fun,ctrlKeyState){		
		if(typeof(keyCode)=="number")keyCode=String.fromCharCode(keyCode).toUpperCase();
		else keyCode=keyCode.toUpperCase();
		this.ListenerCollection["f"+keyCode]=fun;
		this.ListenerCollection["c"+keyCode]=ctrlKeyState;			
	},
	RemoveEventListener:function(keyCode){
		if(this.ListenerCollection["f"+keyCode])delete this.ListenerCollection["f"+keyCode];
		if(this.ListenerCollection["c"+keyCode])delete this.ListenerCollection["c"+keyCode];
	},
	KeyCheck:function(){
		if(!IsIE())event=SearchEvent();
		var kCode=String.fromCharCode(IsIE()?event.keyCode:event.which).toUpperCase();					
		if(KeyBoard.ListenerCollection["f"+kCode]){
			var keyState=KeyBoard.ListenerCollection["c"+kCode];
			if(keyState){
				if(keyState.ctrlKey)if(!event.ctrlKey)return false;
				if(keyState.shiftKey)if(!event.shiftKey)return false;
				if(keyState.altKey)if(!event.altKey)return false;
			}
			try{KeyBoard.ListenerCollection["f"+kCode]();}catch(ex){throw("Delegate Method Fail");}
		}
	},
	BeginListener:function(){
		AddEventListener(document,"onkeydown",this.KeyCheck);
	},
	EndListener:function(){
		RemoveEventListener(document,"onkeydown",this.KeyCheck);
	}
}
///////////////end键盘事件




//处理PNG透明问题
function correctPNG() 
{
   for(var i=0; i<document.images.length; i++)
   {
	  var img = document.images[i]
	  var LW=img.width
	  var LH=img.height
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	  { 
         img.style.filter+="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+img.src+", sizingmethod=scale);" 
         img.src="transparent.gif"
         img.width=LW
         img.height=LH
	  }
   }
}


var xmlHttp;
function executPost(data,page,yb,ybFun)
{
	if(yb==null)yb=false;
	xmlHttp=CreateXmlHttp("POST",page,yb);
	xmlHttp.setRequestHeader("Content-Length",data.length);  
	xmlHttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	if(yb)
	{
		xmlHttp.onreadystatechange = eval(ybFun);
		xmlHttp.send(data);
		return;
	}else
		xmlHttp.send(data);
	return xmlHttp;
	}
	
function postXmlHttp(page,data)
{
	var http=CreateXmlHttp("POST",page,true);
	http.setRequestHeader("Content-Length",data.length);  
	http.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	http.send(data);
	return http;
	}

var Msg=
{
	Info:'',
	isMsg:false,
	Func:null,
	Show:function(msg,n)
	{
		var z=createElement("div",{'id':'MsgBu','class':'MsgBu'});
		z.style.width=document.documentElement.clientWidth+'px';
		z.style.height=document.documentElement.scrollHeight+'px';
		document.body.appendChild(z);
		var b=createElement("div",{'id':'MsgWin','class':'MsgWin'},null,msg);
		b.style.left=Math.floor((document.documentElement.clientWidth-250)/2)+'px';
		b.style.top=Math.floor(document.documentElement.scrollTop+document.documentElement.clientHeight/2-60)+'px';
		document.body.appendChild(b);
		this.Info=msg;
		this.isMsg=true;
		if(n)setTimeout('Msg.Close();',1000*n);
	},
	reShow:function()
	{
		if(!Msg.isMsg)return;
		Msg.Close();
		Msg.Show(Msg.Info);
	},
	upShow:function(newInfo)
	{
		document.getElementById('MsgWin').innerHTML=newInfo;
	},
	timeClose:function(newInfo,n)
	{
		if(newInfo)document.getElementById('MsgWin').innerHTML=newInfo;
		if(!n)n=2;
		setTimeout('Msg.Close();',1000*n);
	},
	Close:function()
	{
		document.body.removeChild(document.getElementById('MsgBu'));
		document.body.removeChild(document.getElementById('MsgWin'));
		this.isMsg=false;
		this.Info='';
		eval(this.Func);
	}
}




var Opt=
{
	Info:'',
	isMsg:false,
	Show:function(msg,w,h)
	{
	    if(this.isMsg)return;
		var z=createElement("div",{'id':'OptWin','class':'MsgBu'});
		z.style.width=document.documentElement.clientWidth;
		z.style.height=document.documentElement.scrollHeight;
		document.body.appendChild(z);
		var b=createElement("div",{'id':'OptWin1','class':'OptWin'},null,msg );
		b.style.left=Math.floor((document.documentElement.clientWidth-w)/2)-15+'px';
		b.style.top=Math.floor(document.documentElement.clientHeight-h)/2.3+'px';
		b.style.width=w+'px';
		b.style.height=h+'px';
		document.body.appendChild(b);
		this.Info=msg;
		this.isMsg=true;
	},
	Close:function()
	{
		document.body.removeChild(document.getElementById('OptWin'));
		document.body.removeChild(document.getElementById('OptWin1'));
		this.isMsg=false;
		this.Info='';
	}
}


//居中的窗口
function Open(src,w,h){
    var t = (window.screen.availHeight-30-h)/2;      
    var l = (window.screen.availWidth-10-w)/2;         
    var win= window.open(src,'','location=no,height='+h+',width='+w+',top='+t+',left='+l+',model=yes,scrollbars=yes');
    return win;   
}