function font_big( size ){
    $("#container").css('fontSize', size);
}

function show_hide( id, force ){
    if( $("#"+id).css('display') == 'none' ){
         $("#"+id).show();
    }else{
         $("#"+id).hide();
    }
}

function show_hide_temp( id, force ){
    if( $("#"+id).css('display') == 'none' ){
        $("#"+id).show();
        setTimeout( function(){ jQuery("#"+id).fadeOut(1000); }, 6000 );
    }else{
        $("#"+id).hide();
    }
}

function show_map( id, indirizzo ){
    if( $("#mappa_"+id+"_container").css('display') == 'none' ){
         $("#mappa_"+id+"_container").show();
         $("#mappa_button_"+id).html('Chiudi dettagli <img src="'+tpl_folder+'/images/libri/arrowDownLibri.png">');

        map = new GMap2(document.getElementById("mappa_"+id));
        geocoder = new GClientGeocoder();

        geocoder.getLatLng(
            indirizzo,
            function(point) {
                map.setCenter(point, 13);
                var marker = new GMarker(point);
                map.addOverlay(marker);
            }
        );
        //$("#mappa_"+id+"_container").googleMaps({ geocode: indirizzo });

    }else{
         $("#mappa_"+id+"_container").hide();
         $("#mappa_button_"+id).html('Mappa <img src="'+tpl_folder+'/images/libri/arrowDxLibri.png">');


    }

}

function do_accordion( id_elements, element ){
    for( i = 1; i <= 15; i++ ){
        if ( $("#"+id_elements+"_"+i).length == 0 ){ continue; }
        $("#"+id_elements+"_"+i).slideUp();
    }
    $("#"+element).slideDown();
}


/* RIGHTS */
function load_rights_elements( classe, type ){
    $.ajax({
        url: site_url+"/rights/ajax_html_book_rights_list_elements/"+classe+"/"+type,
        success: function(risposta){
            $("#right_list_elements").html(risposta);
        }
    });
}

/* APPUNTAMENTI */
function send_promemoria( id ){
    email_promemoria = $("#email_promemoria_"+id).val();
    if($("#iscrizione_newsletter_"+id).attr('checked')){
        iscrizione_newsletter = 'true';
    }else{iscrizione_newsletter = 'false';}
    
    var email_reg_exp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (!email_reg_exp.test(email_promemoria))
    { 
        alert("Inserire un indirizzo email valido");
        $("#email_promemoria_"+id).focus();
    }else{
        $.ajax({
            type: "POST",
            data: "email="+email_promemoria+"&newsletter="+iscrizione_newsletter,
            url: site_url+"/appuntamenti/ajax_add_promemoria/"+id,
            success: function(risposta){
                $("#promemoria_"+id).html(risposta);
            }
        });
    }
}

/* CARRELLO */
function submit_carrello(action){
    if( action == "rebuild" ){
        $("#carrello").attr("action", site_url+"/negozio/carrello_rebuild");
    }
    $("#carrello").submit();
}

function shop_add( id_product ){
    $.ajax({
        url: site_url+"/negozio/ajax_shop_add/"+id_product,
        success: function(){
            shop_refresh();
        }
    });
}

function shop_var_quantity( id_product, quantity ){
    $.ajax({
        url: site_url+"/negozio/ajax_shop_var_quantity/"+id_product+"/"+quantity,
        success: function(){
            shop_refresh();
        }
    });
}

function shop_remove( id_product ){
    $.ajax({
        url: site_url+"/negozio/ajax_shop_remove/"+id_product,
        success: function(risposta){
            if( risposta == "0" ){ document.location.href = site_url+"/negozio/carrello"; }
            else{
                shop_refresh();
            }
        }
    });
}

function shop_refresh(){
    $.ajax({
        url: site_url+"/negozio/ajax_shop_refresh",
        success: function(risposta){
            $("#resoconto").html(risposta);
        }
    });

    if( document.getElementById("elementi_carrello") ){
        $.ajax({
            url: site_url+"/negozio/ajax_carrello_refresh",
            success: function(risposta){
                $("#elementi_carrello").html(risposta);
            }
        });
    }
}


function refresh_spese_spedizione_inline( ){
    spedizione = $("input[name='spedizione']:checked").val();
    pagamento = $("input[name='pagamento']:checked").val();

    if( pagamento == 'contrassegno' && (spedizione == 'spedizione_internazionale_europa' || spedizione == 'spedizione_internazionale_extraeuropa') ){
        alert('Non si può pagare con il contrassegno per le spedizioni fuori dall\'Italia');
        spedizione = $("input[name='spedizione']")[0].checked=true;
        refresh_spese_spedizione_inline();
    }

    type_spedizioni = new Array( 'posta_ordinario', 'pacco_celere_3', 'corriere_espresso', 
        'spedizione_internazionale_europa', 'spedizione_internazionale_extraeuropa' );

    if( pagamento == 'contrassegno' ){
        base = 3;
    }else{ base = 0; }

    for( var cont in type_spedizioni ){
        tmp = $("#costo_"+type_spedizioni[cont]).val();
        tmp = parseFloat(tmp);
        tmp += base;
        tmp = tmp.toFixed(2).replace(".", ",");
        $("#lbl_"+type_spedizioni[cont]).html(tmp+" &euro;");
    }
    use_costo_imposto = false;
    if( pagamento == 'carta_di_credito' ){
        $("#lbl_posta_ordinario").html("0 &euro;");
        if( spedizione == 'posta_ordinario' ){ costo_imposto = 0; use_costo_imposto = true; }
    }else if( pagamento == 'contrassegno' ){
        $("#lbl_spedizione_internazionale_europa").html("non disponibile");
        $("#lbl_spedizione_internazionale_extraeuropa").html("non disponibile");
    }

    totale = $("#totale_carrello").val();
    totale = parseFloat(totale);

    if (totale >= 35.00) {
        $("#lbl_posta_ordinario").html("0 &euro;");
        $("#lbl_pacco_celere_3").html("0 &euro;");
        $("#lbl_corriere_espresso").html("0 &euro;");
        if( spedizione == 'posta_ordinario' || spedizione == 'pacco_celere_3' || spedizione == 'corriere_espresso' ){
            costo_imposto = 0; use_costo_imposto = true;
        }
    }
    
    costo = $("#costo_"+spedizione).val();

    if( use_costo_imposto ){ costo = costo_imposto; }
    costo = parseFloat(costo) + base;
    $("#spese_spedizione_carrello").val(costo);


    totale = costo + totale;

    costo = costo.toFixed(2).replace(".", ",");
    totale = totale.toFixed(2).replace(".", ",");
    $("#div_costo_spedizione").html(costo+" &euro;");
    $("#div_totale_globale").html(totale);


}

function refresh_spese_spedizione( costo ){
    totale = $("#totale_carrello").val();
    $.ajax({
        type: "POST",
        data: "totale="+totale+"&spese_spedizione="+costo,
        url: site_url+"/negozio/ajax_footer_carrello",
        success: function(risposta){
            $("#footer_carrello").html(risposta);
        }
    });
}

/* MEDIA GALLERY TABS */
function media_gallery( class_elem ) {
    //When page loads...
    $(".tab_content_"+class_elem).hide(); //Hide all content
    $("ul#tabs_"+class_elem+" li:first").addClass("active").show(); //Activate first tab
    $(".tab_content_"+class_elem+":first").show(); //Show first tab content

    //On Click Event
    $("ul#tabs_"+class_elem+" li").click(function() {

        $("ul#tabs_"+class_elem+" li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content_"+class_elem).hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
};
/*
$(document).ready(function() {
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
});
*/
