function get_url_parameter(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if ( results == null )
      return "";
    else
      return results[1];
}


$(document).ready(function(){

$("#login").click(function() {

$("#success").hide();
$("#fail").hide();
$("#success2").hide();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();
$("#loading-login").html('');
$("#loading-register").html('');
$("#loading-password").html('');


$("#loading-login").html('<img src="http://www.mafiafamilies.net/images/loading.gif" title="Loading..." valign="middle" height="20" />');
  
$.ajax({
   	type: "POST",
   	url: "http://www.mafiafamilies.net/index/login.php",
	data: $('#loginForm').serialize(),
   	dataType: "json",   
   	cache: false,

success: function(msg){

if(msg.status == 1){

$("#success").show();
$("#fail").hide();
$("#success2").hide();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();

$("#login").attr('disabled','disabled');
$("#loading-login").html('<img src="http://www.mafiafamilies.net/images/success.png" width="21" height="21" title="Success!" />');
$("#success").html(msg.txt);

$('.registered').animate({height: "427"});
$('.login').animate({height: "427"});

setTimeout('go_to_redirect_page()', 1000);
}else if(msg.status == 0) {

$("#success").hide();
$("#fail").show();
$("#success2").hide();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();

$("#login").attr('disabled','');
$("#loading-login").html('<img src="http://www.mafiafamilies.net/images/fail.png" width="21" height="21" title="Failed!" />');
$("#fail").html(msg.txt);

$('.registered').animate({height: "427"});
$('.login').animate({height: "427"});
}




}




 });

return false;


	});
});


 function go_to_redirect_page()
{
    var redirect_parameter = get_url_parameter('redirect');
	var hash = window.location.hash;
    var redirect = ( redirect_parameter === "" ) ? 'http://www.mafiafamilies.net/'+hash  : redirect_parameter;

    window.location.href = window.location.href;
}

/****************        Register        ****************/


$(document).ready(function(){

$("#register").click(function(){

$("#success").hide();
$("#fail").hide();
$("#success2").hide();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();
$("#loading-login").html('');
$("#loading-register").html('');
$("#loading-password").html('');

$("#loading-register").html('<img src="http://www.mafiafamilies.net/images/loading.gif" title="Loading..." valign="middle" height="20" />');



$.ajax({
   	type: "POST",
   	url: "http://www.mafiafamilies.net/index/register.php",
	data: $('#regForm').serialize(),
   	dataType: "json",   
   	cache: false,

success: function(msg){


$("#script_check").fadeOut('slow');
$("#refresh").html('');

$("#script_check").load('http://www.mafiafamilies.net/script2.php' , function(){
$("#script_check").fadeIn('slow');
$("#refresh").html('<img id="refresh" src="http://www.mafiafamilies.net/images/icons/refresh.png" border="0" title="Refresh"/>');
});


if(msg.status == 1){

$("#success").hide();
$("#fail").hide();
$("#success2").show();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();


$("#player").val(msg.player);
$("#password").val(msg.pass);

$("#loading-register").html('<img src="http://www.mafiafamilies.net/images/success.png" width="21" height="21" title="Success!" />');
$("#success2").html(msg.txt);


$("#hide_1").hide();
$("#hide_2").hide();
$("#hide_3").hide();
$("#hide_4").hide();
$("#hide_5").hide();
$("#hide_6").hide();
$("#hide_7").hide();

$("#name").attr('disabled','disabled');
$("#email").attr('disabled','disabled');

$("#header_2").html('Successfully Registered!');
 
$('.login').animate({height: "320"}); 
$('.registered').animate({height: "320"}); 

$(".login").addClass("login active");


}else if(msg.status == 0) {

$("#success").hide();
$("#fail").hide();
$("#success2").hide();
$("#fail2").show();
$("#success3").hide();
$("#fail3").hide();

$("#loading-register").html('<img src="http://www.mafiafamilies.net/images/fail.png" width="21" height="21" title="Failed!" />');
$("#fail2").html(msg.txt);


$('.login').animate({height: "506"}); 

}




}






 });

return false;


	});
});


/****************        LOST PASSWORD        ****************/


$(function() {
$("#changePass").click(function() {

$("#success").hide();
$("#fail").hide();
$("#success2").hide();
$("#fail2").hide();
$("#success3").hide();
$("#fail3").hide();
$("#loading-login").html('');
$("#loading-register").html('');
$("#loading-password").html('');

$("#loading-password").html('<img src="http://www.mafiafamilies.net/images/loading.gif" title="Loading..." valign="middle" height="20"/>');
  
$.ajax({
   	type: "POST",
   	url: "http://www.mafiafamilies.net/index/change_pass.php",
	data: $('#passForm').serialize(),
   	dataType: "json",   
   	cache: false,

success: function(msg){

$("#script_check").fadeOut('slow');
$("#refresh").html('<img src="http://www.mafiafamilies.net/images/loading.gif" border="0" title="Loading..." valign="middle" height="20"/>');

$("#script_check").load('http://www.mafiafamilies.net/script2.php' , function(){
$("#script_check").fadeIn('slow');
$("#refresh").html('<img id="refresh" src="http://www.mafiafamilies.net/images/icons/refresh.png" border="0" title="Refresh"/>');
});


if(msg.status == 1){

$("#success").hide();
$("#fail").hide();
$("#fail2").hide();
$("#success2").show();

$("#loading-password").html('<img src="http://www.mafiafamilies.net/images/success.png" width="21" height="21" title="Success!" />');
$("#success2").html(msg.txt);
}else if(msg.status == 0) {
$("#success").hide();
$("#fail").hide();
$("#success2").hide();
$("#fail2").show();

$("#loading-password").html('<img src="http://www.mafiafamilies.net/images/fail.png" width="21" height="21" title="Failed!" />');
$("#fail2").html(msg.txt);
}

}

 });

return false;
	});
});



$(function(){
$("#refresh").click(function() {

$("#script_check").fadeOut('slow');
$("#refresh").html('<img src="http://www.mafiafamilies.net/images/loading.gif" border="0" title="Loading..." valign="middle" height="20"/>');

$("#script_check").load('http://www.mafiafamilies.net/script2.php' , function(){
$("#script_check").fadeIn('slow');
$("#refresh").html('<img id="refresh" src="http://www.mafiafamilies.net/images/icons/refresh.png" border="0" title="Refresh"/>');
});

return false;
	});
});

$(function(){
$("#refreshs").click(function() {

$("#script_check").fadeOut('slow');
$("#refreshs").html('<img src="http://www.mafiafamilies.net/images/loading.gif" border="0" title="Loading..." valign="middle" height="20"/>');

$("#script_check").load('http://www.mafiafamilies.net/script2.php' , function(){
$("#script_check").fadeIn('slow');
$("#refreshs").html('<img id="refreshs" src="http://www.mafiafamilies.net/images/icons/refresh.png" border="0" title="Refresh" />');
});

return false;
	});
});

