function AbrirAguarde(id_inmueble,tipo_oper,url) {
var opciones="toolbar=no, location=no, directories=no,  status=no, scrollbars=no, menubar=no, width=400, height=215, top=85, left=40";
var pagina=url+"bajar_pdf.php?ID_INMUEBLE="+id_inmueble+"&OPER="+tipo_oper;
window.open(pagina,"",opciones);
}
function AbrirAguardeTipo(id_promo,num_dorm,tipo_oper,url) {

var opciones="toolbar=no, location=no, directories=no,  status=no, scrollbars=no, menubar=no, width=400, height=215, top=85, left=40";
var pagina=url+"bajar_pdf.php?ID_PROMOCION="+id_promo+"&NUM_DORMITORIOS="+num_dorm+"&OPER="+tipo_oper;
window.open(pagina,"",opciones);
}

function maxWindow()
{
      if (document.all || document.layers)
      {
            self.moveTo(0,0);
            self.resizeTo(screen.availWidth,screen.availHeight);
      }
}

function posicionar_logo_cabecera()
{
    if(screen.width==1024)
    {
        document.getElementById("logoPortal").style.left="20px";
    }
    else if(screen.width==1680)
    {
        document.getElementById("logoPortal").style.left="345px";
    }
    else if(screen.width==1280)
    {
        document.getElementById("logoPortal").style.left="145px";
    }
    else
    {
        document.getElementById("logoPortal").style.left="20px";
    }
}


function sgm_addToBookmarks(url,title) {
	/*  */
	// FireFox
	if (window.sidebar && window.sidebar.addPanel){
		window.sidebar.addPanel(title,url,'');
	}
	// Explorer
	else if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(url,title);
	}
	// Resto (CTRL + D): Chrome, Safari, Opera
	else{
		//if(window.navigator.appName == "Netscape")
         	alert("Presione Crtl+D para agregar este sitio en sus Bookmarks");
	}
}

function selmenu(id)
{
    if (document.getElementById(id).className != 'menu_on')
        {
            document.getElementById(id).className = 'menu_on';
        }
}

function desselmenu(id)
{
       switch (id)
    {
        case "pres":
           if (document.getElementById('dvpresentacion').style.display == 'none')
                {
                  document.getElementById('pres').className = 'menu_off';
                }
        break;
        case "gale":
           if (document.getElementById('dvpresentacion').style.display != 'none')
                {
                  document.getElementById('gale').className = 'menu_off';
                }
           else 
               {
                  var divs = document.getElementsByTagName('div');
                 for (i2=0; i2 < divs.length; i2++)
                {
                    if(divs[i2].id.indexOf('dvgaleria_')!=-1)
                    {
                        var strSolapa=divs[i2].id.substring(10,divs[i2].id.length);
                        if (document.getElementById('dvgaleria_' + strSolapa).style.display == 'none')
                            {
                                
                                document.getElementById('gale').className = 'menu_off';
                                break;
                            }
                    }
                }
               }
        break;
        case "ubi":
           if (document.getElementById('dvpresentacion').style.display != 'none')
                {
                  document.getElementById('ubi').className = 'menu_off';
                }
           else if (document.getElementById('dvubicacion').style.display == 'none')
               {
                 document.getElementById('ubi').className = 'menu_off';
               }
        break;
        case "memo":
           if (document.getElementById('dvmemoria').style.display == 'none')
                {
                  document.getElementById('memo').className = 'menu_off';
                }
        break;
       case "cont":
          if (document.getElementById('dvpresentacion').style.display != 'none')
                {
                  document.getElementById('cont').className = 'menu_off';
                }
           else if (document.getElementById('dvcontacto').style.display == 'none')
               {
                 document.getElementById('cont').className = 'menu_off';
               }
        break;
    }

}


function marcarmenu(id)
{
    document.getElementById(id).className = 'menu_on';
    switch (id)
    {
        case "pres":
          if (objExiste(document.getElementById('ubi')))
          {document.getElementById('ubi').className = 'menu_off';}
          if (objExiste(document.getElementById('gale')))
          {document.getElementById('gale').className = 'menu_off';}
          if (objExiste(document.getElementById('memo')))
          {document.getElementById('memo').className = 'menu_off';}
          if (objExiste(document.getElementById('cont')))
          {document.getElementById('cont').className = 'menu_off';}
        break;
        case "gale":
          if (objExiste(document.getElementById('ubi')))
          {document.getElementById('ubi').className = 'menu_off';}
          if (objExiste(document.getElementById('pres')))
          {document.getElementById('pres').className = 'menu_off';}
          if (objExiste(document.getElementById('memo')))
          {document.getElementById('memo').className = 'menu_off';}
          if (objExiste(document.getElementById('cont')))
          {document.getElementById('cont').className = 'menu_off';}
        break;
        case "ubi":
          if (objExiste(document.getElementById('pres')))
          {document.getElementById('pres').className = 'menu_off';}
          if (objExiste(document.getElementById('gale')))
          {document.getElementById('gale').className = 'menu_off';}
          if (objExiste(document.getElementById('memo')))
          {document.getElementById('memo').className = 'menu_off';}
          if (objExiste(document.getElementById('cont')))
          {document.getElementById('cont').className = 'menu_off';}
        break;
        case "memo":
          if (objExiste(document.getElementById('ubi')))
          {document.getElementById('ubi').className = 'menu_off';}
          if (objExiste(document.getElementById('gale')))
          {document.getElementById('gale').className = 'menu_off';}
          if (objExiste(document.getElementById('pres')))
          {document.getElementById('pres').className = 'menu_off';}
          if (objExiste(document.getElementById('cont')))
          {document.getElementById('cont').className = 'menu_off';}
        break;
        case "cont":
          if (objExiste(document.getElementById('ubi')))
          {document.getElementById('ubi').className = 'menu_off';}
          if (objExiste(document.getElementById('gale')))
          {document.getElementById('gale').className = 'menu_off';}
          if (objExiste(document.getElementById('memo')))
          {document.getElementById('memo').className = 'menu_off';}
          if (objExiste(document.getElementById('pres')))
          {document.getElementById('pres').className = 'menu_off';}
        break;
    }
}

function mostrarmenus(capa)
{
    document.getElementById(capa).style.display = 'block';
    switch (capa)
    {
       case 'dvMenuInformacion':
               document.getElementById('nivel3').style.display = 'block';
               if (objExiste(document.getElementById('dvMenuDocumentacion')))
                   {document.getElementById('dvMenuDocumentacion').style.display = 'none';}
                if (objExiste(document.getElementById('pes2')))
                   {document.getElementById('pes2').style.backgroundPosition = '0 0';}
               document.getElementById('dvMenuPreciosDisponibles').style.display = 'none';
               document.getElementById('pes1').style.backgroundPosition = '0 -30px';
               document.getElementById('pes3').style.backgroundPosition = '0 0';
               break;
       case 'dvMenuDocumentacion':
               document.getElementById('nivel3').style.display = 'none';
               document.getElementById('dvMenuInformacion').style.display = 'none';
               document.getElementById('dvMenuPreciosDisponibles').style.display = 'none';
               document.getElementById('pes3').style.backgroundPosition = '0 0';
               document.getElementById('pes1').style.backgroundPosition = '0 0';
               document.getElementById('pes2').style.backgroundPosition = '0 -30px';
               break;
       case 'dvMenuPreciosDisponibles':
               if (objExiste(document.getElementById('dvMenuDocumentacion')))
                  {document.getElementById('dvMenuDocumentacion').style.display = 'none';}
               if (objExiste(document.getElementById('pes2')))
                  {document.getElementById('pes2').style.backgroundPosition = '0 0';}
               document.getElementById('dvMenuInformacion').style.display = 'none';
               document.getElementById('nivel3').style.display = 'none';
               document.getElementById('pes3').style.backgroundPosition = '0 -30px';
               document.getElementById('pes1').style.backgroundPosition = '0 0';
              break;
   }
}

function mostrarcapas(capa)
{
    var divs = document.getElementsByTagName('div');

    if (capa == "dvgaleria" || capa == "dvpresentacion")
    {

        for (i2=0; i2 < divs.length; i2++)
        {
            if(divs[i2].id.indexOf('dvgaleria_')!=-1)
            {
                var strSolapa=divs[i2].id.substring(10,divs[i2].id.length);
                document.getElementById('dvgaleria_' + strSolapa).style.display = 'block';

            }
        }
       if (capa == "dvpresentacion")
        {
            document.getElementById(capa).style.display = 'block';
        }
    }
    else
    {

        for (i2=0; i2 < divs.length; i2++)
        {
            if(divs[i2].id.indexOf('dvgaleria_')!=-1)
            {
                var strcapa=divs[i2].id.substring(10,divs[i2].id.length);
                document.getElementById('dvgaleria_' + strcapa).style.display = 'none';

            }
        }

        document.getElementById(capa).style.display = 'block';
    }

    switch (capa)
    {
       case 'dvpresentacion':
               if (objExiste(document.getElementById('dvubicacion')))
                  {document.getElementById('dvubicacion').style.display = 'block';}
               if (objExiste(document.getElementById('dvmemoria')))
                  {document.getElementById('dvmemoria').style.display = 'none';}
               if(objExiste(document.getElementById('dvcontacto')))
                  {document.getElementById('dvcontacto').style.display = 'block';}
                break;
       case 'dvubicacion':
               if (objExiste(document.getElementById('dvpresentacion')))
                   {document.getElementById('dvpresentacion').style.display = 'none';}
               if (objExiste(document.getElementById('dvmemoria')))
                   {document.getElementById('dvmemoria').style.display = 'none';}
               if (objExiste(document.getElementById('dvcontacto')))
                   {document.getElementById('dvcontacto').style.display = 'none';}
                break;
       case 'dvgaleria':
                if(objExiste(document.getElementById('dvubicacion')))
                    {document.getElementById('dvubicacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvpresentacion')))
                    {document.getElementById('dvpresentacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvmemoria')))
                    {document.getElementById('dvmemoria').style.display = 'none';}
                if(objExiste(document.getElementById('dvcontacto')))
                    {document.getElementById('dvcontacto').style.display = 'none';}
              break;
       case 'dvmemoria':
                if(objExiste(document.getElementById('dvubicacion')))
                    {document.getElementById('dvubicacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvpresentacion')))
                    {document.getElementById('dvpresentacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvcontacto')))
                    {document.getElementById('dvcontacto').style.display = 'none';}
              break;
       case 'dvcontacto':
                if(objExiste(document.getElementById('dvubicacion')))
                    {document.getElementById('dvubicacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvpresentacion')))
                    {document.getElementById('dvpresentacion').style.display = 'none';}
                if(objExiste(document.getElementById('dvmemoria')))
                   {document.getElementById('dvmemoria').style.display = 'none';}
              break;
   }
}

 function objExiste(obj) {
            if (obj)
                {
                    return true;
                }
            else
                {
                    return false;
                }
}


//-------------------------------------------------------------
//  Detectar el navegador
//-------------------------------------------------------------
function detectarNavegador()
{
var navegador = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

    };

    navegador.init();
    return navegador.browser.toUpperCase();
}


//-------------------------------------------------------------
//  Obtener el tamaño de la página
//-------------------------------------------------------------
function ObtenerDimensionesPagina()
{
    var size = {width:0, height:0};
    var D = document;

    size.width=D.body.clientWidth;

    size.height= Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);

    matDimensionesPagina = new Array(size.width,size.height);
    return matDimensionesPagina;
}

//-------------------------------------------------------------
// Centar div en la pagina
//-------------------------------------------------------------
function centrarCapaPagina(idCapa)
{

    var navegador=detectarNavegador();
    
    var scrolledX, scrolledY;
    if( self.pageYOffset )
    {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    }
    else if( document.documentElement && document.documentElement.scrollTop )
    {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    }
    else if( document.body )
    {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    if (navegador.browser.toUpperCase()=='EXPLORER') // IE
    {
        var IpopTop = (document.body.clientHeight - document.getElementById(idCapa).offsetHeight)/2;
        var IpopLeft = (document.body.clientWidth - document.getElementById(idCapa).offsetWidth)/2;
        document.getElementById(idCapa).style.left = IpopLeft + document.body.scrollLeft + "px";
        document.getElementById(idCapa).style.top = IpopTop +  scrolledY + "px";
    }
    else if (navegador.browser.toUpperCase()=='FIREFOX') // FF
    {
        var IpopTop = (window.innerHeight - document.getElementById(idCapa).offsetHeight)/2;
        var IpopLeft = (window.innerWidth - document.getElementById(idCapa).offsetWidth)/2;
        document.getElementById(idCapa).style.left = IpopLeft + window.pageXOffset + "px";
        document.getElementById(idCapa).style.top = IpopTop + scrolledY + "px";
    }
    else // other browser?
    {
        var IpopTop = (document.body.clientHeight - document.getElementById(idCapa).offsetHeight)/2;
        var IpopLeft = (document.body.clientWidth - document.getElementById(idCapa).offsetWidth)/2;
        document.getElementById(idCapa).style.left = IpopLeft + document.body.scrollLeft + "px";
        document.getElementById(idCapa).style.top = IpopTop + scrolledY + "px";
    }


}

//-------------------------------------------------------------
// Centar div en el viewport
//-------------------------------------------------------------
function centrarCapaViewport(Xwidth,Yheight,idCapa) {
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
    } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
    } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
    } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the
    // style sheet with display:none; idCapa is passed as an argument to // the function
    var o=document.getElementById(idCapa);
    var r=o.style;
    r.position='absolute';
    r.top = topOffset + 'px';
    r.left = leftOffset + 'px';
    r.display = "block";
}


//-------------------------------------------------------------
// Bloqueamos la página
//-------------------------------------------------------------
function bloqueaPagina(idFondo)
{
    var matDimensionesPagina = ObtenerDimensionesPagina();

    document.getElementById("fraOverControls").style.display="block";

    document.getElementById(idFondo).style.width=matDimensionesPagina[0]+"px";
	document.getElementById(idFondo).style.height=matDimensionesPagina[1]+"px";
	document.getElementById(idFondo).style.display="block";
}

//-------------------------------------------------------------
// Desbloqueamos la página
//-------------------------------------------------------------
function desbloqueaPagina(idFondo)
{	
	document.getElementById(idFondo).style.display="none";
    document.getElementById("fraOverControls").style.display="none";
}

//-------------------------------------------------------------
// Mostrar ventana del mapa de búsqueda
//-------------------------------------------------------------
function mostrarMapa(urlRaiz)
{
    document.getElementById("fraMapa").src=urlRaiz+"mapa.php";
    bloqueaPagina("contenedorFondo");
    centrarCapaViewport(460,420,"ventanaMapa")
	document.getElementById("ventanaMapa").style.display="block";
}

//-------------------------------------------------------------
// Ocultar ventana del mapa de búsqueda
//-------------------------------------------------------------
function ocultarMapa()
{
    document.getElementById("ventanaMapa").style.display="none";
    desbloqueaPagina("contenedorFondo");
}
