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 += getJSPH("Login_introduceti o adresa de e-mail valida")+" \n";
    }
    
    if (trim($("txPassword").value) == "")
    {
        errors += getJSPH("Login_introduceti o parola")+" \n";
    }
    
    if (errors.length > 0)
    {
        alert(getJSPH("Contact_RemediatiProblemele")+" \n" + errors);
    }
    else
    {
        $("hAction").value = "Login";
        document.getElementById('aspnetForm').submit();
    }
    
   
}

function doSubscribe()
{
    var errors = "";
    //Date pesonale
    if (trim($("txName").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Nume si prenume")+" \n";
    }
    if (trim($("txPhone").value).length == 0)
    {
        errors += getJSPH("Login_completati campul Telefon cu un numar de telefon valid")+" \n"; 
    }
    if (trim($("txBI").value).length == 0)
    {
        errors += getJSPH("Login_completati campul BI")+" \n"; 
    }
    //Informatii de livrare
    if ($("ddDeliveryCountry").selectedIndex == 0)
    {
        errors += getJSPH("Login_alegeti un judet la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryCity").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Localitate la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressStreet").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Strada la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressNo").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Numar la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressScara").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Scara la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressEtaj").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Etaj la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressAp").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul Apartament la Informatii de livrare")+" \n";
    }
    if (trim($("txDeliveryAddressCodPostal").value).length == 0) 
    {
        errors += getJSPH("Login_completati campul CodPostal la Informatii de livrare")+" \n";
    }
    //Informatii autentificare
    try{
        if ((trim($("txFormEmail").value) == "") || (!isEmail($("txFormEmail").value)))
        {
            errors += getJSPH("Login_introduceti o adresa de e-mail valida")+" \n";
        }
        if (trim($("txFormPassword").value).length < 6)
        {
            errors += getJSPH("Login_campul Parola trebuie sa aiba minim 6 caractere")+" \n";
        }
        if (trim($("txFormPasswordCheck").value) == "")
        {
            errors += getJSPH("Login_completati campul Parola, din nou")+" \n";
        }
        if (trim($("txFormPassword").value) != trim($("txFormPasswordCheck").value))
        {
            errors += getJSPH("Login_introduceti acelasi text in campurile Parola si Parola, din nou")+"\n";
        }
    }catch (ex){}
    //Alte informatii
    if ($("ddDomains").selectedIndex == 0)
    {
        errors += getJSPH("Login_alegeti un domeniu de activitate")+" \n";
    }
    //Informatii firma
    try{
        if ($("ckIsCompany").checked)
        {
            if (trim($("txCompanyName").value) == "")
            {
                errors += getJSPH("Login_campul Nume firma")+" \n";
            }
            if (trim($("txCF").value) == "")
            {
                errors += getJSPH("Login_completati campul Cod fiscal")+" \n";
            }
            //Informatii  Sediul social (pentru facturare)
           
            if ($("ddCountry").selectedIndex == 0)
            {
                errors += getJSPH("Login_alegeti un judet-sediu")+" \n";
            }
            if (trim($("txCity").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul Localitate-sediu")+" \n";
            }
//            if (trim($("txAddress").value).length == 0) 
//            {
//                errors += getJSPH("Login_completati campul Adresa-sediu")+" \n";
//            }
            if (trim($("txAddressStreet").value).length == 0) 
            {
            
                errors += getJSPH("Login_completati campul Strada-sediu")+" \n";
            }
            if (trim($("txAddressNo").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul Numar-sediu")+" \n";
            }
            if (trim($("txAddressScara").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul Scara-sediu")+" \n";
            }
            if (trim($("txAddressEtaj").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul Etaj-sediu")+" \n";
            }
            if (trim($("txAddressAp").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul Apartament-sediu")+" \n";
            }
            if (trim($("txAddressCodPostal").value).length == 0) 
            {
                errors += getJSPH("Login_completati campul CodPostal-sediu")+" \n";
            }
        }
    }catch (ex){}
    
    if (errors.length > 0)
    {
        alert(getJSPH("Contact_RemediatiProblemele")+" \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'))
        });
});

