window.onload = init;
var d=document;
function init() {
	so_checkCanCreate();
	}

function so_checkCanCreate() {
	testImage = d.body.appendChild(d.createElement("img"));
	testImage.src = "images/blank.gif?" + new Date().valueOf();
	testImage.id = "so_testImage";
	testImage.onload = so_createCustomCheckBoxes;
}

function so_createCustomCheckBoxes() {
		if(!d.getElementById)return;
		d.body.removeChild(d.getElementById("so_testImage"));
		events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");
		frm = d.getElementsByTagName("form");
		for(i=0;i<frm.length;i++) {
			c = frm[i].elements;
			for(j=0;j<c.length;j++) {
			if(c[j].getAttribute("type") == "checkbox") {
					c[j].style.position = "absolute";
				c[j].style.left = "-9000px";
					n = d.createElement("img");
				n.setAttribute("class","chk");
				if(c[j].checked == false) {
					n.setAttribute("src","images/chk_off.gif");
					n.setAttribute("title","click here to select this option.");
					n.setAttribute("alt","click here to select this option.");
				} else {
					n.setAttribute("src","images/chk_on.gif");
					n.setAttribute("title","click here to deselect this option.");
					n.setAttribute("alt","click here to deselect this option.");
				}			
				n.xid = c[j].getAttribute("name");
					n.frmIndex = i;
					n.onclick = function() { so_toggleCheckBox(this,0);return false; }
					c[j].parentNode.insertBefore(n,c[j].nextSibling)
					c[j].objRef = n;
		
				for(e=0;e<events.length;e++) if(eval('c[j].' +events[e])) eval('n.' + events[e] + '= c[j].' + events[e]);
				fn = c[j].onchange;
				if(typeof(fn) == "function") {
					c[j].onchange = function() { fn(); so_toggleCheckBox(this.objRef,1); return false; }
				} else {
					c[j].onchange = function () { so_toggleCheckBox(this.objRef,1); return false; }
				}
			}
		}
	}
}

function so_toggleCheckBox(imgObj,caller) {
	formObj = d.forms[imgObj.frmIndex];
	objName = imgObj.xid;
		if(!caller)formObj.elements[objName].checked = !formObj.elements[objName].checked?true:false;
	if(imgObj.src.indexOf("images/chk_on.gif")>-1) {
		imgObj.setAttribute("src","images/chk_off.gif");
		imgObj.setAttribute("title","click here to select this option.");
		imgObj.setAttribute("alt","click here to select this option.");
	} else {
		imgObj.setAttribute("src","images/chk_on.gif");
		imgObj.setAttribute("title","click here to deselect this option.");
		imgObj.setAttribute("alt","click here to deselect this option.");
	}
}