﻿
     var box;
  
   function lalala()
   {
   
 
    
    if(!window.console){
      console = typeof(console) !== 'undefined' ? console : { log: function(msg) { $('#log').html(msg + '<br/>\n' + $('#log').html() ); } };
    }

    var arra;
    if(document.getElementById('ctl00_ContentPlaceHolder1_hidenbox') != null)
    {
        arra = document.getElementById('ctl00_ContentPlaceHolder1_hidenbox').value.split(',');
    }
    else
    {
        arra = new Array();
    } 
    if(arra.length != 0)
    {
    if(arra.length == 1)
    {
        if(arra[0] == "")
        {
            arra = new Array();
        }
    }

    $(function() {
        var list1 = [];
        var tagy = zoznamtagov();
        for (var tag in tagy) {
            var tag_meno = tagy[tag].split('_')[0];
            var id = tagy[tag].split('_')[1];
            list1.push({text:tag_meno});
        }
        
        //alert(list1);
        
        box =
      $("input.autobox.0").autobox({
        list: list1,
        match: function(typed) {
              this.typed = typed;
              this.pre_match = this.text;
              this.match = this.post_match = '';
              if (!this.ajax && !typed || typed.length == 0) { return true; }
              var match_at = this.text.search(new RegExp("\\b" + typed, "i"));
              if (match_at != -1) {
                  this.pre_match = this.text.slice(0, match_at);
                  this.match = this.text.slice(match_at, match_at + typed.length);
                  this.post_match = this.text.slice(match_at + typed.length);
                  return true;
              }
              return false;
          },
        //match: function(typed) { return this.text.match(new RegExp(typed)); },
        insertText: function(obj) { return obj.text },
        templateText: "<li><%= text %></li>",
        //templateText: "<li><%= pre_match %><span class='matching' ><%= match %></span><%= post_match %></li>"
        prevals : arra//['stefanko@wilma.com', 'betty@barney.com']
      });     

      $("input.autobox")
        .bind("activate.autobox", function(e, d) { console.log(d); })
        .bind("cancel.autobox", function(e) { console.log("Cancelled"); });
    });

}


}



function zoznamtagov()
    {
        var zoznam = document.getElementById('ctl00_ContentPlaceHolder1_hidenbox_tagy').value;
        if(zoznam!="")
            var tagy = zoznam.split(';');
        //alert('tagy su '+zoznam);
        return tagy;
    }
