 // global var to indicate if client is using stupid IE.
 // Il setez cand incarc firmeform.php fiind prima macheta incarcata
 ie=false;
 
 document.oncontextmenu=function()
 {
   // evt=windows.event;
    StopEvent();
 }
 
 function TabelClickLinia(id,tabel,i,idElement,detaliiPage)
 {  
    evt=window.event;
    TabelSelecteazaLinia(id,tabel,i,idElement,detaliiPage);
    //window.event.returnValue=false;
    //StopEvent();
 }
 
 
 var selectie=[];
 function TabelSelecteazaLinia(id,tabel,i,idElement,detaliiPage)
{
    if(selectie!=null)
    if(selectie[id]!=null)
    {
        if (selectie[id][1]%2==0)
             selectie[id][0].className= "liniePara";
        else selectie[id][0].className= "linieImpara";
        if(detaliiPage!="")
        {
        //ascund detalii           
        tr=document.getElementById("trdetalii"+id+"_"+selectie[id][2]);
        if (tr!=null)
        tr.style.display="none";
        //$("#trdetalii"+id+"_"+selectie[id][2]).fadeOut("slow");
        }
    }
    tabel.className="linieSelectata";
    var selectat=[];
    selectat[0]=tabel;
    selectat[1]=i;
    selectat[2]=idElement;
    selectie[id]=selectat;
    
    //afiseaza detalii
    if(detaliiPage!="")
    {
    tr=document.getElementById("trdetalii"+id+"_"+idElement);
    tr.style.display="block";
    AjaxLoad(detaliiPage,document.getElementById("detalii"+id+"_"+idElement));
    //$("#trdetalii"+id+"_"+idElement).fadeIn("slow");
    //alert(detaliiPage);
    }
}

function TabelOverLinia(id,tabel,i)
{
    if (selectie!=null)
    if (selectie[id]!=null)
    if(selectie[id][1]==i) return;
    tabel.className="linieOver";
}

function TabelOutLinia(id,tabel,i)
{
    if (selectie!=null)
    if (selectie[id]!=null)
    if(selectie[id][1]==i) return;
     if (i%2==0)
             tabel.className= "liniePara";
        else tabel.className= "linieImpara";
}


function StopEvent(pE)
{
   if (!pE)
     if (window.event)
       pE = window.event;
     else
       return;
  if (pE.cancelBubble != null)
     pE.cancelBubble = true;
  if (pE.stopPropagation)
     pE.stopPropagation();
  if (pE.preventDefault)
     pE.preventDefault();
  if (window.event)
     pE.returnValue = false;
  if (pE.cancel != null)
     pE.cancel = true;
}

/*function showForm(id,fisier)
{   
    //alert(id);
    var form=document.getElementById(id+"Form");
    var formContent=document.getElementById(id+"FormContent");
    var formBackground=document.getElementById(id+"FormBackground");
    
    
    //alert(form);
    form.style.display="block";
    formBackground.style.display="block";
    AjaxLoad(fisier,formContent);
}

function hideForm(id)
{
    var form=document.getElementById(id+"Form");
    var formBackground=document.getElementById(id+"FormBackground");
    form.style.display="none";
    formBackground.style.display="none";
} */

function sortTable(fisier, cnt)
{
    //alert(fisier);
    //alert(colNo);
    //alert(type);
    var div=document.getElementById(cnt);
    //alert (div);
    //div.innerHTML = "<p>Test</p>";
    AjaxLoad(fisier, div);
}

function refreshTable(id,fisier,cnt)
{
    id_tabel=id; // ID-ul tabelului pe care se face refresh. (character)
    var div=document.getElementById(cnt);
    AjaxLoad(fisier,div);
    //$("#"+cnt).load(fisier+"?random="+Math.random()*99999,'',refresh_completed); 
    //$("#"+cnt).load(fisier,'',refresh_completed);     
}

function refresh_completed()
{
}

rt2div="";
function refreshTable2(fisier,div)
{
    rt2div=div;  
    //Animatie  
    $("#"+div).html("<br/><br/><table align='center' class='waittable'><tr><td align='center'>Asteptati...</td></tr><tr><td align='center'><img src='images/loading2.gif'/></td></tr></table>");  
    //Incarc 
    if ($.browser.msie)
    {
        var div=document.getElementById(div);
        AjaxLoad(fisier,div);        
    }
    else
    { 
        $("#"+div).load(fisier, function(response, status, xhr) {
          if (status == "error") {
            var msg = "A aparut o eroare: ";
            $("#"+div).html(msg + xhr.status + " " + xhr.statusText);
          }
          else
          {
              //alert(response);
              document.getElementById(div).innerHTML=response;
              executeJavascript(response);
          }
        });    
    }
}

function hideRows(id)
{       
    if($('#btnShowHide'+id).html().toUpperCase().indexOf('table_colapse.png'.toUpperCase())!=-1)      
    {
        setCookie('tabel'+id,'false',30);
        if($.browser.msie)
        {
            document.getElementById('tabel'+id).style.display = 'none';
        }
        else
        {
            $('#tabel'+id).fadeOut('slow');
        }
        $('#btnShowHide'+id).html('<IMG src="images/table_expand.png" class="tabelToolbarBtn1" onmouseover="Tip(\'Afişează/Ascunde tabelul\')" onmouseout="UnTip()"/>');
    }
    else
    {
        setCookie('tabel'+id,'true');
        if($.browser.msie)
        {
            document.getElementById('tabel'+id).style.display = 'inline';
        }
        else
        {
                $('#tabel'+id).fadeIn('slow');
        }
        $('#btnShowHide'+id).html('<IMG src="images/table_colapse.png" class="tabelToolbarBtn1" onmouseover="Tip(\'Afişează/Ascunde tabelul\')" onmouseout="UnTip()"/>');
    }
}

var id_tabel=0; // ID-ul tabelului pe care se face refresh. (character) 
function paginare(id, fisier, cnt)
{
    id_tabel = id;
    if($('#btnPaginare'+id).html().toUpperCase().indexOf('paginare_enable.png'.toUpperCase())!=-1)
    {
        setCookie('tabelPaginare'+id,'true',30);        
    }
    else
    {
        setCookie('tabelPaginare'+id,'false');
    }
    jqLoad(id, fisier, cnt);
}

function jqLoad(id, fisier, cnt)
{
        if($.browser.msie)
        {
            // MS Internet Explorer
            // ajaxload
            var div=document.getElementById(cnt);
            AjaxLoad(fisier,div);
        }
        else
        {
            $('#tabel'+id).html('<tr><td><div><table style="width: 100%; height:70px; background-color: white;"><tr><td align="center"><IMG src="images/bondAnimated.gif"/></td></tr></table></div></td></tr>');
            
            // jquery (nu merge in IE)
            $('#'+cnt).load(fisier,'');  
        }    
}

function changesel(idTabel, idRow)
{
    id=idTabel+idRow; 
    if($('#'+id).attr("src").toUpperCase().indexOf('chk_off_16b.png'.toUpperCase())!=-1)
    {
        $('#'+id).attr("src", "images/chk_on_16b.png");
        lcCmd = idTabel+"_ms["+idRow+"]=true";
        eval(lcCmd);
        //alert(lcCmd);
    }
    else
    {
        $('#'+id).attr("src", "images/chk_off_16b.png");
        lcCmd = idTabel+"_ms["+idRow+"]=false";
        eval(lcCmd);
        //alert(lcCmd);
    }
}

function getSelectedRows(idTabel)
{
    var result = "";
    var id = 0;
    var data = eval(idTabel+"_ms");
    $.each(data, function(key, value) 
    {
      if (value == true)
      {
        id++;
        result+="&id"+id+"="+key;
      }
    });
    alert(result);
    return result;    
}

function test(id)
{
    alert(id);
}

