/*
	common.js
	ultimo aggiornamento 03/05/10
*/


// Window opener functions  v1.0.6
// documentation: http://www.dithered.com/javascript/window/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


/*******************************************************************************
   Popup Window openers
*******************************************************************************/

var winReference = null;



//////////////////////////////////////////////////////////////////////////////////////////
// OpenCenteredWindow									//
// apre una finestra nel centro dello schermo						//
//////////////////////////////////////////////////////////////////////////////////////////
/*function OpenCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {

	var x, y = 0;
	if (screen) {
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
	}
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = OpenPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;

} // OpenCenteredWindow
*/
function OpenCenteredWindow(url, name, width, height) {

	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	winParms += ",toolbar=no,status=no,scrollbars=yes,menubar=no,resizable=no,location=no,directories=no";
	var win = window.open(url, name, winParms);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;

} // OpenCenteredWindow



//////////////////////////////////////////////////////////////////////////////////////////
// OpenPositionedWindow									//
// open a window at a given position on the screen					//
//////////////////////////////////////////////////////////////////////////////////////////
function OpenPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {

	// ie 4.5 and 5.0 mac - windows are 2 pixels too short;
	// if a statusbar is used, the window will be an additional 15 pixels short
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 ||
		agent.indexOf("msie 5.0") != -1) ) {
		height += (status) ? 17 : 2;
	}
	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' +
		x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') +
		((moreProperties) ? ',' + moreProperties : '');
	var reference = OpenWindow(url, name, properties, openerName);
	return reference;

} // OpenPositionedWindow



//////////////////////////////////////////////////////////////////////////////////////////
// OpenWindow										//
// Core utility function that actually creates the window and gives focus to it		//
//////////////////////////////////////////////////////////////////////////////////////////
function OpenWindow(url, name, properties, openerName) {

	// ie4.x pc can't give focus to windows containing documents from a different domain
	// in this case, initially load a local interstisial page to allow focussing before loading final url
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 &&
			agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);
		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
	}
	// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	if (openerName) self.name = openerName;
	return winReference;

} // OpenWindow



//////////////////////////////////////////////////////////////////////////////////////////
// PrintPage()										//
// stampa la pagina									//
//////////////////////////////////////////////////////////////////////////////////////////
function PrintPage() {

	window.print();
	return true;

} // PrintPage



//////////////////////////////////////////////////////////////////////////////////////////
// SubmitReload()									//
// per fare il reload della pagina							//
//////////////////////////////////////////////////////////////////////////////////////////
function SubmitReload(thisform) {

	thisform.submit();
	return true;

} // SubmitReload



//////////////////////////////////////////////////////////////////////////////////////////
// SubmitReload2()									//
// come SubmitReload ma con settaggio variabile myreload				//
// myreload deve essere una variabile hidden						//
//////////////////////////////////////////////////////////////////////////////////////////
function SubmitReload2(thisform) {

	thisform.myreload.value = 1;
	thisform.submit();
	return true;

} // SubmitReload2



//////////////////////////////////////////////////////////////////////////////////////////
// SubmitNewWindow()									//
// fa il submit del form e apre una nuova finestra per visualizzare il risultato	//
// n.b: nel form invece del bottone submit è necessario scrivere una cosa del genere:	//
// form action="...." method="..." name="stampa" target="newpage">			//
// type="button" value="invia" 								//
// onClick="SubmitNewWindows(document.forms.ml,'stampa', 450,180);"			//
//////////////////////////////////////////////////////////////////////////////////////////
function SubmitNewWindow(f, name, width, height) {

	w = OpenCenteredWindow(f.action, name, width, height)
	f.submit();

} // SubmitNewWindow



//////////////////////////////////////////////////////////////////////////////////////////
// TextWrite										//
// scrive il testo nell'elemID								//
//////////////////////////////////////////////////////////////////////////////////////////
function TextWrite(elemID, txt) {

	document.getElementById(elemID).innerHTML=txt;

} // TextWrite



//////////////////////////////////////////////////////////////////////////////////////////
// TextClear										//
// cancella il testo nell'elemID							//
//////////////////////////////////////////////////////////////////////////////////////////
function TextClear(elemID) {

	document.getElementById(elemID).innerHTML="&nbsp;";

} // TextClear
