//********************************************************************************************************//
//*************     Home Page   **************************************************************************//
//********************************************************************************************************//
function MondoEffectRollover( mondo ) {
	if( current_mondo != mondo )
	{
		var sx = mondo + "sx";
		var dx = mondo + "dx";
		var cx = mondo + "cx";
		var tx = mondo + "text";
		this.document.getElementById(sx).src = '/images/angolo-sx-blu.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-blu.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-blu.gif)';	
		this.document.getElementById(tx).style.color = '#FFFFFF';
	}
}

function MondoEffectRollout( mondo ) {
	if( current_mondo != mondo )
	{
		var sx = mondo + "sx";
		var dx = mondo + "dx";
		var cx = mondo + "cx";
		var tx = mondo + "text";
		this.document.getElementById(sx).src = '/images/angolo-sx-grigio.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-grigio.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-grigio.gif)';
		this.document.getElementById(tx).style.color = '#0000A5';
	}
}

function SwitchMondo( mondo ) {
	switch (mondo) {
		case "nuovo":
			window.location.href = link_mondo_nuovo;
			break;
		case "usato":
			window.location.href = link_mondo_usato;
			break;
		case "noleggio":
			window.location.href = link_mondo_noleggio;
			break;
	}
	return true;
}

//********************************************************************************************************//
//*************     Login      **************************************************************************//
//********************************************************************************************************//
function CheckLoginTop(){
	if( document.logintop.username.value == "" )
	{
		alert('Username è vuoto!');
		return false;
	}

	if( document.logintop.password.value == "" )
	{
		alert('Password è vuota!');
		return false;
	}
	return true;
}

function cleanbox() {
	if( document.SearchBox.searchstring.value == "Cerca Prodotto" ||	document.SearchBox.searchstring.value == "Search Product")
			document.SearchBox.searchstring.value = "";
	return true;
}

function checklenght() {
	var str_search;
	str_search = document.SearchBox.searchstring.value;
	if( str_search.length < 3) 
	{
		alert('Inserire una stringa di ricerca maggiore di 3 caratteri');
		return false;
	}
	if( str_search == "Cerca Prodotto" || str_search == "Search Product" )
	{
		alert('Inserire una chiave di ricerca valida');
		return false;
	}
	return true;
}

function cleanboxusername() {
	if( document.logintop.username.value == "username")
			document.logintop.username.value = "";
	return true;
}

function cleanboxpwd() {
	if( document.logintop.password.value == "password")
			document.logintop.password.value = "";
	return true;
}

function display_testit() {
	var t = 750;
	var obj = document.getElementById("testit");
	if (obj) {
		if(obj.style.visibility == "visible") {
			obj.style.visibility = "hidden";
			t = 250;
		} else {
			obj.style.visibility = "visible";
		}
	}
	window.setTimeout("display_testit()", t);
}

window.setTimeout("display_testit()", 750);

//********************************************************************************************************//
//*************   Menu Laterale      *********************************************************************//
//********************************************************************************************************//
function OpenCategoria(idsettore) {
	var old_current_idsettore = current_idsettore;
	current_idsettore = idsettore;
	loading_tip = 0;

	document.getElementById('cat_set' + current_idsettore).style.display = 'none';
	document.getElementById('cat_working' + current_idsettore).style.display = 'none';
	document.getElementById('cat_working' + current_idsettore).style.innerHTML = "";
	document.getElementById('cat_error' + current_idsettore).style.display = 'none';
	document.getElementById('cat_error' + current_idsettore).style.display = "";
	current_idcategoria = '';

	if( current_idsettore == old_current_idsettore ) 
	{
		document.getElementById('cat_set' + idsettore).innerHTML = '';
		current_idsettore = '';
		current_idcategoria = '';
		return;
	}
	else
	{
		if (old_current_idsettore != ''  )
			{
				document.getElementById('cat_set' + old_current_idsettore).innerHTML = '';
				//document.getElementById('cat_working' + old_current_idsettore).style.display = 'none';
				//document.getElementById('cat_error' + old_current_idsettore).style.display = 'none';
			}
	}

	if( loading_cat == 1 || loading_page == 1)
	{	
			document.getElementById('cat_error' + current_idsettore).style.display = '';
					document.getElementById('cat_error' + current_idsettore).innerHTML = "Caricamento in corso ...";
			current_idsettore = old_current_idsettore;
			return;
	}

	document.getElementById('cat_working' + idsettore).style.display = '';
	var pars = 'idsettore=' + idsettore;
	var placeholder = 'cat_set' + idsettore;
	loading_cat = 1;
	var MenuAjax = new Ajax.Updater( placeholder, url_set, { method: 'get', parameters: pars, onLoading: setInit, onComplete: setComplete, onFailure: reportErr, evalScripts:true});

}

function reportErr(request)
{
	 document.getElementById('cat_set' + current_idsettore).style.display = 'none';
	 document.getElementById('cat_working' + current_idsettore).style.display = 'none';
	 document.getElementById('cat_error' + current_idsettore).style.display = '';
	 document.getElementById('cat_error' + current_idsettore).innerHTML = "Caricamento in corso ...";
}

function setInit(){
	document.getElementById('cat_set' + current_idsettore).style.display = 'none';
	document.getElementById('cat_error' + current_idsettore).style.display = 'none';
	document.getElementById('cat_working' + current_idsettore).innerHTML = 'Caricamento';
	document.getElementById('cat_working' + current_idsettore).style.display = '';
}

 function setComplete() {
	document.getElementById('cat_set' + current_idsettore).style.display = '';
	document.getElementById('cat_working' + current_idsettore).style.display = 'none';
	document.getElementById('cat_error' + current_idsettore).style.display = 'none';
					
	cleanErrorSettori();
	loading_cat = 0;
}

function OpenTipologia(idsettore, idcategoria) { 
	var old_current_idcategoria = current_idcategoria;
	var old_current_idsettore = current_idsettore;
	current_idsettore = idsettore;
	current_idcategoria = idcategoria;

	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore).style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").innerHTML = '';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").innerHTML = 'none';

	if( current_idcategoria == old_current_idcategoria ) 
	{
		document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore).innerHTML = '';
		current_idsettore = '';
		current_idcategoria = '';
		return;
	}
	else
	{
		if (old_current_idcategoria != '')
				document.getElementById('tip_cat' + old_current_idcategoria + "_set" + old_current_idsettore).innerHTML = '';
			
	}

	if( loading_tip == 1 )
	{
			document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").style.display = '';
					document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").innerHTML = 'Caricamento in corso ...';
			current_idsettore = old_current_idsettore;
			current_idcategoria = old_current_idcategoria;
			return;
	}


	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").style.display = '';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").innerHTML = 'Caricamento';

	var pars = 'idsettore=' + current_idsettore + "&idcategoria=" + current_idcategoria;
	var placeholder = 'tip_cat' + current_idcategoria + "_set" + current_idsettore;
	loading_tip = 1;
	var SubMenuAjax = new Ajax.Updater( placeholder, url_cat, { method: 'get', parameters: pars, onLoading: setInitSub, onComplete: setCompleteSub, onFailure: reportErrSub, evalScripts:true});
}

function reportErrSub(request)
{
	 document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore).style.display = 'none';
	 document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").style.display = 'none';
	 document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").style.display = '';
	 document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").innerHTML = 'Caricamento in corso ...';
}

function setInitSub(){
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore).style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").style.display = '';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").innerHTML = 'Caricamento';
}

 function setCompleteSub() {
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore ).style.display = '';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "working").style.display = 'none';
	document.getElementById('tip_cat' + current_idcategoria + "_set" + current_idsettore + "error").style.display = 'none';
	loading_tip = 0;
	cleanErrorCategorie();				
}


function apriCatInfo(sName) {
var sRef;
var sPar;
var obj;
sRef = "OpenWindow";
sPar = "menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,width=500,height=600";
obj = window.open(sName,sRef,sPar);
obj.focus();
}
//********************************************************************************************************//
//*************    Tipologia Offerte  Novita   News  Eventi **********************************************//
//********************************************************************************************************//
function reportErrBottoniNav(request)
{
	Element.hide('bottoni_navigazione_info');
	Element.hide('bottoni_navigazione_loading');
	document.getElementById("bottoni_navigazione_error").innerHTML = 'Errore interno del server non è stato possibile caricare i filtri di ricerca';
	Element.show('bottoni_navigazione_error');
}

function SetInitBottoniNav(request)
{
	Element.hide('bottoni_navigazione_info');
	Element.hide('bottoni_navigazione_error');
	document.getElementById("bottoni_navigazione_loading").innerHTML = '<img src="/images/cart_load.gif" align="middle" border="0">Caricamento filtri di ricerca ...';
	Element.show('bottoni_navigazione_loading');
}

function setCompleteBottoniNav(request)
{
	Element.hide('bottoni_navigazione_error');
	Element.hide('bottoni_navigazione_loading');
	Element.show('bottoni_navigazione_info');
}

function EffectRolloverPag( idpag ) {
	if( current_page_off != idpag )
	{
		var cx = "cx" + idpag;
		this.document.getElementById(cx).style.background = 'url(/images/page_bg_over.gif)';
		this.document.getElementById(cx).style.backgroundRepeat = 'no-repeat';
		this.document.getElementById(cx).style.color = '#0000A5';
	}
}

function EffectRolloutPag( idpag ) {
	if( current_page_off != idpag )
	{
		var cx = "cx" + idpag;
		this.document.getElementById(cx).style.background = 'url(/images/page_bg.gif)';
		this.document.getElementById(cx).style.backgroundRepeat = 'no-repeat';
		this.document.getElementById(cx).style.color = '#FFFFFF';
	}
}

function openArticolo(idart, artcodice, idprod) {
	if(idart != "") 
	{
		lang=0;
		if (document.SearchBox.sito.options[0].text=="All site") lang=1;

		if(idprod != "") window.location.href = (lang==0)?'/prod/' + idart + '_' + idprod + '_' + artcodice + '.html':'/product/' + idart + '_' + idprod + '_' + artcodice + '.html';
		else window.location.href = (lang==0)?'/prod/' + idart + '_' + artcodice + '.html':'/product/' + idart + '_' + artcodice + '.html';
	}
}

function openPage( idpag ) {
	if( current_page_off != idpag )
	{
		window.location.href = page_name + current_params + '&page=' + idpag;
	}
}

function openPageNews( idpag ) {
	if( current_page_off != idpag )
	{
		window.location.href = page_name + '?page=' + idpag;
	}
}

function PostMarche() {
	var sel;
	var cur_marca;
	sel = document.getElementById('cur_marca');
	cur_marca = GetMarcaComboValue(sel);
	if (cur_marca == "") return;
	window.location.href = page_name + current_marche + '&marche=' + cur_marca; 
}

function PostCat() {
	var sel;
	var cur_cat;
	sel = document.getElementById('cur_cat');
	cur_cat = GetMarcaComboValue(sel);
	if (cur_cat == "") return;
	window.location.href = page_name + current_cat + '&categoria=' + cur_cat; 
}

function GetMarcaComboValue (cmb) {
	if (!cmb) return 0;
	var iSelIndex = cmb.selectedIndex;
	var sOpt = cmb.options[iSelIndex].value;
	return sOpt;
}

function SwitchCatTip(idtab) {
	var sel;
	sel = document.getElementById('table_prz').style.display;
	if( sel == "")
		{
			document.getElementById('table_prz').style.display = "none";
			document.getElementById('table_mar').style.display = "none";
			document.getElementById('img_prz').src = "/images/open_me.gif";
			document.getElementById('img_mar').src = "/images/open_me.gif";
		}
	else
		{
			document.getElementById('table_prz').style.display = "";
			document.getElementById('table_mar').style.display = "";
			document.getElementById('img_prz').src = "/images/close_me.gif";
			document.getElementById('img_mar').src = "/images/close_me.gif";
		}
}


function SwitchCat(idtab) {
	var sel;
	sel = document.getElementById('table_cat').style.display;
	if( sel == "")
		{
			document.getElementById('table_cat').style.display = "none";
			document.getElementById('table_prz').style.display = "none";
			document.getElementById('table_mar').style.display = "none";
			document.getElementById('img_cat').src = "/images/open_me.gif";
			document.getElementById('img_prz').src = "/images/open_me.gif";
			document.getElementById('img_mar').src = "/images/open_me.gif";
		}
	else
		{
			document.getElementById('table_cat').style.display = "";
			document.getElementById('table_prz').style.display = "";
			document.getElementById('table_mar').style.display = "";
			document.getElementById('img_cat').src = "/images/close_me.gif";
			document.getElementById('img_prz').src = "/images/close_me.gif";
			document.getElementById('img_mar').src = "/images/close_me.gif";
		}
}

function SwitchCatNov(idtab) {
	var sel;
	sel = document.getElementById('table_cat').style.display;
	if( sel == "")
		{
			document.getElementById('table_cat').style.display = "none";
			document.getElementById('table_prz').style.display = "none";
			document.getElementById('table_mar').style.display = "none";
			document.getElementById('img_cat').src = "/images/open_me.gif";
			document.getElementById('img_prz').src = "/images/open_me.gif";
			document.getElementById('img_mar').src = "/images/open_me.gif";
		}
	else
		{
			document.getElementById('table_cat').style.display = "";
			document.getElementById('table_prz').style.display = "";
			document.getElementById('table_mar').style.display = "";
			document.getElementById('img_cat').src = "/images/close_me.gif";
			document.getElementById('img_prz').src = "/images/close_me.gif";
			document.getElementById('img_mar').src = "/images/close_me.gif";
		}
}

function openNews(idnews) {
	if(idnews != "") window.location.href = 'news_detail.php?id=' + idnews;
}

function SwitchCatSearch(idtab) {

var sel;
sel = document.getElementById('table_cat').style.display;
if( sel == "")
	{
		document.getElementById('table_cat').style.display = "none";
		document.getElementById('table_prz').style.display = "none";
		document.getElementById('table_mar').style.display = "none";
		document.getElementById('img_cat').src = "/images/open_me.gif";
		document.getElementById('img_prz').src = "/images/open_me.gif";
		document.getElementById('img_mar').src = "/images/open_me.gif";
	}
else
	{
		document.getElementById('table_cat').style.display = "";
		document.getElementById('table_prz').style.display = "";
		document.getElementById('table_mar').style.display = "";
		document.getElementById('img_cat').src = "/images/close_me.gif";
		document.getElementById('img_prz').src = "/images/close_me.gif";
		document.getElementById('img_mar').src = "/images/close_me.gif";
	}
}

function SwitchCatTab(idtab) {

var sel;
sel = document.getElementById('table_cat').style.display;
if( sel == "")
	{
		document.getElementById('table_cat').style.display = "none";
		document.getElementById('table_prz').style.display = "none";
		document.getElementById('table_mar').style.display = "none";
		document.getElementById('img_cat').src = "/images/open_me.gif";
		document.getElementById('img_prz').src = "/images/open_me.gif";
		document.getElementById('img_mar').src = "/images/open_me.gif";
	}
else
	{
		document.getElementById('table_cat').style.display = "";
		document.getElementById('table_prz').style.display = "";
		document.getElementById('table_mar').style.display = "";
		document.getElementById('img_cat').src = "/images/close_me.gif";
		document.getElementById('img_prz').src = "/images/close_me.gif";
		document.getElementById('img_mar').src = "/images/close_me.gif";
	}
}


//********************************************************************************************************//
//*************    Eventi                                   **********************************************//
//********************************************************************************************************//

function EffectRolloverEv( idpag ) {
	if( current_page_off != idpag )
	{
		var cx = "cx" + idpag;
		this.document.getElementById(cx).style.background = 'url(/images/page_bg_over.gif)';
		this.document.getElementById(cx).style.backgroundRepeat = 'no-repeat';
		this.document.getElementById(cx).style.color = '#0000A5';
	}
}

function EffectRolloutEv( idpag ) {
	if( current_page_off != idpag )
	{
		var cx = "cx" + idpag;
		this.document.getElementById(cx).style.background = 'url(/images/page_bg.gif)';
		this.document.getElementById(cx).style.backgroundRepeat = 'no-repeat';
		this.document.getElementById(cx).style.color = '#FFFFFF';
	}
}

//********************************************************************************************************//
//*************    Articolo                               ************************************************//
//********************************************************************************************************//
function update_cart_ajax(idart, prev, disp, nol, idprod) {
	if(blocca_privato == 1) 
	{
		alert('Per aggiungere al carrello questo prodotto è necessario registrarsi');
		return false;
	}

	var sRef;
	var qta = 1;
	if( document.Data.nprod )
		qta = document.Data.nprod.value;
		sRef = "nol="+nol+"&prev="+prev+"&disp="+disp+"&idart="+idart+"&nprod="+qta;
		if(idprod != "") sRef = sRef + "&idsn=" + idprod;


	if( blocca_usato == 1)
	{
		if( prev == 0 )
		{
			if( (parseInt(qta,10) + parseInt(in_cart_ord,10) ) > parseInt(disp,10)  ) 
			{
				alert("Non puoi superare la disponibilità massima, per gli articoli demo, usati e fine serie");
				return false;
			}
			else in_cart_ord = parseInt(in_cart_ord,10) + parseInt(qta,10);
		}
		else
		{
			if( (parseInt(qta,10) + parseInt(in_cart_prev,10)) >  parseInt(disp,10)    ) 
			{
				alert("Non puoi superare la disponibilità massima, per gli articoli demo e usati");
				return false;
			}
			else in_cart_prev = parseInt(in_cart_prev,10) + parseInt(qta,10);
		}
	}

	if( nol == 1 )
	{
		var ngiorni = GetQtaValue(document.Data.qta);
		var data = document.Data.datainizio.value;
		if( data == "" )
			{
				alert(err_art);
				return false;
			}
		if (prev == 0)
			{
				alert('Per il noleggio non e\' piu\' possibile ordinare. Fare un richiesta di preventivo.');
				return false;
			}
		sRef = sRef + "&ngiorni=" + ngiorni + "&data=" + data;
	}

	pars = sRef;

	var disp_elem = "cart_info";
	disp_elem = disp_elem + nol;

	if( document.getElementById(disp_elem)) document.getElementById(disp_elem).style.display = '';

	addToBasket(prev);
	Element.show('preview_cart_loading');
	Element.hide('preview_cart_section');
	var myAjaxCart = new Ajax.Updater( 'preview_cart_section', url_art, { method: 'get', parameters: pars, onFailure: reportErrCart, onCreate: SetInitCart, onComplete: setCompleteCart, evalScripts:true}); 
}

function reportErrCart(request)
{
	 Element.hide('preview_cart_section');
	 Element.hide('preview_cart_loading');
	 Element.show('preview_cart_error');
}

function SetInitCart(request)
{
	Element.hide('preview_cart_section');
	Element.hide('preview_cart_error');
	Element.show('preview_cart_loading');
}

function setCompleteCart(request)
{
	Element.hide('preview_cart_error');
	Element.hide('preview_cart_loading');
	Element.show('preview_cart_section');
}

function open_window_cart(idart, prev, disp, nol, idprod)
{

	if(blocca_privato == 1) 
	{
		alert('Per aggiungere al carrello questo prodotto è necessario registrarsi');
		return false;
	}

	var sRef;
	var sNome;
	var sParam;
	var qta = 1;
	if( document.Data.nprod )
		qta = document.Data.nprod.value;
	sRef = "/popup/addcart.php?nol="+nol+"&prev="+prev+"&disp="+disp+"&idart="+idart+"&nprod="+qta;
	if (idprod != "") sRef = sRef + "&idsn=" + idprod;

	if( blocca_usato == 1)
	{
		if( prev == 0 )
		{
			if( (parseInt(qta,10) + parseInt(in_cart_ord,10) ) > parseInt(disp,10)  ) 
			{
				alert("Non puoi superare la disponibilità massima, per gli articoli demo e usati");
				return false;
			}
			else in_cart_ord = parseInt(in_cart_ord,10) + parseInt(qta,10);
		}
		else
		{
			if( (parseInt(qta,10) + parseInt(in_cart_prev,10)) >  parseInt(disp,10)    ) 
			{
				alert("Non puoi superare la disponibilità massima, per gli articoli demo e usati");
				return false;
			}
			else in_cart_prev = parseInt(in_cart_prev,10) + parseInt(qta,10);
		}
	}

	if( nol == 1 )
	{
		var ngiorni = GetQtaValue(document.Data.qta);
		var data = document.Data.datainizio.value;
		if( data == "" )
			{
				alert(err_art);
				return false;
			}
		sRef = sRef + "&ngiorni=" + ngiorni + "&data=" + data;
	}
	sParam = "'menubar=no, scrollbars=yes, resizable=yes, status=no, location=no, width=500, height=320'";
	var sName = "PopupCart";
	if (!window.opener)
		wref = window.open(sRef, sName, sParam);
	else
		wref = window.location.href = sRef;
	if (wref) wref.focus();
}


function open_window_cart_acc(idart, prev, disp, nol, block_prv)
{
	if(block_prv == 1) 
	{
		alert('Per aggiungere al carrello questo prodotto è necessario registrarsi');
		return false;
	}
	

	var sRef;
	var sNome;
	var sParam;
	var qta = 1;
	if( nol == 1 )
	{
		sRef = "/popup/addcartnol.php?nol="+nol+"&prev="+prev+"&disp="+disp+"&idart="+idart+"&nprod="+qta;
		sParam = "'menubar=no, scrollbars=yes, resizable=yes, status=no, location=no, width=500, height=420'";
		
	}
	else
	{
		sRef = "/popup/addcart.php?nol="+nol+"&prev="+prev+"&disp="+disp+"&idart="+idart+"&nprod="+qta;
		sParam = "'menubar=no, scrollbars=yes, resizable=yes, status=no, location=no, width=500, height=320'";
	}
	
	var sName = "PopupCart";
	var wref;
	if (!window.opener)
		wref = window.open(sRef, sName, sParam);
	else
		wref = window.location.href = sRef;
	if (wref) wref.focus();
}




function GetQtaValue (cmb) {
	if (!cmb) return 0;
	var iSelIndex = cmb.selectedIndex;
	var sOpt = cmb.options[iSelIndex].value;
	return sOpt;
}



function open_image_detail(str_image, cwidth, cheight)
{

	var sRef;
	var sNome;
	var sParam;
	

	sRef = "/popup/detail_img.php?img="+str_image;
	sParam = "'menubar=no, scrollbars=yes, resizable=yes, status=no, location=no, width=" +cwidth+", height="+cheight+"'";
	
	var sName = "ImageDetail";
	//var wref = window.location.href = sRef;
	var wref = window.open(sRef, sName, sParam);
	if (wref) wref.focus();
	return false;
}

//********************************************************************************************************//
//*************    Accessori Articolo                     ************************************************//
//********************************************************************************************************//
function SwitchAccLineTab() {
	var c;
	var t;

	var m = parseInt(current_line_tab,10);
	t = 0;
	c = 6;
	l = p.length;

	while (t<l) 
	{
		r = new String(p[t]);
		var sx = "sp1" + r;
		var dx = "sp2" + r;
		var cx = "cx" + r;
		var sp = "sp3" + r;
		if( m == 0)
		{
			if(t < c) { 
				//SCOPRO
				//alert( r + " scopro1");
				this.document.getElementById(sx).style.display ='';
				this.document.getElementById(dx).style.display ='';
				this.document.getElementById(cx).style.display ='';
				this.document.getElementById(sp).style.display ='';
			}
			else { 
				//COPRO
				//alert( r + " copro1");
				this.document.getElementById(sx).style.display ='none';
				this.document.getElementById(dx).style.display ='none';
				this.document.getElementById(cx).style.display ='none';
				this.document.getElementById(sp).style.display ='none';
			}
		}
		else
		{
			if(t >= c) {
				//SCOPRO
				//alert( r + " scopro2");
				this.document.getElementById(sx).style.display ='';
				this.document.getElementById(dx).style.display ='';
				this.document.getElementById(cx).style.display ='';
				this.document.getElementById(sp).style.display ='';
			}
			else { 
				//COPRO
				//alert( r + " copro2");
				this.document.getElementById(sx).style.display ='none';
				this.document.getElementById(dx).style.display ='none';
				this.document.getElementById(cx).style.display ='none';
				this.document.getElementById(sp).style.display ='none';
			}
		}
	t++;
	}
	if( m == 1) 
	{
		this.document.getElementById('switchtext').innerHTML = 'INDIETRO &lt;&lt;&lt;';
		current_line_tab = "0";
	}
	else 
	{
		this.document.getElementById('switchtext').innerHTML = 'ALTRI &gt;&gt;&gt;';
		current_line_tab = "1";
	}
}

function AbilitaImageAcc() {
	var ab_value;
	ab_value = document.getElementById('preview1').checked;
	if( ab_value == true ) 
	{
		preview_acc_img = 1;
		return FetchNewCat(current_tab,1);
	}
	else 
	{
		preview_acc_img = 0;
		return FetchNewCat(current_tab,1);
	}
}

function FetchNewCat(idtab, fromcheck) {
	var old_current_tab = current_tab;
	current_tab = idtab;

	if( (current_tab == old_current_tab) && fromcheck == 0 ) return;
	EffectRollout(old_current_tab);
	var pars = 'idtab=' + idtab + '&idarticolo=' + idarticolo;
	if( fromcheck == 1 )
		pars = pars + '&accimg=' + preview_acc_img;

	document.getElementById("acc_working").innerHTML = '<img src="/images/cart_load.gif" align="middle" border="0">Caricamento accessori ...';
	Element.show('acc_working');
	Element.hide('acc_section');
	var myAjax = new Ajax.Updater( 'acc_section', url_acc, { method: 'get', parameters: pars, onFailure: reportErrAcc, onCreate: SetInitAcc, onComplete: setCompleteAcc}); 
}

function reportErrAcc(request)
{
	 Element.hide('acc_section');
	 Element.hide('acc_working');
	 document.getElementById("acc_error").innerHTML = 'Errore, non è stato possibile caricare gli accessori';
	 Element.show('acc_error');
}

function SetInitAcc(request)
{
	Element.hide('acc_section');
	Element.hide('acc_error');
	document.getElementById("acc_working").innerHTML = '<img src="/images/cart_load.gif" align="middle" border="0">Caricamento accessori ...';
	Element.show('acc_working');
}

function setCompleteAcc(request)
{
	Element.hide('acc_error');
	Element.hide('acc_working');
	Element.show('acc_section');
}

function EffectRollover( idcat ) {
	if( current_tab != idcat && idcat != "" )
	{
		var sx = "sx" + idcat;
		var dx = "dx" + idcat;
		var cx = "cx" + idcat;
		var mytext = "text" + idcat;
		this.document.getElementById(sx).src = '/images/angolo-sx-azz.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-azz.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-azz.gif)';
		this.document.getElementById(mytext).style.color = "#0000A5";
	}
}

function EffectRollout( idcat ) {
	if( current_tab != idcat && idcat != "" )
	{
		var sx = "sx" + idcat;
		var dx = "dx" + idcat;
		var cx = "cx" + idcat;
		var mytext = "text" + idcat;
		this.document.getElementById(sx).src = '/images/angolo-sx-blu.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-blu.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-blu.gif)';
		this.document.getElementById(mytext).style.color = "#FFFFFF";
	}
}

//********************************************************************************************************//
//*************    Articolo Dettaglio                     ************************************************//
//********************************************************************************************************//

function FetchNewDetail(idtab, back) {
	var old_current_tab_detail = current_tab_detail;
	current_tab_detail = idtab;

	if ((current_tab_detail == old_current_tab_detail) && back == 0) return;
	EffectRolloutSpec(old_current_tab_detail);
	var url = url_detail;
	if(idtab == 'desc') url = url + 'ajax_artdesc.php';
	if(idtab == 'cattec') url = url + 'ajax_arttec.php';
	if(idtab == 'filevideo') url = url + 'ajax_artfile.php';
	if(idtab == 'kit') url = url + 'ajax_artkit.php';
	if(idtab == 'spec') url = url + 'ajax_artspec.php';
	if(idtab == 'conf') url = url + 'ajax_artconf.php';

	var pars = 'idarticolo='+idarticolo;
	if( idtab == 'kit' || idtab == 'spec' || idtab == 'conf') pars = pars + '&idarticolobase=' + idarticolobase + '&popup=' + popup;

	document.getElementById("detail_working").innerHTML = 'Caricamento in corso ...';
	Element.show('detail_working');
	Element.hide('detail_section');
	var myAjaxDetail = new Ajax.Updater( 'detail_section', url, { method: 'get', parameters: pars, onFailure: reportErrDetail, onCreate: SetInitDetail, onComplete: setCompleteDetail, evalScripts:true}); 
}

function reportErrDetail(request)
{
	Element.hide('detail_section');
	Element.hide('detail_working');
	document.getElementById("detail_error").innerHTML = 'Errore, non è stato possibile caricare la pagina di dettaglio dell\'articolo.';
	Element.show('detail_error');
}

function SetInitDetail(request)
{
	Element.hide('detail_section');
	Element.hide('detail_error');
	document.getElementById("detail_working").innerHTML = 'Caricamento in corso ...';
	Element.show('detail_working');
}

function setCompleteDetail(request)
{
	Element.hide('detail_error');
	Element.hide('detail_working');
	Element.show('detail_section');
}



function EffectRolloverSpec( idcat ) {
	if( current_tab_detail != idcat && idcat != "")
	{
		var sx = idcat + "sx";
		var dx = idcat + "dx";
		var cx = idcat + "cx";
		var mytext = idcat + "_text";
		this.document.getElementById(sx).src = '/images/angolo-sx-azz.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-azz.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-azz.gif)';
		this.document.getElementById(mytext).style.color = "#0000A5";
	}
}

function EffectRolloutSpec( idcat ) {
	if( current_tab_detail != idcat && idcat != "")
	{
			var sx = idcat + "sx";
			var dx = idcat + "dx";
			var cx = idcat + "cx";
			var mytext = idcat + "_text";
			this.document.getElementById(sx).src = '/images/angolo-sx-blu.gif';
			this.document.getElementById(dx).src = '/images/angolo-dx-blu.gif';
			this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-blu.gif)';
			this.document.getElementById(mytext).style.color = "#FFFFFF";
	}
}

//********************************************************************************************************//
//*************    Articolo Usato                         ************************************************//
//********************************************************************************************************//
function FetchNewDetailUsato(idtab, back) {
	var old_current_tab_detail_usato = current_tab_detail_usato;
	current_tab_detail_usato = idtab;

	if ((current_tab_detail_usato == old_current_tab_detail_usato) && back == 0) return;
	EffectRolloutUsato(old_current_tab_detail_usato);
	var url = url_detail;
	if(idtab == 'descusato') url = url + 'ajax_artusato.php';
	if(idtab == 'listusato') url = url + 'ajax_artlistseriale.php';

	var pars = 'idarticolo=' + idarticolo + '&idprodotto=' + idprodotto;
	if( idtab == 'listusato' ) pars = pars + '&idarticolobase=' + idarticolobase + '&popup=' + popup;

	document.getElementById("detail_working_usato").innerHTML = 'Caricamento in corso ...';
	Element.show('detail_working_usato');
	Element.hide('detail_section_usato');
	var myAjaxDetailUsato = new Ajax.Updater( 'detail_section_usato', url, { method: 'get', parameters: pars, onFailure: reportErrDetailUsato, onCreate: SetInitDetailUsato, onComplete: setCompleteDetailUsato, evalScripts:true}); 
}

function reportErrDetailUsato(request)
{
	Element.hide('detail_section_usato');
	Element.hide('detail_working_usato');
	Element.show('detail_error_usato');
	document.getElementById("detail_error_usato").innerHTML = 'Errore, non è stato possibile caricare la pagina di dettaglio dell\'usato.';
}

function SetInitDetailUsato(request)
{
	Element.hide('detail_section_usato');
	Element.hide('detail_error_usato');
	Element.show('detail_working_usato');
	document.getElementById("detail_working_usato").innerHTML = 'Caricamento in corso ...';
}

function setCompleteDetailUsato(request)
{
	Element.hide('detail_error_usato');
	Element.hide('detail_working_usato');
	Element.show('detail_section_usato');
}



function EffectRolloverUsato( idcat ) {
	if( current_tab_detail_usato != idcat )
	{
		var sx = idcat + "sx";
		var dx = idcat + "dx";
		var cx = idcat + "cx";
		var mytext = idcat + "_text";
		this.document.getElementById(sx).src = '/images/angolo-sx-azz.gif';
		this.document.getElementById(dx).src = '/images/angolo-dx-azz.gif';
		this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-azz.gif)';
		this.document.getElementById(mytext).style.color = "#0000A5";
	}
}

function EffectRolloutUsato( idcat ) {
	if( current_tab_detail_usato != idcat )
	{
			var sx = idcat + "sx";
			var dx = idcat + "dx";
			var cx = idcat + "cx";
			var mytext = idcat + "_text";
			this.document.getElementById(sx).src = '/images/angolo-sx-blu.gif';
			this.document.getElementById(dx).src = '/images/angolo-dx-blu.gif';
			this.document.getElementById(cx).style.background = 'url(/images/fondo-cx-blu.gif)';
			this.document.getElementById(mytext).style.color = "#FFFFFF";
	}
}

//********************************************************************************************************//
//*************    Articolo Confronta                     ************************************************//
//********************************************************************************************************//


//********************************************************************************************************//
//*************    Ricerca Articolo                       ************************************************//
//********************************************************************************************************//
function reportErrFiltriSearch(request)
{
	Element.hide('filtri_search_info');
	Element.hide('filtri_search_loading');
	document.getElementById('filtri_search_error').innerHTML = 'Errore interno del server non è stato possibile caricare i filtri di ricerca !!!';
	Element.show('filtri_search_error');
}

function SetInitFiltriSearch(request)
{
	Element.hide('filtri_search_info');
	Element.hide('filtri_search_error');
	document.getElementById('filtri_search_loading').innerHTML = '<img src="/images/cart_load.gif" align="middle" border="0">Caricamento filtri di ricerca ...';
	Element.show('filtri_search_loading');
}

function setCompleteFiltriSearch(request)
{
	Element.hide('filtri_search_error');
	Element.hide('filtri_search_loading');
	Element.show('filtri_search_info');
}

//********************************************************************************************************//
//*************    Opzioni Articolo                       ************************************************//
//********************************************************************************************************//
var optid = Array();
optid[0] = "optprod";
optid[1] = "optacc";
function colore1(k){
if(document.getElementById(k)){
		document.getElementById(k).style.visibility = "visible";
	}
	 window.setTimeout("colore2('" + k +"')",500);
}
function colore2(k){
if(document.getElementById(k)){
	 document.getElementById(k).style.visibility = "hidden";
	}
	 window.setTimeout("colore1('"+ k +"')",500);
}

function blinkopt()
{
	for(i=0; i<optid.length; i++)
	window.setTimeout("colore1('" + optid[i] +"')",500);
}

//********************************************************************************************************//
//*************    Box Articolo                           ************************************************//
//********************************************************************************************************//
function AddProd()
{
	var frm = document.Data;
	frm.nprod.value = parseInt(frm.nprod.value,10) + 1;
	recalcprice();
	return true;
}

function MinProd()
{
	var frm = document.Data;
	if( frm.nprod.value > 1)
	frm.nprod.value = parseInt(frm.nprod.value,10) - 1;
	recalcprice();
	return true;
}

function recalcprice() {
var p = new Array();

var totprice = price;
var totprice_netto = price_netto; 
totprice = totprice * document.Data.nprod.value;
totprice = Math.round(totprice * 100);
totprice = totprice / 100;
var output = new String(totprice);
//Padding
var padder = output;
var arr_pad = padder.split(".");
if( arr_pad.length > 1)
{
	if(arr_pad[1].length == 1)
		padder = padder + "0";
}
else
	padder = padder + ".00";
//End

document.getElementById('prziva').innerHTML = "&euro; " + padder.replace(".",",") + " " + str_price_ivato + " " + str_trasp;
if( offerta2 != 0 )
{
	var totofferta = offerta2 * document.Data.nprod.value;
	totofferta = Math.round(totofferta * 100);
	totofferta = totofferta / 100;
	var output = new String(totofferta);
	//Padding
	var padder = output;
	var arr_pad = padder.split(".");
	if( arr_pad.length > 1)
	{
		if(arr_pad[1].length == 1)
			padder = padder + "0";
	}
	else
		padder = padder + ".00";
	//End
	document.getElementById('offertaiva').innerHTML = "&euro; " + padder.replace(".",",");
}

totprice_netto = totprice_netto * document.Data.nprod.value;
totprice_netto = Math.round(totprice_netto * 100);
totprice_netto = totprice_netto / 100;
var outputnetto = new String(totprice_netto);
//Padding
var padder = outputnetto;
var arr_pad = padder.split(".");
if( arr_pad.length > 1)
{
	if(arr_pad[1].length == 1)
		padder = padder + "0";
}
else
	padder = padder + ".00";
//End
document.getElementById('prznetto').innerHTML = "&euro; " + padder.replace(".",",") + " " + str_price_netto + " " + str_trasp;

if( offerta1 != 0 )
{
	var totofferta2 = offerta1 * document.Data.nprod.value;
	totofferta2 = Math.round(totofferta2 * 100);
	totofferta2 = totofferta2 / 100;
	var outputnetto = new String(totofferta2);
	//Padding
	var padder = outputnetto;
	var arr_pad = padder.split(".");
	if( arr_pad.length > 1)
	{
		if(arr_pad[1].length == 1)
			padder = padder + "0";
	}
	else
		padder = padder + ".00";
	//End
	document.getElementById('offerta').innerHTML = "&euro; " + padder.replace(".",",");
}

return true;
}


function CalcRate() {
var totprice = price;
totprice = totprice * document.Data.nprod.value;
totprice = Math.round(totprice * 100);
totprice = totprice / 100;
if( totprice < consel_min) { alert('Importo minimo finanziabile, 150 euro'); return false; }
if( totprice > consel_max) totprice = consel_max;

var output = new String(totprice);
//Padding
var padder = output;
var arr_pad = padder.split(".");
if( arr_pad.length > 1)
{
	if(arr_pad[1].length == 1)
		padder = padder + "0";
}
else
	padder = padder + ".00";
var wref = window.open("/popup/calcrate.php?imp="+padder, "CalcRate", "width=600, height=450, scrollbars=0, resizable=1, status=0, location=0, toolbar=0, menubar=0");
if (wref) wref.focus();

return;
}

