<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="enrgise" %>
<%@ page import="wenrgise.common.utility.EnrgiseConstants" %>

<html:html locale="true">
<head>
  <html:base />
  <LINK href="../includes/ENRGISE.css" rel=stylesheet> <title><bean:message key="wenrgise.common.search" /></title>
</head>
<enrgise:errors />

<body onload="checkOnLoad();" scroll="no">
<html:form  name="CommonSearchScreen"  action="/CommonSearchScreenMap"  type="wenrgise.common.webtier.form.BaseLOVForm" method="post">
<!-- Hidden Fields -->     
<html:hidden property="txtHidSubmitFirst" value="true" />
<html:hidden property="txtHidAction" />
<html:hidden property="txtHidSelectedValue" />
<html:hidden property="txtHidTotRows" />
<html:hidden property="txtHidTotCols" />

<html:hidden property="lovKey" />
<html:hidden property="insertFlag" />
<input type="hidden" name="multipleFlag" >
<html:hidden property="queryParam" />
<html:hidden property="recursiveFlag" />
<html:hidden property="level" />
<html:hidden property="finalLevel" />
<html:hidden property="initialLevel" />

<!-- Hidden Fields For Parent Field -->
<input type="hidden" name="openerFieldName1" >  
<input type="hidden" name="openerFieldName2" >  
<input type="hidden" name="openerFieldName3" >  
<input type="hidden" name="openerFieldName4" >  
<input type="hidden" name="openerFieldName5" >  
<input type="hidden" name="openerFieldName6" >  
<input type="hidden" name="openerFieldName7" >  
<input type="hidden" name="openerFieldName8" >  
<input type="hidden" name="openerFieldName9" >  
<input type="hidden" name="openerFieldName10" >  
<input type="hidden" name="openerFieldName11" >  
<input type="hidden" name="openerFieldName12" >  
<input type="hidden" name="openerFieldName13" >  
<input type="hidden" name="openerFieldName14" >  
<input type="hidden" name="openerFieldName15" >  
<input type="hidden" name="openerFieldName16" >  
<input type="hidden" name="openerFieldName17" >  
<input type="hidden" name="openerFieldName18" >  
<input type="hidden" name="openerFieldName19" >  
<input type="hidden" name="openerFieldName20" >  


<html:hidden property="searchFieldName1" />  
<html:hidden property="searchFieldName2" />  

<bean:define id="level" name="CommonSearchScreen" property="level"/>
<bean:define id="finalLevel" name="CommonSearchScreen" property="finalLevel"/>
<bean:define id="initialLevel" name="CommonSearchScreen" property="initialLevel"/>
<logic:notEmpty name="CommonSearchScreen" property="searchFieldName1" >
<bean:define id="SearchField1" name="CommonSearchScreen" property="searchFieldName1"/>
<bean:define id="SearchField2" name="CommonSearchScreen" property="searchFieldName2"/>
<table cellpadding="0" cellspacing="0" class="blueBar"  >
  <tr >
     <logic:notEqual name="CommonSearchScreen" property="searchFieldName1" value="NULL" >
      <td width="15%" align="right"><bean:message  key="<%=SearchField1.toString()%>" /></td>
      <td width="30%" align="left"><html:text property="searchField1" size="15" /></td>
     </logic:notEqual>
     <logic:notEqual name="CommonSearchScreen" property="searchFieldName2" value="NULL" >
        <td width="15%" align="right"><bean:message key="<%=SearchField2.toString()%>" /></td>
        <td width="30%" align="left"><html:text property="searchField2" size="15" /></td>
     </logic:notEqual>
     <td width="30%" align="right" ><button accesskey="S" property="butSearch" onclick="Search();" ><bean:message key="wenrgise.common.search" /></button></td>
       </tr>
</table>
</logic:notEmpty>

<logic:greaterThan name="CommonSearchScreen" property="txtHidTotRows" value="0" >
<table width="100%">
  <td class="rowsFound" ><bean:write name="CommonSearchScreen" property="txtHidTotRows" /> <bean:message key="wenrgise.common.rowsFound" /> </td>
</table>  
</logic:greaterThan>
<logic:equal name="CommonSearchScreen" property="txtHidSubmitFirst" value="false" >
<logic:equal name="CommonSearchScreen" property="txtHidTotRows" value="0" >
<table width="100%">
 <td class="rowsNotFound"><bean:message key="wenrgise.common.rowsNotFound" /></td>
</table>
</logic:equal>
</logic:equal>

<div id="divDtlTable" style="height:310px">
<table id="tableId" cellpadding="0" cellspacing="0">
  <logic:greaterThan name="CommonSearchScreen" property="txtHidTotRows" value="0" >
  <tr>
   <td width="1%" wrap class="tableHeader" ><bean:message key="wenrgise.common.select" /></td>
   <logic:iterate id="oHeader" name="CommonSearchScreen" property="headerList"  indexId="hIdx">
      <logic:equal name="CommonSearchScreen" property='<%="visibility["+ hIdx.toString() + "]"%>' value="V" >
        <td class="tableHeader" >
          <bean:message key="<%=oHeader.toString()%>" />
        </td>
      </logic:equal>
   </logic:iterate>
  </tr> 
  
  <!--//For Blank Row -->
  <tr>
    <td width="5%" align="center">
        <input type="radio"  name="selRadio" onclick="setSelectedValue(0);" value="0" >
    </td>
    <logic:iterate id="oHeader" name="CommonSearchScreen" property="headerList"  indexId="hIdx">
        <logic:equal name="CommonSearchScreen" property='<%="visibility["+ hIdx.toString() + "]"%>' value="V" >
         <td align="center" >
            <input type="text" name='<%="detailField"+ String.valueOf(hIdx.longValue()+ 1 ) %>' style="width:100%" readonly="true" />
         </td>
        </logic:equal>
        <logic:notEqual name="CommonSearchScreen" property='<%="visibility["+ hIdx + "]"%>' value="V" >
          <input type="hidden" name='<%="detailField"+ String.valueOf(hIdx.longValue()+ 1 ) %>' name="oDtlList" />   
       </logic:notEqual>
     </logic:iterate>
     </td>
   </tr>
   <!--//For Blank Row -->
  
  
   
<logic:iterate name="CommonSearchScreen" property="detailList" id="oDtlList" type="wenrgise.common.bean.LOVBean" indexId="iDtl">
<tr >
    <td width="5%" align="center">
      <logic:equal name="CommonSearchScreen" property="multipleFlag" value="true" >
        <html:checkbox  property="selRadio" onclick="setSelectedValue(this.value)"  value="<%=String.valueOf(iDtl.longValue() + 1 ) %>" />
      </logic:equal>
      <logic:notEqual name="CommonSearchScreen" property="multipleFlag" value="true" >
        <html:radio property="selRadio" onclick="setSelectedValue(this.value)"  value="<%=String.valueOf(iDtl.longValue() + 1 )%>" />
      </logic:notEqual>
    </td>
    <logic:iterate id="oCol" name="CommonSearchScreen" property="headerList"  indexId="colIdx">
    <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="<%=colIdx.toString()%>">
       <logic:equal name="CommonSearchScreen" property='<%="visibility["+ colIdx.toString() + "]"%>' value="V" >
        <td align="center">
           <html:text property='<%="detailField"+ String.valueOf(colIdx.longValue()+ 1 ) %>' name="oDtlList" style="width:100%" readonly="true" />
        </td>
        </logic:equal>
        <logic:notEqual name="CommonSearchScreen" property='<%="visibility["+ colIdx.toString() + "]"%>' value="V" >
          <html:hidden property='<%="detailField"+ String.valueOf(colIdx.longValue()+ 1 ) %>' name="oDtlList" />   
       </logic:notEqual>
    </logic:greaterEqual>
    </logic:iterate>
  
   </tr>
  </logic:iterate>
</table>

</div>

<!--//Browse buttons For recursive lov  -->
<logic:equal name="CommonSearchScreen" property="recursiveFlag" value="Y" >
<table width="100%"  >

<logic:equal name="CommonSearchScreen" property="initialLevel" value="<%=level.toString()%>" >
  <td width="50%" align="right" ><button property="butPrev" disabled >&lt;</button> </td>
</logic:equal> 
<logic:notEqual name="CommonSearchScreen" property="initialLevel" value="<%=level.toString()%>" >
  <td width="50%" align="right" ><button  property="butPrev" onclick="doPrev()" >&lt;</button> </td>
</logic:notEqual> 
<logic:equal name="CommonSearchScreen" property="finalLevel" value="<%=level.toString()%>" >
  <td width="50%" align="left" ><button  property="butNext" disabled >&gt;</button> </td>
</logic:equal> 
<logic:notEqual name="CommonSearchScreen" property="finalLevel" value="<%=level.toString()%>" >
  <td width="50%" align="left" ><button property="butNext" onclick="doNext()">&gt;</button> </td>
</logic:notEqual> 

</table>
</logic:equal>
<!--//Browse buttons for recursive lov -->



<table width="100%"  class="blueBar">
<!--//Disable Submit button if not in final level -->
<logic:equal name="CommonSearchScreen" property="finalLevel" value="<%=level.toString()%>" >
  <td width="50%" align="right" ><button name="butSave" onclick="Save_Exit();" ><bean:message key="wenrgise.common.select"/></button> </td>
</logic:equal> 
<logic:notEqual name="CommonSearchScreen" property="finalLevel" value="<%=level.toString()%>" >
  <td width="50%" align="right" ><button name="butSave" disabled ><bean:message key="wenrgise.common.select"/></button> </td>
</logic:notEqual> 
<!--//Disable Submit button if not in final level -->

<td width="50%" align="left" ><button name="butClose" onclick="window.close()" ><bean:message key="wenrgise.common.exit" /></button></td>
</table>
</logic:greaterThan>
<input type="hidden" name="holdrecursiveFlag" value='<bean:write name="CommonSearchScreen" property="recursiveFlag" />' >
<input type="hidden" name="holdInitialLevel" value='<bean:write name="CommonSearchScreen" property="initialLevel" />' >
<input type="hidden" name="holdFinalLevel" value='<bean:write name="CommonSearchScreen" property="finalLevel" />' >
<input type="hidden" name="holdLevel" value='<bean:write name="CommonSearchScreen" property="level" />' >
<input type="hidden" name="colCount" value='<bean:write name="CommonSearchScreen" property="txtHidTotCols" />' >
<logic:notEmpty name="CommonSearchScreen" property="insertFlag" >
  <input type="hidden" name="holdInsertFlag" value='<bean:write name="CommonSearchScreen" property="insertFlag" />' >
</logic:notEmpty>
</html:form>
</body>
</html:html>




<script language="javascript" >
var iOpenerFieldCount;

function setOpenerFields(fieldString)
{
  aryOpener = new Array();
  aryOpener = fieldString.split(",");
  iOpenerFieldCount=aryOpener.length;
  //If no opener fields are specified.
  if(iOpenerFieldCount==0)
  {
    alert("At least 1 opener fieldmust be specified");
    return;
  }
  for(i=0; i<iOpenerFieldCount;i++){
    if(aryOpener[i]){
      document.getElementsByName("openerFieldName"+(i+1))[0].value= aryOpener[i];
    }
  }
}

function setSearchFields(fieldString)
{
  arySearch = new Array();
  arySearch = fieldString.split(",");
  if(arySearch[0]){
    document.forms[0].searchFieldName1.value = arySearch[0];
  }
  else{
    document.forms[0].searchFieldName1.value = "NULL";
  }
  if(arySearch[1]){
    document.forms[0].searchFieldName2.value = arySearch[1];
  }
  else{
    document.forms[0].searchFieldName2.value = "NULL";
  }  
 
}



function checkOnLoad(){
   //Set the Display Fields (for return to parent form)
   //--------------------------------------------------
   if(opener.document.forms[0].txtDisplayFields)
   {
    setOpenerFields(opener.document.forms[0].txtDisplayFields.value);
   }
   else
    alert('txtDisplayFields not defined as hidden field in jsp');
   
   //Set the Search fields. 
   //----------------------
   if(opener.document.forms[0].txtSearchFields){
       setSearchFields(opener.document.forms[0].txtSearchFields.value);
   }
   
   //Set Multiple Flag.
   //-------------------
   if(opener.document.forms[0].multipleFlag){
    document.forms[0].multipleFlag.value=opener.document.forms[0].multipleFlag.value;
   }
    
   //Set query Param  
   //---------------
   if(opener.document.forms[0].queryParam){
     document.forms[0].queryParam.value=opener.document.forms[0].queryParam.value;
   }
     
   //Set the LovKey  
   //--------------
   if(opener.document.forms[0].lovKey)
     document.forms[0].lovKey.value=opener.document.forms[0].lovKey.value;
   else
     alert('lovKey not defined as hidden field in jsp page'); 
     
   //Set the recursiveFlag  
   //---------------------
   if(document.forms[0].recursiveFlag.value=="Y")
   {
      window.resizeTo(610,470);     
   }
   
    
    //ColCount is used to check for first submit.
    //-------------------------------------------
    if(document.forms[0].colCount.value=="0"){
      document.forms[0].txtHidAction.value="FirstTime";
   //   document.all.finalLevel.value=0;
   //   document.all.level.value=0;
      document.forms[0].submit();
   }
}

function setSelectedValue(Val)
{
   document.forms[0].txtHidSelectedValue.value=Val;
   if(document.forms[0].holdrecursiveFlag.value=="Y")
   {
     if(Val==0)
     {
        if(document.forms[0].butSave)
        {
          document.forms[0].butSave.disabled=false;
        }
     }
     else
     {
        if(document.forms[0].holdLevel.value!=document.forms[0].holdFinalLevel.Value)
        {
          if(document.forms[0].butSave)
          {
            document.forms[0].butSave.disabled=true;
          }
        }
     }
   }
}

function Search()
{
      document.forms[0].level.value=document.forms[0].holdLevel.value;
      document.forms[0].finalLevel.value=document.forms[0].holdFinalLevel.value;
      document.forms[0].txtHidAction.value="SearchRecords";
      document.forms[0].recursiveFlag.value=document.forms[0].holdrecursiveFlag.value;
      document.forms[0].initialLevel.value=document.forms[0].holdInitialLevel.value;
      document.forms[0].submit();
}

function Save_Exit()
{ 
   var iIndex="";
   if(opener.document.forms[0].txtIndex)
      iIndex = opener.document.forms[0].txtIndex.value;
   
   if(document.forms[0].txtHidSelectedValue.value!="")
   {
      
      //If Multiple flag is true
      //------------------------
      if(document.forms[0].multipleFlag.value=="true"){
           var iCols=document.forms[0].colCount.value;
          var iRows=document.getElementsByName("selRadio").length;
          var arrTable=new Array();
          var arrRow=new Array();
          var iCol,iRow,i=0;
          for(iRow=0;iRow<iRows;iRow++){
            if(document.getElementsByName("selRadio")[iRow].checked){
                arrRow=new Array();
                for(iCol=0;iCol<iCols;iCol++){
                  arrRow[iCol]=document.getElementsByName("detailField"+(iCol+1))[iRow].value;
                }
                arrTable[i++]=arrRow;
            }
          }
          if(opener.doSetFields){
              opener.document.forms[0].multipleFlag.value="false";
              if(opener.document.forms[0].screenMode.value!="Q"){
                opener.document.forms[0].headerDataChanged.value="true";
              }
              opener.doSetFields(arrTable,arrTable.length,iCols);
          }
          else{
              alert('doSetFields() not set in form');    
          }
      }
      else{
          //For setting single Header
          //-------------------------
          if(iIndex=="" ){
            for(i=0;i<iOpenerFieldCount;i++){
              var sOpenerField=document.getElementsByName("openerFieldName"+(i+1))[0];
              var iRetIndex=document.forms[0].txtHidSelectedValue.value;
              var sRetVal=document.getElementsByName("detailField"+(i+1))[iRetIndex].value;
              opener.document.getElementsByName(sOpenerField.value)[0].value=sRetVal;
              if(opener.document.forms[0].screenMode.value!="Q"){
                opener.document.forms[0].headerDataChanged.value="true";
              }
            } 
          }
          //For setting Single Detail
          //-------------------------
          else{
            for(i=0;i<iOpenerFieldCount;i++){
               var oField=document.getElementsByName("openerFieldName"+(i+1))[0].value;
               var oOpenerDtlField=opener.document.getElementsByName(oField)[iIndex];
               var iRetIndex=document.forms[0].txtHidSelectedValue.value;
               oOpenerDtlField.value=document.getElementsByName("detailField"+(i+1))[iRetIndex].value; 
            }
            if(oOpenerDtlField.value != ""){
                if(opener.document.forms[0].screenMode.value!="Q"){
                  opener.document.forms[0].detailDataChanged.value="true";
                }
            }
            //Set detailDataChanged to true
            if(oOpenerDtlField.value != ""){
                if(opener.document.forms[0].screenMode.value!="Q"){
                  opener.document.forms[0].detailDataChanged.value="true";
                }
            }
            //Set the row status to "U"
            if(opener.document.getElementsByName("status")[iIndex])
            {
              if(opener.document.getElementsByName("status")[iIndex].value!="N")
              {
                opener.document.getElementsByName("status")[iIndex].value="U";
              }
            }


          }
      }
   }
   
   
   document.forms[0].txtHidSelectedValue.value="";
   if(document.forms[0].holdInsertFlag.value=="Y")
   {
      opener.doGetInsertData();
   }
   else
   {
    //Event handler on selecting Lov
   if(opener.doOnChangeLov)
   {
       if(opener.document.forms[0].lovKey)
       {
        lovName=opener.document.forms[0].lovKey.value;
       }
       opener.doOnChangeLov(lovName);
   }
   }
    self.close();
}



//For Recursive Lov
//-----------------
function doNext()
{
  if(document.all.txtHidSelectedValue.value != "" )
  {
    document.all.queryParam.value="detailId="+document.getElementsByName("detailField"+(1))[document.all.txtHidSelectedValue.value].value;
    document.all.level.value=parseInt(document.all.holdLevel.value)+1;
    document.all.txtHidAction.value="SearchRecords";
    document.all.finalLevel.value=document.all.holdFinalLevel.value;
    document.all.initialLevel.value=document.all.holdInitialLevel.value;
    document.all.submit();
  }
}

function doPrev()
{
  document.all.level.value=parseInt(document.all.holdLevel.value)-1;
  document.all.txtHidAction.value="SearchRecords";
  document.all.finalLevel.value=document.all.holdFinalLevel.value;
  document.all.initialLevel.value=document.all.holdInitialLevel.value;
  document.all.submit();
}



</script> 


