
var checkboxHeight = "15";
var PlatformCheckboxObj = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].type == "checkbox" && inputs[a].className.indexOf("styled") >= 0) {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].className.replace(/\s*styled\s*/,"");
				inputs[a].style.display = "none";
				span[a].style.cursor = "pointer";
				span[a].style.height = "15px";
				span[a].style.overflow = "hidden";
				span[a].style.backgroundRepeat = "no-repeat";
				span[a].style.backgroundPosition = "center 0px";
				span[a].style.display = "block";
				span[a].style.marginRight = "3px";
				span[a].style.cssFloat = "left";
				span[a].style.styleFloat = "left";
				span[a].style.backgroundImage = "url('/img/common/checkbox/platforms/" + span[a].className + ".gif')";
				if(inputs[a].checked == true) {
					position = "center -" + (checkboxHeight*2) + "px";
					span[a].style.backgroundPosition = position;
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = PlatformCheckboxObj.clear;
				span[a].onmouseup = PlatformCheckboxObj.check;
				document.onmouseup = PlatformCheckboxObj.clear;
			}
		}
	},
	check: function() {
		element = this.nextSibling;
		
		if(element.className.indexOf("all_checkbox") >= 0){
			inputs = document.getElementsByTagName("input");
			for(var b = 0; b < inputs.length; b++)
				if(inputs[b].type == "checkbox" && inputs[b].className.indexOf("styled") >= 0){
					inputs[b].checked = !(element.checked == true);
				}
		}
		else{
		    if(element.checked == true)	element.checked = false;
		    else element.checked = true;
			PlatformCheckboxObj.checkcondition();
		}	

		PlatformCheckboxObj.redraw(element);
		
		//
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++)
			if(inputs[b].type == "checkbox" && inputs[b].className.indexOf("styled") >= 0)
				PlatformCheckboxObj.redraw(inputs[b]);
		PlatformCheckboxObj.checkcondition();
	},
	redraw: function(obj){
		if(obj.checked)
			obj.previousSibling.style.backgroundPosition = "center -" + checkboxHeight*2 + "px";
		else
			obj.previousSibling.style.backgroundPosition = "center 0";
	},
	checkcondition:function(){
		inputs = document.getElementsByTagName("input");
		var allCheckbox = null;
		var IsAllCheckboxChecked = false;
		var count = 0;
		for(var b = 0; b < inputs.length; b++)
			if(inputs[b].type == "checkbox" && inputs[b].className.indexOf("styled") >= 0){
				if(inputs[b].className.indexOf("all_checkbox") >= 0){
					allCheckbox = inputs[b];
				}
				else{
					if(inputs[b].checked) count++;					
				}
			}
		if(count == 0) allCheckbox.checked = true;
		else allCheckbox.checked = false;
		PlatformCheckboxObj.redraw(allCheckbox);
	}
}
