﻿/********************\
---------------------
| name:common.js    |
| author:lixiaoyu   | 
| version:v3.5      |
| update:2008-10-29 |
---------------------
\********************/
//浏览器辨别
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_ie6 = userAgent.indexOf('msie 6.0') != -1 && !is_opera;
var is_ie7 = userAgent.indexOf('msie 7.0') != -1 && !is_opera;
//获取元素
function $(id) { return document.getElementById(id); }
//剔除两端空格
String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
}
Date.fromString = function(str) { return new Date(Date.parse(str.replace(/\-/g, '/'))); }

//退出页面
function exit(win) {
  if (!win) win = window;
  if (is_ie) {
    win.opener = null;
    win.top.close();
  }
  else if (is_opera)
    win.top.close();
  else
    win.top.location.replace = "about:blank";
}
//设置cookie
function SetCookie(key, value, expires) {
  if (expires)
    document.cookie = key + "=" + escape(value) + ";expires=" + expires.toGMTString();
  else {
    var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    document.cookie = key + "=" + escape(value) + ";expires=" + now.toGMTString();
  }
}
//获取cookie
function GetCookie(key) {
  var arr = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)"));
  if (arr != null) return unescape(arr[2]); return null;
}
//删除cookie
function DelCookie(name) {
  var now = new Date();
  now.setTime(now.getTime() - 1);
  var cval = GetCookie(name);
  if (cval != null) {
    document.cookie = name + "=" + cval + ";expires=" + now.toGMTString();
  }
}
//添加到收藏
function addBookMark(title) {
  var tit = (title) ? title : document.title;
  var url = document.location.href;
  if (window.sidebar)
    window.sidebar.addPanel(tit, url, "");
  else if (is_opera) {
    var tmpa = document.createElement("a");
    tmpa.setAttribute("rel", "sidebar");
    tmpa.setAttribute("href", url);
    tmpa.setAttribute("title", tit);
    tmpa.click();
  }
  else
    window.external.AddFavorite(url, tit);
}
//MessageBox
function $iframe(url, width, height, isShowBack, isAutoHeight, isAllowtransparency, isFixed, x, y, scrolling) {
  if (document.getElementById("_iframe_dfull")) return;
  var ds = getDocumentSize();
  var sels = document.getElementsByTagName("select")
  for (var i = 0; i < sels.length; i++) {
    var sel = sels[i];
    if (sel.style.visibility != "hidden") {
      sel.style.visibility = "hidden";
      sel.$iframe = true;
    }
  }
  var dfrm = document.createElement("div");
  dfrm.id = "_iframe_dfrm";
  if (isFixed && !is_ie6) {
    dfrm.style.cssText = "z-index:97999;position:fixed";
    dfrm.style.top = (y ? y : (ds.documentAvailHeight / 2 - height / 2)) + "px";
    dfrm.style.left = (x ? x : (ds.documentAvailWidth / 2 - width / 2)) + "px";
  } else {
    dfrm.style.cssText = "z-index:97999;position:absolute";
    dfrm.style.top = (y ? y : (ds.documentAvailHeight / 2 + ds.dcoumentScrollHeight - height / 2)) + "px";
    dfrm.style.left = (x ? x : (ds.documentAvailWidth / 2 + ds.documentScrollWidth - width / 2)) + "px";
  }
  url = url.indexOf("?") == -1 ? (url + "?randcode=" + Math.random()) : url + "&randcode=" + Math.random();
  dfrm.innerHTML = "<iframe id=\"_iframe_iframe\" name=\"_iframe_iframe\" " + (isAutoHeight ? "onload='autoIFHeight(this)'" : "") + (isAllowtransparency ? " allowtransparency" : "") + " frameborder=\"0\" height=\"" + height + "\" width=\"" + width + "\" scrolling=\"" + (scrolling ? scrolling : "no") + "\"></iframe>";
  if (isShowBack) {
    var dfull = document.createElement("div");
    dfull.id = "_iframe_dfull";
    dfull.style.cssText = "z-index:96999;position:absolute;left:0;top:0;filter:alpha(opacity=50);opacity:0.5;background:#ddd";
    document.body.appendChild(dfull);
    dfull.style.height = ds.documentHeight + "px";
    dfull.style.width = ds.documentWidth + "px";
  }
  document.body.appendChild(dfrm);
  document.getElementById("_iframe_iframe").src = url;
}
function $iframeClose() {
  if (document.getElementById("_iframe_dfrm")) {
    document.body.removeChild(document.getElementById("_iframe_dfrm"));
    if (document.getElementById("_iframe_dfull"))
      document.body.removeChild(document.getElementById("_iframe_dfull"));

    var sels = document.getElementsByTagName("select");
    for (var i = 0; i < sels.length; i++) {
      var sel = sels[i];
      if (sel.style.visibility == "hidden" && sel.$iframe) {
        sel.style.visibility = "visible";
        sel.$iframe = false;
      }
    }
  }
}
function $alert(text, title, iconUrl, okHandle, cancelHandle, yesHandle, noHandle, isEnglish) {
  text = text ? "\"" + text + "\"" : null;
  title = title ? "\"" + title + "\"" : "\"系统温馨提示\"";
  iconUrl = iconUrl ? "\"" + iconUrl + "\"" : "\"/Img/alertDiv.gif\"";
  okHandle = okHandle ? "\"" + okHandle + "\"" : null;
  cancelHandle = cancelHandle ? "\"" + cancelHandle + "\"" : null;
  yesHandle = yesHandle ? "\"" + yesHandle + "\"" : null;
  noHandle = noHandle ? "\"" + noHandle + "\"" : null;
  isEnglish = isEnglish ? "\"" + isEnglish + "\"" : null;
  setTimeout("$alert2(" + text + "," + title + "," + iconUrl + "," + okHandle + "," + cancelHandle + "," + yesHandle + "," + noHandle + "," + isEnglish + ")", 0);
}
function $alert2(text, title, iconUrl, okHandle, cancelHandle, yesHandle, noHandle, isEnglish) {
  okHandle = okHandle ? escape(okHandle) : null;
  cancelHandle = cancelHandle ? escape(cancelHandle) : null;
  yesHandle = yesHandle ? escape(yesHandle) : null;
  noHandle = noHandle ? escape(noHandle) : null;
  okHandle = (okHandle || cancelHandle || yesHandle || noHandle) ? okHandle : true;
  title = title ? title : "\u7cfb\u7edf\u63d0\u793a";
  text = text ? text : "";
  iconUrl = iconUrl ? iconUrl : null;
  var okText = "\u786e\u5b9a";
  var yesText = "\u662f";
  var noText = "\u5426";
  var cancelText = "\u53d6\u6d88";
  if (isEnglish) {
    var okText = "OK";
    var yesText = "Yes";
    var noText = "No";
    var cancelText = "Cancel";
  }
  if (document.getElementById("_alert_dfull")) return;
  var ds = getDocumentSize();
  var sels = document.getElementsByTagName("select");
  for (var i = 0; i < sels.length; i++) {
    var sel = sels[i];
    if (sel.style.visibility != "hidden") {
      sel.style.visibility = "hidden";
      sel.$alert = true;
    }
  }
  var dfull = document.createElement("div");
  dfull.id = "_alert_dfull";
  dfull.style.cssText = "z-index:998;position:absolute;left:0;top:0;filter:alpha(opacity=50);opacity:0.5;background:#ddd";
  document.body.appendChild(dfull);
  dfull.style.height = ds.documentHeight + "px";
  dfull.style.width = ds.documentWidth + "px";
  var dfrm = document.createElement("div");
  dfrm.id = "_alert_dfrm";
  dfrm.style.cssText = "font-size:9pt;z-index:999;position:absolute;width:300px;background:#fff;border:1px solid #69f";
  dfrm.style.top = ds.documentAvailHeight / 2 + ds.dcoumentScrollHeight - 100 + "px";
  dfrm.style.left = ds.documentAvailWidth / 2 + ds.documentScrollWidth - 150 + "px";
  var tmpHtml = new stringBuilder("<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-top:1px solid #fff;border-bottom:1px solid #fff;border-left:1px solid #fff;width:100%;height:100%\">");
  tmpHtml.append("<tr><td valign=\"middle\" style=\"width:269px;cursor:move;padding-left:5px;height:25px;background-color:#cdf\">");
  tmpHtml.append(title);
  tmpHtml.append("</td><td align=\"center\" title=\"ESC\" valign=\"middle\" style=\"cursor:move;width:29px;background-color:#cdf;border-right:1px solid #fff;font-size:14pt;font-weight:bold;color:#f00;cursor:pointer\" onclick=\"$alertClose('");
  tmpHtml.append("')\">\u00d7</td></tr><tr><td colspan=\"2\" align=\"center\" valign=\"middle\" style=\"height:80px\">");
  if (iconUrl) {
    tmpHtml.append("<table cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;height:100%\"><tr><td align=\"center\" valign=\"center\" style=\"width:30%;background:url(");
    tmpHtml.append(iconUrl);
    tmpHtml.append(") no-repeat center center\">&nbsp;</td><td align=\"left\" valign=\"center\" style=\"width:70%;padding-right:10px\">");
    tmpHtml.append(text);
    tmpHtml.append("</td></tr></table>");
  } else {
    tmpHtml.append(text);
  }
  tmpHtml.append("</td></tr><tr><td colspan=\"2\" align=\"center\" valign=\"top\" style=\"height:35px\"><table cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%\"><tr><td width='50px'>&nbsp;</td>");
  if (okHandle) {
    tmpHtml.append("<td align=\"center\"><div style=\"width:60px;text-align:center;padding:3px;border:1px solid #cef;cursor:pointer;background-color:#eff\" onmouseover=\"this.style.backgroundColor='#dff'\" onmouseout=\"this.style.backgroundColor='#eff'\" onclick=\"$alertClose('");
    tmpHtml.append(okHandle);
    tmpHtml.append("')\">");
    tmpHtml.append(okText);
    tmpHtml.append("</div></td>");
  }
  if (yesHandle) {
    tmpHtml.append("<td align=\"center\"><div style=\"width:60px;text-align:center;padding:3px;border:1px solid #cef;cursor:pointer;background-color:#eff\" onmouseover=\"this.style.backgroundColor='#dff'\" onmouseout=\"this.style.backgroundColor='#eff'\" onclick=\"$alertClose('");
    tmpHtml.append(yesHandle);
    tmpHtml.append("')\">");
    tmpHtml.append(yesText)
    tmpHtml.append("</div></td>");
  }
  if (noHandle) {
    tmpHtml.append("<td align=\"center\"><div style=\"width:60px;text-align:center;padding:3px;border:1px solid #cef;cursor:pointer;background-color:#eff\" onmouseover=\"this.style.backgroundColor='#dff'\" onmouseout=\"this.style.backgroundColor='#eff'\" onclick=\"$alertClose('");
    tmpHtml.append(noHandle);
    tmpHtml.append("')\">");
    tmpHtml.append(noText)
    tmpHtml.append("</div></td>");
  }
  if (cancelHandle) {
    tmpHtml.append("<td align=\"center\"><div style=\"width:60px;text-align:center;padding:3px;border:1px solid #cef;cursor:pointer;background-color:#eff\" onmouseover=\"this.style.backgroundColor='#dff'\" onmouseout=\"this.style.backgroundColor='#eff'\" onclick=\"$alertClose('");
    tmpHtml.append(cancelHandle);
    tmpHtml.append("')\">");
    tmpHtml.append(cancelText);
    tmpHtml.append("</div></td>");
  }
  tmpHtml.append("<td width='50px'>&nbsp;</td></tr></table></td></tr></table>");
  dfrm.innerHTML = tmpHtml.toString();
  document.body.appendChild(dfrm);
  //Drag.load("_alert_dfrm");
  var evt = new documentKeyEvent();
  evt.Onkeydown = function() {
    if (evt.KeyCode == 27) {
      $alertClose(cancelHandle);
    }
  };
}
function popCover(zIndex) {
  if (!zIndex)
    zIndex = 997;
  if (document.getElementById("_cover_dfull"))
    return;
  var dfull = document.createElement("div");
  dfull.id = "_cover_dfull";
  dfull.style.cssText = "z-index:" + zIndex + ";position:absolute;left:0;top:0;filter:alpha(opacity=50);opacity:0.5;background:#ddd";
  document.body.appendChild(dfull);
  var ds = getDocumentSize();
  dfull.style.height = ds.documentHeight + "px";
  dfull.style.width = ds.documentWidth + "px";
}
function removeCover() {
  document.body.removeChild(document.getElementById("_cover_dfull"));
}
function $alertClose(handle) {
  if (document.getElementById("_alert_dfrm")) {
    document.body.removeChild(document.getElementById("_alert_dfrm"));
    document.body.removeChild(document.getElementById("_alert_dfull"));
    var sels = document.getElementsByTagName("select");
    for (var i = 0; i < sels.length; i++) {
      var sel = sels[i];
      if (sel.style.visibility == "hidden" && sel.$alert) {
        sel.style.visibility = "visible";
        sel.$alert = false;
      }
    }
    handle ? eval(unescape(handle)) : 0;
  }
}
//获取窗体相关大小
function getDocumentSize() {
  var dW, dH, dAW, dAH, sW, sH, sAW, sAH, dSW, dSH;
  dW = document.documentElement.scrollWidth;
  dAW = document.documentElement.clientWidth;
  sH = window.screen.height;
  sW = window.screen.width;
  dSH = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  dSW = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  sAH = window.screen.availHeight;
  sAW = window.screen.availWidth;
  dH = Math.max(Math.max(document.body.scrollHeight, document.documentElement.clientHeight), document.documentElement.scrollHeight);
  if (navigator.userAgent.toLowerCase().indexOf('opera') != -1 && opera.version()) dAH = document.body.clientHeight;
  else dAH = document.documentElement.clientHeight;
  return { documentWidth: dW, documentAvailWidth: dAW, documentAvailHeight: dAH, documentHeight: dH, screenWidth: sW, screenHeight: sH, screenAvailWidth: sAW, screenAvailHeight: sAH, dcoumentScrollHeight: dSH, documentScrollWidth: dSW };
}
//拖动对象
var Drag = {
  obj: null,
  init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
    o.onmousedown = Drag.start;
    o.hmode = bSwapHorzRef ? false : true;
    o.vmode = bSwapVertRef ? false : true;
    o.root = oRoot && oRoot != null ? oRoot : o;
    if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
    if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
    if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
    if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
    o.minX = typeof (minX) != 'undefined' ? minX : null;
    o.minY = typeof (minY) != 'undefined' ? minY : null;
    o.maxX = typeof (maxX) != 'undefined' ? maxX : null;
    o.maxY = typeof (maxY) != 'undefined' ? maxY : null;
    o.xMapper = fXMapper ? fXMapper : null;
    o.yMapper = fYMapper ? fYMapper : null;
    o.root.onDragStart = new Function();
    o.root.onDragEnd = new Function();
    o.root.onDrag = new Function();
  },
  load: function(id) {//自动初始化
    var o = $(id);
    var size = getDocumentSize();
    var maxW = size.documentWidth - o.offsetWidth;
    var maxH = size.documentHeight - o.offsetHeight;
    if (o.style.position != "absolute") {
      var xy = getPos(o);
      o.style.left = xy.x + "px";
      o.style.top = xy.y + "px";
    }
    Drag.init(o, null, 0, maxW, 0, maxH);
  },
  start: function(e) {
    var o = Drag.obj = this;
    e = Drag.fixE(e);
    var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
    var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
    o.root.onDragStart(x, y);
    o.lastMouseX = e.clientX;
    o.lastMouseY = e.clientY;
    if (o.hmode) {
      if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
      if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
    } else {
      if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
      if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
    }
    if (o.vmode) {
      if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
      if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
    } else {
      if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
      if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
    }
    document.onmousemove = Drag.drag;
    document.onmouseup = Drag.end;
    return false;
  },
  drag: function(e) {
    e = Drag.fixE(e);
    var o = Drag.obj;
    var ey = e.clientY;
    var ex = e.clientX;
    var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
    var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
    var nx, ny;
    if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
    if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
    if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
    if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
    nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
    ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
    if (o.xMapper) nx = o.xMapper(y)
    else if (o.yMapper) ny = o.yMapper(x)
    Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
    Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
    Drag.obj.lastMouseX = ex;
    Drag.obj.lastMouseY = ey;
    Drag.obj.root.onDrag(nx, ny);
    return false;
  },
  end: function() {
    document.onmousemove = null;
    document.onmouseup = null;
    Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
    Drag.obj = null;
  },
  fixE: function(e) {
    if (typeof (e) == 'undefined') e = window.event;
    if (typeof (e).layerX == 'undefined') e.layerX = e.offsetX;
    if (typeof (e).layerY == 'undefined') e.layerY = e.offsetY;
    return e;
  }
};
//键盘事件
function documentKeyEvent() {
  var me = this;
  this.Event = null;
  this.SrcElement = null;
  this.SrcElementID = null;
  this.Type = null;
  this.KeyCode = null;
  this.AltKey = false;
  this.ShiftKey = false;
  this.CtrlKey = false;
  this.Onkeydown = new Function();
  //TODO
  function _init(e) {
    me.Event = e ? e : window.event;
    me.SrcElement = me.Event.srcElement ? me.Event.srcElement : me.Event.target;
    me.SrcElementID = me.SrcElement.id;
    me.Type = me.Event.type;
    me.KeyCode = me.Event.keyCode;
    me.AltKey = me.Event.altKey;
    me.ShiftKey = me.Event.shiftKey;
    me.CtrlKey = me.Event.ctrlKey;
  }
  this._start = function(e) {
    _init(e);
    switch (me.Type) {
      case "keydown": me.Onkeydown(); break;
    }
  };
  document.onkeydown = this._start;
  //TODO
}

//StringBuilder对象
function stringBuilder(s) {
  this.b = new Array(s);
  this.append = function(s) { this.b.push(s); };
  this.count = function() { return this.b.length; };
  this.remove = function(index, count) { this.b.splice(index, count); };
  this.toString = function() { return this.b.join(""); };
}
//可用于QueryString与键值对转换
function parseQueryString(s) {
  if (!s)
    s = window.location.search;
  if (s.substr(0, 1) == "?" || s.substr(0, 1) == "&")
    s = s.substr(1, s.length);
  var nvc = new nameValueCollection();
  nvc.init(s);
  return nvc;
}
//xAttribute v2.0
function xAttribute() {
  this.keys = new Array();
  this.values = new Array();
  this.init = function(s) {
    if (s && s.indexOf("=") != -1) {
      var kvs = s.split("&");
      for (var i = 0; i < kvs.length; i++) {
        var kv = kvs[i].split("=");
        this.add(kv[0], kv[1]);
      }
    }
  };
  this.getValue = function(key) {
    for (var i = 0; i < this.keys.length; i++) {
      if (this.keys[i] == key) return this.values[i];
    }
    return null;
  };
  this.findKey = function(key) {
    for (var i = 0; i < this.keys.length; i++) {
      if (this.keys[i] == key) return i;
    } return -1;
  };
  this.findValue = function(value) {
    for (var i = 0; i < this.values.length; i++) {
      if (this.values[i] == value) return i;
    }
    return -1;
  };
  this.setValue = function(key, value) {
    var idx = this.findKey(key); if (idx != -1)
      this.values[idx] = value; else {
      this.keys.push(key); this.values.push(value);
    }
  };
  this.add = function(key, value) {
    var idx = this.findKey(key); if (idx != -1)
      this.values[idx] = this.values[idx] + "," + value; else {
      this.keys.push(key); this.values.push(value);
    }
  };
  this.remove = function(key) {
    var idx = this.findKey(key);
    if (idx != -1) {
      this.keys.splice(idx, 1); this.values.splice(idx, 1);
    }
  };
  this.clear = function() {
    this.keys = new Array();
    this.values = new Array();
  };
  this.count = function() {
    return this.keys.length;
  };
  this.toString = function() {
    var sb = new stringBuilder();
    if (this.keys.length == 0) return "";
    sb.append(this.keys[0]);
    sb.append("=");
    sb.append(this.values[0].replace(/\&/g, "%26"));
    for (var i = 1; i < this.keys.length; i++) {
      sb.append("&");
      sb.append(this.keys[i]);
      sb.append("=");
      sb.append(this.values[i].replace(/\&/g, "%26"));
    }
    return sb.toString();
  };
} //获取Get值
function getRequestValue(key) {
  return parseQueryString().getValue(key);
}
//键值对对象，注意，键值都区分大小写
function nameValueCollection() {
  this.keys = new Array();
  this.values = new Array();
  this.init = function(s) {
    if (!s) {
      this.keys = new Array();
      this.values = new Array();
    } else {
      var kvs = s.split("&");
      for (var i = 0; i < kvs.length; i++) {
        var kv = kvs[i].split("=");
        this.add(kv[0], kv[1]);
      }
    }
  };
  this.getValue = function(key) {
    for (var i = 0; i < this.keys.length; i++) {
      if (this.keys[i] == key)
        return this.values[i];
    }
    return null;
  };
  this.findKey = function(key) {
    for (var i = 0; i < this.keys.length; i++) {
      if (this.keys[i] == key)
        return i;
    }
    return -1;
  };
  this.findValue = function(value) {
    for (var i = 0; i < this.values.length; i++) {
      if (this.values[i] == value)
        return i;
    }
    return -1;
  };
  this.setValue = function(key, value) {
    var idx = this.findKey(key);
    if (idx != -1)
      this.values[idx] = value;
    else {
      this.keys.push(key);
      this.values.push(value);
    }
  };
  this.add = function(key, value) {
    var idx = this.findKey(key);
    if (idx != -1)
      this.values[idx] = this.values[idx] + "," + value;
    else {
      this.keys.push(key);
      this.values.push(value);
    }
  };
  this.remove = function(key) {
    var idx = this.findKey(key);
    if (idx != -1) {
      this.keys.splice(idx, 1);
      this.values.splice(idx, 1);
    }
  };
  this.clear = function() {
    this.init();
  };
  this.count = function() { return this.keys.length; };
  this.toQueryString = function() {
    var sb = new stringBuilder();
    for (var i = 0; i < this.keys.length; i++) {
      sb.append("&");
      sb.append(this.keys[i]);
      sb.append("=");
      sb.append(this.values[i]);
    }
    return sb.toString();
  };
}

function xForm(action, method, target, divId) {
  this._values = new xAttribute();
  this.divForm = $(divId);
  this.action = action;
  this.method = method;
  this.target = target;
  this.add = function(name, value) { this._values.setValue(name, value); };
  this.submit = function() {
    if ($("__xForm__"))
      return;
    var form = document.createElement("form");
    form.style.display = "none";
    if (this.divForm) {
      var tmp;
      var inputs = this.divForm.getElementsByTagName("input");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp)
          this.add(tmp, inputs[i].value);
      }
      inputs = this.divForm.getElementsByTagName("select");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp)
          this.add(tmp, inputs[i].value);
      }
      inputs = this.divForm.getElementsByTagName("textarea");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp)
          this.add(tmp, inputs[i].value);
      }
    }
    for (var i = 0; i < this._values.keys.length; i++) {
      tmp = document.createElement("input");
      tmp.type = "hidden";
      tmp.name = this._values.keys[i];
      tmp.value = this._values.values[i];
      form.appendChild(tmp);
    }
    document.body.appendChild(form);
    form.method = this.method ? this.method : "post";
    form.id = "__xForm__";
    form.action = this.action;
    form.target = this.target ? this.target : "_self";
    form.submit();
    document.body.removeChild(form);
  };
}
//Post形式跳转页面
function postUrl(url, target, nvc) {
  var form = document.createElement("form");
  form.method = "post";
  form.id = "__XPostform__";
  form.action = url;
  form.target = target;
  form.style.display = "none";
  var field = null;
  for (var i = 0; i < nvc.keys.length; i++) {
    field = document.createElement("input");
    field.type = "hidden";
    field.name = nvc.keys[i];
    field.value = nvc.values[i];
    form.appendChild(field);
  }
  document.body.appendChild(form);
  setTimeout("document.getElementById('__XPostform__').submit();document.body.removeChild(document.getElementById('__XPostform__'));", 0);
}
//html编码
function htmlEncode(t) {
  return t.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
//html解码
function htmlDecode(t) {
  return t.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}
//兼容的透明度
function SetOpacity(obj, opacity) { if (opacity > 1) opacity = opacity / 100; try { obj.style.opacity = opacity; } catch (e) { } try { if (obj.filters) { obj.filters("alpha").opacity = opacity * 100; } } catch (e) { } }
//iframe自适应高度
function autoIFHeight(obj) {
  if (!obj)
    obj = getSrcElement();
  if (document.getElementById) {
    if (obj) {
      if (obj.contentDocument && obj.contentDocument.body.offsetHeight) {
        obj.height = obj.contentDocument.body.offsetHeight;
        if (obj.contentDocument.documentElement) {
          obj.height = obj.contentDocument.documentElement.scrollHeight;
        }
      } else if (document.frames[obj.name].document && document.frames[obj.name].document.body.scrollHeight) {
        obj.height = document.frames[obj.name].document.body.scrollHeight;
      }
    }
  }
}
//验证金钱([0到]10位之间的可0正实数)
function checkMoney(v, mustFill) {
  if (v == null) return false;
  if (!mustFill && v.length == 0)
    return true;
  else if (/^\d*(\.\d*)?$/.test(v) && !isNaN(parseFloat(v)) && parseFloat(v) >= 0 && parseFloat(v) <= 99999999)
    return true;
  else
    return false;
}
//验证整数数字
function checkNumber(v, mustFill, min, max) {
  if (v == null) return false;
  if (!mustFill && v.length == 0)
    return true;
  v = parseInt(v);
  if (isNaN(v) || v < min || v > max)
    return false;
  else
    return true;
}
//验证实数
function checkDecimal(v, mustFill, min, max) {
  if (v == null) return false;
  if (!mustFill && v.length == 0)
    return true;
  v = parseFloat(v);
  if (isNaN(v) || v < min || v > max)
    return false;
  else
    return true;
}
//验证邮箱([0到]50位之间的邮箱格式)
function checkEmail(v, mustFill) {
  if (v == null) return false;
  if (!mustFill && v.trim().length == 0)
    return true;
  else if (v.length > 50 || !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(v))
    return false;
  else
    return true;
}
//验证手机号码([0位或]11位有效手机号码)
function checkMobile(v, mustFill) {
  if (v == null) return false;
  if (/^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1})+\d{8})$/.test(v))
    return true;
  else if (!mustFill && v.length == 0)
    return true;
  else
    return false;
}
//验证电话号码([0位或]4~20位由数字+-组成的号码)
function checkTelephone(v, mustFill) {
  if (v == null) return false;
  if (!mustFill && v.trim().length == 0) return true;
  if (v.length < 7 || v.length > 18 || !/^([\d-+]*)$/.test(v))
    return false;
  else
    return true;
}
//验证身份证号码([0位或]有效身份证号码)
function checkIdCard(sNo, mustFill) {
  if (sNo == null) return false;
  sNo = sNo.toString();
  if (sNo.length == 0 && !mustFill) return true;
  if (sNo.length == 18) {
    var a, b, c;
    if (isNaN(sNo.substr(0, 17))) {
      return false;
    }
    a = parseInt(sNo.substr(0, 1)) * 7 + parseInt(sNo.substr(1, 1)) * 9 + parseInt(sNo.substr(2, 1)) * 10;
    a = a + parseInt(sNo.substr(3, 1)) * 5 + parseInt(sNo.substr(4, 1)) * 8 + parseInt(sNo.substr(5, 1)) * 4;
    a = a + parseInt(sNo.substr(6, 1)) * 2 + parseInt(sNo.substr(7, 1)) * 1 + parseInt(sNo.substr(8, 1)) * 6;
    a = a + parseInt(sNo.substr(9, 1)) * 3 + parseInt(sNo.substr(10, 1)) * 7 + parseInt(sNo.substr(11, 1)) * 9;
    a = a + parseInt(sNo.substr(12, 1)) * 10 + parseInt(sNo.substr(13, 1)) * 5 + parseInt(sNo.substr(14, 1)) * 8;
    a = a + parseInt(sNo.substr(15, 1)) * 4 + parseInt(sNo.substr(16, 1)) * 2;
    b = a % 11;
    if (b == 2) {
      c = sNo.substr(17, 1).toUpperCase();
    }
    else {
      c = parseInt(sNo.substr(17, 1));
    }
    switch (b) {
      case 0: if (c != 1) { return false; } break;
      case 1: if (c != 0) { return false; } break;
      case 2: if (c != "X") { return false; } break;
      case 3: if (c != 9) { return false; } break;
      case 4: if (c != 8) { return false; } break;
      case 5: if (c != 7) { return false; } break;
      case 6: if (c != 6) { return false; } break;
      case 7: if (c != 5) { return false; } break;
      case 8: if (c != 4) { return false; } break;
      case 9: if (c != 3) { return false; } break;
      case 10: if (c != 2) { return false; };
    }
  }
  else {
    if (isNaN(sNo)) { return false; }
  }
  switch (sNo.length) {
    case 15: if (checkDateTime(sNo.substr(6, 2) + '-' + sNo.substr(8, 2) + '-' + sNo.substr(10, 2))) { return true; }
    case 18: if (checkDateTime(sNo.substr(6, 4) + '-' + sNo.substr(10, 2) + '-' + sNo.substr(12, 2))) { return true; }
  }
  return false;
}
//验证日期
function checkDateTime(v, mustFill, min, max) {
  if (v == null) return false;
  if (!mustFill && v.length == 0)
    return true;
  v = Date.parse(v.replace(/\-/g, '/'));
  if (isNaN(v) || v < min || v > max)
    return false;
  else
    return true;
}
//验证用户名合法性
//1.只能由字母或汉字开头
//2.只能由字母、数字或汉字结尾
//3.只能由字母、数字、下划线或汉字组成
//4.以汉字开头，用户名最少2个字符，最多10个字符
//5.以字母开头，用户名最少4个字符，最多20个字符
function checkLoginName(v) {
  return /^([a-zA-Z]\w{2,19}[a-zA-Z0-9]|[\u4E00-\u9FA5][\u4E00-\u9FA5a-zA-Z0-9]{1,9})$/.test(v);
}
//计算日期差unit:1-day
function diffDate(d1, d2, unit) {
  if (isNaN(Date.parse(d1)) || isNaN(Date.parse(d2))) return -1;
  switch (unit) {
    default:
    case 1:
      return parseInt(Math.abs(d1.getTime() - d2.getTime()) / 86400000);
  }
}
//格式输出价格
function clearPrice(d) {
  var result = parseFloat(d);
  if (isNaN(result) || result < 0)
    return "--";
  else
    return (Math.round(result * 100) / 100).toString();
}

//格式输出百分比
function clearPercent(d) {
  var result = parseFloat(d);
  if (isNaN(result) || result < 0)
    return "--";
  else
    return (Math.round(result * 1000) / 10).toString();
}
function clippingString2(s, count) {

}
//裁剪字符串
function clippingString(s, count, unitByByte, autoSuspension) {
  if (!count || count < 1 || !s)
    return "";
  if (unitByByte) {
    var bytec = 0;
    for (var i = 0; i < s.length; i++) {
      bytec += (s.charCodeAt(i) < 0xFF) ? 1 : 2;
      if (bytec >= count)
        if (autoSuspension)
        return s.substr(0, i) + "…";
      else
        return s.substr(0, i);
    }
    return s;
  }
  else {
    if (s.length <= count)
      return s;
    if (autoSuspension)
      return s.substr(0, count) + "…";
    else
      return s.substr(0, count);
  }
}
//json解析
Json = { encode: function(o) { var s = [], p = {}, c = ""; p.isArr = o instanceof Array; if (p.isArr) { p.l = "["; p.r = "]" } else { p.l = "{"; p.r = "}" }; for (k in o) { if (!p.isArr) c = '"' + k + '":'; else c = ""; switch (typeof (o[k])) { case "object": if (o[k] instanceof Object) c += arguments.callee(o[k]); else c += o[k]; break; case "string": c += '"' + o[k].replace("\\", "\\\\").replace('"', '\\"') + '"'; break; case "number": case "boolean": case "null": c += o[k]; break; default: continue }; s.push(c) }; return p.l + s.join(",") + p.r },
  decode: function(str) { var k; try { k = eval('(' + str + ')'); return (typeof k == "object") ? k : '' } catch (e) { return '' } }
};
function JsonDateToJsDate(jsonDate) {
  return new Date(+/\d+/.exec(jsonDate)[0]);
}
//注册事件
function addEvent(oElement, sEvent, func) {
  if (oElement.addEventListener) {
    oElement.addEventListener(sEvent, func, false);
  } else if (oElement.attachEvent) {
    oElement.attachEvent("on" + sEvent, func);
  } else {
    oElement["on" + sEvent] = func;
  }
}
//注册页面加载后事件
function PageOnload(fun) {
  addEvent(window, "load", fun);
}
//注销事件
function removeEvent(oElement, sEvent, func) {
  if (oElement.removeEventListener) {
    oElement.removeEventListener(sEvent, func, false);
  } else if (oElement.detachEvent) {
    oElement.detachEvent("on" + sEvent, func);
  } else {
    oElement["on" + sEvent] = null;
  }
}
//获取事件参数
function getEvent() {
  if (window.event) return window.event;
  var func = getEvent.caller;
  var arg0 = null;
  while (func != null) {
    arg0 = func.arguments[0];
    if (arg0 && ((arg0.constructor == window.top.Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)))
      return arg0;
    func = func.caller;
  }
  return null;
}
//获取事件源元素
function getSrcElement() {
  var e = getEvent();
  return e.srcElement ? e.srcElement : e.target;
}
//获取元素绝对坐标
function getPos(o) {
  var x = 0, y = 0;
  x -= (o.style.borderLeftWidth ? parseInt(o.style.borderLeftWidth) : 0);
  y -= (o.style.borderTopWidth ? parseInt(o.style.borderTopWidth) : 0);
  do {
    x += o.offsetLeft + (o.style.borderLeftWidth ? parseInt(o.style.borderLeftWidth) : 0);
    y += o.offsetTop + (o.style.borderTopWidth ? parseInt(o.style.borderTopWidth) : 0);
    o = o.offsetParent;
  } while (o)
  return { x: x, y: y };
}
//自定义下拉菜单
function XSelectArray(textArray, valueArray, keyArray, actionArray, readonly, maxHeight, autoFind, autoFindColor, className, onpicked, onchanged) {
  remove__xadiv__fun();
  if (!textArray)
    return;
  if (!valueArray || valueArray.length < textArray.length)
    valueArray = textArray;
  if (!keyArray || keyArray.length < textArray.length)
    keyArray = valueArray;
  var txt = getSrcElement();
  if (!txt.id) txt.id = "xatxt_" + Math.random();
  if (readonly) {
    txt.readOnly = true;
    removeEvent(txt, "keydown", Set_v__txt__readonly);
    addEvent(txt, "keydown", Set_v__txt__readonly);
    txt.blur();
    txt.style.cursor = "pointer";
  }
  var xadiv = window.top.document.createElement("div");
  xadiv.style.zIndex = "899";
  xadiv.id = "__xadiv__";
  addEvent(xadiv, "mouseover", Set_v__xadiv__isover);
  addEvent(xadiv, "mouseout", Set_v__xadiv__isout);
  xadiv.setAttribute("txtid", txt.id);
  xadiv.setAttribute("maxHeight", maxHeight);
  xadiv.setAttribute("autoFind", autoFind ? true : false);
  xadiv.setAttribute("autoFindColor", autoFindColor);
  xadiv.setAttribute("onpicked", onpicked);
  xadiv.setAttribute("onchanged", onchanged);
  xadiv.className = className ? className : "xadiv";
  var row = null;
  for (var i = 0; i < textArray.length; i++) {
    row = window.top.document.createElement("a");
    row.id = "__xarow__" + i;
    row.className = "arow";
    row.setAttribute("value", valueArray[i]);
    row.setAttribute("key", keyArray[i]);
    row.innerHTML = textArray[i];
    if (actionArray && actionArray.length >= i) {
      row.setAttribute("href", actionArray[i]);
    } else {
      row.setAttribute("href", "javascript:void(0);");
      addEvent(row, "click", Set_v__txt__setvalue);
    }
    xadiv.appendChild(row);
  }
  if (textArray.length == 1) {
    var isChange = txt.value != valueArray[0];
    txt.value = valueArray[0];
    if (onchanged && isChange)
      eval(onchanged);
    if (onpicked)
      eval(onpicked);
    remove__xadiv__fun();
    return;
  }
  var xy = getPos(txt);
  var px = 0, py = 0, ifr, pifrs;
  var p = window.self;
  var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  if (p.top != p) {
    scrollLeft += Math.max(window.top.document.documentElement.scrollLeft, window.top.document.body.scrollLeft);
    scrollTop += Math.max(window.top.document.documentElement.scrollTop, window.top.document.body.scrollTop);
    pifrs = p.top.document.getElementsByTagName("iframe");
    for (var i = 0; i < pifrs.length; i++) {
      if (pifrs[i].contentWindow == p.self) {
        ifr = pifrs[i];
      }
    }
    px -= (ifr.style.borderLeftWidth ? parseInt(ifr.style.borderLeftWidth) : 0);
    py -= (ifr.style.borderTopWidth ? parseInt(ifr.style.borderTopWidth) : 0);
    do {
      px += ifr.offsetLeft + (ifr.style.borderLeftWidth ? parseInt(ifr.style.borderLeftWidth) : 0);
      py += ifr.offsetTop + (ifr.style.borderTopWidth ? parseInt(ifr.style.borderTopWidth) : 0);
      ifr = ifr.offsetParent;
    } while (ifr)
    xy.x += px;
    xy.y += py;
  }
  window.top.document.body.appendChild(xadiv);
  if (xadiv.offsetHeight > parseInt(maxHeight)) {
    xadiv.style.height = parseInt(maxHeight) + "px";
  }
  var more = xy.x + xadiv.offsetWidth - window.top.document.documentElement.clientWidth;
  if (more > 0)
    xadiv.style.left = xy.x - more + scrollLeft + "px";
  else
    xadiv.style.left = xy.x + "px";
  more = xy.y + xadiv.offsetHeight - scrollTop - window.top.document.documentElement.clientHeight;
  if (more > 0)
    xadiv.style.top = xy.y - more - 1 + "px";
  else
    xadiv.style.top = xy.y + txt.offsetHeight + 1 + "px";
  var overiframe = window.top.document.getElementById("__overiframe__");
  if (!overiframe) {
    overiframe = window.top.document.createElement("iframe");
    overiframe.id = "__overiframe__";
    overiframe.style.position = "absolute";
    overiframe.frameBorder = "0";
    overiframe.style.zIndex = "898";
    window.top.document.body.appendChild(overiframe);
  }
  overiframe.style.width = xadiv.offsetWidth + "px";
  overiframe.style.height = xadiv.offsetHeight + "px";
  overiframe.style.left = parseInt(xadiv.style.left) + "px";
  overiframe.style.top = parseInt(xadiv.style.top) + "px";
  overiframe.style.display = "block";
}
addEvent(window.document, "mousedown", __xadiv__CloseDiv);
addEvent(window.document, "unload", __xadiv__CloseDiv);
addEvent(window.document, "keydown", __xadiv__onkeydown);
function __xadiv__CloseDiv(e) {
  if (window.top.document.getElementById("__xadiv__")) {
    if (window.top.document.getElementById("__xadiv__").getAttribute("isover") != 1) {
      remove__xadiv__fun();
    }
  }
};
function __xadiv__onkeydown(e) {
  var xadiv = window.top.document.getElementById("__xadiv__");
  if (!xadiv)
    return;
  e = e ? e : window.event;
  switch (e.keyCode) {
    //case 8:                                                                                       
    //case 46: document.getElementById(xadiv.getAttribute("txtid")).value = ""; break;                                                                                       
  }
  if (xadiv.getAttribute("autoFind").toString() != "true")
    return;
  var color = window.top.document.getElementById("__xadiv__").getAttribute("autoFindColor");
  color = color ? color : "#6699ff";
  var rows = xadiv.childNodes;
  var key = null;
  var isFind = false;
  for (var i = 0; i < rows.length; i++) {
    key = rows[i].getAttribute("key");
    if (key != null && key.charCodeAt(0) == e.keyCode) {
      if (!isFind) {
        if (xadiv.scrollTop > rows[i].offsetTop || rows[i].offsetTop + rows[i].offsetHeight > xadiv.scrollTop + parseInt(xadiv.getAttribute("maxHeight"))) {
          xadiv.scrollTop = rows[i].offsetTop;
        }
        isFind = true;
      }
      if (rows[i].style.backgroundColor == "") {
        __xadiv__Fat.fade_element(rows[i].id, 20, 1000, color);
      }
    }
  }
}
function Set_v__xadiv__isover() { window.top.document.getElementById("__xadiv__").setAttribute("isover", 1); }
function Set_v__xadiv__isout() { window.top.document.getElementById("__xadiv__").setAttribute("isover", 0); }
function Set_v__txt__readonly() { return false; }
function Set_v__txt__setvalue() {
  var xadiv = window.top.document.getElementById("__xadiv__");
  var txt = document.getElementById(xadiv.getAttribute("txtid"));
  var value = getSrcElement().getAttribute("value");
  var isChange = txt.value != value;
  txt.value = value;
  if (xadiv.getAttribute("onchanged") && isChange) {
    eval(xadiv.getAttribute("onchanged"));
  }
  if (xadiv.getAttribute("onpicked")) {
    eval(xadiv.getAttribute("onpicked"));
  }
  remove__xadiv__fun();
}
function remove__xadiv__fun() {
  var overiframe = window.top.document.getElementById("__overiframe__");
  if (overiframe)
    overiframe.style.display = "none";
  var xadiv = window.top.document.getElementById("__xadiv__");
  if (xadiv) {
    removeEvent(xadiv, "mouseover", Set_v__xadiv__isover);
    removeEvent(xadiv, "mouseout", Set_v__xadiv__isout);
    window.top.document.body.removeChild(xadiv);
  }
}

var __xadiv__Fat = {
  make_hex: function(r, g, b) {
    r = r.toString(16); if (r.length == 1) r = '0' + r;
    g = g.toString(16); if (g.length == 1) g = '0' + g;
    b = b.toString(16); if (b.length == 1) b = '0' + b;
    return "#" + r + g + b;
  },
  fade_element: function(id, fps, duration, from, to) {
    if (!fps) fps = 30;
    if (!duration) duration = 1000;
    if (!from || from == "#") from = "#FFFF33";
    if (!to) to = this.get_bgcolor(id);
    var frames = Math.round(fps * (duration / 1000));
    var interval = duration / frames;
    var delay = interval;
    var frame = 0;
    if (from.length < 7) from += from.substr(1, 3);
    if (to.length < 7) to += to.substr(1, 3);
    var rf = parseInt(from.substr(1, 2), 16);
    var gf = parseInt(from.substr(3, 2), 16);
    var bf = parseInt(from.substr(5, 2), 16);
    var rt = parseInt(to.substr(1, 2), 16);
    var gt = parseInt(to.substr(3, 2), 16);
    var bt = parseInt(to.substr(5, 2), 16);
    var r, g, b, h;
    while (frame < frames) {
      r = Math.floor(rf * ((frames - frame) / frames) + rt * (frame / frames));
      g = Math.floor(gf * ((frames - frame) / frames) + gt * (frame / frames));
      b = Math.floor(bf * ((frames - frame) / frames) + bt * (frame / frames));
      h = this.make_hex(r, g, b);
      setTimeout("__xadiv__Fat.set_bgcolor('" + id + "','" + h + "')", delay);
      frame++;
      delay = interval * frame;
    }
    setTimeout("if(window.top.document.getElementById('" + id + "')) window.top.document.getElementById('" + id + "').style.backgroundColor='';", delay);
  },
  set_bgcolor: function(id, c) {
    var o = window.top.document.getElementById(id);
    if (o)
      o.style.backgroundColor = c;
  },
  get_bgcolor: function(id) {
    var o = window.top.document.getElementById(id);
    while (o) {
      var c;
      if (window.getComputedStyle) c = window.getComputedStyle(o, null).getPropertyValue("background-color");
      if (o.currentStyle) c = o.currentStyle.backgroundColor;
      if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
      o = o.parentNode;
    }
    if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
    var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
    if (rgb) c = this.make_hex(parseInt(rgb[1]), parseInt(rgb[2]), parseInt(rgb[3]));
    return c;
  }
}
//pop图片
function XPopImage(url) {
  var el = getSrcElement();
  el.id = el.id ? el.id : "__tmpid" + Math.random();
  var img = document.createElement("img");
  img.id = "__xpopimage__";
  img.src = url ? url : el.src;
  img.setAttribute("elid", el.id);
  addEvent(img, "load", __XPopImage__removeBKG);
  addEvent(el, "mouseout", __XPopImage__noneDisplay);
  var xy = getPos(el);
  var div = document.createElement("div");
  div.id = "__xpopdiv__";
  div.style.cssText = "height:300px;width:300px;border:2px solid #ddd;position:absolute;background:url(/Img/imgLoading.gif) #fff no-repeat center center";
  div.appendChild(img);
  document.body.appendChild(div);
  div.style.top = xy.y - 150 + "px";
  div.style.left = xy.x + el.offsetWidth + "px";
  __XPopImage__LoopOnLoad();
}
function __XPopImage__LoopOnLoad() {
  if (document.getElementById("__xpopimage__") && document.getElementById("__xpopimage__").complete)
    __XPopImage__removeBKG();
  else
    setTimeout(__XPopImage__LoopOnLoad, 100);
}
function __XPopImage__removeBKG() {
  var img = document.getElementById("__xpopimage__");
  if (img) {
    var div = document.getElementById("__xpopdiv__");
    var el = document.getElementById(img.getAttribute("elid"));
    var xy = getPos(el);
    div.style.height = img.offsetHeight + "px";
    div.style.width = img.offsetWidth + "px";
    div.style.top = xy.y - (div.offsetHeight - el.offsetHeight) / 2 + "px";
  }
}
function __XPopImage__noneDisplay() {
  var img = document.getElementById("__xpopimage__");
  var div = document.getElementById("__xpopdiv__");
  if (img) {
    var el = document.getElementById(img.getAttribute("elid"));
    document.body.removeChild(div);
    if (el) {
      removeEvent(el, "mouseout", __XPopImage__noneDisplay);
    }
  }
}
//日期格式化
var dateFormat = function() {
  var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMs])\1?|"[^"]*"|'[^']*'/g,
    pad = function(val, len) {
      val = String(val);
      len = len || 2;
      while (val.length < len)
        val = "0" + val;
      return val;
    };
  return function(date, mask) {
    var dF = dateFormat;
    if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && !/\d/.test(date)) {
      mask = date;
      date = undefined;
    }
    if (typeof date == "string")
      date = newDate(date);
    if (isNaN(date))
      throw new SyntaxError("invalid date");
    d = date["getDate"](),
        D = date["getDay"](),
        M = date["getMonth"](),
        y = date["getFullYear"](),
        H = date["getHours"](),
        m = date["getMinutes"](),
        s = date["getSeconds"](),
        f = date["getMilliseconds"](),
        flags = {
          d: d,
          dd: pad(d),
          m: m,
          mm: pad(m),
          yy: String(y).slice(2),
          yyyy: y,
          h: H % 12 || 12,
          hh: pad(H % 12 || 12),
          H: H,
          HH: pad(H),
          M: M + 1,
          MM: pad(M + 1),
          s: s,
          ss: pad(s)
        };
    return mask.replace(token, function($0) {
      return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
    });
  };
} ();
Date.prototype.toFormatString = function(mask) {
  return dateFormat(this, mask);
};
//将标准yyyy-MM-dd HH:mm:ss的字符串转换为js日期对象
function newDate(str) {
  var arr = new Array();
  arr[0] = str.substr(0, 4);
  arr[1] = str.substr(5, 2);
  arr[2] = str.substr(8, 2);
  arr[3] = str.substr(11, 2);
  arr[4] = str.substr(14, 2);
  arr[5] = str.substr(17, 2);
  return new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
}
//限一次提交表单v2
document.write("<input type='hidden' id='__submitted__' value='0' />");
function submitOnce(onValidate) {
  var submitted = document.getElementById("__submitted__");
  if (submitted) {
    if (submitted.value == "1") {
      return false;
    }
    submitted.value = "1";
    if (onValidate) {
      var parr = new Array();
      for (var i = 1; i < arguments.length; i++)
        parr.push(arguments[i]);
      if (onValidate.apply(this, parr)) {
        return true;
      }
      else {
        submitted.value = "0";
        return false;
      }
    }
    return true;
  }
  else
    return true;
}
//js分页控件v1(引用stringBuilder，getEvent)
function xPage(_div) {
  this.div = _div;
  this.showNumeric = true;
  this.numericButtonCount = 10;
  this.pageSize = 10;
  this.cssClass = "xpage";
  this.lastPageText = "末页";
  this.firstPageText = "首页";
  this.prevPageText = "上一页";
  this.nextPageText = "下一页";
  this.gotoPageText = "确定";
  this.customInfo = null;
  this.showInputBox = true;
  this.currentPageIndex = 1;
  this.recordCount = 0;
  this.pageCount = function() {
    if (this.recordCount <= 0)
      return 1;
    return Math.ceil(parseInt(this.recordCount) / parseInt(this.pageSize));
  };
  this.onPageChanged = function(i, objName) { };
  this.p = function(objName, i) {
    if (i < 1)
      i = 1;
    else if (i > this.pageCount())
      i = this.pageCount();
    this.currentPageIndex = i;
    this.render(objName);
    this.onPageChanged(i, objName);
  };
  this.dataBind = function(_recordCount, objName) {
    this.recordCount = _recordCount;
    if (this.currentPageIndex > this.pageCount())
      this.currentPageIndex = this.pageCount();
    this.render(objName);
  };
  this.render = function(objName) {
    var s = new stringBuilder();
    var cPageIndex = parseInt(this.currentPageIndex);
    var pCount = this.pageCount();
    var bofIndex = 1;
    var eofIndex = parseInt(this.numericButtonCount);
    if (pCount > eofIndex) {
      var offset = parseInt(eofIndex / 2);
      if (cPageIndex > offset)
        bofIndex = cPageIndex - offset;
      offset = bofIndex + eofIndex - 1;
      if (offset > pCount) {
        bofIndex = pCount - eofIndex + 1;
        eofIndex = pCount;
      }
      else {
        eofIndex = offset;
      }
    }
    else {
      eofIndex = pCount;
    }
    if (cPageIndex == 1) {
      if (this.firstPageText) {
        s.append("<span class=\"firstdisable\">");
        s.append(this.firstPageText);
        s.append("</span>");
      }
      if (this.prevPageText) {
        s.append("<span class=\"prevdisable\">");
        s.append(this.prevPageText);
        s.append("</span>");
      }
    }
    else {
      if (this.firstPageText) {
        s.append("<a class=\"first\" href=\"javascript:");
        s.append(objName);
        s.append(".p('");
        s.append(objName);
        s.append("',1)\">");
        s.append(this.firstPageText);
        s.append("</a>");
      }
      if (this.prevPageText) {
        s.append("<a class=\"prev\" href=\"javascript:");
        s.append(objName);
        s.append(".p('");
        s.append(objName);
        s.append("',");
        s.append(cPageIndex - 1);
        s.append(")\">");
        s.append(this.prevPageText);
        s.append("</a>");
      }
    }
    if (this.showNumeric) {
      for (var i = bofIndex; i <= eofIndex; i++) {
        if (cPageIndex == i) {
          s.append("<span class=\"current\">");
          s.append(i);
          s.append("</span>");
        }
        else {
          s.append("<a class='numeric' href=\"javascript:");
          s.append(objName);
          s.append(".p('");
          s.append(objName);
          s.append("',");
          s.append(i);
          s.append(")\">");
          s.append(i);
          s.append("</a>");
        }
      }
    }
    else {
      s.append("<span class=\"current\">");
      s.append(cPageIndex);
      s.append("</span>");
    }
    if (cPageIndex == pCount) {
      if (this.nextPageText) {
        s.append("<span class=\"nextdisable\">");
        s.append(this.nextPageText);
        s.append("</span>");
      }
      if (this.lastPageText) {
        s.append("<span class=\"lastdisable\">");
        s.append(this.lastPageText);
        s.append("</span>");
      }
    }
    else {
      if (this.nextPageText) {
        s.append("<a class=\"next\" href=\"javascript:");
        s.append(objName);
        s.append(".p('");
        s.append(objName);
        s.append("',");
        s.append(cPageIndex + 1);
        s.append(")\">");
        s.append(this.nextPageText);
        s.append("</a>");
      }
      if (this.lastPageText) {
        s.append("<a class=\"last\" href=\"javascript:");
        s.append(objName);
        s.append(".p('");
        s.append(objName);
        s.append("',");
        s.append(pCount);
        s.append(")\">");
        s.append(this.lastPageText);
        s.append("</a>");
      }
    }
    if (this.customInfo) {
      s.append("<span class=\"custominfo\">");
      s.append(this.customInfo
              .replace(/%PageCount%/g, this.pageCount().toString())
              .replace(/%PageSize%/g, this.pageSize.toString())
              .replace(/%RecordCount%/g, this.recordCount.toString())
              .replace(/%CurrentPageIndex%/g, this.currentPageIndex.toString()));
      s.append("</span>");
    }
    if (this.showInputBox) {
      s.append("<span class=\"boxleft\">第</span><input class=\"inputbox\" type=\"text\" value=\"");
      s.append(cPageIndex);
      s.append("\" id=\"");
      s.append(objName);
      s.append("_input\" onkeyup=\"if(getEvent().keyCode==13){");
      s.append(objName);
      s.append(".p('");
      s.append(objName);
      s.append("',this.value);}\"/><span class=\"boxright\">页</span><a class=\"goto\" href=\"javascript:");
      s.append(objName);
      s.append(".p('");
      s.append(objName);
      s.append("',document.getElementById('");
      s.append(objName);
      s.append("_input').value)\">");
      s.append(this.gotoPageText);
      s.append("</a><input type=\"text\" style=\"display:none\" />");
    }
    this.div.className = this.cssClass;
    this.div.innerHTML = s.toString();
  };
}


//-以下非公有js
//--------ajax
var req;
function creatReq(_url, obj) {
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHttp");
  }
  if (req) {
    req.open("GET", _url, true);
    req.setRequestHeader("If-Modified-Since", "0");
    req.onreadystatechange = obj;
    req.setRequestHeader("charset", "utf-8");
    req.send(null);
  }

}

function callback() {

  if (req.readyState == 4) {
    if (req.status == 200) {

      Dispaly();
    }
    else {
      alert("服务端返回状态" + req.statusText);
    }
  }
  else {
    document.getElementById("lblStr").innerHTML = "";
  }
}

function Dispaly() {
  document.getElementById("lblStr").innerHTML = req.responseText;
  parent.getFromIfr(document.getElementById("lblstr").innerHTML, getHotelName());

}

function DispalyCommon(obj) {
  document.getElementById(obj).innerHTML = req.responseText;

}

function callbackTc() {
  if (req.readyState == 4) {
    if (req.status == 200) {

      DispalyCommon("tcInfo");
    }
    else {
      alert("服务端返回状态" + req.statusText);
    }
  }
  else {
    document.getElementById("tcInfo").innerHTML = "数据加载中";
  }
}

function getHotelName() {
  return document.getElementById("HotelName").value;
}
function sendMercReq(url, UserId, obj) {
  var __url = url + "?UserId=" + UserId;

  creatReq(__url, obj);
  //ShowWhyMerc(3);

}

//特产
function getTcReq(url, obj) {
  //var __url = url + "?UserId=" + UserId;

  creatReq(url, obj);

}

function ShowWhyMerc(id) {
  var l = document.getElementById("hfRownum").value;
  //        for(var i = 0;i < parseInt(l); i++)
  //        {
  //            document.getElementById("Mer"+i).style.display = "none";
  //        }
  //            document.getElementById("Mer"+id).style.display = "";

  var str = document.getElementById("lblstr").innerHTML;

  parent.getFromIfr(document.getElementById("lblstr").innerHTML);

}

//预订弹出
function $$() { return document.getElementById ? document.getElementById(arguments[0]) : eval(arguments[0]); }
var OverH, OverW, ChangeDesc, ChangeH = 20, ChangeW = 20;
function OpenDiv(_Dw, _Dh) {
  OverH = _Dh; OverW = _Dw; //ChangeDesc=_Desc;
  $$("Loading").style.display = '';
  if (_Dw > _Dh) { ChangeH = Math.ceil((_Dh - 10) / ((_Dw - 10) / 20)) } else if (_Dw < _Dh) { ChangeW = Math.ceil((_Dw - 10) / ((_Dh - 10) / 20)) }
  $$("Loading").style.top = (document.documentElement.clientHeight - 500) / 2 + "px";
  $$("Loading").style.left = (document.documentElement.clientWidth - 10) / 2 + "px";
  OpenNow()
}
var Nw = 10, Nh = 10;
function OpenNow() {
  Nw = Nw + ChangeW; Nh = Nh + ChangeH;
  if (OverW > Nw || OverH > Nh) {
    if (OverW > Nw) {
      $$("Loading").style.width = Nw + "px";
      $$("Loading").style.left = (document.documentElement.clientWidth - Nw - 200) / 2 + "px";
    }
    if (OverH > Nh) {
      $$("Loading").style.height = Nh + "px";
      $$("Loading").style.top = 525 + "px"
    }
    window.setTimeout("OpenNow()", 10)
  } else {
    Nw = 10; Nh = 10; ChangeH = 20; ChangeW = 20;
    //$$("Loading").innerHTML=_strT;
  }
}
function checkCNIdCard(sNo) { if (sNo == null) return false; sNo = sNo.value.toString(); if (sNo.length == 18) { var a, b, c; if (isNaN(sNo.substr(0, 17))) { return false; } a = parseInt(sNo.substr(0, 1)) * 7 + parseInt(sNo.substr(1, 1)) * 9 + parseInt(sNo.substr(2, 1)) * 10; a = a + parseInt(sNo.substr(3, 1)) * 5 + parseInt(sNo.substr(4, 1)) * 8 + parseInt(sNo.substr(5, 1)) * 4; a = a + parseInt(sNo.substr(6, 1)) * 2 + parseInt(sNo.substr(7, 1)) * 1 + parseInt(sNo.substr(8, 1)) * 6; a = a + parseInt(sNo.substr(9, 1)) * 3 + parseInt(sNo.substr(10, 1)) * 7 + parseInt(sNo.substr(11, 1)) * 9; a = a + parseInt(sNo.substr(12, 1)) * 10 + parseInt(sNo.substr(13, 1)) * 5 + parseInt(sNo.substr(14, 1)) * 8; a = a + parseInt(sNo.substr(15, 1)) * 4 + parseInt(sNo.substr(16, 1)) * 2; b = a % 11; if (b == 2) { c = sNo.substr(17, 1).toUpperCase(); } else { c = parseInt(sNo.substr(17, 1)); } switch (b) { case 0: if (c != 1) { return false; } break; case 1: if (c != 0) { return false; } break; case 2: if (c != "X") { return false; } break; case 3: if (c != 9) { return false; } break; case 4: if (c != 8) { return false; } break; case 5: if (c != 7) { return false; } break; case 6: if (c != 6) { return false; } break; case 7: if (c != 5) { return false; } break; case 8: if (c != 4) { return false; } break; case 9: if (c != 3) { return false; } break; case 10: if (c != 2) { return false }; } } else { if (isNaN(sNo)) { return false; } } switch (sNo.length) { case 15: if (checkDateTime(sNo.substr(6, 2) + '-' + sNo.substr(8, 2) + '-' + sNo.substr(10, 2))) { return true; } case 18: if (checkDateTime(sNo.substr(6, 4) + '-' + sNo.substr(10, 2) + '-' + sNo.substr(12, 2))) { return true; } } return false; }

//验证框架类定义v8.5 beta
var xValidate = {
  promptValidate: true,
  tipCss: "vtip",
  tipFormat: "{num}.{tip} \n\r",
  validateState: 0,
  errObjSummary: null,
  errTipSummary: null,
  promptSwitchGroup: true,
  validateGroup: null,
  $Tag: function(n) { return document.getElementsByTagName(n); },
  init: function(promptvalidate, tipcss, tipformat, promptswitchgroup, validategroup) {
    if (promptvalidate != null)
      xValidate.promptValidate = promptvalidate;
    if (tipformat != null)
      xValidate.tipFormat = tipformat;
    if (tipcss != null)
      xValidate.tipCss = tipcss;
    if (promptswitchgroup != null)
      xValidate.promptSwitchGroup = promptswitchgroup;
    if (validategroup != null)
      xValidate.validateGroup = validategroup;
    if (xValidate.promptValidate || xValidate.promptSwitchGroup) {
      var v;
      var inputs = xValidate.$Tag("input");
      for (var i = 0; i < inputs.length; i++) {
        v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
        if (xValidate.promptValidate && v && v.length > 0)
          addEvent(inputs[i], "blur", xValidate.xValidateOne);
        v = inputs[i].getAttribute("vgroup");
        if (xValidate.promptSwitchGroup && v && v.length > 0)
          addEvent(inputs[i], "focus", xValidate.switchGroup);
      }
      inputs = xValidate.$Tag("textarea");
      for (var i = 0; i < inputs.length; i++) {
        v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
        if (xValidate.promptValidate && v && v.length > 0)
          addEvent(inputs[i], "blur", xValidate.xValidateOne);
        v = inputs[i].getAttribute("vgroup");
        if (xValidate.promptSwitchGroup && v && v.length > 0)
          addEvent(inputs[i], "focus", xValidate.switchGroup);
      }
      inputs = xValidate.$Tag("select");
      for (var i = 0; i < inputs.length; i++) {
        v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
        if (xValidate.promptValidate && v && v.length > 0)
          addEvent(inputs[i], "change", xValidate.xValidateOne);
        v = inputs[i].getAttribute("vgroup");
        if (xValidate.promptSwitchGroup && v && v.length > 0)
          addEvent(inputs[i], "focus", xValidate.switchGroup);
      }
    }
  },
  xValidateAll: function(groupname) {
    if (groupname)
      xValidate.switchGroup(groupname);
    xValidate.validateState = 2;
    xValidate.errObjSummary = new Array();
    xValidate.errTipSummary = new Array();
    var vs;
    var vr = true;
    var inputs = new Array();
    var tmps = xValidate.$Tag("input");
    for (var i = 0; i < tmps.length; i++) {
      vs = tmps[i].getAttribute("vstyle") || tmps[i].getAttribute("vclass");
      if (vs && vs.length > 0 && tmps[i].getAttribute("vgroup") == xValidate.validateGroup)
        inputs.push(tmps[i]);
    }
    tmps = xValidate.$Tag("select");
    for (var i = 0; i < tmps.length; i++) {
      vs = tmps[i].getAttribute("vstyle") || tmps[i].getAttribute("vclass");
      if (vs && vs.length > 0 && tmps[i].getAttribute("vgroup") == xValidate.validateGroup)
        inputs.push(tmps[i]);
    }
    tmps = xValidate.$Tag("textarea");
    for (var i = 0; i < tmps.length; i++) {
      vs = tmps[i].getAttribute("vstyle") || tmps[i].getAttribute("vclass");
      if (vs && vs.length > 0 && tmps[i].getAttribute("vgroup") == xValidate.validateGroup)
        inputs.push(tmps[i]);
    }
    for (var i = 0; i < inputs.length; i++) {
      if (!xValidate.xValidateOne(inputs[i]) && vr)
        vr = false;
    }
    if (!vr) {
      if (xValidate.errTipSummary.length > 0) {
        var tiphtml = "";
        for (var i = 0; i < xValidate.errTipSummary.length; i++) {
          tiphtml += xValidate.tipFormat.replace(/{tip}/g, xValidate.errTipSummary[i]).replace(/{num}/g, i + 1);
        }
        xValidate.alertHandle(tiphtml, xValidate.errObjSummary[0]);
      }
    }
    xValidate.validateState = 0;
    return vr;
  },
  xValidateDate: function(value, vt, required) {
    if (typeof vt == "string") {
      if (vt.length > 0) {
        if (vt.charAt(0) == "[")
          vt = Json.decode(vt);
        else
          vt = xValidate.templateClass[vt];
      }
    }
    if (!vt || vt.length == 0) {
      alert("验证表达式有误");
      return false;
    }
    for (var j = 0; j < vt.length; j++) {
      if (!required && value.replace(/(^\s*)|(\s*$)/g, "").length == 0)
        continue;
      if (!xValidate.xValidateChip(value, vt[j].type, vt[j]))
        return false;
    }
    return true;
  },
  xValidateChip: function(value, type, voj) {
    var vr, v;
    switch (type) {
      case "empty":
        vr = value.replace(/(^\s*)|(\s*$)/g, "").length > 0;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "equal":
        v = (voj.value.length > 10 && voj.value.indexOf("javascript:") == 0) ? eval(voj.value.substr(11)) : voj.value;
        vr = v == value;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "include":
        v = (voj.value.toString().indexOf("javascript:") == 0) ? eval(voj.value.substr(11)) : voj.value;
        vr = true;
        for (var i = 0; i < v.length; i++) {
          if (value.indexOf(v[i]) != -1) {
            vr = false;
            break;
          }
        }
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "length":
        v = value.length;
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(11)) : parseInt(voj.min);
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(11)) : parseInt(voj.max);
        vr = v >= min && v <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "byte":
        v = xValidate.getLengthByByte(value);
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(11)) : parseInt(voj.min);
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(11)) : parseInt(voj.max);
        vr = v >= min && v <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "number":
        v = parseFloat(value);
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(11)) : parseFloat(voj.min);
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(11)) : parseFloat(voj.max);
        vr = !isNaN(v) && !isNaN(min) && !isNaN(max) && v >= min && v <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "digit":
        v = parseFloat(value);
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(11)) : parseInt(voj.min);
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(11)) : parseInt(voj.max);
        var idx = v.toString().indexOf(".");
        idx = (idx == -1) ? 0 : value.length - idx - 1;
        vr = !isNaN(v) && !isNaN(min) && !isNaN(max) && !isNaN(idx) && idx >= min && idx <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "int":
        v = parseInt(value);
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(11)) : parseInt(voj.min);
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(11)) : parseInt(voj.max);
        vr = !isNaN(v) && !isNaN(min) && !isNaN(max) && v >= min && v <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "date":
        v = Date.fromString(value);
        min = (voj.min.toString().length > 10 && voj.min.toString().indexOf("javascript:") == 0) ? eval(voj.min.substr(1)) : voj.min;
        max = (voj.max.toString().length > 10 && voj.max.toString().indexOf("javascript:") == 0) ? eval(voj.max.substr(1)) : voj.max;
        vr = !isNaN(v) && !isNaN(min) && !isNaN(max) && v >= min && v <= max;
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "regex":
        vr = voj.pattern.test(value);
        if (voj.mirror ? vr : !vr)
          return false;
        break;
      case "function":
        vr = voj.handle(value, voj);
        if (voj.mirror ? vr : !vr)
          return false;
        break;
    }
    return true;
  },
  xValidateOne: function(obj, vt) {
    if (xValidate.validateState == 0)
      xValidate.validateState = 1;
    if (!obj.tagName)
      obj = obj.srcElement || obj.target;
    var vs, vc, v, min, max, vr, vb;
    vs = obj.getAttribute("vstyle");
    vc = obj.getAttribute("vclass");
    if (vs && vs.length > 0 && vs.charAt(0) == "[")
      vs = Json.decode(vs);
    if (vc && vc.length > 0) {
      vb = vc.split("(");
      vc = xValidate.templateClass[vb[0]];
      vb = vb.length == 2 ? vb[1].replace(/\)$/, "") : "";
    }
    if (typeof vt == "string") {
      if (vt.length > 0 && vt.charAt(0) == "[")
        vt = Json.decode(vt);
      else {
        vb = vt.split("(");
        vt = xValidate.templateClass[vb[0]];
        vb = vb.length == 2 ? vb[1].replace(/\)$/, "") : "";
      }
    }
    if ((!vs || vs.length == 0) && (!vc || vc.length == 0) && (!vt || vt.length == 0)) {
      alert("验证表达式有误");
      return false;
    }
    var vo = [];
    var tmpv;
    for (var j = 0; j < xValidate.validateTypes.length; j++) {
      tmpv = xValidate.findValidateItme(vt, xValidate.validateTypes[j]);
      if (tmpv == null)
        tmpv = xValidate.findValidateItme(vs, xValidate.validateTypes[j]);
      if (tmpv == null)
        tmpv = xValidate.findValidateItme(vc, xValidate.validateTypes[j]);
      if (tmpv != null)
        vo.push(tmpv);
    }
    if (!vo || vo.length == 0) {
      alert("验证表达式有误");
      return false;
    }
    v = obj.getAttribute("onvalidating");
    if (!v || (v && eval(v))) {
      for (var j = 0; j < vo.length; j++) {
        if (obj.getAttribute("required") && obj.getAttribute("required").toLowerCase() == "false" && obj.value.replace(/(^\s*)|(\s*$)/g, "").length == 0)
          continue;
        if (!xValidate.xValidateChip(obj.value, vo[j].type, vo[j])) {
          xValidate.xValidateFailed(obj, vo[j].tip, vb);
          return false;
        }
      }
    }
    xValidate.xValidateCorrect(obj);
    if (xValidate.validateState == 1)
      xValidate.validateState = 0;
    v = obj.getAttribute("onvalidated");
    if (v)
      eval(v);
    return true;
  },
  xValidateCorrect: function(obj) {
    var tmp = obj.getAttribute("vtipmode");
    if (!tmp)
      tmp = xValidate.validateState.toString();
    v = tmp.charAt(0);
    if (v == "3" || v == "5" || v == "7")
      $(tmp.split("(")[1].replace(/\)$/, "")).innerHTML = "";
    else if (v == "4" || v == "6" || v == "8")
      $(tmp.split("(")[1].replace(/\)$/, "")).value = "";
    if (v == "1" || v == "5" || v == "6") {
      v = $((obj.name || obj.id) + "_tipdiv");
      if (v)
        document.body.removeChild(v);
    }
    v = obj.getAttribute("vtclass");
    if (v)
      obj.className = v;
  },
  xValidateFailed: function(obj, tip, vb) {
    if (!tip)
      tip = "";
    else
      tip = tip.replace(/%value%/g, obj.value).replace(/%length%/g, obj.value.length).replace(/%byte%/g, xValidate.getLengthByByte(obj.value));
    tip = tip.replace(/{x}/g, vb);
    var v = $((obj.name || obj.id) + "_tipdiv");
    if (v)
      document.body.removeChild(v);
    vb = obj.getAttribute("vtipmode");
    if (!vb)
      vb = xValidate.validateState.toString();
    var m = vb.charAt(0);
    if (m == "1" || m == "5" || m == "6") {
      if (!$((obj.name || obj.id) + "_tipdiv")) {
        var xy = getPos(obj);
        var tipDiv = document.createElement("div");
        tipDiv.id = (obj.name || obj.id) + "_tipdiv";
        tipDiv.style.position = "absolute";
        tipDiv.style.zIndex = "255";
        tipDiv.className = obj.getAttribute("vtipclass") || xValidate.tipCss;
        tipDiv.innerHTML = tip;
        document.body.appendChild(tipDiv);
        var vx = parseInt(obj.getAttribute("vtipx"));
        var vy = parseInt(obj.getAttribute("vtipy"));
        tipDiv.style.left = xy.x + (isNaN(vx) ? 0 : vx) + obj.offsetWidth + "px";
        tipDiv.style.top = xy.y + (isNaN(vy) ? 0 : vy) - tipDiv.offsetHeight / 2 + obj.offsetHeight / 2 + "px";
      }
      else
        $((obj.name || obj.id) + "_tipdiv").innerHTML = tip;
    }
    else if (m == "2" || m == "7" || m == "8") {
      if (xValidate.validateState == 2) {
        xValidate.errTipSummary.push(tip);
        xValidate.errObjSummary.push(obj);
      } else
        xValidate.alertHandle(tip);
    }
    if (m == "3" || m == "5" || m == "7")
      $(vb.split("(")[1].replace(/\)$/, "")).innerHTML = tip;
    else if (m == "4" || m == "6" || m == "8")
      $(vb.split("(")[1].replace(/\)$/, "")).value = tip;
    var vfc = obj.getAttribute("vfclass");
    if (vfc)
      obj.className = vfc;
    if (xValidate.validateState == 1)
      xValidate.validateState = 0;
  },
  onSwitching: function() { return true; },
  onSwitched: Function(),
  switchGroup: function(groupname) {
    if (typeof groupname != "string")
      groupname = (groupname.srcElement || groupname.target).getAttribute("vgroup");
    if (xValidate.validateGroup == groupname)
      return;
    if (!xValidate.onSwitching(groupname))
      return;
    xValidate.validateGroup = groupname;
    var v;
    var inputs = xValidate.$Tag("input");
    for (var i = 0; i < inputs.length; i++) {
      v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
      if (v && v.length > 0) {
        v = inputs[i].getAttribute("vgroup");
        if (v != groupname)
          xValidate.xValidateCorrect(inputs[i]);
      }
    }
    inputs = xValidate.$Tag("textarea");
    for (var i = 0; i < inputs.length; i++) {
      v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
      if (v && v.length > 0) {
        v = inputs[i].getAttribute("vgroup");
        if (v != groupname)
          xValidate.xValidateCorrect(inputs[i]);
      }
    }
    inputs = xValidate.$Tag("select");
    for (var i = 0; i < inputs.length; i++) {
      v = inputs[i].getAttribute("vclass") || inputs[i].getAttribute("vstyle");
      if (v && v.length > 0) {
        v = inputs[i].getAttribute("vgroup");
        if (v != groupname)
          xValidate.xValidateCorrect(inputs[i]);
      }
    }
    xValidate.onSwitched(groupname);
  },
  findValidateItme: function(vo, type) {
    if (!vo || vo.length == 0)
      return null;
    if (typeof vo == "string")
      vo = Json.decode(vo);
    for (var i = 0; i < vo.length; i++) {
      if (vo[i].type == type)
        return vo[i];
    }
    return null;
  },
  getLengthByByte: function(s) {
    if (!s)
      return 0;
    var c = 0;
    for (var i = 0; i < s.length; i++)
      c += (s.charCodeAt(i) < 0xFF) ? 1 : 2;
    return c;
  },
  alertHandle: function(tip, focusObj) {
    alert(tip);
    if (focusObj) {
      if (focusObj.tagName.toLowerCase() == "select")
        focusObj.focus();
      else
        focusObj.select();
    }
  },
  validateTypes: new Array("empty", "equal", "include", "length", "byte", "number", "digit", "int", "date", "regex", "function"),
  templateClass: {
    noempty: [{ type: "empty", tip: "请填写{x}"}],
    username: [{ type: "empty", tip: "请填写{x}用户名称" }, { type: "byte", min: 4, max: 20, tip: "{x}用户名长度应为4~20个字符(一个汉字算两个字符)" }, { type: "regex", pattern: /^([a-zA-Z]\w{2,18}[a-zA-Z0-9]|[\u4E00-\u9FA5][\u4E00-\u9FA5a-zA-Z0-9]{1,9})$/, tip: "{x}用户名格式不正确"}],
    realname: [{ type: "empty", tip: "请填写{x}姓名" }, { type: "regex", pattern: /^[a-zA-Z][\w._-]{1,18}|[\u4E00-\u9FA5]{1,5}$/, tip: "请正确填写{x}姓名"}],
    password: [{ type: "empty", tip: "请填写{x}密码" }, { type: "length", min: 6, max: 20, tip: "请输入6~20个字符的{x}密码"}],
    verify: [{ type: "empty", tip: "请填写{x}确认密码" }, { type: "equal", value: "javascript:$('txtFirstPassword').value", tip: '两次填写的{x}密码不一致'}],
    vcode: [{ type: "empty", tip: "请填写图片上显示的{x}验证码，看不清请点击图片更换" }, { type: "length", min: 4, max: 4, tip: "{x}验证码不正确"}],
    address: [{ type: "empty", tip: "请填写{x}地址" }, { type: "length", min: 2, max: 200, tip: "{x}地址无效"}],
    postcode: [{ type: "empty", tip: "请填写{x}邮政编码" }, { type: "regex", pattern: /^\d{6}$/, tip: "{x}邮政编码无效"}],
    creditcard: [{ type: "empty", tip: "请填写{x}卡号" }, { type: "regex", pattern: /^[0-9]([0-9]|[\-\s]){11,20}[0-9]$/, tip: "{x}卡号格式不正确"}],
    quantity: [{ type: "empty", tip: "请填写{x}数量" }, { type: "int", min: 1, max: 9999, tip: "{x}数量无效"}],
    url: [{ type: "empty", tip: "请填写{x}地址" }, { type: "regex", pattern: /^(http|https)?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/, tip: "{x}地址格式无效"}],
    qq: [{ type: "empty", tip: "请填写{x}QQ号码" }, { type: "regex", pattern: /^[1-9]\d{4,8}$/, tip: "{x}QQ号码格式不正确"}],
    ip: [{ type: "empty", tip: "请填写{x}IP地址" }, { type: "regex", pattern: /^(\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])\.(\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])$/, tip: "{x}IP地址格式无效"}],
    email: [{ type: "empty", tip: "请填写{x}电子邮箱地址" }, { type: "length", min: 8, max: 50, tip: "{x}电子邮箱地址长度无效" }, { type: "regex", pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, tip: "{x}电子邮箱格式不正确"}],
    idcard: [{ type: "empty", tip: "请填写{x}身份证号码" }, { type: "function", handle: checkCNIdCard, tip: "{x}身份证号码无效"}],
    money: [{ type: "empty", tip: "请填写{x}金额" }, { type: "number", min: 0, max: 99999999, tip: "{x}金额不正确" }, { type: "dight", min: 0, max: 2, tip: "{x}金额最多可以填写2位小数"}],
    mobile: [{ type: "empty", tip: "请填写{x}手机号码" }, { type: "regex", pattern: /^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1})+\d{8})$/, tip: "{x}手机号码不正确"}],
    telephone: [{ type: "empty", tip: "请填写{x}电话号码" }, { type: "regex", pattern: /^([\d-+]{7,18})$/, tip: "{x}电话号码不正确"}],
    fax: [{ type: "empty", tip: "请填写{x}传真号码" }, { type: "regex", pattern: /^([\d-+]{7,18})$/, tip: "{x}传真号码不正确"}],
    date: [{ type: "empty", tip: "请填写{x}日期" }, { type: "date", min: new Date(1900, 0, 1), max: new Date(2079, 5, 6), tip: "{x}日期无效"}]
  }
};
var xRequest = {
  queryString: function(key) {
    var uri = window.location.search;
    if (key) {
      var re = new RegExp(key + "\=([^\&\?]*)", "ig");
      return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
    } else {
      var xa = new xAttribute();
      if (uri.length > 0 && uri.charAt(0) == "?")
        uri = uri.substr(1);
      xa.init(uri);
      return xa;
    }
  },
  form: function(name) {
    if (!name) return null;
    var objs = document.getElementsByName(name);
    var v = "";
    for (var i = 0; i < objs.length; i++) {
      if (objs[i].getAttribute("type") == "radio" || objs[i].getAttribute("type") == "checkbox") {
        if (objs[i].checked) v += "," + objs[i].value;
      } else { v += "," + objs[i].value; }
    }
    return (v && v.length > 0) ? v.substr(1) : null;
  },
  getFormValue: function(id) {
    var dform = $(id);
    if (dform) {
      var xa = new xAttribute();
      var tmp;
      var inputs = dform.getElementsByTagName("input");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp) {
          if (inputs[i].getAttribute("type") == "radio" || inputs[i].getAttribute("type") == "checkbox") {
            if (inputs[i].checked)
              xa.add(tmp, encodeURIComponent(inputs[i].value) || "");
          } else
            xa.add(tmp, encodeURIComponent(inputs[i].value) || "");
        }
      }
      inputs = dform.getElementsByTagName("select");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp)
          xa.add(tmp, encodeURIComponent(inputs[i].value) || "");
      }
      inputs = dform.getElementsByTagName("textarea");
      for (var i = 0; i < inputs.length; i++) {
        tmp = inputs[i].getAttribute("name");
        if (tmp)
          xa.add(tmp, encodeURIComponent(inputs[i].value) || "");
      }
      return xa.toString();
    }
    else
      return "";
  },
  setCookie: function(key, value, expires, path, secure) {
    if (!expires) {
      expires = new Date();
      expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
    }
    var str = key + "=" + escape(value) + ";expires=" + expires.toGMTString() + ";path=" + (path || "/") + (secure ? ";secure" : "");
    document.cookie = str;
  },
  getCookie: function(key) { var arr = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return null; },
  delCookie: function(key) {
    var now = new Date();
    now.setTime(now.getTime() - 1);
    var cval = xRequest.getCookie(key); if (cval != null) { document.cookie = key + "=" + cval + ";expires=" + now.toGMTString(); }
  },
  urlReferrer: window.document.referrer,
  url: window.location.href,
  host: window.location.hostname,
  title: window.document.title,
  status: window.status,
  winName: window.name,
  browser: window.navigator.appName,
  version: window.navigator.appVersion,
  appCodeName: window.navigator.appCodeName,
  userAgent: window.navigator.userAgent,
  userLanguage: navigator.language || navigator.userLanguage,
  setHighLight: function(range, word, style) {
    if (!word)
      return;
    if (!style)
      style = "background:#ff0";
    if (range && range.innerHTML) {
      var reg = new RegExp(word, "g");
      range.innerHTML = range.innerHTML.replace(reg, "<span style='" + style + "'>" + word + "</span>");
    }
  },
  addFavorite: function(title) { var tit = (title) ? title : document.title; var url = document.location.href; if (window.sidebar) window.sidebar.addPanel(tit, url, ""); else if (is_opera) { var tmpa = document.createElement("a"); tmpa.setAttribute("rel", "sidebar"); tmpa.setAttribute("href", url); tmpa.setAttribute("title", tit); tmpa.click(); } else window.external.AddFavorite(url, tit); },
  clippingString: function(s, count, unitByByte, autoSuspension) { if (!count || count < 1 || !s) return ""; if (unitByByte) { var bytec = 0; for (var i = 0; i < s.Length; i++) { bytec += (s.charCodeAt(i) < 0xFF) ? 1 : 2; if (bytec >= count) if (autoSuspension) return s.substr(0, i) + "…"; else return s.substr(0, i); } return s; } else { if (s.Length <= count) return s; if (autoSuspension) return s.substr(0, count) + "…"; else return s.substr(0, count); } },
  setDefaultFocus: function(id) { addEvent(window, "load", function() { setTimeout("$('" + id + "').focus()", 0); }); },
  autoHideLinkFocus: function() { for (var i = 0; i < document.links.length; i++) document.links[i].setAttribute("hideFocus", true); },
  clearPrice: function(d, dv) {
    var result = parseFloat(d);
    if (isNaN(result) || result < 0)
      return dv || "--";
    else
      return (Math.round(result * 100) / 100).toString();
  }
};
//v1.0
function jbind(el, jo) {
  if (typeof el == "string") {
    el = $(el);
  }
  var jeval = function(jo, i, n) {
    if (n) {
      if (n == "__%index")
        return i;
      else if (typeof n == "string") {
        return jo.Rows[i][jo.Columns[n]];
      } else {
        return jo.Rows[i][n];
      }
    }
  };
  var p = el.innerHTML.split(/(<!--)|(-->)/g);
  var sb = new stringBuilder();
  var index = "__%index";
  for (var i = 0; i < jo.Rows.length; i++) {
    for (var j = 0; j < p.length; j++) {
      if (j % 2 == 1 && p[j].indexOf("[") != -1)
        sb.append(eval(p[j].replace(/\[([\w"$]+)\]/g, "jeval(jo," + i + ",$1)")));
      else
        sb.append(p[j]);
    }
  }
  el.innerHTML = sb.toString();
}
//v2.0
var xAjax = {
  request: function(method, url, data, responseHandle, errorHandle) {
    var xmlHttp = null;
    if (window.ActiveXObject) {
      try {
        xmlHttp = new ActiveXObject("MSXML2.XMLHTTP") || new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) { xmlHttp = new XMLHttpRequest(); }
    } else
      xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200 && responseHandle) {
          responseHandle(xmlHttp.responseText);
        } else {
          if (errorHandle)
            errorHandle(xmlHttp.status);
        }
      }
    };
    xmlHttp.open(method, url, true);
    if (method.toLowerCase() == "post") {
      xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
      xmlHttp.send(data);
    } else
      xmlHttp.send(null);
  }
};
var typeParse = {
  intParse: function(v, def) {
    if (!v)
      return def;
    v = parseInt(v);
    return isNaN(v) ? def : v;
  },
  floatParse: function(v, def) {
    if (!v)
      return def;
    v = parseFloat(v);
    return isNaN(v) ? def : v;
  }
};
function imgSizeTo(o, w, h) {
  var wz = o.width / w;
  var hz = o.height / h;
  if (wz > hz) {
    if (wz > 1) {
      o.height = parseInt(o.height / wz);
      o.width = w;
    }
  }
  else {
    if (hz > 1) {
      o.width = parseInt(o.width / hz);
      o.height = h;
    }
  }
  o.onload = null;
}
//---flash 去除虚框
function LoadFlashForNoBorder(url, wmode, width, Height) {
  document.write(
  '<embed src="' + url + '" wmode=' + wmode +
  ' quality="high" pluginspage=http://www.macromedia.com/go/getflashplayer type="application/x-shockwave-flash" width="' + width +
  '" height="' + Height + '"></embed>');
}
//倒计时类v2
function countdown() {
  var me = this;
  this.tickSpan = 1; //单位：秒
  this.count = 0;
  this.mms = 0;
  this.addMMS = function(m) { me.mms += m; };
  this.addSeconds = function(sec) { me.mms += sec * 1000; };
  this.addMinutes = function(min) { me.mms += me.addSeconds(min * 60); };
  this.addHours = function(h) { me.mms += me.addMinutes(h * 60); };
  this.addDays = function(d) { me.mms += me.addHours(d * 24); };
  this.addDateTime = function(todate) { me.addMMS(todate.getTime() - new Date().getTime()); };
  this.addDateTimeByServer = function(todate, serverdate) { me.addMMS(todate.getTime() - serverdate.getTime()); };
  this._cd = function() {
    me.mms -= 1000;
    if (me.mms <= 0) {
      me.stop();
      me.finish();
    }
    else if (me.count++ % me.tickSpan == 0) {
      if (me.count > 3600)
        me.count = 0;
      me.tick();
    }
  };
  this._interval = null;
  this.start = function() { me._cd(); me._interval = setInterval(me._cd, 1000); };
  this.stop = function() { window.clearInterval(me._interval); };
  this.tick = function() { };
  this.finish = function() { };
  this.getTotalRemainSeconds = function() { return me.mms / 1000; };
  this.getTotalRemainMinutes = function() { return me.getTotalRemainSeconds() / 60; };
  this.getTotalRemainHours = function() { return me.getTotalRemainMinutes() / 60; };
  this.getTotalRemainDays = function() { return me.getTotalRemainHours() / 24; };
  this.getRemainSeconds = function() { return parseInt(me.mms % (60 * 1000) / 1000); };
  this.getRemainMinutes = function() { return parseInt(me.mms % (60 * 60 * 1000) / (60 * 1000)); };
  this.getRemainHours = function() { return parseInt(me.mms % (24 * 60 * 60 * 1000) / (60 * 60 * 1000)); };
  this.getRemainDays = function() { return parseInt(me.mms / (24 * 60 * 60 * 1000)); };
}
//网速测试v1.0
var NetSpeed = {
  ped: function(s) { },
  ping: function() {
    var img = document.createElement("img");
    img.style.height = "0px";
    img.style.width = "0px";
    if (img.addEventListener)
      img.addEventListener("load", NetSpeed.loaded, false);
    else if (img.attachEvent)
      img.attachEvent("onload", NetSpeed.loaded);
    else
      img["onload"] = NetSpeed.loaded;
    NetSpeed.starttime = new Date();
    img.src = "http://service.sellerbid.com/common/ping.gif?v=" + NetSpeed.starttime.getTime();
    document.body.appendChild(img);
  },
  loaded: function() {
    NetSpeed.ped((new Date().getTime() - NetSpeed.starttime.getTime()));
  },
  starttime: null
};

