var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function $(id){return document.getElementById(id);}
function $$(name){return document.getElementsByName(name);}
if(window.attachEvent==null && HTMLElement.prototype.children==null){HTMLElement.prototype.__defineGetter__("children",function(){var ret =[];for (var i=0;this.childNodes!=null && i<this.childNodes.length; i++){if (this.childNodes[i].nodeType == 1){ret.push( this.childNodes[i])}}return ret})}
if(document.getElementById&&!document.all){HTMLElement.prototype.__defineGetter__("innerText", function(){  return this.textContent;});HTMLElement.prototype.__defineSetter__( "innerText", function(sText){ this.textContent=sText;})}
if(window.HTMLElement) {
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){var r=this.ownerDocument.createRange();r.setStartBefore(this);var df=r.createContextualFragment(sHTML);this.parentNode.replaceChild(df,this);return sHTML;});
    HTMLElement.prototype.__defineGetter__("outerHTML",function(){var attr;var attrs=this.attributes;var str="<"+this.tagName.toLowerCase();for(var i=0;i<attrs.length;i++){attr=attrs[i];if(attr.specified)str+=" "+attr.name+'="'+attr.value+'"';}if(!this.canHaveChildren)return str+">";return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";});
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
  switch(this.tagName.toLowerCase()){
            case "area":
            case "base":
            case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
            return false;
        }
        return true;
     });
}

function JsLoader(){
	this.load=function(url){
		var ss=document.getElementsByTagName("script");
		for(i=0;i<ss.length;i++){if(ss[i].src && ss[i].src.indexOf(url)!=-1){this.onsuccess();return}}
		s=document.createElement("script");s.type="text/javascript";s.src=url;var head=document.getElementsByTagName("head")[0];head.appendChild(s);var self=this;
		s.onload=s.onreadystatechange=function(){if(this.readyState && this.readyState=="loading")return;self.onsuccess();}
		s.onerror=function(){head.removeChild(s);self.onfailure()}
	};
	this.onsuccess=function(){};
	this.onfailure=function(){};
}
var jl=new JsLoader();
jl.onfailure=function(){alert("文件载入失败！")};


var goSearch="";
var SearchText="";
var typeText;
var postUrl="ajax.ey";


function $arr(arrayLike){   
  for(var i=0,ret=[];i<arrayLike.length;i++) ret.push(arrayLike[i]); 
  return   ret   
}   
function toElement(evt){var toElement=document.all?window.event.srcElement:evt.target;return toElement}

//ajax通用方法
function createXmlHttp(){
  var ajaxObj=null;
  if(window.ActiveXObject)
  {
     ajaxObj=new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    if(window.XMLHttpRequest){
    ajaxObj=new XMLHttpRequest();
    }
  }
  return ajaxObj;
}

function postFile(pURL , pHandlerFunc) 
{
    pParameters = "";
    if (pURL.split("?").length >1)
        pParameters = pURL.split("?")[1];
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=pHandlerFunc;
      xmlhttp.open("POST", pURL, true);
      xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      xmlhttp.send(pParameters);
    } 
    else if (window.ActiveXObject) 
    { //IE 
      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
      if (xmlhttp) 
      {
         xmlhttp.onreadystatechange=pHandlerFunc;
         xmlhttp.open('POST', pURL, true);
         xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         xmlhttp.send(pParameters);
      }
    }
}

function imgOpacity(str,opValue,speed,Value,toValue){var myOpacity,Optemp=parseInt(is_ie?str.filters.alpha.opacity:document.defaultView.getComputedStyle(str,null).getPropertyValue('opacity')*100);clearInterval(myOpacity);myOpacity=setInterval(function(){if(Value<100){Optemp-=opValue}else if(Value==100){Optemp+=opValue}if((Value<100&&Optemp<=Value)||(Value==100&&Optemp>=Value)){if(is_ie){str.filters.alpha.opacity=Value}else{str.style.opacity=Value/100}clearInterval(myOpacity);return}if(is_ie){str.filters.alpha.opacity=Optemp}else{str.style.opacity=Optemp/100}},speed);str.onmouseout=function(){clearInterval(myOpacity);if(toValue==undefined){Value=100}else{Value=toValue}imgOpacity(this,opValue,speed,Value)}}

function Trim(str){return str.replace(/(^\s*)|(\s*$)/g, "")}
function LTrim(str){return str.replace(/(^\s*)/g,  "")}
function RTrim(str){return str.replace(/(\s*$)/g,  "")}
function AllTrim(str){return str.replace(/\s*/g,'')}


function GetMessageLength()
{
	var oEditor = FCKeditorAPI.GetInstance('Content') ;
	var oDOM = oEditor.EditorDocument ;
	var iLength ;

	if ( document.all )		// If Internet Explorer.
	{
		iLength = oDOM.body.innerText.length ;
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}
//	oEditor.InsertHtml('')
return iLength
}	

function is_number(){
if ((event.keyCode<48)||(event.keyCode>57)){
alert("\n\n请输入正确的数字.\n\n");
event.returnValue=false;
}
}

function ToNum(strValue,strInteger,goValue){
var str = strValue.value; 
    str = str.replace(/\１/g, "1");  
    str = str.replace(/\２/g, "2");  
    str = str.replace(/\３/g, "3");  
    str = str.replace(/\４/g, "4");  
    str = str.replace(/\５/g, "5");  
    str = str.replace(/\６/g, "6");  
    str = str.replace(/\７/g, "7");  
    str = str.replace(/\８/g, "8");  
    str = str.replace(/\９/g, "9");  
    str = str.replace(/\０/g, "0");  
    str = str.replace(/\一/g, "1");  
    str = str.replace(/\二/g, "2");  
    str = str.replace(/\三/g, "3");  
    str = str.replace(/\四/g, "4");  
    str = str.replace(/\五/g, "5");  
    str = str.replace(/\六/g, "6");  
    str = str.replace(/\七/g, "7");  
    str = str.replace(/\八/g, "8");  
    str = str.replace(/\九/g, "9");  
    str = str.replace(/\壹/g, "1");  
    str = str.replace(/\贰/g, "2");  
    str = str.replace(/\叁/g, "3");  
    str = str.replace(/\肆/g, "4");  
    str = str.replace(/\伍/g, "5");  
    str = str.replace(/\陆/g, "6");  
    str = str.replace(/\柒/g, "7");  
    str = str.replace(/\捌/g, "8");  
    str = str.replace(/\玖/g, "9");  
    str = str.replace(/\零/g, "0");  
    str = str.replace(/\。/g, ".");  
if (strInteger){str = str.replace(/\./g, '');}
if (isNaN(str)){alert('应用半角数字！');strValue.focus();return str=goValue;}
    return str; 
}

function Fgf(str){  
    str = str.replace(/\ /g, "|");  
    str = str.replace(/\　/g, "|");  
    str = str.replace(/\//g, "|");  
    str = str.replace(/\\/g, "|");  
    str = str.replace(/\，/g, "|");  
    str = str.replace(/\,/g, "|");   
    str = str.replace(/\。/g, "|");  
    str = str.replace(/\、/g, "|");   
    str = str.replace(/\./g, "|");
    str = str.replace(/\｜/g, "|");
    str = str.replace(/\／/g, "|"); 
    return str;  
}
function copycode(obj) {
	if(is_ie) {
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}
function Right(Str,n)
{
    return Str.substr(Str.length-n);
}
function Left(Str,n)
{
    return Str.substr(0,n);
}
function Mid(Str,Start,End)
{
    return Str.substring(Start,End);
}

function loadjscssfile(filename, filetype){ 
if (filetype=="js"){ //判断文件类型 
  var fileref=document.createElement('script')//创建标签 
  fileref.setAttribute("type","text/javascript")//定义属性type的值为text/javascript 
  fileref.setAttribute("src", filename)//文件的地址 
} 
else if (filetype=="css"){ //判断文件类型 
  var fileref=document.createElement("link") 
  fileref.setAttribute("rel", "stylesheet") 
  fileref.setAttribute("type", "text/css")  
  fileref.setAttribute("href", filename) 
} 
if (typeof fileref!="undefined") 
  document.getElementsByTagName("head")[0].appendChild(fileref) 
}  


var filesadded="" //保存已经绑定文件名字的数组变量 
function checkloadjscssfile(filename, filetype){
if (filesadded.indexOf("["+filename+"]")==-1){// indexOf判断数组里是否有某一项 
  loadjscssfile(filename, filetype) 
  filesadded+="["+filename+"]" //把文件名字添加到filesadded 
} 
} 





function removejscssfile(filename, filetype){

var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //得到文件类型使用的相应标签名

var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //得到属性名

//得到所有的用来连接外部文件的标签

var allsuspects=document.getElementsByTagName(targetelement)

for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove

if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)

allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()

}

}








function createjscssfile(filename, filetype){

if (filetype=="js"){ //if filename is a external Javascript file

var fileref=document.createElement('script')

fileref.setAttribute("type","text/javascript")

fileref.setAttribute("src", filename)

}

else if (filetype=="css"){ //if filename is an external CSS file

var fileref=document.createElement("link")

fileref.setAttribute("rel", "stylesheet")

fileref.setAttribute("type", "text/css")

fileref.setAttribute("href", filename)

}

return fileref

}


function replacejscssfile(oldfilename, newfilename, filetype){

var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using

var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for

var allsuspects=document.getElementsByTagName(targetelement)

for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove

if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){

   var newelement=createjscssfile(newfilename, filetype)

   allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])

}

}

}

function Move(str){$("Move_top").innerHTML="<img src=\"\/images\/icon\/loading.gif\" alt=\""+str+"\" border=\"0\" />";$("Move_bot").innerHTML=str;$("MoveCss").href="/common/css/Move.css"}


if(!window.attachEvent && window.addEventListener)
{
     Window.prototype.attachEvent=HTMLDocument.prototype.attachEvent=
     HTMLElement.prototype.attachEvent=function(en, func, cancelBubble)
     {
     var cb=cancelBubble?true:false;
     this.addEventListener(en.toLowerCase().substr(2), func, cb);
     };
     Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent=
     HTMLElement.prototype.detachEvent=function(en, func, cancelBubble)
     {
     var cb=cancelBubble?true:false;
     this.removeEventListener(en.toLowerCase().substr(2), func, cb);
     };
}
