/**
 * @author francesco
 */
function getVal(target_id)
{ return document.getElementById(target_id).value; }

function enableButton(target)
{ document.getElementById(target).disabled = false; }

function disableButton(target)
{ document.getElementById(target).disabled = true; }

function precache(photoName)
{
	var newphoto = new Image();
	newphoto.src = photoName;
	return newphoto;
}

function loadingGIF(target)
{
	var contentHTML = "<div align=\"left\">";
	contentHTML += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	contentHTML += "<tr><td align=\"left\"><img hspace=\"10\" src=\"immagini/loading.gif\" width=\"32\" height=\"32\" />";
	contentHTML += "</td></tr></table></div>";
	target.innerHTML = contentHTML;
}

function setOpacity(div, alpha)
{
	var myDiv = document.getElementById(div);

	myDiv.style.mozOpacity = alpha / 100;
	myDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + alpha + ")";
	myDiv.style.opacity = alpha / 100;
}

function popup(urlname)
{
	var stile = "top=0,left=0,fullscreen=yes,status=no,menubar=no";
	stile += ",toolbar=no,scrollbar=yes,resize=yes";
	window.open(urlname, "", stile);
}

function isArray()
{
	if (typeof arguments[0] == 'object')
	{
		var criterion = arguments[0].constructor.toString().match(/array/i);
		return (criterion != null);
	}
	return false;
}

function inArray(array, item)
{
	if (isArray(array))
		for (i = 0; i < array.length; i++)
			if (array[i] == item) return true;
	return false;
}

function lightpopup(message, target)
{
	var marginTop = (ie) ? document.documentElement.scrollTop : window.pageYOffset;

	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 = "100%";
	box.style.height = "100%";

	box.target = target;
	box.onclick = function()
	{
		document.body.removeChild(this);
		document.getElementById(this.target).focus();
	}

	var wall = document.createElement("div");
	wall.id = "wall_" + parseInt(Math.random() * 100);
	wall.style.position = "absolute";
	wall.style.top = "0px";
	wall.style.left = "0px";
	wall.style.width = document.body.clientWidth + "px";
	wall.style.height = document.body.clientHeight + "px";
	wall.style.backgroundColor = "white";

	var pop = document.createElement("div");
	pop.id = "popup_" + parseInt(Math.random() * 100);
	pop.style.position = "absolute";
	pop.style.top = parseInt(marginTop + 10) + "px";
	pop.style.left = "10px";
	pop.style.backgroundColor = "white";
	pop.style.borderColor = "green";
	pop.style.borderWidth = "1px";
	pop.style.borderStyle = "solid";
	pop.style.padding = "10px 10px 10px 10px";

	var contentHTML = "<p>" + message + "</p><br />";
	contentHTML += "<div style=\"width:100%\" align=\"center\">";
	contentHTML += "<a href=\"javascript:void(0);\" title=\"Chiudi\"><b class=\"verde\">OK</b></a>";
	contentHTML += "</div>";
	pop.innerHTML = contentHTML;

	box.appendChild(wall);
	box.appendChild(pop);
	document.body.appendChild(box);

	setOpacity(wall.id, 70);
	setOpacity(pop.id, 80);
}

function check(id, pattern)
{
	var check = new String(document.getElementById(id).value);

	if (!check.match(pattern))
	{
		document.getElementById(id).style.borderColor = "#FF0000";
		document.getElementById(id).focus();
		return false;
	}
	else
	{
		document.getElementById(id).style.borderColor = "gray";
		return true;
	}
}

var ie = (navigator.appName.indexOf("Internet Explorer") != -1) ? 1 : 0;
