<%@ 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" %>
<%@ 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.view" /></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" />



<!-- 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" value=" " />  
<html:hidden property="searchFieldName2" value=" "/>  



<html:hidden property="searchField1" value=" " />
<html:hidden property="searchField2" value=" "/>
<html:hidden property="butSearch" value=" "  />

<logic:greaterThan name="CommonSearchScreen" property="txtHidTotRows" value="0" >
<table width="100%">
  <center><td align="left" ><strong><font color="blue" ><bean:write name="CommonSearchScreen" property="txtHidTotRows" /> Matching Rows Found</font></strong></td></center>
</table>
</logic:greaterThan>
<logic:equal name="CommonSearchScreen" property="txtHidTotRows" value="0" >
<table width="100%">
<center><td align="left" ><strong><font color="red" >No Matching Rows Found</font></strong></td></center>
</table>
</logic:equal>

<div id="divDtlTable" style="height:310px">
<table id="tableId" cellpadding="0" cellspacing="0">
  <logic:greaterThan name="CommonSearchScreen" property="txtHidTotRows" value="0" >
  <bean:define id="oVisib" name="CommonSearchScreen" property="visibilityList" type="java.util.ArrayList" />
  <tr>
   <td width="1%" wrap class="tableHeader" >Select</td>
   <logic:iterate name="CommonSearchScreen" property="headerList" id="Index" indexId="hIdx">
      <%if(oVisib.get(hIdx.intValue()).equals(EnrgiseConstants.VISIBLE)){%>
        <td class="tableHeader" >
          <bean:define  id="msg" name="Index" />
          <bean:message key="<%=msg.toString()%>" />
        </td>
      <%}%>
   </logic:iterate>
  </tr> 
  
<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:hidden  property="selRadio" onclick="setSelectedValue(this.value)"  value="<%=iDtl.toString()%>" />
      </logic:equal>
      <logic:notEqual name="CommonSearchScreen" property="multipleFlag" value="true" >
        <html:hidden property="selRadio" onclick="setSelectedValue(this.value)"  value="<%=iDtl.toString()%>" />
      </logic:notEqual>
    </td>
    
    <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="1">
      <%if(oVisib.get(0).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField1" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField1" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="2">
    <%if(oVisib.get(1).equals(EnrgiseConstants.VISIBLE)){%>
      <td align="center">
       <html:text property="detailField2" name="oDtlList" style="width:100%" />
      </td>
    <%}else{%>
      <html:hidden property="detailField2" name="oDtlList" />   
    <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="3">
   <%if(oVisib.get(2).equals(EnrgiseConstants.VISIBLE)){%>
    <td align="center">
     <html:text property="detailField3" name="oDtlList" style="width:100%"/>
    </td>
   <%}else{%>
     <html:hidden property="detailField3" name="oDtlList" />   
   <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="4">
    <%if(oVisib.get(3).equals(EnrgiseConstants.VISIBLE)){%>
      <td align="center">
       <html:text property="detailField4" name="oDtlList" style="width:100%" />
      </td>
     <%}else{%>
       <html:hidden property="detailField4" name="oDtlList" />   
     <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="5">
  <%if(oVisib.get(4).equals(EnrgiseConstants.VISIBLE)){%>
    <td align="center">
     <html:text property="detailField5" name="oDtlList"  style="width:100%" />
    </td>
   <%}else{%>
     <html:hidden property="detailField5" name="oDtlList" />   
   <%}%>      
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="6">
  <%if(oVisib.get(5).equals(EnrgiseConstants.VISIBLE)){%>
    <td align="center">
     <html:text property="detailField6" name="oDtlList"  style="width:100%" />
    </td>
   <%}else{%>
     <html:hidden property="detailField6" name="oDtlList" />   
   <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="7">
       <%if(oVisib.get(6).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField7" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField7" name="oDtlList" />   
       <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="8">
      <%if(oVisib.get(7).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField8" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField8" name="oDtlList" />   
       <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="9">
       <%if(oVisib.get(8).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField9" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField9" name="oDtlList" />   
       <%}%>    
  </logic:greaterEqual>
  <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="10">
       <%if(oVisib.get(9).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField10" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField10" name="oDtlList" />   
       <%}%>     
  </logic:greaterEqual>
  

   </logic:iterate>
   <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="11">
      <%if(oVisib.get(10).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField11" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField11" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
    <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="12">
      <%if(oVisib.get(11).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField12" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField12" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
    <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="13">
      <%if(oVisib.get(12).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField13" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField13" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="14">
      <%if(oVisib.get(13).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField14" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField14" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="15">
      <%if(oVisib.get(14).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField15" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField15" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="16">
      <%if(oVisib.get(15).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField16" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField16" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="17">
      <%if(oVisib.get(16).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField17" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField17" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="18">
      <%if(oVisib.get(17).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField18" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField18" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="19">
      <%if(oVisib.get(18).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField19" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField19" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
     <logic:greaterEqual name="CommonSearchScreen" property="txtHidTotCols" value="20">
      <%if(oVisib.get(19).equals(EnrgiseConstants.VISIBLE)){%>
        <td align="center">
         <html:text property="detailField20" name="oDtlList" style="width:100%" />
        </td>
       <%}else{%>
         <html:hidden property="detailField20" name="oDtlList" />   
       <%}%>    
    </logic:greaterEqual>
   </tr>
</table>

</div>
<table width="100%"  class="blueBar">
<html:hidden property="butSave" />
<td  align="center" ><html:button property="butClose" onclick="window.close()" value="   Exit   " /></td>
</center>
</table>
</logic:greaterThan>


<bean:define id="colCount" name="CommonSearchScreen" property="txtHidTotCols" />
<input type="hidden" name="colCount" value="<%=colCount%>" >
<logic:notEmpty name="CommonSearchScreen" property="insertFlag" >
<bean:define id="insertFlag" name="CommonSearchScreen" property="insertFlag" />
<input type="hidden" name="holdInsertFlag" value="<%=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.getElementById("openerFieldName"+(i+1)).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.getElementsByName("txtDisplayFields")[0])
    setOpenerFields(opener.document.getElementsByName("txtDisplayFields")[0].value);
   else
    alert('txtDisplayFields not defined as hidden field in jsp');
   
   //Set the Search fields. 
   //----------------------
   if(opener.document.getElementsByName("txtSearchFields")[0]){
       setSearchFields(opener.document.getElementsByName("txtSearchFields")[0].value);
   }
   
   //Set Multiple Flag.
   //-------------------
   if(opener.document.getElementsByName("multipleFlag")[0]){
    document.forms[0].multipleFlag.value=opener.document.getElementsByName("multipleFlag")[0].value;
   }
    
   //Set query Param  
   //---------------
   if(opener.document.getElementsByName("queryParam")[0]){
     document.forms[0].queryParam.value=opener.document.getElementsByName("queryParam")[0].value;
   }
     
   //Set the LovKey  
   //--------------
   if(opener.document.getElementsByName("lovKey")[0])
     document.forms[0].lovKey.value=opener.document.getElementsByName("lovKey")[0].value;
   else
     alert('lovKey not defined as hidden field in jsp page'); 
    
    //ColCount is used to check for first submit.
    //-------------------------------------------
    if(document.forms[0].colCount.value=="0"){
      document.forms[0].txtHidAction.value="FirstTime";
      document.forms[0].submit();
   }
}

function setSelectedValue(Val)
{
   document.forms[0].txtHidSelectedValue.value=Val;
}

function Search()
{
      document.forms[0].txtHidAction.value="SearchRecords";
      document.forms[0].submit();
}

function Save_Exit()
{ 
   var j="";
   if(opener.document.getElementsByName("txtIndex")[0])
      j = opener.document.getElementsByName("txtIndex")[0].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(j=="" ){
            for(i=0;i<iOpenerFieldCount;i++){
              var sOpenerField=document.getElementById("openerFieldName"+(i+1));
              opener.document.getElementById(sOpenerField.value).value=document.getElementsByName("detailField"+(i+1))[document.forms[0].txtHidSelectedValue.value].value;
              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 oo=document.getElementsByName("openerFieldName"+(i+1))[0].value;
               var oOpenerDtlField=opener.document.getElementsByName(oo)[j];
               oOpenerDtlField.value=document.getElementsByName("detailField"+(i+1))[document.forms[0].txtHidSelectedValue.value].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"
            

          }
      }
   }
   
   document.forms[0].txtHidSelectedValue.value="";
   if(document.forms[0].holdInsertFlag.value=="Y")
   {
      opener.doGetInsertData();
   }
   //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();
}


</script> 

