String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


var winname="";

function chatwindows(userid)
{
	winname = "chatwindows"+userid;
	popup("/id/31/monster/"+userid+"/#"+Math.floor(Math.random()*10001),470,680);
}

var handlesplashes = function(o){
	if(o.responseText !== undefined){
		if(document.getElementById)
		{
			if(o.responseText.trim()!="")
			{
				document.getElementById('splashdiv').style.display='';
				document.getElementById('splashdiv').innerHTML=o.responseText;
			}
		}
	}
}

function load_splashes()
{
	//document.write('<div id="splashdiv" style="display:none"></div>');
	//var request = YAHOO.util.Connect.asyncRequest('POST','/id/45/',{success:handlesplashes},'splash=1');
}

function close_splash()
{
	YAHOO.util.Connect.asyncRequest('POST','/id/45/action/_close/','','splash=1');
	document.getElementById('splash').style.display='none';
	document.getElementById('splashdiv').style.display='none';
}

function monstertalk()
{
	winname = "monstertalk";
	popup("/id/32/",400,650);
}
function namepopup(url,w,h,name)
{
	winname = name;
	popup(url,w,h);
}
function popup(urll,w,h)
{
	 pop=window.open(urll,winname,"toolbar=no,location=no,left=10,top=10,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h);
}
function popup2(urll,w,h)
{
	 pop=window.open(urll,winname,"toolbar=no,location=no,left=10,top=10,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+w+",height="+h);
}
function checkboxes(formname,bool)
{
	var obj = eval('document.'+formname).elements;
	for(var x=0;x<obj.length;x++)obj[x].checked=bool;
}
function letterboxaction(action,url,folder)
{
	if(action=='1')
	{
		var obj = document.bbform.elements;
		for(var x=0;x<obj.length;x++)obj[x].checked=true;
	}
	else if(action=='2')
	{
		if(confirm('Ok?'))
		{
			document.bbform.action=url+'action/'+folder+'saveselected/';
			document.bbform.submit();
		}
	}
	else if(action=='3')
	{
		if(confirm('Ok?'))
		{
			document.bbform.action=url+'action/'+folder+'deleteselected/';
			document.bbform.submit();
		}
	}
	else if(action=='4')
	{
		if(confirm('Ok?'))
		{
			document.bbform.action=url+'action/'+folder+'deleteall/';
			document.bbform.submit();
		}
	}

}
function m(obj){
	if(obj.width>424)obj.width=424;
}

var commonPasswords = new Array('password', 'pass', '1234', '1246','parool','123456789','asd','asdasdasd','asdasd','12345','123456','1234567','12345678','1234567890'); 
 
var numbers = "0123456789"; 
var lowercase = "abcdefghijklmnopqrstuvwxyz"; 
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
var punctuation = "!.@$£#*()%~<>{}[]"; 
 
function checkPassword(password,username) { 
 
    var combinations = 0; 
 
    if (contains(password, numbers) > 0) { 
        combinations += 10; 
    } 
 
    if (contains(password, lowercase) > 0) { 
        combinations += 15; 
    } 
 
    if (contains(password, uppercase) > 0) { 
        combinations += 15; 
    } 
 
    if (contains(password, punctuation) > 0) { 
        combinations += punctuation.length; 
    } 


 
    // work out the total combinations 
    var totalCombinations = Math.pow(combinations, password.length); 
	
	if(password.indexOf(username)!=-1 && username!='')
	{
		totalCombinations = 75000;
	}

    // if the password is a common password, then everthing changes... 
    if (isCommonPassword(password)) { 
        totalCombinations = 75000 // about the size of the dictionary 
    } 
 
    // work out how long it would take to crack this (@ 200 attempts per second) 
    var timeInSeconds = (totalCombinations / 200) / 2; 
 
    // this is how many days? (there are 86,400 seconds in a day. 
    var timeInDays = timeInSeconds / 86400 
 
    // how long we want it to last 
    var lifetime = 365; 
 
    // how close is the time to the projected time? 
    var percentage = timeInDays / lifetime; 
 
    var friendlyPercentage = cap(Math.round(percentage * 100), 100); 
    if (totalCombinations != 75000 && friendlyPercentage < (password.length * 5)) { 
        friendlyPercentage += password.length * 5; 
    } 
 
    var progressBar = document.getElementById("progressBar"); 
    if(friendlyPercentage>99)
	{
		progressBar.style.width = "127px";
	}
	else progressBar.style.width = friendlyPercentage + "px"; 
	
    if (percentage > 1) { 
        // strong password 
        progressBar.style.backgroundColor = "#3bce08"; 
        return; 
    } 
 
    if (percentage > 0.5) { 
        // reasonable password 
        progressBar.style.backgroundColor = "#ffd801"; 
        return; 
    } 
 
    if (percentage > 0.10) { 
        // weak password 
        progressBar.style.backgroundColor = "orange"; 
        return; 
    } 
 
    // useless password! 
    if (percentage <= 0.10) { 
        // weak password 
        progressBar.style.backgroundColor = "red"; 
        return; 
    } 
 
 
} 
 
function cap(number, max) { 
    if (number > max) { 
        return max; 
    } else { 
        return number; 
    } 
} 
 
function isCommonPassword(password) { 
 
    for (i = 0; i < commonPasswords.length; i++) { 
        var commonPassword = commonPasswords[i]; 
        if (password == commonPassword) { 
            return true; 
        } 
    } 
 
    return false; 
 
} 
 
function contains(password, validChars) { 
 
    count = 0; 
 
    for (i = 0; i < password.length; i++) { 
        var char = password.charAt(i); 
        if (validChars.indexOf(char) > -1) { 
            count++; 
        } 
    } 
 
    return count; 
}