﻿//ItemDetail 页面的相关客户端脚本
var strLocal;

//是否第一次进入窗体

IsFirstTime	= 0;

function CheckActiviXDownLoad()
{	
	//窗口最大化 
	var x = window.screen.availWidth;
	var y = window.screen.height-30;
	try
	{
		window.move(0,0);	
	}
	catch(e){}
	window.resizeTo(x,y);
	
	//判断控件是否下载	
	var message = "您没有下载相关控件,\n因此您可能在该页面无法打开Word文档并对它进行操作,\n请重新打开该页面,并在弹出的对话框中选择'是'";		
	
	try
	{
		ShowTips(1);
	}
	catch(e)
	{
	//	alert(e);
	}	
}
//显示当前步骤的帮助信息

function ShowTips(t)
{
	//取得当前步骤别名
	var activityDom		= document.all["currentActivity"];
	var StepName = getNodeText(activityDom,"//Alias");		
	if(StepName=="") return;
	var cookieName=StepName+"_"+workflowID;
	//读取Cookie如果时第一次使用该步骤的话，就弹出帮助窗口
	if(GetCookie(cookieName)==null || t==-1)
	{	
		//弹出非模式窗口
		var url="/BMSSFlowWeb/Help/"+workflowID+"/"+StepName+".htm";	
		
		url=encodeURI(url);
		showModelessDialog(url,window,"status:off;dialogWidth:580px;dialogHeight:400px;resizable:yes ");
		//写Cookie
		SetCookie(cookieName,"1");				
	}	
}
//设置Cookie
function SetCookie(sName, sValue)
{
  date = new Date(3005,5,20); //不设置过期期限 
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
//取得Cookie
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function OnShow(id,imgid ,virtual)
{
    var path = '' ;	
	if(id.style.display!="none")
	{					
		id.style.display="none";
		if(virtual != '')	
		    path=  virtual+"/App_Themes/Default/workflow/idt_tle_close.gif";
		else
		    path= "/App_Themes/Default/workflow/idt_tle_close.gif";
	}
	else
	{				
		id.style.display="";
		if(virtual!= '')
		    path= virtual+"/App_Themes/Default/workflow/idt_tle_open.gif";
		else
		    path= "/App_Themes/Default/workflow/idt_tle_open.gif";
		
	} 
	imgid.src = path ;
}

function Show(id)
{
	
	if(id.style.display!="none")				
		id.style.display="none";	
	else			
		id.style.display="";
}

function ShowAttach()
{
	if(actionType==0) 
	{	
		alert("表单尚未保存,请先保存表单！");
		return;
	}

	var sFeatures="dialogHeight: 420px; dialogWidth: 400px; dialogTop: px; dialogLeft: px; edge:Raised; center: Yes; help: Yes; resizable: Yes; status: no;";					    				
	var url='UploadFile.aspx?keys=' + caseID;								
	var result=showModalDialog(url,'1',sFeatures);				
	if(result!=false)
			window.location.reload();
}

function PassDoc(DocID,taskID)
{

	var sFeatures="	dialogHeight: 580px; dialogWidth: 630px; dialogTop: px; dialogLeft: px; edge:Raised; center: Yes; help: Yes; resizable: Yes; status: no";					    				
	var keys=DocID+','+taskID;
	var url='PassDoc.aspx?keys='+keys;								
	window.showModalDialog(url,'1',sFeatures);	
}

function ShowPublish(DocID,DocType,AppCode)
{
	var sFeatures="dialogHeight: 440px; dialogWidth: 430px; dialogTop: px; dialogLeft: px; edge:Raised; center: Yes; help: Yes; status: no;resizable: Yes";
	var keys=DocID+','+DocType + ',' + AppCode;
	//var url='Module.aspx?sUrl=Publish.aspx&keys='+keys;
	var url = 'Publish.aspx?keys=' + keys;
	window.open(url);
	//window.showModalDialog(url,'1',sFeatures);
}

function CloseMe(action)
{
   if(document.all("Toolbar_ImgSave")!=null && (action!=-1&&action!=0)){
	    if(confirm("你现在需要保存业务数据吗？"))
	    {			
		    document.all("Toolbar_ImgSave").click();
	    }
	}
	window.close();
}

function UpdateFormByTable(objs,objDocument)
{
	
	if(Security=="ReadOnly") return;
	if(objDocument==null) 
	{
		alert('请先打开正文再进行填充！');
		return;
		//ViewDoc(null);	
		//objDocument=document.all("dsoFrame").ActiveDocument;	
	}
	
	for(i=0;i<objs.length;i++)
	{	
		try
		{
			var Position=objs[i].Position;
			var val;		
			var TID=parseInt(Position.split(',')[0]);			
			if(TID==-1) TID=objDocument.Tables.Count;  //最后一个表格		
			var RID=parseInt(Position.split(',')[1]);
			var CID=parseInt(Position.split(',')[2]);

			oTable=objDocument.Tables(TID);
		
		//	if((objs[i].id.indexOf("tbTo")>-1||objs[i].id.indexOf("tbCc")>-1 )&& objs[i].id.indexOf("tbTopic")<0)		
		//		val=objs[i].innerText+"："+objs[i].value;		
		//	else 
			if(objs[i].id.indexOf("PrintTime")>-1)
			{
				val=objs[i].value;
				var DatePart=val.split("-");
				val=DatePart[0]+"年"+DatePart[1]+"月"+DatePart[2]+"日 印发";
			}
			else if(objs[i].id.indexOf("ddlHeader")>-1)
			{
				//填充红头
				var sFontInfo	= objs[i].value.split("|");
				//var sFontName	= sFontInfo[0];
				var sFontSize	= sFontInfo[1];
				//var sFontDis	= sFontInfo[2];
				var index		= sFontInfo[3];
				val=objs[i].options[index-1].text;
				var oFont=oTable.Rows(RID).Cells(CID).Range.Font;
				//if(sFontName!="")	oFont.Name=sFontName;
				if(sFontSize!="")	oFont.Size=parseInt(sFontSize);
				//if(sFontDis !="")	oFont.Spacing=parseFloat(sFontDis);
			}
			else if(objs[i].id.indexOf("divSendTo")>-1)
			{
				if(objs[i].innerHTML.indexOf("双击选择主送组")==-1)
					val=objs[i].innerText+"："
				else
					val = "";
			}
			else if(objs[i].id.indexOf("divSendCc")>-1)
			{
				if(objs[i].innerHTML.indexOf("双击选择抄送组")==-1)
					val=objs[i].innerText;
				else
					val = "";
			}
			else
			{
				val = objs[i].value
			}
				
			oTable.Rows(RID).Cells(CID).Range.Text=val;
			
		}
		catch(e)
		{
		//	alert(e+TID+RID+CID);
		}
		
	}
}

//打印
//Show 1：弹出对话框选择表单和流程，适用于有正文的业务表单；
//	   0：直接打印表单；
//     2：打印正文；
function PrintMe(Show)
{
	if(Show==1)
	{
		var url="/InfoWeb/Modules/WebForm/PrintSelect.htm";
		var sFeatures = "dialogHeight: 135px; dialogWidth: 300px; dialogTop: px; dialogLeft: px; edge:Raised; center: Yes; help: Yes; resizable: Yes; scroll:no; status: no;";		
		var reValue=showModalDialog(url,window,sFeatures);
	}else 
	    if(Show==2)
	        reValue="2";
	    else 
		    reValue="1";
	
	if(reValue!=null)
	{
		//打印表单
		if(reValue=="1")
		{
			var cookieName="PrintTips";
			//读取Cookie如果时第一次使用该步骤的话，就弹出帮助窗口
			if(GetCookie(cookieName)==null)
			{	
				//弹出非模式窗口
				var url="/InfoWeb/Modules/WebForm/PrintAlert.htm";				
				showModelessDialog(url,window,"status:off;dialogWidth:340px;dialogHeight:180px;resizable:yes ");	
			}	
			window.print();
		}else 
		{
			//打印正文
			if(DocType==0)
			{
				if(IsFirstTime==0) ViewDoc(null);
				try
				{
					var doc=document.all("dsoFrame");		
					doc.PrintOut(true);
				}
				catch(e)
				{
					alert("打印文档错误!"+e.message);
				}
			}
			else if(DocType==2)
			{
				var isOK = true;
				var ErrMessage = "";
				if(IsFirstTime==0) ViewDoc(null);
				try
				{
					//TODO:Question?
					var obj = document.all("tifFrame").Document;
					
					var printer = document.all["PrinterSelection"];
					printer.MinPage = 1;
					printer.MaxPage = -1;
					printer.Copies = 1;
					if( printer.ShowPrinters() )
                      {
						var from = printer.FromPage - 1;
						var to;
						if(printer.ToPage ==-1)
							to = printer.ToPage;
						else
							to = printer.ToPage - 1;
						copies = printer.Copies;
						//var WsNetWork = new ActiveXObject("WScript.Network");
						//WsNetWork.AddWindowsPrinterConnection(printer.PrinterName);
						//alert(printer.PrinterName);
						obj.PrintOut(from,to,copies,printer.PrinterName);
                      }
				}
				catch(e)
				{
					isOK = false;
					ErrMessage = "打印Tif文档失败!请检查是否出现以下问题：*确定打印机已打开！*重新安装打印机驱动程序！";
					
				}
				if(!isOK)
				{
					alert(ErrMessage);
				}
			}
			else
				alert("只支持Word和Tif的文档的打印，PDF文档请点击正文工具条的打印按钮！");
		}
	}else return;
}

//上传附件表单和正文数据处理
//hasDoc: 1:包含正文，0:不包含正文
function ShowAttach_itemdetail(hasDoc)
{
	if(actionType==0) 
	{	
		alert("你还没保存表单，请先保存，再进行附件操作！");
		return;
	}
	
	if(confirm('上传附件会刷新页面，这会导致还没有保存的表单和正文数据丢失，是否保存表单和正文数据后再上传附件？'))
	{
		if(hasDoc==1)
			Save("<%=GetFileUrl(caseID)%>");
		__doPostBack('<%=lb_saveclientid%>','');
	}
	var sFeatures="dialogHeight: 420px; dialogWidth: 400px; dialogTop: px; dialogLeft: px; edge:Raised; center: Yes; help: Yes; resizable: Yes; status: no;";					    				
	var url='Module.aspx?sUrl=UploadFile.aspx&keys=' + caseID;								
	var result=showModalDialog(url,'1',sFeatures);		
	if(result!=false)
	{
		window.location.reload();
	}
}

function addfollowmark(name, x, y) 
{
  i = objs.length;
  objs[i] = document.getElementById(name);
  objs_x[i] = x;
  objs_y[i] = y;
 
}

function followmark()
{
  for(var i=0; i<objs.length; i++) 
  {
    var fm = objs[i];
    var fm_x = typeof(objs_x[i]) == 'string' ? eval(objs_x[i]) : objs_x[i];
    var fm_y = typeof(objs_y[i]) == 'string' ? eval(objs_y[i]) : objs_y[i];

    if (fm.offsetLeft != document.body.scrollLeft + fm_x) 
    {
      var dx = (document.body.scrollLeft + fm_x - fm.offsetLeft) * step_ratio;
      dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
      fm.style.left = fm.offsetLeft + dx;
    }

    if (fm.offsetTop != document.body.scrollTop + fm_y) {
      var dy = (document.body.scrollTop + fm_y - fm.offsetTop) * step_ratio;
      dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
      fm.style.top = fm.offsetTop + dy;
    }
    fm.style.display = '';
  }
}

function Calculate(c_control,total)
{
	var result = 1;
	for(i=0 ; i < c_control.length;i++)
	{
		values = document.all[c_control[i]].value;
		if(values.length>0)
		{
			if(isNaN(values))
				values = 0;
		}
		else
			values = 0;
			
		result = result * values * 1;
	}
	document.all[total].value = result.toFixed(2);
}

function CalculateTotalPrice(UnitPriceIDs,TotalCharge)
{
	totalprice = 0;
	if(document.all[UnitPriceIDs].value.length >0)
	{
		var control = document.all[UnitPriceIDs].value.split(",");
	}
	for(j=0;j<control.length;j++)
	{
		c_value = document.all[control[j]].value;
		if(c_value.length>0)
		{
			if(isNaN(c_value))
				c_value = 0;
		}
		else
			c_value = 0;
			
		totalprice = totalprice + parseFloat(c_value);
	}
	document.all[TotalCharge].value = totalprice.toFixed(2);;
}

//身份证验证
 function isIdCardNo(num)   
 {   
    num   =   num.toUpperCase();   
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。   
    if   (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num)))   
    {   
       // alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');   
        return   false;   
    }   
    //校验位按照ISO   7064:1983.MOD   11-2的规定生成，X可以认为是数字10。   
    //下面分别分析出生日期和校验位   
    var   len,   re;   
    len   =   num.length;   
    if   (len   ==   15)   
    {   
        re   =   new   RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);   
        var   arrSplit   =   num.match(re);   
    
    //检查生日日期是否正确   
    var   dtmBirth   =   new   Date('19'   +   arrSplit[2]   +   '/'   +   arrSplit[3]   +   '/'   +   arrSplit[4]);   
    var   bGoodDay;   
    bGoodDay   =   (dtmBirth.getYear()   ==   Number(arrSplit[2]))   &&   ((dtmBirth.getMonth()   +   1)   ==   Number(arrSplit[3]))   &&   (dtmBirth.getDate()   ==   Number(arrSplit[4]));   
    if   (!bGoodDay)   
    {   
       // alert('输入的身份证号里出生日期不对！');   
        return   false;   
    }   
    else   
    {   
    //将15位身份证转成18位   
    //校验位按照ISO   7064:1983.MOD   11-2的规定生成，X可以认为是数字10。   
    var   arrInt   =   new   Array(7,   9,   10,   5,   8,   4,   2,   1,   6,   3,   7,   9,   10,   5,   8,   4,   2);   
    var   arrCh   =   new   Array('1',   '0',   'X',   '9',   '8',   '7',   '6',   '5',   '4',   '3',   '2');   
    var   nTemp   =   0,   i;   
    num   =   num.substr(0,   6)   +   '19'   +   num.substr(6,   num.length   -   6);   
    for(i   =   0;   i   <   17;   i   ++)   
    {   
        nTemp   +=   num.substr(i,   1)   *   arrInt[i];   
    }   
    num   +=   arrCh[nTemp   %   11];   
    return   num;   
  }   
  }   
  if   (len   ==   18)   
  {   
      re   =   new   RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);   
      var   arrSplit   =   num.match(re);   
        
      //检查生日日期是否正确   
      var   dtmBirth   =   new   Date(arrSplit[2]   +   "/"   +   arrSplit[3]   +   "/"   +   arrSplit[4]);   
      var   bGoodDay;   
      bGoodDay   =   (dtmBirth.getFullYear()   ==   Number(arrSplit[2]))   &&   ((dtmBirth.getMonth()   +   1)   ==   Number(arrSplit[3]))   &&   (dtmBirth.getDate()   ==   Number(arrSplit[4]));   
      if   (!bGoodDay)   
      {   
         // alert('输入的身份证号里出生日期不对！');   
          return   false;   
      }   
      else   
      {   
          //检验18位身份证的校验码是否正确。   
          //校验位按照ISO   7064:1983.MOD   11-2的规定生成，X可以认为是数字10。   
          var   valnum;   
          var   arrInt   =   new   Array(7,   9,   10,   5,   8,   4,   2,   1,   6,   3,   7,   9,   10,   5,   8,   4,   2);   
          var   arrCh   =   new   Array('1',   '0',   'X',   '9',   '8',   '7',   '6',   '5',   '4',   '3',   '2');   
          var   nTemp   =   0,   i;   
          for(i   =   0;   i   <   17;   i   ++)   
          {   
            nTemp   +=   num.substr(i,   1)   *   arrInt[i];   
          }   
          valnum   =   arrCh[nTemp   %   11];   
          if   (valnum   !=   num.substr(17,   1))   
          {   
             // alert('18位身份证的校验码不正确！应该为：'   +   valnum);   
              return   false;   
          }   
          return   num;   
      }   
  }   
  return   false;   
}  