	function runProcessReply(data)
 {
		 top.g_runWithinTab=false;//mmm dodgy but how else can I stop none runWith's???
   if (data.indexOf("<displayType") > -1) 
   {
     data = findAndExecuteScripts(data);
     validateProcessReply(data);
   }
   else
			{				 	
						var tp = top.g_mainframe.getTPane( "Mat_Pain_Div" );
						
						if ( data.indexOf("<TPaneColor") > -1 )
						{
        sIdx = data.indexOf("<TPaneColor>")+12;
		      eIdx = data.indexOf("</TPaneColor>");
  		    var TPaneColor = data.substring(sIdx, eIdx);	
								data = data.substring(0,sIdx) + data.substring(eIdx+13);
						  tp.bgColor=TPaneColor;
						} else
						{
							 tp.bgColor = "#3E5478";
						}
						
 			 genericTPaneDisplay( data, document.body, 50, 50, document.body, null );
					try
					{
						 if ( g_curFocus && g_curFocus != null )
							{
							  setTimeout("focusElement( '"+g_curFocus.id+"' )",100);//g_curFocus.focus();
							}
							else
							{
					    focusFirst( document.all["Mat_Pain_Form"] );
									setTimeout("focusFirst( document.all['Mat_Pain_Form'] )",1000);
							}
					}catch(e){}
			}			
	}	

 var g_proFrm;	
	
	function validateProcess(formName, pk, link, processNew, oldprocess, additionalUrl,selectedVal )
	{
		 cancelBubble(event);
		 var runWithin = false;			
			g_proFrm=document.getElementById(formName);
			if ( !additionalUrl ) additionalUrl = "";
   if ( !selectedVal) selectedVal = "";
	  if (selectedVal != null && selectedVal != "") additionalUrl += "&selectedText=" + selectedVal;
	
			if ( parent && g_proFrm.elements.framename && g_proFrm.elements.framename.value.length > 0  )
			{
				 var framename = g_proFrm.elements.framename;
					if ( framename && ( !parent.document.view || !parent.document.view.elements.SearchForm) ) 
					{  		
					  if ( framename.value.indexOf("tabSummaryFrame") > -1 )
							{
					    framename = framename.value.replace(/tabSummaryFrame/g,'');
         runWithin = parent.document.all["tabSummaryTable_"+framename] ? parent.document.all["tabSummaryTable_"+framename].getAttribute("runWithin") : parent.document.all["tabFormData_"+framename].getAttribute("runWithin");
							  if ( runWithin == "true" )
							    top.g_runWithinTab = parent.document.all[g_proFrm.elements.framename.value];
							  additionalUrl+="&tabSummary=true";
							}else
							{//for running processes in embedded forms.
										//runWithin=true;
										//top.g_runWithinTab = parent.document.all[g_proFrm.elements.framename.value];
										additionalUrl+="&tabSummary=true";
							}
					}
			}
							
   if ( (pk == -4 || pk == -2 || pk == -11) && link.indexOf('/servlet/') < 0 ) 
     StealthDownload(formName, link, null, null, "runWithin="+runWithin, validateProcessReply );
	  else if ( pk == -1 ) 
		   eval(link);
	  else 
	  {
				 if ( g_proFrm.elements.GenExecutionPk )
		     g_proFrm.elements.GenExecutionPk.value=pk;
					else
					  additionalUrl += "&GenExecutionPk="+pk;
		   var subAction = '';
		   if ( g_proFrm.elements.subAction )
		     subAction = g_proFrm.elements.subAction.value;	  
     if (pk=='-100' || pk=='-2')
		   {
		     rn(g_proFrm.elements.action);
		     StealthDownload(formName, subAction, link, null, "runWithin="+runWithin+"&processStart=true&processType=" + processNew, validateProcessReply );
		   } 
		   else	
					{
						 if ( g_proFrm.elements.SearchForm ) 
							{
								 document.getElementById("frame"+ g_proFrm.elements.searchlistpk.value).contentWindow.importScript(top.g_root+"scripts/tPane.js");
	        document.getElementById("frame"+ g_proFrm.elements.searchlistpk.value).contentWindow.StealthDownload(formName, subAction, null, null, "GenExecutionPk="+g_proFrm.GenExecutionPk.value+"&runWithin="+runWithin+"&processStart=true&processType=" + processNew + "&oldprocess=" + oldprocess + "&sortField=", document.getElementById("frame"+ g_proFrm.elements.searchlistpk.value).contentWindow.validateProcessReply );
							}
							else
							{
								 if ( parent != top ) 
									{
										 try
											{
										   top.g_scrollTopMem=parent.document.all.genericScroller.scrollTop;
											  top.g_scrollGenFormPk=parent.document.view.genFormPk.value;
											} catch(e){}
									}
									StealthDownload(formName, subAction, '/servlet/com.isa.balmoral.admin.process.MatServlet', null, additionalUrl+"&runWithin="+runWithin+"&processStart=true&processType=" + processNew + "&oldprocess=" + oldprocess + "&sortField=", validateProcessReply );
							}
					}
	  }      		
	}
	
	function clearCheckBoxes()
	{
		 var els = document.getElementsByTagName("input");
			if ( els == null ) return;
			for ( i =0; i<els.length; i++ )
			{
				  if ( els[i].type=="checkbox" ) els[i].checked=false;
			}
	}
	
	function validateProcessReply(data)
	{
		var additionUrl="";
		if ( parent.g_proFrm && parent.g_proFrm.elements.SearchForm ) additionUrl="&GenExecutionPk="+parent.g_proFrm.elements.GenExecutionPk.value;
		if ( !g_proFrm ) g_proFrm = document.view;
		var sIdx = data.indexOf("<displayType")+35;
		var eIdx = data.indexOf("</displayType>");
		var displayType = data.substring(sIdx, eIdx);
		data = data.substring(data.indexOf("</displayType>")+14);
	
		switch ( displayType )
		{
		  case 'alert' : clearCheckBoxes(); alert(data); break;
		  case 'alertOC' :
		  {					 
		    if (confirm(data))
						{ try{g_proFrm.removeAttribute("requestInProcess");}catch(e){}
		      StealthDownload( g_proFrm.name, g_proFrm.subAction.value, null, null, "Confirmed=yes"+additionUrl, validateProcessReply, true );
						}
		    else
						  clearCheckBoxes();
		    break;
		  }
		  case 'alertOCA' :
		  {					 
		    if (confirm(data))
						{
							 try{g_proFrm.removeAttribute("requestInProcess");}catch(e){}
 	      StealthDownload( g_proFrm.name, g_proFrm.subAction.value, null, null, "Confirmed=true"+additionUrl, validateProcessReply, true );
						}
		    else
						  clearCheckBoxes();
		    break;
		  }
		  case 'tpane' :
    {
					 try{g_proFrm.removeAttribute("requestInProcess");}catch(e){}
      top.activateShield();
		    sIdx = data.indexOf("<TPaneX")+30;
		    eIdx = data.indexOf("</TPaneX>");
		    var TPaneX = data.substring(sIdx, eIdx);
		    data = data.substring(data.indexOf("</TPaneX>")+10);
		    sIdx = data.indexOf("<TPaneY")+30;
		    eIdx = data.indexOf("</TPaneY>");
		    var TPaneY = data.substring(sIdx, eIdx);
		    data = data.substring(data.indexOf("</TPaneY>")+10);				
						
						var tp = top.g_mainframe.getTPane( "Mat_Pain_Div" );
						if ( !tp ) tp = new top.g_mainframe.TPane("Mat_Pain");
						
						if ( data.indexOf("<TPaneColor") > -1 )
						{
        sIdx = data.indexOf("<TPaneColor>")+12;
		      eIdx = data.indexOf("</TPaneColor>");
  		    var TPaneColor = data.substring(sIdx, eIdx);	
								data = data.substring(0,sIdx) + data.substring(eIdx+13);
						  tp.bgColor=TPaneColor;
						}
      else
      {
        tp.bgColor = "#3E5478";
      }
						
						tp.modal=false;
						tp.repos=true;
						tp.showTPane( data, top.g_mainframe.document.body, parseInt(TPaneX), parseInt(TPaneY), top.g_mainframe.document.body );
		    break;
		  }				
		  case 'alertYN' :
		  {					 
		    if (data.indexOf("<matType") > -1)
		    {		  
		      sIdx = data.indexOf("<matType")+31;
		      eIdx = data.indexOf("</matType>");
		      var matType = data.substring(sIdx, eIdx);
		      data = data.substring(data.indexOf("</matType>")+10);

		      sIdx = data.indexOf("<proType")+31;
		      eIdx = data.indexOf("</proType>");
		      var proType = data.substring(sIdx, eIdx);
		      data = data.substring(data.indexOf("</proType>")+10);
		  
		      sIdx = data.indexOf("<proceId")+31;
        eIdx = data.indexOf("</proceId>");
        var proceId = data.substring(sIdx, eIdx);
		      data = data.substring(data.indexOf("</proceId>")+10);
		      try{g_proFrm.removeAttribute("requestInProcess");}catch(e){}
        StealthDownload( g_proFrm.name, "next", null, null, "Confirmed="+(confirm(data)?"True":"False")+"&currentStepPk="+matType+"&processType="+proType+"&processaction=next&processid="+proceId+"&processStart=true"+additionUrl, validateProcessReply, true ); 
								break;
		    }
		    else
		    {
							 try{g_proFrm.removeAttribute("requestInProcess");}catch(e){}
        StealthDownload( g_proFrm.name, g_proFrm.subAction.value, null, null, "Confirmed="+(confirm(data)?"True":"False")+additionUrl, validateProcessReply, true ); 
								break;
		    }		    
		  }
		  case 'search' :
		  case 'replaceparent' :
		  case 'replacemain' : 
				  if ( top.g_browser != 'IE' ) 
						{ 						   
			     var datas = data.split("<\/script>");																							
								var oNewDoc;
								if ( displayType=="search" )
          oNewDoc = parent.document.open("text/html", "replace");
								else if ( parent.document && parent.g_proFrm && (parent.g_proFrm.tabSummary || g_proFrm.normalSubList || parent.g_proFrm.SearchForm.value == 'true') )
          oNewDoc = displayType=="replaceparent" && parent != top ? parent.document.open("text/html", "replace") : document.open("text/html", "replace");												
        else
						    oNewDoc = document.open("text/html", "replace");
																									
	       oNewDoc.write(datas[0]);												
        for ( d = 1; d < datas.length; d++ )
	       {
	         oNewDoc.write("<\/scr"+"ipt>");
	         oNewDoc.write(datas[d]);							
	       }
        oNewDoc.close();	
						} else
						  ieReplace(displayType,data);
		    break;
		  case 'mainpage' : document.body.innerHTML = data; break;
				case 'script' : findAndExecuteScripts(data); break;//do nothing
		}		
	}
	
	
	function ieReplace( displayType, data )
	{
		 if ( !parent.g_proFrm ) parent.g_proFrm=parent.document.view;
		 var w =window;			
			if ( displayType=="search" || ( ( parent.document && parent.g_proFrm && (parent.g_proFrm.tabSummary || g_proFrm.normalSubList || (parent.g_proFrm.SearchForm && parent.g_proFrm.SearchForm.value == 'true')) &&( displayType=="replaceparent" && parent != top ) ) ) )
     w = parent;										
		 top.g_body=data;
			
			if ( top.g_runWithinTab )
			{				
				 w.setTimeout("top.replaceTabSummary()",10);
			} else
     w.setTimeout("top.replaceMainframe()",10);		
	}
	
 function pime( obj ) 
	{
   if ( obj.parentNode.parentNode.id != "quickLaunchRow" ) return;
			obj.style.marginTop='0';
			obj.style.marginBottom='0';
			obj.style.marginLeft='2';
			obj.style.marginRight='2';
   obj.style.border='1px solid black';
 }  
 function piml( obj ) 
	{
   if ( obj.parentNode.parentNode.id != "quickLaunchRow" ) return;
			obj.style.marginTop='1';
			obj.style.marginBottom='1';
			obj.style.marginLeft='3';
			obj.style.marginRight='3';
   obj.style.border='none';
 }	

 function proMenuReplyRouter(data){getProMenuTPaneReply(data);}
 function showProcessMenu() 
	{
		//**NOTE** processMenu.js has a showProcessMenu function which when loaded will override this function.....easy to follow!
   importScript(top.g_root + "scripts/processMenu.js");
			if ( !g_proFrm ) g_proFrm = document.view;
   StealthDownload( g_proFrm.name, "GetProMenuTPane", "/servlet/com.isa.balmoral.admin.process.MatServlet", null, "GenExecutionPk=", proMenuReplyRouter );				
 }	
	