function check_enter_login(myfield,e){
    var keycode;
    if (window.event){ keycode = window.event.keyCode;
    }else if (e){ keycode = e.which;
    }else{ return true; }
    if (keycode == 13){
        public_login();
        return false;
    }
    else{ return true; }
}
Element.Events.login = {
};
Element.Events.logout = {
};
function public_login(){
    var id_cuenta=$('idcuenta_login').value;
    var contrasena=$('contrasena_login').value;
    var variables='';
    //if($('persistencia_login').checked){
        variables='idcuenta='+id_cuenta+'&contrasena='+contrasena+'&type=p'+'&persistencia=1';
    //}else{
        //variables='idcuenta='+id_cuenta+'&contrasena='+contrasena+'&type=p';
    //}
    var enviarLogin=new Request({
        mehtod: 'post',
        url: 'http://satirarpg.com/'+the_locale+'/login.html',
        encoding: 'utf-8',
        noCache: true,
        onRequest: function(){
            $('theloginbox').innerHTML='<img src="img/loading/loading2.gif" />';
        },
        onFailure: function(){
            $('theloginbox').innerHTML='<form name="formlogin" action="http://satirarpg.com/'+the_locale+'/login.html" method="POST"><em>'+the_id_account_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="text" name="idcuenta" id="idcuenta_login" onkeypress="return check_enter_login(this,event)" /><em>'+the_password_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="password" name="contrasena" id="contrasena_login" onkeypress="return check_enter_login(this,event)" /><input id="contenedor_top_login_submit" onmouseout="rollout_send_button(this)" onmouseover="rollover_send_button(this)" style="background-image: url(\'img/botones/enviar_577.jpg\'); width: 38px; background-position: 0pt 0pt; background-repeat: no-repeat; height: 10px; border-style: none; cursor: pointer;" value=" " type="button" name="enviar" onclick="public_login()" /><input id="persistencia_login" name="persistencia" type="hidden" value="1" /> </form>';
            alert(the_try_again_later_message);
            acomodar_plantilla();
        },
        onSuccess: function(responseText, responseXML){
            if(responseText.substring(0,1)=='s'){
                $('theloginbox').innerHTML='<form name="formlogout" action="http://satirarpg.com/'+the_locale+'/logout.html" method="POST"><strong>'+the_welcome_message+' '+responseText.substring(1)+'</strong> <input type="button" value="'+the_logout_message+'" class="txtbutton" onclick="public_logout()" /></form>';
                is_logged_in=true;
				if(reload_when_logged){
					window.location=the_page;
				}else{
					acomodar_plantilla();
                                        window.fireEvent('login');
				}
            }else{
                is_logged_in=false;
				acomodar_plantilla();
                if(responseText.substring(0,1)=='t'){
                    $('theloginbox').innerHTML='<form name="formlogin" action="http://satirarpg.com/'+the_locale+'/login.html" method="POST"><em>'+the_id_account_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="text" name="idcuenta" id="idcuenta_login" onkeypress="return check_enter_login(this,event)" /><em>'+the_password_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="password" name="contrasena" id="contrasena_login" onkeypress="return check_enter_login(this,event)" /><input id="contenedor_top_login_submit" onmouseout="rollout_send_button(this)" onmouseover="rollover_send_button(this)" style="background-image: url(\'img/botones/enviar_577.jpg\'); width: 38px; background-position: 0pt 0pt; background-repeat: no-repeat; height: 10px; border-style: none; cursor: pointer;" value=" " type="button" name="enviar" onclick="public_login()" /><input id="persistencia_login" name="persistencia" type="hidden" value="1" /> </form>';
                    alert(the_logged_times_error);
                }else{
                    $('theloginbox').innerHTML='<form name="formlogin" action="http://satirarpg.com/'+the_locale+'/login.html" method="POST"><em>'+the_id_account_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="text" name="idcuenta" id="idcuenta_login" onkeypress="return check_enter_login(this,event)" /><em>'+the_password_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="password" name="contrasena" id="contrasena_login" onkeypress="return check_enter_login(this,event)" /><input id="contenedor_top_login_submit" onmouseout="rollout_send_button(this)" onmouseover="rollover_send_button(this)" style="background-image: url(\'img/botones/enviar_577.jpg\'); width: 38px; background-position: 0pt 0pt; background-repeat: no-repeat; height: 10px; border-style: none; cursor: pointer;" value=" " type="button" name="enviar" onclick="public_login()" /><input id="persistencia_login" name="persistencia" type="hidden" value="1" /> </form>';
                    alert(the_user_password_error);
                }
            }
        }
    });
    enviarLogin.send(variables);
}
function public_logout(){
    var variables='type=p';
    var enviarLogout=new Request({
        mehtod: 'post',
        url: 'http://satirarpg.com/es/logout.html',
        encoding: 'utf-8',
        noCache: true,
        onRequest: function(){
            $('theloginbox').innerHTML='<img src="img/loading/loading2.gif" />';
        },
        onFailure: function(){
            $('theloginbox').innerHTML='<form name="formlogout" action="http://satirarpg.com/'+the_locale+'/logout.html" method="POST"><strong>'+the_welcome_message+' '+responseText.substring(1)+'</strong> <input type="button" value="'+the_logout_message+'" class="txtbutton" onclick="public_logout()" /></form>';
            alert(the_try_again_later_message);
            acomodar_plantilla();
        },
        onSuccess: function(responseText, responseXML){
            $('theloginbox').innerHTML='<form name="formlogin" action="http://satirarpg.com/'+the_locale+'/login.html" method="POST"><em>'+the_id_account_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="text" name="idcuenta" id="idcuenta_login" onkeypress="return check_enter_login(this,event)" /><em>'+the_password_message+'</em><input style="border-style: hidden; height: 8px; width: 34px; font-size: 8px;" type="password" name="contrasena" id="contrasena_login" onkeypress="return check_enter_login(this,event)" /><input id="contenedor_top_login_submit" onmouseout="rollout_send_button(this)" onmouseover="rollover_send_button(this)" style="background-image: url(\'img/botones/enviar_577.jpg\'); width: 38px; background-position: 0pt 0pt; background-repeat: no-repeat; height: 10px; border-style: none; cursor: pointer;" value=" " type="button" name="enviar" onclick="public_login()" /><input id="persistencia_login" name="persistencia" type="hidden" value="1" /> </form>';
            is_logged_in=false;
			if(reload_when_logged){
				window.location=the_page;
			}else{
            	acomodar_plantilla();
                window.fireEvent('logout');
			}
        }
    });
    enviarLogout.send(variables);
    return false;
}
