//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 cont_ShowRequestResponses(reqid, page, tagid){
    strOutput = "";
    
    if($('#req_response_'+reqid).html()==""){
        strOutput = $.ajax({
        url: "ajax/ajax.utils.php?action=show_responses&id=" + reqid + "&page=" + page + "&tag_id=" + tagid,
        async: false
        }).responseText;            
        
        $('#req_response_'+reqid).html(strOutput);
        $('#req_response_'+reqid).slideDown('fast');                
    }else{
        $('#req_response_'+reqid).html('');
        $('#req_response_'+reqid).slideUp('fast');                
    }
    

}

function cont_MarkResponseAsWinner(reqid, respid){
    
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=mark_response_as_winner&reqid=" + reqid + "&respid=" + respid,
    async: false
    }).responseText;    
    
    cont_ShowRequestResponses(reqid,1);
}

function cont_CleanRequestWinner(reqid){
    
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=clean_request_winner&reqid=" + reqid,
    async: false
    }).responseText;    
    
    cont_ShowRequestResponses(reqid,1);
}

function showContactDetails(uid){
    strOutput = "";

    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=show_user_details&id=" + uid,
    async: false
    }).responseText;    
    
    $('#contact_details').html(strOutput);
    $('#contact_details').slideDown('normal');    
}


function doSearch(rurl){
    sk = $('#search_key').val();
    sci = $('#search_category_id').val();
    
    if(sk!=""){        
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=marksearch&sk=" + sk,
    async: false
    }).responseText;
    
    sk = sk.replace(" ","-");
    urlus = rurl+"cauta/"+sk+"_"+sci+"/pagina-1.html";
    
    //window.open(url,'_self')    
    //document.location.href = urlus;
    window.open(urlus,'_self');
    }
    
    return false
}

function checkEnter(e){ //e is event object passed from function invocation
    var characterCode //literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else{
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        //document.forms[0].submit() //submit the form
        //alert('avem enter');
        return true
    }
    else{
        return false
    }

}

function removeInputShade(){
    if($('#toplbox_email').val()=="utilizator ..."){
        $('#toplbox_email').removeClass('shaded'); $('#toplbox_email').val(''); $('#toplbox_passwd').removeClass('shaded'); $('#toplbox_passwd').val('');
    }
}

function restoreInputShade(){
    if($('#toplbox_email').val()==""){
        $('#toplbox_email').addClass('shaded'); $('#toplbox_email').val('utilizator ...'); 
        if($('#toplbox_passwd').val()==""){
            $('#toplbox_passwd').addClass('shaded'); $('#toplbox_passwd').val('parola');
        }        
    }
    
}


function deleteReqReply(rr_id, rid, page){
    var answer = confirm ("Sunteti sigur ca doriti sa stergeti?\n\rApasati OK pentru DA");
    if (answer) {    
        strOutput = $.ajax({
        url: "ajax/ajax.utils.php?action=delete_req_reply&id=" + rr_id,
        async: false
        }).responseText;    
        
        $("#reply_container_"+rr_id).fadeOut('normal');    
        $("#show_replies_link_"+rid).html("vezi raspunsuri ("+strOutput+")");
    }
}


function addReplyTag(reply_id, reqid, page){
    
    e_tag = $('#existing_tag_'+reply_id).val();
    n_tag = $('#new_tag_'+reply_id).val();
    
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=add_tag_to_reply&reply_id=" + reply_id + "&existing_tag=" + e_tag + "&new_tag=" + n_tag,
    async: false
    }).responseText;        
    
    $('#req_response_'+reqid).html('');
    cont_ShowRequestResponses(reqid, page);
}

function deleteReplyTag(xtag, reply_id){
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=delete_tag_from_reply&reply_id=" + reply_id + "&tag_id=" + xtag,
    async: false
    }).responseText;        
    
    $("#tag_container_"+reply_id).html(strOutput);    
}

function addReplyTag2(reply_id){
    
    e_tag = $('#existing_tag_'+reply_id).val();
    n_tag = $('#new_tag_'+reply_id).val();
    
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=add_tag_to_reply&reply_id=" + reply_id + "&existing_tag=" + e_tag + "&new_tag=" + n_tag,
    async: false
    }).responseText;        
    
    window.location.reload();
}

function deleteReplyTag2(xtag, reply_id){
    strOutput = $.ajax({
    url: "ajax/ajax.utils.php?action=delete_tag_from_reply&reply_id=" + reply_id + "&tag_id=" + xtag,
    async: false
    }).responseText;        
    
    //$("#tag_container_"+reply_id).html(strOutput);    
    window.location.reload();
}

function deleteReqReply2(rr_id){
    
    var answer = confirm ("Sunteti sigur ca doriti sa stergeti?\n\rApasati OK pentru DA");
    if (answer) {
        strOutput = $.ajax({
        url: "ajax/ajax.utils.php?action=delete_req_reply&id=" + rr_id,
        async: false
        }).responseText;    
        
        //$("#reply_container_"+rr_id).fadeOut('normal');    
        //$("#show_replies_link_"+rid).html("vezi raspunsuri ("+strOutput+")");
        window.location.reload();        
    }
}


function openForPrint(cerere_id){
    window.open("prin_cerere.php?id="+cerere_id,"_blank","width=600, height=500");
}


function check_MakeOfferForm(){
    retVal = true
    errs = "";
    $('#make_offer_error').html('');
    $('#make_offer_error').hide();    
    
    if($('#x_nume').val()==""){retVal=false; errs = errs + "- campul 'Nume' trebuie completat" + "<br />";}
    if($('#x_email').val()==""){retVal=false; errs = errs + "- campul 'Email' trebuie completat" + "<br />";}
    if($('#x_telefon').val()==""){retVal=false; errs = errs + "- campul 'Telefon' trebuie completat" + "<br />";}
    if($('#x_descriere').val()==""){retVal=false; errs = errs + "- campul 'Descriere' trebuie completat" + "<br />";}
    if($('#x_quant').val()==""){retVal=false; errs = errs + "- campul 'Cantitate' trebuie completat" + "<br />";}
    if($('#x_pret').val()==""){retVal=false; errs = errs + "- campul 'Pret' trebuie completat" + "<br />";}
    if($('#x_termen').val()==""){retVal=false; errs = errs + "- campul 'Termen de livrare' trebuie completat" + "<br />";}
    if($('#x_valabil').val()==""){retVal=false; errs = errs + "- campul 'Valabilitate oferta' trebuie completat" + "<br />";}
    
    if(retVal==false){
        errs = "Au fost intampinate urmatoarele erori:" + "<br />" + errs; 
        $('#make_offer_error').html(errs);
        $('#make_offer_error').slideDown('fast');
    }
    
    return retVal
}


function check_SiteContactForm(){
    retVal = true;
    errs = "";
    $('#contact_error').html('');
    
    if($('#nume').val()==""){retVal=false; errs = errs + "- campul 'Nume' trebuie completat" + "<br />";}
    if($('#email').val()==""){retVal=false; errs = errs + "- campul 'Email' trebuie completat" + "<br />";}
    if($('#mesaj').val()==""){retVal=false; errs = errs + "- campul 'Mesaj' trebuie completat" + "<br />";}    
    
    if(retVal==false){
        errs = "Au fost intampinate urmatoarele erori:" + "<br />" + errs; 
        $('#contact_error').html(errs);
        $('#contact_error').slideDown('fast');
    }    
    
    return retVal
}


function check_CerereSendToFriend(){
    retVal = true;
    errs = "";
    $('#sf_error').html('');
    
    if($('#sf_yourname').val()==""){retVal=false; errs = errs + "- campul 'Numele tau' trebuie completat" + "<br />";}
    if($('#sf_youremail').val()==""){retVal=false; errs = errs + "- campul 'Emailul tau' trebuie completat" + "<br />";}
    if($('#sf_fname').val()==""){retVal=false; errs = errs + "- campul 'Numele prietenului' trebuie completat" + "<br />";}    
    if($('#sf_femail').val()==""){retVal=false; errs = errs + "- campul 'Emailul prietenului' trebuie completat" + "<br />";}    
    
    if(retVal==false){
        errs = "Au fost intampinate urmatoarele erori:" + "<br />" + errs; 
        $('#sf_error').html(errs);
        $('#sf_error').slideDown('fast');
    }    
    
    return retVal    
}


function check_CerereSendAMessage(){
    retVal = true;
    errs = "";
    $('#smsg_error').html('');
    
    if($('#y_name').val()==""){retVal=false; errs = errs + "- campul 'Nume' trebuie completat" + "<br />";}
    if($('#y_email').val()==""){retVal=false; errs = errs + "- campul 'Email' trebuie completat" + "<br />";}
    if($('#y_mesaj').val()==""){retVal=false; errs = errs + "- campul 'Mesaj' trebuie completat" + "<br />";}    
    
    if(retVal==false){
        errs = "Au fost intampinate urmatoarele erori:" + "<br />" + errs; 
        $('#smsg_error').html(errs);
        $('#smsg_error').slideDown('fast');
    }    
    
    return retVal    
}

$(document).ready(function(){
	$('span.remarks a.form_remarks').tooltip({showURL:false,fade:250});
	$('span.remarks a.form_remarks').click(function() {return false;});
});

