		/* Variable del validador*/

	var valid;
	
	function buscar(url, actualizar, form)
	{	
		if (validar_sesion() ) {
		new Ajax.Updater(actualizar, url, {parameters : Form.serialize(form.id), method: 'get', encoding: 'ISO-8859-1' });
		}
	}	
	
	function ejecutar(url, actualizar)
	{
		if (validar_sesion() ) {
			new Ajax.Updater(actualizar, url, { method: 'get', encoding: 'ISO-8859-1' });
		}
	}	

	function ejecutar2(url, actualizar, form)
	{	
		if (validar_sesion() ) {
			new Ajax.Updater(actualizar, url, {parameters : Form.serialize(form.id), method: 'get',  encoding: 'ISO-8859-1' });
		}
	}	


	function ejecutar3(url, form, url2, actualizar)
	{	
		if (validar_sesion() ) {
			new Ajax.Request(url, {parameters : Form.serialize(form.id), method: 'get' ,
							onComplete: function() {
								 new Ajax.Updater(actualizar, url2, { method: 'get' });
							
						  }
					});
		}
	}	


	function grabar(result, form)
	{ 	
		if (validar_sesion() ) {
			if (result) {
				var url = form.action;
				new Ajax.Updater('main', url, {parameters : Form.serialize(form.id),  method: 'get', encoding: 'ISO-8859-1' });
				
			}
		}
	}
	
	function grabarIndex(result, form)
	{ 	
			if (result) {
				var url = form.action;
				new Ajax.Updater('main', url, {parameters : Form.serialize(form.id),  method: 'get', encoding: 'ISO-8859-1' });
				
			}
		}

	function grabar_reg(result, form)
	{ 	

			if (result) {
				var url = form.action;
				
				new Ajax.Updater('main', url, {parameters : Form.serialize(form.id),  method: 'get', encoding: 'ISO-8859-1' });
			
			}

	}


	function nuevo(tabla, idFocus, destino)
	{			
		
		if (validar_sesion() ) {
			var url = tabla + ".edit.php?id=-1";
			new Ajax.Updater(destino, url, { method: 'get', encoding: 'ISO-8859-1', 
						 				onComplete: function() {
    											try{
													document.getElementById(idFocus).select();
												} catch (e) {
													try{
														document.getElementById(idFocus).focus();
													} catch (e1) {

													}
												}
												
											  }
						 				});

		}
	}	

	function editar(tabla,id, idFocus)
	{	
		if (validar_sesion() ) {
			var url = tabla + ".edit.php?id=" + id;
			new Ajax.Updater('main', url, { method: 'get', encoding: 'ISO-8859-1', 
											onComplete: function() {
													try{
														document.getElementById(idFocus).select();
													} catch (e) {
														try{
															document.getElementById(idFocus).focus();
														} catch (e1) {
	
														}
													}
												  }
											});
		}
	}	

	function borrar(tabla,id, destino)
	{
		if (validar_sesion() ) {
			
			if ( confirm( 'Está seguro de querer eliminar el registro seleccionado?' ) ) {
				var url = tabla + ".borrar.php?id=" + id;
				new Ajax.Updater(destino, url, { method: 'get',  encoding: 'ISO-8859-1' });
			}
	
		}
	}	


	function valirdarForm(form)
	{
		if (validar_sesion() ) {
			
			valid = new Validation(form, {immediate : false, 
										  onSubmit:false, 
										  onFormValidate : grabar,
										  focusOnError: true
										  
										  
										  });
			var result = valid.validate();
		}
	}					
	
	function valirdarFormIndex(form)
		{	
	
			valid = new Validation(form, {immediate : false, 
										  onSubmit:false, 
										  onFormValidate : grabarIndex,
										  focusOnError: true
										  
										  
										  });
			var result = valid.validate();
		}

	
	function valirdarRegistracion(form)
	{	
			
		valid = new Validation(form, {immediate : false, 
							          onSubmit:false, 
									  onFormValidate : grabar_reg,
									  focusOnError: true});

	
//		if (esalta == "S") {
			
			
			Validation.add('validate-captcha', 'El código de verificación ingresado no coincide', function(v) {
								var ver_cod = document.getElementById(form).verificacionCodigo.value;
								var url = 'miembro.validar.captcha.php?verificacionCodigo=' + ver_cod;
								var valido = "0";
								new Ajax.Request(url, {
  												method: 'get',
												asynchronous:  	false,
								  onSuccess: function(transport) {	existe = transport.responseText;}
												 } );																					  									
									if (trim(existe) == "1"){
										return true ;
									}else{
     									return false;
									}
								}
							
						);
			
			Validation.add('validate-existeemail', 'El mail ingresado ya está registrado', function(v) {
								var id_usuario = document.getElementById(form).idreg.value;
								var url = 'validar_existencia.php?campo=email&id_usuario='+ id_usuario +'&valor=' + v;
								var existe = "N";
								new Ajax.Request(url, {
  												method: 'get',
												asynchronous:  	false,
								  onSuccess: function(transport) {	existe = transport.responseText;}
												 } );																					  									
									if (trim(existe) == "N"){
										return true ;
									}else{
     									return false;
									}
								}
							
						);
			
			Validation.add('validate-existeusuario', 'El usuario ingresado ya está registrado', function(v) {
					var id_usuario = document.getElementById(form).idreg.value;									  
					var url = 'validar_existencia.php?campo=usuario&id_usuario='+ id_usuario +'&valor=' + v;
					var existe = "N";
					new Ajax.Request(url, {
									method: 'get',
									asynchronous:  	false,
					  onSuccess: function(transport) {	existe = transport.responseText;}
									 } );																					  									
						if (trim(existe) == "N"){
							return true ;
						}else{
							return false;
						}
					}
				
			);

		//}

		var result = valid.validate();
	
		
	}	
	
	

	
	
	function limpiar(idForm)
	{
		

			var form = document.getElementById(idForm);
			
			for(i=0; i<form.elements.length; i++){
	
				switch (form.elements[i].type )
				{
					case "textarea":
					case "text":
						form.elements[i].value = "";
						break;
					case "checkbox":
						form.elements[i].checked = false;
						break;
	
					case "select-one":
						form.elements[i].selectedIndex = -1;
						break;
	
					}
			}
			
			
			try{
				valid.reset();
				} catch (e) {}

	}	
	

	
	function trim(str, chars) {
 	   return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	
	function procesando(target) {
		
		document.getElementById(target).innerHTML = "<img style='margin-left:20px' src='images/spinner.gif' alt='procesando' title='procesando' /> Procesando...";
			
	}

	function validar_sesion() {


		var url = 'validar_sesion.php';
					var expiro = "N";
					new Ajax.Request(url, {
									method: 'get',
									asynchronous:  	false,
					  onSuccess: function(transport) {	expiro = transport.responseText;}
									 } );																					  									
						if (trim(expiro) == "expiro"){
							alert('Su sesión ha expirado');
							document.location.href='index.php';
							return false ;
						}else{
							return true;
						}


}	


function verificar(f){ 

	  if(f.value.match(/[^a-záéíóúñÑ\ ]/)){ 

		f.value=f.value.replace(/[^a-záéíóúñÑ\ ]/gi,"") 

	  } 

	f.value = f.value.toLowerCase();

} 

//Permite solo el ingreso de números

function numero(f){ 

  if(f.value.match(/[^0-9]/))

	f.value=f.value.replace(/[^0-9]/gi,"") 

}


function lanzar()
{	alert("hola");
	document.forms[0].submit();
}
