//delete link confirmation
function ConfirmDelete2Link (sUrl) {
    var answer = confirm ("Sunteti sigur ca doriti sa stergeti?\n\rApasati OK pentru DA");
    if (answer) {window.open (sUrl, '_self');}
}


function checkPassRecover(web_root){
    $("#error").hide();
    
    
    if ($("#recover_email").val()=="" || $("#recover_user").val()==""){
        $("#error").html("Ambele campuri trebuie completate pentru a recupera parola.");
        $("#error").slideDown('normal');
    } else {
        strOutput = $.ajax({
        url: web_root+"fe_ajax.php?action=checkRecoverPass&email="+$("#recover_email").val()+"&user="+$("#recover_user").val(),
        async: false
        }).responseText;
        
        if (strOutput=="ok") {
            $("#error").html("V-am trimis un email ce contine instructiuni pentru recuperarea parolei.");
            $("#error").slideDown('normal');            
        } else {
            $("#error").html("Userul sau adresa de email sunt gresite, va rugam sa verificati.");
            $("#error").slideDown('normal');                    
        }
    }
    
    return false
}

function doVisitorSubscribe(web_root){
    var cat_id = $("#sub_cats").val();
    var email = $("#sub_email").val();
    var strOutput = "";
    $("#sub_server_response").hide();
    
    if (email=="") {
        $("#sub_server_response").html("Va rugam sa completati adresa de email!");
        $("#sub_server_response").slideDown('normal');
    } else {        
        if (!echeck(email)) {
            $("#sub_server_response").html("Adresa de email pare introdusa gresit! <br />Va rugam sa verificati!");
            $("#sub_server_response").slideDown('normal');
        } else {
            strOutput = $.ajax({
            url: web_root+"fe_ajax.php?action=doVisitorSubscribe&cat_id="+cat_id+"&email="+email,
            async: false
            }).responseText;
            
            $("#sub_server_response").html(strOutput);
            $("#sub_server_response").slideDown('normal');
        }
    }
}




function getStaticFormContent(form_id, web_root, static_id){
    strOutput = $.ajax({
    url: web_root+"fe_ajax.php?action=getStaticForm&form_id="+form_id+"&static_id="+static_id,
    async: false
    }).responseText;
    
    $('#static_form').html(strOutput);
}



function checkRegisterForm(web_root){
    retVal = true;
    
    mandatory = 0;
    wrong_email = 0;
    passnomatch = 0;
    isunique = 0;
    isunique_user = 0;
    
    if ($('#username').val()=="") {
        retVal=false;mandatory=1;
    } else {
        strOutput = $.ajax({
        url: web_root+"fe_ajax.php?action=getUserCount&user="+$('#username').val(),
        async: false
        }).responseText;                
        
        if (strOutput!=0) {isunique_user = 1; retVal=false;}        
    }
    
    if ($('#password_one').val()=="") {retVal=false;mandatory=1;}
    if ($('#password_two').val()=="") {retVal=false;mandatory=1;}
    if ($('#password_one').val()!="" && $('#password_two').val()!="" && $('#password_one').val()!=$('#password_two').val()) {retVal=false; passnomatch=1;}
    if ($('#company').val()=="") {retVal=false;mandatory=1;}
    if ($('#city').val()=="") {retVal=false;mandatory=1;}
    if ($('#address').val()=="") {retVal=false;mandatory=1;}
    if ($('#contact_nume').val()=="") {retVal=false;mandatory=1;}
    if ($('#contact_prenume').val()=="") {retVal=false;mandatory=1;}
    if ($('#contact_email').val()=="") {retVal=false;mandatory=1;} else {
        if(echeck($('#contact_email').val())==false){
            retVal=false;wrong_email=1;
        } else {
            strOutput = $.ajax({
            url: web_root+"fe_ajax.php?action=getEmailCount&email="+$('#contact_email').val(),
            async: false
            }).responseText;                
            
            if (strOutput!=0) {isunique = 1; retVal=false;}
        }
    }

    if (retVal==false) {
        ehtml = "Nu am putut crea contul pentru ca am intampinat urmatoarele erori:<br />";
        if (mandatory==1) {ehtml = ehtml + "- nu ati completat toate campurile obligatorii<br />"}
        if (wrong_email==1) {ehtml = ehtml + "- adresa de email de contact nu este valida<br />"}
        if (passnomatch==1) {ehtml = ehtml + "- parola introdusa nu se verifica ("+$('#contact_email').val()+")<br />"}
        if (isunique==1) {ehtml = ehtml + "- adresa de email este deja folosita pentru un cont ("+$('#contact_email').val()+")<br />"}
        if (isunique_user==1) {ehtml = ehtml + "- utilizatorul este deja folosit pentru un cont ("+$('#username').val()+")<br />"}
        
        $('#error').html(ehtml);
        $('#error').slideDown('normal');
    }
    
    return retVal
}


function checkEmailValidationForm(web_root){
    
    $('#error').html('');$('#error').hide();
    
    c_email = $('#email').val()
    c_code = $('#confirm_code').val()
    
    if (c_email=="" || c_code=="") {
        $('#error').html('Ambele campuri trebuie completate');$('#error').slideDown('normal');
    } else {
        strOutput = $.ajax({
        url: web_root+"fe_ajax.php?action=checkEmailConfirmation&email="+c_email+"&code="+c_code,
        async: false
        }).responseText;
        
        $('#error').html(strOutput); $('#error').slideDown('normal');
    }
    
    return false
}


function checkLogin (web_root){
    $('#logerr').html(''); $('#logerr').hide();
    
    c_user = $('#username_login').val();
    c_pass = $('#passwd_login').val();
    
    if (c_user=="" || c_pass=="") {$('#logerr').html('completati ambele campuri');$('#logerr').slideDown('normal');} else {
        strOutput = $.ajax({
        url: web_root+"fe_ajax.php?action=doLoginCheck&user="+c_user+"&pass="+c_pass,
        async: false
        }).responseText;        
                
        
        if (strOutput=="good") {
            window.open (web_root+'contulmeu/','_self');
        } else {
            $('#logerr').html('acces respins');$('#logerr').slideDown('normal');
        }
    }
    
    return false
}


function checkAccountEditForm(){
    retVal = true;
    
    mandatory = 0;
    passmatch = 0;
    
    if ($('#username').val()=="") {retVal=false;mandatory=1;}
    if ($('#company').val()=="") {retVal=false;mandatory=1;}
    if ($('#city').val()=="") {retVal=false;mandatory=1;}
    if ($('#address').val()=="") {retVal=false;mandatory=1;}
    if ($('#contact_nume').val()=="") {retVal=false;mandatory=1;}
    if ($('#contact_prenume').val()=="") {retVal=false;mandatory=1;}    
    if ($('#password_one').val()!="" || $('#password_two').val()!=""){
        if ($('#password_one').val()!=$('#password_two').val()){
            passmatch = 1; retVal=false;
        }
    }
    
    if (retVal==false) {
        ehtml = "Nu am putut edita contul pentru ca am intampinat urmatoarele erori:<br />";
        if (mandatory==1) {ehtml = ehtml + "- nu ati completat toate campurile obligatorii<br />"}
        if (passmatch==1) {ehtml = ehtml + "- parolele introduse nu se verifica<br />"}
        
        $('#error').html(ehtml);
        $('#error').slideDown('normal');
    }
    
    return retVal    
}


//checking add event form
function checkAddEventForm(){
    retVal = true;
    
    mandatory = 0;
    email = 0;
    
    if ($('#title').val()=="") {retVal=false;mandatory=1;}
    if ($('#teaser').val()=="") {retVal=false;mandatory=1;}
    if ($('#xcontent').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_contact').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_email').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_web').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_email').val()!="") {if(!echeck($('#evcom_email').val())) {retVal=false;email=1;}}
    
    if (retVal==false) {
        ehtml = "Nu am putut adauga evenimentul pentru ca am intampinat urmatoarele erori:<br />";
        if (mandatory==1) {ehtml = ehtml + "- nu ati completat toate campurile obligatorii<br />"}
        if (email==1) {ehtml = ehtml + "- adresa de email nu este valida<br />"}
        
        $('#error').html(ehtml);
        $('#error').slideDown('normal');
    }    
    
    return retVal
}


//checking add comm form
function checkAddCommForm(){
    retVal = true;
    
    mandatory = 0;
    email = 0;
    
    if ($('#title').val()=="") {retVal=false;mandatory=1;}
    if ($('#teaser').val()=="") {retVal=false;mandatory=1;}
    if ($('#xcontent').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_contact').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_email').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_web').val()=="") {retVal=false;mandatory=1;}
    if ($('#evcom_email').val()!="") {if(!echeck($('#evcom_email').val())) {retVal=false;email=1;}}
    
    if (retVal==false) {
        ehtml = "Nu am putut adauga evenimentul pentru ca am intampinat urmatoarele erori:<br />";
        if (mandatory==1) {ehtml = ehtml + "- nu ati completat toate campurile obligatorii<br />"}
        if (email==1) {ehtml = ehtml + "- adresa de email nu este valida<br />"}
        
        $('#error').html(ehtml);
        $('#error').slideDown('normal');
    }    
    
    return retVal
}


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){           
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){           
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            return false
         }
        
         if (str.indexOf(" ")!=-1){
            return false
         }

          return true                    
    }
 
