<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMSessionImpl"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="java.io.Writer"
%><%@page import="java.util.List"
%><%@page import="java.util.ArrayList"
%><%@page import="java.util.Iterator"
%><%@page import="java.util.Enumeration"
%><%@page import="java.text.DateFormat"
%><%@page import="com.fujitsu.ibpm.dtm.*"
%>
<%-- calls the debug() function --%>
<%@ include file="Debug.jsp" %>

<% //checks the session is valid or not
    request.setCharacterEncoding("UTF-8");
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }
%>
<%@ include file="dtmCommon.jsp" %>
<%
    String decisionTableIdStr = request.getParameter("decisionTableId");
	boolean isActive = false;
	String isActiveStr = (String) session.getAttribute("isActive");
	if(isActiveStr==null){isActive = false;}
	else{
		isActive = new Boolean(isActiveStr).booleanValue();
	}

	DecisionTable decisionTable = null;
	String name="";
	String description="";
	String constraintType="Minimum";
	// check for editing DecisionTable	
  if (actionStr != null && actionStr.length() > 0) {
        if (actionStr.equals("edit")) {
  			int decisionTableId = (new Integer(decisionTableIdStr)).intValue();
         	decisionTable = dtm.getDecisionTable(decisionTableId); 
			name = decisionTable.getName();
			constraintType = decisionTable.getType();
			description = decisionTable.getDescription();
         }
}else{
		 	decisionTableIdStr = "";
		 }
%>

<html>
<head>
<title>Interstage Business Process Manager | Approval DecisionTable</title>
<link href="styles/dtm.css" rel="stylesheet" type="text/css">
<script>
function setDefault(myform)
{
    myform.submit();
}

//focus first on the decision table name text field 
function sf(){
	document.main.decisionTableName.focus();
	}

//trims all leading and trailing blank spaces
function Trim(decisionTableName){
	if(decisionTableName.length < 1){
		return"";
	}
	decisionTableName = RTrim(decisionTableName);
	decisionTableName = LTrim(decisionTableName);
	if(decisionTableName==""){
		return "";
	}
	else{
		return decisionTableName;
	}
} 
//trims all trailing blank spaces
function RTrim(decisionTableName){
	var w_space = String.fromCharCode(32);
	var v_length = decisionTableName.length;
	var tempDecisionTableName = "";
	if(v_length < 0){
		return"";
	}
	var decisionTableIndex = v_length -1;

	while(decisionTableIndex > -1){
		if(decisionTableName.charAt(decisionTableIndex) == w_space){
		}
		else{
			tempDecisionTableName = decisionTableName.substring(0,decisionTableIndex +1);
			break;
		}
		decisionTableIndex = decisionTableIndex-1;

	} 
return tempDecisionTableName;

}
//trims all leading blank spaces
function LTrim(decisionTableName){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = decisionTableName.length;
	var tempDecisionTableName = "";

	var decisionTableIndex = 0;

	while(decisionTableIndex < v_length){
		if(decisionTableName.charAt(decisionTableIndex) == w_space){
		}
		else{
			tempDecisionTableName = decisionTableName.substring(decisionTableIndex,v_length);
			break;
		}
		decisionTableIndex = decisionTableIndex + 1;
	} 
return tempDecisionTableName;
} 



function doSubmit(form) {
	
	
    var decisionTableName = document.main.decisionTableName;
	var decisionTableDescription = document.main.decisionTableDescription;
	// trims all leading and trailing spaces
	if(decisionTableDescription.value.length>256)
	{
		alert("Decision Table description cannot be more than 256 characters.");
		return;
	}
	
	if(decisionTableName.value.length>64)
	{
		alert("Decision Table name cannot be more than 64 characters.");
		return;
	}
	
	decisionTableName.value=Trim(decisionTableName.value);
  	if (decisionTableName.value==null || decisionTableName.value=="")
    {
        alert("Please enter Decision Table name");
        return;
    }
	
	document.main.decisionTableId.value = "<%=decisionTableIdStr%>";
	document.main.pageaction.value = "saveDecisionTable";
	form.action="DecisionTableManagement.jsp";
	
   document.main.submit();
}
</script>
</head>
<%
    session.setAttribute("TabIndex","4");
%>
<body class="bodyClass" onLoad="sf()">
<center>
  <jsp:include page="DTMHeader.jsp" flush="true"/><br/>
            
     <form name="main" method="post"  onsubmit="doSubmit(this);return false;">               
  <TABLE  border="0" cellpadding="4" cellspacing="1" class="tableClass" width="90%" align="center">
    <tr> 
      <td align="right" height="35" valign="top"> 
        
        
        <table border="0" cellpadding=0 cellspacing=0>
          <tr> 
            <td align="right"> 
              <table border="0" cellspacing="0" cellpadding="0">
                <tr background="images/buttons/com_button_bg.gif"> 
                  <td width="15"><img src="images/buttons/but_save.gif"></td>
                  <td background="images/buttons/com_button_bg.gif" nowrap>
				  <a href="javascript:doSubmit(this.main)">
                    <div align="center" class="buttonlink"> OK</div>
                    </a></td>
                  <td width="9"> 
                    <div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div>
                  </td>
                </tr>
              </table>
            </td>
            <td>&nbsp;</td>
            <td> 
              <table border="0" cellspacing="0" cellpadding="0">
                <tr background="images/buttons/com_button_bg.gif"> 
                  <td width="15"><img src="images/buttons/cancel.gif"></td>
                  <td background="images/buttons/com_button_bg.gif" nowrap><a href="DecisionTableManagement.jsp"> 
                    <div align="center" class="buttonlink"> Cancel</div>
                    </a></td>
                  <td width="9"> 
                    <div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr align="center" class="headrow"> 
      <td bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')" align="right"> 
          <div align="left"><font color="#000000" size="2"> Decision Table: 
              <div align="right"> </div>
            </font></div>
      </td>
    </tr>
  </table>
                    <p></p>
    <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
      <tr class="headrow"> 
        <td colspan="5"> <b>Decision Table </b></td>
      </tr>
     
    </table>
       <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
          <tr class="evenrow">  
              <td><b>Name</b>:            
              <input name="pageaction" type="hidden" id="pageaction"></td>
              <td> 
                
          <input type="text" name="decisionTableName" size="32" value="<%QuickForm.writeHtml(out, name);%>"/>
          <input type="hidden" name="decisionTableId" value="<%=decisionTableIdStr%>">        </td>
         </tr>
            <tr class="oddrow"> 
              
        <td valign="top"><b>Description</b>:</td>
              
        <td valign="top"> 
          <textarea name="decisionTableDescription" cols="60" rows="5"><%=description%></textarea>        </td>
            </tr>
       </table>
       
    <br>
    <p>&nbsp;</p>
  </form>     
</center>
</body>
</html>


