function Passwdmeter()
{
    this.styles = new Array();	
	this.styles[0] = {backgroundColor:"#EBEBEB",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #FFFFFF",borderBottom:"solid 1px #FFFFFF",borderTop:"solid 1px #FFFFFF"};	
	this.styles[1] = {backgroundColor:"#3ABB1C",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #FFFFFF",borderBottom:"solid 1px #FFFFFF",borderTop:"solid 1px #FFFFFF"};	
	this.styles[2] = {backgroundColor:"#3ABB1C",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #FFFFFF",borderBottom:"solid 1px #FFFFFF",borderTop:"solid 1px #FFFFFF"};	
	this.styles[3] = {backgroundColor:"#3ABB1C",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #FFFFFF",borderBottom:"solid 1px #FFFFFF",borderTop:"solid 1px #FFFFFF"};	
	this.styles[4] = {backgroundColor:"#3ABB1C",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #FFFFFF",borderBottom:"solid 1px #FFFFFF",borderTop:"solid 1px #FFFFFF"};	
	
	this.divName = "pwd_div_"+Math.ceil(Math.random()*100000);
	
	this.width = "100px";
	this.height = "10px";
    this.selectedIndex = 0;
	this.init();	
}

  Passwdmeter.prototype = {
     tests: {
        len: true,
        letters: true,
        numbers: true,
        specials: true,
        repeat: true,
        order: true
    },
    config: {
        min_len: 6,
        max_len: 20
    },
    init : function(){
	var s = '<table cellpadding="0" id="'+this.divName+'_table" cellspacing="0" style="width:'+this.width+';" border="0">';
	s +='<tr><td colspan=\'4\' align=\'left\' style="font-family: Courier New, Courier, mono;height:3px;color: #999999;font-size: 12px;">Èõ</td><td colspan=\'4\'  align=\'right\' style="font-family: Courier New, Courier, mono;height:3px;color: #999999;font-size: 12px;">Ç¿</td></tr>'
	s += '<tr>';
	for(var i=0;i<4;i++)
	{
		s += '<td id="'+this.divName+'_td_'+i+'" width="24px" height="'+this.height+'" align="center" style="border:solid 1px #999999;"></td>';
	    s +='<td style="widht:1px;"></td>'
	}
	s += '</tr>';
	s += '</table>';
	s += '<span id="'+this.divName+'_span_msg" style="display:none;">';
	s += '</span>';	

    document.write(s);
	this.copyToStyle(this.selectedIndex);	
  },
  copyToObject : function(o1,o2){
	for(var i in o1){
		o2[i] = o1[i];
	}
},
copyToStyle : function(id){
	this.selectedIndex = id;

	for(var i=0;i<id;i++){
		this.copyToObject(this.styles[id],this.$(this.divName+"_td_"+i).style);			
	}
	for(;i<4;i++){
		this.copyToObject(this.styles[0],this.$(this.divName+"_td_"+i).style);
	}
},
 $ : function(s){
	return document.getElementById(s);
},
     // BEGIN TEST FUNCTIONS
  test_name: function(str) {
       return false;
    },
    test_len: function(str) {
        //test the passwords length
        if ((str.length > (this.config.min_len - 1)) && (str.length < (this.config.max_len + 1))) 
        {
            return true;
        }
        return false;
    },
    test_letters: function(str) {
        //test if there are Uppercase & lowercase letters
		if (str.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) 
		{
            return true;
		}
        return false;
    },
    test_numbers: function(str) 
    {
        //test if there is a number and a letter in the string
        var ret = false;
        var num = false;
        var let = false;
		if (str.match(/\d+/)) {
            num = true;
		}
		if (str.match(/[a-z].*/i)) {
            let = true;
		}
        if (num && let) {
            ret = true;
        }
        return ret;
    },
    test_special: function(str) 
    {
		//Checking for special characters
		if (str.match(/[!,@,#,\$,%,^,&,\*,?,_,~]/)) {
            return true;
		}
        return false;
    },
    test_repeatchar: function(str) 
    {
        //test for repeated chars (aaaa, bbbb, 1111, 2222)
        str_chars = 'abcdefghijklmnopqrstuvwxyz012345678909876543210zyxwvutsrqponmlkjihgfedcba';
        for (i=0; i<str_chars.length;i++) {
            /*
                Regexs in cmd should look like this after eval:
                    /[a]+/i
                    /[b]+/i
                    /[c]+/i

                These will return a string of the char
                    searched + any repeating chars.
            */
            cmd = '/[' + str_chars.substr(i, 1) + ']+/i';
            cmd = eval(cmd);
            if (str.match(cmd)) {
                newstr = new String(str.match(cmd));
                if (newstr.length > 3) {
                    //test to see if the repeats are greater than 3
                    return true;
                }
            }
        }
        return false;
    },

    test_order: function(str) 
    {
        //test for ordered chars in the string (1234, abcd, lmno, 5678)
        str_chars = 'abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba';
        for (i=0; i<str_chars.length;i++) {
            nc = str_chars.substr(i + 1, 3);
            if (nc.length == 3) {
                /*
                    Regexs in cmd should look like this after eval:
                        /a(?=bcd)/i
                        /b(?=cde)/i
                        /c(?=def)/i
                */
                cmd = '/' + str_chars.substr(i, 1) + '(?=' + nc + ')/i';
                cmd = eval(cmd);
                if (str.match(cmd)) {
                    return true;
                }
            }
        }
        str_chars = '012345678909876543210';
        for (i=0; i<str_chars.length;i++) {
            nc = str_chars.substr(i + 1, 3);
            if (nc.length == 3) {
                /*
                    Regexs in cmd should look like this after eval:
                        /1(?=234)/i
                        /2(?=345)/i
                        /3(?=456)/i
                */
                cmd = '/' + str_chars.substr(i, 1) + '(?=' + nc + ')/i';
                cmd = eval(cmd);
                if (str.match(cmd)) {
                    return true;
                }
            }
        }
        return false;
    },
     checkPass: function(strPasswd) {
     
        //set all test results to false
        this.len = false;
        this.letters = false;
        this.numbers = false;
        this.specials = false;
        this.repeat = false;
        this.order = false;
        var result='';
        var ls=0;
        if (strPasswd.length > 0) 
        {
            //Start Password Check Logic
            /*
                TODO
                We could put some if's around these & call them based on rules in the setup
            */
            //Length Check
            if (this.tests.len) {
                this.len = this.test_len(strPasswd);
            }
            //Letters Check
            if (this.tests.letters) {
                this.letters = this.test_letters(strPasswd);
            }
            //Numbers Check
            if (this.tests.numbers) {
                this.numbers = this.test_numbers(strPasswd);
            }
            //Special Characters Check
            if (this.tests.specials) {
                this.specials = this.test_special(strPasswd);
            }
            //Check for repeating characters (aaaa, bbbb)
            if (this.tests.repeat) {
                this.repeat = this.test_repeatchar(strPasswd);
            }
            //Check for ordered characters (abcd, 1234)
            if (this.tests.order) {
                this.order = this.test_order(strPasswd);
            }
            
             if (!this.len) 
             {
		        if(ls>1)
		        {
		            ls--;
		        }
		    }
		    else
		    {
		         ls++;
		    } 
		    
		    if (this.name) {
                //Contains the users name
		        if(ls>1)
		        {
		            ls--;
		        }
		    } 
		    else
		    {
		        ls++;
		    }
		    
		     if (this.repeat){
                //contains chars that repeat (1111, aaaa)
		         if(ls>1)
		        {
		            ls--;
		        }
		    }
		    else
		    {
		        ls++;
		    }
		     
		     if (this.order){
                //contains ordered chars (1234, abcd)
		         if(ls>1)
		        {
		            ls--;
		        }
		    }
		    else
		    {
		        ls++;
		    }
		     
		     if (!this.letters) 
		     {
		         if(ls>1)
		        {
		            ls--;
		        }
		    }
		     else
		    {
		        ls++;
		    } 
		    
		     if (!this.numbers) 
		     {
		         if(ls>1)
		        {
		            ls--;
		        }
		    }
		     else
		    {
		        ls++;
		    } 
		    
		     if (!this.specials) 
		     {
		         if(ls>1)
		        {
		            ls--;
		        }
		    }
		     else
		    {
		        ls++;
		    } 
        } 
        
        //½á¹û
        if(ls==0 || !this.len)
        {
             this.copyToStyle(0);
            
        }
        else if(ls<=1)
        {
            this.copyToStyle(1);
   
        }
        else if(ls<3)
        {
            this.copyToStyle(2);
 
        }
         else if(ls<=4)
        {
            this.copyToStyle(3);

        }
        else
        {
            this.copyToStyle(4);

        }
    }
 }