<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" /> 
  
  <link rel="stylesheet" href="/css/simplified.css" media="screen" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="/js/jquery/css/smoothness/jquery-ui-1.8.17.custom.css" type="text/css">
  <!--<link rel="stylesheet" href="/js/jquery/css/redmond/jquery-ui-1.7.2.custom.css" type="text/css">-->

  <script type="text/javascript" src="/js/jquery/jquery-1.7.1.min.js"></script>
  <script type="text/javascript" src="/js/jquery/jquery-ui-1.8.17.min.js"></script>

  {literal}
  <style>
  body {
    /*width: 500px;*/
    margin: 10px auto;
    /*color: #999;*/
    font: 90%/150% Arial, Helvetica, sans-serif;
    /*margin : 0px;*/
    color  : #808080;
    /*font   : normal 8pt sans-serif,Tahoma,MiscFixed;*/
    background-color:#ECECEC;
  }

  #note_text {
    width:100%;
    height:52px;
  }

  .postitem:hover{
    /*background:#EFEFEF;*/
  }
  </style>

  <script>
  function resize()
  {
    var h = $(document.body).height() - 52;
    var w = $(document.body).width();
    if (w > 600) {
      w = 600;
    }

    $('.content-header').width(w-50);
  }

  function showNt(appUid)
  {
    var d = $('#m_'+appUid);

    if (d.css('display') == 'block') {
      d.hide('slow');
    }
    else {
      d.show('slow');
    }
  }

  function addNt(appUid, proUid, tasUid)
  {
    $('textarea#note_text').val('');
    $.post(
        '../appProxy/getNotesList',
        {
            appUid  : appUid,
            pro:proUid,
            tas:tasUid,
            start:0,
            limit:25
        },
        function(responseText) {
            data = jQuery.parseJSON(responseText);
            if (typeof (data.noPerms) != 'undefined') {
                alert(noPerms);
                return false;
            } else {
                $( "#dialog-add-note" ).dialog({
                resizable: false,
                height:192,
                modal: true,
                buttons: {
                  "Add Note": function() {
                      var sendMail = document.getElementById('chkSendMail').checked;
                      sendMail = (sendMail == true) ? '1' : '0';
                    $(this).dialog("close");
                    $.post(
                      '../appProxy/postNote',
                      {appUid  : appUid,
                       noteText: $('textarea#note_text').val(),
                       swSendMail : sendMail},
                      function(responseText) {
                        updateNt(appUid);
                      }
                    );
                    //redirect('home/startCase?id='+id);
                  },
                  Cancel: function() {
                    $(this).dialog( "close" );
                  }
                }
              });
            }
            //updateNt(appUid);
          
        }
    );
    
    
    
  }

  function updateNt(appUid)
  {
    $.post(
      '../appProxy/getNotesList?appUid='+appUid,
      {start:0, limit:100},
      function(resp) {
        data = jQuery.parseJSON(resp);
        content = $('div#m_'+appUid);
        content.html('');
        
        for (i=0; i<data.notes.length; i++) {
          r = data.notes[i];
          
          s = '<div class="appMessage"><table border="0"><tr>' +
                '<td width="50" valign="top">'+
                  '<img border="0" src="../users/users_ViewPhotoGrid?pUID='+r.USR_UID+'" width="40" height="40"/>' +
                '</td><td>' +
                  '<h3>'+r.USR_FIRSTNAME+' '+r.USR_LASTNAME+' ('+r.USR_USERNAME+')</h3>' +
                  '<p><pre>'+r.NOTE_CONTENT+'</pre>' +
                  '<div class="appMessageDate">Posted at '+r.NOTE_DATE+'</div>' +
                '</td></tr></table></div>';
          
          content.append(s);
          $('#n_'+appUid).show('slow');
        }
        d = $('#m_'+appUid);
        d.show('slow');
      }
    );
    return true;
  }

  $(document).ready(function(){
    $("#loadmorebutton").click(function (){
      $('#loadmorebutton').html('<img src="/images/ajax-loader.gif" />');
      $.ajax({
        url: "getApps?t="+listType+"&start="+appListStart+"&limit="+appListLimit,
        success: function(html){
          appListStart += appListLimit;

          if(jQuery.trim(html) != ''){
            $("#commentlist").append(html);
            $('#loadmorebutton').html('Load More');
          }
          else {
            $('#loadmorebutton').replaceWith('<center>No more applications to show.</center>');
          }
        }
      });

      return false;
    });
  });
  {/literal}

  var appListLimit = {$appListLimit};
  var appListStart = {$appListStart};
  var listType     = '{$listType}';
  var noPerms     = '{$noPerms}';
  </script>
  
</head>

<body onload="resize()" onresize="resize()" > 
  <center>
    <div class="content-header" style="text-align:left">
      <h1 style="padding: 10px">{$title} ({$cases_count})</h1>
      <ul id="commentlist">
        {include file='home/applications.html'}
      </ul>

      {if $cases_count > $appListLimit}
      <center>
        <a href="#" style="color:#1F98C7; font-size:12px; font-weight:bold;" id="loadmorebutton">Load More</a>
      </center>
      {/if}
    </div>
  </center>

  <div id="dialog-add-note" title="Case Note" style="display:none">
    <p><!-- <span class="ui-icon ui-icon-document" style="float:left; margin:0 7px 20px 0;"></span> -->
    <span id="startAppTitle"/>
    <textarea id="note_text" rows="2" cols="22"></textarea>
    <div class="x-form-check-wrap" id="ext-gen160" style="font-size:11px">
      <input type="checkbox" name="chkSendMail" id="chkSendMail" autocomplete="off" class=" x-form-checkbox x-form-field" checked="">
      <label class="x-form-cb-label" for="chkSendMail" id="ext-gen161">Send email (Case Participants)</label>
    </div>
    </p>
  </div>
  <br/>
 </body>
 </html>
