﻿/* Chequear dependencias */
if ( typeof Prototype == 'undefined' ) {
	alert( "Prototype no encontrado. Se debe incluir." );
}
if ( typeof fnG == 'undefined' ) {
	alert( "Archivo js fnG no encontrado. Se debe incluir." );
}
/* Chequear dependencias */
maxlimit = 500;
ExpReg = /[0-9]/ig
document.observe( "dom:loaded", 
	function() {
		/* agregar evento click a los Inputs */
		var chk = $('form1').getInputs();
		chk.each( 
			function( elem ) {
				if ( elem.id == "txtTelefono" ) {
					elem.observe( 'keypress', 
						function( event ) {
							fnG.noInputSoloNumeros( event );
						}
					);
					elem.observe( 'keyup', 
						function( event ) {
							fnG.noInputSoloNumeros( event );
						}
					);
				} else if ( elem.id == "txtNombres" || elem.id == "txtApellidos" ) {
					elem.observe( 'keypress', 
						function( event ) {
							if ( !fnG.caracteresValidos( event, ExpReg ) ) {
								Event.stop( event );
							}
						}
					);
					elem.observe( 'keyup', 
						function( event ) {
							if ( !fnG.caracteresValidos( event, ExpReg ) ) {
								Event.stop( event );
							}
						}
					);
					elem.observe( 'blur', 
						function( event ) {
							var str = elem.value;
							elem.value = str.replace( ExpReg, "" );
						}
					);
				}
			}
		);
		if ( $('txtMensaje') != null ) {
			$('txtMensaje').observe( 'keydown', 
				function( event ) {
					fnG.textCounter( $('txtMensaje'), maxlimit, fnG.alerta );
				}
			);
			$('txtMensaje').observe( 'keyup', 
				function( event ) {
					fnG.textCounter( $('txtMensaje'), maxlimit, fnG.alerta );
				}
			);
		}
	}
);

var fnPublico = {

	validoFormIdeas: function() {
		idFormulario = fnG.obtElem( 'form1' );
		with ( idFormulario ) {
			fnG.borraEspacios( idFormulario );
			if ( txtNombres.value == "" ) {
				return fnG.alerta( "Debe ingresar Nombres.", txtNombres );
			}
			if ( txtApellidos.value == "" ) {
				return fnG.alerta( "Debe ingresar Apellidos.", txtApellidos );
			}
			if ( txtDireccion.value == "" ) {
				return fnG.alerta( "Debe ingresar Calle.", txtDireccion );
			}
			if ( cmbComuna.value == 0 ) {
				return fnG.alerta( "Debe seleccionar Comuna.", cmbComuna );
			}
			if ( txtTelefono.value == "" ) {
				return fnG.alerta( "Debe ingresar Teléfono.", txtTelefono );
			}
			if ( txtEmail.value == "" ) {
				return fnG.alerta( "Debe ingresar Email.", txtEmail );
			}
			if ( !fnG.esEmail( txtEmail.value ) ) {
				return fnG.alerta( "Debe ingresar un Email válido.", txtEmail );
			}
			if ( txtMensaje.value.length == 0 ) {
				return fnG.alerta( "Debe ingresar Mensaje.", txtMensaje );
			}
		}
		return true;
	}
}
