
//Username Availability
$(document).ready(function()
{
	$("#usnickname").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("registration_validity/user_availability.php",{usnickname:$(this).val()},function(data)
        {
		  if(data=='<img src=\"images/images/registration_arrow.gif\"/> Username is Not Available!') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(100,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
				  $(this).html(data).addClass('messageboxerror').fadeTo(400,1);
			});		
          }
		  else
		  {
		  	$("#msgbox").fadeTo(100,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Alle Felder sind Pflichtfelder!').addClass('messageboxok').fadeTo(400,1);	
			});
		  }
				
        });
 
	});
});


//Email Validation and Availability
$(document).ready(function()
{
	$("#usemail").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("registration_validity/user_email_availability.php",{usemail:$(this).val()},function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(100,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<img src="images/images/registration_arrow.gif"/> Email is Not Available!').addClass('messageboxerror').fadeTo(400,1);
			});		
          }
		  else if(data=='not')
		  {
		  	$("#msgbox").fadeTo(100,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<img src="images/images/registration_arrow.gif"/> Invalid Email!').addClass('messageboxok').fadeTo(400,1);	
			});
		  }
		  else if(data=='empty')
		  {
		  	$("#msgbox").fadeTo(100,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Alle Felder sind Pflichtfelder!').addClass('messageboxok').fadeTo(400,1);	
			});
		  }
		  else
		  {
		  	$("#msgbox").fadeTo(100,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Alle Felder sind Pflichtfelder!').addClass('messageboxok').fadeTo(400,1);	
			});
		  }
				
        });
 
	});
});


//Password1 Validity
$(document).ready(function()
{
	$("#uspassword1").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("registration_validity/user_password_validity.php",{uspassword1:$(this).val()},function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(100,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<img src="images/images/registration_arrow.gif"/> Password is too short!').addClass('messageboxerror').fadeTo(400,1);
			});		
          }
		  else
		  {
		  	$("#msgbox").fadeTo(100,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Alle Felder sind Pflichtfelder!').addClass('messageboxok').fadeTo(400,1);	
			});
		  }
				
        });
 
	});
});


//Password Strength Detector
function passwordStrength(password)
{
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	 document.getElementById("passwordDescription").innerHTML = desc[score];
	 document.getElementById("passwordStrength").className = "strength" + score;
}
