/**
 *  Lista pannelli presenti in hom
 *  @var {Array} 
 */
var paneList = new Array('domus3d_project','domus3d_panel','domus3d_box');

/**
 * Test per compatibilitą  DOM
 * @return {Boolean}
 */
function domw3c(){
	if(document.getElementById) {
		return true;
	} else {
  		return false;
	}
}

function toggleVisibility (objId) {
	if (!domw3c()) { alert("Attenzione, utilizzare un browser compatibile (IE 5.5 o sup.)"); return; }
	el = document.getElementById(objId);
	if (el.style.display == "none") {
		el.style.display = "block";
	} else {
		el.style.display = "none";
	}
}

/**
 * Apre/chiude un div in base alle classi open e close
 */ 
function togglePane (paneId) {
	if (!domw3c()) { alert("Attenzione, utilizzare un browser compatibile (IE 5.5 o sup.)"); return; }
	for (i=0 ; i < paneList.length ; i++) {
		el = document.getElementById(paneList[i]);
		if (paneId == paneList[i] && el.className == "close") {
//			el.className = "open";
			smoothToggle(paneId, 1);
		} else {
			el.className = "close";
		}
	}
}

function toggleChapter (paneId) {
	if (!domw3c()) { alert("Attenzione, utilizzare un browser compatibile (IE 5.5 o sup.)"); return; }
	i=1;

	prefix = paneId.substring(0, paneId.indexOf("_"));
	while (document.getElementById(prefix + '_' + i) != null) {
		el = document.getElementById(prefix + '_' + i);
		if (paneId == (prefix + '_' + i) && el.className == "close") {
			el.className = "open";
		} else {
			el.className = "close";
		}
		i++;
	}
}

function smoothToggle (paneId, direction, desiredHeight, step) {
	el = document.getElementById(paneId);
	if (desiredHeight == null) {
		el.className = "open";
		desiredHeight = el.offsetHeight;
		el.style.height = "0";
		el.style.overflow = "hidden";
		step = Math.floor(desiredHeight / 8);
	}
	if (el.offsetHeight >= desiredHeight) {
		el.style.height = null;
		el.className = "open";
		return;
	}

	if (direction == 1) {
		newH = parseInt(el.offsetHeight) + step;
		if (newH > desiredHeight) { newH = desiredHeight; }
		//el.setAttribute("style","height: " + newH + "px;");
	} else {
		newH = parseInt(el.offsetHeight) - step;
		if (newH < desiredHeight) { newH = desiredHeight; }
	}
	el.style.height = newH + "px";
	window.setTimeout("smoothToggle('" + paneId + "', " + direction + ", " + desiredHeight + ", " + step + ")",20);
}

/**
 * Seleziona tutti i check di un form che condividono lo stesso nome
 * 
 * @param formObj
 * @param checkName
 * @param status
 * @return void
 */
function selectAll(formObj, checkName, status) {
	checks = formObj.elements[checkName];
	if (checks != null) {
		for (i=0; i < checks.length ; i++) {
			if (checks[i].disabled == false) {
				checks[i].checked = status;
			}
		}
	}
}

function switchAllFiles() {
	checks = document.forms['fileList'].elements["EXCLUDES[]"];
	if (checks != null) {
		for (i=0; i < checks.length ; i++) {
			checks[i].click();
		}
	}
}