/* @jFazio-1.0.0_2.js */

/*************************************************************************
                     ___                               ()         ______
//////////////      //_\\           ////////////////             ////\\\\
//                 //   \\                       //    ||      //        \\
//                //     \\                    //      ||     //          \\
//               //       \\                 //        ||    //            \\
///////////     ///////////\\              //          ||   ((              ))
//             //           \\           //            ||    \\            //
//            //             \\        //              ||     \\          //
//           //               \\     //                ||      \\        //
//__________//_________________\\___////////////////___||________\\\\////

****************************************************************************/
/**
 * jFazio libreria di script v1.0.0_2.
 *
 * Questa libreria contiene classi e oggetti con cui
 * creare e gestire, in modo semplice e intuitivo,
 * testi, finestre, sfondi, forme e colori.
 * Si accede agli oggetti e classi e ai loro metodi nel seguente modo:
 * <html>
 * <head>
 * <script type="text/javascript src="jFazio/jFazio-1.0.0_1.js"></script>
 * <script type="text/javascript>
 * //voglio creare una popup con icona di chiusura
 * //la popup deve visualizzare una pagina html
 *
 * //creo un rettangolo grazie a 'jFazio.getGraphics().drawRect'
 * var popup = jFazio.getGraphics().drawRect("MiaPopUp", 300, 300, true);
 * //setto qualcosa
 *	  popup.setPage("http://www.beatogiacomo.it");
 *	  popup.setBorder("10px dotted yellow");
 *	  popup.setVisible(true);
 *	  popup.setPosition(50, 50);
 * //aggiungo un evento onclick che farà scomparire la popup
 *	  jFazio.getJFEvent().addEventListener(popup, "click", function() {popup.setVisible(false);});
 * //definisco una funzione start() che sposterà MiaPopUp in un punto dello schermo
 * //e poi dopo 1 secondo di attesa tornerà indietro
 *	  function start() {jFazio.getGraphics().moveToBack("MiaPopUp", 20, 20, 660, 400, 50, 20, 0, 1000, true)}
 * </script>
 * </head>
 * <body>
 * <button onclick="start()">Premi qui!</button>
 * </body>
 * </html>
 *
 * @autor Fazio Michele
 * @version 1.0.0_2
 *
 * Date: Sat Feb 13 22:35:13 2011
 */

////////////////////////////////////////// Inizio Configurazione //////////////////////////////////////////
/* Il tuo dominio */
var domain = "http://www.beatogiacomo.it";
/* Cartelle relative al dominio che contengono il pacchetto jFazio */
var jPackage = "/tomcat/jFazio/";
////////////////////////////////////////// Fine Configurazione ////////////////////////////////////////////

(function (FM) {
    var n = FM.navigator, isIE = (n.userAgent.indexOf("MSIE")!=-1),
    w = FM, d = FM.document, h = FM.history, l = FM.location, s = FM.screen;
    function ck(as) {
        var a = as.length;
        var e = as.callee.length;
        if(a != e) {
	  throw new Error("Numero di argomenti errato: attesi: " + e + "; passati: " + a);
        }
    }
    function isS(s) {
        return typeof s === "string";
    }
    function isB(b) {
        return typeof b === "boolean";
    }
    function isN(n) {
        return typeof n === "number";
    }
    function isF(f) {
        return typeof f === "function";
    }
    function ex(m) {
        throw new Error(m);
    }
    var e1 = "Valore del parametro errato!";
    var e2 = "Uno o più valori dei parametri sono errati!";
    var e3 = " non esiste!";
    function JF() {}
    /**
     * Restituisce object
     * @param object
     */
    JF.prototype.get = function(object) {
        if(object && isS(object)) {
	  if(object.indexOf("#", 0)) {
	      this.o = (isIE)? d.all[object.substring(1)]:d.getElementById(object.substring(1));
	  }
        } else {
	  this.o = object;
        }
        return this.o;
    }

    /**
     * Esegue 'code' dopo che la pagina è stata caricata.
     */
    JF.prototype.onloadReady = function(code) {
        if(isF(code)) {
	  FM.onload = code;
        } else if(isS(code)){
	  function feval() {
	      eval(code);
	  }
	  FM.onload = feval;
        }
    }
    //////////////////////////////////////////////////////////////////////// Printer ///////////////////////////////////////////////////////////
    /**
     * Printer
     */
    var Printer = {}
    /**
     * Stampa a video.
     * @param string Un qualsiasi valore da stampare
     */
    Printer.print = function(string) {
        d.write(string);
    }
    /**
     * Stampa a video.
     * @param string Un qualsiasi valore da stampare
     */
    Printer.write = function(string) {
        d.write(string);
    }
    /**
     * Restituisce la classe Printer.
     * @return Printer
     */
    JF.prototype.getPrinter = function() {
        return Printer;
    }
    ////////////////////////////////////////////////////////// Calendar ////////////////////////////////////////////////////////////
    /**
     * Il Calendario.
     */
    function Calendar() {
        this.date = new Date();
    }
    /**
     * Restituisce l'anno corrente.
     */
    Calendar.prototype.getYear = function() {
        return this.date.getFullYear()
    }
    /**
     * Restituisce il mese corrente.
     */
    Calendar.prototype.getMonth = function() {
        return this.date.getMonth()
    }
    /**
     * Restituisce il giorno corrente.
     */
    Calendar.prototype.getDay = function() {
        return this.date.getDate()
    }
    /**
     * Restituisce una istanza dell'oggetto Date.
     */
    Calendar.prototype.getInstance = function() {
        return this.date
    }
    /**
     * Restituisce una istanza dell'oggetto Calendar.
     * @return Una istanza di Calendar
     */
    JF.prototype.getCalendar = function() {
        return new Calendar();
    }
    ////////////////////////////////////////////////////////////////////// Event /////////////////////////////////////////////////////////////
    /**
     * FazioEvent
     */
    var JFEvent = {}

    /**
     *  Aggiunge un listener all'elemento.
     *  @param elementName Un elemento del documento
     *  @param eventType Uno di: 'click', 'mouseover', ecc.
     *  @param handler Azione nella forma: 'function() { codice }'
     */
    JFEvent.addEventListener = function(elementName, eventType, handler) {
        ck(arguments);
        if(isS(elementName)&&isS(eventType)&&isF(handler)) {
	  var el = Graphics.getElement(elementName);
	  if(el) {
	      if(isIE) {
		function H() {
		    event.returnValue = false;
		    handler();
		}
		eventType = "on" + eventType;
		el.attachEvent(eventType, H);
	      } else {
		function h(e) {
		    e.preventDefault();
		    handler();
		}
		el.addEventListener(eventType, h, false);
	      }
	  } else {
	      ex("Non si può aggiungere un listener ad un elemento che non esiste!");
	  }
        } else {
	  ex(e2);
        }
    }

    /**
     * Restituisce la classe JFEvent.
     * @return JFEvent
     */
    JF.prototype.getJFEvent = function() {
        return JFEvent;
    }
    ///////////////////////////////////////////////////////////////////// Environment ////////////////////////////////////////////////////////

    /**
     * Rappresenta l'ambiente di esecuzione
     */
    var Environment = {
        browser : n.userAgent
    }

    /**
     * Crea e restituisce un elemento sfondo dello schermo
     * @param color Un colore nella forma: 'red', 'black', oppure '#000000', '#ff0000' ecc
     * @param opacity Un valore da 1 a 10
     * @return l'elemento schermo
     */
    Environment.createScreenBackground = function(color, opacity) {
        ck(arguments);
        var lightScreen = null;
        if(isS(color)&&isN(opacity)) {
	  Printer.print("<div id='lightScreen' style='position:absolute; top:0px; left:0px; width:100%; height:100%; background-color: #000000; z-index:889; visibility:hidden'></div>");
	  lightScreen = (d.all) ? d.all["lightScreen"] : d.getElementById("lightScreen");
	  lightScreen.style.backgroundColor = color;
	  if(isIE) {
	      lightScreen.style.filter = "alpha(opacity = " + (opacity * 10) + ")";
	  } else {
	      lightScreen.style.opacity = (opacity / 10);
	  }
        } else {
	  ex(e2);
        }
        /*
    lightScreen.onclick = function() {
        lightScreen.style.visibility = 'hidden';
    }
    */
        return lightScreen;
    }
    /**
     * Restituisce le dimensioni della pagina.
     * @return return un array con page width, height e window width, height
     */
    Environment.getPageSize = function() {
        var xScroll, yScroll;
        if (w.innerHeight && w.scrollMaxY) {
	  xScroll = w.innerWidth + w.scrollMaxX;
	  yScroll = w.innerHeight + w.scrollMaxY;
        } else if (d.body.scrollHeight > d.body.offsetHeight){ // all but Explorer Mac
	  xScroll = d.body.scrollWidth;
	  yScroll = d.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	  xScroll = d.body.offsetWidth;
	  yScroll = d.body.offsetHeight;
        }
        var windowWidth, windowHeight, pageHeight, pageWidth;
        if (w.innerHeight) {	// all except Explorer
	  if(d.documentElement.clientWidth){
	      windowWidth = d.documentElement.clientWidth;
	  } else {
	      windowWidth = w.innerWidth;
	  }
	  windowHeight = w.innerHeight;
        }else if (d.documentElement && d.documentElement.clientHeight) { // Explorer 6 Strict Mode
	  windowWidth = d.documentElement.clientWidth;
	  windowHeight = d.documentElement.clientHeight;
        }else if (d.body) { // other Explorers
	  windowWidth = d.body.clientWidth;
	  windowHeight = d.body.clientHeight;
        }
        if(yScroll < windowHeight){
	  pageHeight = windowHeight;
        } else {
	  pageHeight = yScroll;
        }
        if(xScroll < windowWidth){
	  pageWidth = xScroll;
        } else {
	  pageWidth = windowWidth;
        }
        return new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    }
    /**
     * Restituisce lo scorrimento x e y della pagina.
     * @return return un array con x,y page scroll.
     */
    Environment.getPageScroll = function() {
        var xScroll, yScroll;
        if (w.pageYOffset) {
	  yScroll = w.pageYOffset;
	  xScroll = w.pageXOffset;
        } else if (d.documentElement && d.documentElement.scrollTop) {// Explorer 6 Strict
	  yScroll = d.documentElement.scrollTop;
	  xScroll = d.documentElement.scrollLeft;
        }
        else if (d.body) {// all other Explorers
	  yScroll = d.body.scrollTop;
	  xScroll = d.body.scrollLeft;
        }
        return new Array(xScroll,yScroll);
    }
    /**
     * Nasconde lo Sfondo dello schermo opzionale.
     */
    Environment.hideLightScreen = function() {
        var ls = Graphics.getElement("lightScreen");
        if(ls != null) {
	  ls.style.visibility = 'hidden';
        }
        else {
	  ex("L'oggetto LightScreen non è stato ancora creato !");
        }
    }
    /**
     * Carica una immagine nella cache del browser.
     * @param url Il percorso dell'immagine
     * @return Una stringa che rappresenta il percorso dell'immagine o false se l'immagine non viene caricata
     */
    Environment.loadImage = function (url) {
        ck(arguments);
        if(isS(url)) {
	  var img = new Image();
	  img.src = url;
	  return img.src;
        } else {
	  return false;
        }
    }
    /**
     * Apre una finestra del browser.
     * @param url Url da caricare
     * @param name Il nome della finestra
     * @param features Caratteristiche della finestra
     * @param x Posizione sullo schermo x
     * @param y Posizione sullo schermo y
     */
    Environment.openWindow = function(url, name, features, x, y) {
        ck(arguments);
        if(isS(url)&&isS(name)&&isS(features)&&isN(x)&&isN(y)){
	  var win = w.open(url, name, features);
	  win.moveTo(x, y);
        } else {
	  ex(e2);
        }
    }
    /**
     * Visualizza lo Sfondo dello schermo opzionale.
     */
    Environment.showLightScreen = function() {
        var ls = Graphics.getElement("lightScreen");
        if(ls != null) {
	  ls.style.visibility = 'visible';
	  var pagesize = Environment.getPageSize();
	  ls.style.width = pagesize[0] + "px";
	  //alert(pagesize[0]);
	  ls.style.height = pagesize[1] + "px";
        //alert(pagesize[1]);
        }
        else {
	  ex("L'oggetto LightScreen non è stato ancora creato!");
        }
    }
    /**
     * Visualizza una finestra con una messaggio.
     * @param message Il messaggio da visualizzare
     */
    Environment.showMessageDialog = function(message) {
        ck(arguments);
        if(isS(message)) {
	  w.alert(message);
        }
        else {
	  ex(e1);
        }
    }
    /**
     * Visualizza una finestra con una messaggio da confermare.
     * @param message Il messaggio da confemare
     * @param action L'azione o codice da intraprendere se il messaggio è confermato.
     *        action deve essere una stringa di codice es: <code>jFazio.getGraphics().drawString()</code>
     */
    Environment.showConfirmDialog = function(message, action) {
        ck(arguments);
        if(isS(message)) {
	  var x = w.confirm(message);
	  if(x) {
	      eval(action);
	  }
        }
        else {
	  ex(e1);
        }
    }
    /**
     * Restituisce la classe Environment.
     * @return Environment
     */
    JF.prototype.getEnvironment = function() {
        return Environment;
    }
    ////////////////////////////////////////////////////////// Graphics ////////////////////////////////////////////////////////////
    /**
     * Rappresenta il contesto grafico
     */
    var Graphics = {}
    /**
     * Imposta la posizione al centro dello schermo.
     * @param elementName Centra la posizione dell'elemento al centro dello schermo
     */
    Graphics.centerOnScreen = function(elementName) {
        ck(arguments);
        if(isS(elementName)) {
	  var el = Graphics.getElement(elementName);
	  if(el) {
	      el.style.left = ((s.availWidth - this.w) / 2) + "px";
	      el.style.rectStyle.top = ((s.availHeight - this.h) / 3) + "px";
	  } else {
	      ex(elementName + e3)
	  }
        }
        else {
	  ex(e1);
        }
    }
    /**
     * Disegna e restituisce un rettangolo.
     * @param id Il nome univoco del rettangolo
     * @param w La larghezza
     * @param h L'altezza
     * @param closeIcon Un booleano ad indicare se si vuole visualizare o no una icona di chiusura rettengolo
     * @return Il rettengolo disegnato
     */
    Graphics.drawRect = function(id, w, h, closeIcon) {
        ck(arguments);
        if(isS(id)&&isN(w)&&isN(h)&&isB(closeIcon)){
	  return new Rectangle(id, w, h, closeIcon);
        } else {
	  return ex(e2);
        }
    }
    /**
     * Stampa a video e restituisce l'elemento.
     * @param id Il nome univoco del testo da stampare
     * @param string Un qualsiasi valore da stampare
     * @param x coordinata x
     * @param y coordinata y
     */
    Graphics.drawString = function(id, string, x, y) {
        ck(arguments);
        if(isS(id)&&isS(string)&&isN(x)&&isN(y)){
	  return new FString(id, string, x, y);
        }else {
	  return ex(e2);
        }
    }
    /**
     * Restituisce l'elemento name se esiste.
     * @return name se esiste altrimenti null
     */
    Graphics.getElement = function(name) {
        return (isS(name))?((d.all) ? d.all[name] : d.getElementById(name)):ex(e1);
    }
    /**
             * Rende nascosto l'elemento.
             * @param elementName il nome dell'elemento
             */
    Graphics.hide = function(elementName) {
        var el = (d.all) ? d.all[elementName] : d.getElementById(elementName);
        if(el) {
	  el.style.visibility = "hidden";
        }
        else {
	  ex(elementName + e3)
        }
    }
    /**
             * Rende nascosto un elemento in modo graduale.
             * L'elemento deve essere già stato creato e visualizzato.
             *
             * @param elementName un elemento di document
             * @param rate un intero in millisecondi che indica la velocità
             *        per nascondere l'elemento
             */
    Graphics.hideGradual = function(elementName, rate) {
        ck(arguments);
        if(isS(elementName)&&isN(rate)) {
	  var obj = Graphics.getElement(elementName);
	  if(obj) {
	      var count = 100;
	      function ocy() {
		if(isIE) {
		    obj.style.filter = "alpha(opacity=" + count + ")";
		} else {
		    obj.style.opacity = count/100;
		}
		if(count > 0) {
		    w.timeoutH = w.setTimeout(ocy, rate);
		}else {
		    w.clearTimeout(w.timeoutH);
		    obj.style.visibility = "hidden";
		}
		count--;
	      }
	      //this.timeout = window.setTimeout(ocy, 200);
	      ocy();
	  }else {
	      ex(elementName + e3)
	  }
        } else {
	  ex(e2)
        }
    }
    /**
             * Muove l'elemento nella posizione specificata e dopo hideDelay
             * millisecondi lo nasconde.
             * @param elementName un elemento di document
             * @param pointX la coordinata x da raggiungere
             * @param pointY la coordinata y da raggiungere
             * @param speed la velocità di spostamento in millisecondi
             * @param progress un intero ad indicare di quanti pixel l'elemento
             *        deve spostarsi ogni volta che viene chiamata speed.
             *        La divisione ricorsiva tra posizione X e Y iniziale dell'elemento e
             *        progress deve restituire 0.
             * @param hideDelay un intero in millisecondi per posticipare la dissolvenza nel momento
             *        in cui l'elemento raggiunge la posizione desiderata.
             */
    Graphics.moveAndHide = function(elementName, pointX, pointY, speed, progress, hideDelay) {
        ck(arguments);
        if(isS(elementName)&&isN(pointX)&&isN(pointY)&&isN(speed)&&isN(progress)&&isN(hideDelay)) {
	  var obj = Graphics.getElement(elementName);
	  if(obj) {
	      var progressX = progress;
	      var progressY = progress;
	      var currentX = parseInt(obj.style.left);
	      var currentY = parseInt(obj.style.top);
	      w.timeout = null;
	      w.target = false;
	      var xTarget = false;
	      var yTarget = false;
	      obj.onmouseover = function() {
		progressX = progressY = 0;
	      }
	      obj.onmouseout = function() {
		progressX = progressY = progress;
	      }
	      function h() {
		Graphics.hideGradual(obj, 50);
	      }
	      function m() {
		if(currentX > pointX) {
		    currentX -= progressX;
		} else {
		    currentX += progressX;
		}
		if(currentY > pointY) {
		    currentY -= progressY;
		} else {
		    currentY += progressY;
		}

		obj.style.top = currentY + "px";
		obj.style.left = currentX + "px";

		if(parseInt(obj.style.left) == pointX) {
		    progressX = 0;
		    xTarget = true;
		}
		if(parseInt(obj.style.top) == pointY) {
		    progressY = 0;
		    yTarget = true;
		}
		if(xTarget && yTarget) {
		    //obj.target = true;
		    w.setTimeout(h, hideDelay);
		    w.clearTimeout(w.timeoutM);
		}
		else {
		    w.timeoutM = w.setTimeout(m, speed);
		}
	      }
	      m();
	  }else {
	      ex(elementName + e3)
	  }
        } else {
	  ex(e2)
        }
    }
    /**
             * Muove l'elemento nella posizione specificata.
             * @param elementName un elemento di document
             * @param pointX la coordinata x da raggiungere
             * @param pointY la coordinata y da raggiungere
             * @param speed la velocità di spostamento in millisecondi
             * @param progress un intero ad indicare di quanti pixel l'elemento
             *        deve spostarsi ogni volta che viene chiamata speed.
             *        La divisione ricorsiva tra posizione X e Y iniziale dell'elemento e
             *        progress deve restituire 0.
             */
    Graphics.move = function(elementName, pointX, pointY, speed, progress) {
        ck(arguments);
        if(isS(elementName)&&isN(pointX)&&isN(pointY)&&isN(speed)&&isN(progress)) {
	  var obj = Graphics.getElement(elementName);
	  if(obj) {
	      var progressX = progress;
	      var progressY = progress;
	      var currentX = parseInt(obj.style.left);
	      var currentY = parseInt(obj.style.top);
	      w.timeout = null;
	      var xTarget = false;
	      var yTarget = false;
	      obj.onmouseover = function() {
		progressX = progressY = 0;
	      }
	      obj.onmouseout = function() {
		progressX = progressY = progress;
	      }
	      function m() {
		if(currentX > pointX) {
		    currentX -= progressX;
		} else {
		    currentX += progressX;
		}
		if(currentY > pointY) {
		    currentY -= progressY;
		} else {
		    currentY += progressY;
		}

		obj.style.top = currentY + "px";
		obj.style.left = currentX + "px";

		if(parseInt(obj.style.left) == pointX) {
		    progressX = 0;
		    xTarget = true;
		}
		if(parseInt(obj.style.top) == pointY) {
		    progressY = 0;
		    yTarget = true;
		}
		if(xTarget && yTarget) {
		    w.clearTimeout(w.timeoutM);
		}
		else {
		    w.timeoutM = w.setTimeout(m, speed);
		}
	      }
	      m();
	  }else {
	      ex(elementName + e3)
	  }
        } else {
	  ex(e2)
        }
    }
    /**
             * Muove l'elemento nella posizione specificata e dopo delay
             * millisecondi lo fa ritornare indietro alla posizione iniziale.
             * @param elementName un elemento di document
             * @param startX la coordinata x di partenza
             * @param startY la coordinata y di partenza
             * @param endX la coordinata x da raggiungere
             * @param endY la coordinata y da raggiungere
             * @param speed la velocità di spostamento in millisecondi
             * @param progress un intero ad indicare di quanti pixel l'elemento
             *        deve spostarsi ogni volta che viene chiamata speed.
             *        La divisione ricorsiva tra posizione X e Y iniziale dell'elemento e
             *        progress deve restituire 0.
             * @param startDelay ritarto animazione
             * @param delay un intero in millisecondi per posticipare il ritorno indietro nel momento
             *        in cui l'elemento raggiunge la posizione desiderata.
             * @param hideToTarget true se si vuole che l'elemento scompaia alla fine del movimento, false altrimenti
             */
    Graphics.moveToBack = function(elementName, startX, startY, endX, endY, speed, progress, startDelay, delay, hideToTarget) {
        ck(arguments);
        if(isS(elementName)&&isN(startX)&&isN(startY)&&isN(endX)&&isN(endY)&&isN(speed)&&isN(progress)&&isN(startDelay)&&isN(delay)&&isB(hideToTarget)) {
	  var obj = Graphics.getElement(elementName);
	  if(obj) {
	      Graphics.setPosition(obj.id, startX, startY);
	      var progressX = progress;
	      var progressY = progress;
	      var currentX = parseInt(obj.style.left);
	      var currentY = parseInt(obj.style.top);
	      w.timeoutTB = null;
	      w.targetTB = false;
	      var xTarget = false;
	      var yTarget = false;
	      obj.onmouseover = function() {
		progressX = progressY = 0;
	      }
	      obj.onmouseout = function() {
		progressX = progressY = progress;
	      }
	      function h() {
		if(w.targetTB) {
		    if(currentX > startX) {
		        currentX -= progressX;
		    } else {
		        currentX += progressX;
		    }
		    if(currentY > startY) {
		        currentY -= progressY;
		    } else {
		        currentY += progressY;
		    }

		    obj.style.top = currentY + "px";
		    obj.style.left = currentX + "px";

		    if(parseInt(obj.style.left) == startX) {
		        progressX = 0;
		        xTarget = true;
		    }
		    if(parseInt(obj.style.top) == startY) {
		        progressY = 0;
		        yTarget = true;
		    }
		    if(xTarget && yTarget) {
		        w.clearTimeout(w.timeoutTB);
		        xTarget = false;
		        yTarget = false;
		        if(hideToTarget) {
			  Graphics.hide(obj.id);
		        }
		    }
		    else {
		        w.timeoutTB = w.setTimeout(h, speed);
		    }
		}

	      }
	      function m() {
		if(currentX > endX) {
		    currentX -= progressX;
		} else {
		    currentX += progressX;
		}
		if(currentY > endY) {
		    currentY -= progressY;
		} else {
		    currentY += progressY;
		}

		obj.style.top = currentY + "px";
		obj.style.left = currentX + "px";

		if(parseInt(obj.style.left) == endX) {
		    progressX = 0;
		    xTarget = true;
		}
		if(parseInt(obj.style.top) == endY) {
		    progressY = 0;
		    yTarget = true;
		}
		if(xTarget && yTarget) {
		    w.targetTB = true;
		    w.setTimeout(h, delay);
		    w.clearTimeout(obj.timeoutTB);
		    xTarget = false;
		    yTarget = false;
		    progressX = progressY = progress;
		}
		else {
		    w.timeoutTB = w.setTimeout(m, speed);
		}
	      }
	      w.setTimeout(m, startDelay);
	  }else {
	      ex(elementName + e3)
	  }
        } else {
	  ex(e2)
        }
    }
    /**
     * Setta la posizione di un elemento.
     * @param elementName un elemento di document
     * @param x la coordinata x
     * @param y la coordinata y
     */
    Graphics.setPosition = function(elementName, x, y) {
        ck(arguments);
        if(isS(elementName)&&isN(x)&&isN(y)) {
	  var el = (d.all) ? d.all[elementName] : d.getElementById(elementName);
	  if(el) {
	      el.style.position = "absolute";
	      el.style.left = x;
	      el.style.top = y;
	  }else {
	      ex(elementName + e3)
	  }
        } else {
	  ex(e2)
        }
    }
    /**
             * Rende visibile un elemento nascosto.
             * @param elementName il nome dell'elemento
             */
    Graphics.show = function(elementName) {
        var el = (d.all) ? d.all[elementName] : d.getElementById(elementName);
        if(el) {
	  el.style.visibility = "visible";
        }else {
	  ex(elementName + e3)
        }
    }
    /**
     * Restituisce la classe Graphics.
     * @return Graphics
     */
    JF.prototype.getGraphics = function() {
        return Graphics;
    }
    ///////////////////////////////////////////////////////////////////////////// FString /////////////////////////////////////////////////////

    /**
     * Classe FString
     */
    function FString(id, string, x, y) {
        this.id = id;
        this.string = string;
        this.x = x;
        this.y = y;
        this.text = null;
        Printer.print("<span id='"+id+"' style='position: absolute; left: "+x+"px; top:"+y+"px'>"+string+"</span>");
        this.text = (d.all) ? d.all[id] : d.getElementById(id);
        this.style = this.text.style;
    }
    /**
     * Setta il font della stringa.
     * @param fontFace Es: 'Verdana, Times New Roman'
     */
    FString.prototype.setFont = function(fontFace) {
        (isS(fontFace))?this.style.fontFamily = fontFace:ex(e1);
    }
    /**
     * Setta la dimensione della stringa.
     * @param fontSize Es: 10, 20, 50 in pixel
     */
    FString.prototype.setSize = function(fontSize) {
        (isN(fontSize))?this.style.fontSize = fontSize + "px":ex(e1);
    }
    /**
     * Setta lo stile della stringa.
     * @param style Es: 'normal', 'italic', 'oblique'
     */
    FString.prototype.setStyle = function(style) {
        (isS(style))?this.style.fontStyle = style + "px":ex(e1);
    }
    /**
     * Setta lo spessore della stringa.
     * @param weight Es: 'bold', 'bolder', ecc
     */
    FString.prototype.setWeight = function(weight) {
        (isS(weight))?this.style.fontWeight = weight + "px":ex(e1);
    }
    /**
     * Setta la visibilità della stringa.
     * @param visible false per nasconderlo, true altrimenti, oppure 'visible-hidden'
     */
    FString.prototype.setVisible = function(visible) {
        if(typeof visible == "boolean") {
	  if(visible) {
	      this.style.visibility = "visible";
	  } else {
	      this.style.visibility = "hidden";
	  }
        } else {
	  this.style.visibility = visible;
        }
    }
    /**
     * Classe Rectangle
     */
    function Rectangle(id, w, h, closeIcon) {
        this.id = id;
        this.w = w;
        this.h = h;
        var rect = null;
        var content = null;
        var close = null;
        var p = Printer;
        if(closeIcon) {
	  p.print("<div id='"+id+"' style='position: absolute; left:0px; top:0px; width:"+w+"px; height:"+h+"px; border:0px; visibility: hidden; margin:0px; padding:0px; z-index:990'>");
	  p.print("<img id='"+id+"close' src='"+ domain + jPackage +"close.gif' border='0' style='position: absolute; top:0px; left:" + (w - 30) + "px; z-index:992' title='Chiudi' alt='Chiudi' />");
	  p.print("<div id='" + id + "content' aling='center' style='position: absolute; top:10px; left:0px; width:" + (w-30) + "px; height:" + (h - 30) + "px; background-color: #ffffff; border: 10px solid #ff0000; z-index:991'></div>");
	  p.print("</div>");
	  rect = (d.all) ? d.all[id] : d.getElementById(id);
	  content = (d.all) ? d.all[id + "content"] : d.getElementById(id + "content");
	  close = (d.all) ? d.all[id + "close"] : d.getElementById(id + "close");
        } else {
	  p.print("<div id='"+id+"' style='position: absolute; left:0px; top:0px; width:"+w+"px; height:"+h+"px; border:0px; background-color: #ffffff; visibility: hidden; margin:0px; padding:0px; z-index:990'></div>");
	  rect = (d.all) ? d.all[id] : d.getElementById(id);

        }
        this.rect = rect;
        this.rectStyle = rect.style;
        this.contentPane = content;
        this.contentPaneStyle = (content != null) ? content.style : content;
        this.close = close;
        if(close != null) {
	  close.onmouseover = function() {
	      close.style.cursor = "pointer";
	  }
	  close.onmouseout = function() {
	      close.style.cursor = "default";
	  }
        }
    }
    /**
     * Imposta la posizione al centro dello schermo.
     */
    Rectangle.prototype.centerOnScreen = function() {
        this.rectStyle.left = ((s.availWidth - this.w) / 2) + "px";
        this.rectStyle.top = ((s.availHeight - this.h) / 3) + "px";
    }
    /**
     * Un oggetto style.
     * @return L'oggeto style associato al rettangolo
     */
    Rectangle.prototype.getStyleObject = function () {
        return (this.close != null) ? this.contentPaneStyle : this.rectStyle;
    }
    /**
     * Il punto x sullo schermo.
     * @return Il punto x sullo schermo
     */
    Rectangle.prototype.getX = function () {
        return parseInt(this.rectStyle.left, 10);
    }
    /**
     * Il punto y sullo schermo
     * @return Il punto y sullo schermo
     */
    Rectangle.prototype.getY = function () {
        return parseInt(this.rectStyle.top, 10);
    }
    /**
     * Larghezza sullo schermo.
     * @return Larghezza sullo schermo
     */
    Rectangle.prototype.getWidth = function () {
        return parseInt(this.rectStyle.width, 10);
    }
    /**
     * Altezza sullo schermo
     * @return Altezza sullo schermo
     */
    Rectangle.prototype.getHeight = function () {
        return parseInt(this.rectStyle.height, 10);
    }
    /**
     * Imposta il bordo.
     * @param border Nella forma '1px solid red'
     */
    Rectangle.prototype.setBorder = function(border) {
        if(isS(border)) {
	  if(this.contentPane != null) {
	      this.contentPaneStyle.border = border;
	  } else if(this.rect != null) {
	      this.rectStyle.border = border;
	  }
        } else {
	  ex(e1)
        }
    }
    /**
     * Imposta un colore di sfondo.
     * @param color Nella forma 'red', 'yellow' oppure '#ffaacc'
     */
    Rectangle.prototype.setBackgroundColor = function(color) {
        (isS(color))?this.rectStyle.backgroundColor = color:ex(e1);
    }
    /**
     * Imposta la posizione secondo le coordinate specificate e la dimensione.
     * @param x coordinata x
     * @param y coordinata y
     * @param w larghezza
     * @param h altezza
     */
    Rectangle.prototype.setBounds = function(x, y, w, h) {
        ck(arguments);
        if(isN(x)&&isN(y)&&isN(w)&&isN(h)){
	  this.rectStyle.left = x + "px";
	  this.rectStyle.top = y + "px";
	  this.rectStyle.width = w + "px";
	  this.rectStyle.height = h + "px";
        } else {
	  ex(e2)
        }
    }
    /**
     * Imposta la pagina che si vuole caricare nel rettangolo.
     *
     * @param url Url relativo alla pagina da caricare
     */
    Rectangle.prototype.setPage = function (url) {
        if(isS(url)) {
	  var cp = (this.contentPane == null) ? this.rect : this.contentPane;
	  cp.innerHTML = "<iframe src='" + url + "' frameborder='0' marginheight='0' marginwidth='0' width='" + cp.style.width + "' height='" + cp.style.height + "'>Il tuo browser non supporta gli IFRAMES</iframe>";
        } else {
	  ex(e1);
        }
    }
    /**
     * Imposta una immagine per il rettangolo.
     *
     * @param url
     * @param link
     * @param title
     */
    Rectangle.prototype.setImage = function (url, link, title) {
        ck(arguments);
        if(isS(url)&&isS(link)&&isS(title)) {
	  var cp = (this.contentPane == null) ? this.rect : this.contentPane;
	  cp.innerHTML = "<a href='" + link + "'><img src='" + url + "' width='" + cp.style.width + "' height='" + cp.style.height + "' border='0' title='" + title + "' alt='" + title + "' /></a>";
        } else {
	  ex(e2);
        }
    }
    /**
     * Imposta il contenuto che si vuole caricare nel rettangolo.
     *
     * @param content Un testo html o non
     */
    Rectangle.prototype.setContent = function (content) {
        if(isS(content)) {
	  var cp = (this.contentPane == null) ? this.rect : this.contentPane;
	  cp.innerHTML = content;
        } else {
	  ex(e1);
        }
    }
    /**
     * Imposta la posizione secondo le coordinate specificate.
     * @param x coordinata x
     * @param y coordinata y
     */
    Rectangle.prototype.setPosition = function(x, y) {
        ck(arguments);
        if(isN(x)&&isN(y)) {
	  this.rectStyle.left = x + "px";
	  this.rectStyle.top = y + "px";
        } else {
	  ex(e2);
        }
    }
    /**
     * Setta la visibilità del rettangolo.
     * @param visible false per nasconderlo, true altrimenti, oppure 'visible|hidden'
     */
    Rectangle.prototype.setVisible = function(visible) {
        if(isB(visible)) {
	  if(visible) {
	      this.rectStyle.visibility = "visible";
	  } else {
	      this.rectStyle.visibility = "hidden";
	  }
        } else {
	  this.rectStyle.visibility = visible;
        }
    }
    /**
     * Larghezza sullo schermo.
     * @param width Larghezza sullo schermo
     */
    Rectangle.prototype.setWidth = function (width) {
        this.rectStyle.width = width + "px";
    }
    /**
     * Altezza sullo schermo
     * @param height Altezza sullo schermo
     */
    Rectangle.prototype.setHeight = function (height) {
        this.rectStyle.height = height + "px";
    }
    FM.jFazio = FM.JF = new JF();
})(window);
