var X;
var Y;
  
l = document.layers ? 1 : 0;
var opera = navigator.userAgent.indexOf('Opera') > 0;
var konky = navigator.userAgent.indexOf('Konqueror') > 0;

var ult_L1 = 0;
var ult_L2 = 0;
var ult_L3 = 0;
var ult_X1 = 0;
var ult_X2 = 0;

var ample = 640;
var altura = 400;

var oldcolor = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

function setlinia(linia) {
    
    if (typeof(linia.style) == 'undefined' || typeof(linia.cells) == 'undefined') {
        return false;
    }
    
    var celles = linia.cells.length;

    for (var c = 0; c < celles; c++) {
        oldcolor[c] = linia.cells[c].bgColor;
        linia.cells[c].bgColor = '#ccdccc';
    }

    return true;
}

function resetlinia(linia) {

    if (typeof(linia.style) == 'undefined' || typeof(linia.cells) == 'undefined') {
        return false;
    }
    
    var celles = linia.cells.length;

    for (var c = 0; c < celles; c++) {
        linia.cells[c].bgColor = oldcolor[c];
    }

    return true;
}

function getwindowsize() {
   
   if (window.outerWidth) {
      
      ample = window.outerWidth;
      altura = window.outerHeight;
   
   } else {
   
      ample = document.body.clientWidth;
      altura = document.body.clientHeight;
   
   }
   
   return;

   /*
   if (document.body.clientWidth) {
      ample = document.body.clientWidth;
      altura = document.body.clientHeight;
   } else {
      ample = window.outerWidth;
      altura = window.outerHeight;
   }
   return;
   */
}

function pop(ev, nota, tipus, amplada, fokus) {
   
   if (! amplada) amplada = 200;
   
   getwindowsize();
   
   if (ev.pageY) {
     
      X = ev.pageX;
      Y = ev.pageY;
      
   } else { 
   
      X = ev.clientX;
      Y = ev.clientY;
      
      if (! opera && ! l && ! konky) {
         if (document.body.scrollTop) Y += document.body.scrollTop;
         if (document.body.scrollLeft) X += document.body.scrollLeft;
      }
   }

   if (tipus == 0) {   
      Y = Y + 5;
      X = (X - amplada) + 10 ;
      if (X < 0) X = 0;
      ult_X1 = X;
      if (ult_L1) amaga(ult_L1, 0);
      if (ult_L2) amaga(ult_L2, 0);
      if (ult_L3) amaga(ult_L3, 0);
      ult_L1 = nota;
   }else if (tipus == 1) {   
      Y = Y + 10;
      X = X - (amplada / 2)
      if (X < 0) X = 0;
      ult_X1 = X;
      if (ult_L1) amaga(ult_L1, 0);
      if (ult_L2) amaga(ult_L2, 0);
      if (ult_L3) amaga(ult_L3, 0);
      ult_L1 = nota;
   }else if (tipus == 2) {
      Y = Y - 5;
      X = ult_X1 + 80;
      if (X < 0) X = 0;
      ult_X2 = X;
      if (ult_L2) amaga(ult_L2, 0);
      if (ult_L3) amaga(ult_L3, 0);
      ult_L2 = nota;
   }else{
      Y = Y - 5;
      X = ult_X2 + 50;
      if (X < 0) X = 0;
      if (ult_L3) amaga(ult_L3, 0);
      ult_L3 = nota;
   }
      
   /*
   if (ver >= 4 || opera){
      if (nav || opera){
         if (ver >= 5 || opera){
            document.getElementById(nota).style.left = X;
            document.getElementById(nota).style.top = Y;
            document.getElementById(nota).style.visibility = "visible";
            if (fokus) {
               document.js_anar.anar.focus();
            }
         }else{
            amaga(nota, tipus);
            document.eval(nota).left = X;
            document.eval(nota).top = Y;
            document.eval(nota).visibility = "show";
            if (fokus) {
              document.eval(nota).document.js_anar.anar.focus();
            }
         }   
      }else{
         eval(nota).style.width = amplada;   // a fix for IE4?
         eval(nota).style.pixelLeft = X;
         eval(nota).style.pixelTop = Y;
         eval(nota).style.visibility = "visible";
         if (fokus) {
            document.js_anar.anar.focus();
         }
      }
   }
   */
   
   sX(nota, X);
   sY(nota, Y);
   sE(nota);


   if (fokus) {
      if (document.js_anar.anar) {
         document.js_anar.anar.focus();
      } else {
         document.eval(nota).document.js_anar.anar.focus();
      }
   }

   return true;

}

function mostrar_nota() { return void(0); }
function tancar_nota() { return void(0); }

function amaga(nota, tipus){
   if (tipus == 1) {   
      if (ult_L2) amaga(ult_L2, 0);
      if (ult_L3) amaga(ult_L3, 0);
   } else if (tipus == 2) {
      if (ult_L3) amaga(ult_L3, 0);
   }
   
   hE(nota);
   /*
   if (ver >= 4 || opera){
      if (nav || opera){
         if (ver >= 5 || opera){
            document.getElementById(nota).style.left=0;
            document.getElementById(nota).style.visibility="hidden";
         }else{
            document.eval(nota).left=0;
            document.eval(nota).visibility="hide"; 
         }
      }
      else{
         eval(nota).style.pixelLeft=0;
         eval(nota).style.visibility="hidden";
      }
   }
   */
}

function wst(st) {
   if (st) {
      window.status = st;
   } else { 
      window.status = 'Tancar';
   }
   return true;
}   


function gE(e) {
   if (l) return document.layers[e];
   if (document.all) return document.all[e];
   return document.getElementById(e);
}
  
function sX(e, x) {
   e = gE(e); 
   if (l) {
      e.left = x; 
   } else { 
      e.style.left = x;
   }
}
  
function sY(e, y) {
   e = gE(e); 
   if (l) {
      e.top = y; 
   } else { 
      e.style.top = y;
   }
}

function sE(e) { 
   e = gE(e); 
   if(l) {
      e.visibility = 'show';
   } else {
      e.style.visibility='visible';
   }
}
      
function hE(e) {
   e = gE(e); 
   if (l) {
      e.visibility = 'hide';
   } else {
      e.style.visibility = 'hidden';
   }
}
  

/*
function setXY(lx, ly){
   X = parseInt(lx);
   Y = parseInt(ly);
   if (! nav && ! opera) Y = Y + el_body.scrollTop;
}

function xy_nav4(ev){
   X = ev.pageX;
   Y = ev.pageY;
}

if (nav && ver == 4){
   document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove = xy_nav4;
}
*/
