var context = "/sttc"

//打开一个最大化的窗口
function openNewWindow( url,name ,width, height ){
	var newwin = window.open( url, name, "toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,left=0,top=0,width=" + width + ",height=" + height +"" );
	newwin.focus();
	return false;
}

//查看公文详细
function viewArchive($archiveId,$viewType,$typeId) {
	if($archiveId == null || $archiveId == "" || $archiveId <= 0) {
		alert("该流程ID不正确,请重新打开!");
		return;
	}
	URL = context + "/oa/archive/common/archiveManage.do?mhd=toViewArchive&archiveId="+$archiveId+"&viewType="+$viewType+"&typeId="+$typeId;
	openNewWindow(URL,"公文",screen.width,screen.height); 
}

//新增公文
function toNewArchive($sourcePath,$urgeArchiveId) {  
	URL = context + "/mlao/oa/archive/send/temp.jsp?sourcePath="+$sourcePath+"&urgeArchiveId="+$urgeArchiveId+"&coerceEndId=&sequentialId=";
    openNewWindow(URL,"新增公文",screen.width,screen.height);
}

//新增公文
//用于公文督办和公文强制办结 新增
function toNewArchive2($sourcePath,$templateName) {
	var count = 0;
	var length = 0;
	var id = 0;
	var archiveType = "";
	if($templateName.indexOf('强制办结流程')>-1) {
		archiveType = "强制办结";
	}

	try{
		 length = document.forms[0].fid.length;
	} catch(e){
		alert("没有任何记录！");
		return false;
	}
	if (isNaN(length))	{
		try{
			if (document.forms[0].fid.checked)	{
				++count;
				id = document.forms[0].fid.value;
			}
		}catch(e){}
	}
	for(var i=0;i<document.forms[0].fid.length;i++){
		if(document.forms[0].fid[i].checked) {
			id = document.forms[0].fid[i].value;
			count++;
		}
	}
	if(count==0){
		alert("您没有选择任何记录！");
		return false;
	}
	if(count>1) {
		alert("您选择了多条记录，只能选择一条记录处理！");
		return false;
	}
	URL = context + "/mlao/oa/archive/common/archiveForward.jsp?mhd=toNewArchive&sourcePath="+
		$sourcePath+"&urgeArchiveId="+id+"&coerceEndId="+id+"&sequentialId="+id+"&templateName="+$templateName+"&archiveType="+archiveType;
    openNewWindow(URL,"新增公文",screen.width,screen.height);
}

//查看流程日志
function viewFlowLog($archiveId,$templateName){ 
	URL = context + "/mlao/oa/urgermanager/gwDB_toList.do?mhd=toViewFlowWorkItem&archiveID="+$archiveId+"&templateName="+$templateName;
    openNewWindow(URL,"流程查看",screen.width,screen.height);    
}

//办理公文
function doArchive($archiveId,$templateName,$sourcePath) {
	if($sourcePath != "undefined" && $sourcePath != null && $sourcePath != "")
		URL = context + "/mlao/oa/archive/wait/temp.jsp?mhd=toTransactArchive&sourcePath="+$sourcePath+"&archiveId="+$archiveId+"&templateName="+$templateName;
	else
		URL = context + "/mlao/oa/archive/wait/temp.jsp?mhd=toTransactArchive&sourcePath=waitArchive&archiveId="+$archiveId+"&templateName="+$templateName;
	openNewWindow(URL,"公文",screen.width,screen.height);
}

//办结公文(不需要通过审批流程)
function pauseArchive($archiveId,$templateName,$sourcePath) {
	if(confirm("您确定要强制办结该公文吗？") == false){
		return false;
	}	
	if($sourcePath != "undefined" && $sourcePath != null && $sourcePath != "")
		URL = context + "/mlao/oa/archive/wait/temp.jsp?mhd=pauseArchive&sourcePath="+$sourcePath+"&archiveId="+$archiveId+"&templateName="+$templateName;
	else
		URL = context + "/mlao/oa/archive/wait/temp.jsp?mhd=pauseArchive&sourcePath=waitArchive&archiveId="+$archiveId+"&templateName="+$templateName;

	window.location.href = URL;
}

//回收公文
function doCancelArchive(path,templateName,sourcePath){
  	var count = 0;
	var length = 0;
	try{
		 length = document.forms[0].fid.length;
	} catch(e){
		alert("没有任何记录！");
		return false;
	}
	if (isNaN(length))	{
		try{
			if (document.forms[0].fid.checked)	{
				++count;
			}
		}catch(e){}
	}
	for(var i=0;i<document.forms[0].fid.length;i++){
		if(document.forms[0].fid[i].checked)
			count++;
	}
	if(count==0){
		alert("您没有选择任何记录！");
		return false;
	}
	if(count>1) {
		alert("您选择了多条记录，只能选择一条记录处理！");
		return false;
	}
	if(confirm("您确定要重做吗？") == false){
		return false;
	}
	document.forms[0].action = path+"?templateName="+templateName+"&sourcePath="+sourcePath;
  	document.forms[0].mhd.value = "doCancelArchive";	
  	document.forms[0].submit();
 }

//根据ARCHIVEID回收公文
function doCancelArchive2(archiveId,sourcePath){
	document.forms[0].action = "/mlao/oa/archive/common/ArchiveCommon.do?archiveId="+archiveId+"&sourcePath="+sourcePath;
  	document.forms[0].mhd.value = "doCancelArchive";	
  	document.forms[0].submit();
}



