/**
 * ITA:Restituisce la distanza in px del bordo sinistro dell'elemento dal bordo sinistro della finestra
 * ENG: Return the px distance from left border of the element to left border of the window
 **/
function getElementLeft(p_elm) {
	var x = 0;
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	while (elm != null) {
		x+= elm.offsetLeft;
		elm = elm.offsetParent;
	}
	return parseInt(x);
}

/**
 * ITA: Restituisce la larghezza dell'elemento in px
 * ENG: Return the px width of the element
 **/
function getElementWidth(p_elm){
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	return parseInt(elm.offsetWidth);
}

/**
 * ITA: Restituisce la distanza in px del bordo destro dell'elemento dal bordo sinistro della finestra
 * ENG: Return the px distances from right border of the element to left border of window
 **/
function getElementRight(p_elm){
	return getElementLeft(p_elm) + getElementWidth(p_elm);
}

/**
 * ITA: Restituisce la distanza in px del bordo superiore dell'elemento dal bordo superiore della finestra
 * ENG: Return the px distances from top border of the element to top border of the window
 **/
function getElementTop(p_elm) {
	var y = 0;
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	while (elm != null) {
		y+= elm.offsetTop;
		elm = elm.offsetParent;
	}
	return parseInt(y);
}

/**
 * ITA: Restituisce l'altezza dell'elemento in px
 * ENG: Return the px heght of the element
 **/
function getElementHeight(p_elm){
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	return parseInt(elm.offsetHeight);
}

/**
 * ITA: Restituisce la distanza in px del bordo inferiore dell'elemento dal bordo superiore della finestra
 * ENG: Return the px distances from bottom border of the element to border top of the window
 **/
function getElementBottom(p_elm){
	return getElementTop(p_elm) + getElementHeight(p_elm);
}

/**
 * ITA: Restituisce una proprietà dello stile dell'elemento, null se non esiste
 * ENG: Return a style property of the elemnt , it return null if does not exist
 **/
function getElementProperty(p_elm, p_property){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if (elm != null){
		if(elm.style){
			elm = elm.style;
			if(elm[p_property]){
				return elm[p_property];
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}

/**
 * ITA: Setta una proprietà dello stype dell'elemento
 * ENG: Set a property of style type of the element
 **/
function setElementProperty(p_elm, p_property, p_value){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if((elm != null) && (elm.style != null)){
		elm = elm.style;
		elm[ p_property ] = p_value;
	}
}
