var i=1;
var prec_plus='', prec_cat='';
var testo_prodotti_it = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Seleziona il prodotto dall&rsquo;elenco delle categorie qui a sinistra, scegli le dimensioni e tutte le caratteristiche che dovr&agrave; avere, per richiedere subito il tuo preventivo on-line.<br/></p>";
var testo_usato_it = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Edil Euganea oltre ai nuovo prodotti, propone wc, monoblocchi e container usati, per tutti coloro che hanno bisogno di un prodotto di qualit&agrave; ma ad un prezzo ridotto. Chiunque abbia necessit&agrave; di container ma anche monoblocchi e wc usati, pu&ograve; scegliere tra una vasta gamma di prodotti in buono stato che Edil Euganea propone in base alla disponibilit&agrave;.<br/><br/>Seleziona il prodotto usato dall&rsquo;elenco delle categorie qui a sinistra e calcola subito il tuo preventivo on-line.<br/></p>";
var testo_noleggio_it = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Seleziona il prodotto dall&rsquo;elenco delle categorie qui a sinistra e calcola subito il tuo preventivo on-line.<br/></p>";
//
var testo_prodotti_en = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Select the used product from the category list on the left, choose the dimensions and all technical specifications of your product, to ask immediately your quote online.<br/></p>";
var testo_usato_en = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">The company EDIL EUGANEA S.R.L. is able to offer &ndash; as SECOND HAND ITEMS some articles&nbsp; such as WC TOILET, MONOBLOCKS and CONTAINERS for&nbsp; all people requiring&nbsp; for a cheap and quality product<br/>Anyone need for containers as well as toilet blocks and used, can choose from a wide range of products in good condition that Edil Euganea offers subject to availability.<br/><br/>Select the used product from the category list on the left and quickly calculate your quote online.<br/></p>";
var testo_noleggio_en = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Select the used product from the category list on the left and quickly calculate your quote online.<br/></p>";
//
var testo_prodotti_fr = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Cliquez parmi les articles (plac&eacute;s sur le c&ocirc;t&eacute; gauche), choisissez les dimensions et les sp&eacute;cifications techniques de votre produit et veuillez calculer votre devis on line.<br/></p>";
var testo_usato_fr = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Edil Euganea en plus des nouveaux produits , offre une vaste gamme des articles, c&rsquo;est-&agrave;-dire,&nbsp; WC, monoblocs et&nbsp; conteneurs&nbsp; comme materiels d&rsquo;occasion, pour ceux qui ont besoin d&rsquo;un produit de qualit&eacute; mais avec un prix de vente tr&egrave;s convenables; dans le parc Edil Euganea vous trouverez plusieurs produits d&rsquo;occasion , donc vous &ecirc;tes priez &agrave; cliquer parmi les articles (plac&eacute;s sur le c&ocirc;t&eacute; gauche) et veuillez calculer votre devis.<br/><br/>Choisissez un produit pour avoir les donn&eacute;es techniques<br/></p>";
var testo_noleggio_fr = "<p style=\"margin:auto; width: 350px; text-align:justify; margin-top: -20px; font-size: 12px; font-family: Verdana; color: #333;\">Cliquez parmi les articles (plac&eacute;s sur le c&ocirc;t&eacute; gauche) et veuillez calculer votre devis.<br/></p>";
//
var prec_product = "";
var globali = { prec_preview: "", prec_class: "" };
var active_color = "#55bdff";

//Noleggio
var noleggio = {
						n_opt: 0,
						totale: 0.00,
						prec_totale: 0,
						curr_cost: "cost1",
						prec_cost: 0
						};

$(document).ready( function(){
	
	//Fancybox
	$('.fancybox').colorbox( {maxWidth: '800px', maxHeight: '570px'} );

	/*
		Al click sparisce il valore di default e cambia lo stile.
		All'uscita, se non è stato inserito niente, torna il valore di default
	*/
	$('.default_value').each( function(){
		$(this).attr( 'start_value', $(this).val() );
		$(this).css('font-style', 'italic');
		$(this).css('color', '#888');

		$(this).bind( 'focus', function(){
			if( $(this).val() == $(this).attr('start_value') ){
				$(this).css('font-style', 'normal');
				$(this).css('color', '#333');
				$(this).val('');
			}
		} );

		$(this).bind( 'focusout', function(){
			if( $(this).val()=='' ){
				$(this).css('font-style', 'italic');
				$(this).css('color', '#888');
				$(this).val( $(this).attr('start_value') );
			}
		});
	} );
	
	
	/*
		Centro i div informativi al centro della pagina
	*/
	centerX = screen.width/2-parseInt($('.ok').width())/2;
	centerY = screen.height/2-parseInt($('.ok').height());
	$('.ok').css( 'left', centerX );
	$('.ok').css( 'top', centerY );
	$('.ok').fadeIn(500).delay(1000).fadeOut(2000);
	
	
	/*
		Centro i div di errore al centro della pagina
	*/
	centerX = screen.width/2-parseInt($('.error').width())/2;
	centerY = screen.height/2-parseInt($('.error').height());
	$('.error').css( 'left', centerX );
	$('.error').css( 'top', centerY );
	$('.error').fadeIn(500).delay(1000).fadeOut(2000);
} );


function createMailto(name,domain,text,style){
	var STYLE="";
	EMAIL=name+"@"+domain;
	if( text )
		TESTO=text;
	else
		TESTO=EMAIL;
	if( style )
		STYLE="style=\""+style+"\"";
	document.write("<a class=\"mail\" href=\"mailto:"+EMAIL+"\""+STYLE+">"+TESTO+"</a>");
}


/*
	Carica con AJAX un URL sul div "div"
*/
function carica( div, url ){
	$(div).html( "<center><img src='images/loading.gif' /><br/>Caricamento...<br/></center>" );
	$.get( url, function(data, response){
		if( response=="success" )
			$(div).html( data );
		else
			$(div).html( "<span style=\"color:#a00;\"><b><big>Errore durante il caricamento! Riprova</big></b></span>" );
	});
}



/*
	Scrolling del div dei prodotti avanti e indietro
*/
function slideImage( id, n, max ){
	max = parseInt(max) - 327;
	currentX = parseInt( $(id).css('left') );

	if( n == -1 ){
		if( currentX > -parseInt(max) ){
			dst = (currentX + 327*n)+"px";
			$(id).animate({ left: dst });
		}
	}
	else{
		if( currentX < 0 ){
			dst = (currentX + 327*n)+"px";
			$(id).animate({ left: dst });
		}
	}
}



function showDetails( idprodotto, categoria, categoria2, nome_prodotto, lang){
	//tb_show( "", "ajax_productdetails2.php?idprodotto="+idprodotto+"&categoria='"+categoria+"'&categoria2='"+categoria+"'&nome_prodotto='"+nome_prodotto+"'&modal=false&height=500&width=800" );
	tb_show( "", "ajax_productdetails2.php?idprodotto="+idprodotto+"&categoria="+categoria+"&categoria2="+categoria2+"&nomeprodotto="+nome_prodotto+"&lang="+lang+"&modal=false&height=500&width=800" );
}


function changeClass( el, new_class ){
	$(el).attr( "class", new_class );
}

function togliHover(){
	$("h2").removeAttr("onmouseover");
	$("h2").removeAttr("onmouseout");
}





/*
	Crea una riga di tabella con un optional
*/
function add_optional(){
	//check iniziali
	if( parseInt($('#current_optional').val()) <= 0 ){
		alert( "Selezionare un optional..." );
		return false;
	}

	else if( parseInt($('#current_optional_qta').val())<=0 ){
		alert("La quantita' inserita non e' valida!");
		return false;
	}

	//calcoli
	else{
		//aggiungo il costo dell'optional in base ai mesi di noleggio selezionati
		ntempi = $("#tempi_noleggio option:selected").val();
		costo_tempi = "costo"+ntempi;
		cost = parseFloat( $('#current_optional option:selected').attr( costo_tempi ) * parseInt($('#current_optional_qta').val()) );

		
		nome_accessorio = $('#current_optional option:selected').text();
		
		quantita_accessorio = $('#current_optional_qta').val();
		
		$('#optionals_table').html( $('#optionals_table').html()+"\n<div id=\"opt_"+noleggio.n_opt+"\"><div style=\"float:left;\"><b>"+$('#current_optional_qta').val()+"</b> x "+$('#current_optional option:selected').text()+"</div> <div class=\"gray\" style=\"padding-left:10px; float:left;\" onmouseover=\"this.style.cursor='pointer';\" onclick=\"remove_optional("+noleggio.n_opt+", "+cost+", "+quantita_accessorio+");\"><small>(rimuovi questo optional)</small></div><br/></div>" );

		
		
		
		
				
		str_noleggio = $("#accessori_noleggio").val();
		
					
		$("#accessori_noleggio").attr( "value", str_noleggio+' '+quantita_accessorio+'x '+nome_accessorio+'<br/>');
		
		
		
		
		
		
		//Aggiorno il totale
		noleggio.totale = parseFloat($('#totale').text()) + parseFloat(cost);
		noleggio.totale = noleggio.totale.toFixed(2);
		$('#totale').text( noleggio.totale );
		
		$("#costo_totale").attr('value', noleggio.totale+' EUR');
		
		noleggio.n_opt++;
		$("#tempi_noleggio").attr( "disabled", "disable" );
	}
	return true;
}



function remove_optional( n_opt, cost, quantita_accessorio){
	
	
	
	$("#opt_"+n_opt).remove();
	noleggio.totale = noleggio.totale - cost;
	$('#totale').text( noleggio.totale.toFixed(2) );

	$("#costo_totale").attr('value', noleggio.totale+' EUR');
	
	noleggio.n_opt--;

	if( noleggio.n_opt==0 ){
		$("#tempi_noleggio").removeAttr( "disabled" );
		$('#accessori_noleggio').val(" ");
	}
	
	
	
	
			
	str_noleggio = $("#accessori_noleggio").val();
	str_noleggio = str_noleggio.split(quantita_accessorio+'x');
	
	//alert (str_noleggio);
	//str_noleggio = $('#optionals_table').html();
	
	
	
	
	/*$('#accessori_noleggio').val( str_noleggio.replace ('<div style="float:left;">', ''));
	$('#accessori_noleggio').val( str_noleggio.replace ('<small>(rimuovi questo optional)</small>', ''));
	$('#accessori_noleggio').val( str_noleggio.replace ('</div><br></div>', ''));
	*/
	
	/*str_noleggio_2 = str_noleggio.replace ('<small>(rimuovi questo optional)</small>', '');
	str_noleggio_2 = str_noleggio_2.replace ('</div><br></div>', '');
	str_noleggio_2 = str_noleggio_2.replace ('div style="float:left;">', '');
	str_noleggio_2 = str_noleggio_2.replace ('</div> <div class="gray" style="padding-left: 10px; float: left; cursor: pointer;" onmouseover="this.style.cursor="\'"pointer"\'";" onclick="remove_optional(','');
	
	
	alert (str_noleggio_2);*/
	
	
		

}



/*
FUNZIONI PER NOLEGGIO
*/
//Cambia il costo del noleggio in base ai mesi selezionati
function change_cost_noleggio(){
	cost = $("#tempi_noleggio option:selected").attr("cost");
	totale = parseFloat( $("#totale").text() ) - parseFloat( noleggio.prec_cost );
	totale += parseFloat( cost );
	
	$("#totale").text( totale.toFixed(2) );
	
	$("#costo_totale").attr('value', totale+' EUR');
	
	noleggio.prec_cost = cost;
}


function preview_macroarea( img, txt ){
	$("#product_details").html("");
	$('#product_details').html( "<div class='center'>"+txt+"</div><img src='images/macroaree/"+img+"' align='right'/>" );
}



/*function reset_preview_macroarea( txt ){
	$("#product_details").html( "<div class='center'>"+txt+"</div>" );
}*/

function preview_usato( idcategoria , lang ){
	$("#product_details").html( "<center><img src='images/loading.gif' /><br/>Caricamento...<br/></center>" );
	$.get( "ajax_usatolist.php?idcategoria="+idcategoria+"&lang="+lang, function(data, response){
		if( response=="success" )
			$("#product_details").html( data );
		else
			$("#product_details").html( "<span style=\"color:#a00;\"><b><big>Errore durante il caricamento! Riprova</big></b></span>" );
	});
	
	
}

function preview_noleggio( idcategoria, lang ){
	$("#product_details").html( "<center><img src='images/loading.gif' /><br/>Caricamento...<br/></center>" );
	$.get( "ajax_noleggiolist.php?idcategoria="+idcategoria+"&lang="+lang, function(data, response){
		if( response=="success" )
			$("#product_details").html( data );
		else
			$("#product_details").html( "<span style=\"color:#a00;\"><b><big>Errore durante il caricamento! Riprova</big></b></span>" );
	});
}


/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
}
