pMenu = null;
pMenuTop = null;

function selectRow(theRow, color)
{
  if (color != '')
  {
    theRow.style.backgroundColor = color;
  }
  else
  {
    if (theRow.id != '')
      theRow.style.backgroundColor = '#'+theRow.id;
    else
      theRow.style.backgroundColor = '';
  }
}

function activeButton(activeID, arrayB)
{
   for (i=0;i<arrayB.length;i++)
   {
     document.getElementById('menu'+i).src = arrayB[i] + '.gif';
     document.getElementById('data'+i).style.display= 'none';
   }
     
   document.getElementById('menu'+activeID).src = arrayB[activeID] + '_Act.gif';
   document.getElementById('data'+activeID).style.display= 'block';
}



function bookmarksite()
{
  if (document.all)
    window.external.AddFavorite(location.href, document.title);
  else 
    if (window.sidebar)
      window.sidebar.addPanel(document.title, location.href, "")
}

function showSubMenu(name)
{
  objMenu=document.getElementById('sub'+name);
  objTop=document.getElementById('drop'+name);
  if(objMenu.style.display=="none")
  {
    objMenu.style.display="block";
    objTop.className = "menuItemDropJava";
    pMenu = objMenu;
    pMenuTop = objTop;
  }
}

function hideSubMenu()
{
  if (pMenu != null)
  {
    pMenu.style.display="none";
    pMenuTop.className = "menuItemDrop";
    pMenu = null;
  }
}


function showEvents(name,button)
{
  objPanel=document.getElementById(name);
  objButton=document.getElementById(button);
  if(objPanel.style.display=="none")
  {
    objPanel.style.display="block";
    objButton.innerHTML="-";
  }
  else
  {
    objPanel.style.display="none";
    objButton.innerHTML="+";
  }
}

function showEventsImg(name,button)
{
  objPanel=document.getElementById(name);
  objButton=document.getElementById(button);
  if(objPanel.style.display=="none")
  {
    objPanel.style.display="block";
    objButton.innerHTML="<img src='/images/scoreCollapse.gif'>";
  }
  else
  {
    objPanel.style.display="none";
    objButton.innerHTML="<img src='/images/scoreExpand.gif'>";
  }
}


function saveIndex(nIndex)
{
/*
  new Ajax.Request("/ajaxLastIndex.php?index="+nIndex, 
  {
     onSuccess: function(hits) 
     {
     } 
  });
  */
}


function applyTipVote(id, nValue)
{
 $.ajax({
   type: "get",
   url: "/ajaxSetTipVote.php",
   data: "id="+id+"&value="+nValue,
   success: function(msg){
       var str = msg.split("[*]");
       
       document.getElementById('tipInfo_'+id).innerHTML=str[0];
       if (str[1] > 0)
       {
         if (nValue == 1) 
           document.getElementById('tipValueYes_'+id).innerHTML=str[1];
         else
           document.getElementById('tipValueNo_'+id).innerHTML=str[1];
       }
   }
 });
}

function applyNewsVote(id, nValue)
{
 $.ajax({
   type: "get",
   url: "/ajaxSetNewsVote.php",
   data: "id="+id+"&value="+nValue,
   success: function(msg){
       var str = msg.split("[*]");
       document.getElementById('voteInfo_'+id).innerHTML=str[0];
       if (str[1] > 0)
       {
         if (nValue == 1) 
           document.getElementById('voteYes_'+id).innerHTML=str[1];
         else
           document.getElementById('voteNo_'+id).innerHTML=str[1];
       }
   }
 });
}


function applyFavoriteVideo(videoID, nValue, sPref)
{
 $.ajax({
   type: "get",
   url: "/ajaxFavoriteVideo.php",
   data: "id="+videoID+"&value="+nValue,
   success: function(msg){
    
    
    if (msg == 1)
      document.getElementById('videoFavorite_'+videoID).innerHTML = '<small>uspešno dodan</small> <a href="#" onclick="applyFavoriteVideo('+videoID+',0,\''+sPref+'\');return false;"><img src="/images/videoFavoriteOff'+sPref+'.gif" title="Odstrani video iz priljubljenih"></a>';
    else
      document.getElementById('videoFavorite_'+videoID).innerHTML = '<small>uspešno odstranjen</small> <a href="#" onclick="applyFavoriteVideo('+videoID+',1,\''+sPref+'\');return false;"><img src="/images/videoFavoriteOn'+sPref+'.gif" title="Dodaj video med priljubljene"></a>';
   }
 });
}

function removeMessage(nID)
{
 $.ajax({
   type: "get",
   url: "/ajaxDelMessage.php",
   data: "id="+nID,
   success: function(msg){
    if (msg == '1')
    {
      document.getElementById('obj_msg_'+nID).style.display = 'none';
    }
   }
 });
}


function selectLeagueRound(nID,nSelected)
{
 $.ajax({
   type: "get",
   url: "/ajaxGetLeagueSelect.php",
   data: "id="+nID+"&leagueID="+nSelected,
   success: function(msg){
    if (msg != '')
    {
      document.getElementById('round_'+nID).innerHTML = msg;
    }
   }
 });
}


function showTip(name, button)
{
  objPanel=document.getElementById(name);
  objButton=document.getElementById(button);

  if(objPanel.style.height=="100%")
  {
    objPanel.style.height="21px";
    objButton.innerHTML="+ prikaži celoten opis";
  }
  else
  {
    objPanel.style.height="100%";
    objButton.innerHTML="- pomanjšaj opis";
  }
}

function showTip2(name, button)
{
  objPanel=document.getElementById(name);
  objButton=document.getElementById(button);

  if(objPanel.style.display=="block")
  {
    objPanel.style.display="none";
    objButton.innerHTML="+ prikaži opis";
  }
  else
  {
    objPanel.style.display="block";
    objButton.innerHTML="- pomanjšaj opis";
  }
}
                                 
function showVideoGameStats(button,name)
{
  objPanel=document.getElementById(name);
  objButton=document.getElementById(button);
  if(objPanel.style.display=="none")
  {
    objPanel.style.display="block";
    objButton.innerHTML='&#171; skrij statistiko tekme <img style="vertical-align:middle" src="/images/gameStats.gif">'
  }
  else
  {
    objPanel.style.display="none";
    objButton.innerHTML='&#187; prikaži statistiko tekme <img style="vertical-align:middle" src="/images/gameStats2.gif">';
  }
}

function TrimAll(sString)
{                     
  while (sString.substring(0,1) == ' ')
  {
  sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
  sString = sString.substring(0,sString.length-1);
  }
  return sString;     
}


function checkLadderFields(form, nCount)
{
  if(TrimAll(form.fldLadderName.value).length<1) 
  { 
     alert("manjka obvezen podatek - Ime lestvice!"); 
     form.fldLadderName.select();
     form.fldLadderName.focus();
     return false; 
  } 
  if(TrimAll(form.fldLadderName.value).length<5) 
  { 
     alert("Ime lestvice naj vsebuje vsaj 5 znakov"); 
     form.fldLadderName.select();
     form.fldLadderName.focus();
     return false; 
  } 
  bOk = false;
  for(i=1;i<=nCount;i++)
  {
    if(document.getElementById('league_'+i).value>0)
    {
      bOk = true;
      break;
    }
  }
  if(!bOk)
  {
     alert("Izbrati je potrebno vsaj 1 ligo!"); 
     return false; 
  }
  
}

function showUserGraph(panelID, id, lid, bc, w, h, c1, c2, cp1, cp2, gt)
{
   bShow = true;
   if (document.getElementById('panelGraph_'+panelID).style.display=="block")
     bShow = false;
     
   for (i=0;i<=50;i++)
   {
     pElement = document.getElementById('panelGraph_'+i);
     if (gt == '')
     {
       if (pElement != null)
          pElement.style.display="none";
       else
         break;
     }  
     else
       if (pElement != null)
          pElement.style.display="none";
   }
   
   if (bShow)
   {
     document.getElementById('panelGraph_'+panelID).style.display="block";
     
     if (gt != '')
       gt = '&gt='+gt;
     else
       gt = '';
     
     document.getElementById('panelGraphImg_'+panelID).src = '/ajaxGraphLeague.php?id='+id+'&lid='+lid+'&bc='+bc+'&w='+w+'&h='+h+'&c1='+c1+'&c2='+c2+'&cp1='+cp1+'&cp2='+cp2+gt;
   }
   
}



function ltrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function trim(str, chars) {
  return ltrim(rtrim(str, chars), chars);
}

