document.observe('dom:loaded', function() {
  
  	//Lanzar Registro Universal
	$('registro').observe('click', function(event) {
    	event.stop();
		Lightview.show({
	  		href: 'registro/include/registro.php',
	  		rel: 'ajax',
	  		title: 'Registro Universal Bimbo',
	  		options: {
	    		autosize: true,
				ajax: {
		  			onComplete: function(){
		  				var valid2 = new Validation('registro1', {immediate : true});
						Validation.addAllThese([
						['validate-password', 'Your password must be more than 6 characters and not be \'password\' or the same as your name', {
							minLength : 7,
							notOneOf : ['password','PASSWORD','1234567','0123456']
						}],
						['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
							equalToField : 'pas1'
						}]
						]);
		  	
						$('registroEnviar').observe('click', enviarRegistro);
		  			} 
	    		}
	  		}
		});
  	});

});

//Verificar Registro  
function enviarRegistro(event){

msg = "";

if(document.getElementById('nombre').value==""){ msg += "- Introduce tu nombre.\n"; }
if(document.getElementById('apellido').value==""){ msg += "- Introduce tu(s) apellido(s).\n"; }
if(document.getElementById('dia').value==0){ msg += "- Introduce tu d\u00eda de nacimiento.\n"; }
if(document.getElementById('mes').value==0){ msg += "- Introduce tu mes de nacimiento.\n"; }
if(document.getElementById('anio').value==0){ msg += "- Introduce tu a\u00f1o de nacimiento.\n"; }
if(document.getElementById('estado').value==0){ msg += "- Introduce tu Estado.\n"; }
if(document.getElementById('lada').value==""){ msg += "- Introduce tu lada.\n"; }
if(document.getElementById('telefono').value==""){ msg += "- Introduce tu tel\u00e9fono.\n"; }
if(document.getElementById('medio').value==0){ msg += "- Selecciona un medio.\n"; }

if(msg!=""){
	alert("Lo siguientes campos son requeridos:\n"+msg);
	return false;
}else{	  
	if(document.getElementById("pas1").value != document.getElementById("pas2").value || !document.getElementById("pas1").value || !document.getElementById("pas2").value){ 
		alert("Las contrase\u00f1as no coinciden.");
		return false; 
	}else if (document.getElementById("umail").value == "" || document.getElementById("umail").value.indexOf('@') == -1 || document.getElementById("umail").value.indexOf('.')== -1){
		alert("Su direcci\u00f3n de correo electr\u00f3nico no es v\u00e1lida.");
		document.getElementById("umail").focus(); 
		return false;
	}else{
		event.stop();
		Lightview.show({
			href: 'registro/include/verif_registro.php?o=688076062d6513e29967e70d2cdade24',
			rel: 'ajax',
			title: 'Registro Universal Bimbo',
			options: {
		  		menubar: true,
		  		topclose: true,
		  		autosize: true,
		  		ajax: {
		    		parameters: Form.serialize('registro1') // formulario
		  		}
			}
		});
	}
}
}

//Registro en proceso interno
function iRegister(){
	Lightview.show({
		href: 'registro/include/registro.php',
	  	rel: 'ajax',
	  	title: 'Registro Universal Bimbo',
	  	options: {
	    	autosize: true,
			ajax: {
		  		onComplete: function(){
					var valid2 = new Validation('registro1', {immediate : true});
					Validation.addAllThese([
					['validate-password', 'Your password must be more than 6 characters and not be \'password\' or the same as your name', {
						minLength : 7,
						notOneOf : ['password','PASSWORD','1234567','0123456']
					}],
					['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
						equalToField : 'pas1'
					}]
					]);
		  	
					$('registroEnviar').observe('click', enviarRegistro);
				
				}
			}
	  	}
	});
}

//No recuerda contrasena
function iLost(){
	Lightview.show({
		href: 'registro/include/recordar.php',
		rel: 'ajax',
		options: {
			menubar: false,
			topclose: true,
			autosize: true,
			ajax: {
				onComplete: function(){
					$('recordarEnvio').observe('click', enviarPassword);
				} 
			}
		}
	});
}

//Enviar contrasena
function enviarPassword(event) {
	
	event.stop();
	
	if (document.getElementById("umail").value == "" || document.getElementById("umail").value.indexOf('@') == -1 || document.getElementById("umail").value.indexOf('.')== -1){
    	alert("La direcci\u00f3n de correo electr\u00f3nico no es v\u00e1lida.");
		//document.getElementById("umail").focus(); 
		return false;
	}else{
		event.stop();
		Lightview.show({
			href: 'registro/include/verif_password.php?o=cc512ab623b8e3ff69b8d529840bcb3c',
			rel: 'ajax',
			title: 'Recuperar Password',
			options: {
				menubar: true,
				topclose: true,
				autosize: true,
				ajax: {
					parameters: Form.serialize('recordar')
				}
			}
		});
	}
}

//Reenviar correo de bienvenida
function iWelcome(){
	Lightview.show({
	  	href: 'registro/include/recordar_b.php',
	  	rel: 'ajax',
	  	options: {
			menubar: false,
			topclose: true,
			autosize: true,
			ajax: {
				onComplete: function(){
					$('recordarDatos').observe('click', enviarBienvenida);
				} 
			}
	  	}
	});
}

//Enviar correo de bienvevida
function enviarBienvenida(event) {
	event.stop();
	if (document.getElementById("umail").value == "" || document.getElementById("umail").value.indexOf('@') == -1 || document.getElementById("umail").value.indexOf('.')== -1){
    	alert("La direcci\u00f3n de correo electr\u00f3nico no es v\u00e1lida.");
		//document.getElementById("umail").focus(); 
		return false;
	}else{
		event.stop();
 		Lightview.show({
    		href: 'registro/include/ewelcome.php?o=cc512ab623b8e3ff68b8d529840bcb3c',
    		rel: 'ajax',
      		title: 'Reenviar Datos',
    		options: {
	  			menubar: true,
	  			topclose: true,
	  			autosize: true,
      			ajax: {
        			parameters: Form.serialize('recordar')
      			}
    		}
  		});
	}
}

//Otro medio
function otro(x){
	if(x==7){
		document.getElementById("otros").disabled = false;	
		document.getElementById("otros").style.display = '';		
	}else{
		document.getElementById("otros").disabled = true;
		document.getElementById("otros").style.display = 'none';		
	}
}