var inputs;
var tempX = 0
var tempY = 0
var absposy = 0;//  document.getElementById('top').offsetHeight;
var absposx = 0;
var actual_pct=0;
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;



function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
    
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
 
  if (e)
  { 
    if (e.pageX || e.pageY)
    {
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    {
      mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }
  }
  if(actual_pct != "0"){
    ds = fd(actual_pct,1);
    tv = mousey + 20 - absposy; lv = mousex - 15 - absposx;
    lv += 'px';tv += 'px'; 
    ds.left = lv; ds.top = tv;
  }
    
}
var DH = 0;var an = 0;var al = 0;var ai = 0;

if (document.getElementById) {ai = 1; DH = 1;}
else {
  if (document.all) {al = 1; DH = 1;} 
  else { browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} 


function init() {
    replaceChecks();
  
}

function fd(oi, wS) 
  {if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi);
   if (al) return wS ? document.all[oi].style: document.all[oi]; 
   if (an) return document.layers[oi];
  }

function pw() {

return window.innerWidth != null ? window.innerWidth : document.body.clientWidth != null? document.body.clientWidth:null;}

function popUp(oi) {
  if (DH){
    //Hide old
    ds = fd(oi,1);
    st = ds.display;
    
    if (st == "block" || st == "line") { 
        
        ds.display = "none"; 
        actual_pct = 0;
    } 
    else{
        ds.left = "-1000px";
        ds.top = "-1000px";
        ds.display = "block";
        actual_pct = oi;
      }
  }    
}



function replaceChecks() {
    

    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {


        var pct=inputs[i].id.substring(0,4);
        var picture=inputs[i].id.substring(4,6);
        var idcko = inputs[i].id.substring(6);
        if( pct == 'pct_')
        
        if(inputs[i].getAttribute('type') == 'checkbox') {
            
            //create a new image
            var img = document.createElement('img');            
            //check if the checkbox is checked
            if(picture == "1_"){
              pict = idcko+".gif";
            }else pict = "empty.gif";
             
            if(inputs[i].checked) {
                img.src = "/img/pictograms/"+pict;
            } else {
                img.src = "/img/pictograms/no_"+pict;
            }

            
            img.id = 'checkImage'+i;
            img.onclick = new Function('checkChange('+i+')');
            img.onmouseout = new Function("popUp('pctalt_"+idcko+"')"); 
            img.onmouseover = new Function("popUp('pctalt_"+idcko+"')");
            img.position= 'absolute'; 
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            inputs[i].style.display='none';
        }
    }
}


//change the checkbox status and the replacement image
function checkChange(i) {
 
    var pct=inputs[i].id.substring(0,4);
    var picture=inputs[i].id.substring(4,6);
    var idcko = inputs[i].id.substring(6);
       
    if( pct == 'pct_'){
      if(picture == "1_"){
                pict = idcko+".gif";
      }else pict = "empty.gif";
               
      if(inputs[i].checked) {
          
          inputs[i].checked = '';
          document.getElementById('checkImage'+i).src="/img/pictograms/no_"+pict;
      } else {
          inputs[i].checked = 'checked';
          document.getElementById('checkImage'+i).src="/img/pictograms/"+pict;
      }
    }
}



window.onload = init;


