/*
 * JavaScript Document
 * http://www.avanzolinimoto.com
 * Author Denise Mazzini
 * www.denisemazzini.net
 */
function aggiornatempo(){ // Funzione per il display dell'ora e della data 
    giorni = new Array();
    giorni[0] = 'Domenica';
    giorni[1] = 'Lunedi';
    giorni[2] = 'Martedi';
    giorni[3] = 'Mercoledi';
    giorni[4] = 'Giovedi';
    giorni[5] = 'Venerdi';
    giorni[6] = 'Sabato';
    
    mesi = new Array();
    mesi[0] = 'Gennaio';
    mesi[1] = 'Febbraio';
    mesi[2] = 'Marzo';
    mesi[3] = 'Aprile';
    mesi[4] = 'Maggio';
    mesi[5] = 'Giugno';
    mesi[6] = 'Luglio';
    mesi[7] = 'Agosto';
    mesi[8] = 'Settembre';
    mesi[9] = 'Ottobre';
    mesi[10] = 'Novembre';
    mesi[11] = 'Dicembre';
    
    oggi = new Date();
    
    tempSecondi = oggi.getSeconds();
    if (tempSecondi < 10) {
        Secondi = '0' + tempSecondi;
    }
    else {
        Secondi = tempSecondi;
    }
    tempMinuti = oggi.getMinutes();
    if (tempMinuti < 10) {
        Minuti = '0' + tempMinuti;
    }
    else {
        Minuti = tempMinuti;
    }
    tempOre = oggi.getHours();
    if (tempOre < 10) {
        Ore = '0' + tempOre;
    }
    else {
        Ore = tempOre;
    }
    temp = giorni[oggi.getDay()] + ' <br /> ' + oggi.getDate() + ' ' + mesi[oggi.getMonth()] + ' ' + oggi.getFullYear() + '<br />';
    temp += Ore + ':' + Minuti + ':' + Secondi;
    tempDIV = document.getElementById('tempo');
    tempDIV.innerHTML = temp;
}

/*
 * Funzione per la rotazione dei loghi nella home
 */
var images = new Array("img/loghi/honda.gif", "img/loghi/kl.gif", "img/loghi/kawasaki.gif", "img/loghi/suzuki.gif", "img/loghi/valenti.gif", "img/loghi/yamaha.gif");
loop_count = 0;
function logo_rotation(){
    if (loop_count == images.length - 1) {
        loop_count = 0;
    }
    else {
        loop_count++;
    }
    $(document).ready(function(){
        $('#logo').stop().animate({
            opacity: "0.0"
        }, 2000, "linear", function(){
            $('#logo').attr("src", images[loop_count]);
            $('#logo').animate({
                opacity: "1.0"
            }, 2000, "linear");
        });
    });
}

/* 
 * FUNZIONI JQUERY
 * Documentazione disponibile su www.jquery.com
 * Sono librerie javascript per la migliore gestione di componenti ajax
 * ed effetti speciali
 */
$(document).ready(function(){
	setInterval('logo_rotation();', 5000); // ogni 5 secondi cambia logo 
	/*
	 * Funzione per l'effetto sulle immagini della home page 
	 * quando compare la descrizione sopra
	 */
	$('.novita').hover(function(){
		$(this).children("div").each(function(){
			$(this).fadeIn();
		})
	},function(){
		$(this).children("div").each(function(){
			$(this).fadeOut();
		})
	})
	/* effetto ON/OFF sui titoli */
	$('#titolo_moto').hover(function(){
		$(this).attr("src","img/titoli/home/moto_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/moto.jpg");
	})
	$('#titolo_foto').hover(function(){
		$(this).attr("src","img/titoli/home/foto_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/foto.jpg");
	})
	$('#titolo_abbigliamento').hover(function(){
		$(this).attr("src","img/titoli/home/abbigliamento_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/abbigliamento.jpg");
	})
	$('#titolo_accessori').hover(function(){
		$(this).attr("src","img/titoli/home/accessori_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/accessori.jpg");
	})
	$('#titolo_occasione_moto').hover(function(){
		$(this).attr("src","img/titoli/home/moto_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/moto.jpg");
	})
	
	$('#titolo_occasione_abbigliamento').hover(function(){
		$(this).attr("src","img/titoli/home/abbigliamento_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/abbigliamento.jpg");
	})
	$('#titolo_occasione_accessori').hover(function(){
		$(this).attr("src","img/titoli/home/accessori_on.jpg");
	},function(){
		$(this).attr("src","img/titoli/home/accessori.jpg");
	})
    /*
     * Funzione per il login nella sezione di management
     */
    $('#login_manager').submit(function(e){
		e.preventDefault();
		$.get("pwd.php", {
            u: $('#nome').val(),
            p: $('#pass').val()
        }, function(data){
			if(data=="OK"){
			    $('#login_manager').hide();
                $('#menu_manager').show();
            }
            else {
                $('#login_errato').show();  
            }
        }, "text");
    });
    /*
     * Funzione per il logout
     */
	
    $('#logout').click(function(e){
        e.preventDefault();
        $.get("pwd.php", {
            logout: "ok"
        }, function(data){
            if (data == "") {
                location.href = "index.php";
            }
        })
        
    });
    
    
    /*
     * Sezione GESTIONE ACCESSORI
     */
    $('#nuova_categoria').css("display", "none");
    $('#modifica_categoria').css("display", "none");
    $('#cancella_categoria').css("display", "none");
    $('#nuova_sottocategoria').css("display", "none");
    $('#modifica_sottocategoria').css("display", "none");
    $('#cancella_sottocategoria').css("display", "none");
    $('#nuovo_accessorio').css("display", "none");
    $('#modifica_accessorio').css("display", "none");
    $('#cancella_accessorio').css("display", "none");
	
    $('#link_nuova_categoria').click(function(e){
        e.preventDefault();
        if ($('#cancella_categoria').css("display") != "none") {
            $('#cancella_categoria').css("display", "none");
        }
        if ($('#modifica_categoria').css("display") != "none") {
            $('#modifica_categoria').css("display", "none");
        }
        $('#nuova_categoria').show("slow");
    });
    $('#link_nuova_sottocategoria').click(function(e){
        e.preventDefault();
        if ($('#cancella_sottocategoria').css("display") != "none") {
            $('#cancella_sottocategoria').css("display", "none");
        }
        if ($('#modifica_sottocategoria').css("display") != "none") {
            $('#modifica_sottocategoria').css("display", "none");
        }
        // recupero le categorie già presenti
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $first = true;
            $(xml).find('categoria').each(function(){
                if ($first) {
                    $('#categorie_xsotto').html("<option value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
                    $first = false;
                }
                else {
                    $('#categorie_xsotto').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
                }
                
            })
        }, "xml");
        $('#nuova_sottocategoria').show("slow");
    });
    $('#link_modifica_categoria').click(function(e){
        e.preventDefault();
        if ($('#nuova_categoria').css("display") != "none") {
            $('#nuova_categoria').css("display", "none");
        }
        if ($('#cancella_categoria').css("display") != "none") {
            $('#cancella_categoria').css("display", "none");
        }
        // recupero le categorie già presenti
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $first = true;
            $(xml).find('categoria').each(function(){
                if ($first) {
                    $('#categoria_old').html("<option value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
                    $first = false;
                }
                else {
                    $('#categoria_old').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
                }
            })
        }, "xml");
        $('#modifica_categoria').show("slow");
    });
    $('#link_modifica_sottocategoria').click(function(e){
        e.preventDefault();
        if ($('#nuova_sottocategoria').css("display") != "none") {
            $('#nuova_sottocategoria').css("display", "none");
        }
        if ($('#cancella_sottocategoria').css("display") != "none") {
            $('#cancella_sottocategoria').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $('#categoria_old_xsotto').html("<option>Seleziona qui</option>");
            $(xml).find('categoria').each(function(){
                $('#categoria_old_xsotto').append("<option value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
        $('#modifica_sottocategoria').show("slow");
    })
    $('#categoria_old_xsotto').change(function(e){
        $.get("../functions.php", {
            action: "getSottoCategorie",
            id: $('#categoria_old_xsotto').val()
        }, function(xml){
            $('#sottocategorie_da_modificare').html("");
            $(xml).find('sottocategoria').each(function(){
                $('#sottocategorie_da_modificare').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
    });
    $('#categorie_xsotto_cancella').change(function(e){
        $.get("../functions.php", {
            action: "getSottoCategorie",
            id: $('#categorie_xsotto_cancella').val()
        }, function(xml){
            $('#sottocategorie_da_cancellare').html("");
            $(xml).find('sottocategoria').each(function(){
                $('#sottocategorie_da_cancellare').append("<br /><input type='radio' name='id' id='id' value='" + $(this).attr('id') + "' />" + $(this).text());
            })
        }, "xml");
    });
    $('#link_cancella_categoria').click(function(e){
        e.preventDefault();
        if ($('#nuova_categoria').css("display") != "none") {
            $('#nuova_categoria').css("display", "none");
        }
        if ($('#modifica_categoria').css("display") != "none") {
            $('#modifica_categoria').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $first = true;
            $(xml).find('categoria').each(function(){
                if ($first) {
                    $('#categoria_da_cancellare').html("<input type='radio' name='id' id='id' value='" + $(this).attr('id') + "' />" + $(this).text());
                    $first = false;
                }
                else {
                    $('#categoria_da_cancellare').append("<br /><input type='radio' name='id' id='id' value='" + $(this).attr('id') + "' />" + $(this).text());
                }
                
            })
        }, "xml");
        $('#cancella_categoria').show("slow");
    });
    $('#link_cancella_sottocategoria').click(function(e){
        e.preventDefault();
        if ($('#nuova_sottocategoria').css("display") != "none") {
            $('#nuova_sottocategoria').css("display", "none");
        }
        if ($('#modifica_sottocategoria').css("display") != "none") {
            $('#modifica_sottocategoria').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $('#categorie_xsotto_cancella').html("<option>Seleziona</option>");
            $(xml).find('categoria').each(function(){
                $('#categorie_xsotto_cancella').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
        $('#cancella_sottocategoria').show("slow");
    });
    $('#link_nuovo_accessorio').click(function(e){
        e.preventDefault();
        if ($('#cancella_accessorio').css("display") != "none") {
            $('#cancella_accessorio').css("display", "none");
        }
        if ($('#modifica_accessorio').css("display") != "none") {
            $('#modifica_accessorio').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $('#categorie_x_accessorio').html("<option>Seleziona</option>");
            $(xml).find('categoria').each(function(){
                $('#categorie_x_accessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
        $('#nuovo_accessorio').show("slow");
        
    });
    $('#categorie_x_accessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getSottoCategorie",
            id: $('#categorie_x_accessorio').val()
        }, function(xml){
            $('#sottocategoria_x_accessorio').html("");
            $(xml).find('sottocategoria').each(function(){
                $('#sottocategoria_x_accessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
    });
    $('#link_modifica_accessorio').click(function(e){
        e.preventDefault();
        if ($('#cancella_accessorio').css("display") != "none") {
            $('#cancella_accessorio').css("display", "none");
        }
        if ($('#nuovo_accessorio').css("display") != "none") {
            $('#nuovo_accessorio').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $('#CatModAccessorio').html("<option>Seleziona</option>");
            $(xml).find('categoria').each(function(){
                $('#CatModAccessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
        $('#modifica_accessorio').show("slow");
    });
    $('#CatModAccessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getSottoCategorie",
            id: $('#CatModAccessorio').val()
        }, function(xml){
            $('#SottoCatModAccessorio').html("<option>Seleziona</option>");
            $(xml).find('sottocategoria').each(function(){
                $('#SottoCatModAccessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
    });
    $('#SottoCatModAccessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getAccessori",
            id_cat: $('#CatModAccessorio').val(),
            id_sottocat: $('#SottoCatModAccessorio').val()
        }, function(xml){
            $('#ModAccessorio').html("<option>Seleziona</option>");
            $(xml).find('accessorio').each(function(){
                $('#ModAccessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
    })
    $('#ModAccessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getAccessorio",
            id: $('#ModAccessorio').val()
        }, function(xml){
            $(xml).find('accessorio').each(function(){
                $('#NomeModAccessorio').val($(this).children("nome").text());
                $('#IdModAccessorio').val($(this).children("nome").attr('id'));
                $('#MarcaModAccessorio').val($(this).children("marca").text());
                $('#DescModAccessorio').val($(this).children("descrizione").text());
                $('#DisplayFotoModAccessorio').attr("src", "../" + $(this).children("foto").text());
				if($(this).children("occasione").text()=="1"){
					
					$('#occasione').attr("checked","checked");
				}
            })
        }, "xml");
    });
    $('#link_cancella_accessorio').click(function(e){
        e.preventDefault();
        if ($('#modifica_accessorio').css("display") != "none") {
            $('#modifica_accessorio').css("display", "none");
        }
        if ($('#nuovo_accessorio').css("display") != "none") {
            $('#nuovo_accessorio').css("display", "none");
        }
        $.get("../functions.php", {
            action: "getCategorie"
        }, function(xml){
            $('#CatCancAccessorio').html("<option>Seleziona</option>");
            $(xml).find('categoria').each(function(){
                $('#CatCancAccessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
        $('#cancella_accessorio').show("slow");
    });
    $('#CatCancAccessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getSottoCategorie",
            id: $('#CatCancAccessorio').val()
        }, function(xml){
            $('#SottoCatCancAccessorio').html("<option>Seleziona</option>");
            $(xml).find('sottocategoria').each(function(){
                $('#SottoCatCancAccessorio').append("<option  value='" + $(this).attr('id') + "'>" + $(this).text() + "</option>");
            })
        }, "xml");
    });
    $('#SottoCatCancAccessorio').change(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "getAccessori",
            id_cat: $('#CatCancAccessorio').val(),
            id_sottocat: $('#SottoCatCancAccessorio').val()
        }, function(xml){
            $('#AccessoriDaCanc').html("");
            $(xml).find('accessorio').each(function(){
                $('#AccessoriDaCanc').append("<br /><input type='radio' id='idCancAccessorio' name='idCancAccessorio' value='" + $(this).attr('id') + "'>" + $(this).text());
            })
        }, "xml");
    })
    $('#nuova_categoria').submit(function(e){
        e.preventDefault();
        $.post("../functions.php", {
            action: "newCategoria",
            nome: $('#nome').val(),
            descrizione: $('#descrizione').val()
        }, function(data){
            if (data == 0) {
                alert("Categoria " + $('#nome').val() + " creata!");
                location.href='admin_accessori.php';
            }
            else {
                alert("Attenzione! Errori: " + data);
            }
        })
    })
    $('#modifica_categoria').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "modificaCategoria",
            id: $('#categoria_old').val(),
            nome: $('#new_name').val()
        }, function(data){
            if (data == 0) {
                alert("Modifica effettuata");
                location.href='admin_accessori.php';
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    })
    $('#cancella_categoria').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "cancellaCategoria",
            id: $('input:checked').val()
        }, function(data){
            if (data == 0) {
                alert("Cancellazione effettuata");
                location.href='admin_accessori.php';
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    })
    $('#nuova_sottocategoria').submit(function(e){
        e.preventDefault();
        $.post("../functions.php", {
            action: "newSottoCategoria",
            nome: $('#nome_sotto_categoria').val(),
            descrizione: $('#descrizione').val(),
            categoria: $('#categorie_xsotto').val()
        }, function(data){
            if (data == 0) {
                alert("Sottocategoria " + $('#nome').val() + " creata!");
                location.href='admin_accessori.php';
            }
            else {
                alert("Attenzione! Errori: " + data);
            }
        })
    });
    $('#modifica_sottocategoria').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "modificaSottoCategoria",
            id: $('#sottocategorie_da_modificare').val(),
            nome: $('#new_name_sotto').val()
        }, function(data){
            if (data == 0) {
                alert("Modifica effettuata");
                location.href='admin_accessori.php';
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    });
    $('#cancella_sottocategoria').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "cancellaSottoCategoria",
            id: $('input:checked').val()
        }, function(data){
            if (data == 0) {
                alert("Cancellazione effettuata");
                location.href='admin_accessori.php';
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    })
    $('#cancella_accessorio').submit(function(e){
        e.preventDefault();
		$.get("../functions.php", {
            action: "cancellaAccessorio",
            id: $('input:checked').val()
        }, function(data){
            if (data == 0) {
                alert("Cancellazione effettuata");
                location.href="admin_accessori.php";
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    });
    /*
     * Gestione LINKS
     */
    $('#nuovo_link').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "nuovoLink",
            nome: $('#nome_link').val(),
            link: $('#link').val()
        }, function(data){
            if (data == 0) {
                alert("Inserimento link " + $('#nome_link').val() + " avvenuto con successo!");
                $('#nuovo_link').hide();
				location.href="admin_links.php";
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    });
    $('#modifica_link').submit(function(e){
        e.preventDefault();
        $.get("../functions.php", {
            action: "modificaLink",
            nome: $('#nome_link').val(),
            link: $('#link').val(),
            id: $('#id').val()
        }, function(data){
            if (data == 0) {
                alert("Modifica effettuata");
                window.close();
            }
            else {
                alert("ATTENZIONE: Errore " + data);
            }
        }, "text");
    });
	$('#crea_categoria_abbigliamento').submit(function(e){
		e.preventDefault();
		$.get("../functions.php",{
			action:"newCategoriaAbbigliamento",
			nome:$('#nome_categoria').val()
		},function(data){
			if(data==0){
				alert("Categoria "+$('#nome_categoria').val()+ " creata!");
				window.close();
			} else {
                alert("ATTENZIONE: Errore " + data);
			}
		})		
	})
	/*
	 * Pagina Online News
	 */
	$('#elenco_news li').hover(function(){
		$(this).css("text-decoration","underline");
	},function(){
		$(this).css("text-decoration","none");
	});
});

/*
 * Funzioni per la gestione delle foto
 */
function delete_photo(id){
    $(document).ready(function(){
        $.get("../functions.php", {
            action: "delete_photo",
            id: id
        }, function(data){
            if (data == 0) {
                location.href = "admin_foto.php";
            }
            else {
                $('#feedback').html(data);
            }
        }, "text");
    });
}

/*
 * Funzione per la gestione delle news
 */
function show_news(){
    $(document).ready(function(){
        $.get("../functions.php", {
            action: "getNews"
        }, function(xml){
            $(xml).find('new').each(function(){
                var id = $(this).attr('id');
                var titolo = $(this).children('titolo').text();
                var testo = $(this).children('testo').text();
                var data = $(this).children('data').text();
                var ora = $(this).children('ora').text();
                var foto = $(this).children('foto').text();
                $('#elenco_news').append("<tr>" +
                "<td>" +
                titolo +
                "</td>" +
                "<td>" +
                testo +
                "</td>" +
                "<td>" +
                data +
                "</td>" +
                "<td>" +
                ora +
                "</td>" +
                "<td><img src='../" +
                foto +
                "' width='50px' /></td>" +
                "<td><a href='edit_news.php?action=edit&id=" +
                id +
                "'>Modifica</a></td>" +
                "<td><a href='#' onclick='javascript:delete_news(" +
                id +
                ");'>Cancella</a></td>" +
                "</tr>");
                
            })
        }, "xml");
    });
}
/*
 * Funzione invocata al caricamento della pagina di amministrazione moto
 */
function show_moto(){
    $(document).ready(function(){
        $.get("../functions.php", {
            action: "getMoto"
        }, function(xml){
            $(xml).find('moto').each(function(){
                var id = $(this).attr('id');
                var nome = $(this).children('nome').text();
                var modello = $(this).children('modello').text();
                var descrizione = $(this).children('descrizione').text();
                if ($(this).children('nuova').text() == 1) {
                    nuova = "Nuova";
                }
                else {
                    nuova = "Usata";
                }
                var anno = $(this).children('anno').text();
                var foto = $(this).children('foto').text();
                var categoria = $(this).children('categoria').text();
                $('#elenco_moto').append("<tr>" +
                "<td>" +
                nome +
                "</td>" +
                "<td>" +
                nuova +
                "</td>" +
                "<td>" +
                modello +
                "</td>" +
                "<td>" +
                descrizione +
                "</td>" +
                "<td>" +
                anno +
                "</td>" +
                "<td><a href='edit_moto.php?action=edit&id=" +
                id +
                "'>Modifica</a></td>" +
                "<td><a href='#' onclick='javascript:delete_moto(" +
                id +
                ");'>Cancella</a></td>" +
                "</tr>");
                
            })
        }, "xml");
    });
}
/*
 * Funzione invocata al caricamento della pagina di amministrazione abbigliamento
 */
function show_abbigliamento(){
	$(document).ready(function(){
		$.get("../functions.php", {
            action: "getAbbigliamento"
        }, function(xml){
			
            $(xml).find('capo').each(function(){
				
                var id = $(this).attr('id');
                var nome = $(this).children('nome').text();
                var prezzo = $(this).children('prezzo').text();
                var descrizione = $(this).children('descrizione').text();
                if ($(this).children('offroad').text() == 1) {
                    offroad = "Road";
                }
                else {
                    offroad = "Offroad";
                }
                var data = $(this).children('data').text();
                var foto = $(this).children('foto').text();
                var categoria = $(this).children('categoria').text();
				
                $('#elenco_abbigliamento').append("<tr>" +
                "<td><b>" +
                nome +
                "</b></td>" +
                "<td>" +
                prezzo +
                "</td>" +
                "<td>" +
                offroad +
                "</td>" +
                "<td>" +
                descrizione +
                "</td>" +
				"<td>"+
				categoria+
				"</td>" +
                "<td><img width='70px' src='../" +
                foto +
                "' /></td>" +
                "<td><a href='edit_abbigliamento.php?action=edit&id=" +
                id +
                "'>Modifica</a></td>" +
                "<td><a href='#' onclick='javascript:delete_abbigliamento(" +
                id +
                ");'>Cancella</a></td>" +
                "</tr>");
            })
        }, "xml");
		
    });
}
function delete_news(id){
    if (confirm("Sei sicuro di voler cancellare questa news?")) {
        $.get("../functions.php", {
            action: "deleteNews",
            id: id
        }, function(data){
            if (data == 0) {
                location.href = "admin_news.php";
            }
            else {
                $('#feedback').html(data);
            }
        }, "text");
    }
}

function delete_moto(id){
    if (confirm("Sei sicuro di voler cancellare questa moto?")) {
        $.get("../functions.php", {
            action: "deleteMoto",
            id: id
        }, function(data){
            if (data == 0) {
                alert("Cancellazione avvenuta!");
                location.href = "admin_moto.php";
            }
            else {
                $('#feedback').html(data);
            }
        }, "text");
    }
}
function delete_abbigliamento(id){
	if (confirm("Sei sicuro di voler cancellare questo elemento?")) {
        $.get("../functions.php", {
            action: "deleteAbbigliamento",
            id: id
        }, function(data){
            if (data == 0) {
                location.href = "admin_abbigliamento.php";
            }
            else {
                $('#feedback').html(data);
            }
        }, "text");
    }
}
function show_links(){
    $(document).ready(function(e){
        $.get("../functions.php", {
            action: "getLinks"
        }, function(xml){
            $(xml).find('alink').each(function(){
                var deletelink = "javascript:delete_link(" + $(this).children("id").text() + ");";
                var modifylink = "javascript:";
                $('#tabella_link').append("<tr>" +
                "<td>" +
                $(this).children("nome").text() +
                "</td>" +
                "<td>" +
                $(this).children("link").text() +
                "</td>" +
                "<td><a href='#' onclick='javascript:modifica_link(" +
                $(this).children("id").text() +
                ")'>Modifica</a></td>" +
                "<td><a href='#' onclick='" +
                deletelink +
                "'>Cancella</a></td>" +
                "</tr>");
            })
        }, "xml")
    })
}

// Funzione per creare il link alla finestra di modifica del link 
function modifica_link(id){
    window.open('admin_modifica_link.php?id=' + id, 'Modifica Link', 'width=300,height=200,top=300,left=300');
}

function delete_link(id){
    $(document).ready(function(e){
		if (confirm("Sei sicuro di voler cancellare questo link?")) {
			$.get("../functions.php", {
				action: "DeleteLink",
				id: id
			}, function(data){
				if (data == 0) {
					alert("Cancellazione avvenuta!");
					location.href="admin_links.php";
				}
				else {
					$('#feedback').html(data);
				}
			}, "text");
		}
	});
}
function aggiungi_categoria(){
    window.open('admin_nuova_categoria.php', 'Nuova categoria', 'width=300,height=200,top=300,left=300');
}

/* Funzione che ricava i commenti di una foto dato l'id */
function commenti_foto(id){
	$(document).ready(function(){
		$.post("functions.php",{
			action:"getCommentiFoto",
			id:id
		},function(xml){
			$(xml).find('commento').each(function(){
				$('#commenti').html("<b>Commenti</b><br /><br />");
				$('#commenti').append("<span style='font-size:11px;'><b># " + $(this).children("numero").text() + "</b> - Alle " + $(this).children('ora').text()+ " del " + $(this).children('data').text() + " <b>" + $(this).children('autore').text() + "</b> scrive:</span><br />");
				$('#commenti').append("<div style='font-size:12px;font-style:italic;margin-bottom:10px;'>" + $(this).children('testo').text() + "</div>");
			})	
		},"xml");
	})
}


