<?php
// set for 600x800 screen
$table_width = '760';


function display_main_menu($displaybuttons = '', $backpage = '')
{
  do_html_header('Isoleso');

  if ($displaybuttons <> '')
    $buttons = $displaybuttons;
  else
  {   
    $buttons = array();
  
    
      $buttons[0] = 'view-statement';
      $buttons[1] = 'benefit-check';
      $buttons[2] = 'Back';
  }


//  echo $_SERVER['DOCUMENT_ROOT'].'####'.$_SERVER['REQUEST_URI'];
  
  if ($backpage == '')
    display_toolbar($buttons, $_SERVER[HTTP_REFERER]);
  else
    display_toolbar($buttons, $backpage);
  
}

function do_html_header($title = '')
{

  global $table_width;
?>

 <html>
  <head>
        
<!--  <link rel="stylesheet" href="style/add2home.css">
  <script type="text/javascript" src="include/add2home.js" charset="utf-8"></script>  
-->
    <title><?php echo $title?></title>
    <LINK REL="SHORTCUT ICON" HREF="images/favicon.ico">

    <style>
      h1 { font-family: Arial,  Helvetica, sans-serif; font-size: 32; 
           font-weight: bold; color:  white; margin-bottom: 0}
      h2 { font-family: Arial,  Helvetica, sans-serif; font-size: 12; 
           font-weight: bold; color:  red; margin-bottom: 0}
      b { font-family: Arial, Helvetica, sans-serif; font-size: 14; 
          font-weight: bold; color: black }
      th { font-family: Arial,  Helvetica, sans-serif; font-size: 18
           font-weight: bold; color:  white; }
      body, li, td, p { font-family: Arial, Helvetica, sans-serif; 
                     font-size: 14; margin = 5px }
      a { color: #000000 }
    </style>
    
    <link rel="stylesheet" href="jQuery/themes/redmond/jquery-ui.css">
    <link rel="stylesheet" href="SlickGrid/slick.grid.css" type="text/css"/>
    <link rel="stylesheet" href="SlickGrid/Examples/examples.css" type="text/css"/>
    
    <link rel="stylesheet" href="css/emc2.css" type="text/css"/>
    
    <script src="jQuery/jquery-1.11.js"></script>
    <script src="jQuery/ui/jquery-ui.js"></script>
    <script src="jQuery/jquery.ui.touch-punch.js"></script>
    <script src="jQuery/jquery.blockUI.js"></script>
        

    <style>
            
      #mygrid {position:absolute;left:8;right:8;height:700px}
      #header{position: fixed; right:8px; left:0px; padding-left:8px; padding-right:8px; top : 8; background: #fff; width: 100%;  }

    </style>
    
    <style type="text/css">
      table.myTable { border-collapse:collapse; }
      table.myTable td, table.myTable th { border:1px solid black;padding:5px; }


    </style>



  </head>

  <body>
  <table  cellspacing = 0 cellpadding = 0 border = 0 width=100%>
  <tr>
  <td bgcolor = '#FFAF00'><img src = "images/headerleft.jpg" width = "100%"  alt ="" align = "left" /></td>
  <td bgcolor = '#FFAF00'><img src = "images/headerright.jpg" width = "100%"    alt ="" align = "right" /></td>

  <?php
    if (!isset($_SESSION['admin_user']))
      echo '<td bgcolor = "#FFAF00"  valign="top" align="right"><font color="#FFFFFF">Not Logged in</font></td>';
    else
    {
      $loggedin = $_SESSION['admin_user'];
      echo '<td bgcolor = "#FFAF00"  valign="top" align="right">
          <font color="#FFFFFF">Logged in Practice:</font><b> <font color="#FFFFFF">'.$loggedin.'</font></b>
          <p><button id="btnLogout">Logout</button></p>

          </td>';
    }  
  ?> 
  
  </tr>
  </table>

  <div id="benefitcheck" class="dialog"></div>
  
<?php
}

function display_insertorlookup_form($option)
{
  // display form Prompting to Insert Or Lookup       
?>
  <center>
  <table bgcolor='#cccccc'  border = 0 cellpadding = 6 cellspacing = 0>
   <tr>
     <th colspan = 3 bgcolor = '#5B69A6'>
        Insert or Lookup <?php echo ucfirst($option) ?>
     </th>
   </tr>
   <tr>
     <td colspan=3 align="center">

     <tr>
     <td bgcolor = "#cccccc">
 
     <?php 
       echo '<td bgcolor = "#cccccc">';
       display_button('insert', 'insertorlookup.php?action=insertpatient');
  
       echo '<td bgcolor = "#cccccc">';
       display_button('lookup',  'insertorlookup.php?action=lookuppatient');
 
       echo '</td>';
       echo '</tr>';

     ?>
   </td>
     </tr>
   <tr>
 </table></form>
 </center>
<?php
}

function display_lookup_form($Table, $Fields, $OrderBy, $Action,$DisplayFields,$Form, $Show)
{
  // display  Lookup Form
?>
    
  <center>
  <form action=<?php echo'"'.$Action.'"'?>  method="post" >
  <table bgcolor='#cccccc'  border = 0 cellpadding = 6 cellspacing = 0>
   <tr>
     <th colspan = 4 bgcolor = '#5B69A6'>
       Lookup <?php echo $Show ?> 
     </th>
   </tr>
   <tr>
     <td>Search Field:</td>
     <td>Criteria:</td>
     <td>Value:</td>
     <td>Order By:</td>
     </tr>
   <tr>
     <td>
    
      
      <select size="1" name= "Fields">

        <?php
      
          for($i = 0; $i<(sizeof($Fields)); $i++)
          {
             if ($_SESSION[$Form.'Fields'] == $Fields[$i][0])
                 echo '<option selected value="'.$Fields[$i][0].'">'.$Fields[$i][1].'</option>';
             else               
                 echo '<option value="'.$Fields[$i][0].'">'.$Fields[$i][1].'</option>';
          }
        ?>
       
      </select>
      </td>

     <td>
      <select size="1" name= "Criteria">

        <?php 
          if ($_SESSION[$Form.'Criteria'] == '=')
          {
            echo '<option selected value = "=">is equal to</option>';
            echo '<option value = "starting with">starts with</option>';
            echo '<option value = "like">contains</option>';
          }
          else
          if ($_SESSION[$Form.'Criteria'] == 'starting with')
          {
            echo '<option value = "=">is equal to</option>';
            echo '<option selected value = "starting with">starts with</option>';
            echo '<option value = "like">contains</option>';
          }  
          else
          if ($_SESSION[$Form.'Criteria'] == 'like')
          {
            echo '<option value = "=">is equal to</option>';
            echo '<option value = "starting with">starts with</option>';
            echo '<option selected value = "like">contains</option>';
          }
          else
          {
            echo '<option value = "=">is equal to</option>';
            echo '<option value = "starting with">starts with</option>';
            echo '<option value = "like">contains</option>';
          }
            
        ?>        

      </select></td>

    
   <td><input type="text" name= "Value"  value = <?php echo '"'.$_SESSION[$Form.'Value'].'"' ?> ></td>
   
   <td>
      <select size="1" name= "OrderBy">
    
      <?php
      for($i = 0; $i<(sizeof($OrderBy)); $i++)
      {
        if ($_SESSION[$Form.'OrderBy'] == $OrderBy[$i][0])
          echo '<option selected value="'.$OrderBy[$i][0].'">'.$OrderBy[$i][1].'</option>';
        else               
          echo '<option value="'.$OrderBy[$i][0].'">'.$OrderBy[$i][1].'</option>';
      }
      ?>
      </select>
    </td> </tr>
   <tr>
     <td colspan=4 align="center">
     <?php display_form_button('lookup'); ?>
     </td></tr>
     
   <input type="hidden" name="DisplayFields" value = '<?php echo $DisplayFields ?>'>
   <input type="hidden" name="Table" value = '<?php echo $Table ?>'>
   <input type="hidden" name="Form" value = '<?php echo $Form ?>'>
  
 </table></form>
 </center>


<?php
}

function display_form_button($button)
{
  //display one of our standard buttons in a form

  echo "<center><input type = 'image' src = 'images/".$button.".gif' 
                 border = 0 ";
  echo 'width = 149 height = 43 ';
  echo "alt = '".format_action($button)."' /></a></center>";
    
}

function display_button($button,  $newurl = '')
{
  //display one of our standard buttons as a href
  if ($newurl)
   $url = $newurl;
  else
    $url = "index.php?action=$button";
    
  $jqbutton = '".'.$button.'"';

  echo '<button class="'.$button.'" id="'.$button.'">'.format_action($button).'</button>';
?>

  <script src="benefitcheckdialog.js"></script>
  
  <script>

    var checkicon = '<?php echo $button ?>';

    if (checkicon == 'view-statement')
      var icon = 'ui-icon-note';
    else
    if (checkicon == 'benefit-check')
      var icon = 'ui-icon-person';
    else
    if (checkicon == 'Back')
      var icon = 'ui-icon-arrowreturnthick-1-w';
       else
    if (checkicon == 'log-in')
      var icon = 'ui-icon-locked';

/*   if (checkicon == 'benefit-check')
   {  
      $( <?php echo $jqbutton ?> ).button({ icons: { primary: icon} }).click(function(){
          BenefitCheck();
      });
   }
   else
   {  
*/    
      $( <?php echo $jqbutton ?> ).button({ icons: { primary: icon} }).click(function(){
          window.location.href = '<?php echo $url ?>';
      });
  // }  

  </script>


<?php
}

function display_search_button($button, $extra_parameters = '', $newurl = '')
{
  $url = $newurl;
    
  if($extra_parameters)
    $url .= $extra_parameters;
    
  echo "<a href = '$url'>";
  echo "<img src = 'images/$button.gif' border = 0 ";
  echo 'align = top width = 75 height = 21 ';
  echo "alt = '".format_action($button)."' /></a>";
}

function display_wizard_button($button, $extra_parameters = '', $newurl = '')
{
  //display one of our standard buttons as a href
    if ($newurl)
      $url = $newurl." ?action=$button";
    else
      $url = "index.php?action=$button";

  if($extra_parameters)
    $url .= $extra_parameters;
  echo "<center><a href = '$url'>";
  echo "<img src = 'images/$button.png' border = 0 ";
 // echo 'width = 50  ';
  echo "alt = '".format_action($button)."' /></a></center>";
}

function display_pdf_button($button, $extra_parameters = '', $newurl = '')
{
  //display one of our standard buttons as a href
  if ($newurl)
    $url = $newurl." ?action=$button";
  else
    $url = "index.php?action=$button";

  if($extra_parameters)
    $url .= $extra_parameters;
  echo "<center><a href = '$url' target='_BLANK'>";
  echo "<img src = 'images/$button.gif' border = 0 ";
  echo 'width = 27 height = 25 ';
  echo "alt = 'Reprint Invoice' /></a></center>";
}

function display_submit_button($button)
{
  echo "<center><input type = 'image' src = 'images/".$button.".gif' 
                 border = 0 ";
  echo 'width = 50 height = 43 ';
  echo "alt = '".format_action($button)."' /></a></center>";
}

function display_spacer()
{
  //display blank spacer the size of our buttons
  echo "<img src = 'images/spacer.gif' border = 0 ";
  echo 'width = 149 height = 43 ';
  echo "alt = '' />";
}

function format_action($string)
{
  // convert our actions into a displayable string
  // eg "account-setup" becomes "Account Setup"
  $string = str_replace('-', ' ', $string);
  $string = ucwords($string);
  return $string;
}

function display_toolbar($button, $url = '')
{
  // draw our toolbar
  // there are up to five buttons per row and up to three rows
  // these numbers are completely arbitary and depend on the 
  // images size and acceptable screen width

?>

  <style>
   #toolbar {
     padding: 4px;
     display: block;
   }
   *+html #toolbar {
     display: inline;
   }
   #header2{position: fixed; right:8px; left:0px; padding-left:8px; padding-right:8px; top : 79; background: #fff; width: 100%;  }

   </style>

  <p></p>
  <table width = 100% cellpadding = 0 cellspacing = 0 border = 0 class="shadetable indented">
  <tr><td>

  <div id="toolbar" class="ui-widget-header ui-corner-all">


  <?php
  
        for($j = 0; $j < 5; $j++)
        {
          if ($button[$j])
          {
           if ($button[$j] == 'Back')
              display_button($button[$j], $url);
           else
              display_button($button[$j], '');
          }
        }
  ?>

    <script>
    $('#btnLogout').button({ icons: { primary: 'ui-icon-unlocked'} }).click(function(){
        window.location.href = 'index.php?action=log-out';
    });
  </script>

  </div>
  </td></tr></table>

<?php
   



}

function selfURL() 
{
//  return __FILE__;
//$_SERVER['HTTP_HOST']
// $_SERVER['PHP_self']
//$_SERVER['REQUEST_URI'] 

  $url = $_SERVER['PHP_self'].$_SERVER['REQUEST_URI'];
//$url = str_replace( dirname($_SERVER['PHP_SELF']), '', $_SERVER['REQUEST_URI']);

  //echo "new url".$url;

 // ECHO "HOST".$_SERVER['HTTP_HOST'];
//  ECHO "SELF".$_SERVER['PHP_SELF'];
 // ECHO "REQUEST".$_SERVER['REQUEST_URI'];
 // ECHO "PATH TRANS".$_SERVER['PATH_TRANSLATED'];
  
  return $url;
  //$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}


function format_number($str,$decimal_places='2',$decimal_padding="0")
{
     /* firstly format number and shorten any extra decimal places */
     /* Note this will round off the number pre-format $str if you dont want this fucntionality */
     $str              =  number_format($str,$decimal_places,'.','');    // will return 12345.67
     $number      = explode('.',$str);
     $number[1]  = (isset($number[1]))?$number[1]:''; // to fix the PHP Notice error if str does not contain a decimal placing.
     $decimal     = str_pad($number[1],$decimal_places,$decimal_padding);
       
     return (float) $number[0].'.'.$decimal;
}


?>
