﻿<!-- Begin
// JavaScript Helper functions
// (c) 2002-2009 P.Guerra srl Milano - Tutti i diritti riservati
// La riproduzione, l'uso o la distribuzione senza autorizzazione sono vietati.
//
function DetectLanguage()
{
	if (navigator.appName == 'Netscape')
	    var language = navigator.language;
	else
	    var language = navigator.browserLanguage;
	
	var code = language.substring(0,2).tolower;
}

function ToggleTableRow(TableId, RowId)
{
	// visualizza/nasconde una riga di una tabella
	var row;
	var table;
	table = document.getElementById(TableId);
	row = table.rows[RowId];
	if (row.style.display == 'none')
		row.style.display = '';
	else
		row.style.display = 'none';
}

function ToggleShortLong(cell)
{
	// inverte la visualizzazione delle righe con id short e long
	// della tabella a cui appartiene la cella
	var table;
	var table = cell.parentNode.parentNode;
	row = table.rows['short'];
	if (row.style.display == 'none')
	{
		table.className = "collapse";
		row.style.display = '';
	}
	else
	{
		table.className = "collapse_exp";	
		row.style.display = 'none';
	}
	row = table.rows['long'];
	if (row.style.display == 'none')
		row.style.display = 'inline';
	else
		row.style.display = 'none';
}

function ToggleShortLongById(TableId)
{
	// inverte la visualizzazione delle righe con id short e long
	// della tabella indicata
	var table;
	var table = document.getElementById(TableId);
	row = table.rows['short'];
	if (row.style.display == 'none')
	{
		table.className = "collapse";
		row.style.display = '';
	}
	else
	{
		table.className = "collapse_exp";	
		row.style.display = 'none';
	}
	row = table.rows['long'];
	if (row.style.display == 'none')
		row.style.display = '';
	else
		row.style.display = 'none';
}

function ToggleHelp(cell, content_id)
{
	// commuta lo stato delle tabelle di help, modificando header e visibilità della cella "content_id"
	var table = cell.parentNode.parentNode;
	row = table.rows[content_id];
	if (table.className == "collapse")
	{
		row.style.display = '';
		table.className = "collapse_exp";	
	}
	else if (table.className == "collapse_exp")
	{
		table.className = "collapse";
		row.style.display = 'none';
	}
	else if (table.className == "collapse_w")
	{
		row.style.display = '';
		table.className = "collapse_exp_w";	
	}
	else if (table.className == "collapse_exp_w")
	{
		table.className = "collapse_w";
		row.style.display = 'none';
	}
	else if (table.className == "menu")
	{
		row.style.display = '';
		table.className = "menu_exp";	
	}
	else if (table.className == "menu_exp")
	{
		table.className = "menu";
		row.style.display = 'none';
	}
}
//------------------------------------------------------------------------------------------------------------------
// funzioni usate nella validazione dei forms
function inValidCharSet(str,charset)
{
	var result = true;
	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0; i < str.length; i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Inserite un indirizzo email completo nella forma: nome@dominio.ext");
		formField.focus();
		result = false;
	}
	return result;
}
function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Inserite un numero nel campo "' + fieldLabel +'".');
			formField.focus();		
			result = false;
		}
	} 
	return result;
}
function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Inserite un numero nel campo "' + fieldLabel +'".');
			formField.focus();		
			result = false;
		}
	} 
	return result;
}
function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[1],10);
  			var day = parseInt(elems[0],10);
 			var year = parseInt(elems[2],10);
			result = allDigits(elems[1]) && (month > 0) && (month < 13) &&
					 allDigits(elems[0]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Inserite una data nel formato GG/MM/AAAA nel campo "' + fieldLabel +'".');
			formField.focus();		
		}
	} 
	return result;
}
function validRequired(formField,fieldLabel)
{
	var result = true;
	if (formField.value == "")
	{
		alert('Inserite un valore per il campo "' + fieldLabel +'".');
		formField.focus();
		result = false;
	}
	return result;
}
function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}
function isEmailAddr(email)
{
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}
//-------------------

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+'.'+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '€ ' + dblValue + ',' + strCents);
}


function createCookie(name,value,days,hours,minutes) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000 + hours*60*60*1000 + minutes*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//--------------------------------------------------------------------------
function getViewportHeight()
{
	// document.viewport.getHeight() di prototype (fino alla 1.6.2) non sembra
	// funzionare con Opera 9.5 (funzionava con le versioni precedenti)

	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
		viewportheight = window.innerHeight;
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	   viewportheight = document.documentElement.clientHeight
	// older versions of IE
	else
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	return viewportheight;
}
function getViewportWidth()
{
	var viewportwidth;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
		viewportwidth = window.innerWidth;
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	   viewportwidth = document.documentElement.clientWidth;
	// older versions of IE
	else
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	return viewportwidth;
 }
//--------------------------------------------------------------------------
function updateLayout()
{	
	var w0 = document.viewport.getWidth();
	var x = (w0 - 880)>>1;
	if (x<0) x = 0;
	x = x + 146;
	if (x<210) x = 210;
	$('menu').setStyle({left: x+'px'});

    return;
	// var h0 = document.viewport.getHeight(); - non funziona con Opera 9.5 
	var h0 = getViewportHeight();

	if ($('container') != null)
	{
		$('container').setStyle({'height': (h0-100)+'px'});
	}
	if ($('news') != null)
	{
		var mt = $('news').getStyle('margin-top');
		if (mt != null) h0 -= parseInt(mt);
		$('news').setStyle({'height': (h0-100)+'px'});
	}
	
	var x = (w0 - 880)>>1;
	if (x<0) x = 0;
	
	if ($('home_content') != null)
	{
		$('home_content').setStyle({'left': x+'px'});
		$('home_content').setStyle({'top': '100px'});
	}
	x = x + 146;
	if (x<210) x = 210;
	$('top_menu').setStyle({left: x+'px'});
	$('bottom_menu').setStyle({left: x+'px'});
	//
	x = w0 - 150;
	if (x<780) x = 780;
	$('loghi').setStyle({left: x+'px'});
	//
}
//--------------------------------------------------------------------------
// usato per ristemare la gestione delle option list in firefox
function is_firefox()
{
    return (navigator.appName.toLowerCase().indexOf("netscape")>=0 );
}
function fire_event(element,event)
{
    if (document.createEventObject)
    {
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else
    {
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}
function ff_fixchange(obj)
{
    // gestisce l'evento onkeydown nella select che in FireFox non genera l'evento
    // onChange, mentre lo fa in Explorer ed in Opera
    if (is_firefox()) fire_event(obj, 'change');
}
// End -->

