//发送HTTP请求
function SendHttp(sAspFile,sSend)
{
  var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.Open("POST",sAspFile,false);
  try
  {
    xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
    xmlhttp.Send(URLEncoding(sSend));
  }
  catch (exception)
  {
    alert(xmlhttp.responseText)
    return "";
  }

  try
  {
    var str11=bytes2BSTR(xmlhttp.responseBody)
  }
  catch (exception)
  {
      str11=""
  }
  return str11
}

//显示系统提示
function hint_show(title,text)
{
  div_hint_title.innerText=title;
  div_hint_text.innerHTML=text;
  document.all("div_hint_main").style.left=event.clientX + 5;
  document.all("div_hint_main").style.top=event.clientY + 5;
  document.all("div_hint_main").style.display="block";
}

//隐藏系统提示
function hint_hide()
{
  document.all("div_hint_main").style.display="none";
}

//打开弹出式窗口
function pop_url(addr,name,size)
{
  window.open(addr,name,"status=no,toolbar=no,width=450,height=250,titlebar=no,menubar=no,scrollbars=no,resizable=" + size);
}

//导出到电子表格
function export_table(tid)
{
  var excel,sheet,table,row,col;
  table = document.all(tid);
  excel = new ActiveXObject("excel.application");

  rows = table.rows.length;
  cols = table.rows(0).cells.length;
  excel.visible=true;
  excel.Workbooks.Add();
  sheet = excel.ActiveSheet;

  for (row=0; row < rows; row++)
  {
    for (col=0; col < cols; col++)
    {
      sheet.cells(row+1,col+1).value = table.rows(row).cells(col).innerText;
    }
  }
}

//检查日期类型
function check_date(theField,theAlert)
{
  theField.value = trim(theField.value);
  var theValue = theField.value;

  var re = /^\d\d\d\d-\d\d-\d\d$/;

  if (theValue != re.exec(theValue))
  {
    alert(theAlert + "输入不准确，请以格式“yyyy-mm-dd”输入日期，如2001-09-05。")
    theField.select();
    return false;
  }

  if (false == is_date(theValue))
  {
    alert(theAlert + "输入不准确，请输入有效的日期。");
    theField.select();
    return false;
  }

  return true;
}

//检查整数类型
function check_int(theField,theAlert)
{
  theField.value = trim(theField.value);
  var theValue = theField.value;
  var theInt = parseInt(theValue);
  if (isNaN(theInt))
  {
    alert(theAlert + "输入不准确，请输入有效的数字。");
    theField.select();
    return false;
  }

  theField.value = theInt;
  return true;
}

//检查文本类型
function check_text(theField,theAlart)
{
  var theValue = theField.value;

  if (0 == theValue.length)
  {
    alert(theAlart + "不能为空。");
    try {theField.select()} catch (exception){}
    return false;
  }

  return true;
}

//检查邮件地址
function check_mail(theForm,theField)
{
  var tField = theForm.elements(theField);
  tField.value = trim(tField.value);
  var theValue = tField.value;

  var re = /^\w+@\w+\.\w+$/;

  if (theValue != re.exec(theValue))
  {
    alert("请输入正确的邮件地址")
    tField.select();
    return false;
  }

  return true;
}

//取表单中的多值以::分隔
function form_get_values(theForm,theField)
{
  var txt = "";
  for (var i=0;i<theForm.elements.length;i++)
  {
    var e = theForm.elements[i];
    if (e.name == theField && e.checked)
    {
      if (txt == "")
        txt = e.value;
      else
        txt = txt + "::" + e.value;
    }
  }

  return txt;
}

//设置文档的初始事件
document.oncontextmenu=fn_menu;
document.onkeydown=fn_key;

//检查表单的右键菜单
function fn_menu()
{
  var theClass = event.srcElement.tagName.toUpperCase();
  if ("INPUT" == theClass || "TEXTAREA" == theClass)
    return true;
  else
    return false;
}

//检查表单的按键操作
function fn_key()
{
  var code = event.keyCode;
  //检查是F5及F11
  if (116 == code || 122 == code || 114 == code || 117 == code)
  {
    event.keyCode = 0;
    return false;
  }

  //检查是否为回退键
  if (8 == code)
  {
    var theClas = event.srcElement.tagName.toUpperCase();
    if ("INPUT" == theClas)
    {
      var theType = event.srcElement.type.toUpperCase();
      if ("TEXT" == theType || "PASSWORD" == theType || "FILE" == theType) return true;
    }

    if ("TEXTAREA" == theClas) return true;
    event.keyCode = 0;
    return false;
  }

  //检查是否为回车键
  if (13 == code)
  {
    var theClas = event.srcElement.tagName.toUpperCase();

    if ("SELECT" == theClas)
    {
      event.keyCode = 9;
      return true;
    }

    if ("INPUT" == theClas)
    {
      var theType = event.srcElement.type.toUpperCase();
      if ("SUBMIT" == theType || "BUTTON" == theType)
      {
      }
      else if ("FILE" == theType)
        return false;
      else
        event.keyCode = 9;
    }
  }
}

//删除字符串首尾的空格
function trim(theValue)
{
  var retn = theValue;
  retn = retn.replace(/^\s*/g,"");
  retn = retn.replace(/\s*$/g,"");
  return retn;
}

//在一个列表框中加入一个项目
function list_add_item(theList,theText,theValue)
{
  var oNew = new Option(theText,theValue);
  theList.options.add(oNew);
}

//编辑列表框中选择中的一个项目
function list_edit_item(oList,theText,theValue)
{
  var cnt,idx;
  cnt = oList.options.length;
  for (idx = cnt - 1; idx >= 0; idx --)
  {
    oItem = oList.options[idx];
    if (oItem.selected)
    {
      oItem.text = theText;
      oItem.value= theValue;
      oItem.selected = true;
      break;
    }
  }
}

//判断列表中是否已经存在一个值
function list_exist_value(oList,theValue)
{
  var idx;

  for (idx = 0; idx < oList.options.length; idx ++)
  {
    var oItem = oList.options[idx];
    if (oItem.value == theValue) return true;
  }

  return false;
}

//取列表框中的所有值，以xxxxx分隔
function list_get_values(oList)
{
  var idx,values = "";

  for (idx = 0; idx < oList.options.length; idx ++)
  {
    var oItem = oList.options[idx];
    if (values == "")
      values += oItem.value;
    else
      values += "xxxxx" + oItem.value;
  }

  return values;
}

//取列表框中的所有值，以指定的字符分隔
function list_get_all_value(oList,sep)
{
  var idx,values = "";

  for (idx = 0; idx < oList.options.length; idx ++)
  {
    var oItem = oList.options[idx];
    if (values == "")
      values += oItem.value;
    else
      values += sep + oItem.value;
  }

  return values;
}

//在一个列表框中加入另一个列表框中的所有的值
function list_add_all_from(oList,oFrom)
{
  var idx,cnt,found;

  for (idx = 0; idx < oFrom.options.length; idx ++)
  {
    var oItem = oFrom.options[idx];
    found = false;
    for (cnt = 0; cnt < oList.options.length; cnt ++)
    {
      if (oItem.text == oList.options[cnt].text &&
          oItem.value== oList.options[cnt].value)
      {
        found = true;
        break;
      }
    }
    if (false == found)
    {
      var oNew = new Option(oItem.text,oItem.value);
      oList.options.add(oNew);
    }
  }
}

//在一个列表框中加入另一个列表框中的选中的值
function list_add_sel_from(oList,oFrom)
{
  var idx,cnt,found;

  for (idx = 0; idx < oFrom.options.length; idx ++)
  {
    var oItem = oFrom.options[idx];
    if (false == oItem.selected) continue;
    found = false;
    for (cnt = 0; cnt < oList.options.length; cnt ++)
    {
      if (oItem.text == oList.options[cnt].text &&
          oItem.value== oList.options[cnt].value)
      {
        found = true;
        break;
      }
    }
    if (false == found)
    {
      var oNew = new Option(oItem.text,oItem.value);
      oList.options.add(oNew);
    }
  }
}

//移动一个列表框中的所有项到另一个列表框
function list_remove_all_to(oList,oTo)
{
  var idx,cnt,found;

  for (idx = 0; idx < oList.options.length; idx ++)
  {
    var oItem = oList.options[idx];
    found = false;
    for (cnt = 0; cnt < oTo.options.length; cnt ++)
    {
      if (oItem.text == oTo.options[cnt].text &&
          oItem.value== oTo.options[cnt].value)
      {
        found = true;
        break;
      }
    }
    if (false == found)
    {
      var oNew = new Option(oItem.text,oItem.value);
      oTo.options.add(oNew);
    }
  }

  oList.options.length=0;
}

//移动一个列表框中选中的项到另一个列表框
function list_remove_sel_to(oList,oTo)
{
  var idx,cnt,found;

  for (idx = 0; idx < oList.options.length; idx ++)
  {
    var oItem = oList.options[idx];
    if (false == oItem.selected) continue;
    found = false;
    for (cnt = 0; cnt < oTo.options.length; cnt ++)
    {
      if (oItem.text == oTo.options[cnt].text &&
          oItem.value== oTo.options[cnt].value)
      {
        found = true;
        break;
      }
    }
    if (false == found)
    {
      var oNew = new Option(oItem.text,oItem.value);
      oTo.options.add(oNew);
    }
  }

  cnt = oList.options.length;
  for (idx = cnt - 1; idx >= 0; idx --)
  {
    oItem = oList.options[idx];
    if (oItem.selected) oList.options[idx] = null;
  }
}

//清除列表框
function list_clear(oList)
{
  oList.options.length = 0;
}

//在列表框中删除选中的项
function list_remove_sel(oList)
{
  var cnt,idx;
  cnt = oList.options.length;
  for (idx = cnt - 1; idx >= 0; idx --)
  {
    oItem = oList.options[idx];
    if (oItem.selected) oList.options[idx] = null;
  }
}

//返回列表框中选中的项目
function list_get_sel_item(oList)
{
  var cnt,idx;
  cnt = oList.options.length;
  for (idx = cnt - 1; idx >= 0; idx --)
  {
    oItem = oList.options[idx];
    if (oItem.selected) return oItem;
  }
}

//在列表框中删除选中的项
function list_del_sel(oList)
{
  list_remove_sel(oList);
}

//列表框中选中的个数
function list_sel_count(oList)
{
  var cnt,idx,count=0;
  cnt = oList.options.length;
  for (idx = cnt - 1; idx >= 0; idx --)
  {
    oItem = oList.options[idx];
    if (oItem.selected) count ++;
  }

  return count;
}

//在列表框中选中所有的项
function list_sel_all(oList)
{
  var idx;
  for (idx = 0; idx < oList.options.length; idx ++)
  {
    oList.options[idx].selected = true;
  }
}

//删除在另一个列表框中存在的项
function list_remove_by(oList,oBy)
{
  var idx,cnt;
  for (idx = 0;idx < oBy.options.length; idx++)
  {
    for (cnt = 0;cnt < oList.options.length; cnt ++)
    {
      var oItem = oList.options[cnt];
      var oItBy = oBy.options[idx];
      if (oItBy.value == oItem.value && oItBy.text == oItem.text) oList.options[cnt] = null;
    }
  }
}

//自动关闭窗口
function close_window()
{
  idclosewin.Click();
}

//最大化窗口
function max_window()
{
  //
}

//字符串或数字比较
function table_sort_comp(theFrom,theTo)
{
  //数字
  if (!isNaN(parseFloat(theFrom)) && !isNaN(parseFloat(theTo)))
  {
    if (parseFloat(theFrom) < parseFloat(theTo))
      return -1;
    else
      return 1;
  }
  else
  {
    //字符串
    if (theFrom < theTo)
      return -1;
    else
      return 1;
  }
}

//表格排序
function table_sort(idname,startrow,col)
{
  var idx,idy,temp;
  var sortby = event.srcElement.sortby;
  if (sortby == "D")
  {
    event.srcElement.sortby = "A";
    event.srcElement.style.cursor="n-resize";
  }
  else
  {
    event.srcElement.sortby = "D";
    event.srcElement.style.cursor="s-resize";
  }

  //保存表格头部定义于headhtml
  temp = document.all(idname).outerHTML.split("<TBODY>");
  headhtml = temp[0];
  for (idx = 0;idx < startrow;idx++)
  {
    headhtml += document.all(idname).rows(idx).outerHTML;
  }
  //alert(headhtml)

  //取出要排序的数据
  var itemtd,itemtr;
  itemtd = new Array();
  itemtr = new Array();
  for (idx = startrow;idx < document.all(idname).rows.length;idx ++)
  {
    itemtr[idx] = document.all(idname).rows(idx).outerHTML;
    itemtd[idx] = document.all(idname).rows(idx).cells(col).innerText;
  }

  //进行排序
  for (idx = startrow;idx < itemtd.length;idx++)
  {
    for (idy = startrow;idy < itemtd.length-1;idy++)
    {
      if (sortby == 'D')
      {
        if (table_sort_comp(itemtd[idy],itemtd[idy+1]) < 0)
        {
          temp = itemtd[idy];
          itemtd[idy] = itemtd[idy+1];
          itemtd[idy+1] = temp;

          temp = itemtr[idy];
          itemtr[idy] = itemtr[idy+1];
          itemtr[idy+1] = temp;
        }
      }
      else
      {
        if (table_sort_comp(itemtd[idy],itemtd[idy+1]) > 0)
        {
          temp = itemtd[idy];
          itemtd[idy] = itemtd[idy+1];
          itemtd[idy+1] = temp;

          temp = itemtr[idy];
          itemtr[idy] = itemtr[idy+1];
          itemtr[idy+1] = temp;
        }
      }
    }
  }

  //重新生成表格
  for (idx = startrow;idx < itemtr.length;idx ++)
  {
    headhtml += itemtr[idx];
  }
  document.all(idname).outerHTML = headhtml + "</table>";
}

////////日历控件
var cal_zindex = 100;
function cal_init()
{
  this.draw();
  var obj_f = eval(this.form + "." + this.ffld);
  var obj_d = eval(this.name + "_div_cal");
  var nTop,nLft;
  nTop = obj_f.offsetTop + obj_f.offsetHeight;
  nLft = obj_f.offsetLeft;

  obj_f = obj_f.parentElement;
  while (obj_f.tagName != "BODY")
  {
    if (obj_f.tagName == "TD" || obj_f.tagName == "TABLE")
    {
      nTop += obj_f.offsetTop;
      nLft += obj_f.offsetLeft;
    }
    obj_f = obj_f.parentElement;
  }

  obj_d.style.posTop  = nTop;
  obj_d.style.posLeft = nLft;
  this.stat = "hide";
}

function cal_show()
{
  var obj = eval(this.name + "_div_cal").style;
  if (this.stat == "show")
  {
    this.stat = "hide";
    obj.visibility = "hidden";
  }
  else
  {
    this.stat = "show";
    cal_zindex ++;
    obj.zIndex = cal_zindex;
    obj.visibility = "visible";
  }
}

function cal_hide()
{
  this.show();
}

function cal_down(evt)
{
  var yy,mm,dd;
  var obj=evt.srcElement;
  yy = this.yy;
  mm = this.mm;
  dd = obj.innerText;
  this.dd = dd;
  if (mm < 10) mm = "0" + mm;
  if (dd < 10) dd = "0" + dd;
  if (parseInt(dd,10) == 0) return;

  var val = yy + "-" + mm + "-" + dd;
  var opt = eval(this.form + "." + this.ffld + ".options[0]");
  opt.value = val;
  opt.text  = val;

  this.hide();
}

//月中的天数
function cal_dinm(iMonth, iYear)
{
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

function cal_make()
{
	var aMonth= new Array();
	aMonth[0] = new Array(7);
	aMonth[1] = new Array(7);
	aMonth[2] = new Array(7);
	aMonth[3] = new Array(7);
	aMonth[4] = new Array(7);
	aMonth[5] = new Array(7);
	aMonth[6] = new Array(7);

	var dCalDate = new Date(this.yy, this.mm-1, 1);
	var iDayOfFirst = dCalDate.getDay();
	var iDaysInMonth = this.dinm(this.mm,this.yy);
	var iVarDate = 1;
	var i, d, w;

	aMonth[0][0] = "星期日";
	aMonth[0][1] = "星期一";
	aMonth[0][2] = "星期二";
	aMonth[0][3] = "星期三";
	aMonth[0][4] = "星期四";
	aMonth[0][5] = "星期五";
	aMonth[0][6] = "星期六";

	for (d = iDayOfFirst; d < 7; d++)
	{
		aMonth[1][d] = iVarDate;
		iVarDate++;
	}

	for (w = 2; w < 7; w++)
	{
		for (d = 0; d < 7; d++)
		{
			if (iVarDate <= iDaysInMonth)
			{
				aMonth[w][d] = iVarDate;
				iVarDate++;
			}
		}
	}
	return aMonth;
}

function cal_draw()
{
	var myMonth = this.make();
  var doc,syy="",smm="",dyy,step=50;
  var amm = new Array("","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");

  for (dyy=parseInt(this.yy,10)-step;dyy<=parseInt(this.yy,10)+step;dyy++)
  {
    if (dyy == this.yy)
      syy += '<option value="' + dyy + '" selected>' + dyy + '</option>';
    else
      syy += '<option value="' + dyy + '">' + dyy + '</option>';
  }

  for (dyy=1;dyy<=12;dyy++)
  {
    if (dyy == this.mm)
      smm += '<option value="' + dyy + '" selected>' + amm[dyy] + '</option>';
    else
      smm += '<option value="' + dyy + '">' + amm[dyy] + '</option>';
  }

	document.writeln("<DIV id='" + this.name + "_div_cal' style='visibility:hidden;position:absolute;left:0;top:100;width:270;height:140;z-index:0'>");
	document.writeln("<iframe name='" + this.name + "_doc_cal' id='" + this.name + "_doc_cal' width='100%' height='100%' frameborder=1 scrolling='no' style='z-index:0'></iframe>");
	document.writeln("</div>");

  doc = eval(this.name + "_doc_cal").document; this.doc = doc;

  doc.writeln("<style>");
  doc.writeln("  body{font-family:宋体;font-size:9pt;text-decoration:none;margin:0px;padding:0px;}");
  doc.writeln("  select{font-family:宋体;font-size:9pt}");
  doc.writeln("</style>");
  doc.writeln("<body oncontextmenu='return false'>");

  //输出日历
	doc.writeln("<table style='font-size:9pt' border='0' cellspacing='0' cellpadding='0' width='100%'>");
	doc.writeln("  <tr>");
	doc.writeln("    <td bgcolor='#D4D0C8' align='center' height='22' width='100%'>");
	doc.writeln("      <form style='margin-bottom:0;margin-top:0'>");
	doc.writeln("        年份：<select onchange='parent." + this.name + ".move_yy(this.value)'>" + syy + "</select> &nbsp;&nbsp;");
	doc.writeln("        月份：<select onchange='parent." + this.name + ".move_mm(this.value)'>" + smm + "</select>");
	doc.writeln("      </form>");
	doc.writeln("    </td>");
	doc.writeln("  </tr>");
	doc.writeln("</table>");
	doc.writeln("<table style='font-size:9pt' border='0' cellspacing='0' cellpadding='0' bgcolor='white' style='border-top: 1 solid #808080' width='100%'>");
	doc.writeln("  <tr>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080;color:red'>" + myMonth[0][0] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080'>" + myMonth[0][1] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080'>" + myMonth[0][2] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080'>" + myMonth[0][3] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080'>" + myMonth[0][4] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080'>" + myMonth[0][5] + "</td>");
	doc.writeln("    <td align='center' nowrap height='17' style='border-bottom: 1 solid #808080;color:red'>" + myMonth[0][6] + "</td>");
	doc.writeln("  </tr>");

	for (w = 1; w < 7; w++)
	{
	  var cal_color;
		doc.write("<tr>");
		for (d = 0; d < 7; d++)
		{
		  cal_color = "";
		  if (d == 0 || d == 6)
		  {
		    cal_color = "style='color:red'";
		  }

			doc.write("<td align='middle' style='cursor:Hand' id=calCell onclick='parent." + this.name + ".down(event)' onmouseover=this.style.background='#a5cbf7' onmouseout=this.style.background=''>");
			doc.write("<table style='font-size:9pt' border='0' cellpadding='0' cellspacing='0' width='20'><tr><td " + cal_color + "><p style='margin-top: 2px' align='center'>");

			if (! isNaN(myMonth[w][d]))
				doc.write("<font id='" + this.name + "_calDateText' style='CURSOR:Hand'>" + myMonth[w][d] + "</font></p></td></tr></table>");
			else
				doc.write("<font id='" + this.name + "_calDateText' style='CURSOR:Hand'>&nbsp;</font></p></td></tr></table>");

			doc.write("</td>");
		}
		doc.write("</tr>");
	}
	doc.write("</table>");
  doc.writeln("</body>");
  doc.close();
}

function cal_move_yy(yy)
{
  this.yy = yy;
  this.updt();
}

function cal_move_mm(mm)
{
  this.mm = mm;
  this.updt();
}

function cal_updt()
{
	var myMonth = this.make();
	for (w = 1; w < 7; w++)
	{
		for (d = 0; d < 7; d++)
		{
			if (!isNaN(myMonth[w][d]))
			{
				eval(this.name + "_doc_cal." + this.name + "_calDateText[((7*w)+d)-7]").innerText = myMonth[w][d];
			}
			else
			{
				eval(this.name + "_doc_cal." + this.name + "_calDateText[((7*w)+d)-7]").innerText = "";
      }
    }
  }
}

function Cal_Date(frm,fld,val,nam)
{
  this.form = frm;
  this.ffld = fld;
  this.fval = val;
  this.name = nam;

  var  dDate = new Date();
  this.dCurDayOfMonth = dDate.getDate();

  this.draw = cal_draw;
  this.down = cal_down;
  this.make = cal_make;
  this.updt = cal_updt;
  this.hide = cal_hide;
  this.show = cal_show;
  this.init = cal_init;
  this.dinm = cal_dinm;
  this.move_yy = cal_move_yy;
  this.move_mm = cal_move_mm;

  var  tm = val.split("-");
  this.yy = tm[0];
  this.mm = parseInt(tm[1],10);
  this.dd = parseInt(tm[2],10);
}

//Word 报表
function word_report(wordfile,formname,tableid)
{
  var idx;
  var fld = "fieldlist checkbox hidden password radio text textarea select-one select-multiple";

  //启动Word字处理软件
  var oWord,oDoc;
  try
  {
    oWord = new ActiveXObject("Word.application");
    oWord.visible=true;
    oDoc = oWord.documents.open(wordfile,false,true,false);
    oWord.WindowState = 1;
    oWord.Activate();
    oWord.ActiveWindow.View.ShowBookmarks = false;
  }
  catch(e)
  {
    alert(e.description);
    return;
  }

  //打印模模板内容
  for (idx=0;idx<formname.elements.length;idx++)
  {
    var oItem = formname.elements(idx);
    if (fld.indexOf(oItem.type) != -1)
    {
      try
      {
        if (oItem.type == "select-one")
        {
          var text = oItem.options[oItem.selectedIndex].text
          oDoc.bookmarks.item(oItem.name).range.text = trim(text);
        }
        else if (oItem.type == "select-multiple")
        {
          var text = "",ndx=0;
          for (ndx=0;ndx < oItem.options.length;ndx++)
          {
            var oObj = oItem.options[ndx];
            if (text != "") text += "\n";
            text += trim(oObj.text);
          }
          oDoc.bookmarks.item(oItem.name).range.text = text;
        }
        else
        {
          if (oItem.value != "　") oDoc.bookmarks.item(oItem.name).range.text = trim(oItem.value);
        }
      }
      catch(e)
      {
      }
    }
  }

  //打印表格
  if ("undefined" != typeof(tableid))
  {
    try
    {
      var rows = tableid.rows.length;
      var cols = tableid.rows(0).cells.length;
      var row,col,oTab,oRng;

      oWord.Selection.EndKey(6);
      oRng = oWord.Selection.Range;
      oTab = oDoc.Tables.Add(oRng, rows, cols)

      for (row=0; row < rows; row++)
      {
        for (col=0; col < cols; col++)
        {
          oTab.Rows.Item(row+1).Cells.Item(col+1).Range.InsertAfter(tableid.rows(row).cells(col).innerText);
        }
      }
    }
    catch(e)
    {
      alert(e.description);
    }
  }

  //打印预览
  try
  {
    oDoc.protect(2,false,"xxwwordreport");
    oDoc.saveas("c:\\报表.doc");
  }
  catch(e)
  {
  }
  oWord.ShowMe();
  oDoc.PrintPreview();
  oWord.ActiveWindow.ActivePane.View.Zoom.Percentage = 75;
  oWord.Activate();
}
