function killErrors(){
  return true;
}
window.onerror = killErrors;

var FreezeTag = "iframe";
var isFreeze = true;                                                  //弹出层是否冻结页面
var FreezeID = "freeze";                                              //冻结层ID名称
var popWinID = "popwin";                                              //弹出层ID名称
var popWinBT = "窗口标题";                                            //弹出层标题
var popWin_W = 480;                                                   //弹出层宽度
var popWin_H = 320;                                                   //弹出层高度
var FreezeBG = "#000";                                                //冻结层背景色
var FreezeOP = 0.4;                                                   //冻结层透明度
var FreezeZI = 100;                                                   //冻结层深度
var popWinURL = "about:blank";                                        //弹出层连接地址
var isScroll = true;                                                  //弹出层是否滚动

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_mac = userAgent.indexOf('mac') != -1;

function $(id){
  return document.getElementById(id);
}


//获取页面尺寸信息 For XHTML 1.0
function getPosition(){
  var top;
  if(typeof window.pageYOffset != "undefined"){
    top = window.pageYOffset;
  }else if(typeof document.compatMode != "undefined" && document.compatMode != "BackCompat"){
    top = document.documentElement.scrollTop;
  }else if (typeof document.body != "undefined"){
    top = document.body.scrollTop;
  }
  var left = document.documentElement.scrollLeft;
  var height = document.documentElement.clientHeight;
  var width = document.documentElement.clientWidth;
  var pagewidth = document.documentElement.scrollWidth;
  var pageheight = document.documentElement.scrollHeight;
  var windowWidth, windowHeight;
  if(self.innerHeight){ // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  }else if(document.documentElement&&document.documentElement.clientHeight){ // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  }else if(document.body){ // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  if(is_ie){ width = windowWidth; height = windowHeight; }
  return { top: top, left: left, height: height, width: width, pagewidth: pagewidth, pageheight: pageheight };
}

//创建冻结层
function createFreezeDiv(){
  var Position = getPosition();
  var obj;
  if($(FreezeID)==null){
    obj = document.createElement(FreezeTag);
    obj.id = FreezeID;
  } else {
    obj = $(FreezeID);
  }
  obj.style.display = "block";
  obj.style.position = "absolute";
  obj.style.zIndex = FreezeZI;
  obj.style.background = FreezeBG;
  obj.style.filter = "alpha(opacity="+(FreezeOP*100)+")";
  obj.style.opacity = FreezeOP;
  obj.style.zoom = 1;
  obj.style.width = Position.pagewidth + "px";
  obj.style.height = Position.pageheight + "px";
  obj.style.top = "0px";
  obj.style.left = "0px";
  if($(FreezeID)==null){ document.body.appendChild(obj); }
}

//创建弹出层
function showPopWin(){
  if(isFreeze){ createFreezeDiv(); }
  var obj, outstr;
  if($(popWinID)==null){
    obj = document.createElement("div");
    obj.id = popWinID;
  } else {
    obj = $(popWinID);
  }
  obj.style.display  = "block";
  obj.style.position = "absolute";
  obj.style.zIndex = FreezeZI+1;
  obj.style.width    = popWin_W + "px";
  obj.style.height   = popWin_H + "px";
  outstr = "<div class=\"popwin\" style=\"width:"+(popWin_W-12)+"px;height:"+(popWin_H-12)+"px;border-width:6px;\">";
  outstr += "<div class=\"title\" style=\"width:"+(popWin_W-12-10)+"px;margin-top:5px;\"><ul>";
  outstr += "<li>" + popWinBT + "</li>";
  outstr += "<li style=\"float:right;width:20px;\"><a href=\"javascript:void(0);\" onclick=\"closePopWin();\" title=\"关闭窗口\">×</a></li>";
  outstr += "</ul></div>";
  outstr += "<div class=\"bodyer\" style=\"width:"+(popWin_W-12)+"px;height:"+(popWin_H-12-38)+"px;\">";
  outstr += "<iframe id=\"popmain\" name=\"popmain\" src=\"" + popWinURL + "\" width=\"100%\" height=\"100%\" scrolling=\"no\" border=\"0\" frameborder=\"0\"></iframe>";
  outstr += "</div>";
  outstr += "</div>";
  obj.innerHTML = outstr;
  var Position = getPosition();
  obj.style.top  = (Position.top  + (Position.height-popWin_H)/2)  + "px";
  obj.style.left = (Position.left + (Position.width-popWin_W)/2) + "px";
  if (isScroll) {
    window.onscroll = function (){
      Position = getPosition();
      obj.style.top  = (Position.top  + (Position.height-popWin_H)/2)  +"px";
      obj.style.left = (Position.left + (Position.width-popWin_W)/2) +"px";
    }
  }
  if($(popWinID)==null){ document.body.appendChild(obj); }
  document.body.focus();
}

//打开弹出层
function closePopWin(){
  $(popWinID).style.display = "none";
  if (isFreeze) { $(FreezeID).style.display = "none"; }
}

//创建XML组件
function Ajax_GetXMLHttpRequest(){
  var outstr;
  try {
    outstr = new ActiveXObjec("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      outstr = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
      try {
        outstr = new XMLHttpRequest();
      } catch (e) {
      }
    }
  }
  return outstr;
}


function topmenu(str){
  var btn = str.split(",");
  for(var i=0; i<btn.length; i++){
    dropdown(btn[i]);
  }
}

function dropdown(emt){
  $(emt).onmouseover = function() {
    $(emt).getElementsByTagName("div")[0].style.display = "block";
    $(emt).getElementsByTagName("a")[0].className += " on";
  }
  $(emt).onmouseout = function() {
    $(emt).getElementsByTagName("div")[0].style.display = "none";
    $(emt).getElementsByTagName("a")[0].className = emt;
  }
}


//读取页面广告
function loadpromotion(){
  var ptid = pt.split(",");
  var xmlhttp = Ajax_GetXMLHttpRequest();
  xmlhttp.onreadystatechange = function(){
    if(4==xmlhttp.readyState){
      if(200==xmlhttp.status){
        var xmldoc = xmlhttp.responseXML;
        for (var n=0; n<ptid.length; n++) {
          var node = getTagNameAttribute(xmldoc.getElementsByTagName("block"), ptid[n], "id");
          var block_node = xmldoc.getElementsByTagName("block")[node].getElementsByTagName("list");
          var outstr = "";
          for (var i=0; i<block_node.length; i++){
            var pt_media = block_node[i].getAttribute("media");
            var pt_link = block_node[i].getAttribute("link");
            var pt_url = block_node[i].getAttribute("url");
            var pt_width = block_node[i].getAttribute("width");
            var pt_height = block_node[i].getAttribute("height");
            switch (pt_media) {
              case "photo":
                outstr += "<div><a href=\"" + pt_link + "\" target=\"_blank\"><img src=\"" + pt_url + "\" width=\""
                outstr += pt_width + "\" height=\"" + pt_height + "\"></a></div>";
                break;
              case "flash":
                
                break;
              default:
                
            }
          }
          //if ($("promotion[" + n + "]") != null) { $("promotion[" + n + "]").innerHTML = outstr; }
          $(ptid[n]).innerHTML = outstr;
        }

      }else{
        alert(xmlhttp.status);
      }
    }
  }
  var url="/jscript/promotion.xml?t=" + new Date().getTime();
  xmlhttp.open("get",url);
  xmlhttp.send(null);
}

function getTagNameAttribute(str, emt, sid){
  var outstr = 0;
  for (var i=0; i<str.length; i++){
    if (str[i].getAttribute(sid) == emt){ outstr = i; }
  }
  return outstr;
}


//兼容IE、FireFox下获取keyCode方法
function keyCode(evt) {
  evt = evt ? evt : (window.event ? window.event : null);
  var _keyCode = evt.keyCode || evt.which || evt.charCode;
  var reallkey = String.fromCharCode(_keyCode);
  return _keyCode;
}


//集成CheckBox和Radio的Checked事件
function altStyle(obj) {
  function altStyleClear(obj) {
    var input, lis, i;
    lis = obj.parentNode.getElementsByTagName("li");
    for(i=0; i < lis.length; i++){
      lis[i].className = "";
    }
  }
  var input, lis, i, cc, o;
  cc = 0;
  lis = obj.getElementsByTagName("li");
  for(i=0; i < lis.length; i++){
    lis[i].onclick = function(e) {
      o = is_ie ? event.srcElement.tagName : e.target.tagName;
      if(cc) {
        return;
      }
      cc = 1;
      input = this.getElementsByTagName("input")[0];
      if(input.getAttribute("type") == "checkbox" || input.getAttribute("type") == "radio") {
        if(input.getAttribute("type") == "radio") {
          altStyleClear(this);
        }
        if(is_ie || o != "input" && input.onclick) {
          input.click();
        }
        if(this.className != "checked") {
          this.className = "checked";
          input.checked = true;
        } else {
          this.className = "";
          input.checked = false;
        }
      }
    }
    lis[i].onmouseup = function(e) {
      cc = 0;
    }
  }
}

//去除字符串两端空格
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
}
//去除字符串左边空格
String.prototype.ltrim = function() {
  return this.replace(/^\s+/, "");
}
//去除字符串右边空格
String.prototype.rtrim = function() {
  return this.replace(/\s+$/, "");
}

//计算字符串的字节长度，即英文算一个，中文算两个字节
String.prototype.strlen = function() {
  var len = 0;
  for (var i=0; i<this.length; i++) {   
    if (this.charCodeAt(i) > 255) { len+=2; } else { len++; }
  }
  return len;
}
//过滤HTML代码
String.prototype.HTMLEncode = function() {
  var str = "";
  str = this.replace(/&/g, "&amp;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/\'/g, "&#39;");
  str = str.replace(/\"/g, "&quot;");
  str = str.replace(/\n/g, "<br>");
  return str;
}
//转换HTML代码
String.prototype.HTMLDecode = function() {
  var str = "";
  str = this.replace(/&amp;/g, "&");
  str = str.replace(/&lt;/g, "<");
  str = str.replace(/&gt;/g, ">");
  str = str.replace(/&#39;/g, "\'");
  str = str.replace(/&quot;/g, "\"");
  str = str.replace(/<br>/g, "\n");
  return str;
}
//检查是否为正整数
function isInt(strNum){
  var reg = /^[0-9]*[1-9][0-9]*$/;
  var r = strNum.match(reg);
  if(r==null){ return false; }
  return true;
}

//等比例缩放图片，引用方式：<img src="xxx"  onload="javascript:DrawImage(this,200,200);" />
function DrawImage(ImgD,FitWidth,FitHeight){
  var image = new Image();
  image.src = ImgD.src;
  if(image.width>0 && image.height>0){
    if(image.width/image.height>= FitWidth/FitHeight){
      if(image.width>FitWidth){
        ImgD.width = FitWidth;
        ImgD.height = (image.height*FitWidth)/image.width;
      }else{
        ImgD.width = image.width;
        ImgD.height = image.height;
      }
    }else{
      if(image.height>FitHeight){
        ImgD.height = FitHeight;
        ImgD.width = (image.width*FitHeight)/image.height;
      }else{
        ImgD.width = image.width; 
        ImgD.height = image.height;
      }
    }
  }
}

//var oEditor = FCKeditorAPI.GetInstance('content') ;

// Get the editor contents in XHTML.
//alert( oEditor.GetXHTML( true ) ) ;		// "true" means you want it formatted.
//alert( oEditor.EditorDocument.body.innerText ) ;