/**
 * @author francesco
 */
var pagina_redir = "";

function submitFilter(id)
{
	window.location = "/index.php?p=catalogo_auto&cat=" + parseInt(id);
}

function cambia_foto(foto, titolo)
{
	var new_foto = new Image();
	new_foto.src = foto;
	var w = new_foto.width;
	var h = new_foto.height;
	var DIM_MAX = 275;
	
	if (w > DIM_MAX || h > DIM_MAX)
	{
		if (w > h)
		{
			h = h * DIM_MAX / w;
			w = DIM_MAX;
		}
		else
		{
			w = w * DIM_MAX / h;
			h = DIM_MAX;
		}
	}
	
	document.getElementById("foto_principale").src = foto;
	document.getElementById("foto_principale").width = w;
	document.getElementById("foto_principale").height = h;
	document.getElementById("foto_principale").alt = titolo;
	document.getElementById("foto_principale").title = titolo;
	document.getElementById("foto_principale").onclick = function()
	{
		openPhoto(foto);
	}
}

function openPhoto(foto)
{
	var new_foto = new Image();
	new_foto.src = foto;
	var w = new_foto.width;
	var h = new_foto.height;
	var DIM_MAX = 490;
	
	if (w > DIM_MAX || h > DIM_MAX)
	{
		if (w > h)
		{
			h = h * DIM_MAX / w;
			w = DIM_MAX;
		}
		else
		{
			w = w * DIM_MAX / h;
			h = DIM_MAX;
		}
	}
	
	var dimX = screen.width; //larghezza pagina
	var dimY = screen.height; //lunghezza pagina
	
	if (document.all) // IF IE
	{
		dimX = document.body.parentNode.scrollLeft + (dimX / 3);
		dimY = document.body.parentNode.scrollTop + 100;
	}
	else
	{
		dimX = window.scrollX + (dimX / 3); //larghezza pagina
		dimY = window.scrollY + 100; //lunghezza pagina
	}
	
	var wall = document.createElement("div");
	wall.style.position = "absolute";
	wall.style.top = dimY + "px";
	wall.style.left = dimX + "px";
	wall.style.width = "500px";
	wall.style.height = "400px";
	wall.style.backgroundColor = "#FFFFEE";
	wall.style.border = "1px solid black";
	
	var box_video = document.createElement("div");
	box_video.style.position = "relative";
	box_video.style.top = "5px";
	box_video.style.left = "5px";
	box_video.style.width = "495px";
	box_video.style.height = "370px";
	box_video.innerHTML = '<img src="' + foto + '" width="' + w + '" height="' + h + '" />';

	var link = document.createElement("a");
	link.style.position = "relative";
	link.style.top = "10px";
	link.style.left = "230px";
	link.innerHTML = "Chiudi";
	link.href = "javascript:;";
	link.onclick = function() 
	{ 
		document.body.removeChild(wall); 
	}
	
	wall.appendChild(box_video);
	wall.appendChild(link);
	document.body.appendChild(wall);
}



function swapHeader(pic)
{
	document.getElementById("header_foto").src = pic;
}

function Logout(page, red, div)
{
	this.t_page = page;
	this.target = div;
	this.redtarget = red;

	this.exec = function()
	{
		try
		{
			pagina_redir = this.t_page;
			document.getElementById(this.target).innerHTML = "Uscendo ...";
			makeRequest("include_user/php/" + this.redtarget, this.redir, "POST", "");
		} catch (e) { document.getElementById(this.target).innerHTML = e.message; }
	}

	this.redir = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200) window.location.replace(pagina_redir);
			else
			{
				var contentHTML = "<b>Errore durante il trasferimento dati.</b>";
				contentHTML += "<br />Stato : " + xmlhttp.status;
				document.getElementById(user_target).innerHTML = contentHTML;
			}
		}
	}
}

function inviaRichiesta(value)
{
	makeRequest("include_html/mini_sito.php", redir2, "POST", "id=" + value);
}

var redir2 = function()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
			getById("php_response").innerHTML = xmlhttp.responseText;
		}
		else
		{
			var contentHTML = "<b>Errore durante il trasferimento dati.</b>";
			contentHTML += "<br />Stato : " + xmlhttp.status;
			document.getElementById(user_target).innerHTML = contentHTML;
		}
	}
}

function handlePhp()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200) document.getElementById(user_target).innerHTML = xmlhttp.responseText;
		else
		{
			var contentHTML = "<b>Errore durante il trasferimento dati.</b>";
			contentHTML += "<br />Stato : " + xmlhttp.status;
			document.getElementById(user_target).innerHTML = contentHTML;
		}
	}
}

try { LLI.callBack("functions1_lib"); }
catch (e) {}
