
function popup_window(title, name)
{
	window.open (title, name, config='height=600, width=800, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');
}

function trim(str, chars) 
{
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function get_page_height()
{
	arrayPageSize = getPageSize();
	
	return arrayPageSize[1];
}

// getPageSize()
// quirksmode.org

function getPageSize()
{
	var xScroll, yScroll;
	
	if(window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{ 
		// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else 
	{ 
		// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if(self.innerHeight) 
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if(document.documentElement && document.documentElement.clientHeight) 
	{ 
		// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ 
		// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else 
	{
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	
	return arrayPageSize;
}

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us>
Description: This is a quick and dirty password quality meter
		 written in JavaScript so that the password does
		 not pass over the network
Revision Author: Dick Ervasti (dick dot ervasti at quty dot com)
Revision Description: Exchanged text based prompts for a graphic thermometer

NOTE: Instead of putting out all the logging information,
	  the score, and the verdict it would be nicer to stretch
	  a graphic as a method of presenting a visual strength
	  guage.

************************************************************ */

function test_password(password,type)
{
	var passwd = password.value;

	var strength = 0
	
	var description = new Array();
	description[0] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"40\" bgcolor=\"#ff0000\"></td><td height=\"15\" width=\"160\" bgcolor=\"#dddddd\"></td><td>&nbsp;&nbsp;Weakest</td></tr></table>";
	description[1] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"80\" bgcolor=\"#bb0000\"></td><td height=\"15\" width=\"120\" bgcolor=\"#dddddd\"></td><td>&nbsp;&nbsp;Weak</td></tr></table>";
	description[2] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"120\" bgcolor=\"#ff9900\"></td><td height=\"15\" width=\"80\" bgcolor=\"#dddddd\"></td><td>&nbsp;&nbsp;Medium</td></tr></table>";
	description[3] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"160\" bgcolor=\"#00bb00\"></td><td height=\"15\" width=\"40\" bgcolor=\"#dddddd\"></td><td>&nbsp;&nbsp;Strong</td></tr></table>";
	description[4] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"200\" bgcolor=\"#00ee00\"></td><td>&nbsp;&nbsp;Strongest</td></tr></table>";
	description[5] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"25\" width=\"200\" bgcolor=\"#dddddd\"></td><td>&nbsp;&nbsp;Empty</td></tr></table>";

	var intScore   = 0
	var strVerdict = 0

	// PASSWORD LENGTH
	if(passwd.length == 0 || !passwd.length)     // length 0
	{
		intScore = -1
	}
	if(passwd.length > 6)
	{
		intScore = (intScore + 12)
	}
	if(passwd.length > 10)
	{
		intScore = (intScore + 3)
	}

	// LETTERS LOWERCASE
	if(passwd.match(/(.*[a-z])/)) // one lower case letter
	{
		intScore = (intScore+1)
	} 
	if(passwd.match(/(.*[a-z].*[a-z])/)) // two lower case letters
	{
		intScore = (intScore+1)
	}
	if(passwd.match(/(.*[a-z].*[a-z].*[a-z])/)) // three lower case letters
	{
		intScore = (intScore+1)
	}
	
	// LETTERS UPPERCASE
	if(passwd.match(/(.*[A-Z])/)) // one upper case letter
	{
		intScore = (intScore+1)
	} 
	if(passwd.match(/(.*[A-Z].*[A-Z])/)) // two upper case letters
	{
		intScore = (intScore+1)
	}
	if(passwd.match(/(.*[A-Z].*[A-Z].*[A-Z])/)) // three upper case letters
	{
		intScore = (intScore+1)
	}
	
	// NUMBERS
	if(passwd.match(/\d+/)) // one number
	{
		intScore = (intScore+1)
	} 
	if(passwd.match(/(\d.*\d)/)) // two numbers
	{
		intScore = (intScore+1)
	} 
	if(passwd.match(/(\d.*\d.*\d)/)) // three numbers
	{
		intScore = (intScore+1)
	} 
	
	// SPECIAL CHAR
	if(passwd.match(/[^a-zA-Z0-9]/)) // one special character
	{
		intScore = (intScore+2)
	}
	if(passwd.match(/([^a-zA-Z0-9].*[^a-zA-Z0-9])/)) // two special characters
	{
		intScore = (intScore+2)
	} 
	if(passwd.match(/([^a-zA-Z0-9].*[^a-zA-Z0-9].*[^a-zA-Z0-9])/)) // three special characters
	{
		intScore = (intScore+2)
	} 
	
	// COMBOS			
	if(passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // both upper and lower case
	{
		intScore = (intScore+2)
	} 
	
	if(passwd.match(/[a-zA-Z]/) && (passwd.match(/\d+/) || passwd.match(/[^a-zA-Z0-9]/))) // both letters and numbers / special
	{
		intScore = (intScore+5)
	} 
	
	// Upper Letters, Lower Letters, numbers and special characters
	if(passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[^a-zA-Z0-9]/))
	{
		intScore = (intScore+5)
	} 

	if(intScore == -1)
	{
	   strVerdict = description[5]; // none
	}
	else if(intScore > -1 && intScore < 15)
	{
	   strVerdict = description[0]; // weakest
	}
	else if (intScore > 15 && intScore < 25)
	{
	   strVerdict = description[1]; // weak
	}
	else if (intScore > 24 && intScore < 35)
	{
	   strVerdict = description[2]; // medium
	}
	else if (intScore > 34 && intScore < 45)
	{
	   strVerdict = description[3]; // strong
	}
	else
	{
	   strVerdict = description[4]; // strongest
	}
	strength = intScore;

	if(type == "c")
	{
		document.getElementById("strength_bar").innerHTML = (strVerdict);
	}
	else
	{
		return intScore;
	}
}

function show_lookup_overlay()
{
	
	document.getElementById("lookup_overlay").style.display = "";
	document.getElementById("lookup_overlay").style.height = get_page_height() + 'px';
}

function hide_lookup(lookup)
{
	document.getElementById(lookup + "_Lookup_Overlay").style.display = "none";
	
	document.getElementById(lookup + "_Lookup").style.display = "none";
}
