/**********************************************************************
 *
 * $Id: kaWinManager.js,v 1.2 2006/06/12 11:17:10 lbecchi Exp $
 *
 * purpose:  simulate a windows manager for all tool in the viewport (bug 1471)
 *         
 *
 * author: Lorenzo Becchi & Andrea Cappugi
 *
 * TODO:
 *   - 
 * 
 **********************************************************************
 *
 * Copyright (c)  2006, ominiverdi.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 *
 **********************************************************************/

/******************************************************************************
 * kaWinManager - 
 *
 * To use kaWinManager:
 * 
 * 1) select a div to work as your Window Manager:
 * 
 *   var kaWinMan = new kaWinManager('viewport');
 * 
 * 2) create a new instance of a Window (kaWinManager)
 * 
 *   var win1 = kaWinMan.createWin('myToolbar');			
 * 
 * 3) set values for your Window 
 * params: Title (string), top left x (int), top left y (int), width (int), height  (int), 
 * resizable (boolean), draggable (boolean), min width (int), min height (int)
 * 
 *   myToolbarWin.setValues('Toolbar',20,20,200,200,true.true);
 * 
 * 4) inport an existing dom object (ex: a div) into your window:
 * 
 *   myToolbarWin.pushContent(getRawObject('toolbar'));
 * 
 * or set an inner text:
 *
 * myToolbarWin.setContent('a string');
 *
 *****************************************************************************/

 function kaWinManager( id )
 {
    //set the frame div 
	this.desktop = getRawObject( id );
	
	this.windows=new Array();
	this.activeWindow=null;

	this.minZindex = 2000;

 };


kaWinManager.prototype.createWin = function( id ){
	for(var i=0;i<this.windows.length;i++){
		if(this.windows[i].id==id){
			alert('id already in use');
			return
		}
		 
	}
	var newWin = new kaWindow(id,this);
	newWin.position = this.minZindex+this.windows.length;
	this.windows[this.windows.length]= newWin;
	return newWin;
};

kaWinManager.prototype.getWin = function( id ){
	for(var i=0;i<this.windows.length;i++){
	    if(this.windows[i].id==id){
	    	return this.windows[i];
	    }
	}
};

kaWinManager.prototype.setActive = function (window) {
	this.activeWindow = window;
	//alert("Set Active");
	this.positionChanged(window,this.windows.length+this.minZindex);
	
	for( var i=0; i<this.windows.length; i++ ) {
		this.windows[i].domObj.parent.setZindex(this.windows[i].position);
	}
};
kaWinManager.prototype.positionChanged = function ( window , position ) {
	var prevPos = window.parent.position;
	if(prevPos==position) return;
	if(prevPos<position){
		for( var i=0; i<this.windows.length; i++ ) {
			var win = this.windows[i];
			if(win!=window && win.domObj.parent.position > prevPos && win.domObj.parent.position<=position){
				win.domObj.parent.position--;
			}
		}
	} else {
		for( var i=0; i<this.windows.length; i++ ) {
			var win = this.windows[i];
			if(win!=window && win.domObj.parent.position < prevPos && win.domObj.parent.position>=position){
				win.domObj.parent.position++;
			}
		}
	}
	window.parent.position = position;
};

kaWinManager.prototype.setBackgroundImage = function ( src,x,y,w,h ) {
	
	
	this.imgObj = document.createElement('img');
	this.imgObj.id='kaBackImg';
	this.imgObj.src= src; 
	this.imgObj.style.position='absolute'; 
	this.imgObj.style.left=x+'px'; 
	this.imgObj.style.top=y+'px'; 
	this.imgObj.style.width= w + 'px'; 
	this.imgObj.style.height= h + 'px'; 
	this.imgObj.style.zIndex= 0; 
	this.desktop.appendChild( this.imgObj );
};
/******************
* Window Object 
*******************/
function kaWindow(id,winManager){
	this.domObj = null;//domObj init
	this.winManager = winManager;
	this.title = null;
	this.active = null;
	this.position = null;
	this.expanded = true;//is a window is full expanded or rolled up (default: true)
	//this.resizable=false;//if a window can be resized (default: false)
	this.resizing=false;// while a window is resised
	//this.draggable=true;//if a window can be dragged (default: true)
	
	this.pushedObj = null;//the domObj that has, or not, been 'pushed' inside.
	
	for(var i=0;i<this.winManager.windows.length;i++){
		if(this.winManager.windows[i].id==id){
			this.domObj = this.winManager.windows[i];
		}
	}
	
	if(!this.domObj) {
		this.domObj = document.createElement('div');
		this.domObj.parent=this;
		this.domObj.id= id; 
		this.domObj.overflow= 'none';
		this.domObj.onclick=this.setActive;
		this.domObj.omousedown=this.setActive;
		this.domObj.oncontextmenu = function() { return false;};
		this.winManager.desktop.appendChild( this.domObj );
		
		//Desactivamos el boton derecho del raton
		utilidadesOBJ.noContextMenu(this);
	}
	
	return this;
};

kaWindow.prototype.setValues = function(tipoVentana,title,x,y,w,h,resizable,draggable,tituloPestanas,minW,minH) {
	var headerHeight = 24;
	var pestanasHeight = 0;
	var footerHeight = 13;
	this.title = title;
	this.active = true;
	this.expanded = true;
	this.minW=(minW)?minW:250;
	this.minH=(minH)?minH:150;
	this.resizable=resizable;
	this.draggable=draggable;
	
	var initialized=(this.domObj.firstChild)?true:false;

	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	 
	//Para la ventana de pestaņas
	if (tipoVentana == 'Menu' || tipoVentana == 'ToolTip' || tipoVentana == 'VentanaWeb'){
		headerHeight = 24;
		pestanasHeight = 20;
	}
	
	this.domObj.style.zIndex = this.winManager.windows.length+this.winManager.minZindex; 
		
	if (title == 'Mapas'){
		if (navigator.appName=="Netscape")
			headerHeight = 122;
		else
			headerHeight = 125;
	}
	
	//set framebox
	this.domObj.style.position = 'absolute';
	this.domObj.style.left = x+'px';
	this.domObj.style.top = y+'px';
	this.domObj.style.height = h + 'px' ;
	this.domObj.style.width = w + 'px';
	
	//set header
	this.headerObj = document.createElement('div');
	this.headerObj.id = 'objCabecera';
	this.headerObj.className='ventana-cabecera'; 
	this.headerObj.style.position='absolute'; 
	this.headerObj.style.top='0px'; 
	this.headerObj.style.width= w + 'px'; 
	this.headerObj.style.height= headerHeight + 'px'; 
	
		this.headerTitle = document.createElement('h1');
		this.headerTitle.innerHTML= title;
		this.headerObj.appendChild( this.headerTitle );
		
		if (tipoVentana == 'Menu'){
				// BOTON MOVER A LA DERECHA
				this.headerButton1 = document.createElement('div');
				this.headerButton1.className='ventana-izquierda1'; 
				this.headerButton1.name= tipoVentana ;
				this.headerButton1.window= this ; 
				this.headerButton1.onclick= this.ocultaIzquierda ;
				this.headerButton1.onmouseover = this.kaWinmanager_OnMouseOverRight;
		    this.headerButton1.onmouseout = this.kaWinmanager_OnMouseOutRight;  
				this.headerObj.appendChild( this.headerButton1 );
				this.domObj.appendChild( this.headerObj );
			
				// BOTON SUBIR/BAJAR
				this.headerButton2 = document.createElement('div');
				this.headerButton2.className='ventana-arriba1'; 
				this.headerButton2.id = title;
				this.headerButton2.window= this ; 
				this.headerButton2.onclick= this.toggleExpanded;
				this.headerButton2.onmouseover = this.kaWinmanager_OnMouseOverUpDown;
		    	this.headerButton2.onmouseout = this.kaWinmanager_OnMouseOutUpDown; 
				this.headerObj.appendChild(this.headerButton2);
				this.domObj.appendChild(this.headerObj);				
		
		} else if (tipoVentana == 'ToolTip'  || tipoVentana == 'ventanaMultiple' || tipoVentana ==  'streetView'  || tipoVentana == 'ventanaPolPriv'){
				//set header button BOTON CERRAR
				this.headerButton1 = document.createElement('div');
				this.headerButton1.className='ventana-cerrar1'; 
				this.headerButton1.name= tipoVentana ; 
				this.headerButton1.window= this ; 
				this.headerButton1.onclick= this.Ocultar ;
				this.headerButton1.onmouseover = this.kaWinmanager_OnMouseOverClose;
		    	this.headerButton1.onmouseout = this.kaWinmanager_OnMouseOutClose;  
		    	this.headerObj.appendChild( this.headerButton1 );
				this.domObj.appendChild( this.headerObj );
				
				/* Boton Ampliar a Patalla Completa para Mini-Sites
				this.headerButton2 = document.createElement('span');
				this.headerButton2.className='kaWinHeaderExpanderTogglerMaximize'; 
				this.headerButton2.id = title;
				this.headerButton2.style.position='absolute'; 
				this.headerButton2.style.right= '22px' ; 
				this.headerButton2.style.top= '2px' ; 
				this.headerButton2.style.width= '16px' ; 
				this.headerButton2.style.height= '16px' ; // eso -> para el bug en el ie6
				this.headerButton2.name= tipoVentana ; 
				this.headerButton2.window= this ; 
				this.headerButton2.onclick= this.toggleExpandedToolTip;
				this.headerButton2.onmouseover = this.kaWinmanager_OnMouseOverMaximize;
			  this.headerButton2.onmouseout = this.kaWinmanager_OnMouseOutMaximize; 
				this.headerObj.appendChild(this.headerButton2);
				this.domObj.appendChild(this.headerObj);
				*/
		}else if (tipoVentana == 'VentanaWeb'){
			 //set header button BOTON CERRAR
				this.headerButton1 = document.createElement('div');
				this.headerButton1.className='ventana-cerrar1';
				this.headerButton1.name= tipoVentana ; 
				this.headerButton1.window= this ; 
				this.headerButton1.onclick= this.Ocultar ;
				this.headerButton1.onmouseover = this.kaWinmanager_OnMouseOverClose;
		    	this.headerButton1.onmouseout = this.kaWinmanager_OnMouseOutClose;  
				this.headerObj.appendChild( this.headerButton1 );
				this.domObj.appendChild( this.headerObj );
				
				// BOTON SUBIR/BAJAR
				this.headerButton2 = document.createElement('div');
				this.headerButton2.className='ventana-arriba1'; 
				this.headerButton2.id = title;
				this.headerButton2.window= this ; 
				this.headerButton2.onclick= this.toggleExpanded;
				this.headerButton2.onmouseover = this.kaWinmanager_OnMouseOverUpDown;
		    	this.headerButton2.onmouseout = this.kaWinmanager_OnMouseOutUpDown; 
				this.headerObj.appendChild(this.headerButton2);
				this.domObj.appendChild(this.headerObj);
		}
		
		//set header mask (to avoid title selection)
		this.headerMask = document.createElement('div');
		this.headerMask.className='kaWinHeaderTitle'; 
		this.headerMask.style.position='absolute'; 
		this.headerMask.style.width='75%'; 
		this.headerMask.style.top = '0px';
		this.headerMask.style.left = '0px';
		this.headerMask.style.height= headerHeight-4+'px' ;
		this.headerMask.window= this ;
		if(this.draggable){
			this.headerMask.style.cursor='move'
			//Modificado por mi
			//if (!this.resizable)
				//footerHeight=0;
			// Fin de la modificacion
			this.headerMask.onmousemove= this.startDrag; 
			this.headerMask.onmouseup = this.stopDrag; 
			/*this.headerTitle.onmousemove = this.resizeMove; 
			this.headerTitle.onmouseout = this.resizeStop; */
			if (this.headerMask.captureEvents) {
			   this.headerMask.captureEvents(Event.MOUSEDOWN);
			   this.headerMask.captureEvents(Event.MOUSEUP);
			  /* this.headerTitle.captureEvents(Event.MOUSEMOVE);
			   this.headerTitle.captureEvents(Event.MOUSEOUT);*/
			}
		}
		
		this.headerObj.appendChild( this.headerMask );
		
		this.headerClear = document.createElement('div');
		this.headerClear.className='clear';
		this.headerObj.appendChild( this.headerClear );
		
		this.pestanasObj = document.createElement('div');
		this.pestanasObj.className='ventana-pestanas';
		this.pestanasObj.style.position='absolute'; 
		this.pestanasObj.style.top='24px';
		this.pestanasObj.style.width= w + 'px'; 
		this.pestanasObj.style.height= 20 + 'px';
		
		//Maquetado de Pestaņas
		if (tituloPestanas != null){
			//Barra Horizontal de Fondo
			if(tituloPestanas[0]){
				// PESTAŅA IZQUIERDA
				this.tab1 = document.createElement('div');
				this.tab1.className='ventana-pestana2';
				this.tab1.style.margin='2px 0 0 5px'; 
				this.tab1.innerHTML = tituloPestanas[0];
				this.tab1.name = tipoVentana;
				this.tab1.window= this ; 
				this.tab1.onclick= this.TabClick1 ; 	
				this.pestanasObj.appendChild( this.tab1 );
				this.domObj.appendChild( this.pestanasObj ); 
			}
			// PESTAŅA CENTRAL
			if(tituloPestanas[1]){
				this.tab2 = document.createElement('div');
				this.tab2.className='ventana-pestana1';
				this.tab2.innerHTML = tituloPestanas[1];
				this.tab2.name = tipoVentana;
				this.tab2.window= this ; 
				this.tab2.onclick= this.TabClick2 ; 
				this.pestanasObj.appendChild( this.tab2 );
				this.domObj.appendChild( this.pestanasObj );
			}	
			// PESTAŅA DERECHA
			if(tituloPestanas[2]){
				this.tab3 = document.createElement('div');
				this.tab3.className='ventana-pestana1';
				this.tab3.innerHTML = tituloPestanas[2];
				this.tab3.name = tipoVentana;
				this.tab3.window= this ; 
				this.tab3.onclick= this.TabClick3 ; 
				this.pestanasObj.appendChild( this.tab3 );
				this.domObj.appendChild( this.pestanasObj );
				
			}
			// PESTAŅA DERECHA+
			if(tituloPestanas[3]){
				this.tab4 = document.createElement('div');
				this.tab4.className='ventana-pestana1';
				this.tab4.innerHTML = tituloPestanas[3];
				this.tab4.name = tipoVentana;
				this.tab4.window= this ; 
				this.tab4.onclick= this.TabClick4; 
				this.pestanasObj.appendChild( this.tab4 );
				this.domObj.appendChild( this.pestanasObj );
			}
		}
		
	
	
	// El trasfondo es una imagen (NO imagen fondo) con estilo de transparencia

	//set bodybg
	this.bodybgObj = document.createElement('img');
	this.bodybgObj.src='./images/'+firma+'/v-fondo.gif';
	this.bodybgObj.className='ventana-fondo'; 
	this.bodybgObj.style.position='relative'; 
	this.bodybgObj.style.top='0px'; 
	this.bodybgObj.style.width= w + 'px'; 
	this.bodybgObj.style.height= (h - footerHeight - headerHeight - pestanasHeight) + 'px'; 
		
	//set body
	this.bodyObj = document.createElement('div');
	this.bodyObj.id = this.domObj.id+'bodyObj';
	
	if (this.title == 'Mapas')
		this.bodyObj.id = 'objbodyObj';
		
	this.bodyObj.className='ventana-contenido'; 
	this.bodyObj.style.position='absolute'; 
	this.bodyObj.style.top=(headerHeight + pestanasHeight)+'px'; 
	this.bodyObj.style.width= w + 'px'; 
	this.bodyObj.style.height= (h - footerHeight - headerHeight - pestanasHeight) + 'px'; 	
	this.bodyObj.appendChild( this.bodybgObj );	
	
	//set footer
	this.footerObj = document.createElement('div');
	this.footerObj.id = this.domObj.id+'footerObj';
	this.footerObj.className='ventana-pie'; 
	this.footerObj.style.position='absolute'; 
	this.footerObj.style.top=(headerHeight+pestanasHeight+parseInt(this.bodyObj.style.height))+'px'; 	
	this.footerObj.style.width= w + 'px'; 
	this.footerObj.style.height= footerHeight + 'px'; 
	
	
	//set footer button
		this.footerButton = document.createElement('span');
		this.footerButton.className='kaWinFooterResizer'; 
		this.footerButton.style.position='absolute'; 
		this.footerButton.style.right= '3px' ;
		
		if (navigator.appName=="Netscape"){
			this.footerButton.style.top= '2px' ; 
		} else {
			this.footerButton.style.top= '2px' ;
			this.footerButton.style.right= '3px' ; 
		}
		
		this.footerButton.style.width= footerHeight+'px' ; 
		this.footerButton.style.height= footerHeight+'px' ; 
		this.footerButton.window= this ; 
		this.footerButton.onmousedown= this.resize; 
		this.footerButton.onmouseup = this.resizeStop; 
		this.footerButton.onmousemove = this.resizeMove; 
		//this.footerButton.onmouseout = this.resizeStop; 
	
		if (this.footerButton.captureEvents) {
		   this.footerButton.captureEvents(Event.MOUSEDOWN);
		   this.footerButton.captureEvents(Event.MOUSEUP);
		   this.footerButton.captureEvents(Event.MOUSEMOVE);
		  // this.footerButton.captureEvents(Event.MOUSEOUT);
		}
	

	if(this.resizable)
		this.footerObj.appendChild( this.footerButton );
	
	if (tipoVentana != 'ToolTip' && tipoVentana != 'streetView')
		this.domObj.appendChild( this.footerObj );	
		
	if (tipoVentana == 'ToolTip'){
		this.pico = document.createElement('div');
		//this.pico.className = 'picoVentanaPestanas';
		this.pico.className = 'pico';
		this.pico.style.bottom="-20px";
		this.bodyObj.appendChild( this.pico );
		this.domObj.style.display='none'; 
	}
	this.domObj.appendChild( this.bodyObj );
	
	if (navigator.appName=="Netscape" && this.title =="Mapas"){
		this.domObj.style.visibility='visible';
	} else {
		this.domObj.style.display=''; 
	}
	
	return this;
	 
};


kaWindow.prototype.duplicateContent = function( obj ){
	 this.bodyObj.appendChild(obj.cloneNode(true));
};

kaWindow.prototype.setContent = function( text ){
	if(this.pushedObj) {
		this.pushedObj.innerHTML = text;
	} else this.bodyObj.innerHTML = text;
};

kaWindow.prototype.setTitle = function( text ){
	this.domObj.firstChild.firstChild.innerHTML = text;
};

kaWindow.prototype.setZindex = function( z ){
	this.position=z;
	this.domObj.style.zIndex = z;
};

kaWindow.prototype.resize = function( e ){
	
	var thisWindow=this.window;
    e = (e)?e:((event)?event:null);   
     
     thisWindow.resizing=true;
     thisWindow.initX=e.clientX;
     thisWindow.initY=e.clientY;
	 
    document.onmousemove = thisWindow.resizeMove ;
    document.onmouseup   = thisWindow.resizeStop;
	//document.onmouseout     = thisWindow.resizeStop;
	if (document.captureEvents) {	   
		   document.captureEvents(Event.MOUSEUP);
		   document.captureEvents(Event.MOUSEMOVE);
		  //document.captureEvents(Event.MOUSEOUT);
	}
		
	document.win=thisWindow;
    e=null;
};

kaWindow.prototype.resizeMove  = function( e ){
    var viewport = getRawObject('map');
    var thisWindow=(this.window)?this.window:this.win;
	e = (e)?e:((event)?event:null); 
	var xMov = 0;
	var yMov = 0;
    if(thisWindow.resizing) {
		if(thisWindow.initX!=e.clientX)  xMov=(thisWindow.initX-e.clientX);
		if(thisWindow.initY!=e.clientY)  yMov=(thisWindow.initY-e.clientY);

        var oX=thisWindow.initX;
        var oY=thisWindow.initY;

		var startW= thisWindow.w; 
		var startH=thisWindow.h;

		var thisBody=thisWindow.bodyObj;
		var thisBodybg=thisWindow.bodybgObj;
		var thisHeader=thisWindow.headerObj;
		var thisFooter=thisWindow.footerObj;
		var startW=thisWindow.domObj.style.width;
		var startWindowH=thisWindow.domObj.style.height;
		var startBodyH=thisWindow.bodyObj.style.height;
		var startBodybgH=thisWindow.bodybgObj.style.height;
		var startH=thisWindow.domObj.style.height;
    var startFooterTop=thisWindow.footerObj.style.top;	

		var newW = (parseInt(startW)-xMov);
		var newH = (parseInt(startH)-yMov);
		var newWindowH = (parseInt(startWindowH)-yMov);
		var newBodyH = (parseInt(startBodyH)-yMov);
		var newBodybgH = (parseInt(startBodybgH)-yMov);
		var newFooterTop = (parseInt(startFooterTop)-yMov);

		if(newW>=thisWindow.minW && oX<=parseInt(viewport.style.width) && xMov<=parseInt(viewport.style.width)){
			if ( (thisWindow.headerTitle.innerHTML).substr(2) != 'squedas')
			thisWindow.domObj.style.width=thisBody.style.width=thisBodybg.style.width=thisHeader.style.width=thisFooter.style.width=newW+'px';
		}
		
		if(newH>=thisWindow.minH && oY<=parseInt(viewport.style.height) && yMov<=parseInt(viewport.style.height)){ 
		       	thisWindow.domObj.style.height=newWindowH+'px';
			thisBody.style.height=newBodyH+'px';
			thisBodybg.style.height=newBodybgH+'px';
			thisFooter.style.top=newFooterTop+'px';
		}
		
		if(thisBody.firstChild){
			if(newW>=thisWindow.minW)thisBody.firstChild.style.width= newW-2 +'px'; 
			if(newH>=thisWindow.minH)thisBody.firstChild.style.height= newBodyH-3 +'px'; 
		}
	
		//reset init positions
		thisWindow.initX=e.clientX;
		thisWindow.initY=e.clientY;
    }
};
kaWindow.prototype.resizeStop  = function( e ){
	var viewport = getRawObject('map');
	var thisWindow=(this.window)?this.window:this.win;
	if(thisWindow.resizing) {
		document.onmousemove = null ;
		document.onmouseup   = null;
 		document.onmouseuout   = null;
		document.win=null;
		e = (e)?e:((event)?event:null); 
        thisWindow.resizing=false;
        //dirty stuff just for kaMap. to be reimplemented
        //if(myKaMap) myKaMap.resize();
        
        //Controlamos que el ancho del objeto no sobresalga de la pantalla
        if ((getObjectLeft(thisWindow.domObj) + getObjectWidth(thisWindow.domObj)) > parseInt(viewport.style.width) ) {
        	
        	if  (thisWindow.headerTitle.innerHTML == 'Busca Tu Tienda Milar') {
        		windowTabs.headerButton2.onclick();
        	} else if (thisWindow.headerTitle.innerHTML == 'Mapas') {
        		newW=parseInt(viewport.style.width) - getObjectLeft(thisWindow.domObj);
        		var thisBody=thisWindow.bodyObj;
			var thisBodybg=thisWindow.bodybgObj;
			var thisHeader=thisWindow.headerObj;
			var thisFooter=thisWindow.footerObj;
	        	thisWindow.domObj.style.width=thisBody.style.width=objeto.style.width=thisBodybg.style.width=thisHeader.style.width=thisFooter.style.width=newW+'px';
        	}
        }
        /*
        //Controlamos que el alto del objeto no sobresale de la pantalla
        if ((getObjectTop(thisWindow.domObj) + getObjectHeight(thisWindow.domObj)) > parseInt(viewport.style.height) ) {
        	
        	if (thisWindow.headerTitle.innerHTML == 'Mapas') {
        		kaLegend_ajustaTamano();
        	} else if (thisWindow.headerTitle.innerHTML == 'Busca Tu Tienda Milar') {
        		windowTabs.headerButton2.onclick();
        	} 
        	
        } */
    }
         
};

kaWindow.prototype.toggleExpanded  = function(){
	
	var objeto="#"+this.window.domObj.id;
	
	if(this.window.expanded) {
		/*
		this.window.domObj.style.height='0px';
		this.window.bodyObj.style.display='none';
		this.window.bodybgObj.style.display='none';
		this.window.footerObj.style.display='none';
		this.window.headerButton2.style.height= 16+'px' ;
		
		$("#"+this.window.domObj.id+"bodyObj").slideUp("slow");
		$("#"+this.window.domObj.id+"footerObj").slideUp("slow");
		*/
		
		$(objeto+"footerObj").slideUp("fast", function(){$(objeto+"bodyObj").slideUp("slow");});
		
		if (this.window.domObj.id == 'VentanaWeb'){
			$("#ventanaPestanasToolTip").fadeIn("slow");
			this.window.domObj.style.height = '40px';
		}
		
		this.window.headerButton2.className='ventana-abajo2';
		
	} else { 
		/*
		this.window.bodyObj.style.display='block';
		this.window.bodybgObj.style.display='block';
		this.window.footerObj.style.display='block';
		this.window.domObj.style.height=this.window.h+'px';
		
		$("#"+this.window.domObj.id+"bodyObj").slideDown("slow");
		$("#"+this.window.domObj.id+"footerObj").slideDown("slow");
		*/
		
		$(objeto+"bodyObj").slideDown("slow", function(){$(objeto+"footerObj").slideDown("fast");});
		
		if (this.window.domObj.id == 'VentanaWeb'){
			$("#ventanaPestanasToolTip").fadeOut("slow");
			this.window.domObj.style.height = document.getElementById('VentanaWebbodyObj').style.height;
		}
			
		this.window.headerButton2.className='ventana-arriba2';
	}
	
	this.window.expanded=(this.window.expanded)?false:true;

};

kaWindow.prototype.toggleExpandedToolTip = function(){ 
		
	//map.removeOverlay(ToolTipInstanceTabWindow);
	if (this.window)
		this.window.headerButton2.onmouseout();
		
	$("#ventanaPestanasToolTip").fadeOut("slow");
	
	if (parseInt($("#ventanaPestanas").css('left')) > -1){
	 	var anchoTabsWindows = parseInt($("#ventanaPestanas").css('width'));
	 	$("#menu").fadeOut("slow", function(){$("#ventanaPestanas").animate({"left": "-="+anchoTabsWindows+"px"}, "slow", function(){windowWeb.domObj.style.display = 'block';});});
	} else
		$("#menu").fadeOut("slow", function(){windowWeb.domObj.style.display = 'block';});
	
	windowWeb.Agrandar(windowWeb, 'pantallaCompleta');	
	ventanaMiniSites.tab1.onclick();
	
};

kaWindow.prototype.Ocultar  = function(){//alert(this.window.headerButton1.name);
		
		if (this.window.headerButton1.name == 'ToolTip'){ 
			eliminaToolTip();
			if (ventanaMiniSites.domObj.style.display=='block')
				ventanaMiniSites.headerButton1.onclick();
				
			 
		} else if (this.window.headerButton1.name == 'VentanaWeb'){
			//map.addOverlay(ToolTipInstanceTabWindow);
			$("#VentanaWeb").fadeOut("fast", function(){$("#ventanaPestanasToolTip").fadeIn("fast");});
			$("#menu").fadeIn("slow");
			
		} else if ((this.window.headerButton1.name == 'ventanaMultiple') || (this.window.headerButton1.name == 'streetView')){
			
			if (streetViewHandler){ 
				GEvent.removeListener(streetViewHandler);
				//Elimino el Icono del Mapa
				if(iconoStreeView != null)
					map.removeOverlay(iconoStreeView);
				//Libero Recursos usados por el Flash
				myPanorama2.remove();
				//Quito la capa Street-View
				map.removeOverlay(streeViewOverlay);
				map.getDragObject().setDraggableCursor("auto"); 
				streetViewHandler = null;
			}
				
			$("#"+this.window.headerButton1.name).fadeOut("slow");
		
		} else if (this.window.headerButton1.name == 'ventanaPolPriv'){ 
			$("#ventanaPolPriv").fadeOut("fast");

		} 
		
		this.window.headerButton1.onmouseout();
		$("#DragZoomdivApantallamiento").css({display: 'none',cursor: 'default'});
};

kaWindow.prototype.TabClick1  = function(){
	
		if (!this.window.expanded){
			this.window.headerButton2.onclick();
			this.window.headerButton2.className='ventana-arriba1';
		}
		
		if(this.window.tab1){ 
			this.window.tab1.style.zIndex = 1000;
			this.window.tab1.className = 'ventana-pestana2';
		}
		
		if(this.window.tab2){ 
       this.window.tab2.style.zIndex = 5; 
       this.window.tab2.className = 'ventana-pestana1'; 
    } 

		if(this.window.tab3){
			this.window.tab3.style.zIndex = 5;
			this.window.tab3.className = 'ventana-pestana1';
		}
		 
		if(this.window.tab4)
			this.window.tab4.className = 'ventana-pestana1';
		 
		$("#tab1"+this.window.tab1.name).css("display","block");
		$("#tab2"+this.window.tab1.name).css("display","none");
		$("#tab3"+this.window.tab1.name).css("display","none");
		$("#tab4"+this.window.tab1.name).css("display","none");
		
		//Mostramos de carrusel de fotos
		document.getElementById("divCarruselFotos").style.display = 'block';
		document.getElementById("dataVentanaWeb").style.overflowY = 'auto';
};

kaWindow.prototype.TabClick2  = function(){ 
		
		if (!this.window.expanded){
			this.window.headerButton2.onclick();
			this.window.headerButton2.className='ventana-arriba1';			
		}
		
		this.window.tab2.style.zIndex = 1000;
		
		if(this.window.tab1){ 
			this.window.tab1.style.zIndex = 1000;
			this.window.tab1.className = 'ventana-pestana1';
		}
		
		if(this.window.tab3){
			this.window.tab3.style.zIndex = 5;
			this.window.tab3.className = 'ventana-pestana1';
		}
		
		if(this.window.tab4)
			this.window.tab4.className = 'ventana-pestana1';
			
		this.window.tab2.className = 'ventana-pestana2';
		
		$("#tab2"+this.window.tab2.name).css("display","block");
		$("#tab1"+this.window.tab2.name).css("display","none");
		$("#tab3"+this.window.tab2.name).css("display","none");
		$("#tab4"+this.window.tab2.name).css("display","none");
		
		//Mostramos de carrusel de fotos
		document.getElementById("divCarruselFotos").style.display = 'block';
		document.getElementById("dataVentanaWeb").style.overflowY = 'auto';
};

kaWindow.prototype.TabClick3  = function(){
	
		if (!this.window.expanded){
			this.window.headerButton2.onclick();
			this.window.headerButton2.className='ventana-arriba1';
		}
		
		if(this.window.tab1){ 
			this.window.tab1.style.zIndex = 5;
			this.window.tab1.className = 'ventana-pestana1';
		}
		
		this.window.tab3.style.zIndex = 1000;
		 
		if(this.window.tab2){ 
			this.window.tab2.style.zIndex = 5; 
			this.window.tab2.className = 'ventana-pestana1';
		}
		
		if(this.window.tab4)
			this.window.tab4.className = 'ventana-pestana1';
			
		this.window.tab3.className = 'ventana-pestana2';
		
		$("#tab3"+this.window.tab3.name).css("display","block");
		$("#tab2"+this.window.tab3.name).css("display","none");
		$("#tab4"+this.window.tab3.name).css("display","none");
		$("#tab1"+this.window.tab3.name).css("display","none");
		 
		if (this.window.domObj.id == 'ventanaPestanasToolTip'){ 
			for(i=0;i<100;i++){
				if(document.getElementById("panoflash"+i)){
					document.getElementById("panoflash"+i).style.width = document.getElementById('ventanaPestanasToolTipbodyObj').style.width;
					return;
				}
			}
		}else if (this.window.domObj.id == 'VentanaWeb'){
			//Street View
			document.getElementById("tab3VentanaWeb").style.height = this.window.bodyObj.style.height;
			var puntoX = variablesGlobalesOBJ.tiendaSeleccionada[0]["point"].lat();
			var puntoY = variablesGlobalesOBJ.tiendaSeleccionada[0]["point"].lng();
			var coordenadas = new GLatLng(puntoX, puntoY);																																					
			
			var panoramaOptions = {latlng:coordenadas,zoom:1};
			myPanorama = new GStreetviewPanorama(document.getElementById("tab3VentanaWeb"),panoramaOptions);
			
	    //Fin Street View
		}
		
		//Ocultamos de carrusel de fotos
		document.getElementById("divCarruselFotos").style.display = 'none';
		 
};

kaWindow.prototype.TabClick4  = function(){
	
		if (!this.window.expanded){
			this.window.headerButton2.onclick();
			this.window.headerButton2.className='ventana-arriba1';			
		}
		
		this.window.tab4.style.zIndex = 1000;
		this.window.tab1.style.zIndex = 5;
		this.window.tab2.style.zIndex = 5;
		this.window.tab3.style.zIndex = 5;
		
		this.window.tab1.className = 'ventana-pestana1';
		this.window.tab2.className = 'ventana-pestana1';
		this.window.tab3.className = 'ventana-pestana1';
		this.window.tab4.className = 'ventana-pestana2';
		
		$("#tab4"+this.window.tab1.name).css("display","block");
		$("#tab2"+this.window.tab1.name).css("display","none");
		$("#tab1"+this.window.tab1.name).css("display","none");
		$("#tab3"+this.window.tab1.name).css("display","none");
		
		//Ocultamos de carrusel de fotos 
    document.getElementById("divCarruselFotos").style.display = 'none'; 
    $("#tab4"+this.window.tab1.name).css("width",document.body.offsetWidth); 
    document.getElementById("tab4VentanaWeb").firstChild.style.width = document.body.offsetWidth - 10 + 'px'; 
    document.getElementById("tab4VentanaWeb").firstChild.style.height = parseInt(document.getElementById("dataVentanaWeb").style.height) - 14 + 'px'; 
    document.getElementById("tab4VentanaWeb").firstChild.style.margin = '7px 5px 7px 5px'; 
    document.getElementById("dataVentanaWeb").style.overflowY = 'hidden'; 

};

kaWindow.prototype.Agrandar  = function(objeto, opciones){

	var vieportH = document.body.offsetHeight;
	var vieportW = document.body.offsetWidth; 
	
	var cuerpo = 33;
	var y = 27;
	
	cuerpo = cuerpo + 20;
	
	var alto = vieportH - 27;
	var altoStreeView = vieportH/2;
	
	/*
	this.window.domObj.style.height = alto + 'px';
	this.window.bodyObj.style.height = (alto - cuerpo) + 'px';
	this.window.bodybgObj.style.height = alto - cuerpo + 'px';
	this.window.footerObj.style.top = vieportH - (13 + y) + 'px';
	//pushedObj donde va el contenido de la ventana
	this.window.pushedObj.style.height = alto - cuerpo + 'px';
	*/
	if (opciones == 'pantallaCompleta'){ 
		objeto.domObj.style.height = alto + 'px';
		objeto.domObj.style.width = vieportW + 'px';
		objeto.headerObj.style.width= vieportW + 'px'; 
		objeto.pestanasObj.style.width = vieportW + 'px';
		objeto.bodyObj.style.height = (alto - cuerpo - 4) + 'px';
		objeto.bodyObj.style.width = vieportW + 'px';
		//objeto.bodyObj.style.overflowY = 'auto';
		//objeto.bodyObj.style.overflowX = 'hidden';
		objeto.bodybgObj.style.height = alto - cuerpo + 'px';
		objeto.bodybgObj.style.width = vieportW + 'px';
		objeto.footerObj.style.top = vieportH - (13 + y) + 'px';
		objeto.footerObj.style.width = vieportW + 'px';
		document.getElementById("dataVentanaWeb").style.width = '100%';
		document.getElementById("contactaTienda").style.width = document.getElementById("detalleTienda").style.width = vieportW - 375 + 'px';
		
		//pushedObj donde va el contenido de la ventana
		objeto.pushedObj.style.height = alto - cuerpo + 'px';
		
		//Cargo Galeria de imagenes
		if (document.getElementById("tab3VentanaWeb").style.display == 'block' || document.getElementById("tab4VentanaWeb").style.display == 'block'){
			return;
		}else {
			document.getElementById("divCarruselFotos").style.display = 'block';
			utilidadesOBJ.montarCarrusel();
		}
		
		//Genero la ficha de la tienda
		var detalleTienda = '';
		
		//detalleTienda += "<div class='minisite-banner'><img style='height:120px;align:right;width:99%' src='images/LP/generico-banner.jpg'></div>";	
		detalleTienda += "<div class='minisite-banner'></div>";	
		detalleTienda += "<h1>"+variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][0]+"</h1>";
		detalleTienda += "<p class='flecha'>Direcci&oacute;n:</p><p class='dato'>"+variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][1]+"</p>";
		detalleTienda += "<div class='clear'></div><div class='minisite-intercalar'><p class='flecha'>C.P.:</p><p class='dato'>"+variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][2]+"</p></div>";
		detalleTienda += "<div class='clear'></div><p class='flecha'>Poblaci&oacute;n/Provincia:</p><p class='dato'>"+variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][3]+"</p>";
 		detalleTienda += "<div class='clear'></div><div class='minisite-intercalar'><p class='flecha'>Tel&eacute;fono:</p><p class='dato'>921 43 82 54</p></div>";
		detalleTienda += "<div class='clear'></div><p class='flecha'>Fax:</p><p class='dato'>921 43 46 85</p>";
		detalleTienda += "<div class='clear'></div><div class='minisite-intercalar'><p class='flecha'>E-Mail:</p><p class='dato'>"+(variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][6]).split(':')[1]+"</p></div></div>";
		document.getElementById("detalleTienda").innerHTML = detalleTienda;
		//Actualizo el formulario de contacto de la tienda
		document.getElementById("formContactoTienda").innerHTML = 'Puede comunicarse con nosotros de forma inmediata y directa, solamente rellene este formulario y en breve desde ' + variablesGlobalesOBJ.tiendaSeleccionada[0]["infTienda"][0] + ' nos pondremos en contacto con Usted.';
		
	}else if (opciones == 'streetView'){ 
		alto = altoStreeView;
		objeto.domObj.style.height = alto + 'px';
		objeto.domObj.style.width = vieportW + 'px';
		objeto.headerObj.style.width= vieportW + 'px'; 
		objeto.bodyObj.style.height = (alto - 20) + 'px';
		objeto.bodyObj.style.width = vieportW + 'px';
		objeto.bodybgObj.style.height = alto - 20 + 'px';
		objeto.bodybgObj.style.width = vieportW + 'px';
		//objeto.footerObj.style.top = vieportH - (13 + y) + 'px';
		//objeto.footerObj.style.width = vieportW + 'px';
		//pushedObj donde va el contenido de la ventana
		//objeto.pushedObj.style.height = alto  + 'px';
		document.getElementById("streeViewPanel").style.width = vieportW + 'px';
		document.getElementById("streeViewPanel").style.height = (alto - 20) + 'px';
		
		objeto.domObj.style.left='0px';
		objeto.domObj.style.top= alto +'px';
		
	} else if (opciones == 'polPrivacidad'){ 
		vieportW = vieportW - 400;
		alto = alto - 50;
		
		objeto.domObj.style.height = alto + 'px';
		objeto.pestanasObj.style.width= vieportW + 'px'; 
		objeto.domObj.style.width = vieportW + 'px';
		objeto.headerObj.style.width= vieportW + 'px'; 
		objeto.bodyObj.style.height = (alto - 20) + 'px';
		objeto.bodyObj.style.width = vieportW + 'px';
		objeto.bodybgObj.style.height = alto - 20 + 'px';
		objeto.bodybgObj.style.width = vieportW + 'px';
		objeto.footerObj.style.position='absolute';
		objeto.footerObj.style.top= parseInt(objeto.bodyObj.style.height) + 13 + 'px';
		objeto.footerObj.style.width = vieportW + 'px';
		//pushedObj donde va el contenido de la ventana
		objeto.pushedObj.style.height = alto - (4 + y)  + 'px';
		document.getElementById("politicaPrivacidad").style.width = '100%'; 
		objeto.domObj.style.left='330px';
		objeto.domObj.style.top= '62px';

	} else {
		objeto.domObj.style.height = alto + 'px';
		objeto.bodyObj.style.height = (alto - cuerpo) + 'px';
		objeto.bodybgObj.style.height = alto - cuerpo + 'px';
		objeto.footerObj.style.top = vieportH - (13 + y) + 'px';
		//pushedObj donde va el contenido de la ventana
		objeto.pushedObj.style.height = alto - cuerpo + 'px';
		
		document.getElementById("resultadosTiendasCarcanas").style.height = (alto - cuerpo - 105) + 'px';
		document.getElementById("directions").style.height = (alto - cuerpo - 170) + 'px';
		document.getElementById("tab3MenuBuscador").style.height = (alto - cuerpo - 36) + 'px';
		
	}
};

kaWindow.prototype.ocultaIzquierda  = function(){
	$("#menu").click();
}
kaWindow.prototype.setActive = function(){
	this.parent.winManager.setActive(this);
};

kaWindow.prototype.pushContent = function( obj, estado ){
	var pushedObj = obj;
	var targetObj = this.bodyObj;
	this.pushedObj = obj;
	targetObj.appendChild(pushedObj);
	pushedObj.style.position = 'absolute';
	pushedObj.style.height = parseInt(targetObj.style.height)-3+'px';
	pushedObj.style.width = parseInt(targetObj.style.width)-2+'px';
	pushedObj.style.top = 0;
	pushedObj.style.left = 0;
	
	if (estado)
		pushedObj.className = 'visibilidad';
	else
		pushedObj.className = targetObj.className;
};

kaWindow.prototype.replaceContent = function(){
	
	var targetObj = this.bodyObj;
	
	for(var i=0;i<targetObj.childNodes.length;i++){
	//Oculto la capa visible y viceversa
		if (targetObj.childNodes[i].className == 'visibilidad')
			targetObj.childNodes[i].className = targetObj.className;
		else
			targetObj.childNodes[i].className = 'visibilidad';
	}
	cierraMenus('N1');
	cierraMenus('N2');
};

kaWindow.prototype.startDrag = function(  ){
	var minX=0;
	var maxX=parseInt(getObjectWidth(this.window.winManager.desktop))-153;
	var minY=0;
	var maxY=parseInt(getObjectHeight(this.window.winManager.desktop))-23;
	//Drag.init(sensible obj, obj to drag, minX,maxX,minY,maxY)
	Drag.init(this,this.window.domObj,0,maxX,0,maxY);
	
};
kaWindow.prototype.stopDrag = function(  ){

};

// Controlan el aspecto de los botones de las ventanas cuando el raton esta OVER
kaWindow.prototype.kaWinmanager_OnMouseOverUpDown  = function(){
    	
   if (this.window.headerButton2.className == 'ventana-abajo1') 
   	this.window.headerButton2.className='ventana-abajo2';
   else if (this.window.headerButton2.className == 'ventana-arriba1') 
   	this.window.headerButton2.className='ventana-arriba2';
};

kaWindow.prototype.kaWinmanager_OnMouseOutUpDown  = function(){
   if (this.window.headerButton2.className == 'ventana-abajo2') {
   	this.window.headerButton2.className='ventana-abajo1';
   } else {
   	this.window.headerButton2.className='ventana-arriba1';
   }
};

kaWindow.prototype.kaWinmanager_OnMouseOverClose  = function(){
    	
   if (this.window.headerButton1.className == 'ventana-cerrar1') {
   	this.window.headerButton1.className='ventana-cerrar2';
   }
};

kaWindow.prototype.kaWinmanager_OnMouseOutClose  = function(){

   if (this.window.headerButton1.className == 'ventana-cerrar2') 
   	this.window.headerButton1.className='ventana-cerrar1';
};

kaWindow.prototype.kaWinmanager_OnMouseOverMaximize  = function(){
    	
   if (this.window.headerButton2.className == 'kaWinHeaderExpanderTogglerMaximize') {
   	this.window.headerButton2.className='kaWinHeaderExpanderTogglerMaximizeOver';
   }
};

kaWindow.prototype.kaWinmanager_OnMouseOutMaximize  = function(){

   if (this.window.headerButton2.className == 'kaWinHeaderExpanderTogglerMaximizeOver') 
   	this.window.headerButton2.className='kaWinHeaderExpanderTogglerMaximize';
};

kaWindow.prototype.kaWinmanager_OnMouseOverRight  = function(){
   this.window.headerButton1.className='ventana-izquierda2';
};

kaWindow.prototype.kaWinmanager_OnMouseOutRight  = function(){
   this.window.headerButton1.className='ventana-izquierda1';
};

kaWindow.prototype.mouseWheelGoogleEnable  = function(){
	map.enableScrollWheelZoom();	
}

kaWindow.prototype.mouseWheelGoogleDisable  = function(){
	map.disableScrollWheelZoom();	
}
