// PARAMETRI CONFIGURABILI ///////////////////////////////////////////////////////////////////////////////////

immagine_titlebar = ""; // solo per le nuove chromeless compatibili //chromeless/titlebar2.gif
						// copre il titolo html
altezza_titlebar = 20;
titolo_generico = ""; // specificare solo nel caso le finestre abbiano tutte lo stesso nome
font_titlebar = "Arial";
size_font_titlebar = 10; 
colore_titolo = "#D1D0D2";
barra_scorrimento = "no"; // yes|no|auto
autocentramento = "yes";
colore_bordo = "#D1D0D2"; // colore del bordo e della titlebar
spessore_bordo = 1;
label_minimize = "Minimize";
label_close = "Close";

path_chromeless = "/img/";

// RICOSTRUZIONE NOME URL
stringa1 = "";
stringa2 = "";
// ESEMPIO u = 'popup/' + u + '.php';   u = stringa1 + u + stringa2

//FORZARE L'USO DI UNA VERSIONE DELLE CHROMELESS
flag_versione = "auto"; // new|old|auto
//new: forza l'uso della nuova chromeless indipendentemente dal browser
//old: forza l'uso della vecchia chromeless indipendentemente dal browser
//auto: esegue l'autodetection del browser

// IMMAGINI CHROMELESS <5.5
img_minimize = path_chromeless + "min_up.gif";
img_minimize_over = path_chromeless + "min_ovr.gif";
img_maximize = path_chromeless + "max_up.gif";
img_maximize_over = path_chromeless + "max_ovr.gif";
img_close = path_chromeless + "close_up.gif";
img_close_over = path_chromeless + "close_ovr.gif";
img_restore = path_chromeless + "res_up.gif";
img_restore_over = path_chromeless + "res_ovr.gif";
img_clock = path_chromeless + "clock.gif";

// IMMAGINI CHROMELESS >= 5.5
img_minimize = path_chromeless + "min_up.gif";
img_close = path_chromeless + "close_up.gif";

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//                                                            //
//           BYKLEIN CHROMELESS WINDOW OBJECT 1.0             //
//             FOR MICROSOFT IEXPLORER 5.5 & UP               //
//                                                            //
//   (c) Copyright 2002. Mariano Klein || www.byklein.com     //
//         Distributed under the terms of the GNU GPL         //
//                                                            //
//    Thanks to Gabriel Suchowolski || www.microbians.com     //
////////////////////////////////////////////////////////////////

ChromelessWindow = function ()
{
	this.URL = null;
	this.title = null;
	this.titleFont = null;
	this.titleSize = 0;
	this.titleColor = null;
	this.titlebarImage = null;
	this.titlebarHeight = 0;
	this.scrollbars = null;
	this.w = 0;
	this.h = 0;
	this.centered = null;
	this.xPos = 0;
	this.yPos = 0;
	this.borderColor = null;
	this.borderSize = 0;
	this.closeBottom = null;
	this.minimizeBottom = null;
	
	this.chromelessCompatible = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4 ? true:false;
	this.titlebarContent = null;
	this.chromelessWW = null;
	
	
}

ChromelessWindow.prototype.openChromeless = function()
{
	this.runCode();
	
}

ChromelessWindow.prototype.closeChromeless = function()
{
	this.chromelessWW.close();
}

ChromelessWindow.prototype.setURL = function(newURL)
{
	this.URL = newURL;
	if(this.chromelessWW)
	{
		this.chromelessWW.execScript("b.all.canvas.URL='"+newURL+"'");
		this.chromelessWW.execScript("showChromeless()");
	}
}

ChromelessWindow.prototype.moveTo = function()
{
	this.xPos = arguments[0];
	this.yPos = arguments[1];
	if(this.chromelessWW)
	{
		this.chromelessWW.execScript('var cx='+this.xPos+';');
		this.chromelessWW.execScript('var cy='+this.yPos+';');
		this.chromelessWW.execScript("showChromeless()");
	}
}

ChromelessWindow.prototype.resizeTo = function()
{
	this.w = arguments[0];
	this.h = arguments[1];
	this.cH = (this.h-this.titlebarHeight)-this.borderSize;
	this.cW = this.w -(this.borderSize*2);
	if(this.chromelessWW)
	{
		this.chromelessWW.execScript('var cw='+this.w+';');
		this.chromelessWW.execScript('var ch='+this.h+';');
		this.chromelessWW.execScript("b.all.canvas.style.width='"+this.cW+"'");
		this.chromelessWW.execScript("b.all.canvas.style.height='"+this.cH+"'");
		this.chromelessWW.execScript("b.all.closeBottom.style.right='"+this.borderSize+"'");
		this.chromelessWW.execScript("b.all.minimizeBottom.style.right='"+(this.borderSize+20)+"'");
		this.chromelessWW.execScript("showChromeless()");
	}
}



ChromelessWindow.prototype.runCode = function()
{
	if(this.centered=="yes")
	{
		var tempX = this.w;
		var tempY = this.h;
		this.xPos = (screen.availWidth/2)-(tempX/2);
		this.yPos = (screen.availHeight/2)-(tempY/2);
	}
	if (this.chromelessCompatible)
	{
		this.chromelessWW = window.open("about:blank","","top=5000,left=5000,width=100,height=100,scrollbars="+this.scrollbars);
	}
	else
	{
		this.chromelessWW = window.open(this.URL, "chromelessWindow", "top="+this.yPos+",left="+this.xPos+",width="+this.w+",height="+this.h+",toolbar=0,scrollbars="+this.scrollbars+",resizable=0");
	}
	this.cH = (this.h-this.titlebarHeight)-this.borderSize;
	this.cW = this.w -(this.borderSize*2);
	this.c = "<object type='text/html' border='0' style='position:absolute;z-index:2;top:"+this.titlebarHeight+"px;left:"+this.borderSize+"px;width:"+this.cW+"px;height:"+this.cH+"px;' data='"+this.URL+"' id='canvas'></object>";

	if((this.titlebarImage==undefined)||(this.titlebarImage==null)||(this.titlebarImage==""))
	{
		this.titlebarContent="";
		this.tb = false;
	}
	else
	{
		this.titlebarContent="<img id='menu' unselectable='on' src='"+this.titlebarImage+"' style='position:absolute; top:0px; left:0px;z-index:2'>";
		this.tb = true;
	}
	this.menu = "\
		<div id='Title' unselectable='on' style='font-family:Arial;font-size:11px;font-weight:regular;position:absolute;top:5px;left:"+this.borderSize+"px;width:70%;height:15px;cursor:default;font-family:"+this.titleFont+";font-size:"+this.titleSize+";color:"+this.titleColor+";z-index:3'>&nbsp;"+this.title+"</div>\
		<img alt="+label_close+" style='cursor:hand' id='closeBottom' unselectable='on' src='"+this.closeBottom+"' style='position:absolute; top:5px; right:"+(this.borderSize+4)+"px;z-index:3'>\
		"+this.titlebarContent+"\
		<img alt="+label_minimize+" style='cursor:hand' id='minimizeBottom' unselectable='on' src='"+this.minimizeBottom+"' style='position:absolute; top:5px; right:"+(this.borderSize+20)+"px;z-index:3'>\
		<div id='fondo' unselectable='on' style='position:absolute; top:0px; left:0px; width:100%; height:100%; background-color:"+this.borderColor+";z-index:1'></div>";

	if (this.chromelessCompatible)
	{
		this.chromelessWW.moveTo(300,-5000);
		this.chromelessWW.resizeTo(800,600);
		this.chromelessWW.document.writeln('<html>');
		this.chromelessWW.document.writeln('<head>');
		this.chromelessWW.document.writeln('<META HTTP-EQUIV="imagetoolbar" CONTENT="no">');
		this.chromelessWW.document.writeln('<style>');
		this.chromelessWW.document.writeln('BODY{border:0px !important;}');
		this.chromelessWW.document.writeln('</style>');
		this.chromelessWW.document.writeln('</head>');
		this.chromelessWW.document.writeln('<body>');
		this.chromelessWW.document.writeln('<script>');
		this.chromelessWW.document.writeln('var c=window.createPopup();');
		this.chromelessWW.document.writeln('var b=c.document.body;');
		this.chromelessWW.document.writeln("var ox=oy=ix=iy=0;");
		this.chromelessWW.document.writeln("var allContent =\""+this.menu+this.c+"\";");
		this.chromelessWW.document.writeln('b.innerHTML=allContent;');
		this.chromelessWW.document.writeln('var cx='+this.xPos+';');
		this.chromelessWW.document.writeln('var cy='+this.yPos+';');
		this.chromelessWW.document.writeln('var cw='+this.w+';');
		this.chromelessWW.document.writeln('var ch='+this.h+';');
		this.chromelessWW.document.writeln('function showChromeless(){');
		this.chromelessWW.document.writeln('c.show(cx,cy,cw,ch);focus()');
		this.chromelessWW.document.writeln('}');
		this.chromelessWW.document.writeln('var mm=false;');
		this.chromelessWW.document.writeln('var cmove=b.all("fondo");');
		this.chromelessWW.document.writeln('var allb=b.all("allborders");');
		this.chromelessWW.document.writeln('var cmove2=(b.all("menu"))?b.all("menu"):"";');
		this.chromelessWW.document.writeln('var ctitle=b.all("Title");');
		this.chromelessWW.document.writeln('ctitle.style.visibility=('+this.tb+')?"hidden":"visible";');
		this.chromelessWW.document.writeln('var cclose=b.all("closeBottom");');
		this.chromelessWW.document.writeln('var cminimize=b.all("minimizeBottom");');
		this.chromelessWW.document.writeln('cclose.onclick=function(){opener=self;self.close()};');
		this.chromelessWW.document.writeln('cminimize.onclick=function(){if(top.opener&&!top.opener.closed){top.opener.window.focus()};top.window.blur()};');
		this.chromelessWW.document.writeln('var ox=oy=ix=iy=0;');
		this.chromelessWW.document.writeln('var m=0;');
		this.chromelessWW.document.writeln('ctitle.onmousedown=function(){m=1};');
		this.chromelessWW.document.writeln('ctitle.onmouseup=function(){m=0};');
		this.chromelessWW.document.writeln('cmove.onmousedown=function(){m=1};');
		this.chromelessWW.document.writeln('cmove.onmouseup=function(){m=0};');
		this.chromelessWW.document.writeln('cmove2.onmousedown=function(){m=1};');
		this.chromelessWW.document.writeln('cmove2.onmouseup=function(){m=0};');
		this.chromelessWW.document.writeln('document.body.onclick=function(){ if (m) { focus();cx=ix+event.screenX-ox;cy=iy+event.screenY-oy;c.show(cx,cy,cw,ch) }else { ix=cx; iy=cy; ox=event.screenX; oy=event.screenY } };');
		this.chromelessWW.document.writeln('setInterval("document.body.click()",20);');
		this.chromelessWW.document.writeln('onfocus=function(){showChromeless();}');
		this.chromelessWW.document.writeln('</script>');
		this.chromelessWW.document.writeln('</body>');
		this.chromelessWW.document.writeln('</html>');
		this.chromelessWW.document.location.reload();
		this.chromelessWW.document.title = this.title;
		this.chromelessWW.execScript("focus();");
	}
	else
	{
		this.chromelessWW.document.title = this.title;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////


function openIT3(u,title,W,H,X,Y,n,b,x,m,r) {
	
	// RICOSTRUZIONE NOME URL
	u = stringa1 + u + stringa2;


	// DETECT BROWSER ////////////////////////////////////////////////////
	
	this.chromelessNewCompatible= false;
	agent= navigator.userAgent;
	if (agent.indexOf("Galeon/") != -1)
	  this.chromelessNewCompatible= true;
	else if (agent.indexOf("MSIE") != -1)
	{
	  ver= parseFloat(agent.substr(agent.indexOf("MSIE")+5));
	  if (ver >= 5.5)
  	  this.chromelessNewCompatible= true;
	}
	
	// RILEVA L'EVENTUALE FORZATURA PER CARICARE UNA VERSIONE PRECISA DELLA CHROMELESS
	if (flag_versione != "auto")
	{
		if (flag_versione == "new") {this.chromelessNewCompatible = true;}
		else {this.chromelessNewCompatible = false;}
	}
	
	/////////////////////////////////////////////////////////////////////
	
	if (this.chromelessNewCompatible)
	{
		var myChromeless = new ChromelessWindow();
		/////////////////////////////////////////////
		//These are the attributes you can customize//
		/////////////////////////////////////////////
		myChromeless.URL = u;
		myChromeless.title = title;
		myChromeless.titlebarImage = immagine_titlebar;
		myChromeless.titlebarHeight = altezza_titlebar;
		myChromeless.titleFont = font_titlebar;
		myChromeless.titleSize = size_font_titlebar;
		myChromeless.titleColor = colore_titolo;
		myChromeless.scrollbars = barra_scorrimento; 
		myChromeless.w = W + 4 + spessore_bordo * 2; //width
		myChromeless.h = H + 4 + altezza_titlebar + spessore_bordo; //height
		myChromeless.centered = autocentramento;	
		myChromeless.xPos = X;
		myChromeless.yPos = Y;
		myChromeless.borderColor = colore_bordo;
		myChromeless.borderSize = spessore_bordo;
		myChromeless.minimizeBottom = img_minimize;
		myChromeless.closeBottom = img_close;
		/////////////////////////////////////////////
	
		if ((X!=null) && (Y!=null)) {myChromeless.centered = "no";}
		
		if (title=="") {myChromeless.title = titolo_generico;}
		
		myChromeless.openChromeless();
	}
	else
	{
	var n   = 'home';	
	var cU  = img_close;
	var cO  = img_close_over;
	var cL  = img_clock;
	var mU  = img_minimize;
	var mO  = img_minimize_over;
	var xU  = img_maximize;
	var xO  = img_maximize_over;
	var rU  = img_restore;
	var rO  = img_restore_over;
	//var tH  ='<font face="' + font_titlebar + '" size=1 color=' + colore_titolo + '>&nbsp;'+ title +'</font>' //originale
	var tH  = '<div unselectable="on" style="font-weight:regular;font-family:'+font_titlebar+';font-size:'+size_font_titlebar+';color:'+colore_titolo+';">&nbsp;'+title+'</div>';
	var tW  = title;
	var wB  = colore_bordo;
	var wBs = colore_bordo;
	var wBG = colore_bordo;
	var wBGs= colore_bordo;
	var wNS ='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0';
	var fSO ='scrolling=' + barra_scorrimento;
	var brd =b||spessore_bordo;
	var max =x||false;
	var min =m||false;
	var res =r||true;
	var tsz =altezza_titlebar;
	return chromeless(u,n,W,H,X,Y,cU,cO,cL,mU,mO,xU,xO,rU,rO,tH,tW,wB,wBs,wBG,wBGs,wNS,fSO,brd,max,min,res,tsz)
	
	}

}

