﻿// JScript 文件
     /******************************************
     * 控制框架页的自适应高度        DivID是需要控制高度的最外层DIV的ID
     ******************************************/
      function InitIframe(DivID)
      {
           //控制页面大小
         var h = window.frameElement.offsetHeight ;
         document.getElementById(DivID).style.height = h-40;
         if(document.getElementById(DivID).style.height<380)
         document.getElementById(DivID).style.height=380;
      }


     /******************************************
     * 通用GridView的勾选框，全选反选事件
     ******************************************/
       //勾选事件
     function AddRemoveValues(oChk) 
     {      
         var obj = document.getElementById(HddChkID);

          CancelSelect();
          //在处理这个地方需要注意的是：你保存的值应该具有唯一性，这样才能不会替换错误的项。
          if(oChk.checked)
          obj.value += "," + oChk.value; 
          else
          {
          var obj2 = obj.value;
          obj.value = obj2.replace(','+oChk.value,''); 
         }

     }
     
    function CancelSelect()
    {
         var cbxCount = 0; //除全选复选框外的选中的复选框,
         var cbxAmount = 0;//复选框总数
         var cancelSign = 0; //判断是否取消全选标识
         var Cbox=document.getElementById(gridView_ID).getElementsByTagName("input");
         if (Cbox.length != undefined)
         {
          for(var i=0;i<=Cbox.length-1;i++)
          {
           if(Cbox[i].type=='checkbox')
           { cbxAmount = cbxAmount +1; }
           if(Cbox[i].type=='checkbox' && Cbox[i].checked==true)
           { cbxCount = cbxCount +1;     }        
           if(Cbox[i].type=='checkbox' && Cbox[i].checked==false && document.getElementById(ChkAll).checked == true)
          { 
          cancelSign = 1;
          cbxCount = cbxCount -1;
          }
           }
          }                  
    if (document.getElementById(ChkAll).checked == true && cancelSign == 1)
    { document.getElementById(ChkAll).checked = false; }
    if (document.getElementById(ChkAll).checked == false && 
             cbxAmount == cbxCount + 1)
    { document.getElementById(ChkAll).checked = true; }
    }     

     //权限、反选事件
    function SelectAllCheckboxes()
    {
         var obj = document.getElementById(HddChkID);
         var Cbox = document.getElementById(gridView_ID).getElementsByTagName("input");
       if (document.getElementById(ChkAll).checked == true)
        {
              if (Cbox.length != undefined)
                   {
               for(var i=0;i<=Cbox.length-1;i++)
                if(Cbox[i].type=='checkbox' && Cbox[i].checked==false)
                  {
                       Cbox[i].checked=true;
                         obj.value += "," + Cbox[i].value; 
                   }
               }
         }
        else
        {
        if (Cbox.length != undefined)
            {
                for(var i=0;i<=Cbox.length-1;i++)
                 if(Cbox[i].type=='checkbox' && Cbox[i].checked==true)
                   {
                          Cbox[i].checked=false;//取消值
                          var obj2 = obj.value;
                          obj.value = obj2.replace(','+Cbox[i].value,''); 
                   }
            }
         } 
    }
    
    
        /************************************
     * 根据id和IsClose的值打开或关闭某div层
     * 参数值IsClose:true/false；id表示div的id
     ************************************/
    function ExploitLegend(id)
    {
        if(document.getElementById(id).style.display=="none")
        document.getElementById(id).style.display="block";
        else
        document.getElementById(id).style.display="none";
    }

    /************************************
     * 根据给定的URL地址获取指定szName的
     * 参数值szUrl:当前url的地址；szName需要匹配的参数名
     ************************************/
    function GetQueryString(szUrl,szName)
    {
	    if (szUrl.length<2) return null;
	    var re=new RegExp(szName+"=[^&]+","i");
	    var arr=szUrl.match(re);
	    if (arr==null)
		    return null;
	    else
		    return arr[0].substring(arr[0].indexOf("=")+1,arr[0].length);
    }

    /**********************
     * 验证给定字符串是否只
     * 由数字组成
     **********************/
    function IsNumeric(text)
    {
	    text=String(text);
	    var re=/[\x2d]?[0-9]+(\x2e[0-9]+)?/i
	    var arr=text.match(re);
	    return !(arr==null || arr[0]!=text);
    }

    /************************
     * 验证邮箱地址格式
     ************************/
    function ValidEmail(email)
    {
	    email=String(email);
	    var re=/[^@]+@[^\x2e@]+\x2e[^\.@]+(\x2e[^\x2e@]+)*/i
	    var arr=email.match(re);
	    return !(arr==null || arr[0]!=email);
    }
    
    /************************
    用途：检查输入字符串是否为空或者全部都是空格

    输入：str

    如果全是空返回true,否则返回false
     ************************/    
    
    function isNull(str)
    {

    if ( str == "" ) return true;

    var regu = "^[ ]+$";

    var re = new RegExp(regu);

    return re.test(str);
    }
    
    
    /************************
    用途：检查输入字符串是否只由英文字母和数字和下划线组成

    输入： str：字符串

    如果通过验证返回true,否则返回false
     ************************/      
    function isNumberOr_Letter(str)
    { 

        var regu = "^[0-9a-zA-Z\_]+$";

        var re = new RegExp(regu);

        if (re.test(str)) 

        return true;

        else

        return false;

    }
    /**********************
    用途:tab页切换
     ***********************/
    function nTabs(thisObj,Num)
    {
      if(thisObj.className == "active")
         return;
      var tabObj = thisObj.parentNode.id;
      var tabList = document.getElementById(tabObj).getElementsByTagName("li");
      for(i=0; i <tabList.length; i++)
      {
         if (i == Num)
         {
             thisObj.className = "active";
             document.getElementById(tabObj+"_Content"+i).style.display = "block";
         }
         else
         {
             tabList[i].className = "normal"; 
             document.getElementById(tabObj+"_Content"+i).style.display = "none";
         }
      }
  }
    
     /******************************************
     * JS调用cookie类（包括创建、读取、修改、删除、清楚所有cookie）
     ******************************************/
  function eyunCookie() {
      this.key = ""; //初始化key。 
      this.value = ""; //初始化key's value。 
      this.expires = 0; //初始化cookie的有效时间，单位毫秒。 
      this.init = function()//对象初始化 
      {
          this.key = "";
          this.value = "";
          this.expires = 0;
      }
      this.set = function(key, value, expires)//设置cookie 
      {
          if (this.key == "") this.key = key;
          if (this.value == "") this.value = value;
          if (this.expires <= 0) this.expires = expires;
          if (this.key == "" || typeof (this.key) != "string") {
              //alert("请先设置欲保存的cookie名称！"); 
              this.init();
              return false;
          }
          if (this.key.match(/[,; ]/)) {
              //alert("cookie名称中不能包含“,”、“;”或空格！"); 
              this.init();
              return false;
          }
          if (this.value.toString().match(/[,; ]/) || typeof (this.value) == "undefined") {
              //alert("cookie值中不能包含“,”、“;”或空格！"); 
              this.init();
              return false;
          }
          if (this.expires <= 0 || typeof (this.expires) != "number") {
              //alert("请先正确设置cookie的有效时间！"); 
              this.init();
              return false;
          }
          var cookie = document.cookie;
          if (cookie.indexOf(this.key + "=") != -1) {
              //                     if(!confirm("欲保存的cookie名称已经存在，是否要进行替换？")) 
              //                        {
              //                           this.init(); 
              //                            return false; 
              //                        }                     
          }

          var dt = new Date();
          dt.setTime(dt.getTime() + this.expires);
          document.cookie = this.key + "=" + this.value + ";expires=" + dt.toGMTString();

          this.init();
          return true;
      }



      this.get = function(key)//取得名为key的cookie的值 
      {
          if (key == "" || key.match(/[,; ]/)) {
              //alert("请正确设置欲查找的cookie名称！") 
              return false;
          }

          var cookie = document.cookie;
          var start = cookie.indexOf(key + "=");

          if (start == -1) {
              //alert("欲查找的cookie不存在！") 
              return false;
          }

          var end = cookie.indexOf(";", start);
          if (end == -1)
              end = cookie.length;
          var getCookie = cookie.substring(start + key.length + 1, end);
          //alert("cookie："+key+"的值为"+getCookie); 
          return getCookie;
      }



      this.showAll = function() {
          alert("共有以下cookie对：\n" + document.cookie.split(";").toString().replace(/,/g, "\n"));
      } //显示所有cookie 



      this.del = function(key)//删除名为key的cookie 
      {
          if (key == "" || key.match(/[,; ]/)) {
              //alert("请正确设置欲删除的cookie名称！") 
              return false;
          }

          var dt = new Date();
          dt.setTime(dt.getTime());
          document.cookie = key + "=eyunDelete;expires=" + dt.toGMTString();
          this.init();
          return true;
      }



      this.destroy = function()//销毁所有cookie 
      {
          var dt = new Date();
          dt.setTime(dt.getTime());
          while (document.cookie != "")
              document.cookie = document.cookie + ";expires=" + dt.toGMTString();
          this.init();
          return true
      }
  }


  /**********************************************************
  * md5.js
  *
  * A JavaScript implementation of the RSA Data Security, Inc. MD5
  * Message-Digest Algorithm.
  *
  * Copyright (C) Paul Johnston 1999. Distributed under the LGPL.
  ***********************************************************/

  /* to convert strings to a list of ascii values */
  var sAscii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  var sAscii = sAscii + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

  /* convert integer to hex string */
  var sHex = "0123456789ABCDEF";
  function hex(i) {
      h = "";
      for (j = 0; j <= 3; j++) {
          h += sHex.charAt((i >> (j * 8 + 4)) & 0x0F) +
sHex.charAt((i >> (j * 8)) & 0x0F);
      }
      return h;
  }

  /* add, handling overflows correctly */
  function add(x, y) {
      return ((x & 0x7FFFFFFF) + (y & 0x7FFFFFFF)) ^ (x & 0x80000000) ^ (y & 0x80000000);
  }

  /* MD5 rounds functions */
  function R1(A, B, C, D, X, S, T) {
      q = add(add(A, (B & C) | (~B & D)), add(X, T));
      return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
  }

  function R2(A, B, C, D, X, S, T) {
      q = add(add(A, (B & D) | (C & ~D)), add(X, T));
      return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
  }

  function R3(A, B, C, D, X, S, T) {
      q = add(add(A, B ^ C ^ D), add(X, T));
      return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
  }

  function R4(A, B, C, D, X, S, T) {
      q = add(add(A, C ^ (B | ~D)), add(X, T));
      return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
  }

  /* main entry point */
  function calcMD5(sInp) {

      /* Calculate length in machine words, including padding */
      wLen = (((sInp.length + 8) >> 6) + 1) << 4;
      var X = new Array(wLen);

      /* Convert string to array of words */
      j = 4;
      for (i = 0; (i * 4) < sInp.length; i++) {
          X[i] = 0;
          for (j = 0; (j < 4) && ((j + i * 4) < sInp.length); j++) {
              X[i] += (sAscii.indexOf(sInp.charAt((i * 4) + j)) + 32) << (j * 8);
          }
      }

      /* Append padding bits and length */
      if (j == 4) {
          X[i++] = 0x80;
      }
      else {
          X[i - 1] += 0x80 << (j * 8);
      }
      for (; i < wLen; i++) { X[i] = 0; }
      X[wLen - 2] = sInp.length * 8;

      /* hard-coded initial values */
      a = 0x67452301;
      b = 0xefcdab89;
      c = 0x98badcfe;
      d = 0x10325476;

      /* Process each 16-word block in turn */
      for (i = 0; i < wLen; i += 16) {
          aO = a;
          bO = b;
          cO = c;
          dO = d;

          a = R1(a, b, c, d, X[i + 0], 7, 0xd76aa478);
          d = R1(d, a, b, c, X[i + 1], 12, 0xe8c7b756);
          c = R1(c, d, a, b, X[i + 2], 17, 0x242070db);
          b = R1(b, c, d, a, X[i + 3], 22, 0xc1bdceee);
          a = R1(a, b, c, d, X[i + 4], 7, 0xf57c0faf);
          d = R1(d, a, b, c, X[i + 5], 12, 0x4787c62a);
          c = R1(c, d, a, b, X[i + 6], 17, 0xa8304613);
          b = R1(b, c, d, a, X[i + 7], 22, 0xfd469501);
          a = R1(a, b, c, d, X[i + 8], 7, 0x698098d8);
          d = R1(d, a, b, c, X[i + 9], 12, 0x8b44f7af);
          c = R1(c, d, a, b, X[i + 10], 17, 0xffff5bb1);
          b = R1(b, c, d, a, X[i + 11], 22, 0x895cd7be);
          a = R1(a, b, c, d, X[i + 12], 7, 0x6b901122);
          d = R1(d, a, b, c, X[i + 13], 12, 0xfd987193);
          c = R1(c, d, a, b, X[i + 14], 17, 0xa679438e);
          b = R1(b, c, d, a, X[i + 15], 22, 0x49b40821);

          a = R2(a, b, c, d, X[i + 1], 5, 0xf61e2562);
          d = R2(d, a, b, c, X[i + 6], 9, 0xc040b340);
          c = R2(c, d, a, b, X[i + 11], 14, 0x265e5a51);
          b = R2(b, c, d, a, X[i + 0], 20, 0xe9b6c7aa);
          a = R2(a, b, c, d, X[i + 5], 5, 0xd62f105d);
          d = R2(d, a, b, c, X[i + 10], 9, 0x2441453);
          c = R2(c, d, a, b, X[i + 15], 14, 0xd8a1e681);
          b = R2(b, c, d, a, X[i + 4], 20, 0xe7d3fbc8);
          a = R2(a, b, c, d, X[i + 9], 5, 0x21e1cde6);
          d = R2(d, a, b, c, X[i + 14], 9, 0xc33707d6);
          c = R2(c, d, a, b, X[i + 3], 14, 0xf4d50d87);
          b = R2(b, c, d, a, X[i + 8], 20, 0x455a14ed);
          a = R2(a, b, c, d, X[i + 13], 5, 0xa9e3e905);
          d = R2(d, a, b, c, X[i + 2], 9, 0xfcefa3f8);
          c = R2(c, d, a, b, X[i + 7], 14, 0x676f02d9);
          b = R2(b, c, d, a, X[i + 12], 20, 0x8d2a4c8a);

          a = R3(a, b, c, d, X[i + 5], 4, 0xfffa3942);
          d = R3(d, a, b, c, X[i + 8], 11, 0x8771f681);
          c = R3(c, d, a, b, X[i + 11], 16, 0x6d9d6122);
          b = R3(b, c, d, a, X[i + 14], 23, 0xfde5380c);
          a = R3(a, b, c, d, X[i + 1], 4, 0xa4beea44);
          d = R3(d, a, b, c, X[i + 4], 11, 0x4bdecfa9);
          c = R3(c, d, a, b, X[i + 7], 16, 0xf6bb4b60);
          b = R3(b, c, d, a, X[i + 10], 23, 0xbebfbc70);
          a = R3(a, b, c, d, X[i + 13], 4, 0x289b7ec6);
          d = R3(d, a, b, c, X[i + 0], 11, 0xeaa127fa);
          c = R3(c, d, a, b, X[i + 3], 16, 0xd4ef3085);
          b = R3(b, c, d, a, X[i + 6], 23, 0x4881d05);
          a = R3(a, b, c, d, X[i + 9], 4, 0xd9d4d039);
          d = R3(d, a, b, c, X[i + 12], 11, 0xe6db99e5);
          c = R3(c, d, a, b, X[i + 15], 16, 0x1fa27cf8);
          b = R3(b, c, d, a, X[i + 2], 23, 0xc4ac5665);

          a = R4(a, b, c, d, X[i + 0], 6, 0xf4292244);
          d = R4(d, a, b, c, X[i + 7], 10, 0x432aff97);
          c = R4(c, d, a, b, X[i + 14], 15, 0xab9423a7);
          b = R4(b, c, d, a, X[i + 5], 21, 0xfc93a039);
          a = R4(a, b, c, d, X[i + 12], 6, 0x655b59c3);
          d = R4(d, a, b, c, X[i + 3], 10, 0x8f0ccc92);
          c = R4(c, d, a, b, X[i + 10], 15, 0xffeff47d);
          b = R4(b, c, d, a, X[i + 1], 21, 0x85845dd1);
          a = R4(a, b, c, d, X[i + 8], 6, 0x6fa87e4f);
          d = R4(d, a, b, c, X[i + 15], 10, 0xfe2ce6e0);
          c = R4(c, d, a, b, X[i + 6], 15, 0xa3014314);
          b = R4(b, c, d, a, X[i + 13], 21, 0x4e0811a1);
          a = R4(a, b, c, d, X[i + 4], 6, 0xf7537e82);
          d = R4(d, a, b, c, X[i + 11], 10, 0xbd3af235);
          c = R4(c, d, a, b, X[i + 2], 15, 0x2ad7d2bb);
          b = R4(b, c, d, a, X[i + 9], 21, 0xeb86d391);

          a = add(a, aO);
          b = add(b, bO);
          c = add(c, cO);
          d = add(d, dO);
      }
      return hex(a) + hex(b) + hex(c) + hex(d);
  }
