// JavaScript Document
function LoadURL(param)
{
	if(param=='azienda')
	{
		LoadPage("index-block.html");	
	}
	else if(param=='servizi')
	{
		LoadPage("servizi-block.html");	
	}
	else if(param=='autorizzazioni')
	{
		LoadPage("autorizzazioni-block.html");	
	}
	else if(param=='tipirifiuti')
	{
		LoadPage("tipirifiuti-block.html");	
	}
	else if(param=='dovesiamo')
	{
		LoadPage("dovesiamo-block.html");	
	}
	else if(param=='foto')
	{
		LoadPage("foto-block.html");
	}
	else if(param=='contatti')
	{
		LoadPage("contatti-block.html");
	}
}

function LoadAutorizzazioniPrivate(form)
{
	utente = form.user.value;
	pass = form.pass.value;
	LoadGeneric("autorizzazioni_private.php?user="+utente+"&pass="+pass,"autorizzazioni_private");	
}

function LoadPage(page)
{
	var content = document.getElementById("content");
    var url = "./pagine/" + page;
    var preloadText = "Caricamento in corso...";
    if(typeof XMLHttpRequest != "undefined") 
	{ 
            x = new XMLHttpRequest();
	}
	else 
	{ 
		try { x = new ActiveXObject("Msxml2.XMLHTTP");} 
    	catch (e) { try { x = new ActiveXObject("Microsoft.XMLHTTP");} catch (e){x = null;}}
	}
	if (x) 
    {
		content.innerHTML = preloadText;
        x.onreadystatechange = function() 
		{
			if (x.readyState == 4 && (x.status == 200))
            {
            	content.innerHTML = x.responseText;
            }
        }
        x.open("GET", url, true);
        x.send(null);
    }
}

function LoadGeneric(page,mycontent)
{
	var content = document.getElementById(mycontent);
    var url = "./pagine/" + page;
    var preloadText = "Caricamento in corso...";
    if(typeof XMLHttpRequest != "undefined") 
	{ 
            x = new XMLHttpRequest();
	}
	else 
	{ 
		try { x = new ActiveXObject("Msxml2.XMLHTTP");} 
    	catch (e) { try { x = new ActiveXObject("Microsoft.XMLHTTP");} catch (e){x = null;}}
	}
	if (x) 
    {
		content.innerHTML = preloadText;
        x.onreadystatechange = function() 
		{
			if (x.readyState == 4 && (x.status == 200))
            {
            	content.innerHTML = x.responseText;
            }
        }
        x.open("GET", url, true);
        x.send(null);
    }
}

function LoadFoto(num)
{
	document.contenitore.src = 'foto/'+num+'.jpg';	
}

function SendMail(form)
{
	nome = form.nome.value;
	cognome = form.cognome.value;
	email = form.email.value;
	telefono = form.telefono.value;
	richiesta = form.richiesta.value;
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   	if (Filtro.test(trim(email)) && trim(richiesta)!= "")
    {
		LoadGeneric("richiesta-info.php?nome="+nome+"&cognome="+cognome+"&telefono="+telefono+"&email="+email+"&richiesta="+richiesta,"result_email");
	}
	else
	{
		document.getElementById("result_email").innerHTML = "Inserire una richiesta ed un indirizzo valido.";	
	}
}

function trim(stringa)
{
	return stringa.replace(/^\s*/, "").replace(/\s*$/, "");
}
