//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '/imgsite/false2.png';
var imgTrue = '/imgsite/true2.png';
var imgBlank= '/imgsite/blank.png';
//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
    //debugger;
    //document.forms(0).style.display='none';
	replaceChecks();
	//document.forms(0).style.display='';
}

function replaceChecks() {
	
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}
            	
			

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			var x= inputs[i].onclick;
			if (x==null) 
			{img.onclick = new Function('checkChange('+i+')')} 
			else 
			{x="" + inputs[i].onclick;
			x = x.substr(23);
			var lengte = x.length-1;
			x = x.substr(0,lengte);
			if (navigator.appVersion.indexOf('MSIE')!=-1)
			{img.onclick = new Function('checkChange('+i+');' + x);}
			else
			{img.onclick = new Function('checkChange('+i+');' + x + '}');}
			}
			
			//alert(inputs[i].onclick);
			//set image 
			//img.onclick = new Function('checkChange('+i+')');
			//img.onclick = new Function('alert(\'ok\')');
			//img.onclick = new Function(x);
			
			var y = img.onclick;
			
			//img.onclick="alert('ok')";
			//place image in front of the checkbox
			if(inputs[i].disabled) {
				img.src = imgBlank;
				img.width=0;
			} else {
			}
			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].checked) {
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}

window.onload = init;