function comprobarPassword(tmpValue){
	var lowerCase = ((new RegExp(/[a-z]+/g)).test(tmpValue)) ? 0.5 : 0;
	var upperCase = ((new RegExp(/[A-Z]+/g)).test(tmpValue)) ? 0.5 : 0;
	var numbers = ((new RegExp(/[0-9]+/g)).test(tmpValue)) ? 0.5 : 0;
	
	var specialCharacters = ((new RegExp(/[^a-z0-9]+/gi)).test(tmpValue)) ? 0.5 : 0;
	
	var characters = (tmpValue.length > 2) ? 1 : 0;
	
	nivel = Math.ceil((lowerCase + upperCase + numbers + specialCharacters + (characters / 2) ) * characters);	
	var niveles = [
		['invalido','Inválida'],
		['facil','Fácil'],
		['media','Media'],
		['dificil','Difícil']
	];
		
	return niveles[nivel];
}

function Confirmar(evt){
		var frm = document.frmRegistro;
		if(!frm.acepto.checked){
			alert('Debe aceptar las condiciones para registrarse.');
			return cancelHref(evt);
		}
		var strError = '';
		var objCheck = new check("frmRegistro");
		
		
		objCheck.checkEmail("txtEmail", "e-mail", 1, 200, false);
		objCheck.checkString("txtPassword1", "contraseña", 3, 20, false);
		objCheck.checkString("txtNombre", "nombre", 1, 100, false);
		objCheck.checkString("txtApellidos", "apellidos", 1, 100, false);
		objCheck.checkString("txtTelefono", "telefono", 1, 100, true);
		objCheck.checkString("txtDireccion", "dirección", 1, 100, true);
		objCheck.checkString("txtCodigoPostal", "código postal", 1, 100, true);
		objCheck.checkString("txtPoblacion", "población", 1, 100, true);
		objCheck.checkCombo("cmbProvincias", "provincia",  false);
		
		
			objCheck.checkEmail("txtEmail_T", "e-mail (tienda)", 1, 200, true);
			objCheck.checkString("txtRazonSocial", "razonSocial", 1, 50, true);
			objCheck.checkString("txtNombreComercial", "nombre comercial", 1, 100, true);
			objCheck.checkString("txtCIF", "CIF", 1, 9, true);
			objCheck.checkString("txtTelefono_T", "teléfono (tienda)", 1, 100, true);
			objCheck.checkString("txtFax", "fax", 1, 100, true);
			objCheck.checkString("txtWeb", "web", 5, 200, true);

		
		
		strError = objCheck.toString();
		
		if (strError == "") {
			if(frm.txtPassword1.value != frm.txtPassword2.value){
				alert('Las contraseñas deben coincidir.');
				return cancelHref(evt);
			}
			frm.submit();
		}
		else {
			alert (strError);
			return cancelHref(evt);
		}
}

function Comportamientos() {
	if($("submit-enviar")) {	
		listen('click', 'submit-enviar', Confirmar);
	}
	if($("contrasena")) {
			$("contrasena").onkeyup = function(e){
				
				var nivel = comprobarPassword(this.value);
				var tmpDificultad = $("dificultad");
					
				tmpDificultad.innerHTML = "Seguridad de contraseña <strong>" + nivel[1] + "</strong>";
				tmpDificultad.getElementsByTagName('strong')[0].className = nivel[0];
				
			}
	}	 
	if (document.getElementById) {
		if($("dificultad")) {
			$("dificultad").style.display = "block";			
		}
	}
	else if (document.removeChild) 
    {
        var div = document.getElementById("dificultad");
        div.parentNode.removeChild(div);
    } 
}	
