function ConfirmBorrar(){
	
	return confirm('¿Esta seguro que desea borrar este registro?');
	
}
function Reseleccionar(oSelect, mValor) {
	
	if(oSelect && mValor != '') {
		
	for(i in oSelect.options) {
			
		if(oSelect.options[i]) {
			
			if(oSelect.options[i].value == mValor) {
				oSelect.selectedIndex = oSelect.options[i].index;
				return true;
			}
		}
	}
	}
}


function CheckTodos(OnOff){
	
	aInputs = document.getElementsByTagName('INPUT');
	
	for(n=0; n < aInputs.length; n++) {
		
		if(aInputs[n].type) {
			if(aInputs[n].type == 'checkbox') {
				aInputs[n].checked = OnOff;
			}
			
		}
		
	}
	
}

function alfanumerico(car) {  
     return(alfabetico(car) || numerico(car));  
}  

function alfabetico(car) {                                    
    var alfa = "ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuvxyz";  
     return(alfa.indexOf(car) != - 1);  
}  
 
function numerico(car) {                                    
     var num = "0123456789";   
     return(num.indexOf(car) != - 1); 
}  

function esMenor(car, cant){
	
	if(car.length < cant){
		return true;
	}
	
}

function esMayor(car, cant){
	
	if(car.length > cant){
		return true;
	}
	
}

// Original: http://www.quirksmode.org/js/mailcheck.html 
// Adapted by Fernando Cuadrado - www.estudioquadra.com
function checkMail(email)
{
	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)){
		return true;
	}
}

function ValidarFrmUsuario(){
	
	var u = document.getElementById('user');
	var p = document.getElementById('pass');
	var r = document.getElementById('id_rol');
	var a = document.getElementById('aprobado');
	var e = document.getElementById('email');
	
	if(u.value == ""){
		alert('Ingrese un nombre de Usuario.');
		u.focus();
		return false;
	}
	
	if(esMenor(p.value, 4)){
		alert('-La contraseña es requerida\n-Debe contener al menos 5 carácteres.\n-Solo caracteres alfanumericos.');
		p.focus();
		return false;
	}
	
	if(r.value == 0){
		alert('Debe seleccionar algún perfil.');
		return false;
	}
	
	if(!checkMail(e.value)){
		
		alert('Ingrese un email válido.');
		e.focus();
		return false;
		
	}
	
	return true;
}

function ValidarFrmAsociacion(){
	
	var a = document.getElementById('asociacion');
	var c = document.getElementById('ciudad');
	var e = document.getElementById('email');
	var n = document.getElementById('nombre');
	var ap = document.getElementById('apellido1');
	var p = document.getElementById('provinciaid');
	var co = document.getElementById('comunidadid');
	var f = document.getElementById('fax');
	
	/*
	alert (document.getElementById('provinciaid'));
	alert('a: ' + a);
	alert('c: ' + c);
	alert('e: ' + e);
	alert('n: ' + n);
	alert('ap: ' + ap);
	alert('p: ' + p);
	alert('co: ' + co);
	alert('f: ' + f);
	*/
	
	if(a.value == ""){
		alert('Debe ingresar un nombre para la Asociación.');
		a.focus();
		return false;
	}
	
	if(n.value == ""){
		alert('Debe ingresar el nombre del titular.');
		n.focus();
		return false;		
	}
	
	if(ap.value == ""){
		alert('Debe ingresar el apellido del titular.');
		ap.focus();
		return false;		
	}
	
	if(p.value == 0){
		alert('Debe ingresar la provincia.');
		p.focus();
		return false;		
	}
	
	if(co.value == 0){
		alert('Debe ingresar la comunidad.');
		co.focus();
		return false;		
	}
	
	if(c.value == ""){
		alert('Debe ingresar la ciudad a la que pertenece la Asociación.');
		c.focus();
		return false;
	}
	
	if(!checkMail(e.value)){
		
		alert('Ingrese un email válido.');
		e.focus();
		return false;
		
	}
	
	return true;
}

function ValidarFrmOlvide(){
	
	var u = document.getElementById('user');
	
	if(u.value == ''){
		
		alert('No hay ningún usuario para informar.\nSe lo redireccionará al Login.');
		window.location.replace('?p=login');
		return false;
	}
	return true;
	
}

function IrPagina(controlador, id){
	
	var p = document.getElementById(id);
	
	window.location.href = '?p=' + controlador + '&pag=' + p.value;
	
}

function ValidarPruebas(aObj){
	
	ok = true;
	
	for(i=0; i < aObj.lenght; i++){
		
		if(aObj[i].value == ''){
			ok = false;
		}
		
	}
	
	return ok;
	
}

function AsignarSel(){
	
	var a = document.getElementById('id_asociacion');
	var alt = document.getElementById('asoc_alt');
	
	alt.value = a.value;
	
}

function ValidarCarnets(){
	
	var a = document.getElementById('asociacion');
	
	if(a.value > 0){
		return true;
	} else {
		alert('Debe seleccionar al menos una asociación.');	
		return false;
	}
	
		
}


function DesSelectUser(){
	
	var p = document.getElementById('id_rol');
	var a = document.getElementById('id_asociacion');
	
	if(p.value == 3 || p.value == 5){
		a.disabled = false;
	} else {
		a.disabled = true;
	}
	
}


//Título de la página
document.title = "Federación española de familias numerosas";
