﻿
//===========
// PATCH LINK
//===========
window.onload = function OnLoad() { PatchLink(); Init(); }
function Init(){}
function PatchLink()
{
	for (var i=0; i<document.links.length; i++)
	{
		// Attributo target specificato in className per compatibilità XHTML
        if (document.links[i].className.search("target_blank") >= 0)
			document.links[i].target="_blank";
		
		// Link verso documenti e/o pubblicazioni editati da backoffice e link speciali (immagine, fotogallery, stampa)
        if (document.links[i].className.search("target_open") >= 0)
        	document.links[i].href = 'javascript:OpenLink("'+ document.links[i].href +'")';
	}	
}


//===========
// OPEN POPUP
//===========
function OpenLink(arg)
{
	var name = "_blank";
	try	{ queryString = arg.split("?")[1] }	catch(e) { queryString = "_blank" }
		
	// Default features
	var features = "width=700, height=500, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";

	// Specific features
	if (arg.search("OpenGallery.asp") >= 0)
	{
		features = "width=700, height=500, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";
	}
	else if (arg.search("OpenImage.asp") >= 0)
	{
		features = "width=700, height=500, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";
	}
	else if (arg.search("OpenObject.asp") >= 0)
	{
		// link a oggetti aperti nella stessa pagina 
		document.location = arg;
		return;
	}
	else if (arg.search("OpenDoc.asp") >= 0)
	{
		features = "width=800, height=600, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";		
	}
	else
	{
		// Redirezione con arg inalterato, tipicamente utilizzata per la versione stampabile
		features = "width=800, height=600, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";		
	}

	// Le aperture in popup sono segnalate con parametro sulla query
	window.open(arg +"&popup=1", name, features).focus();
}
