﻿ //页面的一般操作
 //建立人：姚晶
 //建立时间：2008.2.25
 //说明：页面的常规操作
 
 //1.div拖动，使用说明：did(div的id名)
  var   ms=0;     
  function   did(obj)
  {   
      ms=obj;   
      event.srcElement.setCapture();   
      x=document.all(ms).style.pixelLeft-event.x;   
      y=document.all(ms).style.pixelTop-event.y;  
  }   
    
  function   document.onmousemove()
  {   
      if(ms)
      {   
          document.all(ms).style.pixelLeft=x+event.x;   
          document.all(ms).style.pixelTop=y+event.y;   
      }   
  }   
    
  function   document.onmouseup()
  {   
      if(ms)
      {   
          event.srcElement.releaseCapture();   
          ms=0;   
      }   
  }   
  
  //2.创建一个StringBuilder类
  //自定义动态字串连接类，替换字串的+=操作功能
function StringBuilder()
{
    this._element_ =new Array();
}
StringBuilder.prototype.append=function(item)
{
    this._element_.push(item);
}
StringBuilder.prototype.toString=function()
{
    return this._element_.join("");
}
StringBuilder.prototype.join=function(separator)
{
    return this._element_.join(separator);
}
StringBuilder.prototype.length=function()
{
    return this._element_.length;
}

//关闭div对象
//参数为对象ID
function DeleteDiv(value) {
    var obj = $("#" + value);
    if (obj != null) {
        obj.hide();
    }
}

//下拉框选择
function select(name, value) {
    $(document).ready(function() {
        $('select[name="' + name + '"]').find('option').each(function(i) {
            if ($(this).val() == value) {
                $(this).attr('selected', 'selected');
                return false;
            }
        });
    });
}

//各选择功能
//多选下拉框
function selectMore(obj, value) {
    //计数器
    var j = 0;
    var strCheck = value.split(',');
    var num=strCheck.length;
    $(document).ready(function() {
        obj.find('option').each(function(i) {
            for (var k = 0; k < num; k++) {
                if ($(this).val() == strCheck[k]) {
                    $(this).attr('selected', 'selected');
                    j++;
                    break;
                }
                if (j == num) {
                    //全部选择完成，跳出循环
                    return false;
                }
            }
        });
    });
}

//单选选择
function selRadio(name, value) {
    $(document).ready(function() {
        $('input[name="' + name + '"]').each(function(i) {
            if ($(this).val() == value) {
                $(this).attr('checked', 'checked');
                return false;
            }
        });
    });
}

//复试多选
function selCheckbox(name, value) {
    if (jQuery.trim(value) == '') return;
    $(document).ready(function() {
        var strCheck = value.split(',');
        //创建一个计数器，如果全部选择完成跳出循环
        var j = 0;
        $('input[name="' + name + '"]').each(function(i) {
            for (var k = 0; k < parseInt(strCheck.length); k++) {
                if ($(this).val() == strCheck[k]) {
                    $(this).attr('checked', 'checked');
                    j++;
                    break;
                }
            }
            if (j == strCheck.length) {
                //全部选择完成，跳出循环
                return false;
            }
        });
    });
}

//获取值
//单选
function getRadio(obj) {
    var value = "";
    $(document).ready(function() {
        obj.each(function(i) {
            if ($(this).attr('checked') == true) {
                value = $(this).val();
                return false;
            }
        });
    });
    return value;
}

//判断输入的长度，如果过长将切断(jquery)
function limitLen(obj,len)
{
    var val=obj.val();
    if(val.length>len)
    {
        obj.val(val.substring(0,len));
    }
}

//自动计算Iframe内容的高度，调用方式使用window.setInterval("reinitIframe()", 1000)
function reinitIframe(Idname){
    var iframe = document.getElementById(Idname);
    try{
    var bHeight = iframe.contentWindow.document.body.scrollHeight;
    var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
    var height = Math.max(bHeight, dHeight);
    iframe.height =  height;
    }catch (ex){}
}