﻿

function $D(d) { return document.getElementById(d); }

function $N(d) { return document.getElementsByName(d); }


/* 加入收藏夹 */
function bookmark(t, u) {
  var title, url
  if (t == '')
    title = document.title;
  else
    title = t
  if (u == '')
    url = document.location.href
  else
    url = u;

  if (window.sidebar)
    window.sidebar.addPanel(title, url, "");
  else if (window.opera && window.print) {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel', 'sidebar');
    mbm.setAttribute('href', url);
    mbm.setAttribute('title', title);
    mbm.click();
  }
  else if (document.all)
    window.external.AddFavorite(url, title);
}

//通用展开/隐藏.
function ShowHide(item) {
  var cont = item;
  var objCont = document.getElementById(cont);
  if (objCont.style.display == "none") {
    objCont.style.display = "block";
  }
  else
    objCont.style.display = "none";
}

function SetCookie(name, value) {
  var expdate = new Date();
  expdate.setTime(expdate.getTime() + 1000 * (24 * 60 * 60 * 1000));
  document.cookie = name + "=" + escape(value) + ";expires=" + expdate.toGMTString();
}

function GetCookie(name) {
  var tCookie = document.cookie.split("; ");
  for (var i = 0; i < tCookie.length; i++) {
    var aCrumb = tCookie[i].split("=");
    if (name == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  return "";
}
function GetInt32(objValue) {
  return parseInt(objValue, 10);
}

function ConfirmAction(str) {
  if (confirm(str))
    return true;
  else
    return false;
}

function SelectAll() {
  for (var i = 0; i < document.form1.selectid.length; i++) {
    var e = document.form1.selectid[i];
    e.checked = !e.checked;
  }
}

//功能：根据所有的单个复选框状态确定"全选"复选框的状态.
//参数：paraSimgle单个复选框的name属性值.
//      paraAll"全选"复选框的id属性值.
function ChkSingle(paraSimgle, paraAll) {
  var result = 0;
  $D(paraAll).checked = false;
  var arr = $N(paraSimgle);
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].checked == true) {
      result++;
    }
  }
  if (result == arr.length)
    $D(paraAll).checked = true;
  return result;
}

//功能：根据"全选"复选框状态确定所有的单个复选框的状态.
//参数：paraSimgle单个复选框的name属性值.
//      paraAll"全选"复选框的id属性值.
function ChkAll(paraSimgle, paraAll) {
  var arr = $N(paraSimgle);
  for (var i = 0; i < arr.length; i++)
    arr[i].checked = $D(paraAll).checked;
  if ($D(paraAll).checked)
    return arr.length;
  else
    return 0;
}

function ConfirmButton(obj) {
  if (!Page_ClientValidate()) {
    obj.style.display = "inline";
    return false;
  }
  else {
    obj.style.display = "none";
    return true;
  }
}
function ConfirmButton(obj, gname) {
    if (!Page_ClientValidate(gname)) {
        obj.style.display = "block";
        return false;
    }
    else {
        obj.style.display = "none";
        return true;
    }
}

//功能：给表格第一列(标题列)添加背景色
//参数：TabID表格ID属性值.
//      BeginTrNum开始的行号.
function AddBgcolorForTable(TabID, BeginTrNum) {
  var TabObj = $D(TabID);
  var sTDBgcolor = '#E8F5FF';
  for (var i = BeginTrNum; i < TabObj.rows.length; i++) {
    if (TabObj.rows[i].style.display != 'none') {
      TabObj.rows[i].cells[0].bgColor = sTDBgcolor;
      if (sTDBgcolor == '#E8F5FF')
        sTDBgcolor = 'DEEFFF';
      else
        sTDBgcolor = '#E8F5FF';
    }
  }
}

function center(obj) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(obj).height();
    var popupWidth = $(obj).width();
    $(obj).css({
        "position": "absolute",
        "z-index": "4",
        "top": (windowHeight - popupHeight) / 2 + $(document).scrollTop(),
        "left": (windowWidth - popupWidth) / 2
    });
} 
