/** * 
 * @author francesco 
 * */
var pagina_redir = "";
function enterBox(id, text){	var box = document.getElementById(id);	if (box.value == text) 		box.value = "";}function exitBox(id, text){	var box = document.getElementById(id);	if (box.value == "")		box.value = text;}
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;		
		}	
	}
}

function checkForm(nome_form)
{
    var oForm = document.getElementById(nome_form);
    var field;
    
    for (var i = 0; i < oForm.elements.length; i++)
    {
        field = oForm.elements[i];

        switch (field.type)
        {
        	case "text" :
        	case "textarea" :
        	case "select-one" :
        	case "file" :

	            if (field.value.length <= 0)
	            {
		            alert("Il campo non puo' essere vuoto");
		            field.value = "";
					field.style.backgroundColor = "#f0f0f0";
					field.style.borderColor = "#ff0000";
					field.focus();
					return;
	            }
	            else if ((field.id == "coperti" || field.name == "coperti" || 
	            		field.id == "telefono" || field.name == "telefono" || 
	            		field.id == "cellulare" || field.name == "cellulare") &&
	            		isNaN(field.value))
	            {
	            	alert("Il campo puo' contenere solo numeri");
	                field.style.backgroundColor = "#f0f0f0";
					field.style.borderColor = "#ff0000";
	                field.value = "";
	                field.focus();
	                return;
	            }
	            else if ((field.id == "email" || field.name == "email") && (field.value.indexOf("@") <= 0 || field.value.indexOf("@") == field.value.length - 1))
	            {
	            	alert("E' necessario inserire una e-mail valida");
	                field.style.backgroundColor = "#f0f0f0";
					field.style.borderColor = "#ff0000";
	                field.value = "";
	                field.focus();
	                return;
	            }
	            else if ((field.id == 'giorno' || field.id == 'data' || field.name == 'giorno' || field.name == 'data'))
	            {
	            	var temp = field.value.split("/");
	            	if (temp[0].length != 2 || temp[1].length != 2 || temp[2].length != 4)
	            	{
	            		alert("La data deve essere in formato GG/MM/AAAA");
		                field.style.backgroundColor = "#f0f0f0";
						field.style.borderColor = "#ff0000";
		                field.value = "";
		                field.focus();
		                return;
	            	}
	            	else
	            	{
	            		field.style.backgroundColor = "";
		            	field.style.borderColor = "";
	            	}
	            }
	            else
	            {
	            	field.style.backgroundColor = "";
	            	field.style.borderColor = "";
	            }
	            
	            break;

            case "checkbox" :

				if (field.checked == false)
				{
					alert("Il campo deve essere selezionato");
					field.focus();
					return;
				}

				break;

            case "radio" :

				field = document.getElementsByName(field.name);

				var checked = false;
				for (var j in field)
					if (field[j].checked)
					{
						checked = true;
						break;
					}

				if (!checked)
				{
					alert("Deve essere selezionata almeno un'opzione");
					field[0].focus();
					return;
				}
            	
	            break;
        }
    }

    document.getElementById(nome_form).submit();
}

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 box = document.createElement("div");
	box.id = "box_" + parseInt(Math.random() * 100);
	box.style.position = "absolute";
	box.style.top = "0px";
	box.style.left = "0px";
	box.style.width = screen.width + "px";
	box.style.height = screen.height + "px";
	
	var back = document.createElement("div");
	back.id = "back_div";
	back.style.position = "absolute";
	back.style.top = "0px";
	back.style.left = "0px";
	back.style.width = "100%";
	back.style.height = "100%";
	back.style.backgroundColor = "black";
	*/
	var wall = document.createElement("div");
	wall.id = "wall_div";
	wall.style.position = "absolute";
	wall.style.top = dimY + "px";
	wall.style.left = dimX + "px";
	wall.style.width = w + 10 + "px";
	wall.style.height = h + 50 + "px";
	wall.style.backgroundColor = "#F4F4EC";
	wall.style.border = "1px solid black";
	wall.style.textAlign = "center";
	
	var box_video = document.createElement("div");
	box_video.id = "box_div";
	box_video.style.position = "relative";
	box_video.style.paddingTop = "5px";
	box_video.style.width = "auto";
	box_video.style.height = "auto";
	box_video.innerHTML = '<img src="' + foto + '" width="' + w + '" height="' + h + '" />';

	var link = document.createElement("a");
	link.id = "link_box";
	link.className = "utility";
	link.style.position = "relative";
	link.style.top = "10px";
	link.innerHTML = "Chiudi";
	link.href = "javascript:;";
	link.onclick = function() 
	{ 
		document.body.removeChild(wall);
	}

	/*
	wall.appendChild(box_video);
	wall.appendChild(link);
	box.appendChild(back);
	box.appendChild(wall);
	document.body.appendChild(box);
	*/
	wall.appendChild(box_video);
	wall.appendChild(link);
	document.body.appendChild(wall);
	/*
	setOpacity(back.id, 50);
	setOpacity(wall.id, 100);
	*/
}

try { LLI.callBack("functions1_lib"); }
catch (e) {}
