{include file="Header.htm"}
<script>
{literal}
MyCP.set_debug(0);
/* Get all values of the form. */
function getValues()
{
    RowID   = document.getElementById("RowID").value;
    ColID   = document.getElementById("ColID").value;
    BlockID = document.getElementById("BlockID").value;
    PageCFG = document.getElementById("PageCFG").value;
}

/* Ajax front js to get block defination. */
function getBlock()
{
    getValues();
    MyCP.call("AjaxFrontCommon.php", "getBlock", updateBlock, PageCFG, RowID, ColID, BlockID);
    return false;
}

/* Ajax front js to update page. */
function updateBlock(result)
{   
    document.getElementById("LayoutList").innerHTML = result.Block[0].Layout[0].data; 
    document.getElementById("TableList").innerHTML  = result.Block[0].TableName[0].data;
    document.getElementById("FieldList").innerHTML  = result.Block[0].Field[0].data; 
    document.getElementById("Caption").value        = result.Block[0].Caption[0].data; 
    document.getElementById("Where").value          = result.Block[0].Where[0].data; 
}
/* Ajax front js to get fields defination. */
function getFields(TableName)
{
	MyCP.call('AjaxFrontCommon.php', 'getFields', updateFields, TableName);
	return false;
}
/* Ajax front js to update page. */
function updateFields(result)
{
    document.getElementById("FieldList").innerHTML = result.Block[0].Field[0].data;
}

function switchActive(CellID)
{
    document.getElementById(CellID).className = "active";
    for(I = 0; I <Cells.length; I ++)
    {
        var Cell = document.getElementById(Cells[I]);
        if(Cells[I] != CellID)
        {
            Cell.className="inactive";
        }
    }
}
{/literal}
</script>
<body>
<h3>Manage Front Common Page. </h3>
{if $PageCFG}
  <ul>
    <li><a href="#" onclick="switchDisplay('SetPage',  'SetBlock')">Set the page.</a></li>
    <li><a href="#" onclick="switchDisplay('SetBlock', 'SetPage')">Set the block.</a></li>
    {include file='Page/ViewAndDownLink.htm'}
  </ul>
{/if}
  <form method="post" id="SetPage">
    <table align="center" class="tblnarrow noborder">
    <caption>{if $PageCFG}Edit Front Page {$PageCFG}.{else}Create a Front Page.{/if}</caption>
    <tr>
      <th>FileName</th>
      <td><input type="text" name="PageCFG" id="PageCFG" value="{$Page.PhpFile}" /> (.php)</td>
    </tr>
    <tr>
      <th>PageTitle</th>
      <td><input type="text" name="PageTitle" value="{$Page.PageTitle}" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="SavePage" value="Save" class="submit" /></td>
    </tr>
    </table>
  </form>
  {if $PageCFG}
    <form method="post" target="innerwin" id="SetBlock" style="display:none">
     <table align="center" class="tblnarrow noborder">
      <caption>Define blocks</caption>
      <tr>
        <th>Select block</th>
        <td>
          {$RowList}{$ColList}{$BlockList}
          <input type="button" value="ok" class="button" onclick="getBlock()" />
        </td>
      </tr>
      <tr>
        <th>Set column style</th>
        <td id="LayoutList"></td>
      <tr>
        <th>Select tables</th>
        <td id="TableList"><select size="4" style="width:90%"></select></td>
      </tr>
      <tr>
        <th>Select Fields</th>
        <td id="FieldList"><select size="4" style="width:90%"></select></td>
      </tr>
      <tr>
        <th>Caption</th>
        <td><input type="text" name="Caption" id="Caption" class="text" /></td>
      </tr>
      <tr>
        <th>Where</th>
        <td><input type="text" name="Where" id="Where" class="text" /></td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input type="submit" name="SaveBlock" value="Save" class="submit" />
          <input type="hidden" name="PageCFG"   value="{$PageCFG}" />
        </td>
      </tr>
      </table>
    </form>
    <script>getBlock();</script>
  {/if}
  <div align="center"><iframe name="innerwin" height="0" frameborder="0"></iframe></div>
</body>
</html>