/*
 * Setta il clip di un layer
 */
function set_clip(layerId, topVal, rightVal, bottomVal, leftVal)
{
	var layer = window.document.getElementById(layerId);

	layer.style.clip = "rect(" + topVal + "px " + rightVal + "px " + bottomVal + "px " + leftVal + "px)";
}

/*
 * Permette di modificare la visibilita' di un layer
 */
function set_layer_visibility(layerId, val)
{
	var layer = window.document.getElementById(layerId);

	layer.style.visibility = val;
}

/*
 * Restituisce la larghezza di un Viewport
 */
function get_viewport_width() {
	var width = 0;
	/*if( document.documentElement && document.documentElement.clientWidth ) {
		width = document.documentElement.clientWidth;
	}
	else */if( document.body && document.body.clientWidth ) {
		width = document.body.clientWidth;
	}
	else if( window.innerWidth ) {
		width = window.innerWidth;// - 18;
	}
	return width;
}

/*
 * Restituisce l'altezza di un Viewport
 */
function get_viewport_height()
{
	var height = 0;

	/*alert("1 - " + document.documentElement.clientHeight);
	alert("2 - " + document.body.clientHeight);
	alert("3 - " + window.innerHeight);*/

	if (window.innerHeight) {
		height = window.innerHeight
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		height = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight ) {
		height = document.body.clientHeight;
	}

	/*if( document.documentElement && document.documentElement.clientHeight ) {
		height = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		height = document.body.clientHeight;
	}
	else if( window.innerHeight ) {
		height = window.innerHeight;// - 18;
	}*/
	return height;
}

/*
 * Margine sinistro di un layer
 */
function get_left_margin(element)
{
	if( document.getElementById ) {
		// Get a reference to divTest and measure its width and height.
		var div = document.getElementById(element);
		var divWidth = div.offsetWidth ? div.offsetWidth : div.style.width ? parseInt( div.style.width ) : 0;
		
		// Calculating setX and setX so the div will be centered in the viewport.
		var setX = ( get_viewport_width() - divWidth ) / 2;

		// If setX or setY have become smaller than 0, make them 0.
		if( setX < 0 ) setX = 0;

		return setX;
	}
}

