function docId(id){ return document.getElementById(id); }

/* Calculo de la fortaleza de la contraseña:
	+1 Tamaño 6-8
	+1 Tamaño 9-12
	+1 Uso de minúsculas
	+1 Uso de mayúsculas
	+1 Uso dígitos
*/

function remove12(e12id){
	if(docId(e12id)){
		error12=docId(e12id);	
		parentError=error12.parentNode;
		parentError.removeChild(error12);
	}
}

function calculateStrength(fPasswd, idResult) {

	if(fPasswd.maxLength>1&&fPasswd.type=='password'){
		fPasswd.maxLength=15;
	}
		
	var iStrength = 0;

	var reMin = new RegExp("[a-z]");
	var reMay = new RegExp("[A-Z]");
	var reDig = new RegExp("[0-9]");

	if(fPasswd.value.length > 10) {
		iStrength = 2;
	}else if(fPasswd.value.length > 7) {
		iStrength = 1;
	}
	else {
		iStrength = 0;
	}
	
	// Comprobamos ahora las expresiones
	var sPasswd = fPasswd.value;
	if(sPasswd.match(reMin)) { iStrength += 1; } 
	if(sPasswd.match(reMay)) { iStrength += 1; } 
	if(sPasswd.match(reDig)) { iStrength += 1; }

	var colores=new Array('FF0000','FFAE01','EAFF00','B5FF04','2BB113');
	
	colorBar=docId(idResult).getElementsByTagName('div')[0];
	colorBar.style.width=(iStrength*20)+'%';
	if(iStrength>0){ 
		colorBar.style.backgroundColor='#'+colores[iStrength-1]; 
	}	
	docId(idResult+'Value').innerHTML=iStrength*20+'%';
}

error12 = '';

function changePasswInput(selInput,typeInput){
	//alert('cambia, cambia');
	inputParent=selInput.parentNode;
	
	newInput = document.createElement('INPUT');

	newInput.name=selInput.name;
	newInput.id=selInput.id;
	newInput.onchange=selInput.onchange;
	newInput.onkeyup=selInput.onkeyup;
	
	if(typeInput=='P'){
		newInput.size=20;
		newInput.maxLength=15;
		newInput.type='password';
		newInput.value=selInput.value.substr(0,12);
	}else{ //type='T'
		newInput.size=30;
		newInput.maxLength=100;
		newInput.type='text';
		newInput.value=selInput.value;
		if(error12!=''){
			if(docId(error12id)){docId(error12id).style.display='none'}
		}
	}

	inputParent.replaceChild(newInput, selInput);
}
