function buildWeak() {
var $weak='';
$weak=$weak+'a';
$weak=$weak+'b';
$weak=$weak+'c';
$weak=$weak+'d';
$weak=$weak+'e';
$weak=$weak+'f';
$weak=$weak+'g';
$weak=$weak+'h';
$weak=$weak+'i';
$weak=$weak+'j';
$weak=$weak+'k';
$weak=$weak+'l';
$weak=$weak+'m';
$weak=$weak+'n';
$weak=$weak+'o';
$weak=$weak+'p';
$weak=$weak+'q';
$weak=$weak+'r';
$weak=$weak+'s';
$weak=$weak+'t';
$weak=$weak+'u';
$weak=$weak+'v';
$weak=$weak+'w';
$weak=$weak+'x';
$weak=$weak+'y';
$weak=$weak+'z';
return $weak;
}

function buildMedium() {
var $medium='';
$medium=$medium+'0';
$medium=$medium+'1';
$medium=$medium+'2';
$medium=$medium+'3';
$medium=$medium+'4';
$medium=$medium+'5';
$medium=$medium+'6';
$medium=$medium+'7';
$medium=$medium+'8';
$medium=$medium+'9';
$medium=$medium+'A';
$medium=$medium+'B';
$medium=$medium+'C';
$medium=$medium+'D';
$medium=$medium+'E';
$medium=$medium+'F';
$medium=$medium+'G';
$medium=$medium+'H';
$medium=$medium+'I';
$medium=$medium+'J';
$medium=$medium+'K';
$medium=$medium+'L';
$medium=$medium+'M';
$medium=$medium+'N';
$medium=$medium+'O';
$medium=$medium+'P';
$medium=$medium+'Q';
$medium=$medium+'R';
$medium=$medium+'S';
$medium=$medium+'T';
$medium=$medium+'U';
$medium=$medium+'V';
$medium=$medium+'W';
$medium=$medium+'X';
$medium=$medium+'Y';
$medium=$medium+'Z';
return $medium;
}

function buildStrong() {
var $strong='';
$strong=$strong+'!';
$strong=$strong+'!';
$strong=$strong+'#';
$strong=$strong+'$';
$strong=$strong+'%';
$strong=$strong+'&';
$strong=$strong+',';
$strong=$strong+'.';
$strong=$strong+':';
$strong=$strong+'-';
$strong=$strong+'­';
$strong=$strong+'­';
$strong=$strong+'–';
$strong=$strong+'—';
$strong=$strong+';';
$strong=$strong+'?';
$strong=$strong+'@';
$strong=$strong+'[';
$strong=$strong+']';
$strong=$strong+'^';
$strong=$strong+'ˆ';
$strong=$strong+'_';
$strong=$strong+'{';
$strong=$strong+'|';
$strong=$strong+'}';
$strong=$strong+'~';
$strong=$strong+'¡';
$strong=$strong+'¡';
$strong=$strong+'¦';
$strong=$strong+'¦';
$strong=$strong+'¨';
$strong=$strong+'¨';
$strong=$strong+'¯';
$strong=$strong+'¯';
$strong=$strong+'¸';
$strong=$strong+'¸';
$strong=$strong+'¿';
$strong=$strong+'¿';
$strong=$strong+'˜';
$strong=$strong+'‚';
$strong=$strong+'„';
$strong=$strong+'‹';
$strong=$strong+'›';
$strong=$strong+'›';
$strong=$strong+'+';
$strong=$strong+'<';
$strong=$strong+'=';
$strong=$strong+'>';
$strong=$strong+'±';
$strong=$strong+'±';
$strong=$strong+'«';
$strong=$strong+'«';
$strong=$strong+'»';
$strong=$strong+'»';
$strong=$strong+'×';
$strong=$strong+'×';
$strong=$strong+'÷';
$strong=$strong+'÷';
$strong=$strong+'¢';
$strong=$strong+'¢';
$strong=$strong+'£';
$strong=$strong+'£';
$strong=$strong+'¤';
$strong=$strong+'¤';
$strong=$strong+'¥';
$strong=$strong+'¥';
$strong=$strong+'§';
$strong=$strong+'§';
$strong=$strong+'©';
$strong=$strong+'©';
$strong=$strong+'¬';
$strong=$strong+'¬';
$strong=$strong+'®';
$strong=$strong+'®';
$strong=$strong+'°';
$strong=$strong+'°';
$strong=$strong+'µ';
$strong=$strong+'µ';
$strong=$strong+'†';
$strong=$strong+'‡';
$strong=$strong+'•';
$strong=$strong+'…';
$strong=$strong+'‰';
$strong=$strong+'€';
$strong=$strong+'¼';
$strong=$strong+'¼';
$strong=$strong+'½';
$strong=$strong+'½';
$strong=$strong+'¾';
$strong=$strong+'¾';
$strong=$strong+'¹';
$strong=$strong+'¹';
$strong=$strong+'²';
$strong=$strong+'²';
$strong=$strong+'³';
$strong=$strong+'³';
$strong=$strong+'ª';
$strong=$strong+'ª';
$strong=$strong+'Á';
$strong=$strong+'á';
$strong=$strong+'À';
$strong=$strong+'à';
$strong=$strong+'Â';
$strong=$strong+'â';
$strong=$strong+'Ä';
$strong=$strong+'ä';
$strong=$strong+'Ã';
$strong=$strong+'ã';
$strong=$strong+'Å';
$strong=$strong+'å';
$strong=$strong+'Æ';
$strong=$strong+'æ';
$strong=$strong+'Ç';
$strong=$strong+'ç';
$strong=$strong+'Ð';
$strong=$strong+'ð';
$strong=$strong+'É';
$strong=$strong+'é';
$strong=$strong+'È';
$strong=$strong+'è';
$strong=$strong+'Ê';
$strong=$strong+'ê';
$strong=$strong+'Ë';
$strong=$strong+'ë';
$strong=$strong+'ƒ';
$strong=$strong+'Í';
$strong=$strong+'í';
$strong=$strong+'Ì';
$strong=$strong+'ì';
$strong=$strong+'Î';
$strong=$strong+'î';
$strong=$strong+'Ï';
$strong=$strong+'ï';
$strong=$strong+'Ñ';
$strong=$strong+'ñ';
$strong=$strong+'º';
$strong=$strong+'º';
$strong=$strong+'Ó';
$strong=$strong+'ó';
$strong=$strong+'Ò';
$strong=$strong+'ò';
$strong=$strong+'Ô';
$strong=$strong+'ô';
$strong=$strong+'Ö';
$strong=$strong+'ö';
$strong=$strong+'Õ';
$strong=$strong+'õ';
$strong=$strong+'Ø';
$strong=$strong+'ø';
$strong=$strong+'Œ';
$strong=$strong+'œ';
$strong=$strong+'Š';
$strong=$strong+'š';
$strong=$strong+'ß';
$strong=$strong+'Þ';
$strong=$strong+'þ';
$strong=$strong+'™';
$strong=$strong+'Ú';
$strong=$strong+'ú';
$strong=$strong+'Ù';
$strong=$strong+'ù';
$strong=$strong+'Û';
$strong=$strong+'û';
$strong=$strong+'Ü';
$strong=$strong+'ü';
$strong=$strong+'Ý';
$strong=$strong+'ý';
$strong=$strong+'Ÿ';
$strong=$strong+'ÿ';
$strong=$strong+'Ž';
$strong=$strong+'ž';
return $strong;
}
function buildIllegal() {
var $illegal='';
$illegal=$illegal+"'";
$illegal=$illegal+'`';
$illegal=$illegal+'´';
$illegal=$illegal+'‘';
$illegal=$illegal+'’';
$illegal=$illegal+'“';
$illegal=$illegal+'"';
$illegal=$illegal+'”';
$illegal=$illegal+'¶';
$illegal=$illegal+'·';
$illegal=$illegal+'/';
$illegal=$illegal+'\\';
return $illegal;
}

function isWhat($ch,$what) 
{
	var $isat=-1;
	if ($what=="illegal") 
	{
		var $illegal=buildIllegal();
		$isat=$illegal.indexOf($ch);
	}
	if ($what=="strong")
	{
		var $strong=buildStrong();
		$isat=$strong.indexOf($ch);
	}
	if ($what=="medium") 
	{
		var $medium=buildMedium();
		$isat=$medium.indexOf($ch);
	}
	if ($what=="weak") 
	{
		var $weak=buildWeak();
		$isat=$weak.indexOf($ch);
	}
	if ($isat>-1){return true;}
	if ($isat==-1){return false;}
}

function updateStrength()
{
	$score='weak';
	$pw=register.password.value;

	var $ch='';
	var $isweak='';
	var $isstrong='';
	var $ismedium='';
	var $isillegal='';
	var $highest='';
	var $divnum=0;

	$divnum=$pw * 1;

	if ($divnum==$pw) 
	{
		$highest='weak';
		$score='weak';
	} 
	else 
	{
		for ($x=0; $x < $pw.length; $x++) 
		{
			$ch=$pw.charAt($x);
			$isillegal=isWhat($ch,'illegal');
			$isstrong=isWhat($ch,'strong');
			$ismedium=isWhat($ch,'medium');
			$isweak=isWhat($ch,'weak');
		
			if ($isillegal==true) 
			{
				$isresult='illegal';
				$highest='illegal';
			}
			if ($isstrong==true) 
			{
				$isresult='strong';
				if ($highest=='illegal'){}else{$highest='strong';}
			}
			if ($ismedium==true) 
			{
				$isresult='medium';
				if ($highest=='illegal') {} else {if ($highest=='strong') {} else {$highest='medium';}}
			}
			if ($isweak==true) 
			{
				$isresult='weak';
				if ($highest=='illegal') 
				{
				} 
				else 
				{
					if ($highest=='strong') 
					{
					} 
					else 
					{
						if ($highest=='medium') {} else {$highest='weak';}
					}
				}
			} 
		}
	}

	if ($highest=='illegal') 
	{
		alert('Ce caractère n\'est pas autorisé: '+$ch+'.');
		$score='Caractère interdit';
		register.password.value='';
		document.getElementById("div1").style.backgroundColor = '#FF0000';
		document.getElementById("div2").style.backgroundColor = '#FFFFFF';
		document.getElementById("div3").style.backgroundColor = '#FFFFFF';
		document.getElementById("div4").style.backgroundColor = '#FFFFFF';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
	} 
	else 
	{
		$score=$highest;
		if ($highest=="illegal") 
		{
			document.getElementById("div1").style.backgroundColor = '#FF0000';
			document.getElementById("div2").style.backgroundColor = '#FFFFFF';
			document.getElementById("div3").style.backgroundColor = '#FFFFFF';
			document.getElementById("div4").style.backgroundColor = '#FFFFFF';
			document.getElementById("div5").style.backgroundColor = '#FFFFFF';
			document.getElementById("div6").style.backgroundColor = '#FFFFFF';
			document.getElementById("div7").style.backgroundColor = '#FFFFFF';
			document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		}
		if ($highest=="strong") 
		{
			document.getElementById("div1").style.backgroundColor = '#00FF00';
			document.getElementById("div2").style.backgroundColor = '#00FF00';
			document.getElementById("div3").style.backgroundColor = '#00FF00';
			document.getElementById("div4").style.backgroundColor = '#00FF00';
			document.getElementById("div5").style.backgroundColor = '#00FF00';
			document.getElementById("div6").style.backgroundColor = '#00FF00';
			document.getElementById("div7").style.backgroundColor = '#00FF00';
			document.getElementById("div8").style.backgroundColor = '#00FF00';
		}
		if ($highest=="medium") 
		{
			document.getElementById("div1").style.backgroundColor = '#00FF00';
			document.getElementById("div2").style.backgroundColor = '#00FF00';
			document.getElementById("div3").style.backgroundColor = '#00FF00';
			document.getElementById("div4").style.backgroundColor = '#00FF00';
			document.getElementById("div5").style.backgroundColor = '#FFFFFF';
			document.getElementById("div6").style.backgroundColor = '#FFFFFF';
			document.getElementById("div7").style.backgroundColor = '#FFFFFF';
			document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		}
		if ($highest=="weak") 
		{
			document.getElementById("div1").style.backgroundColor = '#00FF00';
			document.getElementById("div2").style.backgroundColor = '#00FF00';
			document.getElementById("div3").style.backgroundColor = '#FFFFFF';
			document.getElementById("div4").style.backgroundColor = '#FFFFFF';
			document.getElementById("div5").style.backgroundColor = '#FFFFFF';
			document.getElementById("div6").style.backgroundColor = '#FFFFFF';
			document.getElementById("div7").style.backgroundColor = '#FFFFFF';
			document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		}
	}

	$len=$pw.length;
	if ($len<5) 
	{
		$score='Très faible';
		document.getElementById("div1").style.backgroundColor = '#FF0000';
		document.getElementById("div2").style.backgroundColor = '#FFFFFF';
		document.getElementById("div3").style.backgroundColor = '#FFFFFF';
		document.getElementById("div4").style.backgroundColor = '#FFFFFF';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
	}
	if($score=="strong" && $len<7)
	{
		document.getElementById("div1").style.backgroundColor = '#00FF00';
		document.getElementById("div2").style.backgroundColor = '#00FF00';
		document.getElementById("div3").style.backgroundColor = '#00FF00';
		document.getElementById("div4").style.backgroundColor = '#00FF00';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		$score='Moyenne';
	}
	if ($len>10) 
	{
		if ($score=='weak') 
		{
			document.getElementById("div1").style.backgroundColor = '#00FF00';
			document.getElementById("div2").style.backgroundColor = '#00FF00';
			document.getElementById("div3").style.backgroundColor = '#00FF00';
			document.getElementById("div4").style.backgroundColor = '#00FF00';
			document.getElementById("div5").style.backgroundColor = '#FFFFFF';
			document.getElementById("div6").style.backgroundColor = '#FFFFFF';
			document.getElementById("div7").style.backgroundColor = '#FFFFFF';
			document.getElementById("div8").style.backgroundColor = '#FFFFFF';
			$score='Moyenne';
		}
	}
	if ($len>=24) 
	{
		document.getElementById("div1").style.backgroundColor = '#FF0000';
		document.getElementById("div2").style.backgroundColor = '#FFFFFF';
		document.getElementById("div3").style.backgroundColor = '#FFFFFF';
		document.getElementById("div4").style.backgroundColor = '#FFFFFF';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		
		alert('Votre mot de passe est trop long.');
		$score='Trop long';
		register.password.value='';
	}
	if ($len<=0) 
	{
		document.getElementById("div1").style.backgroundColor = '#FFFFFF';
		document.getElementById("div2").style.backgroundColor = '#FFFFFF';
		document.getElementById("div3").style.backgroundColor = '#FFFFFF';
		document.getElementById("div4").style.backgroundColor = '#FFFFFF';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
		$score="-";
	}
	if($pw==register.pseudo.value)
	{
		$score='Très faible';
		document.getElementById("div1").style.backgroundColor = '#FF0000';
		document.getElementById("div2").style.backgroundColor = '#FFFFFF';
		document.getElementById("div3").style.backgroundColor = '#FFFFFF';
		document.getElementById("div4").style.backgroundColor = '#FFFFFF';
		document.getElementById("div5").style.backgroundColor = '#FFFFFF';
		document.getElementById("div6").style.backgroundColor = '#FFFFFF';
		document.getElementById("div7").style.backgroundColor = '#FFFFFF';
		document.getElementById("div8").style.backgroundColor = '#FFFFFF';
	}
	
	if($score=="weak"){$score="Faible";}
	if($score=="strong"){$score="Forte";}
	if($score=="medium"){$score="Moyenne";}
	document.getElementById("secu_level").innerHTML=$score;
	document.getElementById("secu_level_h").value=$score;
}

function is_ok()
{
	if(document.getElementById("secu_level_h").value!="Forte")
	{
		if(window.confirm("Votre niveau de sécurité du mot de passe n\'est pas optimale. Il est préférable d\'opter pour un mot de passe incluant chiffres, lettres (Majuscules/minuscules) et caractères spéciaux. Cliquez sur \"Annuler\" pour modifier votre mot de passe, ou OK si vous voulez malgrès tout valider votre inscription avec ce mot de passe."))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}