
function initHome()
    {
        externallinks();
	   	var totslide = $('#bannerhome').children().length;
	   	
   		$('#bannerhome').cycle({ 
		    fx:    'fade',
		    speed:  2000,
			timeout:  5000,
			after: onAfter1   
		 });
		 
		 if (totslide == 1)
		 	onAfter1("", "", {currSlide: 0});
		 
		
		
		 AdjustSlideBox();
		 
		 $('#boxslide').cycle({ 
			prev: '#left-arrow',  
			next: '#right-arrow',   
			fx: 'scrollHorz',  
			timeout: 0,
			pause: 1,  
			after: UpdateInfoNovita
		});
		
		$('#boxslideoff').cycle({ 
			prev: '#left-arrow-off',  
			next: '#right-arrow-off',   
			fx: 'scrollHorz',  
			timeout: 0,
			pause: 1,  
			after: UpdateInfoOfferte
		});
		
		var preloadBg = new Image();
		preloadBg.src = no_testo_bg;
		var isIE6 = false; 
		if($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7) isIE6 = true;
		
		var preloadBg2 = new Image();
		if(isIE6)
			preloadBg2.src = with_testo_bg_ie6;
		else
			preloadBg2.src = with_testo_bg;
  }


var buildAlert = function(imageTodisplay, textTodisplay, cWidth, cHeight) {
$('body').append('<div class="CustomPopin"><div id="my_close" style="padding-top:6px; text-align:right; padding-right:6px; display:none;"><a href="#" onclick="closePopin(); return false;" title="Chiudi"><img src="/images/prettyPopin/b_close.gif" border="0" /></a></div><div class="CustomContent"><div id="my_error" style="text-align:center; font-weight:bold;"><img src="' + imageTodisplay + '" border="0" /><br/><br />' + textTodisplay + '</div><div class="CustomContent-container"></div></div></div>');
$c = $('.CustomPopin .CustomContent .CustomContent-container'); 

		var scrollPos = CustomScroll();

				cpopinWidth = 250;
				cpopinHeight =  100;
				if (!isNaN(cWidth) && cWidth >= cpopinWidth) cpopinWidth = cWidth;
				if (!isNaN(cHeight) && cHeight >= cpopinHeight) cpopinHeight = cHeight;
				$c.parent().parent().find('#my_close').show();
				$('.CustomPopin').width(cpopinWidth).height(cpopinHeight).css({
					'top': ($(window).height()/2) + scrollPos['scrollTop'] - (cpopinHeight/2),
					'left': ($(window).width()/2) + scrollPos['scrollLeft'] - (cpopinWidth/2)
				}).show().fadeIn(1000);
		
		};


var closePopin = function() {
		$('#overlay').fadeOut(1000,function(){ $(this).remove(); });
		$('.CustomPopin').fadeOut(1000,function(){ $(this).remove(); });
};

		
var buildOverlayAlert = function() {
				$('body').append('<div id="overlay"></div>');
				$('#overlay').css('height',$(document).height());
				$('#overlay').css('opacity',0).fadeTo(1000, 0.5);
			
			};

function openMarche()
	{
		if(curr_sel == '0' ) { buildAlert('/images/nolog.jpg', "Per visualizzare le marche disponibili e\' necessario selezionare prima la tipologia!", 250, 120 ); buildOverlayAlert(); $(window).scroll(function(){ CustomCenter(); });  return false;}
		if(opened_marcamenu == '0')
		{
                $.ajax({   
        		type: "GET",   
        		url: local_link_marche,   
        		data: "idtip=" + parseInt(curr_sel, 10), 
        		timeout: 10000,  //10 secondi
        		success: function(msg){
                    overlib( msg, WIDTH, 200, HEIGHT, 100, STICKY, CENTER, OFFSETX, -20, TEXTSIZE, '10px', TEXTCOLOR, '#525252', FGCOLOR, '#CFCFCF', BGCOLOR, '#333333', BORDER, 2);		
			        opened_marcamenu = '1';
		            opened_selezionemenu = '0';
			        opened_marcaadv = '0';
                    document.getElementById('marca' + curr_marca).style.backgroundColor = backcolor;
			        $('#boxmarca').scroll(function() { marca_scroll_pos = $('#boxmarca').scrollTop(); });
			        $('#boxmarca').animate({scrollTop: marca_scroll_pos}, 'slow');
                
                }});
				

			

		}
		else
		{
			cClick();
			opened_marcaadv = '0';
			opened_marcamenu = '0';
			opened_selezionemenu = '0';
		}
		return true;
	}

function AppOpenLivello1(idsettoreapp) {
var old_curr_menu_liv1_app = curr_menu_liv1_app;
curr_menu_liv1_app = idsettoreapp;
loading_tip_app = 0;

document.getElementById('app_liv2_' + curr_menu_liv1_app).style.display = 'none';
document.getElementById('app_liv2_working' + curr_menu_liv1_app).style.display = 'none';
document.getElementById('app_liv2_working' + curr_menu_liv1_app).innerHTML = "";
document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = 'none';
document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "";
curr_menu_liv2_app = '';

if( curr_menu_liv1_app == old_curr_menu_liv1_app ) 
{
	document.getElementById('app_liv2_' + curr_menu_liv1_app).innerHTML = '';
	document.getElementById('app_liv2_' + curr_menu_liv1_app).style.display = 'none';
	document.getElementById('app_liv2_working' + curr_menu_liv1_app).style.display = 'none';
    document.getElementById('app_liv2_working' + curr_menu_liv1_app).innerHTML = "";
	document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = 'none';
    document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "";
	curr_menu_liv1_app = '';
	curr_menu_liv2_app = '';
	return;
}
else
{
	if (old_curr_menu_liv1_app != ''  )
		{
			document.getElementById('app_liv2_' + old_curr_menu_liv1_app).innerHTML = '';
			document.getElementById('app_liv2_' + old_curr_menu_liv1_app).style.display = 'none';
			document.getElementById('app_liv2_working' + old_curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_working' + old_curr_menu_liv1_app).innerHTML = "";
			document.getElementById('app_liv2_error' + old_curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_error' + old_curr_menu_liv1_app).innerHTML = "";
		}
}


if( loading_cat_app == 1 || loading_page_app == 1)
{	
		document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "Caricamento in corso ...";
		document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = '';
		curr_menu_liv1_app = old_curr_menu_liv1_app;
		return;
}



var url = localsetapp;
var pars = 'idsettoreapp=' + idsettoreapp;
var placeholder = 'app_liv2_' + idsettoreapp;

loading_cat_app = 1;
$.ajax({   
		type: "GET",   
		url: localsetapp,   
		data: "idsettoreapp=" + idsettoreapp, 
		timeout: 10000,  //10 secondi
		success: function(msg){
			document.getElementById('app_liv2_' + idsettoreapp).innerHTML = '';
			$('#app_liv2_' + idsettoreapp).html(msg);
			$('#app_liv2_' + idsettoreapp).slideDown("slow", function(){   document.getElementById('app_liv2_' + curr_menu_liv1_app).style.display = ''; });
			document.getElementById('app_liv2_working' + curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_working' + curr_menu_liv1_app).innerHTML = "";
			document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "";
            if( backcolor == '#ffb931')
                document.getElementById('app_cat' + idsettoreapp).style.backgroundImage = "url(/images/over_liv1.jpg)";
            else
			     document.getElementById('app_cat' + idsettoreapp).style.backgroundImage = "url(/images/over_liv1_nol.jpg)";
			
			//cleanErrorSettori();
			loading_cat_app = 0;
		},
		beforeSend: function(xmlobj){
			document.getElementById('app_liv2_' + curr_menu_liv1_app).style.display = 'none';
			document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "";
			document.getElementById('app_liv2_working' + curr_menu_liv1_app).style.display = '';
            document.getElementById('app_liv2_working' + curr_menu_liv1_app).innerHTML = "<img src=\"/images/ajax-loading.gif\" style=\"border:0; vertical-align:absmiddle\" alt=\"\" /> Caricamento...";
			if (old_curr_menu_liv1_app != '') 
            {
                if( backcolor == '#ffb931')
                    document.getElementById('app_cat' + old_curr_menu_liv1_app).style.backgroundImage = "url(/images/menu_liv1.jpg)";
                else
                    document.getElementById('app_cat' + old_curr_menu_liv1_app).style.backgroundImage = "url(/images/menu_liv1_nol.jpg)";
            }
        },
		error: function(xmlobj, msg, errobj) {
			document.getElementById('app_liv2_' + curr_menu_liv1_app).style.display = 'none';
     		document.getElementById('app_liv2_working' + curr_menu_liv1_app).style.display = 'none';
            document.getElementById('app_liv2_working' + curr_menu_liv1_app).innerHTML = "";
     		document.getElementById('app_liv2_error' + curr_menu_liv1_app).style.display = '';
     		if (msg == "error") document.getElementById('app_liv2_error' + curr_menu_liv1_app).innerHTML = "Errore di caricamento ...";
     		if (old_curr_menu_liv1_app != '') document.getElementById('app_cat' + old_curr_menu_liv1_app).style.backgroundImage = "url(/images/over_liv1_nol.jpg)";
		} 
});

}

function AppHighLightLivello2(idsetapp, idcatapp)
{
	if( idcatapp != curr_menu_liv2_app)
    {
        if( backcolor == '#ffb931')
            document.getElementById('app_cat' + idsetapp + '_' + idcatapp).style.backgroundImage = "url(/images/over_liv2.jpg)";
        else
		  document.getElementById('app_cat' + idsetapp + '_' + idcatapp).style.backgroundImage = "url(/images/over_liv2_nol.jpg)";
    }
}

function AppResetLivello2(idsetapp, idcatapp)
{
	if( idcatapp != curr_menu_liv2_app)
    {
        if( backcolor == '#ffb931')
            document.getElementById('app_cat' + idsetapp + '_' + idcatapp).style.backgroundImage = "url(/images/menu_liv2.jpg)";
        else
            document.getElementById('app_cat' + idsetapp + '_' + idcatapp).style.backgroundImage = "url(/images/menu_liv2_nol.jpg)";
    }
}	

function AppHighLightLivello1(idcatapp)
{
	if(idcatapp != curr_menu_liv1_app)
    {
        if( backcolor == '#ffb931')
            document.getElementById('app_cat' + idcatapp).style.backgroundImage = "url(/images/over_liv1.jpg)";
        else
		    document.getElementById('app_cat' + idcatapp).style.backgroundImage = "url(/images/over_liv1_nol.jpg)";
    }
}

function AppResetLivello1(idcatapp)
{
	if(idcatapp != curr_menu_liv1_app)
    {
        if( backcolor == '#ffb931')
            document.getElementById('app_cat' + idcatapp).style.backgroundImage = "url(/images/menu_liv1.jpg)";
        else
		  document.getElementById('app_cat' + idcatapp).style.backgroundImage = "url(/images/menu_liv1_nol.jpg)";
    }
}





function MenuEffect(menu1, menu2, keytoset)
{

	$('#' + menu1).slideUp("fast", function(){
				$('#' + menu1).hide();
				$('#' + menu2).show();
				$('#' + menu2).slideDown("fast", function(){ currleftmenu = keytoset;  });
			});
}

function SwitchContestMenu(menu)
{
	switch (menu)
	{
		case 'app':
			MenuEffect('menualbero', 'menualberoapp', 'app');
			$('#linkapplicazioni').css({'color' : '#333333'});
			$('#linktipologia').css({'color' : '#ffffff'});
			$('#testatamenu').css({'background' : 'url(/images/bg_indiceprodotti_2.jpg) no-repeat top left'});
			$('#txtmenutype').text('per settori di applicazione');
			break;
		case 'tip':
			MenuEffect('menualberoapp', 'menualbero', 'tip');
			$('#linkapplicazioni').css({'color' : '#ffffff'});
			$('#linktipologia').css({'color' : '#333333'});
			$('#testatamenu').css({'background' : 'url(/images/bg_indiceprodotti_1.jpg) no-repeat top left'});
			$('#txtmenutype').text('gli articoli per tipologia');
			break;
		default:
			$('#menualberoapp').hide();
			$('#menualbero').show();
			currleftmenu = 'tip';
			
	}
}

function OpenLivello2(idsettore, idcategoria) { 
var old_curr_menu_liv2 = curr_menu_liv2;
var old_curr_menu_liv1 = curr_menu_liv1;
curr_menu_liv1 = idsettore;
curr_menu_liv2 = idcategoria;

document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";

if( curr_menu_liv2 == old_curr_menu_liv2 ) 
{
	document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = '';
	document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
	document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
    document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
	document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
    document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
	curr_menu_liv2 = '';
	return;
}
else
{
	if (old_curr_menu_liv2 != '')
	{		
		document.getElementById('liv3_' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).innerHTML = '';
		document.getElementById('liv3_' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).style.display = 'none';
		document.getElementById('liv3_working' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).style.display = 'none';
        document.getElementById('liv3_working' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).innerHTML = "";
		document.getElementById('liv3_error' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).style.display = 'none';
        document.getElementById('liv3_error' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).innerHTML = "";
	}
		
}

if( loading_tip == 1 )
{
		document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = '';
        document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "Caricamento in corso...";
		curr_menu_liv1 = old_curr_menu_liv1;
		curr_menu_liv2 = old_curr_menu_liv2;
		return;
}


document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2 ).style.display = '';
document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2 ).innerHTML = "<img src=\"/images/ajax-loading.gif\" style=\"border:0; vertical-align:absmiddle;\" alt=\"Caricamento\"/> Caricamento...";
var url = locallinkcat;
var pars = "idsettore=" + curr_menu_liv1 + "&idcategoria=" + curr_menu_liv2;
var placeholder = 'liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2;

loading_tip = 1;

$.ajax({   
		type: "GET",   
		url: locallinkcat,   
		data: "idsettore=" + curr_menu_liv1 + "&idcategoria=" + curr_menu_liv2, 
		timeout: 10000,  //10 secondi
		success: function(msg){
			document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = '';
			$('#liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).html(msg);
			$('#liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).slideDown("slow", function(){ document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = ''; });	
			document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
            document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
			document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
            document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
			document.getElementById('cat' + curr_menu_liv1 + "_" + curr_menu_liv2).style.backgroundImage = "url(/images/over_liv2.jpg)";	
			if(typeof window.cleanErrorCategorie == 'function') cleanErrorCategorie();	
			loading_tip = 0;	
		},
		beforeSend: function(xmlobj){
			document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
			document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
            document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
			document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = '';
            document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "<img src=\"/images/ajax-loading.gif\" style=\"border:0; vertical-align:absmiddle;\" alt=\"Caricamento\"/> Caricamento...";
			if (old_curr_menu_liv2 != '') document.getElementById('cat' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).style.backgroundImage = "url(/images/menu_liv2.jpg)";
		},
		error: function(xmlobj, msg, errobj) {
			document.getElementById('liv3_' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
     		document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = 'none';
            document.getElementById('liv3_working' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "";
     		document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).style.display = '';
     		if (msg == "error") document.getElementById('liv3_error' + curr_menu_liv1 + "_" + curr_menu_liv2).innerHTML = "Errore di caricamento ...";
     		if (old_curr_menu_liv2 != '') document.getElementById('cat' + old_curr_menu_liv1 + "_" + old_curr_menu_liv2).style.backgroundImage = "url(/images/over_liv2.jpg)";
		} 
});

}

function OpenLivello1(idsettore) {
var old_curr_menu_liv1 = curr_menu_liv1;
curr_menu_liv1 = idsettore;
loading_tip = 0;

document.getElementById('liv2_' + curr_menu_liv1).style.display = 'none';
document.getElementById('liv2_working' + curr_menu_liv1).style.display = 'none';
document.getElementById('liv2_working' + curr_menu_liv1).innerHTML = "";
document.getElementById('liv2_error' + curr_menu_liv1).style.display = 'none';
document.getElementById('liv2_error' + curr_menu_liv1).inerHTML = "";
curr_menu_liv2 = '';

if( curr_menu_liv1 == old_curr_menu_liv1 ) 
{
	document.getElementById('liv2_' + curr_menu_liv1).innerHTML = '';
	document.getElementById('liv2_' + curr_menu_liv1).style.display = 'none';
	document.getElementById('liv2_working' + curr_menu_liv1).style.display = 'none';
    document.getElementById('liv2_working' + curr_manu_liv1).innerHTML = "";
	document.getElementById('liv2_error' + curr_menu_liv1).style.display = 'none';
    document.getElementById('liv2_error' + curr_menu_liv1).innerHTML = "";
	curr_menu_liv1 = '';
	curr_menu_liv2 = '';
	return;
}
else
{
	if (old_curr_menu_liv1 != ''  )
		{
			document.getElementById('liv2_' + old_curr_menu_liv1).innerHTML = '';
			document.getElementById('liv2_' + old_curr_menu_liv1).style.display = 'none';
			document.getElementById('liv2_working' + old_curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_working' + old_curr_menu_liv1).innerHTML = "";
			document.getElementById('liv2_error' + old_curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_error' + old_curr_menu_liv1).innerHTML = "";
		}
}


if( loading_cat == 1 || loading_page == 1)
{	
		document.getElementById('liv2_error' + curr_menu_liv1).innerHTML = "Caricamento in corso ...";
		document.getElementById('liv2_error' + curr_menu_liv1).style.display = '';
		curr_menu_liv1 = old_curr_menu_liv1;
		return;
}



var url = locallinkset;
var pars = 'idsettore=' + idsettore;
var placeholder = 'liv2_' + idsettore;

loading_cat = 1;
$.ajax({   
		type: "GET",   
		url: locallinkset,   
		data: "idsettore=" + idsettore, 
		timeout: 10000,  //10 secondi
		success: function(msg){
			document.getElementById('liv2_' + idsettore).innerHTML = '';
			$('#liv2_' + idsettore).html(msg);
			$('#liv2_' + idsettore).slideDown("slow", function(){   document.getElementById('liv2_' + curr_menu_liv1).style.display = ''; });
			document.getElementById('liv2_working' + curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_working' + curr_menu_liv1).innerHTML = "";
			document.getElementById('liv2_error' + curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_error' + curr_menu_liv1).innerHTML = "";
			document.getElementById('cat' + idsettore).style.backgroundImage = "url(/images/over_liv1.jpg)";
			
			cleanErrorSettori();
			loading_cat = 0;
		},
		beforeSend: function(xmlobj){
			document.getElementById('liv2_' + curr_menu_liv1).style.display = 'none';
			document.getElementById('liv2_error' + curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_error' + curr_menu_liv1).innerHTML = "";
			document.getElementById('liv2_working' + curr_menu_liv1).style.display = '';
            document.getElementById('liv2_working' + curr_menu_liv1).innerHTML = "<img src=\"/images/ajax-loading.gif\" style=\"border:0; vertical-align:absmiddle\" alt=\"Caricamento\"/> Caricamento...";
			if (old_curr_menu_liv1 != '') document.getElementById('cat' + old_curr_menu_liv1).style.backgroundImage = "url(/images/menu_liv1.jpg)";
		},
		error: function(xmlobj, msg, errobj) {
			document.getElementById('liv2_' + curr_menu_liv1).style.display = 'none';
     		document.getElementById('liv2_working' + curr_menu_liv1).style.display = 'none';
            document.getElementById('liv2_working' + curr_menu_liv1).innerHTML = "";
     		document.getElementById('liv2_error' + curr_menu_liv1).style.display = '';
     		if (msg == "error") document.getElementById('liv2_error' + curr_menu_liv1).innerHTML = "Errore di caricamento ...";
     		if (old_curr_menu_liv1 != '') document.getElementById('cat' + old_curr_menu_liv1).style.backgroundImage = "url(/images/over_liv1.jpg)";
		} 
});

}



function HighLightLivello3(idset, idcat, idtip)
{
	if( idtip != curr_menu_liv3)
		document.getElementById('cat' + idset + '_' + idcat + '_' + idtip).style.backgroundImage = "url(/images/over_liv3.jpg)";
}

function ResetLivello3(idset, idcat, idtip)
{
	if( idtip != curr_menu_liv3)
		document.getElementById('cat' + idset + '_' + idcat + '_' + idtip).style.backgroundImage = "";
}

function HighLightLivello2(idset, idcat)
{
	if( idcat != curr_menu_liv2)
		document.getElementById('cat' + idset + '_' + idcat).style.backgroundImage = "url(/images/over_liv2.jpg)";
}

function ResetLivello2(idset, idcat)
{
	if( idcat != curr_menu_liv2)
		document.getElementById('cat' + idset + '_' + idcat).style.backgroundImage = "url(/images/menu_liv2.jpg)";
}

function HighLightLivello1(idcat)
{
	if(idcat != curr_menu_liv1)
		document.getElementById('cat' + idcat).style.backgroundImage = "url(/images/over_liv1.jpg)";
}

function ResetLivello1(idcat)
{
	if(idcat != curr_menu_liv1)
		document.getElementById('cat' + idcat).style.backgroundImage = "url(/images/menu_liv1.jpg)";
}
    
    
    
    function manageFocus()
    {
       if(document.getElementById("username"))
       {
            document.getElementById("username").onfocus=function() {
            focuseduser=true;
            };
            document.getElementById("username").onblur=function() {
            focuseduser=false;
            };
       }
       
       if(document.getElementById("pwd"))
       {
            document.getElementById("pwd").onfocus=function() {
            focusedpwd=true;
            };
            document.getElementById("pwd").onblur=function() {
            focusedpwd=false;
            };
       }
    }
    
    
    function externallinks()
    {
    var c=document.getElementById('content');
    if(c)
    {
        var ls=c.getElementsByTagName('a');
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external')
            {
                ls[i].className+=ls[i].className?' extlink':'extlink';
                ls[i].title+='(opens in new window)';
                ls[i].onclick=function(){window.open(this.href);return false}
            }
        }
    }
    }
    
    function SelSelezioneOpt(idsel)
	{
		document.getElementById('sel' + curr_sel).style.backgroundColor = '#CFCFCF';	
		curr_sel = idsel;
		document.getElementById('sel' + idsel).style.backgroundColor = backcolor;
		document.getElementById('src_sezione').innerHTML = document.getElementById('sel' + idsel).innerHTML;
		document.getElementById('selezioneval').value = idsel;
		document.getElementById('selezionetext').value = document.getElementById('sel' + idsel).innerHTML;
		ResetMarche();
		cClick();
		opened_marcaadv = '0';
		opened_selezionemenu = '0';
		opened_marcamenu = '0';
	}
	
	function ResetMarche()
	{
			curr_marca = '0';
			marca_scroll_pos = 0;
			document.getElementById('marcaval').value = "0";
			document.getElementById('marcatext').value = "Scegli la marca";
			document.getElementById('src_marca').innerHTML = "Scegli la marca";
	}
    
   	function SwitchSelColor(elemDiv)
	{
		if( ('sel' + curr_sel) != elemDiv.id) elemDiv.style.backgroundColor = backcolor;
	}

	function SwitchSelColor2(elemDiv)
	{
		if( ('sel' + curr_sel) != elemDiv.id) elemDiv.style.backgroundColor = '#CFCFCF';
	}
    
   	function SwitchColor(elemDiv)
	{
		if( ('marca' + curr_marca) != elemDiv.id) elemDiv.style.backgroundColor = backcolor;
	}

	function SwitchColor2(elemDiv)
	{
		if( ('marca' + curr_marca) != elemDiv.id) elemDiv.style.backgroundColor = '#CFCFCF';
	}
    
   	function SelMarcaOpt(idval)
	{
		document.getElementById('marca' + curr_marca).style.backgroundColor = '#CFCFCF';	
		curr_marca = idval;
		document.getElementById('marca' + idval).style.backgroundColor = backcolor;
		document.getElementById('src_marca').innerHTML = document.getElementById('marca' + idval).innerHTML;
		document.getElementById('marcaval').value = idval;
		document.getElementById('marcatext').value = document.getElementById('marca' + idval).innerHTML;	
		cClick();
		opened_marcaadv = '0';
		opened_marcamenu = '0';
		opened_selezionemenu = '0';
	}
    


function AdjustSlideBox()
{
	
		//SLIDE BOX NOVITA
			kn = 1;
			max_desc_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('info' +  kn))
				{
					if( max_desc_height < $('#info' + kn).height()) max_desc_height = $('#info' + kn).height();
				}
				kn++;
			}
			kn = 1;
			while(kn <= 12)
			{
				if(document.getElementById('info' +  kn))
				{
					$('#info' + kn).height(max_desc_height);
				}
				kn++;
			}
			
			
			kn= 1;
			max_img_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('imghome' + kn))
				{
					if( max_img_height < $('#imghome' + kn).height()) max_img_height = $('#imghome' + kn).height();
				}
				kn++;
			}
			
			
			kn = 1;
			while(kn <= 12)
			{
				if(document.getElementById('imghome' +  kn))
				{
					$('#imghome' + kn).height(max_img_height);
					subheight = max_img_height - $('#imgelem' + kn).height();
					if( subheight > 0)
					{
						subheight = subheight / 2;
						$('#imgelem' + kn).css("padding-top", subheight); 
					}
					
				}
				kn++;
			}
			
			kn = 1;
			max_piece_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('piece' +  kn))
				{
					if( max_piece_height < $('#piece' + kn).height()) max_piece_height = $('#piece' + kn).height();
				}
				kn++;
			}
			kn=1;
			while(kn <= 3)
			{
				if(document.getElementById('slide' +  kn))
					$('#slide' + kn).height(max_piece_height);
				kn++;
			}
			
			$('#boxslide').height(max_piece_height);
			
			//SLIDE BOX OFFERTE
			kn = 1;
			max_desc_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('infooff' +  kn))
				{
					if( max_desc_height < $('#infooff' + kn).height()) max_desc_height = $('#infooff' + kn).height();
				}
				kn++;
			}
			kn = 1;
			while(kn <= 12)
			{
				if(document.getElementById('infooff' +  kn))
				{
					$('#infooff' + kn).height(max_desc_height);
				}
				kn++;
			}
			
			
			kn= 1;
			max_img_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('imghomeoff' + kn))
				{
					if( max_img_height < $('#imghomeoff' + kn).height()) max_img_height = $('#imghomeoff' + kn).height();
				}
				kn++;
			}
			
			
			kn = 1;
			while(kn <= 12)
			{
				if(document.getElementById('imghomeoff' +  kn))
				{
					$('#imghomeoff' + kn).height(max_img_height);
					subheight = max_img_height - $('#imgelemoff' + kn).height();
					if( subheight > 0)
					{
						subheight = subheight / 2;
						$('#imgelemoff' + kn).css("padding-top", subheight); 
					}
					
				}
				kn++;
			}
			
			kn = 1;
			max_piece_height = 0;
			while(kn <= 12)
			{
				if(document.getElementById('pieceoff' +  kn))
				{
					if( max_piece_height < $('#pieceoff' + kn).height()) max_piece_height = $('#pieceoff' + kn).height();
				}
				kn++;
			}
			kn=1;
			while(kn <= 3)
			{
				if(document.getElementById('slideoff' +  kn))
					$('#slideoff' + kn).height(max_piece_height);
				kn++;
			}
			
			$('#boxslideoff').height(max_piece_height);
			
    }
    
function UpdateInfoNovita(curr, next, opts)
{
	var inizio = 1;
	if (opts.currSlide * 4 != 0) inizio = opts.currSlide * 4;
	document.getElementById('InfoNovita').innerHTML = inizio + ' - ' + ((opts.currSlide + 1) * 4) + ' di ' +  opts.slideCount * 4;
}

function UpdateInfoOfferte(curr, next, opts)
{
	var inizio = 1;
	if (opts.currSlide * 4 != 0) inizio = opts.currSlide * 4;
	document.getElementById('InfoOfferte').innerHTML = inizio + ' - ' + ((opts.currSlide + 1) * 4) + ' di ' +  opts.slideCount * 4;
}

   function onAfter1(curr,next,opts) { 
		currslide = opts.currSlide + 1;
		if(arr_banner_testo.length > currslide && arr_banner_testo[currslide] != "")
		{
			document.getElementById('testobanner').innerHTML = arr_banner_testo[currslide];
			var isIE6 = false; 
			if($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7) isIE6 = true;
			
			if(isIE6)
			{
				if(document.getElementById('copertura_banner').style.backgroundImage != "url(" + with_testo_bg_ie6 + ")")
					document.getElementById('copertura_banner').style.backgroundImage = "url(" + with_testo_bg_ie6 + ")";
			}
			else
			{
				if(document.getElementById('copertura_banner').style.backgroundImage != "url(" + with_testo_bg + ")")
					document.getElementById('copertura_banner').style.backgroundImage = "url(" + with_testo_bg + ")";
			}
		}
		else
		{
			document.getElementById('testobanner').innerHTML = arr_banner_testo[currslide];
			if(document.getElementById('copertura_banner').style.backgroundImage !=  "url(" + no_testo_bg +")")
				document.getElementById('copertura_banner').style.backgroundImage = "url(" + no_testo_bg + ")";
		}
} 

    function cleanUsername()
    {
        if(document.getElementById('username'))
        {
            if (document.getElementById('username').value == "Username") document.getElementById('username').value = "";
        }
        
        return true;
    }
    
    function cleanPwd()
    {
        if(document.getElementById('pwd'))
        {
            if (document.getElementById('pwd').value == "Password") document.getElementById('pwd').value = "";
        }
        
        return true;
    }
    
    function CheckLoginTop(){
		if( document.getElementById("username").value == "" || document.getElementById("username").value == "Username" )
		{
			alert('L\'Username e\' vuoto!');
			return;
		}
	
		if( document.getElementById("pwd").value == "" || document.getElementById("pwd").value == "Password" )
		{
			alert('La Password e\' vuota!');
			return;
		}
	
		document.getElementById('logintop').submit();
	}
	
	function openBannerLink()
	{
		if( arr_banner_link.length > currslide && arr_banner_link[currslide] != "" )
		{	
			if(arr_banner_target.length > currslide && arr_banner_target[currslide] == "1")
				window.open(arr_banner_link[currslide], 'ExternalLink', '');
			else
				window.location.href = arr_banner_link[currslide];
		}		
	
	}



	function cleanRicerca()
	{
		
		if(document.getElementById('searchkey'))
		{
			if(document.getElementById('searchkey').value == "Inserisci parola chiave")  document.getElementById('searchkey').value = "";
		}
	}
	
	function cleanNewUser()
	{
		if(document.getElementById('newuser'))
		{
			if(document.getElementById('newuser').value == "Username") document.getElementById('newuser').value = "";
		}
	}
	
	function cleanNewEmail()
	{
		if(document.getElementById('newemail'))
		{
			if(document.getElementById('newemail').value == "E-mail") document.getElementById('newemail').value = "";
		}
	}
	
	function SubmitFirstFilter()
	{
		marca = document.getElementById('marcatext').value;
		tipo = document.getElementById('selezioneval').value;
		search = document.getElementById('searchkey').value;
		var params = "?";
		if(marca != "" && marca != "Scegli la marca") params += "marche=" + escape(marca);
		if(tipo != "" && tipo != "Scegli la tipologia") 
		{
			if(params != "?")
				params += "&tipo=" + escape(tipo);
			else
				params += "tipo=" + escape(tipo);
		}
		
		if(search.length < 3) {alert('La chiave di ricerca deve essere MINIMO di 3 caratteri.'); return false;}
		if(search == "Inserisci parola chiave") {alert('Inserisci una chiave di ricerca valida!'); return false;}
		
		if(params != "?")
			params +="&searchstring=" + escape(search);
		else
			params +="searchstring=" + escape(search);
			
		window.location.href = '/search.php' + params;
		return false;
	}
    
    
    function CustomScroll(){
			scrollTop = $(window).scrollTop();
			scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
			return {scrollTop:scrollTop,scrollLeft:scrollLeft};
}

function CustomCenter() {
			if(!$('.CustomPopin')) return;
			var scrollPos = CustomScroll();

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};

			projectedTop = ($(window).height()/2) + scrollPos['scrollTop'] - ($('.CustomPopin').height()/2);
			if(projectedTop < 0) {
				projectedTop = 10;
				_followScroll = false;
			}else{
				_followScroll = true;
			};

			$('.CustomPopin').css({
				'top': projectedTop,
				'left': ($(window).width()/2) + scrollPos['scrollLeft'] - ($('.CustomPopin').width()/2)
			});	
}

		function getFunctionName(fn) 
		{ 
		 var rgx = /^function\s+([^\(\s]+)/ 
		 var matches = rgx.exec(fn.toString()); 
		 return matches ? matches[1] : "anonymous" 
		} 
 
		function HandlerExists(triggerName, handlerName) { 
		        exists = false; 
		        if ($("a[rel^='prettyPhoto']").data('events') !== undefined) { 
		            var event = $("a[rel^='prettyPhoto']").data('events')[triggerName]; 
		            if(event !== undefined) 
		            { 
		                $.each(event, function(i, handler) { 
		                    if (getFunctionName(handler) == handlerName) { 
		                        exists = true; 
		                    } 
		                }); 
		            } 
		        } 
		        return exists; 
		    } 
            
            
  function checkKeycode(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    
    if (document.getElementById("username"))
    {
        if (keycode == 13 && focuseduser == true) 
		{
			CheckLoginTop();
        	return true;
        }
    }
    
    if (document.getElementById("pwd"))
    {
        if (keycode == 13 && focusedpwd == true) 
		{
			CheckLoginTop();
        	return true;
        }
    }
   
    return true;
}

function HighLightLivello1(idcat)
{
	if(idcat != curr_menu_liv1)
		document.getElementById('cat' + idcat).style.backgroundImage = "url(/images/over_liv1.jpg)";
}

function ResetLivello1(idcat)
{
	if(idcat != curr_menu_liv1)
		document.getElementById('cat' + idcat).style.backgroundImage = "url(/images/menu_liv1.jpg)";
}

function openPrettyHome(filelink, desclink, widthlink, heightlink)
{
	$.prettyPhoto.open(filelink + '?iframe=true&width=' + widthlink + '&height=' + heightlink, '', desclink);
    return false;
}    
    
    
