/*****************************************************
filename: jquery.signup.js
description: contains needed functions to display
signup dialog and call signup.php to
create an account
created by: kailer
last modified by: kailer
*****************************************************/
// signup dialog
$(function(){
// vars
var username = $("#username"),
email = $("#email"),
password = $("#password"),
pass_confirm = $("#pass_confirm"),
country = $("#country"),
day = $("#day"),
month = $("#month"),
year = $("#year"),
country_code = $("#country_code"),
terms = $("#terms"),
dev_env = $("#dev_env").val();
// signup dialog links
$('#dialog_signup, #dialog_signup_tb, #dialog_signup_pn, #dialog_signup_pn2, #signup_link').click(function(){
if(dev_env == 1)
pageTracker._trackPageview('/regnumonline/signup');
if($("#player").length > 0)
$f("player").hide();
$('#dialog').dialog('open');
return false;
});
// terms dialog link
$('#dialog_terms').click(function(){
$('#termstext').dialog('open');
return false;
});
function checkLength(o,n,min,max)
{
if ( o.val().length > max || o.val().length < min )
return false;
else
return true;
}
function checkRegexp(o,regexp,n)
{
if (!(regexp.test(o.val())))
return false;
else
return true;
}
function showStatus(o,t,m)
{
var img = new Array("http://download01.regnumonlinegame.com/images/common/info.png","http://download01.regnumonlinegame.com/images/common/ok.png","http://download01.regnumonlinegame.com/images/common/error.png");
$("#"+o+"_icon").html("
");
$("#"+o+"_info").html(m);
$("#"+o+"_icon").fadeIn(600);
$("#"+o+"_info").fadeIn(600);
}
function hideStatus(o)
{
$("#"+o+"_icon").fadeOut(600);
$("#"+o+"_info").fadeOut(600);
}
function hideAllStatuses()
{
$(".tooltipMessage").css("display", "none");
$(".tooltipIcon").css("display", "none");
}
function showInfoTip(o)
{
$("#"+o+"_tip").fadeIn(600);
}
function hideInfoTip(o)
{
$("#"+o+"_tip").css("display", "none");
}
function showAjax(l)
{
if( $("#"+l+"_info").css("display") == "block" )
{
$("#"+l+"_info").css("display", "none");
$("#"+l+"_icon").css("display", "none");
}
$("#"+l+"_loader").css("display", "block");
}
function hideAjax(l)
{
$("#"+l+"_loader").css("display", "none");
}
function checkField(o)
{
if ($("#"+o+"_check").val() == "1")
return true;
else
{
if ( o == "birthdate")
{
showInfoTip("birthdate");
$("#day").focus();
} else
$("#"+o).focus();
return false;
}
}
function checkTerms(o)
{
if (o.attr('checked'))
{
$("#terms_check").val("1");
return true;
} else
{
showInfoTip("terms");
$("#terms_check").val("0");
return false;
}
}
function age(p_month,p_day,p_year)
{
month = $("#curmonth").val();
day = $("#curday").val();
year = $("#curyear").val();
if((month >= p_month && day >= p_day) || (month > p_month))
return (year - p_year);
else
return (year - p_year - 1);
}
// if input is focused, show info tip
$(".formLayer input, .formLayer select").focus(function()
{
var local_id = $(this).attr("id");
showInfoTip(local_id);
if(local_id == "day" || local_id == "month" || local_id == "year")
showInfoTip("birthdate");
if (local_id == "password" && $("#pass_confirm_check").val() == "0")
{
hideStatus("pass_confirm");
$("#pass_confirm").val("");
}
}).blur(function()
{
var local_id = $(this).attr("id");
var vtype = 0;
var validPass = true;
hideInfoTip(local_id);
if(local_id == "day" || local_id == "month" || local_id == "year")
hideInfoTip("birthdate");
if($("#"+local_id).val() != "")
{
switch (local_id)
{
case "username": vtype = 1; break;
case "email": vtype = 2; break;
}
if (local_id == "username" || local_id == "email")
{
showAjax(local_id);
$("#"+local_id).attr("readonly", true);
$("#"+local_id).css("background-color","#141414");
$.ajax({
type: "GET",
url: "sections/validator.php",
async: false,
data: "vtype="+vtype+"&vtext="+$(this).val(),
success: function(obtdata)
{
var v_result = "",
reg_exp = new RegExp ("1");
v_result = reg_exp.test(obtdata);
hideAjax(local_id);
if (v_result == true)
{
showStatus(local_id,1,"Válido");
$("#"+local_id+"_check").val("1");
$("#"+local_id).attr("readonly", false);
$("#"+local_id).css("background-color","#000000");
} else
{
showStatus(local_id,2,"Inválido o en uso");
$("#"+local_id+"_check").val("0");
$("#"+local_id).attr("readonly", false);
$("#"+local_id).css("background-color","#000000");
}
},
error: function()
{
alert("Your browser does not support JQuery correctly. You will be sent to a non JQuery signup page.\nSorry for any caused inconvenience.");
window.location = $("#alternate_signup").val();
}
});
} else if (local_id == "password")
{
validPass = validPass && checkLength(password,"password",6,30);
validPass = validPass && checkRegexp(password,/^([0-9a-zA-Z])+$/,"");
validPass = validPass && (username.val() != password.val());
if (!validPass)
{
showStatus(local_id,2,"Inválido");
$("#pass_confirm").attr("readonly", true);
$("#pass_confirm").css("background-color","#141414");
$("#"+local_id+"_check").val("0");
$("#pass_confirm_check").val("0");
} else
{
showStatus(local_id,1,"Válido");
$("#pass_confirm").attr("readonly", false);
$("#pass_confirm").css("background-color","#000000");
$("#"+local_id+"_check").val("1");
}
} else if (local_id == "pass_confirm")
{
validPass = validPass && (password.val() == pass_confirm.val());
if (!validPass)
{
showStatus(local_id,2,"No confirmado");
$("#"+local_id+"_check").val("0");
} else
{
showStatus(local_id,1,"Confirmado");
$("#"+local_id+"_check").val("1");
}
} else if (local_id == "day" || local_id == "month" || local_id == "year")
{
if (($("#month").val() != "") && ($("#day").val() != "") && ($("#year").val() != ""))
{
if(age($("#month").val(),$("#day").val(),$("#year").val()) >= 13)
{
showStatus("birthdate",1,"Mayor de 13 ańos");
$("#birthdate_check").val("1");
} else
{
showStatus("birthdate",2,"Menor de 13 ańos");
$("#birthdate_check").val("0");
}
}
}
} else
{
if(local_id == "day" || local_id == "month" || local_id == "year")
{
hideStatus("birthdate");
$("#birthdate_check").val("0");
} else if(local_id == "password")
{
$("#pass_confirm").attr("readonly", true);
$("#pass_confirm").css("background-color","#141414");
} else
{
hideStatus(local_id);
$("#"+local_id+"_check").val("0");
}
}
});
// signup dialog
$("#dialog").dialog({
autoOpen: false,
open: function() {
$(".ui-widget-header").css("background","url(http://download01.regnumonlinegame.com/images/spanish/headers/signup_header.png)");
$(this).css("visibility", "visible");
username.focus();
},
height: 435,
width: 300,
shadow: false,
resizable: false,
modal: true,
buttons: {
'Crear cuenta': function() {
var bValid = true;
bValid = bValid && checkField("username");
bValid = bValid && checkField("email");
bValid = bValid && checkField("password");
bValid = bValid && checkField("pass_confirm");
bValid = bValid && checkField("birthdate");
bValid = bValid && checkTerms(terms);
if (bValid) {
$("#dialog").dialog('option', 'buttons', { "Creando cuenta...": function() { } });
showInfoTip("creating");
$.ajax({
type: "POST",
url: "create_account.php",
data: "username="+username.val()+"&email="+email.val()+"&password="+password.val()+"&country="+country_code.val()+"&day="+$("#day").val()+"&month="+$("#month").val()+"&year="+$("#year").val()+"&ref="+$("#referer").val()+"&extra_dp="+$("#extra_dp").val()+"&extra_brand="+$("#extra_brand").val()+"&extra_locale="+$("#extra_locale").val(),
success: function(obtdata)
{
if (obtdata == "ok")
{
window.location = $("#landing_url").val();
} else
{
alert("There was an error processing data. Please communicate with support@ngdstudios.com.ar attaching the following data:\n\n"+obtdata);
window.location = $("#main_page").val();
}
}
});
}
},
'Cancelar' : function() {
$(this).dialog('close');
}
},
close: function() {
hideAllStatuses();
$("#addfrm").each(function(){this.reset();});
if($("#player").length > 0)
$f("player").show();
}
});
$("#termstext").dialog({
autoOpen: false,
open: function() {
$(this).css("visibility", "visible");
},
height: 435,
width: 300,
shadow: false,
resizable: false,
modal: false,
buttons: {
'Declinar': function()
{
$(this).dialog('close');
if (terms.attr('checked'))
{
terms.attr('checked',false)
}
},
'Aceptar': function()
{
$(this).dialog('close');
if (!terms.attr('checked'))
{
terms.attr('checked',true)
}
}
}
});
});