﻿/*	copyright www.laRouteDuNet.fr 2007

    gestion login

	ATTENTION: nécessite prototype.js, hash.js
*/

//if(typeof Prototype == 'undefined')
//  throw("login.js requires prototype.js library");
if(typeof MD5 == 'undefined')
  throw("login.js requires hash.js library");

var LoginAutomat = Class.create();

LoginAutomat.prototype = {
    initialize: function() {
        Event.observe(window, 'load', this.load.bind(this), false);             //init
    },
    load: function() {
        //la page est chargée
        var elm=$('login');
        if (elm) {
            Event.observe(elm, 'submit', this.submit.bindAsEventListener(this), false);
        }
        var elmget=$('loginget');
        if (elmget) {
            Event.observe(elmget, 'click', this.loginget.bindAsEventListener(this), false);
        }
    },
    submit: function(e) {
        var elm=Event.element(e);
        var TS=elm.elements['TS'];
        var DATA=elm.elements['DATA'];
        var PWD=elm.elements['PWD'];
        try {
            DATA.value=MD5.sign(TS.value+PWD.value);
            PWD.value='';
        }
        catch (err) {}
    },
    loginget: function(e) {
        var elm=$('login');
        if (elm) {
            var UID=elm.elements['UID'];
            UID.parentNode.childNodes[0].innerHTML='eMail';
            var PWD=elm.elements['PWD'];
            PWD.parentNode.style.display='none';
        }        
    }
}
LoginAutomat=new LoginAutomat();