var http_login = createObject();
var http_forgot = createObject();

function page_login() {
    var inpt_log = dgeby_input_email.value;
    var inpt_pass = dgeby_input_password.value;
    if (inpt_log=="" || inpt_pass=="") {
        login_error_open();
    } else {
        var dati_login = "log=" + inpt_log + "&pass=" + inpt_pass;

        http_login.onreadystatechange = login_response;
        http_login.open('POST', '/utente/login_page_check.php', true);
        http_login.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        http_login.setRequestHeader("Content-length", dati_login.length);
        http_login.setRequestHeader("Connection", "close");
        http_login.send(dati_login);
    }
}
function login_response() {
    if(http_login.readyState == 4){
        var response_log = http_login.responseText;
        if (response_log=='ERROR') {
            login_error_open();
        } else {
            //dgeby_menu.innerHTML = response_log;
            window.open('/index', '_top');
        }
    }
}
function login_error_open() {
    dgeby_input_email.style.borderColor = '#888888';
    dgeby_input_password.style.borderColor = '#888888';
    dgeby_div_bkg.style.display = 'block';
    dgeby_error.style.display = 'block';

    dgeby_error_titolo.innerHTML = 'Avviso Login';
    dgeby_error_close.innerHTML = '<a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onclick="login_error_close(); return false;"onmouseover="MM_swapImage(\'error_close_img\',\'\',\'/images/x_blu.png\',1)"><img src="/images/x_grey.png" alt="Close" id="error_close_img" width="10px" height="10px" /></a>';
    dgeby_error_testo.innerHTML = 'Gentile Cliente,<br />per procedere alla login le chiediamo di controllare i dati inseriti';
    dgeby_error_button.innerHTML = '<a href="javascript:void(0)" onclick="login_error_close(); return false;"><input type="button" id="submit" value="Close" class="button" tabindex="21" /></a>';
}
function login_error_close() {
    dgeby_input_email.style.borderColor = '#E32219';
    dgeby_input_password.style.borderColor = '#E32219';
    fn_error_close();
}

function page_logout() {
    window.open('/utente/disconnect.php', '_top');
}
function page_forgot() {
    var inpt_forgot = dgeby_input_forgot.value;
    var dati_forgot = "forgot=" + inpt_forgot;

    http_forgot.onreadystatechange = page_forgotReply;
    http_forgot.open('POST', '/utente/forgot_check.php', true);
    http_forgot.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    http_forgot.setRequestHeader("Content-length", dati_forgot.length);
    http_forgot.setRequestHeader("Connection", "close");
    http_forgot.send(dati_forgot);
}
function page_forgotReply() {
    if(http_forgot.readyState == 4){
        dgeby_div_bkg.style.display = 'block';
        dgeby_error.style.display = 'block';
        var response_forgot = 0, html_print_testo;
        response_forgot = http_forgot.responseText;

        if (response_forgot=='OK') {
            animatedcollapse.hide('collections');
            html_print_testo = 'Gentile Cliente,<br />abbiamo provveduto ad inviarle al suo indirizzo e-mail una nuova password generata casualmente.<br />In qualsiasi momento potr&agrave; cambiarla nella sezione "Modifica i miei dati" accedendo al sito.<br /><br /><br />Cordialmente<br />Lo staff Digital Neon';
        } else {
            html_print_testo = 'Gentile Cliente,<br />siamo spiacenti ma l\'indirizzo e-mail inserito non &egrave; presente nel nostro database.<br />La invitiamo a controllare l\'indirizzo inserito o ad effettuare la procedura di registrazione.<br /><br /><br />Cordialmente<br />Lo staff Digital Neon';
        }
        dgeby_error_titolo.innerHTML = 'Recupero Password';
        dgeby_error_close.innerHTML = '<a href="javascript:void(0)" onmouseout="MM_swapImgRestore()"onclick="fn_error_close(); return false;"onmouseover="MM_swapImage(\'error_close_img\',\'\',\'/images/x_blu.png\',1)"><img src="/images/x_grey.png" alt="Close" id="error_close_img" width="10px" height="10px" /></a>';
        dgeby_error_testo.innerHTML = html_print_testo;
        dgeby_error_button.innerHTML = '<a href="javascript:void(0)" onclick="fn_error_close(); return false;"><input type="button" id="submit" value="Close" class="button" tabindex="21" /></a>';
    }
}
function fn_attivazione(input) {
    dgeby_error_titolo.innerHTML = 'Avviso Registrazione';
    dgeby_error_close.innerHTML = '<a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onclick="fn_attivazione_close(); return false;"onmouseover="MM_swapImage(\'error_close_img\',\'\',\'/images/x_blu.png\',1)"><img src="/images/x_grey.png" alt="Close" id="error_close_img" width="10px" height="10px" /></a>';
    if (input=='ATTIVATO') {
        dgeby_error_testo.innerHTML = 'Gentile Cliente,<br />le confermiamo l\'attivazione del suo account.<br /><br />&Egrave; possibile visualizzare o modificare i dati della registrazione effettuando il Login nell\'apposita sezione.';
    } else {
        dgeby_error_testo.innerHTML = 'Gentile Cliente,<br />le confermiamo la cancellazione del suo account.<br /><br />Per qualsiasi evenienza &egrave; possibile effettuare una nuova registrazione nell\'apposita sezione.';
    }
    dgeby_error_button.innerHTML = '<a href="javascript:void(0)" onclick="fn_attivazione_close(); return false;"><input type="button" id="submit" value="Close" class="button" tabindex="21" /></a>';
    dgeby_div_bkg.style.display = 'block';
    dgeby_error.style.display = 'block';
}
function fn_attivazione_close() {
    dgeby_error.style.display = 'none';
    dgeby_div_bkg.style.display = 'none';
}
function fc_mailing() {
    var alert_inp = document.getElementById('input_subscribe');
    if (isEmail(alert_inp.value)==1) {
        var dati_post_alert = "lm/lm.php?cmd=subscribe&list=Mailing&email=" + alert_inp.value;
        window.open('http://www.digitalneon.it/' + dati_post_alert, '_blank')
        alert_inp.value = 'your email address';
    } else {
        alert_inp.style.borderColor = '#E32219';
    }
}
