﻿// JScript 文件

function RemoveAllNodes(TbodyID)
{
    var Tbody = document.getElementById(TbodyID);
    var Count = Tbody.childNodes.length;
    if(Count != 0)
    {
        for(i = 0; i < Count; i++)
        {
            Tbody.removeChild(Tbody.childNodes[0]);
        }
    }
}

//日期转字符串（日期）
//格式：yyyy-mm-dd
function ConvertDateTimeToString(Date)
{
    var Year = 0;
    var Month = 0;
    var Day = 0;
    var DateTime = Date.split(' ')[0].split('-');
    Year = DateTime[0];
    Month = DateTime[1];
    Day = DateTime[2];
    var DateTimeString = "";
    DateTimeString = Year + "-";
    if(Month < 10)
    {
        DateTimeString = DateTimeString + "0" + Month + "-";
    }
    else
    {
        DateTimeString = DateTimeString + Month + "-";
    }
    if(Day < 10)
    {
        DateTimeString = DateTimeString + "0" + Day;
    }
    else
    {
        DateTimeString = DateTimeString + Day;
    }
    return DateTimeString;
}


//显示一定长度的字符串信息,超出部分用".."代替(字符串,长度（中文字个数）)
function GetLenStr(str,lenNum)
{
    var i;
    var len;
    len = 0;
    for (i=0;i<str.length;i++)
    {
        if (str.charCodeAt(i)>255)
           len+=1;
        else 
           len+=0.5;
        if(len>lenNum && i<str.length)
        {
            str = str.substring(0,i)+"..";
            break;
        }
    }
    return str;
}

//
function RegConKeyDownEvent(ButtonID,TextID)
{   
      var BObj=document.getElementById(ButtonID);
      var TObj=document.getElementById(TextID);
      if(TObj!=null)
      {
          TObj.onkeydown =function(){if(window.event.keyCode==13){  
               window.event.returnValue=false;
               BObj.onclick();}
            };
      }
}

//获取字符串字节长度
function GetStringLenth(str)
{
    var len = 0;
    for (i = 0; i < str.length; i++)
    {
        if (str.charCodeAt(i) > 255)
        {
           len += 2;
        }
        else
        { 
           len++;
        }
    }
    return len;
}

function SetTimeOutJumpToPage(URL,Time)
{
    setTimeout("window.location='" + URL + "'",Time);
}


// 用正则表达式将前后空格  
// 用空字符串替代。  
function Trim(str)  
{  
    return str.replace(/(^\s*)|(\s*$)/g, "");  
}

//删除列表多余行
function deleteTableRow(TableObj,num)
{
   if(TableObj!=null)
   {
      while(TableObj.rows.length> num)
      {
          TableObj.deleteRow(-1);
      }
   }
}

function Div(exp1, exp2)
{
    var n1 = Math.round(exp1); //四舍五入
    var n2 = Math.round(exp2); //四舍五入    
    var rslt = n1 / n2; //除    
    if (rslt >= 0)
    {
        rslt = Math.floor(rslt); //返回值为小于等于其数值参数的最大整数值。
    }
    else
    {
        rslt = Math.ceil(rslt); //返回值为大于等于其数字参数的最小整数。
    }    
    return rslt;
}