﻿    //function $(objID) { return document.getElementById(objID); }
    //keydown事件
    function entryToTab() {
        ///	<summary>
        ///		keydown事件转换成tab按钮
        ///	</summary>
       var sTagName = event.srcElement.tagName.toLowerCase(); 
       if   (window.event.keyCode==13 && sTagName != 'textarea')   window.event.keyCode=9 ;  //Tab键
    }
    
  
 
    //前后空格
    String.prototype.trim = function() {
    ///	<summary>
    ///		出除前后空格
    ///	</summary>
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
    } 
    //前空格
    String.prototype.ltrim = function() 
    { 
    return this.replace(/(^\s*)/g, ""); 
    } 
    //后空格
    String.prototype.rtrim = function() 
    { 
    return this.replace(/(\s*$)/g, ""); 
    }

    
    //keypress
    function checkNumber() {
        ///	<summary>
        ///		检测是否是数字型
        ///	</summary>
        if ((event.keyCode >= 48) && (event.keyCode <= 57)) {
            event.returnValue = true;
        }
        else {
            event.returnValue = false;
        }
    }

    //keypress
    function checkDouble(obj) {
        if (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 46)) {
            if (event.keyCode == 46) {
                if (obj.value.indexOf('.') >= 0 || obj.value == "")
                    event.returnValue = false;
            }
            else
                event.returnValue = true;
        }
        else {
            event.returnValue = false;
        }
    }
    var patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
    function checkCN(obj) {
        ///	<summary>
        ///		检测输入的是否中文，如果是中文则去除
        ///	</summary>
        ///	<param name="val" type="stringvalue">要检测的字符串。</param>
        
        if (patrn.test(obj.value)) {
            obj.value = obj.value.replace(patrn, '');
        }
    }
    
     var regemail=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
     //onblur
     function checkEmail(email)
     {
         return regemail.test(email);
     }
     
     var regmobile=/^(13[0-9]|15[^4]|18[6|7|8|9])\d{8}$/;
     var regphone = /^((0\d{2,3}))?(([-]?)\d{8,12})+([-](\d{1,7}))?$/;
     //\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}  
     ///^((0\d{2,3}))?(([-]?)\d{7,8})+([-](\d{1,7}))?$/;
     
     function checkPhone(phone)//电话
     {
		return regphone.test(phone);
     }
     function checkMobile(mobile)//手机
     {
         return regmobile.test(mobile);
     }

    //检查obj长度在max和min之间
     function checkLength(obj, minlength, maxlength) {
         ///	<summary>
         ///		检测obj.value是否在最小长度和最大长度之间
         ///	</summary>
         ///	<param name="val" type="stringvalue">要检测的字符串。</param>
         if (obj.value.length <= maxlength && obj.value.length >= minlength)
             return true;
         return false;
     }
        
     //显示日期 span的id 和是否显示时间，否则只显示日期
     function showDateTime(objid, showtime) {
     
         today = new Date();

         var year = today.getFullYear();
         var month = today.getMonth() + 1;
         var day = today.getDate();
         var timetext = "";
         if (showtime) {
             var hours = today.getHours();
             var minutes = today.getMinutes();
             var seconds = today.getSeconds();
             var timeValue = hours; //((hours >12) ? hours -12 :hours);
             timeValue += ((minutes < 10) ? ":0" : ":") + minutes + "";
             //timeValue += (hours >= 12) ? "PM" : "AM";
             timeValue += ((seconds < 10) ? ":0" : ":") + seconds + "";
             timetext = year + "年" + month + "月" + day + "日  " + '星期' + '日一二三四五六'.charAt(new Date().getDay()) + '  ' + timeValue;

         }
         else {
             timetext = year + "年" + month + "月" + day + "日  " + '星期' + '日一二三四五六'.charAt(new Date().getDay());
         }
         
         document.getElementById(objid).innerHTML = timetext;
         if (showtime) {
             setTimeout("showDateTime('"+objid+"',"+showtime+")", 1000); //设置过1000毫秒就是1秒，调用showtime方法
         }
     }
     
     //显示模态对话框
     function showmodal(url, width, height) {
         ///	<summary>
         ///		显示模态对话框
         ///	</summary>
         ///	<param name="url" type="string">url</param>
         ///	<param name="width" type="string">宽度 ‘600px’</param>
         ///	<param name="height" type="string">高度 ‘500px’</param>
         var szFeatures = 'dialogWidth:' + width + ';dialogHeight:' + height + ';center:yes;help:no;resizable:yes;status:no;scroll:yes;';
         var str = window.showModalDialog(url, '', szFeatures);
         return str;
     }
        
       //设置控件焦点
      function setFocus(obj) {
          window.setTimeout("document.getElementById('" + obj.id + "').focus()", 50);
          obj.select();
      }
      
      ///处理IE6加载png图片问题 onload(this)
      function loadPng(o) {
          var Brow = new Object();
          Brow.Browser = {
              ie: /msie/.test(window.navigator.userAgent.toLowerCase()),
              moz: /gecko/.test(window.navigator.userAgent.toLowerCase()),
              opera: /opera/.test(window.navigator.userAgent.toLowerCase()),
              safari: /safari/.test(window.navigator.userAgent.toLowerCase())
          };
          if (Brow.Browser.ie) {
              try {
                  var img = o; var imgName = o.src.toUpperCase(); if (imgName.substring(imgName.length - 3, imgName.length) == "PNG")
                  { var imgID = (img.id) ? "id='" + img.id + "' " : ""; var imgClass = (img.className) ? "class='" + img.className + "' " : ""; var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; var imgStyle = "display:inline-block;" + img.style.cssText; if (img.align == "left") imgStyle = "float:left;" + imgStyle; if (img.align == "right") imgStyle = "float:right;" + imgStyle; if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle; var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>"; img.outerHTML = strNewHTML; }
              } catch (e) { }
          }
      }
      
     //创建xmlhttp对象;进行ajax操作
      function createxmlhttp()
      {
          var xmlhttp = false;
          try {
              xmlhttp = new ActiveXObject("Msxml12.XMLHTTP");
          }
          catch (e) {
              try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e) {
                  //xmlhttp=new XMLHttpRequest();
                  xmlhttp = false;
              }
          }
          if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
              xmlhttp = new XMLHttpRequest();
              if (xmlhttp.overrideMimeType) {
                  xmlhttp.overrideMimeType('text/xml'); //是指MIME类别;
              }
          }
          return xmlhttp;
      }

      //setRowColor("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
      function setRowColor(o, a, b, c, d) {
          //            if(document.getElementById(o)==null)
          //                return;
          try {
              var t = document.getElementById(o).getElementsByTagName("tr");
          }
          catch (e) {
              return;
          }
          if (t == null)
              return;
          for (var i = 0; i < t.length; i++) {
              t[i].style.backgroundColor = (i % 2 == 0) ? a : b;
              //click颜色暂时去掉  sjfe_cn
//              t[i].onclick = function() {
//                  //            //   if(this.x!="1"){
//                  //            //    this.x="1";//本来打算直接用背景色判断，FF获取到的背景是RGB值，不好判断
//                  //            //    this.style.backgroundColor=d;
//                  //            //   }else{
//                  //                this.x="0";
//                  //                this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
//                  //            //   }



//                  if (event.srcElement.parentElement.className != "dgfooter" && event.srcElement.parentElement.className != "dvfooter")// && row!=null)
//                  {
//                      //GridViewColor(GridViewId,NormalColor,AlterColor,HoverColor,SelectColor,SelectChk);
//                      var tmp = this.style.background;
//                      var first = true; ;

//                      for (var j = 0; j < t.length; j++) {
//                          t[j].x = "0";
//                          if (t[j].style.background == d) {

//                              first = false;
//                              t[j].style.background = (j % 2 == 0) ? a : b;

//                          }
//                      }

//                      if (tmp == d) {
//                          this.style.background = (this.sectionRowIndex % 2 == 0) ? a : b;
//                          this.x = "0";
//                      }
//                      else {
//                          this.style.background = d;
//                          this.x = "1";
//                      }
//                  }

//              }
              t[i].onmouseover = function() {

                  if (this.x != "1") this.style.background = c; //this.style.cursor = 'pointer';

              } //

              t[i].onmouseout = function() {
                  if (this.x != "1") {
                      this.style.background = (this.sectionRowIndex % 2 == 0) ? a : b;
                  }
              }
          }
      }
      //GridView颜色
      function setColor(dvobj) {
          setRowColor(dvobj, '#ffffff', '#ffffff', '#E7F4F7', '#ccffff'); //#ecf9fc
      }

      //treeview的复选框js联动onclick= SelectNodes(this)
      function SelectNodes(obj) {

          var evt = window.event || arguments.callee.caller.arguments[0]; // 获取event对象
          var o = evt.srcElement || evt.target; // 获取触发事件的源对象

          //var o = window.event.srcElement;
          var inputobj;
          if (o.tagName == "INPUT" && o.type == "checkbox") {
              var parentobj = o.parentNode;
              inputobj = o;
              while (parentobj.tagName != "TABLE") {
                  parentobj = parentobj.parentNode
              }
              var nextobj = parentobj.nextSibling
              if (nextobj != null) {
                  if (nextobj.tagName == "DIV") {
                      var x = nextobj.getElementsByTagName("INPUT");
                      //var s = "";
                      //处理子节点
                      for (var i = 0; i < x.length; i++) {
                          if (x[i].tagName == "INPUT" && x[i].type == "checkbox") {
                              if (inputobj.checked)
                                  x[i].checked = true
                              else
                                  x[i].checked = false
                          }
                      }
                  }
              }
              //处理父节点,选中才处理父节点
              if (inputobj.checked) {
                  parentobj = parentobj.parentNode;
                  while (parentobj.id != obj.id) {
                      while (parentobj.tagName != "DIV") {
                          parentobj = parentobj.parentNode
                      }

                      var preNode = parentobj.previousSibling;
                      if (preNode.tagName == "TABLE") {
                          var chk = preNode.getElementsByTagName("INPUT");
                          for (var j = 0; j < chk.length; j++) {
                              if (chk[j].tagName == "INPUT" && chk[j].type == "checkbox") {
                                  chk[j].checked = true;
                              }
                          }
                      }
                      parentobj = preNode.parentNode;
                  }
              }

          }
      }
