/*****************************************************************************
SHAJAX - Auxiliar Window Control
Copyright (C) 2006  Daniel Dalgo

This library is free software; you can redistribute it and/or modify it under 
the terms of the GNU Lesser General Public License as published by the 
Free Software Foundation; either version 2.1 of the License, or (at your option) 
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY 
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along 
with this library; if not, write to the Free Software Foundation, Inc., 59 
Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*****************************************************************************
*****************************************************************************
*****************************  CONTACT **************************************
							   -------
PLEASE, CONTACT US AT:
www.7bits.com.ec
ddalgo@7bits.com.ec
Quito, Ecuador
*****************************************************************************
***************************  EXTRA FILES ************************************
							 -----------
Also, please refer to the helper files annexed
- "updates.txt" 
- "bugs.txt"
for info about new features or bugs in this library, and also use it 
for post your own information. Contact us using the media referred above, in
the CONTACT section.

All the files referred here, in the EXTRA FILES section, and the new info
posted in those files are also covered for the license here mentioned.
*****************************************************************************/

// Javascript

var VentanaAuxHandler = {
	idTipoControl		: "ventanaAuxControl",
	separador			: "_",
	
	getEvent			:	function (e, el) {
								if (!e) {
									if (el){
										e = el.ownerDocument.parentWindow.event;
									} else {
										e = window.event;
									}
								}
								if (!e.srcElement) {
									var el = e.target;
									
									while (el != null && el.nodeType != 1){
										el = el.parentNode;
									}
									e.srcElement = el;
								}
								if (typeof e.offsetX == "undefined"){
									e.offsetX = e.layerX;
									e.offsetY = e.layerY;
								}
								
								return e;
							},

	onFocus				: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								this.VentanaAux.setActivado(true);
							},
	onBlur				: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								this.VentanaAux.setActivado(false);
							},
	onClick				: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								/** Se garantiza que la ventana sobre la que se ha
								 * hecho click sea la que se visualice, siempre y cuando
								 * la ventana no esté minimizada
								 * SOLUCION SOLO PARA FIREFOX. ESTE NO DEBE SER EL LUGAR PARA ESTE
								 * CODIGIO SINO DEBERIA IR EN EL EVENO onmouusedon, PERO EN IE AL 
								 * HABILITAR ESTE CODIGO EN ESE EVETNO, DESHABILITA
								 * EL FUNCIONAMIENTO DE LOS BOTONES DE CERRAR O MINIMIZAR
								 */
								if(window.ActiveXObject){
									/** Es una forma rústica de identificar al browser ie
									 */
									if(!this.VentanaAux.getMinimizado()){
										this.VentanaAux.doBringToFront();
									}
								}
							},
	onMouseDown			: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								/** Se garantiza que la ventana sobre la que se ha
								 * hecho click sea la que se visualice, siempre y cuando
								 * la ventana no esté minimizada
								 * SOLO PARA FIREFOX. EN IE EL HABILITAR ESTE CODIGO DESHABILITA
								 * EL FUNCIONAMIENTO DE LOS BOTONES DE CERRAR O MINIMIZAR
								 */
								if(window.XMLHttpRequest){
									/** Es una forma rústica de identificar al browser Firefox
									 */
									if(!this.VentanaAux.getMinimizado()){
										this.VentanaAux.doBringToFront();
									}
								}
								
								/** Solo si no es titulable se puede efectuar un movimiento
								 * de la ventana
								 */
								if(this.VentanaAux.getTitulable()){
									return;
								}
								
								if(window.XMLHttpRequest){
									/** Es una forma rústica de identificar al browser Firefox
									 */
									
									if(e.button!=0){
										/** Solo reacciona a clicks con el botón izquierdo
										 */
										return;
									}
								} else {
									/** Se supone que es ie
									 */
									if(e.button!=1){
										/** Solo reacciona a clicks con el botón izquierdo
										 */
										return;
									}
								}
								
								this.VentanaAux.mouseButtonPressed=e.button;
								this.VentanaAux.diferencialX=e.clientX-parseInt(this.VentanaAux.getX());
								this.VentanaAux.diferencialY=e.clientY-parseInt(this.VentanaAux.getY());
							},
	onMouseUp			: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								/** Solo si no es titulable se puede efectuar un movimiento
								 * de la ventana
								 */
								if(this.VentanaAux.getTitulable()){
									return;
								}
								
								this.VentanaAux.mouseButtonPressed=null;
								this.VentanaAux.diferencialX=null;
								this.VentanaAux.diferencialY=null;
							},
	onMouseOver			: null,
	onMouseMove			: 	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								/** Solo si no es titulable se puede efectuar un movimiento
								 * de la ventana
								 */
								if(this.VentanaAux.getTitulable()){
									return;
								}
								
								if(this.VentanaAux.mouseButtonPressed!=null){
									this.VentanaAux.setX(e.clientX-this.VentanaAux.diferencialX);
									this.VentanaAux.setY(e.clientY-this.VentanaAux.diferencialY);
								}
							},
	onMouseOut			: null,
	onKeyDown			: null,
	onKeyPress			: null,
	onKeyUp				: null,
	onMouseWheel		: null,
	onPropertyChange	: null,


	onMouseDown_BarraTitulo	: 	function(e){
									e=VentanaAuxHandler.getEvent(e, this);
									
									if(window.XMLHttpRequest){
										/** Es una forma rústica de identificar al browser Firefox
										 */
										
										if(e.button!=0){
											/** Solo reacciona a clicks con el botón izquierdo
											 */
											return;
										}
									} else {
										/** Se supone que es ie
										 */
										if(e.button!=1){
											/** Solo reacciona a clicks con el botón izquierdo
											 */
											return;
										}
									}
									
									this.VentanaAux.mouseButtonPressed=e.button;
									this.VentanaAux.diferencialX=e.clientX-parseInt(this.VentanaAux.getX());
									this.VentanaAux.diferencialY=e.clientY-parseInt(this.VentanaAux.getY());
								},
	onMouseUp_BarraTitulo	: 	function(e){
									e=VentanaAuxHandler.getEvent(e, this);
									
									this.VentanaAux.mouseButtonPressed=null;
									this.VentanaAux.diferencialX=null;
									this.VentanaAux.diferencialY=null;
								},
	onMouseOver_BarraTitulo	: null,
	onMouseMove_BarraTitulo	: 	function(e){
									e=VentanaAuxHandler.getEvent(e, this);
									
									if(this.VentanaAux.mouseButtonPressed!=null){
										this.VentanaAux.setX(e.clientX-this.VentanaAux.diferencialX);
										this.VentanaAux.setY(e.clientY-this.VentanaAux.diferencialY);
									}
								},
	onMouseOut_BarraTitulo	: null,

	onClick_MinMax		:	function(e){
								e=VentanaAuxHandler.getEvent(e, this);

								this.VentanaAux.setMinimizado(!this.VentanaAux.getMinimizado());
							},

	onClick_Cerrar		:	function(e){
								e=VentanaAuxHandler.getEvent(e, this);
								
								this.VentanaAux.setCerrado(!this.VentanaAux.getCerrado());
							}
};



