// Funzione per i banner per poter validare la pagine w3c
function banner_1()
{
	contenuto="<ob"+"ject classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='200' height='100'><param name='movie' value='banner/case24_laterale.swf?bid=1'><param name='quality' value='high'><param name='bgcolor' value='#ffffff'><embed src='./banner/case24_laterale.swf?bid=1' quality=high bgcolor='#ffffff' width='200' height='100' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed></ob"+"ject>";
	document.getElementById('case24').innerHTML=contenuto;
}
function banner_2()
{
	contenuto="<ob"+"ject classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='200' height='100'><param name='movie' value='banner/autoaffari.swf?bid=2'><param name='quality' value='high'><param name='bgcolor' value='#ffffff'><embed src='./banner/autoaffari.swf?bid=2' quality=high bgcolor='#ffffff' width='200' height='100' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed></ob"+"ject>";
	document.getElementById('autoaffari').innerHTML=contenuto;
}
function banner_3()
{
	contenuto="<ob"+"ject classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='200' height='100'><param name='movie' value='banner/cercocamion.swf?bid=3'><param name='quality' value='high'><param name='bgcolor' value='#ffffff'><embed src='./banner/cercocamion.swf?bid=3' quality=high bgcolor='#ffffff' width='200' height='100' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed></ob"+"ject>";
	document.getElementById('cercocamion').innerHTML=contenuto;
}

function mostraform()
{
	document.getElementById('divform').style.display='block';
}
// verifica i campi inseriti prima dell'invio dell'e-mail
function verifica_email_interna()
{
	document.contatti.nome.className="testo";	
	document.contatti.citta.className="testo";	
	document.contatti.email.className="testo";
	document.contatti.messaggio.className="ok";
	var valori_email=/[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	procedi=true;
	if(document.contatti.nome.value=="")
	{
		document.contatti.nome.className="inviaErrore";	
		procedi=false;
		alert("Inserire il nome.");
		document.contatti.nome.focus();
	}else if(document.contatti.citta.value==""){
		document.contatti.citta.className="inviaErrore";	
		procedi=false;
		alert("Inserire la città.");
		document.contatti.citta.focus();
	}else if((document.contatti.email.value=="")||(!document.contatti.email.value.match(valori_email))){
		document.contatti.email.className="inviaErrore";	
		procedi=false;
		alert("Inserire un'e-mail valida.");
		document.contatti.email.focus();
	}else if(document.contatti.messaggio.value==""){
		document.contatti.messaggio.className="errore";	
		procedi=false;
		alert("Inserire il messaggio.");
		document.contatti.messaggio.focus();
	}
		
	if(procedi==true)
	{
		var a=confirm("Accetti il trattamento dei tuoi dati personali?");
		if(a)
		{

			document.contatti.submit();
		}
	}
}
// verifica i campi inseriti prima dell'invio dell'e-mail
function verifica_email()
{
	document.contatti.nome.className="testo";	
	document.contatti.citta.className="testo";	
	document.contatti.email.className="testo";
	document.contatti.messaggio.className="ok";	
	procedi=true;
	if(document.contatti.nome.value=="")
	{
		document.contatti.nome.className="inviaErrore";	
		procedi=false;
		alert("Inserire il nome o ragione sociale.");
		document.contatti.nome.focus();
	}else if(document.contatti.citta.value==""){
		document.contatti.citta.className="inviaErrore";	
		procedi=false;
		alert("Inserire la città.");
		document.contatti.citta.focus();
	}else if(document.contatti.email.value==""){
		document.contatti.email.className="inviaErrore";	
		procedi=false;
		alert("Inserire un'e-mail valida.");
		document.contatti.email.focus();
	}else if(document.contatti.messaggio.value==""){
		document.contatti.messaggio.className="errore";
		procedi=false;
		alert("Inserire il messaggio.");
		document.contatti.messaggio.focus();
	}else if(document.contatti.privacy[1].checked){
		procedi=false;
		alert("Devi accettare il trattamento dei dati personali!");
	}
	
	if(procedi==true)
	{
		document.contatti.submit();
	}
}

// Visualizzazione sottomenù
function visualizzaMenu(valore, pagina)
{
	var xmlHttp = getXmlHttpObject();
	xmlHttp.open("GET", "./include/ajax.php?funzione=menu&valore="+valore+"&pagina="+pagina, true);
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.send(null);
	function stateChanged() 
	{
		if(xmlHttp.readyState == 4) 
		{
			//Stato OK
			if (xmlHttp.status == 200) 
			{
				var resp = xmlHttp.responseText;
				document.getElementById('sottoMenu').innerHTML=resp;
			}
		}
	}
}

// Funzione indispensabile per il funzionamento delle chiamate in ajax
function getXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		//Firefox e Opera
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

// Banner scorrevoli a lato
// Script per avere il banner laterale che segue lo scroll della pagina
window.onerror = null;
var topMargin = 10;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left)
{
	if(ns6)
	{
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}else if(ie4){
		this.obj = document.all[id].style;
		this.obj.left = left;
		return this.obj;
	}else if(ns4){
		this.obj = document.layers[id];
		this.obj.left = left;
		return this.obj;
	}
}
function layerSetup()
{
	floatLyr = new layerObject('floatLayer', 780);
	window.setInterval("main()", 10)
}

function floatObject()
{
	if(ns4 || ns6)
	{
		findHt = window.innerHeight;
	}else if(ie4){
		findHt = document.body.clientHeight;
	}
}

function main()
{
	if(ns4)
	{
		this.currentY = document.layers["floatLayer"].top;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	}else if(ns6){
		this.currentY = parseInt(document.getElementById('floatLayer').style.top);
		this.scrollTop = scrollY;
		mainTrigger();
	}else if(ie4){
		this.currentY = floatLayer.style.pixelTop;
		this.scrollTop = document.body.scrollTop;
		mainTrigger();
	}
}

function mainTrigger()
{
	var newTargetY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY )
	{
		if ( newTargetY != this.targetY )
		{
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
	}
}

function floatStart()
{
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt)
	{
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}else{
		this.D = this.currentY;
	}
}

function animator()
{
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY ))
	{
		if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
		if ( ns4 )document.layers["floatLayer"].top = newY;
		if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
	}
}

function start()
{
	if(ns6||ns4)
	{
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		floatObject();
	}else if(ie4){
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup();
		floatObject();
	}
}