var nsubmit = 0;
function sendForm (where) {
	if (nsubmit <= 0) where.form.submit();
	nsubmit ++;
}

function Elem (what) { // sostituito con la funzione di Prototype '$'
	if (typeof(what) == 'string')
		var elem = document.getElementById(what);
	else var elem = what;
	if (elem) return elem;
	else return false;
}
function addListener(element, baseName, handler) {
	if (element.addEventListener)
		element.addEventListener(baseName, handler, false);
	else if (element.attachEvent)
		element.attachEvent('on' + baseName, handler);
}
function bindMethod(method, scope){
    return function() {
        method.apply(scope,arguments);
    }
}

function popUp(url, w, h, option) {
	w = (w=='')?600:w;
	h = (h=='')?500:h;
	var wl = Math.round((screen.width-w)/2);
	var wt = Math.round((screen.height-h)/2);
	// toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes
	if (!option) option = 'status=no,scrollbars=yes,resizable=yes';
	option += ',width='+w+',height='+h+',top='+wt+',left='+wl+'';
	var windowName = '';
	window.open(url, windowName, option);
}

function finpop(id,idcat,idimg) {
	var pagina="finpop.php?id="+id+"&idcat="+idcat+"&idimg="+idimg;
	fin=window.open(pagina,"","scrollbars=yes,width=500,height=500");
	fin.document.close();
}

function startList() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function amendPageLayout () {
	//if (document.all && document.getElementById) {
		var menuCol = Elem('top-menu-box');
		var contCol = Elem('main-content-box');
		var a = parseInt(( menuCol.clientHeight || menuCol.offsetHeight ), 10);
		var b = parseInt(( contCol.clientHeight || contCol.offsetHeight ), 10);
		var c = 180;
		var x = a - b - c;
		/*alert ('a: '+a+';\n'+'b: '+b+';\n'+'x: '+x+';\n'+'height: '+(b + x + 5)+'px\n'+'formula: (' + b + '+' + x + '+' + '5)'+'px');*/
		if (x > 0)
			contCol.style.height = (b + x + 5)+'px';
	//}
}

function startUp () {
	startList();
	amendPageLayout ();
}
