// JavaScript Document

//global variables that can be used by ALL the function son this page.
var ccinputs;
//var imgFalse = './Theme/check1.gif';
//var imgTrue = './Theme/check2.gif';

var falseImages = new Array("./i/true.png ", "./i/reg-true.gif", './Theme/check1.gif', "./i/true-login.gif" );
var trueImages  = new Array("./i/false.png ", "./i/reg-false.gif", './Theme/check2.gif', "./i/false-login.gif" );

//falseImages = {" ./i/false.png "," ./i/reg-false.gif "};
//trueImages  = {" ./i/true.png "," ./i/reg-true.gif "};

if (which) {
   imgFalse = falseImages[which];
   imgTrue  = trueImages[which];
}

function cinit() {
	replaceChecks();
}

function replaceChecks() {

	//get all the input fields on the page
	cinputs = document.getElementsByTagName('input');
	
	//cycle trough the input fields
	for(var i=0; i < cinputs.length; i++) {
	
		//check if the input is a checkbox
		if(cinputs[i].getAttribute('type') == 'checkbox') {
		    var imgId = 'checkImage' + i;

		    //create a new image
		    var img = document.createElement('img');
			
		    //check if the checkbox is checked
		    if(cinputs[i].checked) {
			    img.src = imgTrue;
		    } else {
			    img.src = imgFalse;
		    }
			
		    //set image ID and onclick action
		    img.id = imgId;
			
		    //set image
		    img.onclick = new Function('checkChange('+i+')');
		    //place image in front of the checkbox
		    cinputs[i].parentNode.insertBefore(img, cinputs[i]);
			
		    //hide the checkbox
		    cinputs[i].style.display = 'none';

		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(cinputs[i].checked) {
		cinputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		cinputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}
