function alreadyOpen(nome) {
	var Match = document.cookie.match( /popup=([^;]+)/ )
	if (Match) {
		var popupNames = Match[1].split(",")
		for (var i=0; i<popupNames.length; i++) {
			if (popupNames[i] == nome) return true
		}
		document.cookie = "popup=" + Match[1] + "," + nome + "; PATH=/"
	} else {
		document.cookie = "popup=" + nome + "; PATH=/"
	}
	return false
}


function getParam(kind, width, height) {
	var param
	switch (kind) {
		case 'niente':
			param = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
			break;
		case 'compl':
			param = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes';
			break;
		case 'scroll':
			param = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
			break;
		default:
			param = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes';
			break; 
	}
	param += (width  ? ',width=' +width  : '')
	param += (height ? ',height='+height : '')
	return param
}


function apriUrlNelSito(contentFrame, topFrame) {
	document.location = contentFrame ;
	if (topFrame != '')	{
		top.sopra.location = topFrame ;
	}
}


function apriSoloPopUp(url, nome, kind, width, height, checkNotReOpen) {
	if (checkNotReOpen || !alreadyOpen(nome)) {
		var param = getParam(kind, width, height);
		if (window.focus) window.open(url, (nome ? nome : 'BmwNewWindow'), param).focus()
		else window.open(url, (nome ? nome : 'BmwNewWindow'), param)
	}
}


function apriPopUp_e_UrlNelSito(url, nome, kind, width, height, contentFrame, topFrame) {
	var param = getParam(kind, width, height);
	document.location = contentFrame ;
	if (topFrame != '') {
		top.sopra.location = topFrame ;
	}
	window.open(url, (nome ? nome : 'BmwNewWindow'), param).focus();
}


function newIndex(indexPage) {
	top.location = indexPage
}

