//functii pentru formular
function validateForm(o) 
{
  f = o.form;
  return validate('email');  
}

function abonareUtilizator(o)
{
    $('#ajax-loader').show();
    
    f = o.form;
    var post_data = 'email=' + f['email'].value ;  
    
    
    $.ajax({
        type:        'post',
        url:        '/index.php?p=ajax&a=abonare-recomandari',
        data:        post_data,
        success:    function(r){
                if(r == '0')
                {           
                    //ok
                    $( '#abonare_recomandari' )[ 0 ].reset();
                    $( '#explicatii' ).hide();
                    $( '#mesaj_ok' ).css({'display':'block','margin-top':'25px','margin-bottom':'25px'}); 
                    $('#ajax-loader').hide();
                }
                if(r == '1')
                {
                    //adresa exista deja
                     $( '#eroare' ).css({'display':'block','margin-top':'25px','margin-bottom':'25px'}); 
                     $('#ajax-loader').hide();
                }                                
        },
        error:        function(){
            alert( "Eroare de trimitere.\nVa rugam contactati echipa InfoPensiuni.ro" );
            $('#ajax-loader').hide();
        }
    })
         
}

//functie js de validare a inputurilor
function validate(str)
{

    var err = 0;

    var str;

    var vector = str.split(",");

    for (i=0;i<vector.length;i++)

    {

        if (document.getElementById(vector[i]).value == "") {

            document.getElementById(vector[i]).style.backgroundColor = "#ffd8d8";

            err++;

        } else {

            document.getElementById(vector[i]).style.backgroundColor = "white";

        if ((vector[i]=='email') || (vector[i]=='email2') || (vector[i]=='email_exp') || (vector[i]=='email_dest')) { 

            var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

            if (!filter.test(document.getElementById(vector[i]).value)) {

            document.getElementById(vector[i]).style.backgroundColor = "#ffd8d8";


            err++;

            }

        }

        }

    }

    if (err > 0) {

        alert("Va rugam sa completati corect adresa de email");

        return false;

    } else {

        return true;

    }

}


function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     if(key == 13) document.getElementById('btnRecom').click(); 
          
     return (key != 13);
}


