({
	name:"HTMLInputControl",
	
	/**
	 * HTML template for inputs with types <code>file</code>
	 * @see InputFactory.customizeFile()
	 */
	FILE_TEMPLATE: "<button>Browse...</button>",
	
	/**
	 * <code>window.onload</code> event handler.
	 * @param e Event
	 */
	onload: function(e) {
		var e,i,d,w = window;
		d = w.document;
		if(w.VBArray) {
			try {
				d.execCommand("BackgroundImageCache",false,true);
			} catch (x){}
		}
		var inputs = d.getElementsByTagName("INPUT");
		for(i=0; i<inputs.length;) {
			e = inputs[i++];
			if(e.type=="checkbox" || e.type=="radio") this.customizeBoxes(e, i);
			else if(e.type == "file") this.customizeFile(e, i++); //@bug DKCMSS-2318
		}
	},
	
	/**
	 * Customizes inputs with types <code>file</code>
	 * @param input HTMLInputElement
	 * @param index int
	 * @see InputFactory.onload()
	 * @see InputFactory.FILE_TEMPLATE
	 */
	customizeFile: function(input, index) {
		input.__onchange = input.onchange;
		input.onchange = function(e){
			this.parentNode.parentNode.previousSibling.firstChild.value = this.value;
			if(this.__onchange)this.__onchange(e);
		};
		var d = document;
		var cell, row, table = d.createElement("TABLE");
		table.border = "0";
		table.cellPadding = "0";
		table.cellSpacing = "0";
		table.className = "file-container";
		cell = (row = table.insertRow(-1)).insertCell(-1);
		cell.appendChild(d.createElement("INPUT"));
		cell = row.insertCell(-1);
		cell.innerHTML = "<label>" + (this.FILE_TEMPLATE.replace("{text}",(input.title || "Browse..."))) + "</label>";
		input.parentNode.insertBefore(table, input);
		cell.firstChild.insertBefore(input, cell.firstChild.firstChild);
	},
	
	/**
	 * Customizes inputs with types <code>radio</code> and <code>checkbox</code>
	 * @param input HTMLInputElement
	 * @param index int
	 * @see InputFactory.onload()
	 */
	customizeBoxes: function(input, index){
		input.__onclick = input.onclick;
		
		input.onclick=function(e){
			var o = this;
			if (o.__onclick && (o.className == o.type)) o.__onclick(e);

			o.className = o.type;
			if(o.type=="radio" && o.checked && o._) {
				var i,inputs = o.form.elements[o.name];
				for(i=0; i<inputs.length;)
					inputs[i++].previousSibling.className = o.type + "_unchecked";
			}
			o.previousSibling.className = o.type + "_" + (o.checked ? "" : "un") + "checked";
			o.previousSibling.innerHTML = "&nbsp;";
			o._ = 1;
			return o.id || (o.id = o.type + "_" + index);
		};
		
		var d=document;
		var lab = d.createElement("LABEL")
		input.parentNode.insertBefore(lab, input);
		input.onclick();
		lab.onclick=function(){
			if(input.checked){input.checked="";input.onclick();
			}else{input.checked="checked";input.onclick();} 
		}

		//lab.htmlFor = input.onclick();		
		var label = input.previousSibling;
		
		if(input.disabled){
			label.setAttribute("disabled", "disabled");
			label.className += (input.checked) ? " " + input.type + "_checked_disabled" : " " + input.type + "_unchecked_disabled";
		}
		
		if(input.getAttribute("indeterminate")=="true"){
			input.indeterminate = true;
			label.className += " " + input.type + "_indeterminate" + ((input.disabled) ? "_disabled" : "");
		}
		
		if(window.VBArray && !input.disabled) {
			label.onmouseover = function() {
				if(this.className.indexOf("hover") == -1) {
					this._className = this.className;
					this.className += " " + this.className + "_hover";
				}
			};
			
			label.onmouseout = function() {
				if(this.className.indexOf("hover") != -1) {
					this.className = this.className.replace(" " + this._className + "_hover", "");
				}
			};
			
			label.onmousedown = function() {
				this.onmouseout();
				if(this.className.indexOf("active") == -1) {
					this._className = this.className;
					this.className += " " + this.className + "_active";
				}
			};
			
			label.onmouseup = function() {
				if(this.className.indexOf("active") != -1) {
					this.className = this.className.replace(" " + this._className + "_active", "");
				}
			};
		}
	},
	
	/**
	 * Initializing component, sets <code>onload</code> handler
	 * @see InputFactory.onload()
	 */
	init:function(){
		var n, h, w = window;
		n = this.name; 
		w[n] = this;
		h = function(e) {
			w[n].onload(e);
		};
		(w.attachEvent) ? w.attachEvent("onload", h) : w.addEventListener("load", h, false);
	}
}).init();