// Checkbox replacement
// http://www.terminally-incoherent.com/blog/2008/03/24/3-value-checkbox-with-jquery/
var inputs;
var checked = '/images/on.png';
var unchecked = '/images/off.png';

function replaceChecks()
{
   //get all the input fields on the funky_set inside of the funky_form
   inputs = document.getElementsByTagName('input');

   //cycle trough the input fields
   for(var i=0; i < inputs.length; i++)
   {
      //check if the input is a funky_box
      if(inputs[i].className == 'on_off')
      {
         //create a new image
         var img = document.createElement('img');

         //check if the checkbox is checked
         if(inputs[i].value == 0 )
         {
            img.src = unchecked;
            inputs[i].checked = false;
         }
         else if(inputs[i].value = 1 )
         {
            img.src = checked;
            inputs[i].checked = true;
         }
 
         //set image ID and onclick action
         img.id = 'checkImage'+i;

         //set image
         img.onclick = new Function('checkChange('+i+')');
         //place image in front of the checkbox
         inputs[i].parentNode.insertBefore(img, inputs[i]);

         //hide the checkbox
         inputs[i].style.display='none';
      }
}
}

//change the checkbox status and the replacement image
function checkChange(i) 
{
   if(inputs[i].value==0)
   {
      inputs[i].checked = true;
      inputs[i].value = 1;
      document.getElementById('checkImage'+i).src=checked;
   }
   else if(inputs[i].value==1)
   {
      inputs[i].checked = false;
      inputs[i].value = 0;
      document.getElementById('checkImage'+i).src=unchecked;
   }
}

window.onload = replaceChecks;