var xmlHttp

/////////////////////////////checkOccupation//////////////////////////////////////////

function checkOccupation(choice, profileID)
{ 
xmlHttp=GetXmlHttpObjectOccupation()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkOccupation.php"
url=url+"?choice="+choice
url=url+"&profileID="+profileID
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedOccupation
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedOccupation() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("OccupationDiv").innerHTML=xmlHttp.responseText 
   } 
}


function GetXmlHttpObjectOccupation()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

/////////////////////////////checkPasswordStrength.js//////////////////////////////////////////

function checkPasswordStrength(password, nickName)
{ 
xmlHttp=GetXmlHttpObjectPasswordStrength()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkPasswordStrength.php"
url=url+"?Password="+password
url=url+"&NickName="+nickName
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedPasswordStrength
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedPasswordStrength() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("PasswordDiv").innerHTML=xmlHttp.responseText 
   } 
}


function GetXmlHttpObjectPasswordStrength()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

//////////////////////////////checkStringsCompare.js////////////////////////////////

function checkStringsCompare(str1,str2)
{ 
xmlHttp=GetXmlHttpObjectStringsCompare()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkStringsCompare.php"
url=url+"?str1="+str1
url=url+"&str2="+str2
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedStringsCompare
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function checkStringsCompare2(str1,str2)
{ 
xmlHttp=GetXmlHttpObjectStringsCompare()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkStringsCompare.php"
url=url+"?str1="+str1
url=url+"&str2="+str2
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedStringsCompare2
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}


function stateChangedStringsCompare() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("EmailCompareDiv").innerHTML=xmlHttp.responseText 
   } 
}

function stateChangedStringsCompare2() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("PasswordCompareDiv").innerHTML=xmlHttp.responseText 
   } 
}



function GetXmlHttpObjectStringsCompare()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

//////////////////////////////////////checkNick.js/////////////////////////////////

function checkNick(nickName)
{ 
xmlHttp=GetXmlHttpObjectNickName()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkNickName.php"
url=url+"?NickName="+nickName
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedNickName
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedNickName() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("NickDiv").innerHTML=xmlHttp.responseText 
   } 
}


function GetXmlHttpObjectNickName()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

//////////////////////////////////////checkNickReferrer.js/////////////////////////////////

function checkNickReferrer(nickNameReferrer)
{ 
xmlHttp=GetXmlHttpObjectNickName()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkNickNameReferrer.php"
url=url+"?NickNameReferrer="+nickNameReferrer
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedNickNameReferrer
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedNickNameReferrer() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("NickReferrerDiv").innerHTML=xmlHttp.responseText 
   } 
}


function GetXmlHttpObjectNickNameReferrer()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

//////////////////////////////////////confirmReferrer.js/////////////////////////////////
function confirmReferrer(nickNameReferrer, page)
	  {
		new Ajax.Updater('confirmReferrer', page, 
		{			
			onLoading:function(request)
			{
				//Element.show('subscriptions_indicator');
			}, 
			onComplete:function(request)
			{
				//Element.hide('subscriptions_indicator');
				//setTimeout("fixHeight()",700);
			}, 
			parameters:'action=confirmReferrer&nickNameReferrer='+nickNameReferrer, 
			evalScripts:true, 
			asynchronous:true
		})		
	  }

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=.wallst.net";
}

////////////////////////////////////////checkEmail.js////////////////////////////////

function checkEmail(email)
{ 
xmlHttp=GetXmlHttpObjectEmail()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url="http://login.wallst.net/checkEmail.php"
url=url+"?email="+email
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedEmail
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedEmail() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("EmailDiv").innerHTML=xmlHttp.responseText 
   } 
}


function GetXmlHttpObjectEmail()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

//////////////////////////////////passwordStrengthMeter.js/////////////////////////////////////

// Password strength meter
// This jQuery plugin is written by firas kassem [2007.04.05]
// Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/

var shortPass = 'Too short'
var badPass = 'Bad'
var goodPass = 'Good'
var strongPass = 'Strong'

function passwordStrength(password,username)
{
    score = 0 
    
    //password < 4
    if (password.length < 4 ) { return document.forms.step1Form.scoreImage.src = 'http://login.wallst.net/images/icon_ajax_password_strength_1.gif' }
    
    //password == username
    if (password.toLowerCase()==username.toLowerCase()) document.forms.step1Form.scoreImage.src = 'http://login.wallst.net/images/icon_ajax_password_strength_2.gif'
    
    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5 
    
    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 
    
    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10 
    
    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15 
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15 
    
    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15 
    
    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10 
    
    //verifing 0 < score < 100
    if ( score < 0 )  score = 0 
    if ( score > 100 )  score = 100 
    
	document.forms.step1Form.score.value = score
	
    if (score < 34 )  document.forms.step1Form.scoreImage.src = 'http://login.wallst.net/images/icon_ajax_password_strength_3.gif' 
    if (score < 68 )  document.forms.step1Form.scoreImage.src = 'http://login.wallst.net/images/icon_ajax_password_strength_4.gif'
    //return strongPass
}


// checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
// checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'

function checkRepetition(pLen,str) {
    res = ""
    for ( i=0; i<str.length ; i++ ) {
        repeated=true
        for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
            repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
        if (j<pLen) repeated=false
        if (repeated) {
            i+=pLen-1
            repeated=false
        }
        else {
            res+=str.charAt(i)
        }
    }
    return res
}

////////////////////////////////////passwordmeter.js//////////////////////////////////////////

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
Description: This is a quick and dirty password quality meter 
		 written in JavaScript so that the password does 
		 not pass over the network.
License: MIT License (see below)
Modified: 20060620 - added MIT License
Modified: 20061111 - corrected regex for letters and numbers
                     Thanks to Zack Smith -- zacksmithdesign.com
---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>

Permission is hereby granted, free of charge, to any person 
obtaining a copy of this software and associated documentation 
files (the "Software"), to deal in the Software without 
restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or 
sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following 
conditions:

   The above copyright notice and this permission notice shall 
be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
OR OTHER DEALINGS IN THE SOFTWARE. 
---------------------------------------------------------------


Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 1 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 1 (2 points): letters, numbers and special characters 
					exist
level 1 (2 points): mixed case letters, numbers and special 
					characters exist


NOTE: Because I suck at regex the code might need work
	  
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 testPassword(passwd)
{
		var intScore   = 0
		var strVerdict = "weak"
		var strLog     = ""
		
		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3)
			strLog   = strLog + "3 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6)
			strLog   = strLog + "6 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12)
			strLog   = strLog + "12 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18)
			strLog   = strLog + "18 point for length (" + passwd.length + ")\n"
		}
		
		
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
			strLog   = strLog + "1 point for at least one lower case char\n"
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one upper case char\n"
		}
		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one number\n"
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least three numbers\n"
		}
		
		
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one special char\n"
		}
		
									 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least two special chars\n"
		}
	
		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for upper and lower letters\n"
		}

		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for letters and numbers\n"
		}
 
									// [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for letters, numbers and special chars\n"
		}
	
	
		if(intScore < 16)
		{
		   strVerdict = "very weak"
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = "weak"
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = "mediocre"
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = "strong"
		}
		else
		{
		   strVerdict = "stronger"
		}
	
	document.forms.passwordForm.score.value = (intScore)
	document.forms.passwordForm.verdict.value = (strVerdict)
	document.forms.passwordForm.matchlog.value = (strLog)
	
}
