﻿//MAPGUIDE SERWIS
var LstBoxResult;
var ResultType;
var ResultCategory;

function InitListBox(id, LstWidth, LstHeight, LstColor, HoverColor, SelColor, OnDblClick)
{
   var txtMsg = $get('msgNoResults');  
   var langMsg = txtMsg ? txtMsg.innerHTML : '';    
   var IdListy = Math.random().toString().replace(".","");     
   var Arguments = {        
      Base: top.document.getElementById(id),           
      Multiselect: false,
      Rows: 3,
      Width: LstWidth,
      ListHeight : LstHeight,
      FontSize: '11px',       
      FontHoverWeight: 'normal',
      ItemSpanClass: 'LstItem',
      HoverItemBackColor: HoverColor,      
      HoverBorderdColor: HoverColor,
      SelectedItemBackColor: SelColor,
      NormalItemBackColor: LstColor, 
      MsgNoResults: langMsg,
      TopMsgNoResults: 12, 
      ClickEventHandler: OnDblClick
   };           
   var LstBox = new ListBox(Arguments);                 
   return LstBox    
}

function CalculateListPos(id, deltax, xPos)
{
  var dlg = $get(id); 
  if (dlg)  
  {
    var x = ie() ? deltax : deltax - 2;
    if (xPos)
      x = xPos;
    dlg.style.left = x + 'px';      
  }  
}

function GetSelectedItem(LstBox)
{ 
   var value = LstBox.GetSelectedValue(); 
   var text = LstBox.GetSelectedText();          
   ShowQuery(value, text, top.ResultType, top.ResultCategory);  
   return false;    
}

function InitListResult()
{
  LstBoxResult = InitListBox('Results_LstResult', 356, 370, '#EFF4FA','#B3CCE6','#CFE0EF',OnDblClickResult);    
  CalculateListPos('Results_LstResult',0,0); 
}  

function DisposeListResult()
{  
    if (LstBoxResult)
    {
        LstBoxResult.Dispose();  
        LstBoxResult = null; 
    }
}

var OnDblClickResult = function(Sender, EventArgs)
{ 
  if (top.LstBoxResult)  
     GetSelectedItem(top.LstBoxResult);                       
} 

function FillResultList(lstID, lstValue, typ, category)
{  
  top.ResultType = typ;
  top.ResultCategory = category;
     
  var arrID = new Array();
  if (lstID != '')
    arrID = lstID.toString().split('^');
  
  var arrValue = new Array();
  if (lstValue != '')
    arrValue = lstValue.toString().split('^');
  
  if (top.LstBoxResult)
  {
    top.LstBoxResult.DeleteItems();    
    for (var j = 0; j <= arrID.length-1; j++)
    {
       if (j>0) 
           top.LstBoxResult.AddItem(arrValue[j], arrID[j]);  
       else           
           top.LstBoxResult.AddItem(arrValue[j], arrID[j], true);       
    }     
  }    
}    

function ClearDropDown(ddl) 
{
  var len = ddl.options.length;
    for (i=0; i<len; i++) {
       ddl.remove(0); 
    }
}

function InitSportObjectList(sourceList)
{   
  var dlgFrame = top.document.getElementById('iSearchAdv');
  if (dlgFrame) {
    var ddList = dlgFrame.contentWindow.document.getElementById("TabSport_ddSport");       
    if (ddList && sourceList) 
    {           
      ClearDropDown(ddList); 
      var opcje = ddList.options;     
      for (var j = 0; j <= sourceList.options.length-1; j++) 
      {
        opcje[j] = new Option(sourceList.options[j].value);
        opcje[j].value = sourceList.options[j].text;      
      }  
    }    
  } 
}

