var PubFun = {	
	//************************************************************************************************************************

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//取事件
	getEvent : function(){	
		if(document.all)	return window.event;		
		func=PubFun.getEvent.caller;			
		while(func!=null)
		{	
			var arg0=func.arguments[0];
			if(arg0)
			{
				if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
					|| (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){	
					return arg0;
				}
			}
			func=func.caller;
		}
		return null;
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//取浏览器类型
	,getPlatform : function(){
		var _platform = null;
		if (typeof(navigator) == "undefined")
		{
			return "not-browser";
		}
		var ua = navigator.userAgent.toLowerCase();
		if (/msie/i.test(ua))
		{
			if (/msie 6/i.test(ua))
			{
				_platform = "ie6";
			}
			else if (/msie 5\.5/i.test(ua))
			{
				_platform = "ie5.5";
			}
			else if (/msie 5\.[^5]/i.test(ua))
			{
				_platform = "ie5";
			}
			else
			{
				_platform = "ie";
			}
		}
		else if (/gecko/i.test(ua))
		{
			_platform = "moz";
		}
		else if (/opera/i.test(ua))
		{
			_platform = "opera";
		}
		else
		{
			_platform = "other";
		}
		return _platform;
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//转换数据成HTML
	//pXml : XML数据源对象
	//pXslt : XSLT模板数据对象
	//pDefaultHtml : 当转换出错时返回的默认数据
	,transitionXslt : function(pXml,pXslt,pDefaultHtml)
	{	
		//因为pXml可能是由 createXmlDoc()函数建立的空XML,
		//所以无法用.documentElement.tagName来检查XML是否失败
		
		//检查是否XSL文件出错
		var xslError=false ;
		try{  
			var xsl=pXslt.documentElement.tagName;
			if (!xsl) throw new Error(99997,"转换XSL文件失败");
		}catch(x){
			xslError=true;
		}
		//尝试转换，如果转换失败，则可判定XML失败
		
		try{
				if(window.ActiveXObject)
				{//	alert(pXml.xml);alert(pXslt.xml)
					return pXml.transformNode(pXslt);	
				}
				else
				{
					var xsltProcessor = new XSLTProcessor();
					xsltProcessor.importStylesheet(pXslt);
					var fragment=xsltProcessor.transformToFragment(pXml,document);
					var tDiv = document.createElement('div');
					tDiv.appendChild(fragment);		
					var tHTML = tDiv.innerHTML;
					tDiv.innerHTML = '';
					var tDiv = null;
					xsltProcessor = null;
					return tHTML;
				}
		}catch(x){		//alert(x.message)
			if 	(pDefaultHtml) return pDefaultHtml;
			if  (xslError)   return "<p>读取XSL文件时失败,请检查XSL格式是否正确</p>";
			return "<p>读取XML数据时失败,请检查服务器返回数据是否正确<p>";
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//把一段html代码插入指定的对象最后面
	//pObj : 要插入的父对象
	//pContent:要插入的内容
	,insertBottom : function (pObj, pContent)
	{
		var el = $(pObj);
		if(el.insertAdjacentHTML)
		{			
			if(el.tagName == 'TABLE')
			{//alert(el.id)
				//在表格中不能直接以HTML的方式把一行插入进到， 所以上面的方法不行
				//try{
				var oDiv=document.createElement("div"),tRows;
				oDiv.innerHTML = "<table>"+pContent+"</table>"
				var oRows= oDiv.childNodes[0].tBodies[0].rows;
				while(oRows.length>0){
					pObj.tBodies[0].appendChild(oRows[0])
				}
				oDiv = null;
				oRows = null;
				//}catch(e){alert('e.description')}
			}else
			{
				el.insertAdjacentHTML('beforeEnd', pContent);	
			}
			
			
		}else
		{
			var tRange = el.ownerDocument.createRange();				
			initializeRange(tRange,el);				
			insertContent([tRange.createContextualFragment(pContent)],el);
			tRange = null;
		}		
		
		function initializeRange(pRange,pElement){
			pRange.selectNodeContents(pElement);
			pRange.collapse(pElement);
		}
		
		function insertContent(fragments,pElement) {
			fragments.each((function(fragment) {	
			  pElement.appendChild(fragment);
			}).bind(this));
		}
	}	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//取URL的参数
	//pPara: 参数名
	,getParam : function(pPara)
	{
		if(!pPara || (pPara + '').trim() == '') return null;
		var tUrl = document.location.toString().toLowerCase();		//当前页面的地址，转成小写
		var re = new RegExp("(\\\?|&)"+pPara.toLowerCase()+"=([^&]+)(&|$)");
		var tArr = tUrl.match(re);
		if(tArr) return tArr[2];
		else return null;
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//动态加载JS文件
	//pUrl : 要加载的文件路径
	//onLoad: 回调函数
	//parentElement : 加载JS的父容器
	,loadJS : function(pUrl,options)
	{
		//var defaultOptions = {
	//	  parentElement:  document.body
   		//}
    //	Object.extend(defaultOptions, options || {});
		if(!options.parentElement) options.parentElement = document.body;
		
		if(options.parentElement && typeof options.parentElement == 'string')
			options.parentElement = document.getElementById(options.parentElement);
			
		tUrls = pUrl.split(',');
		var tCountNum = tUrls.length;
		var tNum = 0;
		for(i = 0; i < tCountNum; i++)		
		{
			var oScript = document.createElement('script');
			oScript.src = tUrls[i];	
			oScript.defer = true;		
			options.parentElement.appendChild(oScript);
			if(options.onLoad && typeof options.onLoad == 'function')
			{
				if(getPlatform().indexOf('ie') >= 0)
				{
					oScript.onreadystatechange = function(){						
						if(oScript.readyState=="complete" || oScript.readyState=="loaded")	
						{
							tNum++;
							if(tNum == tCountNum){	options.onLoad.call(this);}
						}
					 }
				}else
				if(getPlatform() == 'moz')
				{						
					 oScript.onload = function(){	
					 		tNum++;
							if(tNum == tCountNum)	options.onLoad.call(this);				
					 }
				}
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//设为绝对坐标
	,absolutize : function(element){
		element = $(element);
	    element.style.position=(document.all)?'absolute':'fixed'	
      //  element._absolutize = true;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//取得坐标
	//pObj:目标对象
	,getPos : function(pObj){
		 pObj = $(pObj);
		 var to=new Object();
		 to.left=to.right=to.top=to.bottom=0;
		 try{
			 to.left = Position.positionedOffset(pObj)[0];
			 to.top = Position.positionedOffset(pObj)[1];			
			 to.right=to.left+pObj.offsetWidth;
			 to.bottom=to.top+pObj.offsetHeight;
		 }catch(e){}
		 return to;		 
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//取页面的宽高
	,getPageSize : function(){
		
		var xScroll, yScroll;	
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//取页面滚动位置
	,getPageScroll : function(){
		var scrollY = 0 , scrollX = 0; 
		if (typeof window.pageYOffset != 'undefined') { 
			scrollX = window.pageXOffset;
			scrollY = window.pageYOffset; 
		} 
		else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { 
			scrollX = document.documentElement.scrollLeft;		 
			scrollY = document.documentElement.scrollTop; 
		} 
		else if (typeof document.body != 'undefined') { 
			scrollX = document.body.scrollLeft;
			scrollY = document.body.scrollTop; 
		} 
		//alert(scrollX)
		return {X:scrollX,Y:scrollY}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	,encodeQueryString : function(sContent)
	{
		var s = sContent + "";
		s = encodeURI(s);
		s = s.replace(/&/g, "%26");
		s = s.replace(/=/g, "%3D");
		return s;
	}

	,showModalDialog : function(URL,width,height)
	{
		return window.showModalDialog(URL,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;status:no;center:yes;edge:raised;scroll:no")
	}

	,getNextNode : function(obj)
	{
		var oNode = obj.nextSibling;
		while(oNode){
			if(oNode.tagName) return oNode;
			oNode = oNode.nextSibling;
		}
		return null;
	}
	 //********************* 字符串类*********************//
	 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	 //取字符串的实际长度，一个汉字等于2个字节
	,getLength : function(pStr){
		return pStr.replace(/[^\x00-\xff]/g,"**").length;
	}
	 //********************* 效果动作类*********************//
	 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	 //鼠标放上图片时换另一幅图
	 ,overChangeImg : function(pObj,pSrc){
		var obj = $(pObj);
		if(!obj) return false;
		if(obj.getAttribute('oSrc')) return false;
		if(typeof pSrc != 'string') return false;
		obj.setAttribute('oSrc',obj.src);
		obj.src = pSrc;
	 }
	  //鼠标离开图片时换回原图
	  ,outChangeImg : function(pObj){
		var obj = $(pObj);
		if(!obj) return false;
		if(!obj.getAttribute('oSrc')) return false;		
		obj.src = obj.getAttribute('oSrc');
		obj.setAttribute('oSrc',null);
		
	 }
	 //建立一透明层
	 ,createOverLay : function(){
		 if($('_OverLayDiv')){
			$('_OverLayDiv').show();
			$('_OverLayDiv').style.height = PubFun.getPageSize()[1] + 'px';
		 	$('_OverLayDiv').style.width = PubFun.getPageSize()[0] + 'px';	
			IndexClass.setMaxIndex(oDiv);
			return;
		 }
		 var oDiv = document.createElement('div') 
		 oDiv.style.height = PubFun.getPageSize()[1] + 'px';
		 oDiv.style.width = PubFun.getPageSize()[0] + 'px';	
		 IndexClass.setMaxIndex(oDiv);	
		// oDiv.style.zIndex += 1;
		 PubFun.absolutize(oDiv);
		 oDiv.style.backgroundColor = "#000000";
		 oDiv.id = "_OverLayDiv"		 
		 Element.setOpacity(oDiv,0.6);
		 oDiv.onmousedown = function(){return false};
		 oDiv.oncontextmenu = function(){return false};
		 oDiv.style.left = "0px";
		 oDiv.style.top = "0px";
		 oDiv.innerHTML = '<span style=" position:absolute;filter:alpha(opacity=0); -moz-opacity:0; width:1px; height:1px;">0</span><iframe id="_OverLayDivIframe" style="width:100%; height:100%; z-index:-1; position:absolute; left:0px; top:0px; border-style:none" />';
		 document.body.appendChild(oDiv);
		 Element.setOpacity($('_OverLayDivIframe'),0.6);
	} 
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
   //分页
	,goPage : function(pPage,pXml,pXslt,pBody,pMaxPage,pCallback){
		if(!pPage || isNaN(pPage)) return false;
		if(!pXml) return false;
		if(!pBody) return false
		var tObj = $(pBody);
		if(!tObj) return false;//版块表格
		var tPage = parseInt(pPage);
		if(tPage <= 0){
			tPage = 1;
		}else if(pMaxPage && !isNaN(pMaxPage) && tPage > parseInt(pMaxPage)){
			tPage = parseInt(pMaxPage);
		}
		//if(tPage == pPage) return true;//等于当前页
		if(pXml.indexOf('?') > 0){
			pXml += '&Page=' + tPage;	
		}else{
			pXml += '?Page=' + tPage;
		}
		pBody.innerHTML = '正读取数据...';
		var oXml = null,oXslt = null;
		var tFlag = false;
		if(typeof pXslt == 'string')
		{
			new Ajax.Request(pXslt,{method:'get',
				onSuccess:function(o){
					oXslt = o.responseXML;	
					Success();
				}
			});
		}else
		{
			oXslt = pXslt;	
			Success();
		}
		new Ajax.Request(pXml,{method:'get', 
			onSuccess : function(o){	
				oXml = o.responseXML;
				Success();
			}
		});
		
		function Success()
		{//alert(oXslt.xml)
			if(!oXml || !oXslt || tFlag) return false;
			
			tObj.innerHTML = '';	
			PubFun.insertBottom(tObj,PubFun.transitionXslt(oXml,oXslt));//加入到页面中
			tFlag = true;
			try{
				if(typeof pCallback == 'function'){
					pCallback(pBody);
				}
			}catch(e){}
		}
		
	}
	//取随机数
	,GetRandom : function(n,pOnlyNumber){
		if(!pOnlyNumber){
			var tChars = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];	
			tChars = tChars.concat(['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']);
			var tRndChar = Math.round(Math.random() * 52);
			if(tRndChar == 52) tRndChar = 0;
			var tChar = tChars[tRndChar];
			if(!n || isNaN(n)) return tChar;
			if(parseInt(n) < 1) n = 1;		 
			var tRndNum = Math.round(Math.random() * (Math.pow(10,n-1) -1)).toString();			
			while(tRndNum.length <n-1){
				tRndNum = '0' + tRndNum;
			}
			return tChar + tRndNum;
		}else{
			var tRndNum = Math.round(Math.random() * (Math.pow(10,n) -1)).toString();			
			while(tRndNum.length <n){
				tRndNum = '0' + tRndNum;
			}
			return tRndNum;
		}
	}
}




//*************************************************************************************************************************
//数组操作类
//*************************************************************************************************************************
var arrHandle= {

	Remove : function(oArr,val)
	{
		oArr.splice(this.getIndexOfElement(oArr,val),1)
		return oArr;
	}
	
	,Add : function(oArr,val)
	{
		oArr.unshift(val)
		return oArr;
	}

	,getIndexOfElement : function(oArr,val)
	{

		for (var i=0;i<=oArr.length-1;i++)
		{
			if (oArr[i]==val)
			{
				return i;
				break;
			}
		}
	}	
}
//*************************************************************************************************************************
//zIndex操作类
//*************************************************************************************************************************
var IndexClass = {
	zIndex : {
		MaxValue : 10,
		getValue : function()
		{			
			this.MaxValue++;
			return ++this.MaxValue;
		}
		
	}
	,AddIndex : function(pId){
		var e = $(pId);
		if(!e) return false;
		if(e.style.zIndex == this.MaxValue) return;
		e.style.zIndex = ++e.style.zIndex;
	}
	,DecIndex : function(pId){
		var e = $(pId);
		if(!e) return false;
		if(e.style.zIndex <= 0) return e.style.zIndex;
		e.style.zIndex = --e.style.zIndex;
	}
	,setMaxIndex : function(pId)
	{
		var e = $(pId);
		if(!e) return false;
		e.style.zIndex = IndexClass.zIndex.getValue();
	}
	,setMinIndex : function(pId){
		var e = $(pId);
		if(!e) return false;
		e.style.zIndex = 0;
	}
}
//*************************************************************************************************************************
//客户端缓存类
//*************************************************************************************************************************
var Cache = {	
	dict:{},
	getCache : function(name)
	{
		return this.dict[name];
	},
	setCache : function(name,content)
	{
		this.dict[name] = content;
	},
	delCache : function(name)
	{
		if(this.dict[name]) this.dict[name] = null;
	}	
}


//*************************************************************************************************************************
//扩展prototype1.4
//*************************************************************************************************************************

Element.getOpacity = function(element){  
  var opacity;
  if (opacity = Element.getStyle(element, 'opacity'))  
    return parseFloat(opacity);  
  if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))  
    if(opacity[1]) return parseFloat(opacity[1]) / 100;  
  return 1.0;  
}

Element.setOpacity = function(element, value){  
  element= $(element);  
  if (value == 1){
    Element.setStyle(element, { opacity: 
      (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 
      0.999999 : null });
    if(/MSIE/.test(navigator.userAgent))  
      Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});  
  } else {  
    if(value < 0.00001) value = 0;  
    Element.setStyle(element, {opacity: value});
    if(/MSIE/.test(navigator.userAgent))  
     Element.setStyle(element, 
       { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
                 'alpha(opacity='+value*100+')' });  
  }   
}  
 
Element.getInlineOpacity = function(element){  
  return $(element).style.opacity || '';
}  

Element.childrenWithClassName = function(element, className) {  
  return $A($(element).getElementsByTagName('*')).select(
    function(c) { return Element.hasClassName(c, className) });
}



if (!Element.makePositioned2)
{
  Element.makePositioned2=function(element) 
  	{
    	element = $(element);
	    element.style.position=(document.all)?'absolute':'fixed'	
      //  element._madePositioned = true;
	}	
}


//*********************************************************************************************************
//*********************************************************************************************************

if (!Array.removeByIndex)
{
   Array.prototype.removeByIndex = function(x) 
   {
      if( isNaN(x) || x > this.length )  return false;
      for( var i=0,n=0; i<this.length; i++ )   if( i!= x ) this[n++]=this[i];
      this.length-=1;
   }	
}


if (!Array.removeByValue) 
{
   Array.prototype.removeByValue = function(x) 
   {
      for ( var i = 0 ; i < this.length ; i++ )  if (this[i]==x) return this.removeByIndex(i)
   }
}

Array.prototype.call = function() {
  var args = arguments;
  this.each(function(f){ f.apply(this, args) });
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!String.trim){
	String.prototype.trim  =function()
	{
		return this.replace(/(^\s*)|(\s*$)/g,"")
	}
}
if (!String.isMail){
	String.prototype.isMail=function()
	{
		return /^\w+([-+._]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this);
	}
}

if(!String.isDate){
	String.prototype.isDate=function(){
		var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
		 if(r==null){
			  return false;
		 } 
		 var d= new Date(r[1], r[3]-1, r[4]); 
		 if(!(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4])){  
			  return false;
		 }
		 return true;	
	}
}

String.prototype.parseColor = function() {  
  var color = '#';  
  if(this.slice(0,4) == 'rgb(') {  
    var cols = this.slice(4,this.length-1).split(',');  
    var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);  
  } else {  
    if(this.slice(0,1) == '#') {  
      if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();  
      if(this.length==7) color = this.toLowerCase();  
    }  
  }  
  return(color.length==7 ? color : (arguments[0] || this));  
}
///////////////////////////////////////////////////////////////////////////////////////////
//格式化数字，比如 1234--->  1,234    345678  ---> 34,678  返回的一个字符串
Object.extend(Number.prototype, {
  format3: function() {
	var arr=$A(String(this).strip()).reverse(),i=0
	return this?$A(arr.inject("",function(a,b){return (++i%3==0)?(a+b+","):(a+b)})).reverse().join("").replace(/^\,?/,""):0
  },
  formatFloat : function( pos)
  {
	return Math.round(this*Math.pow(10, pos))/Math.pow(10, pos);
  }
});
//********************************************************************************************************************************

//简写document.createElement函数
if (typeof $C == 'undefined')
$C = function(t){
  return document.createElement(t)
};