/*
 * HTML editing in form
 */
function formatStr(v) {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    document.selection.createRange().text = '<' + v + '>' + str + '</' + v + '>';
}
function insertLink() {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var my_link = prompt('Enter URL:', 'http://');
    if (my_link != null)
        document.selection.createRange().text = '<a href="' + my_link + '">' + str + '</a>';
}

/*
 * Dreamweaver function
 */
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/*
** Rintracciare la posizione degli oggetti in base al nome.
*/
function findPosX(obj) {
	var curleft = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

/*
 * Apre una nuova finestra
 */
function openWindow(theURL,winName,features) {
  w = window.open(theURL,winName,features);
  w.focus();
  return false;
}

// Apre il popup delle news
function openCreditsPopup(force)
{
	openWindow('/popup_credits.asp','creditsPopup','scrollbars=yes,resizable=yes,,width=350,height=350');
}


////////////////////////////
////// Gestione popup //////
////////////////////////////

// Apre una finestra dedicata appositamente ai popup di immagini.
var imagePopup='';
function openImagePopup(theURL) {
//	if (imagePopup.location && !imagePopup.closed) {
//		imagePopup.location.href = theURL; 
//	} else {
  		imagePopup=window.open(theURL,'imagePopup','resizable=yes,width=700,height=600,toolbar=no,location=no');
//	}
	imagePopup.focus(); 
}

// Original:  Alan Chu
// Web Site:  http://homepage.hkpeoples.net
// Modified by: sistrall
function fitWindowSize(imgName) {
	if ((navigator.appName == "Netscape") ? 1 : 0) {
		window.innerWidth = document.layers[0].document.images[imgName].width;
		window.innerHeight = document.layers[0].document.images[imgName].height + altezzaFondoPagina;
	}
	if ((navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0) {
		window.resizeTo(500, 500);
		width = 500 - (document.body.clientWidth -  document.images[imgName].width);
		height = 500 - (document.body.clientHeight -  document.images[imgName].height) + altezzaFondoPagina;
		window.resizeTo(width, height);
		//alert(width + ' ' + height);
	}
}

function setImagePopupSize() {
	var vOffset = 175-93;
	var hOffset = 30-4;
	
	if (self.innerWidth) {
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
		newWidth = document.images["immagine"].width + hOffset;
		newHeight = document.images["immagine"].height + vOffset;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
		newWidth = document.images["immagine"].width + hOffset;
		newHeight = document.images["immagine"].height + vOffset;
	}
	else if (document.body) {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
		newWidth = document.images["immagine"].width + hOffset;
		newHeight = document.images["immagine"].height + vOffset;
	}
	else return;

	if (document.layers) {
		tmp1 = parent.outerWidth - parent.innerWidth;
		tmp2 = parent.outerHeight - parent.innerHeight;
		newWidth -= tmp1;
		newHeight -= tmp2;
	}
	parent.window.resizeTo(newWidth,newHeight);
	//parent.window.moveTo(self.screen.width/4,self.screen.height/4);
	parent.window.focus();
}



