function submitOnEnter(e) {
	if (window.event && window.event.keyCode == 13) {
		doLogin();
	}
	else if (e.keyCode == 13) {
		doLogin();
	}
}

function onRegisterPressed()
{
    document.location="Inregistrare.aspx";
}

function onNotRegisterPressed()
{
    $("hAction").value = "SkipRegister";
    document.getElementById('aspnetForm').submit();
}

function doLogin()
{
    var errors = "";
    if ((trim($("txEmail").value) == "") || (!isEmail($("txEmail").value)))
    {
        errors += ("Introduceti o adresa de e-mail valida")+" \n";
    }
    
    if (trim($("txPassword").value) == "")
    {
        errors += ("Introduceti o parola")+" \n";
    }
    
    if (errors.length > 0)
    {
        alert(("Remediati problemele")+" \n" + errors);
    }
    else
    {
        $("hAction").value = "Login";
        document.getElementById('aspnetForm').submit();
    }
    
   
}

function doSubscribe()
{
    var errors = "";
    //Date pesonale
    if (trim($("txName").value).length == 0) 
    {
        errors += ("Login_completati campul Nume si prenume")+" \n";
    }
    if (trim($("txPhone").value).length == 0)
    {
        errors += ("Login_completati campul Telefon cu un numar de telefon valid")+" \n"; 
    }
    if (trim($("txBI").value).length == 0)
    {
        errors += ("Login_completati campul BI")+" \n"; 
    }
    //Informatii de livrare
    if ($("ddDeliveryCountry").selectedIndex == 0)
    {
        errors += ("Login_alegeti un judet")+" \n";
    }
    if (trim($("txDeliveryCity").value).length == 0) 
    {
        errors += ("Login_completati campul Localitate")+" \n";
    }
    if (trim($("txDeliveryAddress").value).length == 0) 
    {
        errors += ("Login_completati campul Adresa")+" \n";
    }
    //Informatii autentificare
    try{
        if ((trim($("txFormEmail").value) == "") || (!isEmail($("txFormEmail").value)))
        {
            errors += ("Introduceti o adresa de e-mail valida")+" \n";
        }
        if (trim($("txFormPassword").value).length < 6)
        {
            errors += ("Login_campul Parola trebuie sa aiba minim 6 caractere")+" \n";
        }
        if (trim($("txFormPasswordCheck").value) == "")
        {
            errors += ("Login_completati campul Parola, din nou")+" \n";
        }
        if (trim($("txFormPassword").value) != trim($("txFormPasswordCheck").value))
        {
            errors += ("Introduceti acelasi text in campurile Parola si Parola, din nou")+"\n";
        }
    }catch (ex){}
    //Alte informatii
    /*if ($("ddDomains").selectedIndex == 0)
    {
        errors += ("Login_alegeti un domeniu de activitate")+" \n";
    }*/
    //Informatii firma
    try{
        if ($("ckIsCompany").checked)
        {
            if (trim($("txCompanyName").value) == "")
            {
                errors += ("Login_campul Nume firma")+" \n";
            }
            if (trim($("txCF").value) == "")
            {
                errors += ("Login_completati campul Cod fiscal")+" \n";
            }
            //Informatii  Sediul social (pentru facturare)
            if ($("ddCountry").selectedIndex == 0)
            {
                errors += ("Login_alegeti un judet-sediu")+" \n";
            }
            if (trim($("txCity").value).length == 0) 
            {
                errors += ("Login_completati campul Localitate-sediu")+" \n";
            }
            if (trim($("txAddress").value).length == 0) 
            {
                errors += ("Login_completati campul Adresa-sediu")+" \n";
            }
        }
    }catch (ex){}
    
    if (errors.length > 0)
    {
        alert(("Remediati problemele")+" \n" + errors);
    }
    else
    {
        $("hAction").value = "Subscribe";
        document.getElementById('aspnetForm').submit();
    }
}

function showDiv(element)
{
    $(element).style.display = "block";
}

function hideDiv(element)
{
    $(element).style.display = "none";
}

jQuery(document).ready(function($){
    //Initialize the element state
    toggleElement($('#companyToggler input'),$('#dvCompany'));

    $('#companyToggler input')
        .bind('click change',function(){
            toggleElement($('#companyToggler input'),$('#dvCompany'))
        });
});


