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 $h(id) {$(id).style.display='none';}
function $s(id) {$(id).style.display='block';}
function $cs(id,c){$(id).className=c;}
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 hasClassName(element,className){
  if (!(element = $(element))) return;
  var elementClassName = element.className;
  if (elementClassName.length == 0) return false;
  if (elementClassName == className || elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) return true;
  return false;
}
function addClass(elem,className){
 if (elem.nodeType == 1 && !hasClassName( elem,className ) ) elem.className += (elem.className ? " " : "") + className;
}
function include(sFileName){ 
  var ss = document.getElementsByTagName('script');
  for(var i=0;i<ss.length;i++){if(ss[i].src.toLowerCase()==sFileName.toLowerCase()) return;}  
  w('<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;
}
function getDomain(){var d=document.domain;var A=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;if(!A.test(d)){if(d!="localhost"){return"zbinfos.com"}else{return""}}return d}
//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 chgBgColor(e,flag) {if(isIE())e.style.backgroundColor=(flag==1?'#FFFF66':'white');else e.style.backgroundColor=(flag==1? hex2rgb(0xe3f5ff):'white');}

function scalePhoto(imgId,width,height){
  var img = $(imgId);
  if(img != null){
    var imgWidth = img.width;
    var imgHeight = img.height;
    if(imgWidth==0 || imgHeight==0) {
      var oImg = new Image();
      oImg.src = img.src;
      if(oImg.readyState=='complete') {imgWidth=oImg.width;imgHeight=oImg.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 closeWin() {window.opener = null;window.close();}
function openWin_link(link) {createHref(link,'_blank');}
function hidden_link(link) {createHref(link,'_self');}
function createHref(link) {
  var a = document.createElement('A');
  a.href = link;
  a.target = '_blank';
  a.style.visibility = 'hidden';
  document.body.appendChild(a);
  a.click();
}
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 oFrm=arguments[0] || document.forms[0] || $('form1');
  var els=document.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;
}

/* 日期相关  */
//判断是否是正确的日期,sDate必须形如 2008-02-08 或者 2008-2-8,中间连接符-可替换为其他
function isDateString(sDate){ 
  var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
  var iaDate = new Array(3);
  var year, month, day;
  if (arguments.length != 1) return false;
  if(sDate.length<8||sDate.length>10) return false;
  year = parseFloat(sDate.substr(0,4));
  if(sDate.length==10){month = parseFloat(sDate.substr(5,2));day=parseFloat(sDate.substr(8,2));}
  else{month = parseFloat(sDate.substr(5,1));day=parseFloat(sDate.substr(7,1));}

  if (year < 1900 || year > 2100) return false;
  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
  if (month < 1 || month > 12) return false;
  if (day < 1 || day > iaMonthDays[month - 1]) return false;
  return true;
}

function formatDateTime(date,format){
  var str = format;
  var Week = ['日','一','二','三','四','五','六'];

  str=str.replace(/yyyy|YYYY/,date.getFullYear());
  str=str.replace(/yy|YY/,(date.getYear() % 100)>9?(date.getYear() % 100).toString():'0' + (date.getYear() % 100));
  var m = date.getMonth()+1;
  str=str.replace(/MM/,m>9?m.toString():'0' + m);
  str=str.replace(/M/g,m);

  str=str.replace(/w|W/g,Week[date.getDay()]);

  str=str.replace(/dd|DD/,date.getDate()>9?date.getDate().toString():'0' + date.getDate());
  str=str.replace(/d|D/g,date.getDate());

  str=str.replace(/hh|HH/,date.getHours()>9?date.getHours().toString():'0' + date.getHours());
  str=str.replace(/h|H/g,date.getHours());
  str=str.replace(/mm/,date.getMinutes()>9?date.getMinutes().toString():'0' + date.getMinutes());
  str=str.replace(/m/g,date.getMinutes());

  str=str.replace(/ss|SS/,date.getSeconds()>9?date.getSeconds().toString():'0' + date.getSeconds());
  str=str.replace(/s|S/g,date.getSeconds());

  return str;
}

function getPageSize(){
  var xs, ys;//xScroll,ys;
  var d=document.body;
  var dd=document.documentElement;
  var w=window;
  var ww,wh;//windowWidth, windowHeight;
  var pw,ph;//pageWidth,pageHeight
  if (w.innerHeight && w.scrollMaxY){xs = d.scrollWidth;ys = w.innerHeight + w.scrollMaxY;}
  else if (d.scrollHeight > d.offsetHeight){xs = d.scrollWidth;ys = d.scrollHeight;}
  else{xs = d.offsetWidth;ys = d.offsetHeight;}
  
  if (self.innerHeight){ww = self.innerWidth;wh = self.innerHeight;}
  else if (dd && dd.clientHeight){ww = dd.clientWidth;wh = dd.clientHeight;}
  else if (d){ww = d.clientWidth;wh = d.clientHeight;}
  if(ys<wh)ph = wh; else ph = ys;
  if(xs<ww)pw = ww; else pw = xs;
  return [pw,ph,ww,wh];
}
