Web.Components.Boxes = function () {
	this.Objetos 	= Web.Library.Instances.create('Objects');
	this.Documents 	= Web.Components.Instances.create('Documents');
	this.str_type   = 'radio';
	this.fl_retorno = 1;
	this.counter    = 0;
	this.str_labels = 1;
	this.fl_left    = 'N';
	this.force_create = 'N';
	this.str_name     = "";
	this.obj_events   = {};
	
	this.create = function (strInput, criarEm, ID) {
		var objInput, criar, atributos, Events;
		this.setName( (this.getName() != "") ? this.getName() : ((ID == null) ? strInput : ID) );
		
		ID       = this.getName();
		objInput = this.Objetos.getObj(strInput, 'INPUT');
		criar    = (typeof objInput == 'string') ? true : false;
		criarEm  = (criarEm != null && typeof this.Objetos.getObj(criarEm) == 'object') ? this.Objetos.getObj(criarEm) : criarEm;
		criarEm  = (typeof criarEm == 'object') ? criarEm : this.Objetos.getBody();
		Events   = this.getEvents();

		if (criar || (this.getForceCreate() == 'S')) {
			objInput = this.Documents.newInput(strInput, this.getInputType(), null, null, this.getForceCreate());
			
			objInput.setAttribute('name', (this.str_type == 'radio') ? ID : ID +'[]');
			objInput.setAttribute('id', ID +'_Pos_'+ this.counter);
			objInput.setAttribute('posID',  this.counter );
			
			criarEm.appendChild(objInput);
		}
		
		if (typeof Events == 'object') {
			for (x in Events) {
				if (Events[x] == '______array' || Events[x] == '') continue;
				this.Objetos.register(objInput, Events[x][0], Events[x][1]);
			}
		}
		
		objInput['objRadio'] = this;
		
		this.setInput(objInput);
		this.setCreateAT(criarEm);
		
		if (this.counter == 0) {
			this.setInputID(ID);
			this.setObjDIV( this.Documents.newHolder() );
		}
		
		this.setCurrLabel( this.Documents.newLabel(null, {'id':this.counter,'for':objInput.id}) );
		
		this.getObjDIV().appendChild(objInput);
		criarEm.appendChild( this.getObjDIV() );
		
		if (this.getInputType() == 'radio') {
			this.Objetos.register(objInput,'click', function () {
															this['objRadio'].MarkAll(false);
															this.checked = true;
													});
					
		}
		
		this.counter++;
		
		return (this.getRetorno() == 2) ? this : objInput;
	}
	
	this.Fill = function (objArray, strName, strCriarEm) {
		for (x in objArray) {
			if (objArray[x] == '______array') continue;
			this.createN(objArray[x], strName, strCriarEm);
		}
	}
	
	this.createText = function (texto, argumentos) {
		var Obj = document.createElement("SPAN");
		Obj.innerHTML = texto;
		
		this.Objetos.setAttributes(Obj, argumentos);
		this.getCurrLabel().appendChild( Obj );
		this.getObjDIV().appendChild( this.getCurrLabel() );
		
		if (this.getFLLeft() == 'S') {
			this.getObjDIV().appendChild( this.getInput() );
		}
	}
	
	this.createN = function (qtd, strInput, criarEm) {
		var objInput, objCreate, newArray, selecionado = this.getSelected();
		objInput = this.Objetos.getObj(strInput, 'INPUT');
		criarEm  = (criarEm != null && typeof this.Objetos.getObj(criarEm) == 'object') ? this.Objetos.getObj(criarEm) : criarEm;
		
		objCreate = (criarEm != null) ? ((typeof criarEm == 'string') ? this.Objetos.findObj(criarEm) : criarEm) : "";
		objInput  = (strInput == "") ? this.getInput() : strInput;

		if (typeof qtd != 'object') {
			newArray = new Array();
			for (var i = 0; i < qtd; i++) newArray.push(i);
			
			qtd = newArray;
		}
		
		for (var i in qtd) {
			var objRadio = this.create(objInput, objCreate, strInput);

			if (typeof qtd == 'object') {
				objRadio.value = i;
				if (selecionado != null) {
					if (typeof selecionado == 'string') {
						if (objRadio.value == selecionado) {
							objRadio.checked = true;
						}
					} else {
						for (var j = 0; j < selecionado.length; j++) {
							if (objRadio.value == selecionado[j]) {
								objRadio.checked = true;
							}
						}
					}
				}
			}
			
			if (this.getLabels() == 1) {
				this.createText(qtd[i]);
			}
		}
	}
	
	this.Select = function (objArray, objObj) {
		var radios = (objObj == null) ? document.getElementsByTagName("INPUT") : objObj;
		this.MarkAll(false);
		
		for (var i = 0; i < radios.length; i++) {
			if (typeof radios[i][0] == 'object') {
				this.Select(objArray, radios[i]);
			} else {
				var Name = (this.getInputType().toLowerCase() == 'checkbox') ? this.getInputID()+'[]' : this.getInputID();
				if (radios[i].type == this.getInputType()) {
					this.SelectME(radios[i], objArray);
				}
			}
		}
	}
	
	this.SelectME = function (objObj, objArray) {
		if (typeof objArray != 'object') {
			objObj.checked = (objArray == objObj.value);
		} else {
			for (var x = 0; x < objArray.length; x++) {
				if (typeof objArray[x] == 'object') {
					this.SelectME(objObj, objArray[x]);
				} else if (objArray[x] == objObj.value) objObj.checked = true;
			}
		}
	}
	
	this.MarkAll = function (val, objObj) {
		var radios = (objObj == null) ? document.getElementsByTagName("INPUT") : objObj;
		val = (val==null) ? false : val;
		
		for (var i = 0; i < radios.length; i++) {
			if (typeof radios[i][0] == 'object') {
				this.MarkAll(val, radios[i]);
			} else {
				var Name = (this.getInputType().toLowerCase() == 'checkbox') ? this.getInputID()+'[]' : this.getInputID();
				if (radios[i].type == this.getInputType() && radios[i].name == Name) {
					radios[i].checked = val;
				}
			}
		}
	}
	
	this.setAttribute = function (argumentos) {
		var radios = document.getElementsByTagName("INPUT");
		
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].type == this.getInputType() && radios[i].name == this.getInputID()) {
				this.setAttributes(radios[i], argumentos);
			}
		}
	}
	
	this.AddEvent = function (strEvent, strFunc) {
		var radios = document.getElementsByTagName("INPUT");
		strEvent   = (strEvent == 'change') ? 'mouseup' : strEvent;
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].type == this.getInputType() && radios[i].name == this.getInputID()) {
				this.Objetos.register(radios[i], strEvent, strFunc);
			}
		}
	}
	
	this.RemoveEvent = function (strEvent, strFunc) {
		var radios = document.getElementsByTagName("INPUT");
		
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].type == this.getInputType() && radios[i].name == this.getInputID()) {
				this.Objetos.unregister(radios[i], strEvent, strFunc);
			}
		}
	}
	
	this.getRadio = function (pos) {
		var radios = document.getElementsByTagName("INPUT");
		
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].type == this.getInputType() && radios[i].name == ((this.str_type == 'radio') ? this.getInputID() : this.getInputID() +'[]')) {
				if (radios[i].getAttribute('posID') == pos) {
					return radios[i];
				}
			}
		}
		
		return false;
	}
	
	this.setAttributes = function (Obj, argumentos) {
		this.Objetos.setAttributes(Obj, argumentos);
	}
	
	this.getObjObj = function () { return this.objDiv; }
	this.setObjObj = function (valor) { this.objDiv = valor; }
	
	this.getName = function () { return this.str_name; }
	this.setName = function (valor) { this.str_name = valor; }
	
	this.getInput = function () { return this.obj_input; }
	this.setInput = function (valor) { this.obj_input = valor; }
	
	this.getText = function () { return this.str_text; }
	this.setText = function (valor) { this.str_text = valor; }
	
	this.getInputType = function () { return this.str_type; }
	this.setInputType = function (valor) { this.str_type = valor; }
	
	this.getLabels = function () { return this.str_labels; }
	this.setLabels = function (valor) { this.str_labels = valor; }
	
	this.getSelected = function () { return this.str_selected; }
	this.setSelected = function (valor) { this.str_selected = valor; }
	
	this.getInputID = function () { return this.input_id; }
	this.setInputID = function (valor) { this.input_id = valor; }
	
	this.getObjDIV = function () { return this.objDiv; }
	this.setObjDIV = function (valor) { this.objDiv = valor; }
	
	this.getFLLeft = function () { return this.fl_left; }
	this.setFLLeft = function (valor) { this.fl_left = valor; }
	
	this.getCurrLabel = function () { return this.curr_label; }
	this.setCurrLabel = function (valor) { this.curr_label = valor; }
	
	this.getCreateAT = function () { return this.create_at; }
	this.setCreateAT = function (valor) { this.create_at = valor; }

	this.getRetorno = function () { return this.fl_retorno; }
	this.setRetorno = function (valor) { this.fl_retorno = valor; }
	
	this.getEvents = function () { return this.obj_events; }
	this.setEvents = function (valor) { this.obj_events = valor; }
	
	this.getForceCreate = function () { return this.force_create; }
	this.setForceCreate = function (valor) { this.force_create = valor; }
}
