function enhanceCheckboxes() {
// finds every checkbox on the page
// and converts it to a graphical version
  // find all input controls:
  var els=document.getElementsByTagName("input");
  // for each input element...
  for(var i=0; i < els.length; i++) {
    if (els[i].type=='checkbox') { // its a checkbox
      // hide the original checkbox control:  
      els[i].style.display='none';
      // create the graphical alternative:
      var img = document.createElement("img");
      // initial state of graphical checkbox 
      // is the same as the original checkbox:
      var varServer = location.protocol.toLowerCase() + "//" + location.host + "/";
      if (els[i].checked) {
        img.src= varServer + "images/il/checked.gif";
        img.title="Checked";
      } else {
        img.src= varServer + "images/il/unchecked.gif";
        img.title="Unchecked";
      } 
      // assign our onclick event 
      img.onclick= toggleCheckbox;
      // insert the new, clickable image into the DOM
      // infront of the original checkbox:
       els[i].parentNode.insertBefore(img, els[i]);
       //alert(els[i].name);
       els[i].chkImage = img;
    }  
  }
}

function toggleCheckbox() {
  // graphical checkbox onclick event handler
  // toggle the checkbox state:
  var varServer = location.protocol.toLowerCase() + "//" + location.host + "/";
  if (this.title == "Checked") {
    // toggle the image and title:  
    this.src= varServer + "images/il/unchecked.gif";
    this.title="Unchecked";
    // update the hidden real checkbox to match the state of the graphical 
    // version:
    this.nextSibling.checked=false;
  } else {
    // toggle the image and title:  
    this.src= varServer + "images/il/checked.gif";
    this.title="Checked";
    // update the hidden real checkbox to match the state of the graphical 
    // version:
    this.nextSibling.checked=true;
  }
}

function addCheckBoxEvent(obj, evType, fn){
	if (obj.addEventListener){
   		obj.addEventListener(evType, fn, true);
   		return true;
 	} else if (obj.attachEvent) {
   		var r = obj.attachEvent("on"+evType, fn);
   		return r;
 	} else {
   		return false;
 	}
}

function removeCheckBoxEvent(obj, evType, fn) {
  	if (obj.removeEventListener) {
  		obj.removeEventListener(evType, fn, true);
  		return true;
  	} else if (obj.detachEvent){
  		var r = obj.detachEvent("on" + evType, fn);
  		return r;
  	} else return false;
}

addCheckBoxEvent(window, 'load', enhanceCheckboxes);
