/**
 *
 * @copyright Copyright (c) 2009 tmedia.de - (http://www.tmedia.de)
 * @author Johannes Teitge, teitge@tmedia.de
 * 
 */

  function pwd_get_strength(labels,colors) {
    
    labels = labels.split('|');  // Example: Type password|More Characters|Strong|Medium|Weak  
    colors = colors.split('|');  // Example: green|orange|red;

    var pwd = document.getElementById("password");
    
    var pwd_width = document.getElementById("pwd_panel");
    
//    pwd_width = pwd_width.firstChild;
//    pwd_width = pwd_width.nextSibling;    
//    alert(pwd_width.attributes.length );    
//    alert(pwd_width.nodeName + " "  + pwd_width.getAttribute('class') );
//    pwd_width.style.backgroundColor = 'black';
//    pwd_width.style.width = '300px';
//    alert(pwd.offsetWidth);        
    pwd_width.style.width = pwd.offsetWidth+'px';    
//    alert(pwd_width.nodeName);    

    
    pwd_width = pwd.offsetWidth;    
//    pwd_width = pwd_width.replace(/px/g,"");
    
    var strength = document.getElementById("strength");    
    var strength_text = document.getElementById("strength_text");    
    
    var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
    var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
    var enoughRegex = new RegExp("(?=.{6,}).*", "g");
    if (pwd.value.length==0) {
      strength.innerHTML = "";
      strength_text.innerHTML = labels[0];
      strength.style.width = '0';            
    } else if (false == enoughRegex.test(pwd.value)) {
      strength.innerHTML = "";
      strength_text.innerHTML = labels[1];
      strength.style.width = '0';            
    } else if (strongRegex.test(pwd.value)) {
      strength_text.innerHTML = labels[2];    
      strength.style.backgroundColor = colors[0];
      strength.style.width = pwd_width+'px';                   
    } else if (mediumRegex.test(pwd.value)) {
      strength_text.innerHTML = labels[3];    
      strength.style.backgroundColor = colors[1];
      strength.style.width = (pwd_width*(2/3))+'px';
    } else { 
      strength.style.backgroundColor = colors[2];
      strength.style.width = (pwd_width/3)+'px';                
      strength_text.innerHTML = labels[4];      
    }
  }