    /*
     * 检查字段是否为空或只包括空字符串
     * @param field 待检查字段
     * @param message 提示信息
     */
    function checkNull(field,message)
    {
        var value = packStr(field.value);
        if(value.length < 1)
        {
            field.select();
            field.focus();
            alert(message);
            return true;
        }
        return false;
    }

    /*
     * 检查字段长度是否小于指定长度(去除前面空格和后面空格)
     * @param field 待检查字段
     * @param length 指定最小长度
     * @param message 提示信息
     */
    function checkMinLength(field,length,message)
    {
        var value = packStr(field.value);
        if(value.length < length)
        {
            field.select();
            field.focus();
            alert(message);
            return true;
        }
        return false;
    }

    function getSelectedOptionArray(from)
    {
        var array1 = new Array();
        for (var i = 0; i < from.length; i++)
        {
              if (from[i].selected)
              {
                array1.push(from[i]);
              }
        }
        return array1;
    }

    function getSelectedOptionValueAndTextArray(from,values,labels)
    {
        for (var i = 0; i < from.length; i++)
        {
              if (from[i].selected)
              {
                values.push(from[i].value);
                labels.push(from[i].text);
              }
        }
    }

    /*
     * 检查字段长度是否大于指定长度(去除前面空格和后面空格)
     * @param field 待检查字段
     * @param length 指定最小长度
     * @param message 提示信息
     */
    function checkMaxLength(field,length,message)
    {
        var value = packStr(field.value);
        if(value.length > length)
        {
          if (field.type != "hidden")
          {
            field.select();
            field.focus();
          }
            alert(message);
            return true;
        }
        return false;
    }

    /**
     * 去除value的前面空格和后面空格
     */
    function packStr(value)
    {
        var index = 0;
        do{
          index = value.indexOf(" ");
          if(index == 0)
          {
            value = value.substring(1);
          }
        }while(index == 0)

        do{
          index = value.lastIndexOf(" ");
          if(index == value.length - 1)
          {
            value = value.substring(0,value.length - 1);
          }
        }while(index == value.length)
        return value;
    }
    /**
     *  从一个select移动选中的option到另一个select,
     *  不在目标添加已包含的项目
     *  @param from 源
     *  @param target 目标
     *  @param remove 若为真，则将选中的项目从源去除
     */
    function oneToOne(from,target,remove,targetMaxLength)
    {
        if(remove == null)
        {
            remove = false;
        }

        if(targetMaxLength == null)
        {
            targetMaxLength = 100000;
        }

        for (var i = 0; i < from.length; i++)
        {
              var temp = null;
              if (from[i].selected)
              {
                temp = from[i];
                if(remove)
                {
                  from[i--] = null;
                }

              }

              if(temp != null && target.length < targetMaxLength)
              {
                var add = true;
                for(var j = 0;j < target.length;j++)
                {
                    if(target[j].value == temp.value)
                    {
                        add = false;
                        break;
                    }
                }
                if(add)
                {
                    target.options[target.length] = new Option(temp.text,temp.value);
                    target.options[target.length - 1].selected = true;
                }
              }
        }

    }

    /**
     * 移除下拉列表中选中的项目
     */
    function removeOption(from)
    {
        for (var i = 0; i < from.length; i++)
        {
              if (from[i].selected)
              {
                from[i--] = null;
              }
        }
    }

    /**
     * 选中下拉列表中选所有的项目
     */
    function selectAllOption(from)
    {
        for (var i = 0; i < from.length; i++)
        {
              from[i].selected = true;
        }
    }

    function doRequest(url,checkfield,parameterName)
    {
        doRequest(url,checkfield,parameterName,200,200);
    }

    function changeRelCheckBox(mainCheckfield,toCheckfield)
    {
        if(mainCheckfield != null)
        {
            doCheckedAction(toCheckfield,mainCheckfield.checked);
        }
    }

    function doCheckedAction(checkfield,toState)
    {
        var ids = checkfield;
        var idlength = 0;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              ids[i].checked = toState;
              idlength++;
            }
            if(idlength <= 0 )
            {
                ids.checked = toState;
            }
        }
    }

    function checkedAll(checkfield)
    {
        doCheckedAction(checkfield,true);
    }

    function cancelAllchecked(checkfield)
    {
        doCheckedAction(checkfield,false);
    }



    function doCreatePostValueFromCheckBox(checkfield,parameterName)
    {

        var url = "&";
        var idlength = 0;
        var ids = checkfield;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              if(ids[i].checked)
              {
                url += "&"+parameterName+"=" + ids[i].value;
                idlength++;
              }
            }
            if(idlength <= 0 )
            {
                if(ids.checked)
                {
                    url += "&"+parameterName+"=" + ids.value;
                    idlength++;
                }
            }
        }
        if(idlength == 0)
        {
          alert("请至少选择一个记录");
          return false;
        }
        return url;
    }

    function doRequest(url,checkfield,parameterName,width,height)
    {

        url += "&";
        var idlength = 0;
        var ids = checkfield;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              if(ids[i].checked)
              {
                url += "&"+parameterName+"=" + ids[i].value;
                idlength++;
              }
            }
            if(idlength <= 0 )
            {
                if(ids.checked)
                {
                    url += "&"+parameterName+"=" + ids.value;
                    idlength++;
                }
            }
        }
        if(idlength == 0)
        {
          alert("请选择至少一个记录");
          return;
        }
        window.showModalDialog(url,window,'scroll=0');
       // window.open(url,'','width='+width+',height='+height);
    }
    /**
     * 提交申请，checkbox列表只选中一个
     */
    function doRequestOne(url,checkfield,parameterName,width,height)
    {
        url += "&";
        var idlength = 0;
        var ids = checkfield;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              if(ids[i].checked)
              {
                url += "&"+parameterName+"=" + ids[i].value;
                idlength++;
              }
            }
            if(idlength <= 0 )
            {
                if(ids.checked)
                {
                    url += "&"+parameterName+"=" + ids.value;
                    idlength++;
                }
            }
        }
        if(idlength == 0 || idlength > 1)
        {
          alert("请选择至少一个记录");
          return;
        }
        window.showModalDialog(url,window,'scroll=0');
       // window.open(url,'','width='+width+',height='+height+',scrollbars=auto');
    }

    /**
     * 检查是否有且仅有一个checkbox被选中，若是返回checkbox value;
     */
    function checkOneCheck(checkfield)
    {

        var idlength = 0;
        var ids = checkfield;
        var value = null;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              if(ids[i].checked)
              {
                value = ids[i].value;
                idlength++;
              }
            }
            if(idlength <= 0 )
            {
                if(ids.checked)
                {
                    ids = ids.value;
                    idlength++;
                }
            }
        }
        if(idlength != 1)
        {
            return null;
        }
        else
        {
            return value;
        }

    }

    /**
     * 检查是否有且仅有一个checkbox被选中，若是返回checkbox value;
     */
    function getCheckedBox(checkfield)
    {
        var values = new Array();
        var idlength = 0;
        var ids = checkfield;
        if(ids != null){
            for(i = 0;i < ids.length;i++)
            {
              if(ids[i].checked)
              {
                values.push(ids[i]);
                idlength++;
              }
            }
            if(idlength <= 0 )
            {
                if(ids.checked)
                {
                    values.push(ids);
                    idlength++;
                }
            }
        }
        return values;

    }


    function doRequestBig(url,checkfield,parameterName)
    {
        doRequest(url,checkfield,parameterName,800,600);
    }

    /**
     * 检查参数是否为整型
     */
    function isInt(value)
    {
      var tmp = parseInt(value)
      if (isNaN(tmp))
      {
        return false
      }
      else if (tmp.toString() == value)
      {
        return true
      }
      else
      {
        return false
      }
    }

    /**
     * 检查表单域的值是否为整型,并且大小在min和max之间
     * 检查出错时候是否弹出消息
     * field    表单域
     * min      最小值
     * max      最大值
     * message  弹出对话框的消息,null值或者空消息就不弹出
     */
    function checkInt(field, min, max, message)
    {
      var b = isInt(field.value);
      if (b)
      {
        value = parseInt(field.value);
        if (value < min || value > max)
        {
          b = false;
        }
      }
      if (!b && message != "" && message != null)
      {
        alert(message);
      }
      field.select();
      field.focus();
      return b;
    }

    function prePage(form,pageNoField)
    {
        if(pageNoField.value == 1 || pageNoField.value == 0)
        {
            alert("当前第一页");
            return false;
        }
        pageNoField.value = parseInt(pageNoField.value) - 1;
        form.submit();
    }

    function nextPage(form,pageNoField,totalPageNoField)
    {
        if(pageNoField.value ==  totalPageNoField.value)
        {
            alert("当前为最后一页");
            return false;
        }
        pageNoField.value = parseInt(pageNoField.value) + 1;
        form.submit();
    }

    function setPageNo(pageNoField, pn, tp)
    {
       pageNo = parseInt(pn);
       totalPage = parseInt(tp);
       if (pageNo < 1)
       {
         pageNoField.value = 1;
       }
       else  if (pageNo > totalPage)
       {
         pageNoField.value = totalPage;
       }else
       {
         pageNoField.value = pageNo;
       }
    }

   function showWindow(url) {
       window.showModalDialog(url,window,"status:false");
    }

    function checkedCheckBox(checkbox,i)
    {
        var ids = checkbox;
        if(ids != null)
        {

            if(ids[i] != null)
            {
              ids[i].checked = true;
            }else
            {
              ids.checked = true;
            }

        }

    }

    

    function onCheckBox(checkbox)
    {
      if(checkbox.checked)
      {
         checkbox.value = "true";
      }else
      {
         checkbox.value = "false";
      }
    }


