function passwordStrength(password)
{
	var desc = new Array();
	var Errordesc = new Array();
	var img = new Array();
	img[0] = "very_weak";
	img[1] = "weak";
	img[2] = "better";
	img[3] = "medium";
	img[4] = "strong";
	img[5] = "strongest";
	desc[0] = "Very weak";
	desc[1] = "Weak";
	desc[2] = "Medium";
	desc[3] = "Quite strong";
	desc[4] = "Strong";
	desc[5] = "Very strong";
	Errordesc[0] = "";
	Errordesc[1] = "Failed: Two consecutive '-' not allowed";
	Errordesc[2] = "Failed: Same character more than twice in succession not allowed";
	Errordesc[3] = "Failed: Alternate repeat characters not allowed";
	Errordesc[4] = "Failed: Must be at least 7 characters";
	Errordesc[5] = "Failed: Must have at least one number and one letter";
	Errordesc[6] = "Failed: Has illegal characters i.e. ' : ; \" < > [ ] { } + = \ / | ` ¬ , . £";
	Errordesc[7] = "Failed: Has ascending characters e.g. abc123";
	Errordesc[8] = "Failed: Has descending characters e.g. cba321";

	var score   = 0;
	var errors  = 0;
	var hasLetters = password.match(/[a-z]/) || password.match(/[A-Z]/);
	var hasNumbers = password.match(/\d+/);
	var hasSymbols = password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/);
	var hasIllegalChar = password.match(/[^a-zA-Z\d!@#$%\^&*?_~\-\(\)]+/);
	var consecutiveChars = 0;
	var charOne = 0
	var charTwo = 0;
	
	for (i = 0; i < password.length; i++)
	{
		var curChar = password.charCodeAt(i);
		if ((curChar >= 65 && curChar <= 90) ||
			(curChar >= 97 && curChar <= 122) ||
			(curChar >= 48 && curChar <= 57))
		{
			if (charOne == charTwo - 1 &&
				charTwo == curChar - 1)
			{
				errors = 7;
				break;
			}
			else if (charOne == charTwo + 1 &&
				charTwo == curChar + 1)
			{
				errors = 8;
				break;
			}
		}

		// Store last two characters
		if (charOne == 0)
			charOne = curChar;
		else if (charTwo == 0)
			charTwo = curChar;
		else
		{
			charOne = charTwo;
			charTwo = curChar;
		}	
	}
	
  // Must enter a letter and number
	if (!hasLetters || !hasNumbers)
		errors = 5;

  // Must be 7 characters
	if (password.length < 7)
		errors = 4;
		
  // Check for more than 3 alternating repeat characters i.e. 12121212
	if (password.length >= 6)
	{
    for (var i = 0; i < password.length - 2; i++) 
    {
      if (password.substr(i,2) == password.substr(i+2, 2) && password.substr(i,2) == password.substr(i+4, 2))
      {
        errors = 3;
        break;
      }
    }
	}

  // Check for errors first
	//if password has two "-" then fail it
	if (password.match(/.*[\-]{2}/))
    errors = 1;
  
  // Check for more than 2 repeat characters
	var charcounter = 0;
	for (var i = 0; i < password.length - 1; i++) 
	{
		if (password.substr(i,1) == password.substr(i+1, 1)) 
			charcounter++;
		else
			charcounter = 0;
		if(charcounter >= 2) 
			errors = 2;
	}

	// Check for illegal characters
	if (hasIllegalChar)
		errors = 6;
	
	if (errors == 0)
	{
		// Password will be bigger than 6 give 1 point
		score++;
		
		//if password has both lower and uppercase characters give 1 point	
		if (password.match(/[a-z]/) && password.match(/[A-Z]/)) score++;

		//if password has at least one number give 1 point
		if (hasNumbers) score++;

		//if password has at least special characters give 1 point
		if (hasSymbols)	score++;

		//if password bigger than 12 give another 1 point
		if (password.length > 12) score++;

		// Output the strengtg
		document.getElementById("passwordDescription").innerHTML = desc[score];
		document.getElementById("passwordStrengthImage").src = "images/pm_" + img[score] + ".gif";
	}
	else
	{
		if (password.length == 0)
		{
			document.getElementById("passwordDescription").innerHTML = "&#160;";
			document.getElementById("passwordStrengthImage").src = "images/pm_empty.gif";
		}
		else
		{
			document.getElementById("passwordDescription").innerHTML = Errordesc[errors];
			document.getElementById("passwordStrengthImage").src = "images/pm_empty.gif";
		}
	}

}
