// JavaScript Document
var Message = Class.create({
	initialize: function(blShowButton,blShowScroll) {
		this.strTitle = "";
		this.strText = "";
		this.intX	=	0;
		this.intY	=	0;
		this.intWidth	=	0;
		this.intHeight	=	0;
		this.blVisible	=	false;
		this.flOpacityDegree	=	1.0;
		this.blShowButton	=	((blShowButton==null)?true:blShowButton);
		this.OPACITY	=	0.9;
		
		this.pr_object	=	null;		
		this.pr_object_title	=	null;
		this.pr_object_text	=	null;
		this.pr_object_text_ok	=	null;
		this.ID = "ID"+Date().toJSON().gsub(" ","");
                this.blShowScroll = ((blShowScroll==null)?false:blShowScroll);
		
	},
	/**
	 * Setea el titulo de la ventana
	 * @param {String} strTitle el titulo de la ventana
	 */
	setTitle: function(strTitle) {
		this.strTitle	=	strTitle;
		this.pv_process_repaintTitle();
	},
	setText: function(strText) {
		this.strText	=	strText;
		this.pv_process_repaintText();
	},
	getTitle: function() {
		return this.strTitle;
	},
	getText: function() {
		return this.strText;
	},
	setX: function (intX){
		this.intX	=	intX;
	},
	setY: function (intY){
		this.intY	=	intY;
	},
	getX: function (){
		return this.intX;
	},
	getY: function (){
		return this.intY;
	},
	getWidth: function (){
		return this.intWidth;
	},
	getHeight: function (){
		return this.intHeight;
	},
	setWidth: function (intWidth){
		this.intWidth	=	intWidth;
		this.pv_process_resize();
	},
	setHeight: function (intHeight){
		this.intHeight	=	intHeight;
		this.pv_process_resize();
	},
	showButtonOk: function (blShowButton){
		this.blShowButton	=	blShowButton;
	},
	setVisible: function (blVisible){
		if(blVisible)
			if(!this.blVisible)
				this.pv_process_show();
		else
			this.pv_process_hide();		
	},	
	isVisible: function (){
		return this.blVisible;
	},
	setHideWithEffect : function (){
		//heredo de la clase y la extiendo
		var MessageThreadHide = Class.create(PeriodicalExecuter,{
			initialize: function($super, callbackFunction, time , this_) {
				$super(callbackFunction,time);
				this.this_ = this_;
			}
		});
		new MessageThreadHide(this.pv_Thread_Hide_Effect,0.1,this);
	},
	setOpacity : function (flOpacityDegree){
		$(this.ID).setOpacity(0);
		$(this.ID+"_").setOpacity(flOpacityDegree);
		this.flOpacityDegree	=	flOpacityDegree;
	},
	getOpacity : function (){
		return this.flOpacityDegree;
	},
	//private
	pv_process_hide : function(){
		$(this_.ID).hide();
		$(this_.ID+"_div").hide();
		$(this_.ID+"_").hide();
		this_.blVisible	=	false;		
	},
	//private
	pv_process_show : function(){
		if(this.pr_object==null)
			this.pv_process_create();
		$(this.ID).show();
		$(this.ID+"_").show();
		this.blVisible	=	true;
		this.pr_object.style.top = this.getY()+document.viewport.getScrollOffsets().top+"px";
		this.setY(this.getY()+document.viewport.getScrollOffsets().top);
	},
	//private
	pv_process_create : function(){
		this.setX((document.viewport.getWidth()/2)-(this.getWidth()/2));
		this.setY(((document.viewport.getHeight()/2)-(this.getHeight()/2))/*+document.viewport.getScrollOffsets().top*/);
		
		this.container	=	document.createElement("iframe");		
		this.container.id = this.ID;
		this.container.classReference	=	this;//esta propiedad se agrega para pasarle el manejador
		this.container.style.position = "absolute";
                this.container.style.zIndex = 20;
		this.container.style.left = "0px";
		this.container.style.top = "0px";
		this.container.style.width = (document.viewport.getWidth()-20)+"px";
		this.container.style.height = document.viewport.getHeight()+document.viewport.getScrollOffsets().top+"px";
		this.container.frameborder = 0;
		this.container.allowtransparency	=	"true";
		this.container.scrolling="no";
		document.body.appendChild(this.container);		
		
		this.containerdiv	=	document.createElement("div");
		this.containerdiv.id = this.ID+"_div";
		this.containerdiv.classReference = this;
                this.containerdiv.style.zIndex = 21;
		this.containerdiv.style.position = "absolute";
		this.containerdiv.style.left = "0px";
		this.containerdiv.style.top = "0px";
		this.containerdiv.style.width = (document.viewport.getWidth()-20)+"px";
		this.containerdiv.style.height = document.viewport.getHeight()+document.viewport.getScrollOffsets().top+"px";

		this.pr_object	=	document.createElement("div");
		this.pr_object.id	=	this.ID + "_";
		this.pr_object.classReference	=	this;//esta propiedad se agrega para pasarle el manejador
		this.pr_object.style.position = "absolute";
		this.pr_object.style.left = this.getX()+"px";
		this.pr_object.style.top = this.getY()+"px";
		this.pr_object.style.width = this.getWidth()+"px";
		this.pr_object.style.height = this.getHeight()+"px";
		this.pr_object.style.backgroundColor = "#FF0000";
		
		this.pr_object_title	=	document.createElement("div");		
		this.pr_object_title.id	=	this.ID + "_t";
		this.pr_object_title.classReference = this;
		this.pr_object_title.innerHTML	=	"&nbsp;&nbsp;"+this.getTitle();
		this.pr_object_title.position = "absolute";
                this.pr_object_title.style.paddingTop = "5px";
		this.pr_object_title.left = "0px";
		this.pr_object_title.top = "0px";
		this.pr_object_title.style.width	=	this.pr_object.style.width;
		this.pr_object_title.style.height	=	"20px";
		this.pr_object_title.style.backgroundColor = "#333333";
		this.pr_object_title.style.color = "#CCCCCC";
		this.pr_object_title.style.fontFamily = "Arial, Helvetica, sans-serif";
		this.pr_object_title.style.fontSize = "12px";
		this.pr_object_title.style.fontWeight = "bold";
		this.pr_object_title.style.cursor = "move";
		this.pr_object.appendChild(this.pr_object_title);
		
		this.pr_object_text_container	=	document.createElement("div");
		this.pr_object_text_container.style.position = "absolute";
		this.pr_object_text_container.style.left = "0px";
		this.pr_object_text_container.style.top = "21px";
		this.pr_object_text_container.style.width = this.getWidth()+"px";
		this.pr_object_text_container.style.height = (this.getHeight()-21)+"px";
		this.pr_object_text_container.style.backgroundColor = "#CCCCCC";

		this.pr_object_text	=	document.createElement("div");
		this.pr_object_text.innerHTML	=	this.getText();
		this.pr_object_text.classReference	=	this;//esta propiedad se agrega para pasarle el manejador
		this.pr_object_text.style.position = "absolute";
		this.pr_object_text.style.left = "10px";
		this.pr_object_text.style.top = "4px";
		this.pr_object_text.style.width = this.getWidth()-20+"px";
		this.pr_object_text.style.height = (this.getHeight()-62)+"px";		
		this.pr_object_text.style.color = "#333333";
		this.pr_object_text.style.fontFamily = "Arial, Helvetica, sans-serif";
		this.pr_object_text.style.fontSize = "12px";
                if(this.blShowScroll)
                  this.pr_object_text.style.overflow="hidden";
		this.pr_object_text_container.appendChild(this.pr_object_text);
		this.pr_object.appendChild(this.pr_object_text_container);
              if(this.blShowButton){
			//dibuja el boton
			this.pv_process_createButtonOk();			
		}
		
		this.containerdiv.appendChild(this.pr_object);
		document.body.appendChild(this.containerdiv);
		
		//Propiedades iniciales
		this.setOpacity(this.OPACITY);
		this.setVisible(false);
		
		if(this.blShowButton){
			//Eventos
			function onClickOkButton(event) {
				Event.element(event).classReference.setHideWithEffect();
			}
			$(this.pr_object_text_ok.id).observe('click', onClickOkButton);
		}
		
		this.blMouseDown = false;
		this.arrayMouseClick = Array(3);
		
		function onMouseDownTitle(event) {
			this_ = Event.element(event).classReference;
			this_.arrayMouseClick[0]=(Event.pointerX(event) - this_.getX());
			this_.arrayMouseClick[1]=(Event.pointerY(event)-this_.getY());
			this_.arrayMouseClick[2]=Event.pointerX(event);
			this_.arrayMouseClick[3]=Event.pointerY(event);
			this_.blMouseDown= true;
		}
		function onMouseUpTitle(event) {
			this_ = Event.element(event).classReference;
			if(this_ !=null){
				if(this_.blMouseDown && this_.arrayMouseClick[2] != Event.pointerX(event) && this_.arrayMouseClick[3] != Event.pointerY(event)){				
					this_.pr_object.style.left = (Event.pointerX(event)-this_.arrayMouseClick[0])+"px";
					this_.pr_object.style.top = (Event.pointerY(event)-this_.arrayMouseClick[1])+"px";
					this_.setX(Event.pointerX(event)-this_.arrayMouseClick[0]);
					this_.setY(Event.pointerY(event)-this_.arrayMouseClick[1]);
				}
				this_.blMouseDown = false;
			}
		}
		function onMouseMoveTitle(event) {
			this_ = Event.element(event).classReference;
			if(this_.blMouseDown ){
				this_.pr_object.style.left = (Event.pointerX(event)-this_.arrayMouseClick[0])+"px";
				this_.pr_object.style.top = (Event.pointerY(event)-this_.arrayMouseClick[1])+"px";
				this_.setX(Event.pointerX(event)-this_.arrayMouseClick[0]);
				this_.setY(Event.pointerY(event)-this_.arrayMouseClick[1]);
				
				this_.arrayMouseClick[0]=(Event.pointerX(event) - this_.getX());
				this_.arrayMouseClick[1]=(Event.pointerY(event)-this_.getY());
				this_.arrayMouseClick[2]=Event.pointerX(event);
				this_.arrayMouseClick[3]=Event.pointerY(event);
			}
		}
		
		$(this.pr_object_title.id).observe('mousedown', onMouseDownTitle);
		$(this.pr_object_title.id).observe('mouseup', onMouseUpTitle);
		$(this.pr_object_title.id).observe('mousemove', onMouseMoveTitle);
		$(this.containerdiv.id).observe('mouseup', onMouseUpTitle);		
		
		
		//heredo de la clase y la extiendo
		/*var MessageThread = Class.create(PeriodicalExecuter,{
			initialize: function($super, callbackFunction, time , this_) {
				$super(callbackFunction,time);
				this.this_ = this_;
			}
		});		
		new MessageThread(this.pv_Thread_check_offSet,1,this);*/
	},
	//private
	pv_process_createButtonOk	:	function(){
		if(this.pr_object!=null){			
			this.pr_object_text_ok	=	document.createElement("div");
			this.pr_object_text_ok.id = this.ID + "_b";
			this.pr_object_text_ok.classReference	=	this;//esta propiedad se agrega para pasarle el manejador
			this.pr_object_text_ok.innerHTML	=	"Aceptar";
			this.pr_object_text_ok.style.position = "absolute";
			this.pr_object_text_ok.style.left = ((this.getWidth()/2)-50)+"px";
			this.pr_object_text_ok.style.top = (this.getHeight()-31)+"px";
			this.pr_object_text_ok.style.width = 100+"px";
			this.pr_object_text_ok.style.height = 20+"px";
			this.pr_object_text_ok.style.backgroundColor = "#333333";
			this.pr_object_text_ok.style.color = "#CCCCCC";
			this.pr_object_text_ok.style.fontFamily = "Arial, Helvetica, sans-serif";
			this.pr_object_text_ok.style.fontSize = "13px";
			this.pr_object_text_ok.style.fontWeight = "bold";
			this.pr_object_text_ok.style.cursor = "pointer";
			this.pr_object_text_ok.style.cursor = "hand";
			this.pr_object_text_ok.style.textAlign = "center";
			this.pr_object.appendChild(this.pr_object_text_ok);
		}
	},
	pv_process_resize	:	function(){
		if(this.pr_object!=null){			
			this.pr_object.style.width = this.getWidth()+"px";
			this.pr_object.style.height = this.getHeight()+"px";
			this.pr_object_title.style.width	=	this.pr_object.style.width;
			this.pr_object_text_container.style.width = this.getWidth()+"px";
			this.pr_object_text_container.style.height = (this.getHeight()-21)+"px";
			this.pr_object_text.style.width = this.getWidth()-20+"px";
			this.pr_object_text.style.height = (this.getHeight()-62)+"px";
			if(this.blShowButton){
				if(this.pr_object_text_ok == null)
					this.pv_process_createButtonOk();
				this.pr_object_text_ok.style.left = ((this.getWidth()/2)-50)+"px";
				this.pr_object_text_ok.style.top = (this.getHeight()-31)+"px";
			}
		}
	},
	
	//private
	pv_process_repaintTitle	:	function(){
		if(this.pr_object!=null){			
			this.pr_object_title.innerHTML	=	"&nbsp;&nbsp;"+this.getTitle();
		}
	},
	
	//private
	pv_process_repaintText	:	function(){
	        
              if(this.pr_object!=null){
			this.pr_object_text.innerHTML	=	this.getText();
                        
                        if(this.blShowButton){
				//dibuja el boton
                                if(this.pr_object_text_ok==null){
                                  this.pv_process_createButtonOk();
                                  //Eventos
                                  var onClickOkButton = function(event) {
                                          Event.element(event).classReference.setHideWithEffect();
                                  }
                                  $(this.pr_object_text_ok.id).observe('click', onClickOkButton);
                                }else{
                                  var onClickOkButton = function(event) {
                                          Event.element(event).classReference.setHideWithEffect();
                                  }
                                  $(this.pr_object_text_ok.id).observe('click', onClickOkButton);
                                }
			}
              }
	},
	
	//private
	/*pv_Thread_check_offSet	:	function(Thread){
		Thread.this_.pr_object.style.top = Thread.this_.getY()+document.viewport.getScrollOffsets().top+"px";
	},*/
	
	//private
	pv_Thread_Hide_Effect	:	function(Thread){
		this_	=	Thread.this_;
		if(this_.getOpacity()<=0.2){
			Thread.stop();
			this_.pv_process_hide();
			this_.setOpacity(this.OPACITY);			
		}else
			this_.setOpacity(this_.getOpacity()-0.3);
	}
  }
);//fin de la clase Message
	
/*// save arguments
this.title = title;
this.oContent = oContent;

// initialization 
this.mx = 0;
this.my = 0;

// create table for window with title-bar and content
this.oTable = document.createElement("table");
this.oTable.border = 1;

// set the position of the window
this.oTable.style.position = "absolute";
this.oTable.style.left = x + "px";
this.oTable.style.top = y + "px";

// set background to white (default is transparent)
this.oTable.style.backgroundColor = "white";

// link from the table to the JSWindow object
this.oTable.jsWindow = this;

// if anywhere in the table are is clicked, bring the window to front.
this.oTable.onmousedown = JSWindow.prototype.onBringToFront;

// append to document body
document.body.appendChild(this.oTable);

// add row for title bar
var oTR = this.oTable.insertRow(0);
oTR.className = "JSWindowTitleStyle";

// title 
var oTD = oTR.insertCell(0);
oTD.innerHTML = title;
oTD.jsWindow = this;
oTD.onmousedown = JSWindow.prototype.tdOnMouseDown;

// minimize
this.oMinTD = oTR.insertCell(1);
this.oMinTD.innerHTML = "_";
this.oMinTD.onclick = JSWindow.prototype.onMinimize;
this.oMinTD.jsWindow = this;

// close
oTD = oTR.insertCell(2);
oTD.innerHTML = "X";
oTD.jsWindow = this; 
oTD.onmousedown = JSWindow.prototype.onBringToFront;
oTD.onclick = JSWindow.prototype.onClose;

// add row for window content
// a single cell the same width as the title bar row
oTR = this.oTable.insertRow(1);
oTD = oTR.insertCell(0);
oTD.colSpan = 3;
oTD.appendChild(oContent);
 
} */

/*JSWindow.prototype.onBringToFront = function()
{
 
    this.jsWindow.bringToFront(); 
  }
JSWindow.prototype.bringToFront = function()
{ 
    // move table to bottom of document body
document.body.appendChild(this.oTable); 
  } */


