var tempo = null;
function ricerca_generale(str){
	if(str == "Es. materasso memory 180x200"){
		document.form_ricerca_generale.word.value = "";
		document.getElementById('div_ricerca_generale').style.display = "none";
	}else{
		document.getElementById('div_ricerca_generale').style.display = "block";
		if(tempo) clearTimeout(tempo);
		tempo = setTimeout("apri_ricerca()",1000);
		
	}
}

function apri_ricerca(){
	var str = document.form_ricerca_generale.word.value;
	document.getElementById('frame_ricerca_generale').src='articoli_ricerca.php?word='+str;
}

function chiudi_ricerca(){
	document.getElementById('div_ricerca_generale').style.display = "none";
}

function login(){
	if(document.form_login.Username.value==""){
		alert("Specificare lo username");
	}else
	if(document.form_login.Password.value==""){
		alert("Specificare la password");
	}else{
		document.form_login.submit();
	}
}

function search_by_name(valore){
	if(valore=="Nome del prodotto..."){
		document.form_ricerca_dettagliata.Nome_prodotto.value="";
	}
}

function cambia_quantita(){
	document.form_carrello.aggiorna_quantita.value=1;
	document.form_carrello.submit();
}

function scegli_comune(Prov,sezione){
	document.getElementById('frame_comuni_'+sezione).src="http://www.giwamaterassi.it/comuni.php?Provincia="+Prov+"&sezione="+sezione;
	if(sezione=="anagrafica"){
		document.getElementById('frame_comuni_spedizione').src="http://www.giwamaterassi.it/comuni.php?Provincia="+Prov+"&sezione="+sezione;
		document.getElementById('frame_comuni_fatturazione').src="http://www.giwamaterassi.it/comuni.php?Provincia="+Prov+"&sezione="+sezione;
	}
}

function rollover_vote(vote){
	if(vote == 1){
		document.getElementById('vote1').src='images/stella_ev.jpg';
		document.getElementById('vote2').src='images/stella_gray.jpg';
		document.getElementById('vote3').src='images/stella_gray.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(vote == 2){
		document.getElementById('vote1').src='images/stella_ev.jpg';
		document.getElementById('vote2').src='images/stella_ev.jpg';
		document.getElementById('vote3').src='images/stella_gray.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(vote == 3){
		document.getElementById('vote1').src='images/stella_ev.jpg';
		document.getElementById('vote2').src='images/stella_ev.jpg';
		document.getElementById('vote3').src='images/stella_ev.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(vote == 4){
		document.getElementById('vote1').src='images/stella_ev.jpg';
		document.getElementById('vote2').src='images/stella_ev.jpg';
		document.getElementById('vote3').src='images/stella_ev.jpg';
		document.getElementById('vote4').src='images/stella_ev.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(vote == 5){
		document.getElementById('vote1').src='images/stella_ev.jpg';
		document.getElementById('vote2').src='images/stella_ev.jpg';
		document.getElementById('vote3').src='images/stella_ev.jpg';
		document.getElementById('vote4').src='images/stella_ev.jpg';
		document.getElementById('vote5').src='images/stella_ev.jpg';
	}
}


function rollout_vote(){
	if(document.form_incart.Voto.value == 1){
		document.getElementById('vote1').src='images/stella.jpg';
		document.getElementById('vote2').src='images/stella_gray.jpg';
		document.getElementById('vote3').src='images/stella_gray.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(document.form_incart.Voto.value == 2){
		document.getElementById('vote1').src='images/stella.jpg';
		document.getElementById('vote2').src='images/stella.jpg';
		document.getElementById('vote3').src='images/stella_gray.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(document.form_incart.Voto.value == 3){
		document.getElementById('vote1').src='images/stella.jpg';
		document.getElementById('vote2').src='images/stella.jpg';
		document.getElementById('vote3').src='images/stella.jpg';
		document.getElementById('vote4').src='images/stella_gray.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(document.form_incart.Voto.value == 4){
		document.getElementById('vote1').src='images/stella.jpg';
		document.getElementById('vote2').src='images/stella.jpg';
		document.getElementById('vote3').src='images/stella.jpg';
		document.getElementById('vote4').src='images/stella.jpg';
		document.getElementById('vote5').src='images/stella_gray.jpg';
	}
	if(document.form_incart.Voto.value == 5){
		document.getElementById('vote1').src='images/stella.jpg';
		document.getElementById('vote2').src='images/stella.jpg';
		document.getElementById('vote3').src='images/stella.jpg';
		document.getElementById('vote4').src='images/stella.jpg';
		document.getElementById('vote5').src='images/stella.jpg';
	}
}

function vota(id,voto){
	document.getElementById('frame_voto').src="articolo_vota.php?ID_articolo="+id+"&Voto="+voto;
}

function riporta(nome){
	nome_campo = nome.toLowerCase();
	var Fatturazione = "Fatturazione_"+nome_campo;
	var Spedizione = "Spedizione_"+nome_campo;
	document.form_ordine[Fatturazione].value=document.form_ordine[nome].value;
	document.form_ordine[Spedizione].value=document.form_ordine[nome].value;
}

function copia_anagrafica(sezione){
	document.form_ordine[sezione+"_nome"].value = document.form_ordine.Nome.value;
	document.form_ordine[sezione+"_ragione_sociale"].value = document.form_ordine.Ragione_sociale.value;
	document.form_ordine[sezione+"_cognome"].value = document.form_ordine.Cognome.value;
	document.form_ordine[sezione+"_indirizzo"].value = document.form_ordine.Indirizzo.value;
	document.form_ordine[sezione+"_cap"].value = document.form_ordine.Cap.value;
	document.form_ordine[sezione+"_id_nazione"].value = document.form_ordine.ID_nazione.value;
	document.form_ordine[sezione+"_provincia"].value = document.form_ordine.Provincia.value;
	if(sezione=="Spedizione"){
	document.getElementById('frame_comuni_spedizione').src="http://www.giwamaterassi.it/comuni.php?ID_comune="+frame_comuni_anagrafica.document.form.Citta.value+"&Provincia="+document.form_ordine[sezione+"_provincia"].value;
	}
	if(sezione=="Fatturazione"){
	document.getElementById('frame_comuni_fatturazione').src="http://www.giwamaterassi.it/comuni.php?ID_comune="+frame_comuni_anagrafica.document.form.Citta.value+"&Provincia="+document.form_ordine[sezione+"_provincia"].value;
	}
}

function copia_spedizione(sezione){
	document.form_ordine[sezione+"_nome"].value = document.form_ordine.Spedizione_nome.value;
	document.form_ordine[sezione+"_ragione_sociale"].value = document.form_ordine.Spedizione_ragione_sociale.value;
	document.form_ordine[sezione+"_cognome"].value = document.form_ordine.Spedizione_cognome.value;
	document.form_ordine[sezione+"_indirizzo"].value = document.form_ordine.Spedizione_indirizzo.value;
	document.form_ordine[sezione+"_cap"].value = document.form_ordine.Spedizione_cap.value;
	document.form_ordine[sezione+"_id_nazione"].value = document.form_ordine.Spedizione_id_nazione.value;
	document.form_ordine[sezione+"_provincia"].value = document.form_ordine.Spedizione_provincia.value;

	if(sezione=="Fatturazione"){
	document.getElementById('frame_comuni_fatturazione').src="http://www.giwamaterassi.it/comuni.php?ID_comune="+frame_comuni_spedizione.document.form.Citta.value+"&Provincia="+document.form_ordine[sezione+"_provincia"].value;
	}
}


function scegli_modalita_pagamento(id){
	if(id==6){
		document.getElementById('div_modalita_finanziamento').style.height='120px';
		document.form_ordine.Finanziamento.value = "si";
	}else{
		document.getElementById('div_modalita_finanziamento').style.height='2px';
		document.form_ordine.Tipologia_finanziamento.value = "";
		document.form_ordine.Finanziamento.value = "";
	}
	if(id==3){
		document.getElementById('div_contrassegno').style.display='block';
		document.form_ordine.Spese_contrassegno_calcolo.value=document.form_ordine.Spese_contrassegno.value;
		document.getElementById('Span_spese_contrassegno').innerHTML=""+document.form_ordine.Spese_contrassegno.value;
		document.form_ordine.Totale_calcolo.value=(1*(document.form_ordine.Spese_contrassegno.value))+(1*(document.form_ordine.Spese_spedizione_calcolo.value))+(1*(document.form_ordine.Subtotale_calcolo.value));
		
		Totale_virgola = document.form_ordine.Totale_calcolo.value;
		Totale_virgola = Totale_virgola.replace(".",",");
		document.getElementById('Totale').innerHTML=""+Totale_virgola;
		
	}else{
			document.form_ordine.Spese_contrassegno_calcolo.value='0';
			document.getElementById('div_contrassegno').style.display='none';
			document.form_ordine.Totale_calcolo.value=0+(1*(document.form_ordine.Spese_spedizione_calcolo.value))+(1*(document.form_ordine.Subtotale_calcolo.value));		
			Totale_virgola = document.form_ordine.Totale_calcolo.value;
			Totale_virgola = Totale_virgola.replace(".",",");
			document.getElementById('Totale').innerHTML=""+Totale_virgola;
	}
	document.getElementById("frame_modpag").src = "frame_modpag.php?ID_modalita_pagamento="+id+"&Totale_calcolo="+document.form_ordine.Subtotale_calcolo.value+"&Spese_spedizione_calcolo="+document.form_ordine.Spese_spedizione_calcolo.value;
}

function dettagli(sezione, lingua){
	document.getElementById('dettagli_dettagli').src="http://www.giwamaterassi.it/images/"+lingua+"/dettagli_dettagli.gif";
	document.getElementById('dettagli_modalita').src="http://www.giwamaterassi.it/images/"+lingua+"/dettagli_modalita.gif";
	document.getElementById('dettagli_info').src="http://www.giwamaterassi.it/images/"+lingua+"/dettagli_info.gif";
	document.getElementById('dettagli_'+sezione).src="http://www.giwamaterassi.it/images/"+lingua+"/dettagli_"+sezione+"_over.gif";
	document.getElementById('div_dettagli').style.display="none";
	document.getElementById('div_info').style.display="none";
	document.getElementById('div_modalita').style.display="none";
	document.getElementById('div_'+sezione).style.display="block";
}

function ulteriori_dettagli(){
	if(document.getElementById('ulteriori_dettagli').style.display=="block"){
		document.getElementById('ulteriori_dettagli').style.display="none";
	}else{
		document.getElementById('ulteriori_dettagli').style.display="block";
	}
}

function invia_richiesta(){
	if(document.form_richiesta.Nome.value==""){
		alert("Specificare il nome");
		document.form_richiesta.Nome.focus();
	}else
	if(document.form_richiesta.Cognome.value==""){
		alert("Specificare il cognome");
		document.form_richiesta.Cogome.focus();
	}else
	if(document.form_richiesta.Telefono.value==""){
		alert("Specificare il numero di telefono");
		document.form_richiesta.Telefono.focus();
	}else
	if(document.form_richiesta.Email.value==""){
		alert("Specificare l'indirizzo e-mail");
		document.form_richiesta.Email.focus();
	}else{
		document.form_richiesta.submit();
	}
}

function change_photo(id,main,id_articolo){
	if(main==0){
		document.getElementById('foto_articolo').src="http://www.giwamaterassi.it/img/Articoli/medium/"+id+".jpg";
		document.getElementById('miniatura_foto_articolo').src="http://www.giwamaterassi.it/img/Articoli/extrasmall/"+id_articolo+".jpg";
		document.getElementById('div_miniatura_foto_articolo').style.display="block";
		document.getElementById('link_zoom').href="http://www.giwamaterassi.it/img/Articoli/big/"+id+".jpg";
	}else{
		document.getElementById('foto_articolo').src="http://www.giwamaterassi.it/img/Articoli/medium/"+id_articolo+".jpg";
		document.getElementById('miniatura_foto_articolo').src="http://www.giwamaterassi.it/images/white.gif";
		document.getElementById('div_miniatura_foto_articolo').style.display="none";
		document.getElementById('link_zoom').href="http://www.giwamaterassi.it/img/Articoli/big/"+id_articolo+".jpg";
	}
}

function check_search(lang){
	
	if(document.form_ricerca_dettagliata["Nome_"+lang].value=="" && document.form_ricerca_dettagliata.ID_categoria.value=="" && document.form_ricerca_dettagliata.ID_marca.value=="" && document.form_ricerca_dettagliata.Codice.value==""){
		alert("Specificare la categoria, il nome o la marca!");
	}else{
		if(document.form_ricerca_dettagliata["Nome_"+lang].value=="Nome del prodotto..." || document.form_ricerca_dettagliata["Nome_"+lang].value=="Product name..."){
			document.form_ricerca_dettagliata["Nome_"+lang].value="";
		}
		if(document.form_ricerca_dettagliata.Codice.value=="Ricerca per codice..."){
			document.form_ricerca_dettagliata.Codice.value="";
		}
		document.form_ricerca_dettagliata.submit();
	}
}

function check_search_simply(lang){
	
	if(document.form_ricerca_semplice.Search.value==""){
		alert("Specificare il testo da cercare!");
	}else
	if(document.form_ricerca_semplice.Search.value.length < 3){
		alert("Il testo da cercare è troppo corto!");
	}else{
		document.form_ricerca_semplice.submit();
	}
}

function scrivi_nome_prodotto(lang){
	if(document.form_ricerca_dettagliata["Nome_"+lang].value=="Nome del prodotto..." || document.form_ricerca_dettagliata["Nome_"+lang].value=="Product name..."){
		document.form_ricerca_dettagliata["Nome_"+lang].value="";
	}	
}
function scrivi_codice(){
	if(document.form_ricerca_dettagliata.Codice.value=="Ricerca per codice..."){
		document.form_ricerca_dettagliata.Codice.value="";
	}	
}

$(document).ready(function(){
	//create a bubble popup for each DOM element with class attribute as "text", "button" or "link" and LI, P, IMG elements.

	$('.popup_rates').CreateBubblePopup({
		selectable: true,
		position: 'top',
		align: 'center',
		innerHtml: '<img src="images/loading.gif" style="border:0px; vertical-align:middle; margin-right:10px; display:inline;" />loading!',
		innerHtmlStyle: { color:'#FFFFFF', 'text-align':'center' },
		themeName: 'azure',
		themePath: 'images/jquerybubblepopup-theme'
  	});
	
	$('.popup_rates').mouseover(function(){
		var button = $(this);		
		//$.get('popup_votazioni.php?ID_articolo='+$(this).attr("name"), function(data) {
		$.get('http://www.giwamaterassi.it/votazioni-PV'+$(this).attr("name")+'.html', function(data) {
			
			var seconds_to_wait = 1;
			function pause(){
				var timer = setTimeout(function(){
					seconds_to_wait--;
					if(seconds_to_wait > 0){
						pause();
					}else{
						button.SetBubblePopupInnerHtml(data, false); //false -> it shows new innerHtml but doesn't save it, then the script is forced to load everytime the innerHtml... 
					};
				},1000);
			};pause();
		});
	}); //end mouseover event

});

