
//to pull a value from a query string in to the javascript file
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  
  if(qs == null)
    return default_;
  else
    return qs[1];
}

// url example
//http://www.bloggingdeveloper.com?author=bloggingdeveloper
// to get the value
//var author_value = getQuerystring('author');


function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
   return (S4()+"cl"+S4());
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
function validAlpha(theValue) {
	var pattern = new RegExp(/^[a-zA-Z _-]+$/);
	return pattern.test(theValue);
}
function validNumeric(theValue) {
	var pattern = new RegExp(/^[0-9 ]+$/);
	return pattern.test(theValue);
}
function validAlphaNumeric(theValue) {
	var pattern = new RegExp(/^[0-9a-zA-Z _-]+$/);
	return pattern.test(theValue);
}
function validPassword(theValue)
{
	
	// -- Toggle to true or false, if you want to change what is checked in the password
	var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";
	var m_strNumber = "0123456789";
	var m_strCharacters = "!@#$%^&*?_~";
	
	// Reset combination count
	var score = 0;
	
	// Password length
	// -- Less than 4 characters
	if (theValue.length < 5)
	{
		score += 5;
	}
	// -- 5 to 7 characters
	else if (theValue.length > 4 && theValue.length < 8)
	{
		score += 10;
	}
	// -- 8 or more
	else if (theValue.length > 7)
	{
		score += 25;
	}

	// Letters
	var nUpperCount = countContain(theValue, m_strUpperCase);
	var nLowerCount = countContain(theValue, m_strLowerCase);
	var nLowerUpperCount = nUpperCount + nLowerCount;
	// -- Letters are all lower case
	if (nUpperCount == 0 && nLowerCount != 0) 
	{ 
		score += 10; 
	}
	// -- Letters are upper case and lower case
	else if (nUpperCount != 0 && nLowerCount != 0) 
	{ 
		score += 20; 
	}
	
	// Numbers
	var nNumberCount = countContain(theValue, m_strNumber);
	// -- 1 number
	if (nNumberCount == 1)
	{
		score += 10;
	}
	// -- 3 or more numbers
	if (nNumberCount >= 3)
	{
		score += 20;
	}
	
	// Characters
	var nCharacterCount = countContain(theValue, m_strCharacters);
	// -- 1 character
	if (nCharacterCount == 1)
	{
		score += 10;
	}	
	// -- More than 1 character
	if (nCharacterCount > 1)
	{
		score += 25;
	}
	
	// Bonus
	// -- Letters and numbers
	if (nNumberCount != 0 && nLowerUpperCount != 0)
	{
		score += 2;
	}
	// -- Letters, numbers, and characters
	if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)
	{
		score += 3;
	}
	// -- Mixed case letters, numbers, and characters
	if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)
	{
		score += 5;
	}
	
	return score;
}

// Checks a string for a list of characters
function countContain(strPassword, strCheck)
{ 
	// Declare variables
	var nCount = 0;
	
	for (i = 0; i < strPassword.length; i++) 
	{
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) 
		{ 
	        	nCount++;
		} 
	} 
 
	return nCount; 
} 

