function openDic()
{
	var dic = new Array();
	//this would have to run an ajax call to server file
	return dic;
}
	
function passwordStrength(element, Div, pos)
{
	var password = document.getElementById(element).value;
	var c = password.length;
	var n = 0;
	var lL = 0;
	var lU = 0;
	var s = 0;
	var x;
	var y;
	//run the dictionary function to open a file and return the whole dictionary
	//var dic = openDic();
	var dic = new Array('the', 'and', 'password', 'testing', 'test', 'hello');
	var easy = new Array('qwerty', '12345678910');
	var lettersUp = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	var lettersLow = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
	var numbers = new Array('0','1','2','3','4','5','6','7','8','9');
	var specials = new Array(' ','!','£','$','%','^','&','*','(',')','-','_','+','=','[', ']', '{', '}','#','@','~',';',':',',','.','<','>','/','\\','?','|','`','¬','"','\'','€');
	var passArray = new Array();
	
	passArray = password.split('');
	
	//check characters in password
	for(x in passArray)
	{
		//check against lettersLow
		for(y in lettersLow)
		{
			if(passArray[x] == lettersLow[y])
			{
				lL++;
			}
		}
		//check against lettersUp
		for(y in lettersUp)
		{
			if(passArray[x] == lettersUp[y])
			{
				lU++;
			}
		}
		//check against numbers
		for(y in numbers)
		{
			if(passArray[x] == numbers[y])
			{
				n++;
			}
		}
		//check against specials
		for(y in specials)
		{
			if(passArray[x] == specials[y])
			{
				s++;
			}
		}
	}
	
	//check for all characters no longer used can interfere with return
	//if((s + n + lL + lU) < c)
	//{
		//alert("ERROR " +); //please do not use spaces :" + s + " s " + n + " n " + lL + " lL " + lU + " lU " + c);
	//}
	
	//check for the password in the dictionary
	for(x in dic)
	{
		if(dic[x] == password)
		{
			c = 0;
		}
	}
	
	//check for the password in the easy list 
	for(x in easy)
	{
		if(easy[x] == password)
		{
			c = 0;
		}
	}
	
	if(c > 15)
	{
		//if they have used lL, lU, S and N green if three or two yellow if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 100;
		}
		else if((((lL != 0) && (lU != 0)) && (n != 0)) || (((lL != 0) && (s != 0)) && (n != 0)) || (((lL != 0) && (lU != 0)) && (s != 0)) || ((n != 0) && ((s != 0) && (lU != 0))))
		{
		    code = 70;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 50;
		}
		else if((lL != 0) || (lU != 0) || (n != 0) || (s != 0))
		{
		    code = 30;
		}
		else
		{
			code = 10
		}
	}
	else if(c > 10)
	{
		//if they have used lL, lU, S and N green if three yellow or two orange if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 70;
		}
		else if((((lL != 0) && (lU != 0)) && (n != 0)) || (((lL != 0) && (s != 0)) && (n != 0)) || (((lL != 0) && (lU != 0)) && (s != 0)) || ((n != 0) && ((s != 0) && (lU != 0))))
		{
		    code = 50;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 30;
		}
		else
		{
			code = 10;
		}
	}
	else if(c > 7)
	{
		//if they have used lL, lU, S and N green if three or two yellow if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 50;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 30;
		}
		else
		{
			code = 10;
		}
	}
	else if(c == 0)
	{
	    code = 0;
	}
	else
	{
		code = c+5;
	}

	setDivColour(code, pos);
}

function setDivColour(code, pos)
{
	var divToStyleA = document.getElementById('passA'+pos);
	var divToStyleB = document.getElementById('passB'+pos);
	var divToStyleC = document.getElementById('passC'+pos);
	var divToStyleD = document.getElementById('passD'+pos);
	var divToStyleE = document.getElementById('passE'+pos);
	
	divToStyleE.style.backgroundColor = "#ffffff";
	divToStyleD.style.backgroundColor = "#ffffff";
	divToStyleC.style.backgroundColor = "#ffffff";
	divToStyleB.style.backgroundColor = "#ffffff";
	divToStyleA.style.backgroundColor = "#ffffff";
	
	//only for the best passwords create a red, orange, yellow, green and blue blocks
	if(code > 80)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleE.style.backgroundColor = "#0080FF";
		divToStyleD.style.backgroundColor = "#00ff00";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red, orange, yellow and green blocks
	else if(code > 60)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleD.style.backgroundColor = "#00ff00";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red, orange and yellow blocks
	else if(code > 40)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red and orange block
	else if(code > 20)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//remove the strength checker
	else if(code == 0)
	{
	    document.getElementById('pStrength'+pos).style.display = "none";
		divToStyleA.style.backgroundColor = "#ffffff";
	}
	//set the starting div to red
	else
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
}

//this functions checks that the passwords match
function passSame(first, second, pos)
{
	var password1 = document.getElementById(first).value;
	var password2 = document.getElementById(second).value;
	
	if((password1 == password2) && ((password1 != '') && (password2 != '')))
	{
		document.getElementById('passMatch'+pos).style.display = "inline";
		document.getElementById('passMatch'+pos).style.backgroundColor = "#ffffff";
		document.getElementById('passMatch'+pos).innerHTML = '<img width="15px height="15px" src="../images/tick.gif" alt="an image of a blue tick." title="Passwords match">';
	}
	else
	{
		document.getElementById('passMatch'+pos).style.display = "inline";
		document.getElementById('passMatch'+pos).style.backgroundColor = "#ffffff";
		document.getElementById('passMatch'+pos).innerHTML = '<img width="15px height="15px" "src="../images/cross.gif" alt="an image of a red x." title="Passwords do not match">';
	}
}

function passwordLetters(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	// # " ' ; & 
	if((keynum == 35) || (keynum == 38) || (keynum == 34) || (keynum == 39) || (keynum == 59))
	{
		return false;
	}
	else if(keynum == 8)
	{
		return true;
	}
	else
	{
		return true;
	}
}