var username_min = 2;var username_max = 25;var password_min = 5;var password_max = 35;var ajax_delay = 1500;var timeOn = null;var desc_min = 2;var desc_max = 300;var icon_error = "
";
var icon_ok = "
";
var icon_process = "
";
var cur_file="registrarse.php"; //window.location;
var error_flag=0;var first_error="";
i_error = new Image(); i_error.src = "templates/default/images/error.gif";
i_ok = new Image(); i_ok.src = "templates/default/images/ok.gif";
i_process = new Image(); i_process.src = "templates/default/images/gif.gif";
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function isBlank(val){
if(val==null){return true;}
for(var i=0;i< val.length;i++) {
if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false; }
}
return true;
}
function set_first_error(err_type){
if (!first_error && err_type){
first_error=err_type;
return first_error;
}
}
function validar_email(valor,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(valor)
{
if(check_email(valor))
{
document.getElementById("email_error").innerHTML = " " + icon_ok;
document.getElementById('email').className = 'txt_ok';
if(timeOn) clearTimeout(timeOn);
timeOn = setTimeout("email_check('"+valor+"')",ajax_delay);
}
else
{
if(timeOn) clearTimeout(timeOn);
document.getElementById('email').className = 'txt_error';
document.getElementById("email_error").innerHTML = " " + icon_error + " Por favor, introduce un e-mail válido";
}
}
/*
else
{
document.getElementById("email_error").innerHTML = " " + icon_error + " Por favor, rellena el campo e-mail";
document.getElementById('email').className = 'txt_error';
}
*/
}
}
function mail_error(valor)
{
if(valor)
{
if(!check_email(valor))
{
document.getElementById('email').className = 'txt_error';
document.getElementById("email_error").innerHTML = " " + icon_error + " Por favor, introduce un e-mail válido";
}
}
/*
else
{
document.getElementById('email').className = 'txt_error';
document.getElementById("email_error").innerHTML = " " + icon_error + " Por favor, rellena el campo e-mail";
}
*/
}
function check_email(valor)
{
return /^[a-z0-9_\.\-]+@[a-z0-9_\.\-]+(\.[a-z0-9_]{2,3})+$/i.test(valor);
}
// AJAX email availability check
function email_check(email)
{
if(timeOn) clearTimeout(timeOn);
document.getElementById('email_error').innerHTML = icon_process + " Comprobando disponibilidad del e-mail";
__$.ajax({
url: "registrarse_ajax_email_check.php?email="+email,
cache: false,
beforeSend: function (req){
//show_loader('#email_error');
return req;
},
complete: function (req,status){
return req;
},
success: function(html){
__$('#email_error').html(html);
if (__$('#email_result').attr("value")=='available'){
__$('#email').removeClass("txt_ok");
__$('#email').addClass("txt_ok");
check_all_errors();
}
if(__$('#email_result').attr("value")=='taken'){
__$('#email').removeClass('txt_error');
__$('#email').addClass('txt_error');
}
}
});
}
// change the icon of the selected country
function change_contry_icon(value)
{
__$.ajax({
url: "registrarse_ajax_country_icon.php?pais="+value,
cache: false,
beforeSend: function (req){
//show_loader('#pais_error');
return req;
},
complete: function (req,status){
return req;
},
success: function(html){
//hide_loader();
__$('#pais_icono').html(html);
}
});
}
// dynamic validate for country
function select_country(value)
{
if(value==0)
{
document.getElementById('idpais').className = 'txt_error';
document.getElementById("pais_error").innerHTML = " " + icon_error + " Por favor, selecciona un pais";
}
else
{
document.getElementById('idpais').className = 'txt_ok';
document.getElementById("pais_error").innerHTML = " " + icon_ok;
check_all_errors();
}
}
// dynamic validate for description
function count_char(text,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
var karakter = text.length ;
var cr = text.split("\n");
karakter = karakter - cr.length + 1;
if(karakter > desc_max)
{
var tmp = text.substr(0,desc_max+cr.length-1);
document.getElementById('descripcion').value = tmp;
karakter = desc_max;
}
if(karakter < desc_max)
{
document.getElementById('descripcion').className = 'txt_ok';
document.getElementById('descripcion_error').innerHTML = " " + icon_ok;
}
document.getElementById('desc_count').innerHTML = karakter;
}
}
function check_description(text)
{
if(text && text.length < desc_min)
{
document.getElementById('descripcion_error').innerHTML = " " + icon_error + " El mínimo número de caracteres para este campo es de " + desc_min;
document.getElementById('descripcion').className = 'txt_error';
}
if(!text)
{
document.getElementById('descripcion').className = 'txt';
check_all_errors();
}
}
function valid_username(text)
{
return text ? /^([a-zA-ZçñáéíóúàèìòùüïöüÁÉÍÓÚÀÈÌÒÙÜÏÖÜ\s0-9-]+)$/i.test(text): false;
/*
var valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-";
var valid_entry = true;
for(var i=0; i < text.length; i++)
{
if (valid_chars.indexOf(text.charAt(i)) == -1) valid_entry = false;
}
return valid_entry;
*/
}
function user_validate(text,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(text)
{
if(valid_username(text))
{
if(text.length <= username_max)
{
document.getElementById('usuario_error').innerHTML = "";
document.getElementById('usuario').className = 'txt_selected';
if(timeOn) clearTimeout(timeOn);
timeOn = setTimeout("user_check('"+text+"')",ajax_delay);
}
if(text.length > username_max) document.getElementById('usuario').value = document.getElementById('usuario').value.substr(0,username_max);
}
else
{
if(timeOn) clearTimeout(timeOn);
document.getElementById('usuario').className = 'txt_error';
document.getElementById("usuario_error").innerHTML = " " + icon_error + " No se admiten caracteres especiales ni espacios en el campo usuario";
}
}
else
{
document.getElementById('usuario').className = 'txt_selected';
document.getElementById("usuario_error").innerHTML = " " ;
if(timeOn) clearTimeout(timeOn);
}
}
}
function check_user_ok(text)
{
if(text)
{
if(valid_username(text))
{
if(document.getElementById('username_result'))
{
if(document.getElementById('username_result').value=='taken') document.getElementById('usuario').className = 'txt_error';
else {
document.getElementById('usuario').className = 'txt_ok';
}
}
//else user_check(text);
}
}
}
// AJAX user availability check
function user_check(username)
{
if(timeOn) clearTimeout(timeOn);
if(username && username.length < username_min)
{
document.getElementById('usuario').className = 'txt_error';
document.getElementById("usuario_error").innerHTML = " " + icon_error + " El mínimo número de caracteres para este campo es de " + username_min;
}
else
{
document.getElementById('usuario_error').innerHTML = icon_process + " Comprobando disponibilidad del nombre de usuario";
__$.ajax({
url: "registrarse_ajax_username_check.php?username="+username,
cache: false,
beforeSend: function (req){
//show_loader('#usuario_error');
return req;
},
complete: function (req,status){
return req;
},
success: function(html){
__$('#usuario_error').html(html);
if (__$('#username_result').attr ("value")=='available'){
__$('#usuario').removeClass('txt_ok');
__$('#usuario').addClass('txt_ok');
check_all_errors();
}
if(__$('#username_result').attr("value")=='taken'){
__$('#usuario').removeClass('txt_error');
__$('#usuario').addClass('txt_error');
}
}
});
}
}
function check_key(e)
{
var code=0;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
return code;
}
// password validate
function password_check(text,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(text)
{
document.getElementById("repetir_password_error").innerHTML = " ";
document.getElementById("repetir_password_error").style.display = 'none';
document.getElementById("password_error").innerHTML = " " + icon_ok;
document.getElementById('password').className = 'txt_ok';
if(text && text.length < password_min)
{
document.getElementById('password').className = 'txt_error';
document.getElementById("password_error").innerHTML = "" + icon_error + " El mínimo número de caracteres para el campo contraseña es de " + password_min;
}
if(text && text.length > password_max)
{
document.getElementById('password').className = 'txt_error';
document.getElementById("password_error").innerHTML = "" + icon_error + " El máximo número de caracteres para el campo contraseña es de " + password_max;
}
check_all_errors();
}
else
{
document.getElementById("password_error").innerHTML = " ";
document.getElementById('password').className = 'txt_selected';
}
}
}
function password_match(e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(document.getElementById('password').value == document.getElementById('repetir_password').value && document.getElementById('repetir_password').value)
{
document.getElementById('repetir_password').className = 'txt_ok';
document.getElementById("repetir_password_match").innerHTML = " " + icon_ok ;
document.getElementById("repetir_password_error").innerHTML = " ";
document.getElementById("repetir_password_error").style.display = 'none';
}
else
{
document.getElementById("repetir_password_match").innerHTML = " " ;
document.getElementById('repetir_password').className = 'txt_selected';
}
}
}
function password_match_ok(e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(document.getElementById('password').value != document.getElementById('repetir_password').value)
{
if(document.getElementById('repetir_password').value.length>0)
{
document.getElementById('repetir_password').className = 'txt_error';
document.getElementById("repetir_password_match").innerHTML = " ";
document.getElementById("repetir_password_error").innerHTML = "" + icon_error + " Los campos contraseña y repetir contraseña deben coincidir";
document.getElementById("repetir_password_error").style.display = 'inline';
}
}
if(document.getElementById('password').value == document.getElementById('repetir_password').value && document.getElementById('repetir_password').value)
{
document.getElementById('repetir_password').className = 'txt_ok';
document.getElementById("repetir_password_match").innerHTML = " " + icon_ok ;
document.getElementById("repetir_password_error").innerHTML = " ";
document.getElementById("repetir_password_error").style.display = 'none';
check_all_errors();
}
/*
if(document.getElementById('password').value && !document.getElementById('repetir_password').value)
{
document.getElementById('repetir_password').className = 'txt_error';
document.getElementById("repetir_password_match").innerHTML = " ";
document.getElementById("repetir_password_error").innerHTML = "" + icon_error + " Por favor, rellena el campo Repetir contraseña";
document.getElementById("repetir_password_error").style.display = 'inline';
}
if(!document.getElementById('password').value && !document.getElementById('repetir_password').value)
{
document.getElementById('repetir_password').className = 'txt_error';
document.getElementById("repetir_password_error").innerHTML = " " + icon_error + " Por favor, rellena el campo contraseña";
document.getElementById("repetir_password_error").style.display = 'inline';
}
*/
}
}
// validate nombre & apellido
function check_nombre_apellido(text,obj,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(obj=='nombre')
{
if(text)
{
if(valid_nombre(text))
{
document.getElementById('nombre').className = 'txt_ok';
document.getElementById("nombre_error").innerHTML = " " + icon_ok;
check_all_errors();
}
else
{
document.getElementById('nombre').className = 'txt_error';
document.getElementById("nombre_error").innerHTML = " " + icon_error + " Por favor, utiliza sólo caracteres válidos";
}
}
else
{
document.getElementById('nombre').className = 'txt_selected';
document.getElementById("nombre_error").innerHTML = " ";
}
}
if(obj=='apellido')
{
if(text)
{
if(valid_nombre(text))
{
document.getElementById('apellido').className = 'txt_ok';
document.getElementById("apellido_error").innerHTML = " " + icon_ok;
check_all_errors();
}
else
{
document.getElementById('apellido').className = 'txt_error';
document.getElementById("apellido_error").innerHTML = " " + icon_error + " Por favor, utiliza sólo caracteres válidos";
}
}
else
{
document.getElementById('apellido').className = 'txt_selected';
document.getElementById("apellido_error").innerHTML = " " ;
}
}
}
}
function valid_nombre(text)
{
return /[a-zA-ZÀ-Ÿ\s]/i.test(text);
}
function valid_apellido(text)
{
var valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
var valid_entry = true;
for(var i=0; i < text.length; i++)
{
if (valid_chars.indexOf(text.charAt(i)) == -1) valid_entry = false;
}
return valid_entry;
}
// validate URL
function check_URL(text,e)
{
if(check_key(e)!=9 && check_key(e)!=13)
{
if(text)
{
if(valid_URL(text))
{
document.getElementById('url').className = 'txt_ok';
document.getElementById("url_error").innerHTML = " " + icon_ok;
check_all_errors();
}
else
{
document.getElementById('url').className = 'txt_selected';
document.getElementById("url_error").innerHTML = " ";
}
}
else document.getElementById("url_error").innerHTML = " ";
}
}
function URL_error(text)
{
if(text)
{
if(!valid_URL(text))
{
document.getElementById("url").className = 'txt_error';
document.getElementById("url_error").innerHTML = " " + icon_error + " Por favor, introduce una dirección URL válida.";
}
}
else
{
document.getElementById("url_error").innerHTML = " ";
document.getElementById('url').className = 'txt';
}
}
function valid_URL(s)
{
var regexp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
return regexp.test(s);
}
// check contact permit
function check_contacto_permitir(value)
{
if(!value)
{
document.getElementById('permitir_contacto').className = 'txt_error';
document.getElementById("permitir_contacto_error").innerHTML = " " + icon_error + " Por favor, selecciona si deseas o no permitir que contacten contigo";
}
else
{
document.getElementById('permitir_contacto').className = 'txt_ok';
document.getElementById("permitir_contacto_error").innerHTML = " " + icon_ok;
check_all_errors();
}
}
// check anonymous
function check_anonimo(value)
{
if(!value)
{
document.getElementById('anonimo').className = 'txt_error';
document.getElementById("anonimo_error").innerHTML = " " + icon_error + " Por favor, selecciona si quieres mostrar tu nombre o aparecer como anónimo";
}
else
{
document.getElementById('anonimo').className = 'txt_ok';
document.getElementById("anonimo_error").innerHTML = " " + icon_ok;
check_all_errors();
}
}
function upload_avatar(file)
{
if(file)
{
archivo_upload();
document.getElementById("avatar_error").innerHTML = " " + icon_ok;
document.getElementById("avatar").className = "";
check_all_errors();
}
}
// Show and hide help on the form
// show help messages in forms
function showHelp(message) {
$(message).style.display="block";
}
// hide help messages in forms
function hideHelp(message) {
$(message).style.display="none";
}
function loadRegisterHelp() {
// show help message actions
// Event.observe('usuario', 'focus', function(e){ showHelp('help_usuario') });
// hide help message actions
// Event.observe('usuario', 'blur', function(e){ hideHelp('help_usuario') });
}
function blur_field(dis){
clsName=dis.className;
if (clsName){
clsName=clsName.replace("txt_selected","txt");
dis.className=clsName;
}
}
function show_loader(origin){
__$(origin).append("
|