
var dragapproved = false;var eventsource,x,y;var popeventsource = "";var temp1 = 0;var temp2 = 0;function nocontextmenu(){event.cancelBubble = true
event.returnValue = false;return false;}function nodrags(){dragapproved = false;}function move(){if (event.button ==1 && dragapproved){var newleft = temp1 + event.clientX - x;var newtop = temp2 + event.clientY - y;eventsource.style.pixelLeft = newleft;eventsource.style.pixelTop = newtop;movelines();return false;}}function drags(){if (event.button != 1)
return;var objRect = event.srcElement;if (event.srcElement.tagName.toLowerCase() == 'textbox') objRect = event.srcElement.parentElement;if ((objRect.tagName == 'roundrect'||objRect.tagName=='polyline'||objRect.tagName=='oval') && (!event.ctrlKey)){dragapproved = true;eventsource = objRect;temp1 = eventsource.style.pixelLeft;temp2 = eventsource.style.pixelTop;x = event.clientX;y = event.clientY;document.onmousemove = move;rect_selected(objRect,"red");}}function rect_selected(objRect,color){clear_selColor("roundrect");clear_selColor("line");clear_selColor("polyline");clear_selColor("oval");if(objRect)objRect.fillcolor=color;}function line_selected(objLine){clear_selColor("roundrect");clear_selColor("line");clear_selColor("polyline");if(objLine)objLine.strokeColor="red";}function clear_selColor(tag){if(tag=="roundrect"){var rects=document.getElementsByTagName(tag);for(var i=0;i<rects.length;i++){rects[i].fillColor="#EEEEEE";	}}else if(tag=="line"){var lines=document.getElementsByTagName(tag);for(var i=0;i<lines.length;i++){lines[i].strokeColor="black";	}}if(tag=="polyline"){var pollys=document.getElementsByTagName(tag);for(var i=0;i<pollys.length;i++){pollys[i].fillColor="#EEEEEE";}}if(tag=="oval"){var ovals=document.getElementsByTagName(tag);for(var i=0;i<ovals.length;i++){ovals[i].fillColor="#EEEEEE";}}}function movelines(){var source;var object;var sourceObj;var objectObj;var x0,y0,x1,y1;var p0,p1;var a = document.getElementsByTagName('line');for (var i = 0; i < a.length; i++){source = a[i].getAttribute('source');object = a[i].getAttribute('object');if ((source != null) && (object != null)){sourceObj = document.getElementById(source);objectObj = document.getElementById(object);if ((sourceObj == null) || (objectObj == null)) continue;if (sourceObj.style.pixelLeft > objectObj.style.pixelLeft){if ((sourceObj.style.pixelLeft - objectObj.style.pixelLeft) <= objectObj.style.pixelWidth){x0 = sourceObj.style.pixelLeft + sourceObj.style.pixelWidth / 2;x1 = objectObj.style.pixelLeft + objectObj.style.pixelWidth / 2;if (sourceObj.style.pixelTop >  objectObj.style.pixelTop){y0 = sourceObj.style.pixelTop;y1 = objectObj.style.pixelTop  + objectObj.style.pixelHeight;}else{y0 = sourceObj.style.pixelTop + sourceObj.style.pixelHeight;y1 = objectObj.style.pixelTop;}}else{x0 = sourceObj.style.pixelLeft;x1 = objectObj.style.pixelLeft + objectObj.style.pixelWidth;y0 = sourceObj.style.pixelTop + sourceObj.style.pixelHeight / 2;y1 = objectObj.style.pixelTop + objectObj.style.pixelHeight / 2;}}else{if ((objectObj.style.pixelLeft - sourceObj.style.pixelLeft) <= objectObj.style.pixelWidth){x0 = sourceObj.style.pixelLeft + sourceObj.style.pixelWidth / 2;x1 = objectObj.style.pixelLeft + objectObj.style.pixelWidth / 2;if (sourceObj.style.pixelTop >  objectObj.style.pixelTop){y0 = sourceObj.style.pixelTop;y1 = objectObj.style.pixelTop  + objectObj.style.pixelHeight;}else{y0 = sourceObj.style.pixelTop + sourceObj.style.pixelHeight;y1 = objectObj.style.pixelTop;}}else{x0 = sourceObj.style.pixelLeft + sourceObj.style.pixelWidth;x1 = objectObj.style.pixelLeft;y0 = sourceObj.style.pixelTop + sourceObj.style.pixelHeight / 2;y1 = objectObj.style.pixelTop + objectObj.style.pixelHeight / 2;}}a[i].from = String(x0) + ',' + String(y0);a[i].to = String(x1) + ',' + String(y1);a[i].style.pixelLeft = x0 + 'px';a[i].style.pixelTop = y0 + 'px';strIF = a[i].getAttribute('title');if ((strIF != null) && (strIF != '')){var id = 'if_' + source + '_' + object;var obj = document.getElementById(id);var left = (x0 + (x1 - x0) / 2 - 30);var top = (y0 + (y1 - y0) / 2 - 15);if (obj != null){obj.style.pixelLeft = left + 'px';obj.style.pixelTop = top + 'px';obj.style.left = left + 'px';obj.style.top = top + 'px';obj.style.display = '';}}a[i].style.display = '';}}}function document.onreadystatechange(){if (document.readyState=='complete'){movelines();document.onmousedown = drags;document.onmouseup = nodrags;  }}function set_wenzi(){var obj=null
var rects=document.getElementsByTagName("roundrect");for(var i=0;i<rects.length;i++){if(rects[i].fillColor=="red"){obj=rects[i]
open_dialog('select_tb.htm',600,256,0);break;}}if(obj==null){var polys=document.getElementsByTagName("polyline");for(var i=0;i<polys.length;i++){if(polys[i].fillColor=="red"){obj=polys[i]
var fromobj=get_fromobj_rect(obj)
var fileName=fromobj.getElementsByTagName("textbox")[0].getAttribute('data-fileName')
var tb_setName=fromobj.getElementsByTagName("textbox")[0].getAttribute('data-tbsetName')
if(fileName==""&&tbsetName==""){alert("请先设置上一步骤的表名")}else{show_resource_cols(fileName,tb_setName)}break;}}}if(obj==null){alert("请选择流程框")}}function get_fromobj_rect(toobj){var lines=document.getElementsByTagName("line");for(var j=0;j<lines.length;j++){if(lines[j].id.split("_")[2]==toobj.id){var fromobj=document.getElementById(lines[j].id.split("_")[1])
break;}}if (fromobj.tagName!="roundrect"){return get_fromobj_rect(fromobj)}return 	fromobj}function show_resource_cols(fileName,tb_setName){var url="../"+asp_php+"/set_input_type."+asp_php+"?exe=get_all_cols&tb_setName="+tb_setName+"&fileName="+fileName;gid('frame_blank').src=url;}function show_all_cols(s,n){if(s==""){return}var arr=s.split('|/tr|'),arr1;if(n==''){var obj=document.getElementById('all_cols');}else{var obj=document.getElementById(n);}var ss="";for (var i=0;i<arr.length;i++){if(arr[i].indexOf('|/td|')>-1){arr1=arr[i].split('|/td|');var cnName=arr1[1];var col_id=arr1[0];ss+="<div style='margin:10px;'>"+cnName+"<a onclick=set_poly_ok('"+cnName+"','"+col_id+"') href='#ytd'>选择</a></div>"}}obj.innerHTML=ss
obj.style.display=""}function set_poly_ok(cnName,col_id){var polys=document.getElementsByTagName("polyline");for(var i=0;i<polys.length;i++){if(polys[i].fillColor=="red"){var obj=polys[i].getElementsByTagName("textbox")[0];obj.innerHTML=cnName
obj.setAttribute('data-cnName',cnName)
obj.setAttribute('data-colid',col_id)
break;}}document.getElementById('all_cols').style.display="none"}function get_mokuai_tbName(cnName,tb_setName,fileName){var rects=document.getElementsByTagName("roundrect");for(var i=0;i<rects.length;i++){if(rects[i].fillColor=="red"){var obj=rects[i].getElementsByTagName("textbox")[0];obj.innerHTML=cnName
obj.setAttribute('data-fileName',fileName)
obj.setAttribute('data-tbsetName',tb_setName)
break;}}}function createNode(left,top,tag){var alt=document.getElementById("alt");if(alt)alt.removeNode(true);var tags=document.getElementsByTagName(tag);var new_id;if(tags.length==0){id=1;}else{var id=tags[tags.length-1].id
id=id.substring(1)
id=parseInt(id)+1;}var flag=null
var s="";var color="red";if (tag=="roundrect"){flag="r";new_id=flag+id
s="<vml:roundrect inset='2pt,2pt,2pt,2pt' id='"+new_id+"' flowtype='' passcount='0'";s+="flowtitle='<br>"+new_id+"' flowflag='0' readonly='0' receiverid='' receivername=''";s+="fillcolor='#EEEEEE' ondblclick='change_text(this)' style='left: "+left+"; top: "+top+"; width: 100; position: absolute;";s+="height: 50; vertical-align: middle; cursor: hand; text-align: center; z-index: 1'";s+="arcsize='4321f' coordsize='21600,21600' title='流程"+id+",下一步骤:'>";s+="<vml:shadow on='T' type='single' color='#b3b3b3' offset='3px,3px' /><br>";s+="<vml:textbox inset='1pt,2pt,1pt,1pt' data-fileName='' data-tbsetName=''  onselectstart='return false;'>流程"+new_id+"</vml:textbox>";s+="</vml:roundrect>";	}else if(tag=="polyline"){flag="p";new_id=flag+id
s="<vml:polyline  id='"+new_id+"'  Points='0,30,70,55,140,30,70,5,0,30' flowtype='' passcount='0'";s+="flowtitle='<br>"+new_id+"' flowflag='0' readonly='0' receiverid='' receivername=''";s+="fillcolor='#EEEEEE' ondblclick='change_text(this)' style='left: "+left+"; top: "+top+"; width:140; position: absolute;";s+="height:50; vertical-align: middle; cursor: hand; text-align: center; z-index: 1'";s+="arcsize='4321f' coordsize='21600,21600' title='条件"+id+",流向:'>";s+="<vml:shadow on='T' type='single' color='#b3b3b3' offset='3px,3px' /><br>";s+="<vml:textbox inset='1pt,2pt,1pt,1pt' data-cnName='' data-colid='' style='vertical-align: middle; word-break: break-all;' onselectstart='return false;'>条件"+new_id+"</vml:textbox>";s+="</vml:polyline>";	}else if(tag=="oval"){flag="o";new_id=flag+id
s="<vml:oval  id='"+new_id+"' passcount='0'";s+="flowtitle='<br>"+new_id+"' flowflag='0' readonly='0' receiverid='' receivername=''";s+="fillcolor='#EEEEEE' ondblclick='change_text(this)' style='left: "+left+"; top: "+top+"; width:10; position: absolute;";s+="height:10; vertical-align: middle; cursor: hand; text-align: center; z-index: 1'";s+="arcsize='4321f' coordsize='21600,21600'>";s+="<vml:shadow on='T' type='single' color='#b3b3b3' offset='3px,3px' /><br>";s+="</vml:oval>";}else{return;	}document.getElementById("liucheng").insertAdjacentHTML("beforeEnd",s);rect_selected(document.getElementById(new_id),color)}function delNode(){var selObj=null;var ovals=document.getElementsByTagName("oval");for(var i=0;i<ovals.length;i++){if(ovals[i].fillcolor=="red"){selObj=ovals[i];}}if(selObj){var lines=document.getElementsByTagName("line");var id_sub,j,arr=new Array(),k=0;for(j=0;j<lines.length;j++){id_sub=lines[j].id.split("_");if(id_sub[1]==selObj.id||id_sub[2]==selObj.id){arr[k]=lines[j].id;k++;}}for(var n=0;n<arr.length;n++){delete_line(arr[n])	}selObj.removeNode(true);}}function change_text(rect){var obj=rect.getElementsByTagName("textbox")[0];if(obj.innerHTML.indexOf("<INPUT")==-1){obj.innerHTML="<input value='"+obj.innerText+"' style='width:90px' onkeydown='if(event.keyCode==13){this.blur()}' onblur='change_text_back(this)' class='text'/>";getSelectPos(obj.getElementsByTagName("INPUT")[0]);}}function change_text_back(obj){obj.parentNode.innerHTML=obj.parentNode.innerHTML.replace(obj.outerHTML,obj.value)	}function getSelectPos(esrc){if(esrc==null){esrc=event.srcElement; }var rtextRange =esrc.createTextRange();rtextRange.moveStart('character',esrc.value.length);rtextRange.collapse(true);rtextRange.select(); }function drawLine(){if(event.button==2){var toObj=event.srcElement;if (event.srcElement.tagName.toLowerCase() == 'textbox') toObj = event.srcElement.parentElement;if(toObj.tagName!="roundrect"&&toObj.tagName!="polyline"&&toObj.tagName!="oval")return;var fromObj=null;var endarrow="endarrow='block'";var tiaojian="";var rects=document.getElementsByTagName("roundrect");for(var i=0;i<rects.length;i++){if(rects[i].fillcolor=="red"){fromObj=rects[i];break;}}if(fromObj==null){var polys=document.getElementsByTagName("polyline");for(var i=0;i<polys.length;i++){if(polys[i].fillcolor=="red"){fromObj=polys[i];break;}}}if(fromObj==null){var ovals=document.getElementsByTagName("oval");for(var i=0;i<ovals.length;i++){if(ovals[i].fillcolor=="red"){fromObj=ovals[i];break;}}}if(toObj&&fromObj){var source=fromObj.id;var object=toObj.id;if(source==object)return;if (toObj.tagName=="oval"){endarrow=""}if (fromObj.tagName=="polyline"){tiaojian="<vml:textbox  style='vertical-align:middle;word-break: break-all;' onselectstart='return false;'>是/否</vml:textbox>"}if(document.getElementById("line_"+source+"_"+object)){return;}s="<vml:line mfrid='"+source+"' id='line_"+source+"_"+object+"' title='' source='"+source+"' object='"+object+"' strokecolor=black from='0,0' to='0,0' ondblclick='change_text(this)' style='position: absolute;display: none; z-index: 2' arcsize='4321f' coordsize='21600,21600' onmousedown='line_selected(this)'>";s+="<vml:stroke "+endarrow+">";s+="</vml:stroke>";s+="<vml:shadow on='T' type='single' color='#b3b3b3' offset='1px,1px' />";s+=tiaojian;s+="</vml:line>";document.getElementById("liucheng").insertAdjacentHTML("beforeEnd",s);rect_selected(toObj,"red");movelines();var name=fromObj.getElementsByTagName("textbox")[0].innerText;var lines=document.getElementsByTagName("line","red");var nextStr="";for(var j=0;j<lines.length;j++){if(lines[j].id.indexOf("line_"+source+"_")>-1){var to_id=lines[j].id.split("_")[2];var o=document.getElementById(to_id);nextStr+=o.getElementsByTagName("textbox")[0].innerText+",";}}nextStr=nextStr.substr(0,nextStr.length-1)
var title=name+",下一步骤:"+nextStr;fromObj.title=title;}}}function delete_rect(){var selObj=null;var rects=document.getElementsByTagName("roundrect");for(var i=0;i<rects.length;i++){if(rects[i].fillcolor=="red"){selObj=rects[i];}}if(selObj){var lines=document.getElementsByTagName("line");var id_sub,j,arr=new Array(),k=0;for(j=0;j<lines.length;j++){id_sub=lines[j].id.split("_");if(id_sub[1]==selObj.id||id_sub[2]==selObj.id){arr[k]=lines[j].id;k++;}}for(var n=0;n<arr.length;n++){delete_line(arr[n])	}selObj.removeNode(true);}}function delete_oval(){var selObj=null;var ovals=document.getElementsByTagName("oval");for(var i=0;i<ovals.length;i++){if(ovals[i].fillcolor=="red"){selObj=ovals[i];}}if(selObj){var lines=document.getElementsByTagName("line");var id_sub,j,arr=new Array(),k=0;for(j=0;j<lines.length;j++){id_sub=lines[j].id.split("_");if(id_sub[1]==selObj.id||id_sub[2]==selObj.id){arr[k]=lines[j].id;k++;}}for(var n=0;n<arr.length;n++){delete_line(arr[n])	}selObj.removeNode(true);}}function delete_poly(){var selObj=null;var polys=document.getElementsByTagName("polyline");for(var i=0;i<polys.length;i++){if(polys[i].fillcolor=="red"){selObj=polys[i];}}if(selObj){var lines=document.getElementsByTagName("line");var id_sub,j,arr=new Array(),k=0;for(j=0;j<lines.length;j++){id_sub=lines[j].id.split("_");if(id_sub[1]==selObj.id||id_sub[2]==selObj.id){arr[k]=lines[j].id;k++;}}for(var n=0;n<arr.length;n++){delete_line(arr[n])	}selObj.removeNode(true);}}function delete_line(id){var line=document.getElementById(id);if(line){line.removeNode(true)}}function delete_sel_line(){var lines=document.getElementsByTagName("line");for(var i=0;i<lines.length;i++){if(lines[i].strokeColor=="red"){delete_line(lines[i].id);	}}}function showMenu(){if(event.button==2&&event.srcElement.tagName=="BODY"){}else{var menu=document.getElementById("menu");if(event.srcElement.parentNode==menu){}}}function set_main(){if(request("exe")=="save"){var url="../"+asp_php+"/liucheng_manage."+asp_php+"?exe=set_main&id="+request("id");_gId("frame_blank").src=url;}else{alert("请先保存此流程图!");	}}function change_size(wf,hf){var arr=new Array("roundrect","polyline","oval")
for(n=0;n<arr.length;n++){var tag=arr[n]
var nodes=_gTagName(tag);if(nodes.length>0){for(var i=0;i<nodes.length;i++){var w=nodes[i].style.pixelWidth 
var h=nodes[i].style.pixelHeight
nodes[i].style.width=w*wf;nodes[i].style.height=h*hf;}movelines();}}}function save_liucheng(exe){var url="../"+asp_php+"/liucheng_manage.asp?exe="+exe;form1.action=url;form1.content.value=document.getElementById("liucheng").innerHTML;form1.submit();}function set_title(){var href=document.location.href;if(href.indexOf("exe=save")>-1){var id=href.split("id=")[1];save_liucheng("save&id="+id);}else{window.showModalDialog("../main/liucheng_set_title.htm",window,"dialogHeight=100px;dialogWidth=300px;help=no;scroll=no")		}}function save_ok(id){alert("save ok.")
document.location.href+="?exe=save&id="+id}function save_failed(err){alert("error："+err);	}function get_liucheng(){var href=document.location.href;if(href.indexOf("exe=save")>-1){var id=href.split("id=")[1]
var url="../asp/liucheng_manage.asp?exe=show&id="+id
var req = getAjax();req.open("GET", url, true);req.onreadystatechange = function(){if(req.readyState==4){var arr=req.responseText.split("|/td|");document.getElementById("liucheng").innerHTML= arr[0];document.title=arr[1];}};req.send(null);}}function getAjax(){var oHttpReq = null;if(window.ActiveXObject)
oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");else if(window.createRequest)
oHttpReq = window.createRequest();else
oHttpReq = new XMLHttpRequest();return oHttpReq;}