window.onerror = function(){return true;}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, "");}
String.prototype.removeHTMLTags = function() { return this.replace(/<[^>]+>/gi, '').replace(/&nbsp;/gi,'');}
function trim(str) { return str.replace(/^\s+|\s+$/g, "");}
function w(s) {document.write(s);};
function a(s) {alert(s);};
function isIE() {var agt=navigator.userAgent.toLowerCase();var is_ie=(agt.indexOf("msie")!=-1 && document.all);if(is_ie)return true;return false;}
function isEmpty(theString){if((theString==null)||(theString.length==0))return true;return false;};
function isNumber(s){return(/^([0-9]\.)?[0-9]{1,32}$/g.test(s.trim()));};
function isInt(s){ s+="";return(!(s.length<1 || isNaN(s) || parseInt(s,10) < 0 || parseFloat(s) > parseInt(s,10)));}
function getInt(s) {if(s.length<1 || isNaN(s)) return 0;return parseInt(s,10);}
function $(id) {if(typeof(id)=='object') return id;try {return document.getElementById(id);}catch(e){try{return document.getElementsByName(id)[0]}catch(e){return null;}}}
function $F(id) {
  var e = $(id);
  switch (e.tagName.toLowerCase()) {
    case 'input':{if(e.type.toLowerCase() =="checkbox" || e.type.toLowerCase() =="radio") return e.checked ? e.value : '';return e.value;}
    case 'textarea':return e.value;
    case 'select':{var index = e.selectedIndex;return index >= 0 ? (e.options[index].value) : '';}
  }
}
function include(sFileName){ 
  var ss = document.getElementsByTagName('script');
  for(var i=0;i<ss.length;i++){if(ss[i].src.toLowerCase()==sFileName.toLowerCase()) return;}  
		document.write('<scr'+'ipt language = "JavaScript" src="'+ sFileName +'"></scri'+'pt>');
}
//Get an attribute from cookie
function getCookie(cookieName){
 if (document.cookie.length>0){ 
  var start=document.cookie.indexOf(cookieName + "=")
  if (start!=-1){ 
   start=start + cookieName.length+1 
   end=document.cookie.indexOf(";",start)
   if (end==-1) end=document.cookie.length
   return unescape(document.cookie.substring(start,end))
  } 
 }
 return null;
}

//Put an attribute into the cookie
function setCookie(cookieName,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=cookieName+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate);}

// Function Description: 返回字符串的实际长度, 一个汉字算2个长度
function strLen(str){return str.replace(/[^\x00-\xff]/g, "**").length;}

function sltInitValue(slt, initValue) {
  var v = initValue;
  var o = $(slt);
  for(var i=0;i<o.options.length;i++){if(o.options[i].value.toString()==v.toString()){o.options[i].selected=true;return;}}
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){obj.addEventListener(evType, fn, true);return true;}
 else if (obj.attachEvent){var r = obj.attachEvent("on"+evType, fn);return r;}
 else {return false;}
}


function scalePhoto(imgId,width,height){
  var img = $(imgId);
  if(img != null){
    var imgWidth = img.width;
    var imgHeight = img.height;  
    if(imgWidth>width&&imgHeight>height){
      //both image's width and height are larger than required one
      var widthRate = imgWidth/width;
      var heightRate = imgHeight/height;
      if(widthRate>heightRate){
        //use width to retrieve the image
        img.width=width;
        img.height=imgHeight*(width/imgWidth);
      }else{
        img.height=height;
        img.width=imgWidth*(height/imgHeight);
      }      
    }
    else if(imgWidth>width){
      //the image width lg than the required width
      img.width=width;
      img.height=imgHeight*(width/imgWidth);
    }
    else if(imgHeight>height){
      //the image height lg than the required
      img.height=height;
      img.width=imgWidth*(height/imgHeight);  
    }    
  }
}//end of scalePhoto()

/*
---------Example:
var ajax = new Ajax();
var fnShowChoose = function(xml) {
  if(xml.responseBody != v) {n.innerHTML = '请输入正确的验证码';n.className = 'noteError';return false;}
}
ajax.connect("GetCheckCode.asp", "GET", "", fnShowChoose);
*/
function Ajax(){
  var xmlhttp = false, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { alert(e);xmlhttp = false; }}}
  if (!xmlhttp) return null;

  //fnDone : 获取or提交信息完毕后执行函数
  this.connect = function(sURL, sMethod, sVars, fnDone, parObj) {
    if (!xmlhttp) return false;
    bComplete = false;
    sVars = (sVars == '') ? Math.random() : sVars + '&' + Math.random( );
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET") {
        xmlhttp.open(sMethod, sURL + '?' + sVars, true);
       // xmlhttp.setRequestHeader("Content-Type", "text/html;charset=GB2312");
        sVars = "";
      }
      else { // post      
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      }
      
      xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState == 4 && !bComplete) {bComplete = true;fnDone(xmlhttp, parObj);}};
      xmlhttp.send(sVars);
    }
    catch(e) { return false; }
    return true;
  };
  return this;
}

function rgb2hexColor(strRgb){ 
  var strColor; 
  var ch; 
  var arrColor = strRgb.substr(strRgb.indexOf("(") + 1, strRgb.indexOf(")") - 1).split(","); 
  strColor = "0x"; 
  for (var i = 0; i < 3; i++) { ch = parseInt(arrColor, 10).toString(16);strColor += ch.length == 2 ? ch : "0" + ch; } 
  return strColor;
}

function hex2rgb(hex) { 
  var r = (0xFF0000 & hex) >> 16;
  var g = (0x00FF00 & hex) >> 8;
  var b = (0x0000FF & hex);
  return "rgb(" + r + "," + g + "," + b + ")";
}

function getPoss(el,sTOp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sTOp];
  //d = (el.offsetParent);
  //if(d==null) {if(el.id)a(el.id); else {if(el.className)a(el.className); else a(el.tagName)}; a(iPos)}
  
		el = el.offsetParent;

	} 
	return iPos;
}

function showw(el,idd,text ) {
	var m = $(idd);
 if(text)m.innerHTML = text;
	m.style.left = getPoss(el,"Left") -5 + "px";
	m.style.top = getPoss(el,"Top") + el.offsetHeight -4+ "px";
 if(m.style.position=='')m.style.position='absolute';
	m.style.display="block";
}
function disp(idd){document.getElementById(idd).style.display="none";}

function chgWrapBgColor(e, color){var o = e || event.srcElement || event.target;o.style.backgroundColor = color;}

function closeWin() {window.opener = null;window.close();}
function openWin_link(link) {
 var a = document.createElement('A');
 a.href = link;
 a.target = '_blank';
 a.style.visibility = 'hidden';
 document.body.appendChild(a);
 a.click();
}

function hidden_link(link) {
 var a = document.createElement('A');
 a.href = link;
 a.target = '_self';
 a.style.visibility = 'hidden';
 document.body.appendChild(a);
 a.click();
}


function showInputTip(e, text) {
  var o = e || $(e) || event.srcElement || event.target;
}

function loadJs(file){
  var scriptTag = document.getElementById('loadScript');
  var head = document.getElementsByTagName('head').item(0)
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
  script.type = 'text/javascript';
  script.id = 'loadScript';
  head.appendChild(script)
}

function preloadImg(url) {var img= new Image();img.src=url;}

//检查是否有选中，若无选中返回false
function chkHasSlted(){
 var n=arguments[0] || 'cbxID';
 var es=document.getElementsByName(n);
 for(var i=0;i<es.length;i++){if(es[i].checked == true) return true;}
 return false;
}
//选中/
function sltAll(){
  var e=event.srcElement || window.event.target || $('cbxSltAll');
  var frm=arguments[0] || document.forms[0];
  var els=frm.getElementsByTagName('input');
  for (var i=0;i<els.length;i++ ){
   if(els[i].type=='checkbox'&&els[i].name!=e.name)els[i].checked=e.checked;
  }
}