﻿function submitOnEnter(e) {
	if ((window.event && window.event.keyCode == 13) || e.keyCode == 13)
		doLogin();
}

function onRegisterPressed() {
    document.location = "/inregistrare.aspx";
}

function doLogin()
{
    var errors = "";
    
    if (trim(document.getElementById("txEmail").value) == "" || !isEmail(document.getElementById("txEmail").value))
        errors += " - introduceţi o adresă de e-mail validă\n";
    
    if (trim(document.getElementById("txPassword").value) == "")
        errors += " - introduceţi o parolă\n";
    
    if (errors.length > 0)
        alert("Vă rugăm să verificaţi următoarele probleme:\n" + errors);
    else
    {
        document.getElementById("hAction").value = "Login";
        document.getElementById('frmMain').submit();
    }
}

function doSubscribe(id) {
    var errors = "";

    name = trim(document.getElementById("txName").value);
    surname = trim(document.getElementById("txSurname").value);
    email = trim(document.getElementById("txEmail").value);
    password = trim(document.getElementById("txPassword").value);
    passwordAgain = trim(document.getElementById("txPasswordAgain").value);
    cnp = trim(document.getElementById("txCNP").value);
    phone = trim(document.getElementById("txPhone").value);
    country = document.getElementById("ddCountry").selectedIndex;
    city = trim(document.getElementById("txCity").value);
    address = trim(document.getElementById("txAdress").value);
    agree = document.getElementById("ckTerms").checked;

    if (name.length == 0)
        errors += " - completaţi numele\n";

    if (surname.length == 0)
        errors += " - completaţi prenumele\n";

    if (email.length == 0 || (!isEmail(email)))
        errors += " - introduceţi o adresă de e-mail validă\n";

    if (id == 0 || (id != 0 && password.length > 0)) {
        if (password.length < 6)
            errors += " - parola trebuie să aibă minim 6 caractere\n";
        
        if (passwordAgain.length == 0)
            errors += " - trebuie să confirmaţi parola în câmpul \"Parola, din nou\"\n";
        
        if (password != passwordAgain)
            errors += " - confirmarea parolei este incorectă\n";
    }

    if (cnp.length == 0)
        errors += " - completaţi CNP-ul\n";

    if (phone.length == 0)
        errors += " - introduceţi un număr de telefon valid\n";

    if (country == 0)
        errors += "- alegeti ţara\n";

    if (city.length == 0)
        errors += " - completaţi oraşul\n";
    
    if (address.length == 0) 
        errors += " - completaţi adresa\n";

    if (!agree)
        errors += " - trebuie să fiţi de acord cu condiţiile specificate\n";

    if (errors.length > 0)
        alert("Vă rugăm să verificaţi următoarele probleme:\n" + errors);
    else {
        document.getElementById("hAction").value = "Subscribe";
        document.getElementById('frmMain').submit();
    }
}

function showDiv(element) {
    document.getElementById(element).style.display = "block";
}

function hideDiv(element) {
    document.getElementById(element).style.display = "none";
}

