Web.Components.Forms = function () {
	this.Masking    = Web.Components.Instances.create('Forms.Masking');
	this.Elements   = Web.Components.Instances.create('Forms.Elements');
	this.Validation = Web.Components.Instances.create('Forms.Validation');

	this.Validation['Messages']					= Web.Components.Instances.create('Forms.Validation.Messages');
	this.Validation['Messages']['classForms']	= this;
	this.Masking['classForms']	  = this;
	this.Elements['classForms']	  = this;
	this.Validation['classForms'] = this;

	this.Objetos 	= Web.Library.Instances.create('Objects');
	this.Documents 	= Web.Components.Instances.create('Documents');

	this.Faces      = new Object();
	this.currItem   = '';
	this.toCompare  = '';
	this.serverMethods = new Object();
	this.clientMethods = new Object();

	this.start = function () {
		var objFormValidation = this;
		this.Objetos.addLoadEvent( function () {
										objFormValidation.startMethod();
								   } );
	};

	this.startMethod = function () {
		var Focado         = false;
		var listMethods    = null;
		var strFormIDError = this.Validation.Messages.getMessage("notIdentified");

		for (var i = 0; i < document.forms.length; i++) {
			if (document.forms[i].id == "") {
				document.body.innerHTML = '';
				printError( strFormIDError );

				return false;
			}

			document.forms[i]['classForms'] = new Web.Components.Forms();
			
			with (document.forms[i]) {
				classForms.setForm(document.forms[i]);

				for (var j = 0; j < elements.length; j++) {
					if (!Focado && getAttribute('Focus') == 'true' && elements[j].style.display != 'none' && elements[j].type != 'hidden' && elements[j].name != undefined) {
						elements[j].focus();
						Focado = true;
					}
					
					if (elements[j].getAttribute('runOnServer') != null) {
						listMethods = elements[j].getAttribute('runOnServer').toString().split(";");

						classForms.serverMethods[ elements[j].name ] = new Object();
						classForms.serverMethods[ elements[j].name ]['listMethods']   = new Object();
						classForms.serverMethods[ elements[j].name ]['ajax']          = new Object();
						classForms.serverMethods[ elements[j].name ]['methodResults'] = new Object();

						for (var k = 0; k < listMethods.length; k++ ) {
							if (listMethods[k] == "") continue;

							classForms.serverMethods[ elements[j].name ]['listMethods'][k] = new Object();
							classForms.serverMethods[ elements[j].name ]['listMethods'][k]['method'] = listMethods[k].split(":")[0].trim();
							classForms.serverMethods[ elements[j].name ]['methodResults'][ listMethods[k].split(".")[1].trim() ] = new Object();

							if (k > 0)
								classForms.serverMethods[ elements[j].name ]['methodResults'][ listMethods[k].split(".")[1].trim() ]['result'] = false;
						}

						classForms.serverBuildMessages(elements[j]);
					}

					if (elements[j].getAttribute('runOnClient') != null) {
						listMethods = elements[j].getAttribute('runOnClient').toString().split(";");

						classForms.clientMethods[ elements[j].name ] = new Object();
						classForms.clientMethods[ elements[j].name ]['listMethods']   = new Object();
						classForms.clientMethods[ elements[j].name ]['client']        = new Object();
						classForms.clientMethods[ elements[j].name ]['methodResults'] = new Object();

						for (var k = 0; k < listMethods.length; k++ ) {
							if (listMethods[k] == "") continue;

							classForms.clientMethods[ elements[j].name ]['listMethods'][k] = new Object();
							classForms.clientMethods[ elements[j].name ]['listMethods'][k]['method'] = listMethods[k].split(":")[0].trim();
							classForms.clientMethods[ elements[j].name ]['methodResults'][ listMethods[k].split(".")[1].trim() ] = new Object();
							
							if (k > 0)
								classForms.clientMethods[ elements[j].name ]['methodResults'][ listMethods[k].split(".")[1].trim() ]['result'] = false;
						}

						classForms.clientBuildMessages(elements[j]);
					}
				}
			
				onsubmit = function () { return false; };
				classForms.Objetos.register(document.forms[i], 'submit', function () { 
																			if (this['classForms'].Valida(this)) this.submit();
																	 });
				
				classForms.Elements.doPostBack(document.forms[i]);
				classForms.Elements.setReset(document.forms[i]);
				classForms.Masking.setMasks(document.forms[i]);
			}
		}

		listMethods = null;
	};

	this.encodeAll = function (objForm) {
		for (var i = 0; i < objForm.elements.length; i++) {
			try {
				if ( new String(objForm.elements[i]) == 'undefined' ) continue;
				if ( objForm.elements[i].tagName.toLowerCase() == 'input' || objForm.elements[i].tagName.toLowerCase() == 'textarea' )
					objForm.elements[i].value = objForm.elements[i].value.utf8_encode();
			} catch (e) {}
		}
	};

	this.decodeAll = function (objForm) {
		for (var i = 0; i < objForm.elements.length; i++) {
			try {
				if ( new String(objForm.elements[i]) == 'undefined' ) continue;
				if ( objForm.elements[i].tagName.toLowerCase() == 'input' || objForm.elements[i].tagName.toLowerCase() == 'textarea' )
					objForm.elements[i].value = objForm.elements[i].value.utf8_decode();
			} catch (e) {}
		}
	};

	this.serverBuildMessages = function (objObj) {
		var objClass    = null;
		var listMethods = Array();
		var serverAjax  = new c_Ajax();
		var evalRes     = "";

		this.serverMethods[ objObj.name ]['result'] = null;

		listMethods = objObj.getAttribute('runOnServer').toString().split(";");
		objClass    = "var " +listMethods[0].split(".")[0].trim()+ " = { \n";
		
		for (var x in this.serverMethods[ objObj.name ]['listMethods']){
			if (this.serverMethods[ objObj.name ]['listMethods'][x] == '______array' || x == 'isArray' || x == 'objAjax') continue;
			
			with (this.serverMethods[ objObj.name ]) {
				
				objClass += listMethods[x]['method'].split(".")[1]+ " : function (resultado) { \n";
				objClass += "var objElement = classObjetos.findObj('" +objObj.form.id+ "').elements['" +objObj.name+ "'];\n";
				objClass += " if (objElement.form['classForms'].Validation.Messages.validAllServer( objElement )) { \n";
				objClass += "   objElement.form['classForms'].Validation.facesValid ('" +objObj.name+ "', resultado, true, \"" +listMethods[x]['method'].split(".")[1]+ "\"); \n";
				objClass += " }\n";
				objClass += "},\n";

				this.serverMethods[ objObj.name ]['ajax']['objAjax'] = null;
				listMethods[x]['strMethod'] = listMethods[x]['method'].split(".")[1];

				evalRes += "var objNewElem = new Object();\n";

				if (typeof objObj.length == 'undefined') {
					evalRes += "objNewElem['id']    = objObj.id;\n";
					evalRes += "objNewElem['name']  = objObj.name;\n";
					evalRes += "objNewElem['value'] = objObj.value;\n";

					if (objObj.tagName.toLowerCase() == 'textarea')
						evalRes += "objNewElem['innerHTML'] = objObj.innerHTML;\n";
				} else {
					for (var i = 0; i < objObj.length; i++) {
						evalRes += "objNewElem[" +i+ "] = new Object();\n";
						evalRes += "objNewElem[" +i+ "]['id']    = objObj.id.replace(\"[]\", \"\");\n";
						evalRes += "objNewElem[" +i+ "]['name']  = objObj.name.replace(\"[]\", \"\"); \n";
					}
				}

				evalRes += listMethods[x]['method'].split(".")[0] +"." +listMethods[x]['method'].split(".")[1]+ "(objNewElem);\n";
				evalRes += "objNewElem = null;\n\n";
			}
		}

		objClass   = objClass.substring(0, objClass.length - 2);
		objClass  += "};";
		eval(objClass);

		classForms.Objetos.register(objObj, 'blur', function () {
																	eval(evalRes.replace(/objObj/g, 'this'));
																 });
		
		this.serverMethods[ objObj.name ]['ajax']['objAjax'] = eval(listMethods[0].split(".")[0].trim());

		serverAjax._obj_temp = this.serverMethods[ objObj.name ]['ajax']['objAjax'];
		serverAjax.register("Faces/" + (listMethods[0].split(".")[0].trim()), eval(listMethods[0].split(".")[0].trim()));

		serverAjax  = null; 
		listMethods = null;
	};

	this.clientBuildMessages = function (objObj) {
		var objClass    = null;
		var listMethods = "";
		var evalRes     = "";
		var evalReturn  = "";

		this.clientMethods[ objObj.name ]['result'] = null;

		listMethods = objObj.getAttribute('runOnClient').toString().split(";");
		objClass    = "var _" +listMethods[0].split(".")[0].trim()+ " = { \n";

		for (var x in this.clientMethods[ objObj.name ]['listMethods']){
			if (this.clientMethods[ objObj.name ]['listMethods'][x] == '______array' || x == 'isArray' || x == 'objAjax') continue;

			with (this.clientMethods[ objObj.name ]) {
				objClass += listMethods[x]['method'].split(".")[1]+ " : function (resultado) { \n";
				objClass += "var objElement = classObjetos.findObj('" +objObj.form.id+ "').elements['" +objObj.name+ "']; \n";
				objClass += " if (objElement.form['classForms'].Validation.Messages.validAllServer( objElement )) { \n";
				objClass += "   objElement.form['classForms'].Validation.facesValid ('" +objObj.name+ "', resultado, false, \"" +listMethods[x]['method'].split(".")[1]+ "\"); \n";
				objClass += " }\n";
				objClass += "},\n";

				listMethods[x]['strMethod']	= listMethods[x]['method'].split(".")[1];

				evalRes	+= "evalReturn = " +listMethods[x]['method'].split(".")[0] +"." +listMethods[x]['method'].split(".")[1]+ "(this); ";
				evalRes	+= "_" +listMethods[x]['method'].split(".")[0] +"." +listMethods[x]['method'].split(".")[1]+ "(evalReturn); ";
			}
		}

		objClass  = objClass.substring(0, objClass.length - 2);
		objClass += "};";
		eval(objClass);

		classForms.Objetos.register(objObj, 'blur', function () {
																	eval(evalRes);
																 });
		
		this.clientMethods[ objObj.name ]['client']['objClass']  = eval("_" +listMethods[0].split(".")[0].trim());
		this.clientMethods[ objObj.name ]['client']['objClient'] = eval(listMethods[0].split(".")[0].trim());
		this.clientMethods[ objObj.name ]['client']['objClient']['classForms'] = objObj.form['classForms'];

		listMethods = null;
	};

	this.Valida = function (objForm) { 
		return this.Validation.Valida(objForm);
	};

	this.validaArray = function (objForm, objElements) {
		return this.Validation.validaArray(objForm, objElements);
	};

	this.getMessage = function (valor) { return this.Validation.Messages.getMessage(valor); };

	this.getForm = function () { return this.objForm; };
	this.setForm = function (value) { this.objForm = value; };
}

Web.Components.Forms.Validation = function () {
	this.Debug	   = new Array();
	this.isError   = 0;
	this.Messages  = null; 
	this.Pregs     = {
		'email'  : "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
		'url'    : "^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+\."
	};

	this.currPreg  = '';

	this.validaArray = function (theForm, objElements) {
		var objObj		      = null;
		theForm.style.display = 'none';

		for (var i = 0; i < objElements.length; i++) {
			if (objElements[i] == undefined) continue;

			objObj = objElements[i].cloneNode(true);

			if (objElements[i].type == 'select-one')
				objObj.options[ objElements[i].options.selectedIndex ].selected = true;

			theForm.appendChild( objObj );
		}
		
		return this.Valida( theForm );
	};

	this.Valida = function (objForm) {
		var contador   = 0;
		var currCall   = "";
		var resCall    = false;
		var objNewElem = new Object();
		this['classForms'].setForm(objForm);
		this['classForms'].Validation.Debug = new Array();
		
		if (this['classForms'].getForm().getAttribute('modalDiv') != null) this.Messages.setModalDiv(this['classForms'].getForm().getAttribute('modalDiv'));
		else this.Messages.setModalDiv("");

		if (this['classForms'].getForm().getAttribute('modalAux') != null) this.Messages.setModalDivAux(this['classForms'].getForm().getAttribute('modalAux'));
		else this.Messages.setModalDivAux("");

		for (var i = 0; i < this['classForms'].getForm().elements.length; i++) {
			this['classForms'].currItem	= this['classForms'].getForm().elements[i];

			if (typeof this['classForms'].currItem['classForms'] == 'undefined')
				this['classForms'].currItem['classForms'] = this['classForms'];

			if (typeof this['classForms'].currItem['blurObj'] == 'undefined')
				this['classForms'].currItem['blurObj']    = new Object();

			if (typeof this['classForms'].currItem['errors'] == 'undefined')
				this['classForms'].currItem['errors'] = new Object();
						
			if (this['classForms'].currItem.type != 'select-multiple' && this['classForms'].currItem.getAttribute("required") != null) {
				try {
					this['classForms'].currItem.value = this['classForms'].currItem.value.trim();	
				} catch (e) {}
			}
			
			if (this['classForms'].currItem.getAttribute('preg_match') != null) {
				this.currPreg = this.Pregs[this['classForms'].currItem.getAttribute('preg_match').toLowerCase()];

				if (this.currPreg != null)
					this['classForms'].currItem.setAttribute('preg', this.currPreg);
			}
			
			if (this['classForms'].currItem.getAttribute('compare') != null)
				this.toCompare = objForm.elements[this['classForms'].currItem.getAttribute('compare')];

			// validacoes
			if (this.Messages.counter <= 0) {
				this.ValidEmpty();
				this.ValidMinLength();
				this.ValidDocuments();
				this.ValidExpression();
				this.ValidCompares();
				this.isNumeric();
				this.ValidDate();
				this.ValidAge();

				if (this['classForms'].currItem.getAttribute('runOnServer') != null && this['classForms'].currItem.getAttribute('runOnServer').toString().split(".").length >1) {
					for (var x in this['classForms'].serverMethods[ this['classForms'].currItem.name ]['listMethods']) {
						with (this['classForms'].serverMethods[ this['classForms'].currItem.name ]) {
							if (listMethods[x] == '______array' || x == 'isArray') continue;

							if (listMethods[x]['strMethod'] != "") {
								if (typeof this['classForms'].currItem.length == 'undefined') {
									objNewElem['id']       = this['classForms'].currItem.id;
									objNewElem['name']     = this['classForms'].currItem.name;
									objNewElem['value']    = this['classForms'].currItem.value;

									if (this['classForms'].currItem.tagName.toLowerCase() == 'textarea')
										objNewElem['innerHTML'] = this['classForms'].currItem.innerHTML;
								} else {
									for (var i = 0; i < this['classForms'].currItem.length; i++) {
										objNewElem[i] = new Object();
										objNewElem[i]['id']    =  this['classForms'].currItem.id.replace("[]", "");
										objNewElem[i]['name']  =  this['classForms'].currItem.name.replace("[]", "");
										objNewElem[i]['value'] = (this['classForms'].currItem[i].checked || this['classForms'].currItem[i].selected || (this['classForms'].currItem[i].type != 'checkbox' && this['classForms'].currItem[i].type != 'radio' && this['classForms'].currItem.type != 'select-multiple')) ? this['classForms'].currItem[i].value : "";
									}
								}

								eval("ajax['objAjax']." +listMethods[x]['strMethod']+ "(objNewElem);");
							}
						}
					}
				}

				if (this['classForms'].currItem.getAttribute('runOnClient') != null && this['classForms'].currItem.getAttribute('runOnClient').toString().split(".").length >1) {
					for (var x in this['classForms'].clientMethods[ this['classForms'].currItem.name ]['listMethods']) {
						with (this['classForms'].clientMethods[ this['classForms'].currItem.name ]) {
							if (listMethods[x] == '______array' || x == 'isArray') continue;

							if (listMethods[x]['strMethod'] != "") {
								eval("client['objClass']." +listMethods[x]['method'].split(".")[1]+ "(client['objClient']." +listMethods[x]['strMethod']+ "(this['classForms'].currItem));");
							}
						}
					}
				}
			}

			if (this.isError > 0 && contador == 0) {
				if (this['classForms'].currItem.getAttribute('getDay') != null && typeof this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')] == 'object') {
					with (this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')]) {
						if (style.display != 'none' && this['classForms'].getForm().style.display != 'none')
							focus();
					}
				} else {
					if (this['classForms'].currItem.style.display != 'none' && this['classForms'].getForm().style.display != 'none')
						this['classForms'].currItem.focus();
				}

				contador++;
			}
		}

		this.currPreg  = null; 
		this.toCompare = null;
		objNewElem     = null;
		currCall       = null;
		resCall        = null;

		if (contador >0 && this.Messages.modal_div != '') {
			this.Messages.ShowModal();
		}
		
		if (contador >0) {
			if (this.Messages.modifica_flag) {
				this.Messages.getModificaFlag().value = '';
			}
			
			location = this.Messages.getAncora();
			return false;
		}
	
		return true;
	};

	this.ValidEmpty = function () {
		var CURRENT_VALIDATION = 1;
		var objObj			   = this['classForms'].currItem.value;

		if (this['classForms'].currItem.getAttribute('required') != null && this['classForms'].currItem.value == "") {
			this.Messages.currMSG = this.Messages.getMessage('empty');
			this.isError = 1;
			
			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this.value != \"\"";
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidEmpty();";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;			
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.ValidMinLength = function (Back) {
		var CURRENT_VALIDATION = 2;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;

		if (this['classForms'].currItem.getAttribute('minlength') != null && this['classForms'].currItem.value.length < this['classForms'].currItem.getAttribute('minlength')) {
			this.Messages.currMSG = this.Messages.getMessage('minLength');
			this.isError = 1;
			
			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this.value.length >= this.getAttribute('minlength')";
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidMinLength(true);";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.Assign('tamanho', this['classForms'].currItem.getAttribute('minlength'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;			
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.ValidDocuments = function () {
		var CURRENT_VALIDATION = 3;
		var checkDoc, strEval;

		if ( this['classForms'].currItem.value != "" && (checkDoc = this['classForms'].currItem.getAttribute('CheckDoc')) != null ) {
			strEval = "this['classForms'].currItem.value.";

			switch (checkDoc.toLowerCase()) {
				case 'cpf':
						strEval += "isCpf()";
					break;

				case 'cnpj':
						strEval += "isCNPJ()";
					break;
			}

			if (!eval(strEval)) {
				this.Messages.currMSG = this.Messages.getMessage('error');
				this.isError = 1;
				
				if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
					this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
				
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = strEval;
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidDocuments();";
				this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
				
				this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
				this.Messages.SetErrors();

				return false;
			} else {
				this.isError = 0;			
				this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

				return true;
			}
		} 
	};

	this.ValidExpression = function (Back) {
		var CURRENT_VALIDATION = 4;
		var Expressao, objExp;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;	
		
		if ((Expressao = this['classForms'].currItem.getAttribute('preg')) != null) {
			objExp = new RegExp();
			objExp.compile(Expressao);
			
			this['classForms'].currItem['objExp'] = objExp;
		}
		
		if (this['classForms'].currItem.getAttribute('preg') != null && !this['classForms'].currItem['objExp'].test(this['classForms'].currItem.value)) {
			this.Messages.currMSG = this.Messages.getMessage('error');
			this.isError = 1;
			
			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this['objExp'].test(this.value)";
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidExpression(true);";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.ValidCompares = function (Back) {
		var CURRENT_VALIDATION = 5;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;

		if (this['classForms'].currItem.getAttribute('compare') != null && this['classForms'].currItem.value != this['classForms'].toCompare.value) {
			this.Messages.currMSG = this.Messages.getMessage('dontMatch');
			this.isError = 1;
			
			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this.value == this['classForms'].toCompare.value";
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidCompares(true);";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo_1', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.Assign('campo_2', this['classForms'].toCompare.getAttribute('appear'));
			this.SetErrors();

			return false;
		} else {
			this.isError = 0;
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.isNumeric = function (Back) {
		var CURRENT_VALIDATION = 6;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;

		if ((this['classForms'].currItem.getAttribute('required') != null || this['classForms'].currItem.value.length > 0) && (this['classForms'].currItem.getAttribute('numeric') != null && String(parseInt(this['classForms'].currItem.value)) == "NaN")) {
			this.Messages.currMSG = this.Messages.getMessage('invalidNumber');
			this.isError = 1;
			
			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "String(parseInt(this.value)) != \"NaN\"";
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.isNumeric(true);";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;			
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.ValidDate = function (Back) {
		var CURRENT_VALIDATION = 7;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;

		if (this['classForms'].currItem.getAttribute('CheckDate') != null) {
			var strAge = this['classForms'].currItem.value;

			if (this['classForms'].currItem.getAttribute('getDay') != null) {
				if (typeof this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')] == 'object') {
					strAge = this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')].value +'/'+ this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')].value +'/'+ this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')].value;
					
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')]['classForms'] = this['classForms'];
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')]['classForms'] = this['classForms'];
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')]['classForms'] = this['classForms'];
					
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')]['classForms']['currObj']   = this['classForms'].currItem;
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')]['classForms']['currObj'] = this['classForms'].currItem;
					this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')]['classForms']['currObj']  = this['classForms'].currItem;
					
					if (typeof this['classForms'].currItem['blurObj'][ CURRENT_VALIDATION ] == 'undefined') {
						// onchange data day
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidDate(true);
								}
							});
						
						// onchange data month
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidDate(true);
								}
							});
						
						//onchange data year
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidDate(true);
								}
							});

						this['classForms'].currItem['blurObj'][ CURRENT_VALIDATION ] = true;
					}
				}
			}

			this['classForms'].currItem.value = strAge;
			
			if (!this['classForms'].currItem.value.isDate()) {
				this.Messages.currMSG = this.Messages.getMessage('invDate');
				this.isError = 1;
				
				if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
					this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
				
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this.value.isDate()";
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidDate(true);";
				this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
				
				this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
				this.Messages.SetErrors();

				return false;
			} else {
				this.isError = 0;
				this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

				return true;
			}
		}
	};

	this.ValidAge = function (Back) {
		var CURRENT_VALIDATION = 8;

		if (Back != null) this.isError = 0;
		if (this.isError >0) return false;

		if (this['classForms'].currItem.getAttribute('CheckAge') != null) {
			var strAge = this['classForms'].currItem.value;

			if (this['classForms'].currItem.getAttribute('getDay') != null) {
				if (typeof this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')] == 'object') {
					strAge = this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')].value +'/'+ this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')].value +'/'+ this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')].value;
					
					this['classForms'].getForm().elements[this.currItem.getAttribute('getDay')]['classForms']   = this;
					this['classForms'].getForm().elements[this.currItem.getAttribute('getMonth')]['classForms'] = this;
					this['classForms'].getForm().elements[this.currItem.getAttribute('getYear')]['classForms']  = this;
					
					this['classForms'].getForm().elements[this.currItem.getAttribute('getDay')]['classForms']['currObj']   = this.currItem;
					this['classForms'].getForm().elements[this.currItem.getAttribute('getMonth')]['classForms']['currObj'] = this.currItem;
					this['classForms'].getForm().elements[this.currItem.getAttribute('getYear')]['classForms']['currObj']  = this.currItem;
					
					if (typeof this['classForms'].currItem['blurObj'][ CURRENT_VALIDATION ] == 'undefined') {
						// onchange data day
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidAge(true);
								}
							});
						
						// onchange data month
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getMonth')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidAge(true);
								}
							});
						
						// onchange data year
						this['classForms'].Objetos.register(this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getYear')], 'change', function () {
								this['classForms']['currObj'].value = this['form'].elements[this['classForms']['currObj'].getAttribute('getDay')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getMonth')].value +'/'+ this['form'].elements[this['classForms']['currObj'].getAttribute('getYear')].value;

								if (this['classForms']['currObj'].value.validAge(this['classForms']['currObj'].getAttribute('CheckAge'))) {
									this['classForms'].Validation.Messages.RemoveMessage(this.parentNode, this['classForms']['currObj']);
								} else {
									this['classForms']['currItem'] = this['classForms']['currObj'];
									this['classForms'].Validation.ValidAge(true);
								}
							});
						
						this.currItem['blurObj'][ CURRENT_VALIDATION ] = true;
					}
				}
			}
			
			this.value = strAge;
			
			if (!this['classForms'].currItem.value.validAge(this['classForms'].currItem.getAttribute('CheckAge'))) {
				this.Messages.currMSG = this.Messages.getMessage('invAge');
				this.isError = 1;
				
				if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
					this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
				
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = "this.value.validAge(this.getAttribute('CheckAge'))";
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.ValidAge(true);";
				this['classForms'].currItem['currValid'] = CURRENT_VALIDATION; // validando idade;
				
				this.Messages.Assign('anos', this['classForms'].currItem.getAttribute('CheckAge'));
				this.Messages.SetErrors();

				return false;
			} else {
				this.isError = 0;
				this['classForms'].currItem['currValid'] = 1; // volta para a primeira validação;
				this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

				return true;
			}
		}
	};

	this.serverValid = function (itemName, condition, mensagem) {
		var CURRENT_VALIDATION      = 9;

		this['classForms'].currItem = this.classForms.getForm().elements[itemName];
		condition					= condition.replace(/this/g, "this['classForms'].currItem");

		if (typeof this['classForms'].currItem['blurObj'] != 'object')
			this['classForms'].currItem['blurObj'] = new Object();

		this['classForms'].currItem['classForms']  = this['classForms'];

		if (!(eval(condition))) {
			this.Messages.currMSG = mensagem;
			this.isError = 1;

			if (typeof this['classForms'].currItem['errors'] == 'undefined')
				this['classForms'].currItem['errors'] = new Object();

			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']   = condition;
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']  = "this['classForms'].Validation.serverValid('"+itemName+"', \""+condition.replace(/this\['classForms'\]\.currItem/g, 'this').replace(/\"/g, "\\\"")+"\", '"+mensagem+"');";
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			return true;
		}
	};

	this.facesValid = function (itemName, resultado, OnServer, strMethod) {
		var CURRENT_VALIDATION      = 10;

		this['classForms'].currItem = this.classForms.getForm().elements[itemName];

		if (typeof this['classForms'].currItem['blurObj'] != 'object')
			this['classForms'].currItem['blurObj'] = new Object();

		if (OnServer)
			this['classForms'].serverMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['resultado'] = resultado;
		else
			this['classForms'].clientMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['resultado'] = resultado;

		this['classForms'].currItem['classForms']  = this['classForms'];

		if (resultado != "") {
			this.Messages.currMSG = resultado;
			this.isError = 1;

			if (typeof this['classForms'].currItem['errors'] == 'undefined')
				this['classForms'].currItem['errors'] = new Object();

			if (typeof this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] == 'undefined')
				this['classForms'].currItem['errors'][ CURRENT_VALIDATION ] = new Object();
			
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currRes']    = undefined;
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['currCall']   = undefined;
			this['classForms'].currItem['errors'][ CURRENT_VALIDATION ]['facesValid'] = true;
			this['classForms'].currItem['currValid'] = CURRENT_VALIDATION;
			
			if (OnServer)
				this['classForms'].serverMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['result'] = false;
			else
				this['classForms'].clientMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['result'] = false;
			
			this.Messages.Assign('campo', this['classForms'].currItem.getAttribute('appear'));
			this.Messages.SetErrors();

			return false;
		} else {
			this.isError = 0;
			this.Messages.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);

			if (OnServer)
				this['classForms'].serverMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['result'] = true;
			else
				this['classForms'].clientMethods[ this['classForms'].currItem.name ]['methodResults'][ strMethod ]['result'] = true;

			return true;
		}
	};
}

Web.Components.Forms.Validation.Messages = function () {
	this.currMSG       = '';
	this.modal_div     = '';
	this.modal_div_aux = '';
	this.ancora		   = '';
	this.modifica_flag = '';
	this.counter       = 0;
	this.flShowModal   = false;
	this.IDLang		   = IDLang;
	this.langXml       = new DomXml( XML_HOME + "forms.xml");
	this.AppendMessage = function () {
		var Texto;
		Texto = (typeof this['classForms'].currItem['objTexto'] == 'object') ? this['classForms'].currItem['objTexto'] : document.createElement("DIV");
		Texto.id 		  = '_bloco_'+this['classForms'].currItem.name;
		Texto.style.font  = 'bold 7pt Arial';
		Texto.style.color = 'red';
		
		Texto.innerHTML   = this.currMSG;

		this['classForms'].currItem.parentNode.appendChild(Texto);
		this['classForms'].currItem['objTexto'] = Texto;

		if (classObjetos.findObj('errorPageMain')) {
			document.body.innerHTML = document.getElementById('errorPageMain').innerHTML;
			document.title += " - Error Page";
		}

		Texto = null;
	};

	this.RemoveMessage = function (objItem, objInput) {
		var ID    = '_bloco_'+objInput.name;
		var PItem = objItem.parentNode;
		var Items = objItem.getElementsByTagName("DIV");
		var Item  = "";

		if (!this.validFieldAllErrors()) return false;
		
		for (var i = 0; i < Items.length; i++) {
			if (Items[i].id == ID) {
				Item = Items[i];
			}
		}
		
		if (typeof Item == 'object') {
			objItem.removeChild(Item);
		}

		PItem = null;
		Items = null;
	};

	this.SetErrors = function () {
		if (this.modal_div != '') {
			this['classForms'].Validation.Debug[this['classForms'].Validation.Debug.length] = this.currMSG;
		} else {
			this.AppendMessage();

			if (this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['facesValid'] != true) {
				if (typeof this['classForms'].currItem['blurObj'][ this['classForms'].currItem['currValid'] ] == 'undefined') {
					this['classForms'].Objetos.register(this['classForms'].currItem, 'blur', function (evt) {
																												this['classForms'].currItem = this;
																												this['classForms'].Validation.Messages.SetErrors_OnBlur(evt);
																											});

					this['classForms'].currItem['blurObj'][ this['classForms'].currItem['currValid'] ] = true;
				}
			}
		}
	};

	this.SetErrors_OnBlur = function (evt) {
		evt = evt || window.event;
		evt = evt.keyCode;
		
		if (typeof this['classForms'].currItem['currValid'] == 'undefined') return false;
		if (typeof this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['currRes'] == 'undefined') return false;

		// digo que o "this" é o item atual
		this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['currRes'] = this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['currRes'].replace(/this/g, "this['classForms'].currItem").replace(/this\['classForms'\]\.currItem\.this\['classForms'\]\.currItem/g, "this['classForms'].currItem");

		// digo que por default a entrada está incorreta
		this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ][ 'validReturn' ] = false;

		if (eval(this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['currRes'])) {
			this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ][ 'validReturn' ] = true;	
			
			this.RemoveMessage(this['classForms'].currItem.parentNode, this['classForms'].currItem);
		} else {
			if (this['classForms'].currItem.getAttribute('getDay') != null && typeof this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')] == 'object') {
				this['classForms'].getForm().elements[this['classForms'].currItem.getAttribute('getDay')].focus();
			} else if (this['classForms'].Validation.counter <= 0 && evt != 9 && evt != 0) {
				this['classForms'].currItem.focus();
			}

			eval(this['classForms'].currItem['errors'][ this['classForms'].currItem['currValid'] ]['currCall']);
		}
	};

	this.validFieldAllErrors = function () {
		for (var i in this['classForms'].currItem['errors']) {
			if (this['classForms'].currItem['errors'][i] == '______array' || i == 'isArray') continue;
			
			if (this['classForms'].currItem['errors'][i]['facesValid']) return true;
			if (!eval(this['classForms'].currItem['errors'][i][ 'currRes' ].replace(/this/g, "this['classForms'].currItem"))) {
				eval(this['classForms'].currItem['errors'][i]['currCall']);

				return false;
			}
		}

		return true;
	};

	// vai pegar todos os methods e ver o atual, ver o resultado e ou parar nele até ser true e executar os outros
	// repensar nisso, servirá, futuramente, para a execução de 2 ou mais métodos no runOnServer e no runOnClient
	this.validAllServer = function (objElement) {
		/*var objMethods = objElement.classForms.clientMethods[ objElement.name ]['methodResults'];
		var flReturn   = false;

		for (x in objMethods){
			if (objMethods[x]['result'] != true && typeof objMethods[x]['result'] == 'undefined') {
				flReturn = true;
				break;
			} else if (flReturn && objMethods[x]['result'] == false) {
				flReturn = false;
				break;
			}
		} */

		return true; //this['classForms'].Validation.isError == 0;
	};
	// if (validAllServer()) { validFaces(); }

	this.ShowModal = function () {
	var txterror = "";
		if (this.modal_div == "") return false;
		this.getModalDiv().style.display = 'block';

		if (this.modal_div_aux) {
			this.getModalDivAux().style.display    = 'block';
			this.getModalDivAux().style.visibility = 'visible';
		} 

		txterror += "<ul>";

		for (x in this['classForms'].Validation.Debug) {
			if (this['classForms'].Validation.Debug[x] == "______array" || x == 'isArray' || typeof this['classForms'].Validation.Debug[x] == 'object' || typeof this['classForms'].Validation.Debug[x] == 'function') continue;
			txterror += "<li>" +unescape(this['classForms'].Validation.Debug[x])+ "</li>";
		}
		
		txterror += "</ul>";

		this.getModalDiv().innerHTML = txterror;

		this['classForms'].Validation.Debug = Array();
		txterror = null;
	};
	
	this.Assign = function (texto,strReplace) {
		strReplace   = (strReplace != null && strReplace != "") ? strReplace : (this['classForms'].currItem.name.substring(0,1).toUpperCase() + this['classForms'].currItem.name.substring(1).toLowerCase());
		texto 	     = "{%"+texto+"}";
		
		this.currMSG = this.currMSG.replace(texto,strReplace);
		
		return this.currMSG;
	};

	this.getMessage  = function (value) { return this.langXml.selectSingleNodeAsString("//language[@id_idioma='" +this.IDLang+ "']/" +value); }
	
	this.getModalDiv = function () { return this['classForms'].Objetos.findObj(this.modal_div); };
	this.setModalDiv = function (valor) { this.modal_div = valor; };
	
	this.getModalDivAux = function () { return this['classForms'].Objetos.findObj(this.modal_div_aux); };
	this.setModalDivAux = function (value) { this.modal_div_aux = value; };
				
	this.getAncora = function () { return (this.ancora != "") ? this.ancora : 'javascript:;'; };
	this.setAncora = function (value) { this.ancora = value; };

	this.getModificaFlag = function () { return this['classForms'].getForm().elements[this.modifica_flag]; };
	this.setModificaFlag = function (value) { this.modifica_flag = value; };
}

Web.Components.Forms.Masking = function() {
	this.MaskME = function (Obj, evt, strMask) {
		evt = evt || window.event;
		evt = evt.keyCode;
		
		if (evt != 0 && evt != 8 && evt != 9 && evt != 46 && evt != 37 && evt != 39 && evt != 36 && evt != 35) {
			if (Obj.value.length > strMask.length) {
				Obj.value = Obj.value.substring(0, strMask.length);
			}
			
			if (strMask.charAt(Obj.value.length) != 'x') {
				Obj.value += strMask.charAt(Obj.value.length);
			}
		}
	};
	
	this.setMasks = function (objForm) {
		var thisForm, Elements;
		thisForm = (objForm != null) ? objForm : this.classForms.getForm();
		Elements = thisForm.elements;

		for (var i = 0; i < Elements.length; i++) {
			Elements[i]['classForms'] = this['classForms'];

			if (Elements[i].getAttribute('mask') != null) {
				Elements[i].classForms.Objetos.register(Elements[i], 'keydown', function (evt) {
																							this.classForms.Masking.MaskME(this, evt, this.getAttribute('mask'));
																						});
			}
			
			if (Elements[i].getAttribute('maxlength') != null) {
				Elements[i].classForms.Objetos.register(Elements[i], 'keyup', function (evt) {
																						evt = evt || window.event;
																						evt = evt.keyCode;

																						if (this.value.length == this.getAttribute('maxlength') && (evt != 0 && evt != 8 && evt != 9 && evt != 46 && evt != 37 && evt != 39 && evt != 36 && evt != 35)) {
																							if (this.classForms.Elements.nextObj(this)) {
																								this.classForms.Elements.nextObj(this).focus();
																							}
																						}
																					});
			}
		}

		thisForm = null;
		Elements = null;
	};
}

Web.Components.Forms.Elements = function () {
	this.getObjIndex = function (objForm, objObj) {
		var thisForm = (objForm != null) ? objForm : this['classForms'].getForm();

		for (var i = 0; i < thisForm.elements.length; i++) {
			if (thisForm.elements[i].name == objObj.name) {
				return i;
			}
		}

		thisForm = null;
	};
	
	this.nextObj = function (objObj) {
		var Index;
		Index = this.getObjIndex(objObj['form'], objObj)+1;
		
		while (Index <= objObj['form'].elements.length) {
			if (typeof objObj['form'].elements[Index] == 'object' && objObj['form'].elements[Index].type != 'hidden') {

				return objObj['form'].elements[Index];
			}

			Index++;
		}
		
		return false;
	};
	
	this.previousObj = function (objObj) {
		var Index;
		Index = this.getObjIndex(objObj['form'], objObj);

		while (Index >= 0) {
			if (typeof objObj['form'].elements[Index] == 'object' && objObj['form'].elements[Index].type != 'hidden') {
				return objObj['form'].elements[Index];
			}

			Index--;
		}
		
		return false;
	};
	
	this.hasPost = function (objForm) {
		var thisForm = (objForm != null) ? objForm : this['classForms'].getForm();

		if (typeof thisForm != 'object' || typeof _REQUEST == 'undefined') {
			thisForm = null;

			return false;
		}
		
		if (thisForm.elements.length <= 0) {
			thisForm = null;

			return false;
		}
		
		for (var i = 0; i < thisForm.elements.length; i++) {
			if (_REQUEST[thisForm.elements[i].name] != null && _REQUEST[thisForm.elements[i].name] != undefined) {
				thisForm = null;

				return true;
			}
		}

		thisForm = null;
		
		return false;
	};
	
	this.doPostBack = function (objForm) {
		var thisForm, objObj, Nome;
		thisForm  = (objForm != null) ? objForm : this['classForms'].getForm();

		if (this.hasPost(thisForm)) {
			for (var i = 0; i < thisForm.elements.length; i++) {
				Nome = thisForm.elements[i].name;

				if (Nome) Nome = Nome.replace(/\[\]/g,'');
				if (typeof _REQUEST[Nome] == 'undefined') continue;

				switch (thisForm.elements[i].type) {
					case 'text':
							eval("var __"+Nome+" = Web.Components.Instances.create('Inputs');");
							objObj = eval("__"+Nome);
							
							objObj.setObjObj(thisForm.elements[i]);
							objObj.setAttributes({'value':_REQUEST[Nome]});
						break;
					
					case 'password':
							eval("var __"+Nome+" = Web.Components.Instances.create('Inputs');");
							objObj = eval("__"+Nome);
							
							objObj.setObjObj(thisForm.elements[i]);
							objObj.setAttributes({'value':''});
						break;
						
					case 'checkbox':
					case 'radio':
							eval("var __"+Nome+" = Web.Components.Instances.create('Boxes');");
							objObj = eval("__"+Nome);

							objObj.setInputType(thisForm.elements[i].type.toLowerCase());
							objObj.setInputID(Nome);
							objObj.setObjObj(thisForm.elements[i]);
							objObj.Select(_REQUEST[Nome]);
						break;
						
					case 'select-one':
					case 'select-multiple':
							eval("var __"+Nome+" = Web.Components.Instances.create('Selects');");
							objObj = eval("__"+Nome);

							objObj.setObjObj(thisForm.elements[i]);
							objObj.Select(_REQUEST[Nome]);
						break;
				}
			}
		}

		thisForm = null;
		objObj   = null;
	};
	
	this.setReset = function (objForm) { 
		var thisForm = (objForm != null) ? objForm : this['classForms'].getForm();

		for (var i = 0; i < thisForm.elements.length; i++) {
			if (thisForm.elements[i].type == 'reset') {
				thisForm.elements[i]['classForms'] = this['classForms'];

				if (this.hasPost(thisForm)) {
					thisForm.elements[i].onclick   = function () { return false; }
					this['classForms'].Objetos.register(thisForm.elements[i], 'click', function () { this['classForms'].Elements.doPostBack(this.form); return false; });
				}
			}
		}

		thisForm = null;
	};
}
