﻿Spif.DOMEvents.attach(
  window,
  'load',
  function()
  {
    Verzuimbenchmark.init();        
  }
);

function checkIE6()
{
  var is_ie6 = (
	  window.external &&
    typeof window.XMLHttpRequest == "undefined"
  );    
  if (is_ie6 == true)
  {
    Spif.ClassNameAbstraction.add(document.body, ' ie6');
  }
}

var Verzuimbenchmark = 
{
  verzuimbenchmark: null,
  glasspane: null,  
  init: function()
  {
    this.verzuimbenchmark = document.getElementById('overlayVerzuimbenchmark');
    
    this.glasspane = document.getElementById('glasspane');
    if (this.verzuimbenchmark != null)
      this.appendToDocument();
  },
  appendToDocument: function()
  {
    document.body.appendChild(this.glasspane);          
    document.body.appendChild(this.verzuimbenchmark);         
  },
  selectTab: function(tabNr, el)
  {
    //el.parentNode
    for (var i = 0; i < 5; i++)
    {
      if (Spif.ClassNameAbstraction.contains(el.parentNode.childNodes[i], 'no-border'))
        Spif.ClassNameAbstraction.replace(el.parentNode.childNodes[i], 'no-border', '');       
    }
    
    if (tabNr != 0)
    {
      if (!Spif.ClassNameAbstraction.contains(el.previousSibling, 'no-border'))
        Spif.ClassNameAbstraction.add(el.previousSibling, 'no-border'); 
    }
    
    this.changeButtons(tabNr);
    
      //Spif.ClassNameAbstraction.replace(this.glasspane, 'shown', 'hidden'); 
  },
  show: function()
  {        
    if(this.verzuimbenchmark == null)
      Verzuimbenchmark.verzuimbenchmark = document.getElementById('overlayVerzuimbenchmark');
    
    if(this.glasspane == null)
      Verzuimbenchmark.glasspane = document.getElementById('glasspane');
    
    if (Spif.ClassNameAbstraction.contains(this.glasspane, 'hidden'))
      Spif.ClassNameAbstraction.replace(this.glasspane, 'hidden', 'shown'); 

    if (Spif.ClassNameAbstraction.contains(this.verzuimbenchmark, 'hidden'))
      Spif.ClassNameAbstraction.replace(this.verzuimbenchmark, 'hidden', 'shown'); 
  },
  hide: function()
  {  
    if (Spif.ClassNameAbstraction.contains(this.glasspane, 'shown'))
      Spif.ClassNameAbstraction.replace(this.glasspane, 'shown', 'hidden'); 
    if (Spif.ClassNameAbstraction.contains(this.verzuimbenchmark, 'shown'))      
    Spif.ClassNameAbstraction.replace(this.verzuimbenchmark, 'shown', 'hidden'); 
  },
  activateCheckbox: function(value, id, el)
  {
    document.getElementById(id).value = value;
    var p = el.parentNode.parentNode;
    var col = p.getElementsByTagName('img');
    
    for (var i = 0; i < col.length; i++)
    {
      col[i].src = '/images/verzuimbenchmark/checkbox-inactive.png';
    }
    el.src = '/images/verzuimbenchmark/checkbox-active.png';  
  },
  moveForward: function()
  {    
    var el = document.getElementById('tabContainer');
    
    for (var i = 0; i < 6; i++)
    {
      if (Spif.ClassNameAbstraction.contains(el.childNodes[i], '-selected'))
      {
        Spif.ClassNameAbstraction.replace(el.childNodes[i], '-selected', '-unselected');       
        Spif.ClassNameAbstraction.replace(el.childNodes[i].nextSibling, 'unselected', 'selected');    
        
        if (!Spif.ClassNameAbstraction.contains(el.childNodes[i], 'no-border'))
          Spif.ClassNameAbstraction.add(el.childNodes[i], 'no-border');
                
        if (i != 0)
        {
          if (Spif.ClassNameAbstraction.contains(el.childNodes[i].previousSibling, 'no-border'))
            Spif.ClassNameAbstraction.replace(el.childNodes[i].previousSibling, 'no-border', ''); 
        }   
        
        this.changeButtons(i+1);
        
        return;
      }  
      
    }   
  },
  moveBack: function()
  {    
    var el = document.getElementById('tabContainer');
    for (var i = 0; i < 6; i++)
    {
      if (Spif.ClassNameAbstraction.contains(el.childNodes[i], '-selected'))
      {
        Spif.ClassNameAbstraction.replace(el.childNodes[i], '-selected', '-unselected');       
        Spif.ClassNameAbstraction.replace(el.childNodes[i].previousSibling, 'unselected', 'selected');    
        
        if (i >= 2)
        {        
          if (!Spif.ClassNameAbstraction.contains(el.childNodes[i-2], 'no-border'))
            Spif.ClassNameAbstraction.add(el.childNodes[i-2], 'no-border');
        }
                
        if (i != 4)
        {
          //if (!Spif.ClassNameAbstraction.contains(el.childNodes[i].nextSibling, 'no-border'))
            //Spif.ClassNameAbstraction.replace(el.childNodes[i].nextSibling, 'no-border', ''); 
          if (Spif.ClassNameAbstraction.contains(el.childNodes[i], 'no-border'))
            Spif.ClassNameAbstraction.replace(el.childNodes[i], 'no-border', '');    
        }   
        
        this.changeButtons(i-1);
        
        return;
      }  
    }
  },
  changeButtons: function(tabNr)
  {
    var el = document.getElementById('verzuimbenchmarkControl');
    if (tabNr == 0)
    {
      if (Spif.ClassNameAbstraction.contains(el, 'controlLast'))
        Spif.ClassNameAbstraction.replace(el, 'controlSubmit', 'controlFirst');
      else if (Spif.ClassNameAbstraction.contains(el, 'controlDefault'))
        Spif.ClassNameAbstraction.replace(el, 'controlDefault', 'controlFirst');
    }
    else if (tabNr == 5)
    {      
      if (Spif.ClassNameAbstraction.contains(el, 'controlDefault'))
        Spif.ClassNameAbstraction.replace(el, 'controlDefault', 'controlLast');
      else if(Spif.ClassNameAbstraction.contains(el, 'controlFirst'))
        Spif.ClassNameAbstraction.replace(el, 'controlFirst', 'controlLast');    
    }
    else
    {
      if (Spif.ClassNameAbstraction.contains(el, 'controlLast'))
        Spif.ClassNameAbstraction.replace(el, 'controlLast', 'controlDefault');
      else if(Spif.ClassNameAbstraction.contains(el, 'controlFirst'))
        Spif.ClassNameAbstraction.replace(el, 'controlFirst', 'controlDefault');
    }
  },  
  submit: function(id)
  {
    document.getElementById(id).submit();
  },
  newSearch: function()
  {
    document.getElementById("meldingsfrequentie-school").value = "";
    document.getElementById("verzuimpercentage-school").value = "";
    return true;
  }
}


