var CustomForm = {
	start: function() {
		var inputs = document.getElementsByTagName("input");
		var spanObj = Array();
		
		for(var i = 0; i < inputs.length; i++) {
			if((inputs[i].type == "checkbox" || inputs[i].type == "radio")) {
				spanObj[i] = document.createElement("span");
				spanObj[i].className = inputs[i].type;

				if(inputs[i].checked) {
					spanObj[i].className = inputs[i].type + " checked";
				}
				
				if (inputs[i].getAttribute("onclick") != null) {
					spanObj[i].setAttribute("onclick", inputs[i].getAttribute("onclick"));
				}
				
				inputs[i].parentNode.insertBefore(spanObj[i], inputs[i]);
				inputs[i].onchange = CustomForm.clear;
				spanObj[i].onmousedown = CustomForm.pushed;
				spanObj[i].onmouseup = CustomForm.check;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked) {
			this.className = element.type + " clickchk";
		} else {
			this.className = element.type + " click";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.className = element.type;
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.className = element.type + " checked";
			} else {
				this.className = element.type + " checked";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(var i = 0; i < inputs.length; i++) {
					if(inputs[i].name == group && inputs[i] != this.nextSibling) {
						inputs[i].previousSibling.className = inputs[i].type;
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var j = 0; j < inputs.length; j++) {
			if (inputs[j].previousSibling) {
				if(inputs[j].checked) {
					inputs[j].previousSibling.className = inputs[j].type + " checked";
				} else {
					inputs[j].previousSibling.className = inputs[j].type;
				}
			}
		}
	}
}
window.onload = CustomForm.start;
