<%@page import="com.capgemini.framework.common.DateHelper" %>
<%@page import="com.capgemini.framework.common.SettingsHelper" %>
<%@page import="com.capgemini.framework.common.StringHelper"%>
<%@page import="com.capgemini.reports.database.javabean.enumeration.ReportCriteriaEnum"
        import="com.capgemini.reports.database.manager.MngSchedulingCriteriaVal" %>
<%@page import="java.util.Map"%>
<%
    /*
     * Available request parameters:
     *  "isUpdateReport"       (boolean)             Is this a submission of a NEW report or an UPDATE?
     *  "idReport"             (long)    <Optional>  Report Id in case of an UPDATE request
     */
    boolean isDevMode            = SettingsHelper.isDevMode();
    boolean isUpdate = Boolean.valueOf(request.getParameter("isUpdateReport"));
    Long    reportID             = isUpdate ? Long.valueOf(request.getParameter("idReport")) : new Long(-1);
	
    // Default values in each field. May contain nothing / existing values / development values
	String theDefaultGen = "";
	String theDefaultProduct = "";
	String theDefaultUnit = "";
	String theDefaultDate = "";
    String theMonoMulti = "MONO" ;
	
    if (isDevMode){ // Devmode default values
		theDefaultGen     = "C25";
		theDefaultProduct = "29R0";
		theDefaultUnit    = "245";	
		theDefaultDate    = DateHelper.getDate(); // Today
	}
    if( isUpdate){ // Existing values to reload from DB
        Map<ReportCriteriaEnum, String> theFunctionalCriteriaValues = new MngSchedulingCriteriaVal().getFunctionalMap(reportID);

		theDefaultGen     = StringHelper.replaceNullByEmpty( theFunctionalCriteriaValues.get(ReportCriteriaEnum.GENERIC_ASSEMB));
		theDefaultProduct = StringHelper.replaceNullByEmpty( theFunctionalCriteriaValues.get(ReportCriteriaEnum.PRODUCT));
		theDefaultUnit    = StringHelper.replaceNullByEmpty( theFunctionalCriteriaValues.get(ReportCriteriaEnum.UNIT));
		theDefaultDate    = StringHelper.replaceNullByEmpty( theFunctionalCriteriaValues.get(ReportCriteriaEnum.EFFECTIVITY_DATE));
		theMonoMulti      = StringHelper.replaceNullByEmpty( theFunctionalCriteriaValues.get(ReportCriteriaEnum.MONO_MULTI));
	}
%>

<!-- HTML, will probably be imported right inside a form -->
<table cellspacing="0" cellpadding="3" border="0">
	<tr>
	   <td class="tdFieldTitle" valign="top">Niveau :</td>
	   <td>
	       <div style="font-size:12px;">
                <input type="radio" class="radioInput" id="mono" name="mono_multi" value="mono"   <%=( ("MONO".equals(theMonoMulti))) ? "checked" : "" %>/> Mono
                <input type="radio" class="radioInput" id="multi" name="mono_multi" value="multi" <%=(!("MONO".equals(theMonoMulti))) ? "checked" : "" %>/> Multi
	           <br/>
	           <br/>
	       </div>
	   </td>
	</tr>
	<tr>
        <td class="tdFieldTitle">G&eacute;n&eacute;rique &quot;Vue Technique&quot; :</td>
        <td>
            <input type="text" id="generic" name="generic" value="<%= theDefaultGen %>" />
        </td>
    </tr>
	<tr>
        <td class="tdFieldTitle required">Produit* :</td>
        <td>
            <input type="text" id="product_id" name="product_id" value="<%= theDefaultProduct %>"/>
        </td>
    </tr>
	<tr>
        <td class="tdFieldTitle required">Unit* :</td>
        <td>
            <input type="text" id="unit" name="unit" value="<%= theDefaultUnit %>"/>
        </td>
    </tr>
	<tr>
		<td class="tdFieldTitle required">Date d'effectivit&eacute;* :</td>
		<td>
			<!-- Start calendar definition -->
			<input id="datepicker" type="text" name="datepicker" style="cursor:hand;" value="<%= theDefaultDate %>"/>
			<div class="flow-element">
                <div id="container">
                </div>
            </div>
			<!-- End calendar definition -->
		</td>
	</tr>
	<tr>
        <td class="tdFieldTitle" colspan="2" style="text-align:center;"><br/>
        	<div id="loading" style="display:none;">
        		<i>Traitement en cours...</i><br/><img src="/kurt-web/ihm/progress.gif" vspace="6" width="129" height="20">
        	</div>
        </td>
    </tr>
</table>

<!-- Internal functional Javascript methods (checks etc.) -->
<script>
   /* Automatic checks before sending the form */
	function checkForm()
	{
		var isCheckOk = false;
		
		if (isMandatoryFieldEmpty("product_id")){
			parent.Dialog("Erreur", "Veuillez saisir le champ obligatoire : Produit.");
		}else if (isMandatoryFieldEmpty("unit")){
			parent.Dialog("Erreur", "Veuillez saisir le champ obligatoire : Unit.");
		}else if (isMandatoryFieldEmpty("datepicker")){
			parent.Dialog("Erreur", "Veuillez saisir le champ obligatoire : Date d'Effectivit&eacute;.");
		}else if (!isNumber("unit")){
			document.getElementById("unit").focus();
			parent.Dialog("Erreur", "Vous devez saisir un entier dans le champ Unit");
		}else{
			isCheckOk = true;
		}
	
		return isCheckOk;
	}

	/* Initialize date picker */
	initPicker('datepicker','container');
</script>