
var busy_type='c'; /* 'c|o|p|r|t' */
var busy_size=110;
var busy_color='#FFFFFF'; //'#801e39';

function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) 
{
	return stringToTrim.replace(/\s+$/,"");
}

function switchLang( language ) 
{
	if (dictionary[language] == null) return;

	new Ajax.Request('ajax/lang.php', {
					 method: 'post',
					 parameters: {lang: language}
	});
}


var reqno = 0;
var busy = null;
var timeoutID = null;

var captcha_result = false;
var captcha_string = '';

function checkCaptchaDigit( obj ) 
{
	var code = obj.value;
	if (captcha_string == code) return;
	
	captcha_result = false;
	captcha_string = code;

	new Ajax.Request('ajax/captcha.php', {
					 method: 'post',
					 parameters: {captcha: code},
					 onComplete: function(transport) {
	 									captcha_result = (trim(transport.responseText) == 'OK');
										obj.style.borderWidth = '3px';
	 									obj.style.borderColor = captcha_result ? 'green;' : 'red';
					 				 }
	});
}

function checkCaptcha( code ) 
{
	return captcha_result;
}

function mytoggle( block )
{
	var status = jq('#' + block).attr("status");
	
	if (status == 'closed')
	{
		jq('#' + block).attr("status", 'opened');
		jq('#' + block).show();
		if (jq('#' + block + '_IMG'))
			jq('#' + block + '_IMG').attr('src', 'images/opened.jpg');
	}
	else 
	{
		jq('#' + block).attr("status", 'closed');
		jq('#' + block).hide();
		if (jq('#' + block + '_IMG'))
			jq('#' + block + '_IMG').attr('src', 'images/closed.jpg');
	}
	return false;
}
function grp_open( tog )
{
		jq('#_G' + tog).attr("status", 'opened');
		jq('#T_G' + tog).fadeTo(0, 1);
		jq('#_G' + tog).show();
		jq('#_G' + tog + '_block').show();
}
function grp_close( tog )
{
		jq('#_G' + tog).attr("status", 'closed');
		jq('#_G' + tog).hide();
		jq('#_G' + tog + '_block').hide();
}
function close_grp_toggle( tog, grp, prd )
{
	var status = jq('#_G' + tog).attr("status");
	var grp_toggle_list = jq('#grp').attr('value').split('#');

	for (var k = 0; k < grp_toggle_list.size(); ++k)
	{
		if (grp_toggle_list[k].length <= 0) continue;
		jq('#_G' + grp_toggle_list[k]).attr("status", 'closed');
		jq('#_G' + grp_toggle_list[k]).hide();
		jq('#_G' + grp_toggle_list[k] + '_block').hide();
		jq('#T_G' + grp_toggle_list[k]).fadeTo(0, (status == 'closed') ? 0.5 : 1);
	}
	if (status == 'closed')
	{
		i = '_G' + tog + '_block';
			
		if ($(i).rows.length == 0)
		{
			timeoutID = window.setTimeout("getBlocco('" + i + "', '" +  grp + "', '" +  prd + "')", 1000);
		}
		else
		{
			while ($( 'dimensioni_pdf' ).rows.length > 0) $( 'dimensioni_pdf' ).deleteRow(0);
			var row = $( 'dimensioni_pdf' ).insertRow(-1);
			var cell = row.insertCell(0);
			cell.innerHTML = jq('input#DIM_PDF_' + tog).attr('value');
		}
		jq('#_G' + tog).attr("status", 'opened');
		jq('#T_G' + tog).fadeTo(0, 1);
		jq('#_G' + tog).show();
		jq('#_G' + tog + '_block').show();
	}
	else 
	{
		jq('#_G' + tog).attr("status", 'closed');
		jq('#_G' + tog).hide();
		jq('#_G' + tog + '_block').hide();
	}
	return false;
}
function getBlocco( id, grp, prd )
{
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	jq.post( "do_dimensione_blocco.php", 
		{i: id, gruppo: grp, prodotto: prd},
		function(data) {
				var row = $(i).insertRow(-1);
				var cell = row.insertCell(0);					 	
				cell.innerHTML = data;

				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
	   }
	);
	var id3 = 'dimensioni_pdf';
	
	var id2 = 'DIM_PDF_' + id;
	
	jq.get( "dimensioni_pdf_g.php", 
		{ gruppo: grp, id: id2 }, 
		function(data) {
			jq('input#' + id2).attr('value', data);

			var id3 = 'dimensioni_pdf';
			
			while ($( id3 ).rows.length > 0) $( id3 ).deleteRow(0);

			var row = $( id3 ).insertRow(-1);
			var cell = row.insertCell(0);

			cell.innerHTML = data;
		}
	);
}

function acc_expand_all( root, block )
{
	var rstyle = jq('#' + root).attr("status");
	var bstyle = jq('#' + block).attr("style");
	
	if (rstyle == 'closed')
	{
		jq('#' + block).show();
		jq('#' + block).attr("status", "opened");
	}
	else
	{
		jq('#' + block).hide();
		jq('#' + block).attr("status", "closed");
	}
	return false;
}

function getResult2( listino, page, tab ) 
{
	if (listino.length <= 0) 
	{
		emptyResult();
		return;
	}

	if (null != timeoutID)
		window.clearTimeout( timeoutID );

	timeoutID = window.setTimeout("doGetResult2('" + listino + "', '" +  page + "', '" +  tab + "')", 1000);
	
	hilite(null);
}
function doGetResult2( listino, pg, tab ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	if (jq('#tab').attr('value') == 'L')
		url = 'do_listino.php';
	else if (jq('#tab').attr('value') == 'D')
		url = 'do_dimensioni.php';
//	else if (jq('#tab').attr('value') == 'P')
//		url = 'do_prestazioni.php';
	else if (jq('#tab').attr('value') == 'F')
		url = 'do_download.php';
	
	jq.post( url, 
		{listino: listino, req: reqno, page: pg, tab: tab},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;
			 	
			 	while ($('result').rows.length > 0)
			 		$('result').deleteRow(0);
			 	
			 	var row = $('result').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[2];
				
				if (1 == a[1])
				{
					jq(function() { jq("#tabs").tabs(); });
					if (tab == 'L')
						jq("#tabs").tabs( 'select' , 0 );
					else if (tab == 'D')
						jq("#tabs").tabs( 'select' , 1 );
					else if (tab == 'F')
						jq("#tabs").tabs( 'select' , 2 );
//					else if (tab == 'P')
//						jq("#tabs").tabs( 'select' , 3 );
				}
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
			       }
	);
}
function getResultFast( codice )
{
	if ($F("codice_backup") == $F("codice")) return;
	$("codice_backup").value = $F("codice");
	if($("codice").value.length<3)
	{
		emptyResult(); 
		return;
	} 
	getResult($F("codice"), $F("descrizione"), 1, $F("tab"));
}
function getResult( codice, descrizione, page, tab ) 
{
	if (codice.length < 3)      codice='';
	if (descrizione.length < 3) descrizione='';

	if ( (codice.length <= 0) 
	  && (descrizione.length <= 0) )
	{
		emptyResult();
		return;
	}
	if (null != timeoutID)
		window.clearTimeout( timeoutID );

	timeoutID = window.setTimeout("doGetResult('" + codice + "', '" + descrizione + "', '" +  page + "', '" +  tab + "')", 1000);
	
	hilite(null);
}
function doGetResult( codice, descrizione, pg, tab ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	if (jq('#tab').attr('value') == 'L')
		url = 'do_listino.php';
	else if (jq('#tab').attr('value') == 'D')
		url = 'do_dimensioni.php';
//	else if (jq('#tab').attr('value') == 'P')
//		url = 'do_prestazioni.php';
	else if (jq('#tab').attr('value') == 'F')
		url = 'do_download.php';
	
	jq.post( url, 
		{codice: codice, descrizione: descrizione, req: reqno, page: pg, tab: tab},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;
			 	
			 	while ($('result').rows.length > 0)
			 		$('result').deleteRow(0);
			 	
			 	var row = $('result').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[2];
				
				if (1 == a[1])
				{
					jq(function() { jq("#tabs").tabs(); });
					if (tab == 'L')
						jq("#tabs").tabs( 'select' , 0 );
					else if (tab == 'D')
						jq("#tabs").tabs( 'select' , 1 );
					else if (tab == 'F')
						jq("#tabs").tabs( 'select' , 2 );
//					else if (tab == 'P')
//						jq("#tabs").tabs( 'select' , 3 );
				}
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
			       }
	);
}
function doGetTab( codice, descrizione, tab ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	if (jq('#tab').attr('value') == 'L')
		url = 'do_listino.php';
	else if (jq('#tab').attr('value') == 'D')
		url = 'do_dimensioni.php';
	else if (jq('#tab').attr('value') == 'P')
		url = 'do_prestazioni.php';
	else if (jq('#tab').attr('value') == 'F')
		url = 'do_download.php';
	
	jq.post( url, 
		{codice: codice, descrizione: descrizione, req: reqno, tab: tab, page: 1, channel: tab},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;

			 	var row = $(tab + 'tab').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[2];
				
				if (1 == a[1])
				{
					jq(function() { jq("#tabs").tabs(); });
					if (tab == 'L')
						jq("#tabs").tabs( 'select' , 0 );
					else if (tab == 'D')
						jq("#tabs").tabs( 'select' , 1 );
					else if (tab == 'F')
						jq("#tabs").tabs( 'select' , 2 );
					else if (tab == 'P')
						jq("#tabs").tabs( 'select' , 3 );
				}
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
			       }
	);
}
function doGetTab2( listino, tab ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	if (jq('#tab').attr('value') == 'L')
		url = 'do_listino.php';
	else if (jq('#tab').attr('value') == 'D')
		url = 'do_dimensioni.php';
	else if (jq('#tab').attr('value') == 'P')
		url = 'do_prestazioni.php';
	else if (jq('#tab').attr('value') == 'F')
		url = 'do_download.php';
	
	jq.post( url, 
		{listino: listino, req: reqno, tab: tab, page: 1, channel: tab},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;

			 	var row = $(tab + 'tab').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[2];
				
				if (1 == a[1])
				{
					jq(function() { jq("#tabs").tabs(); });
					if (tab == 'L')
						jq("#tabs").tabs( 'select' , 0 );
					else if (tab == 'D')
						jq("#tabs").tabs( 'select' , 1 );
					else if (tab == 'F')
						jq("#tabs").tabs( 'select' , 2 );
					else if (tab == 'P')
						jq("#tabs").tabs( 'select' , 3 );
				}
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
	       }
	);
}
function doGetTab3( esatto, tab ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	if (jq('#tab').attr('value') == 'L')
		url = 'do_listino.php';
	else if (jq('#tab').attr('value') == 'D')
		url = 'do_dimensioni.php';
	else if (jq('#tab').attr('value') == 'P')
		url = 'do_prestazioni.php';
	else if (jq('#tab').attr('value') == 'F')
		url = 'do_download.php';
	
	jq.post( url, 
		{esatto: esatto, req: reqno, tab: tab, page: 1, channel: tab},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;

			 	var row = $(tab + 'tab').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[2];
				
				if (1 == a[1])
				{
					jq(function() { jq("#tabs").tabs(); });
					if (tab == 'L')
						jq("#tabs").tabs( 'select' , 0 );
					else if (tab == 'D')
						jq("#tabs").tabs( 'select' , 1 );
					else if (tab == 'F')
						jq("#tabs").tabs( 'select' , 2 );
					else if (tab == 'P')
						jq("#tabs").tabs( 'select' , 3 );
				}
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
	       }
	);
}

function emptyResult()
{
	while ($('result').rows.length > 0)
 		$('result').deleteRow(0);

 	resetMenu();
 }
function resetMenu()
{
/*	
	jq.get( "do_menu.php", 
		{ codice: '', descrizione: '', page: 0 }, 
		function(data) {
				while ($('menu_table_container').rows.length > 0)
			 		$('menu_table_container').deleteRow(0);

			 	var row = $('menu_table_container').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = data;
				}
	);
*/
}
function resetForm()
{
	jq('#codice').attr('value', '');
	jq('#descrizione').attr('value', '');
	jq('#codice_backup').attr('value', '');
	jq('#descrizione_backup').attr('value', '');
}
function viewTree()
{
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	resetMenu();

	jq.get( "tree.php", 
		{ },
		function(data) {while ($('result').rows.length > 0)
			 		$('result').deleteRow(0);
			 	
			 	var row = $('result').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = data;
				
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
			       }
	);
}

function display_hover_prompt( id ) 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $(id); 
	if (objref == null) return;
	var scroll_top = (ie) ? iebody.scrollTop : window.pageYOffset; 
	var docwidth = (ie) ? iebody.clientWidth : window.innerWidth; 
	var docheight = (ie) ? iebody.clientHeight: window.innerHeight; 
	var objwidth = objref.offsetWidth; 
	var objheight = objref.offsetHeight; objref.style.left = docwidth/2-objwidth/2+'px'; objref.style.top = scroll_top+docheight/1.8-objheight/2+'px'; 
	var showonscrollvar = setInterval(id + '_static_hover_prompt()', 50); objref.style.visibility = 'visible'; 
} 
function static_hover_prompt( id ) 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $(id); 
	if (objref == null) return;
	var scroll_top = (ie) ? iebody.scrollTop : window.pageYOffset; 
	var docwidth = (ie) ? iebody.clientWidth : window.innerWidth; 
	var docheight = (ie) ? iebody.clientHeight: window.innerHeight; 
	var objwidth = objref.offsetWidth; 
	var objheight = objref.offsetHeight; objref.style.top = scroll_top+docheight/1.8-objheight/2+'px'; 
} 
function hide_hover_prompt( id ) 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $(id); 
	objref.style.visibility = 'hidden'; 
	if (objref == null) return;
	if (typeof showonscrollvar != 'undefined') 
	{ 
		clearInterval(showonscrollvar); 
	} 
} 
function waiting_display_hover_prompt() 
{ 
	display_hover_prompt('waiting');
} 
function waiting_static_hover_prompt() 
{ 
	static_hover_prompt('waiting');
} 
function waiting_hide_hover_prompt() 
{ 
	hide_hover_prompt('waiting');
}

function sconti_display_hover_prompt() 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $('sconti'); 
	if (objref == null) return;
	var scroll_top = (ie) ? iebody.scrollTop : window.pageYOffset; 
	var docwidth = (ie) ? iebody.clientWidth : window.innerWidth; 
	var docheight = (ie) ? iebody.clientHeight: window.innerHeight; 
	var objwidth = objref.offsetWidth; 
	var objheight = objref.offsetHeight; objref.style.left = docwidth/2-objwidth/2-305+'px'; objref.style.top = scroll_top+docheight/1.8-objheight/2+'px'; 
	var showonscrollvar = setInterval('sconti_static_hover_prompt()', 50); objref.style.visibility = 'visible'; 
} 
function sconti_static_hover_prompt() 
{ 
	static_hover_prompt('sconti'); 
} 
function sconti_hide_hover_prompt() 
{ 
	hide_hover_prompt('sconti');
}


function loginerr_display_hover_prompt() 
{ 
	display_hover_prompt('login_err');
} 
function loginerr_static_hover_prompt() 
{ 
	static_hover_prompt('login_err'); 
} 
function loginerr_hide_hover_prompt() 
{ 
	hide_hover_prompt('login_err');
}
function login_display_hover_prompt() 
{ 
	display_hover_prompt('login_err');
} 
function login_static_hover_prompt() 
{ 
	static_hover_prompt('login_div'); 
} 
function login_hide_hover_prompt() 
{ 
	hide_hover_prompt('login_div');
}

function disable_display_hover_prompt() 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $('disable'); 
	if (objref == null) return;
	var scroll_top = (ie) ? iebody.scrollTop : window.pageYOffset; 
	var docwidth = (ie) ? iebody.clientWidth : window.innerWidth; 
	var docheight = (ie) ? iebody.clientHeight: window.innerHeight; 
	var objwidth = objref.offsetWidth; 
	var objheight = objref.offsetHeight; objref.style.left = '0px'; objref.style.top = scroll_top+'px'; 
	var showonscrollvar = setInterval('disable_static_hover_prompt()', 50); objref.style.visibility = 'visible'; 
} 
function disable_static_hover_prompt() 
{ 
	var ie = document.all && !window.opera; 
	var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; 
	var objref = $('disable'); 
	if (objref == null) return;
	var scroll_top = (ie) ? iebody.scrollTop : window.pageYOffset; 
	var docwidth = (ie) ? iebody.clientWidth : window.innerWidth; 
	var docheight = (ie) ? iebody.clientHeight: window.innerHeight; 
	var objwidth = objref.offsetWidth; 
	var objheight = objref.offsetHeight; objref.style.top = scroll_top+'px'; 
} 
function disable_hide_hover_prompt() 
{ 
	hide_hover_prompt('disable');
}

function display_event()
{
	waiting_display_hover_prompt();
	sconti_display_hover_prompt();
	disable_display_hover_prompt();
}

if (window.addEventListener) 
{ 
	window.addEventListener('load', display_event, false) 
} 
else if (window.attachEvent) 
{ 
	window.attachEvent('onload', display_event) 
} 
else if (document.getElementById) 
{ 
	window.onload = display_event; 
}

function doPrd( id )
{
	if ( !$(id) ) return;

	var status = jq('#' + id).attr("status");
	jq('#' + id).attr("status", (status == 'closed') 
				  ? 'opened' : 'closed');
	if ( $('raquo' + id) )
		jq('#raquo' + id).attr('src', (status == 'closed') 
				    	    ? opened_icon : closed_icon);
	if (status == 'closed')
		jq('#' + id).show();
	else
		jq('#' + id).hide();

	return status;
}

function doOpenClosePrd( id )
{
	var status =  doPrd( id, status );
}
function doOpenCloseAllPrd( id )
{
	var items = $F('map' + id).split('!');
	if (items.length == 0) return false;

	var icons = $F('icon' + id).split('!');
	if (icons.length == 0) return false;

	// PRODOTTO
	var status =  doPrd( id, status );

	// ACCESSORIO
	for (var k = 0;k < items.length; ++k) // Hide/Show
	{
		if (!items[k]) continue;
		if (!jq('#' + items[k])) continue;

		if (status == 'closed')
			jq('#' + items[k]).show();
		else
			jq('#' + items[k]).hide();
	}
	for (var k = 0;k < icons.length; ++k) // Icons
	{
		if ($(icons[k]))
			jq('#' + icons[k]).attr("status", (status == 'closed') 
							? 'opened' : 'closed');
		if ($('raquo' + icons[k]))
			jq('#raquo' + icons[k]).attr('src', (status == 'closed') 
						 	  ? opened_icon : closed_icon);
	}
	if ($('raquo_af_' + id))
		jq('#raquo_af_' + id).attr('src', (status == 'closed') 
					 	? opened_icon : closed_icon);
	return false;
}
function doOpenCloseAllAcc( id )
{
	if ( !$(id) ) return;

	var status = jq('#' + id).attr("status");
	jq('#' + id).attr("status", (status == 'closed') 
				  ? 'opened' : 'closed');
	if ($('raquo' + id))
		jq('#raquo' + id).attr('src', (status == 'closed') 
				    	    ? opened_icon : closed_icon);
	var items = $F('map' + id).split('!');
	if (items.length == 0) return false;

	var icons = $F('icon' + id).split('!');
	if (icons.length == 0) return false;
	// ACCESSORI
	for (var k = 0;k < items.length; ++k) // Hide/Show
	{
		if (!items[k]) continue;
		if (!jq('#' + items[k])) continue;

		if (status == 'closed')
			jq('#' + items[k]).show();
		else
			jq('#' + items[k]).hide();
	}
	for (var k = 0;k < icons.length; ++k) // Icons
	{
		if ($(icons[k]))
			jq('#' + icons[k]).attr("status", (status == 'closed') 
							? 'opened' : 'closed');
		if ($('raquo' + icons[k]))
			jq('#raquo' + icons[k]).attr('src', (status == 'closed') 
							  ? opened_icon : closed_icon);
	}
	return false;
}
function changeTab( tab )
{
	$("tab").value = tab;
	if (tab == 'L')
	{
		jq("#Lview").show(); jq("#Tview").hide(); jq("#paging").show();
	}
	else if (tab == 'T')
	{
		jq("#Tview").show(); jq("#Lview").hide(); jq("#paging").hide();
	}
}

function resize(){ return;
	var htmlheight = document.body.parentNode.clientheight; 
	var windowheight = window.screen.height; 
	var frame = document.getElementById("frame1"); 
	if ( htmlheight < windowheight ) 
	 { frame.style.height = windowheight + "px"; } 
} 
function showScalaSconti()
{
	resize();
	jq('#disable').show();
	jq('#sconti').show();
}
function hideScalaSconti()
{
	resize();
	jq('#disable').hide();
	jq('#sconti').hide();
}
function showLogin()
{
	resize();
	jq('#disable').show();
	jq('#login_div').show();
}
function hideLogin()
{
	resize();
	jq('#disable').hide();
	jq('#login_div').hide();
}

function getProdottoInDimensioni( codice, id )
{
	jq('#selected').attr('value', codice);
	jq('#Dselected').attr('value', codice);
	
	var id1 = 'PRD_' + id;
	
	jq.get( "dimensioni_prodotto.php", 
		{ codice: codice, id: id1 }, 
		function(data) {
			while ($( id1 ).rows.length > 0) $( id1 ).deleteRow(0);

			var row = $( id1 ).insertRow(-1);
			var cell = row.insertCell(0);

			cell.innerHTML = data;
		}
	);
	var id2 = 'DIM_PDF_' + id;
	
	jq.get( "dimensioni_pdf.php", 
		{ codice: codice, id: id2 }, 
		function(data) {
			jq('input#' + id2).attr('value', data);

			var id3 = 'dimensioni_pdf';
			
			while ($( id3 ).rows.length > 0) $( id3 ).deleteRow(0);

			var row = $( id3 ).insertRow(-1);
			var cell = row.insertCell(0);

			cell.innerHTML = data;
		}
	);
}
function tableFilter( id , id_sel, id_constr )
{
	var obj = jq('table#' + id);
	var rows = jq('table#' + id).find('tr.jqchoose');

	if (rows.length <= 0) return;

	var obj_constr = jq('#' + id_constr);
	var attr_choosen = obj_constr.attr('choosen');
	
	if ( attr_choosen && attr_choosen.length && jq(attr_choosen) )
		jq('#' + attr_choosen).css('font-weight', 'normal');

	obj_constr.attr('choosen', id_sel);
	attr_choosen = id_sel;
	jq('#' + attr_choosen).css('font-weight', 'bolder');

	var row = jq(rows.get(0)).find('td.tab_totale');

	var constrains = new Array( row.length );

	for (k = 0; k < row.length ; ++k)
	{
		constrains[k] = '';

		var cell = jq(row.get(k));

		if ( !cell.attr('choosen') ) continue;
		if (  cell.attr('choosen') == '') continue;

		constrains[k] = jq( '#' + cell.attr('choosen') ).html();
	}
	for (k = 1; k < rows.length ; ++k)
	{
		var row = jq(rows.get(k)).find('td.tab_totale_in');
		var displayValue = '';

		for (x = 1; x < row.length ; ++x)
		{
			if (constrains[x] == '') continue;

			cellValue = jq(row.get(x)).html();

			if ( trim(constrains[x]) != trim(cellValue) )
			{
				displayValue = 'none';
				break;
			}
		}
		if (displayValue == 'none')
		{
			jq(rows.get(k)).hide();
		}
		else
		{
			jq(rows.get(k)).show();
		}
	}
}
function tableReset( id )
{
	closeMiniMenu( id + '_LABEL' + '_COL' );

	var rows = jq('table#' + id + ' tr.jqchoose');

	var row = jq(rows.get(0)).find('td.tab_totale');

	for (k = 0; k < row.length ; ++k)
	{
		var cell = jq(row.get(k));

		attr_choosen = cell.attr('choosen');

		if ( !attr_choosen ) continue;
		if (  attr_choosen == '' ) continue;

		jq('#' + attr_choosen).css('font-weight', 'normal');
		cell.attr('choosen', '');
	}
	rows.show();
}
function closeMiniMenu( id )
{
	var a = $( id ).value.split('#');

	for (k = 0; k < a.length ; ++k)
	{
		if (!$(a[k])) break;
		$( a[k] ).hide();
	}
}

function jsgoto( id )
{
	var location = window.location.toString();
	var a = location.split('#');	

	window.location = a[0] + '#' + id;
}

function goTab( tabname )
{
/*	
	var text = ' sel=' + jq('#selected').attr('value')
			 + ' L=' + jq('#Ltab').attr('current')
	         + ' D=' + jq('#Dtab').attr('current')
	         + ' P=' + jq('#Ptab').attr('current')
	         + ' listino=' + jq('#sel_listino').attr('value')
	         + ' codice=' + jq('#sel_codice').attr('value')
	         + ' descrizione=' + jq('#sel_descrizione').attr('value');

	alert( 'gotab ' + tabname + text + ' ' +jq('#selected').attr('value').length );
*/
	jq('#sel_tab_' + tabname).attr('checked', true);

	if (jq('#selected').attr('value').length <= 0)
	{
		if (jq('#' + tabname + 'tab tr').length > 0) return;
		
		if (null != timeoutID)
			window.clearTimeout( timeoutID );

	 	while (jq('#' + tabname + 'tab tr').length > 0)
			jq('#' + tabname + 'tab tr:first').remove();

		if (jq('#sel_listino').attr('value').length > 0)
			timeoutID = window.setTimeout("doGetTab2('" 
				  + jq('#sel_listino').attr('value') + "', '" 
				  +  tabname + "', '" + tabname + "')", 1000);
		else
			timeoutID = window.setTimeout("doGetTab('" 
				  + jq('#sel_codice').attr('value') + "', '" 
				  + jq('#sel_descrizione').attr('value') + "', '" 
				  +  tabname + "', '" + tabname + "')", 1000);
		return;
	}
	if (jq('#selected').attr('value') == jq('#' + tabname + 'tab').attr('current')) return;

	if (null != timeoutID)
		window.clearTimeout( timeoutID );

	while (jq('#' + tabname + 'tab tr').length > 0)
		jq('#' + tabname + 'tab tr:first').remove();

	timeoutID = window.setTimeout("doGetTab3('" 
		  + jq('#selected').attr('value') + "', '" 
		  +  tabname + "', '" + tabname + "')", 1000);
}


function goPrivacy() 	   { goToPage('privacy.php', null); }
function goHome()    	   { /*goToPage('home.php', null);hilite('homeMenu');*/ window.location.href = 'index.html'; }
function goAzienda() 	   { goToPage('azienda.php', null);hilite('aziendaMenu'); }
function goProdotti() 	   { goToPage('prodotti.php', null);hilite('prodottiMenu'); }
function goContatti() 	   { goToPage('contatti.php', null);hilite('contattiMenu'); }
function goReteVendita()   { goToPage('retevendita.php', null);hilite('retevenditaMenu'); }
function goPartnership()   { goToPage('partnership.php', null);hilite('partnershipMenu'); }
function goIstruzioni( tab )    { goToPage('istruzioni.php?tab=' + tab, null); }

function hilite( idMenu )
{
	jq('table#tableUpperMenu').find('td').css('font-weight', 'normal');
	jq('table#tableUpperMenu').find('td').css('color', '#000000');

	if (idMenu)
	{
		jq('table#tableUpperMenu').find('td#' + idMenu).css('color', '#08519e');
		jq('table#tableUpperMenu').find('td#' + idMenu).css('font-weight', 'bold');
	}
}

function chooseRegion( reg )
{
	jq('div.regioni').hide();
	jq('div.' + reg).show();
}

function goToPage( page, param )
{
	++reqno;

	jq.get( page, 
		{ req: reqno, par: param }, 
		function(data) {	 	
				while ($('result').rows.length > 0)
					   $('result').deleteRow(0);

			 	var row = $('result').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = data;
		}
	);
	if (page != 'home.php')
	{
		if ( jq('#searchPanelForm').is(":hidden") )
			chooseSearch( 'L' );
	}
	/*
	else
	{
		jq('#searchPanelForm').hide();
	}
	*/
}

function chooseSearch( tab )
{
	jq("#tab").attr("value", tab);
	jq('#searchPanelForm').show();
	jq('#sel_tab_L').attr('checked', false);
	jq('#sel_tab_D').attr('checked', false);
	jq('#sel_tab_P').attr('checked', false);
	jq('#sel_tab_' + tab).attr('checked', true);
	jq('#codice').focus();
}



function agente( sigla )
{
		var r = jq('#agente_' + sigla).attr( 'value' );
			
		var a = r.split('|');
		
		jq('#agente_detail #regione').text( a[ 0] );
		jq('#agente_detail #sigla').text( a[ 1] );
		jq('#agente_detail #competenza').text( a[ 2] );
		jq('#agente_detail #agenzia').text( a[ 3] );
		if (a[4].length)
		{
			jq('#agente_detail #contatto_show').show();
			jq('#agente_detail #contatto').text( a[ 4] );
		}
		else
		{
			jq('#agente_detail #contatto_show').hide();
		}
		jq('#agente_detail #indirizzo').text( a[ 5] );
		jq('#agente_detail #civico').text( a[ 6] );
		jq('#agente_detail #cap').text( a[ 7] );
		jq('#agente_detail #comune').text( a[ 8] );
		jq('#agente_detail #provincia').text( a[ 9] );
		jq('#agente_detail #telefono1').text( a[10] );
		if (a[11].length)
		{
			jq('#agente_detail #telefono2_show').show();
			jq('#agente_detail #telefono2').text( a[11] );
		}
		else
		{
			jq('#agente_detail #telefono2_show').hide();
		}
		if (a[12].length)
		{
			jq('#agente_detail #telefono3_show').show();
			jq('#agente_detail #telefono3').text( a[12] );
		}
		else
		{
			jq('#agente_detail #telefono3_show').hide();
		}
		jq('#agente_detail #fax').text( a[13] );
		jq('#agente_detail #email').text( a[14] );
		jq('#agente_detail #email').attr( 'href', 'mailto:' + a[14] );
		jq('#agente_detail #note').text( a[15] );
		//jq('#agente_detail #coords').text( a[16] );
		jq('#agente_detail #gmaps').attr( 'src', a[17].split("^").join("'") );
		jq('#disable').show();
		jq('#agente_detail').show();
}

function getProdotti( listino ) 
{
	if (listino.length <= 0) 
	{
		emptyResult();
		return;
	}

	if (null != timeoutID)
		window.clearTimeout( timeoutID );

	timeoutID = window.setTimeout("doGetProdotti('" + listino + "')", 1000);
	
	hilite(null);
}
function doGetProdotti( list ) 
{
	++reqno;
	
	if (null == busy)
	{
		try{
			jq('#waiting').show();
			busy = getBusyOverlay($('waiting'), { color:'#C8C8C8', 
						 	     opacity:0.5, 
							     text:'loading', 
							     style:'text-decoration:blink;font-weight:bold;font-size:12px;color:white'},
							   {color:busy_color, size:busy_size, type:busy_type});
		}
		catch(e)
		{
			alert(e.message);
			busy = null;
		}
	}
	var url = '';
	
	jq.post( 'do_prodotti.php', 
		{listino: list, req: reqno},
		function(data) {var a = data.split('|');
			 	if (reqno > a[0]) return;
			 	
			 	while ($('prodotti').rows.length > 0)
			 		$('prodotti').deleteRow(0);
			 	
			 	var row = $('prodotti').insertRow(-1);
			 	var cell = row.insertCell(0);					 	
				cell.innerHTML = a[1];
				
				if (null != busy)
				{
					busy.remove(); 
					busy = null;
					jq('#waiting').hide();
				}
			       }
	);
}

