
 // Format Displaying Curreny for displaying only
  function currency_format_display(cash,cur='$'){
    // console.log(cash);
    if(isNaN(cash) || cash == null || cash==0){
      return  0 + " $";
    }else{
      //return cur +" "+ cash;
      
      var value = parseFloat(cash);
      var num =   value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' '+cur;
      return num;
      //return cur +" "+ value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
    }

  }


  


  function currency_format(cash,cur='$'){
    // console.log(cash);
    if(isNaN(cash) || cash == null || cash==0){
      return "$ "+ 0;
    }else{
      return cur +" "+ parseFloat(cash).toFixed(2);
      
     // var value = parseFloat(cash);
     // var num = '$ ' + value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
     // return num;
    }

  }


  function escape_notes(){
    $("span[data-popup='tooltip']").each(function(){
        var deco = $(this).attr('data-original-title');
        deco = decodeURIComponent(deco);
        $(this).attr('data-original-title',deco);
     }); 
  }

  function escapeHtml(unsafe) {
    
     safe = unsafe.replace(/%/g, "&_25_;");
    safe = safe.replace(/\\/g, "&_5C_;");
    safe = safe.replace(/"/g, "&_quot_;");
    safe = safe.replace(/'/g, "&#_039_;");
    //alert(safe)
    return safe;
 }

 function decodeURIComponent_back(unsafe) {
    
    safe = unsafe.replace(/&_25_;/g, "%");
    safe = safe.replace(/&_5C_;/g, "\\");
    safe = safe.replace(/&_quot_;/g, '"');
    safe = safe.replace(/&#_039_;/g, "'");
    // alert(safe)
    return safe;
 }

 Date.dateDiff = function(datepart, fromdate, todate) {
    datepart = datepart.toLowerCase();
    var diff = todate - fromdate;
    var divideBy = { w:604800000,
                     d:86400000,
                     h:3600000,
                     n:60000,
                     s:1000 };

    return Math.floor( diff/divideBy[datepart]);
  }


  function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
      return 'not';
  }

$(function() {
  // tag input

  // Basic initialization
    $('.tokenfield').tokenfield();
  //
    // Teal
    //

    // Add class on init
    $('.tokenfield-teal').on('tokenfield:initialize', function (e) {
        $(this).parent().find('.token').addClass('bg-teal')
    });

    // Initialize plugin
    $('.tokenfield-teal').tokenfield();

    // Add class when token is created
    $('.tokenfield-teal').on('tokenfield:createdtoken', function (e) {
        $(e.relatedTarget).addClass('bg-teal')
    });

    // ========================================
    //
    // Tags input
    //
    // ========================================


    // Display values
    $('.tags-input, [data-role="tagsinput"], .tagsinput-max-tags, .tagsinput-custom-tag-class').on('change', function(event) {
        var $element = $(event.target),
            $container = $element.parent().parent('.content-group');

        if (!$element.data('tagsinput'))
        return;

        var val = $element.val();
        if (val === null)
        val = "null";
    
        $('pre.val > code', $container).html( ($.isArray(val) ? JSON.stringify(val) : "\"" + val.replace('"', '\\"') + "\"") );
        $('pre.items > code', $container).html(JSON.stringify($element.tagsinput('items')));
        Prism.highlightAll();
    }).trigger('change');



    // Basic examples
    // ------------------------------

    // Basic initialization
    $('.tags-input').tagsinput();


    // Allow dublicates
    $('.tags-input-dublicates').tagsinput({
        allowDuplicates: true
    });


    // Set maximum allowed tags
    $('.tagsinput-max-tags').tagsinput({
        maxTags: 5
    });


    // Custom tag class
    $('.tagsinput-custom-tag-class').tagsinput({
        tagClass: function(item){
            return 'label bg-success';
        }
    });

});