/************************************************************
 *                                                          *
 * Php Fusion Register Password Check v2                    *
 * Script Author: Michael Burkhardt, www.b-topia.de         *
 * Angepasst an PHP Fusion: Diavolo, http://dug-portal.com  *
 * For System: Php-Fusion v7                                *
 *                                                          *
 * Dieses Copyright darf nicht entfernt werden!!            *
 *                                                          *
 ************************************************************/

// Function (getPWScore) Start
function getPWScore(source) {

    var score_pw_length      = 6;
    var score_small_letter   = 1;
    var score_digit          = 2;
    var score_capital_letter = 4;
    var score_special_sign   = 0;

    var is_included_small   = false;
    var is_included_digit   = false;
    var is_included_capital = false;
    var is_included_special = false;
    
    var pw_char_score = 0;
    var pw_included_score = 0;
    
    for (var i = 0; i < source.length; i++) {
      var oneChar = source.charAt(i);
      if (oneChar >= "a" && oneChar <= "z") {
        pw_char_score += score_small_letter;
        is_included_small = true;
      }
      else if (oneChar >= "A" && oneChar <= "Z") {
        pw_char_score += score_capital_letter;
        is_included_capital = true;
      }
      else if (oneChar >= "0" && oneChar <= "9") {
        pw_char_score += score_digit;
        is_included_digit = true;
      }
      else {
        pw_char_score += score_special_sign;
        is_included_special = true;
      }
    }
    
    if (is_included_small) {
      pw_included_score += score_small_letter;
    }
    if (is_included_capital) {
      pw_included_score += score_capital_letter;
    }
    if (is_included_digit) {
      pw_included_score += score_digit;
    }
    if (is_included_special) {
      pw_included_score += score_special_sign;
    }
    
    return ( pw_char_score * pw_included_score / ( (score_small_letter + score_digit + score_capital_letter - 1) * score_pw_length ) );
  }

// Function (calcPlainPW) Start
  function calcPlainPW() {
   
    var targetObject = document.getElementById("plainScore");
    var pwText = document.getElementById("plainPW").value;
    var pwScore = getPWScore(pwText);
    
    while(targetObject.firstChild) {
      targetObject.removeChild(targetObject.firstChild);
    }
// alert(pwText + ": " + pwScore);
    var textNode = document.createTextNode(Math.round(pwScore * 100) / 100);
	targetObject.appendChild(textNode);

// Hier kann die Empfindlichkeit der Check Funktion eingestellt werden
	if (pwScore < 1.0) {
	  targetObject.style.backgroundColor = "#f66";
	  targetObject.style.border = "solid 1px #700";
	}
	else if (pwScore < 3.0) {
	  targetObject.style.backgroundColor = "#FFE97F";
	  targetObject.style.border = "solid 1px #FFD800";
	}
	else if (pwScore < 5.0) {
	  targetObject.style.backgroundColor = "#0094FF";
	  targetObject.style.border = "solid 1px #0026FF";
	} 
	else {
	  targetObject.style.backgroundColor = "#00FF21";
	  targetObject.style.border = "solid 1px #007F0E";
	}
  }