﻿var images = [];
var titleImage = [];
var descImage = [];
var videos = [];
var titleVideo = [];
var descVideo = [];
var planosDoc = "";
var otrosDoc = "";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function replaceAll(textoOriginal, buscar, reemplazar)
{
    while (textoOriginal.indexOf(buscar) != -1)
        texto = textoOriginal.replace(buscar, reemplazar);

    return textoOriginal;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CARGA DE FORMULARIO
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function goToForm() {
    window.open("formulario.aspx");
}
// MOSTRAR COMPARTIR
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function shared()
{
    document.getElementById("div_shared").style.display = (document.getElementById("div_shared").style.display == "none" ? "inline" : "none");
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CARGA IMAGENES CABECERA
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadImages()
{
    var strContentImg = "";
    var strAjax = "AJAX_LOAD_IMAGES";

    var strZona = "-1";
    if (document.getElementById("hdCurrentZona") && document.getElementById("hdCurrentZona").value != "" && document.getElementById("hdCurrentZona").value != "0")
        strZona = document.getElementById("hdCurrentZona").value;

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true"
        + "&edificio=" + document.getElementById("hdCurrentEdificio").value
        + "&zona=" + strZona,
        datatype: "xml",
        success: function (xml)
        {
            var xmlEd = xml;
            var images = xmlEd.getElementsByTagName("image");

            for (var a = 0; a < images.length; a++)
            {

                if (isExplorer)
                {
                    strContentImg += "<img src='" + images[a].getElementsByTagName("keyFile")[0].text + "' alt='' />";
                }
                else
                {
                    strContentImg += "<img src='" + images[a].getElementsByTagName("keyFile")[0].childNodes[0].nodeValue + "' alt='' />";
                }


            }
            document.getElementById("SlidePhoto").innerHTML = strContentImg;

            $('#SlidePhoto').jqFancyTransitions(
                            {
                                width: 960, height: 350,
                                effect: '',
                                position: 'top',
                                direction: 'left',
                                strips:15,
                                stripDelay:40,
                                delay: 5000

                            }
                                );
        }
    });

}




//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// EDIFICIOS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function goToEdificio(idEmpresa, idEdificio) 
{
    document.location.href = "edificio.aspx?Ed=" + idEdificio;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function activeEdificio(idEmpresa, idEdificio) 
{
    changeImageMarker(idEdificio);

    //showContentGeneric(idEmpresa, idEdificio, -1);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONTENIDOS GENERICOS ASOCIADOS A empresa, edificio o zona
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showContentGeneric(idEmpresa, idEdificio, idZona ) 
{
    var strAjax = "AJAX_SHOWGENERIC_CONTENT";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
        "&idEmpresa=" + idEmpresa+
        "&idEdificio=" + idEdificio+
        "&idZona=" + idZona,
        datatype: "xml",
        success: function (xml) {
            $('#divContent').xslt({
                dataTypeXML: true,
                xml: xml,
                xslUrl: 'Xsl/genericContent.xsl'
            });
        }
    });
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MOSTRAR EDIFICIOS ASOCIADOS A LAS ZONAS MARCADAS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showEdifByZona() 
{
    var strAjax = "AJAX_SHOW_EDIFICIO_BY_ZONA";
 
    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
        "&idZona=" + document.getElementById("hdZonasSelected").value,
        datatype: "xml",
        success: function (xml)
        {
            var xmlEd = xml;
            var edificios = xmlEd.getElementsByTagName("edificio");
            for (i = 0; i < edificios.length; i++)
            {
                if (isExplorer)
                    idEd = edificios[i].getElementsByTagName("codigoInterno")[0].text;
                else
                    idEd = edificios[i].getElementsByTagName("codigoInterno")[0].childNodes[0].nodeValue;

                document.getElementById("divEdif_" + idEd).className = "menuBulding On";
                if (document.getElementById("hdEdificiosZonas").value.indexOf(idEd) == -1)
                {
                    if (document.getElementById("hdEdificiosZonas").value != "")
                        document.getElementById("hdEdificiosZonas").value += ",";

                    document.getElementById("hdEdificiosZonas").value += idEd;
                }
            }
            var arrDivs = document.getElementsByTagName("div");
            for (a = 0; a < arrDivs.length; a++)
            {
                if (arrDivs[a].id.indexOf("divEdif_") > -1)
                {
                    var countE = 0;
                    for (i = 0; i < edificios.length; i++)
                    {
                        var idEd = "";
                        if (isExplorer)
                            idEd = edificios[i].getElementsByTagName("codigoInterno")[0].text;
                        else
                            idEd = edificios[i].getElementsByTagName("codigoInterno")[0].childNodes[0].nodeValue;

                        if (arrDivs[a].id.split("_")[1] == idEd)
                        {
                            countE++;
                            break;
                        }
                    }
                    if (countE == 0)
                        document.getElementById(arrDivs[a].id).className = "menuBulding";
                }
            }
        }
    });
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CARGA DE ZONAS PARA PROPIEDADES SOFISTICADAS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadZonas() {
 
    if (document.getElementById("Properties").innerHTML == "")
    {
        var strAjax = "AJAX_SHOW_ZONAS";

        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true",
            datatype: "xml",
            success: function (xml) {
                $('#Properties').xslt({
                    dataTypeXML: true,
                    xml: xml,
                    xslUrl: 'Xsl/listZonas.xsl'
                });
            }
        });
    }
}

//===================================================================
// ESTRUCTURAS
//===================================================================
function goToStruct(idEstructura, tipo, url) 
{
    if (tipo == "CONTENT")
        document.location.href = "estructuras.aspx?idE=" + idEstructura;
    else if (tipo == "URL")
        document.location.href = url;
    else if (tipo == "URLNEW")
        window.open(url);
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showEstructZona(idZona, idEdificio, nombreZona, urlCorta)
{
    document.getElementById("hdCurrentZona").value = idZona;
    document.getElementById("hdCurrentZonaPretty").value = urlCorta;
    document.getElementById("hdCurrentZonaName").value = nombreZona;
    document.getElementById("p_dispon").style.visibility = "visible";
    
    var arrLinks = document.getElementsByTagName("a");
    if (arrLinks != null && arrLinks.length > 0)
    {
        for (var a = 0; a < arrLinks.length; a++)
            if (arrLinks[a].id.indexOf("linkZona_") > -1)
                document.getElementById(arrLinks[a].id).className = "linkNull";
    }
    document.getElementById("linkZona_" + idZona).className = "linkNull Active";

     loadImages();

    var firstEstruc = 0;

    var strAjax = "AJAX_SHOW_ESTRUCTURA_BY_EDIF_ZONA";
    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
         "&idEdificio=" + idEdificio + "&idZona=" + idZona,
        datatype: "xml",
        success: function (xml)
        {
            var xmlEd = xml;
            var estructuras = xmlEd.getElementsByTagName("estructura");

            if (estructuras == null || estructuras.length == 0)
            {
                document.getElementById("BuildingHeadSubMenu").innerHTML = "&nbsp;&nbsp;";
            }
            else
            {
                var strEstruc = "<ul>";
                for (i = 0; i < estructuras.length; i++)
                {
                    if (isExplorer)
                    {
                        strEstruc += "<li><a id='link_" + estructuras[i].getElementsByTagName("idEstructura")[0].text + "' class='linkNull' href='javascript:showContentEstructura(" + estructuras[i].getElementsByTagName("idEstructura")[0].text + ");'>" + estructuras[i].getElementsByTagName("nombre")[0].text + "</a></li>";
                        if (i == 0)
                            firstEstruc = estructuras[i].getElementsByTagName("idEstructura")[0].text;
                    }
                    else
                    {
                        strEstruc += "<li><a id='link_" + estructuras[i].getElementsByTagName("idEstructura")[0].childNodes[0].nodeValue + "' class='linkNull' href='javascript:showContentEstructura(" + estructuras[i].getElementsByTagName("idEstructura")[0].childNodes[0].nodeValue + ");'>" + estructuras[i].getElementsByTagName("nombre")[0].childNodes[0].nodeValue + "</a></li>";
                        if (i == 0)
                            firstEstruc = estructuras[i].getElementsByTagName("idEstructura")[0].childNodes[0].nodeValue;
                    }

                }
                // strEstruc += "<a href='avascript:showTiposZonas(" + idZona + "," + idEdificio + ");'>Unidades Inmobiliarias</a>";
                strEstruc += "</u>";
                document.getElementById("BuildingHeadSubMenu").innerHTML = strEstruc;

                if (firstEstruc != 0)
                    showContentEstructura(firstEstruc);
            }


            showInfoProperties(idZona, idEdificio, nombreZona, document.getElementById("hdCurrentPrettyEdificio").value, document.getElementById("hdCurrentZonaPretty").value);


        }
    });
    
   
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showInfoProperties(idZona, idEdificio, nombreZona, prettyEd, prettyZo)
{
    var strAjax = "AJAX_SHOW_TOTAL_UDS_BY_TIPO";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
         "&idEdificio=" + idEdificio + "&idZona=" + idZona,
        datatype: "xml",
        success: function (xml)
        {
            var xmlEd = xml;
            var tipoZona = xmlEd.getElementsByTagName("tipoZona");

            if (tipoZona.length > 0)
            {
                var strEstruc = "<img style='float:right;padding-left:8px;' alt='' src='App_Themes/Images/IcoTag.png' /><h1>Nuestra oferta en " + nombreZona + "</h1>";
                strEstruc += "<ul>";
                for (i = 0; i < tipoZona.length; i++)
                {
                    if (isExplorer)
                    {
                        strEstruc += "<li><a href='disponibilidadInmobiliaria.aspx?Ed=" + prettyEd + "&Zo=" + prettyZo + "&Tz=" + tipoZona[i].getElementsByTagName("urlCorta")[0].text + "'>" + tipoZona[i].getElementsByTagName("nombre")[0].text + " (" + tipoZona[i].getElementsByTagName("total")[0].text + " uds )</a></li>";
                    }
                    else
                    {

                        strEstruc += "<li><a href='disponibilidadInmobiliaria.aspx?Ed=" + prettyEd + "&Zo=" + prettyZo + "&Tz=" + tipoZona[i].getElementsByTagName("urlCorta")[0].childNodes[0].nodeValue + "'>" + tipoZona[i].getElementsByTagName("nombre")[0].childNodes[0].nodeValue + " (" + tipoZona[i].getElementsByTagName("total")[0].childNodes[0].nodeValue + " uds)</a></li>";

                    }
                }
                strEstruc += "</u>";

                document.getElementById("BuldingTipeZone").innerHTML = strEstruc;
                document.getElementById("BuldingTipeZone").style.visibility = "visible";
                document.getElementById("p_dispon").style.visibility = "visible";
            }
            else
            {
                document.getElementById("BuldingTipeZone").style.visibility = "hidden";
            }
        }
    });
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONTENIDOS POR ESTRUCTURA
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showContentEstructura(idEstructura)
{
  
    var strAjax = "AJAX_SHOWESTRUCTURA_CONTENT";

    var arrLinks = document.getElementsByTagName("a");
    if (arrLinks != null && arrLinks.length > 0)
    {
        for (var a = 0; a < arrLinks.length; a++)
            if (arrLinks[a].id.indexOf("link_") > -1)
                document.getElementById(arrLinks[a].id).className = "linkNull";
    }
    document.getElementById("link_" + idEstructura).className = "linkNull Active";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
             "&idEstructura=" + idEstructura,
        datatype: "xml",
        success: function(xml) {
            var objXml = xml;
            var est = objXml.getElementsByTagName("estructura");
        
            var strName = "";
            var strDesc = "";
            if (isExplorer) {
                strName = est[0].getElementsByTagName("Nombre")[0].text;
                strDesc = est[0].getElementsByTagName("Contenido")[0].text;
            }
            else {
                strName = est[0].getElementsByTagName("Nombre")[0].childNodes[0].nodeValue;
                strDesc = est[0].getElementsByTagName("Contenido")[0].childNodes[0].nodeValue;
            }

            var strText = "<h1>" + strName + "</h1>";
            strText += "<p>" + strDesc + "</p>";
 
            document.getElementById("TextContent").innerHTML = strText;
        }
    });

    loadFilesByEstructura(idEstructura, -1, -1, "Img_Ed");
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadFilesByEstructura(idEstructura, idTipoZona, idUnidad, nameDiv)
{
    videos.length = 0;
    images.length = 0;
    
    if( document.getElementById("BuldingArchives"))
        document.getElementById("BuldingArchives").innerHTML = "";

    var strAjax = "AJAX_SHOW_ESTRUCTURA_FILES";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&idEdificio=" + document.getElementById("hdCurrentEdificio").value +
            "&idZona=" + document.getElementById("hdCurrentZona").value +
            "&idTipoZona=" + idTipoZona +
            "&idUnidad=" + idUnidad +
             "&idEstructura=" + idEstructura,
        datatype: "xml",
        success: function (xml)
        {


            var strHtml = "";
            var objXml = xml;
            var fotos = objXml.getElementsByTagName("foto");
            if (fotos != null && fotos.length > 0)
            {
                images.length = 0;
                titleImage.length = 0;
                descImage.length = 0;

                for (var a = 0; a < fotos.length; a++)
                {
                    var strImage = "";
                    if (isExplorer)
                        strImage = fotos[a].getElementsByTagName("url")[0].text;
                    else
                        strImage += fotos[a].getElementsByTagName("url")[0].childNodes[0].nodeValue;

                    images.push(strImage);
                    titleImage.push("");
                    descImage.push("");
                }
                strHtml += "<div class='Folder' onclick='loadPhotos();'><img alt='' src='App_Themes/Images/IcoFotos.png' /><br />Fotos</div>";
            }

            var videosss = objXml.getElementsByTagName("video");
            if (videosss != null && videosss.length > 0)
            {
                for (var b = 0; b < videosss.length; b++)
                {
                    var strV = "";
                    if (isExplorer)
                        strV = videosss[b].getElementsByTagName("url")[0].text;
                    else
                        strV += videosss[b].getElementsByTagName("url")[0].childNodes[0].nodeValue;

                    videos.push(strV);
                    titleVideo.push("");
                    descVideo.push("");
                }
                strHtml += "<div class='Folder' onclick='loadVideos();'><img alt='' src='App_Themes/Images/IcoVideos.png' /><br />Videos</div>";
            }
            var planos = objXml.getElementsByTagName("plano");
            if (planos != null && planos.length > 0)
            {
                if (planos.length == 1)
                {
                    var strUrlUn = "";
                    if (isExplorer)
                    {
                        strUrlUn = planos[0].getElementsByTagName("url")[0].text;
                    }
                    else
                    {
                        strUrlUn += planos[0].getElementsByTagName("url")[0].childNodes[0].nodeValue;
                    }
                    strHtml += "<div class='Folder' id='icoPlanosF' onclick='void(window.open(\"" + decodeURIComponent(strUrlUn) + "\"));' ><img alt=''src='App_Themes/Images/IcoPlanos.png' /><br />Planos</div>";
                }
                else
                {
                    strHtml += "<div class='Folder' id='icoPlanosF' onclick='showPlanosInfo();' ><img alt=''src='App_Themes/Images/IcoPlanos.png' /><br />Planos</div>";

                    planosDoc = "<ul>";

                    for (var b = 0; b < planos.length; b++)
                    {
                        var strName = "";
                        var strExt = "";
                        var strUrl = "";
                        if (isExplorer)
                        {
                            strName = planos[b].getElementsByTagName("nombre")[0].text;
                            strExt = planos[b].getElementsByTagName("ext")[0].text;
                            strUrl = planos[b].getElementsByTagName("url")[0].text;
                        }
                        else
                        {
                            strName += planos[b].getElementsByTagName("nombre")[0].childNodes[0].nodeValue;
                            strExt += planos[b].getElementsByTagName("ext")[0].childNodes[0].nodeValue;
                            strUrl += planos[b].getElementsByTagName("url")[0].childNodes[0].nodeValue;
                        }

                        planosDoc += "<li class='" + strExt + "'><a href='" + decodeURIComponent(strUrl) + "' target='_blank'>" + decodeURIComponent(strName) + "</a></li>";
                    }
                    planosDoc += "</ul>";
                }
            }

            var otros = objXml.getElementsByTagName("otro");
            if (otros != null && otros.length > 0)
            {
                strHtml += "<div class='Folder' id='icoOtrosF'  onclick='showOtrosInfo();' ><img alt='' src='App_Themes/Images/IcoOtrosArchivos.png' /><br />Otros</div>";

                otrosDoc = "<ul>";

                for (var b = 0; b < otros.length; b++)
                {
                    var strName = "";
                    var strExt = "";
                    var strUrl = "";
                    if (isExplorer)
                    {
                        strName = otros[b].getElementsByTagName("nombre")[0].text;
                        strExt = otros[b].getElementsByTagName("ext")[0].text;
                        strUrl = otros[b].getElementsByTagName("url")[0].text;
                    }
                    else
                    {
                        strName += otros[b].getElementsByTagName("nombre")[0].childNodes[0].nodeValue;
                        strExt += otros[b].getElementsByTagName("ext")[0].childNodes[0].nodeValue;
                        strUrl += otros[b].getElementsByTagName("url")[0].childNodes[0].nodeValue;
                    }

                    otrosDoc += "<li class='" + strExt + "'><a href='" + decodeURIComponent(strUrl) + "' target='_blank'>" + decodeURIComponent(strName) + "</a></li>";
                }
                otrosDoc += "</ul>";
            }


            if (nameDiv == "Img_Dispo")
            {
                strHtml += "<div class='Folder' style='float:right' onclick='UXInterest();' >";
                strHtml += "<img alt='' src='App_Themes/Images/IcoInfo.png' /><br />Info</div>";

                strHtml += "<div class='Folder' id='icoAlertasF' style='float:right' onclick='showAlerts();' >";
                strHtml += "<img alt='' src='App_Themes/Images/IcoAlertas.png' /><br />Alertas</div>";

                strHtml += "<div class='Folder'  id='icoCompartirF'  style='float:right'  onclick='loadIframe();'>";
                strHtml += "<img alt='' src='App_Themes/Images/IcoComparte.png' /><br />Compartir</div>";
            }


            document.getElementById("BuildingImages").innerHTML = strHtml;
        }
    });

    
 
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadPhotos()
{

    if (document.getElementById("icoPlanosF"))
        document.getElementById("icoPlanosF").className = "Folder";

    if (document.getElementById("icoOtrosF"))
        document.getElementById("icoOtrosF").className = "Folder";

    $.prettyPhoto.open(images, titleImage, descImage);
    $.prettyPhoto.startSlideshow();

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadVideos()
{
  if (document.getElementById("icoPlanosF"))
        document.getElementById("icoPlanosF").className = "Folder";

    if (document.getElementById("icoOtrosF"))
        document.getElementById("icoOtrosF").className = "Folder";

    $.prettyPhoto.open(videos, titleVideo, descVideo);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showPlanosInfo() {

    if (document.getElementById("icoPlanosF") && document.getElementById("icoPlanosF").className == "Folder")
    {
        document.getElementById("icoPlanosF").className = "Folder Active";
        if (document.getElementById("icoOtrosF"))
            document.getElementById("icoOtrosF").className = "Folder";

        if (document.getElementById("icoAlertasF"))
            document.getElementById("icoAlertasF").className = "Folder";

        if (document.getElementById("icoCompartirF"))
            document.getElementById("icoCompartirF").className = "Folder";

        if (document.getElementById("AlertsConfig"))
            document.getElementById("AlertsConfig").style.display = "none";

        document.getElementById("BuldingArchives").innerHTML = planosDoc;
    } 
    else
    {
        document.getElementById("icoPlanosF").className = "Folder";
        document.getElementById("BuldingArchives").innerHTML = "";
    }

}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showOtrosInfo()
{
    if (document.getElementById("icoOtrosF").className == "Folder")
    {
        if (document.getElementById("icoPlanosF"))
            document.getElementById("icoPlanosF").className = "Folder";

        if (document.getElementById("icoAlertasF"))
            document.getElementById("icoAlertasF").className = "Folder";

        if (document.getElementById("icoCompartirF"))
            document.getElementById("icoCompartirF").className = "Folder";

        document.getElementById("icoOtrosF").className = "Folder Active";

        if (document.getElementById("AlertsConfig"))
            document.getElementById("AlertsConfig").style.display = "none";
        document.getElementById("BuldingArchives").innerHTML = otrosDoc;
    }
    else
    {
        document.getElementById("icoOtrosF").className = "Folder";
        document.getElementById("BuldingArchives").innerHTML = "";
    }
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showOtrosArchivosInfo()
{
  //  document.getElementById("BuldingArchives").innerHTML = planosDoc;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showTiposZonas(domain, prettyEd)
{
     document.location.href = "disponibilidadInmobiliaria.aspx?Ed=" + prettyEd + "&Zo=" + document.getElementById("hdCurrentZonaPretty").value;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CARGA DE TIPOS DE ZONAS en relacion a edificio y zona
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showTiposZonas2(idEdificio)
{
    UXpanel();
    var arrLinks = document.getElementsByTagName("a");
    if (arrLinks != null && arrLinks.length > 0)
    {
        for (var a = 0; a < arrLinks.length; a++)
            if (arrLinks[a].id.indexOf("link_") > -1)
                document.getElementById(arrLinks[a].id).className = "linkNull";
    }

    var strAjax = "AJAX_SHOW_TIPOS_ZONAS";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
              "&idZona=" + document.getElementById("hdCurrentZona").value +
               "&idEdificio=" + idEdificio,
        datatype: "xml",
        success: function (xml)
        {
            $('#div_tiposZonas').xslt({
                dataTypeXML: true,
                xml: xml,
                xslUrl: 'Xsl/tiposZonasList.xsl'
            });
        }
    });
    document.getElementById("Disponibilidad").style.display = "block";
    document.getElementById("TextContent").style.visibility = "hidden";
    document.getElementById("TextContent").style.display = "none";
    document.getElementById("AdditionalContent").style.visibility = "hidden";
    document.getElementById("AdditionalContent").style.display = "none";
    document.getElementById("div_tiposZonas").style.display = "inline";
 
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MOSTRAR UNIDADES INMOBILIARIAS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showUnidades(idTipoZona, verTodo)
{
   
    if (idTipoZona == null || idTipoZona == "" || idTipoZona == "-1")
        idTipoZona = document.getElementById("hdCurrentTipoZona").value;


    UXshareNoVisible();
    document.getElementById("BuldingArchives").innerHTML = "";
   
    document.getElementById("AlertsConfig").style.display = "none";

    if (document.getElementById("icoCompartirF"))
        document.getElementById("icoCompartirF").className = "Folder";

    if (document.getElementById("icoPlanosF"))
        document.getElementById("icoPlanosF").className = "Folder";
    if (document.getElementById("icoOtrosF"))
        document.getElementById("icoOtrosF").className = "Folder";

    if (document.getElementById("icoAlertasF"))
        document.getElementById("icoAlertasF").className = "Folder";


    document.getElementById("hdCurrentTipoZona").value = idTipoZona;


    var arrDiv = document.getElementsByTagName("div");
    if (arrDiv != null && arrDiv.length > 0)
    {
        for (var a = 0; a < arrDiv.length; a++)
        {
            if (arrDiv[a].id.indexOf("divTZ_") > -1)
                document.getElementById("divTZ_" + arrDiv[a].id.split("_")[1]).className = "Item ItemNormal";
        }
    }

    document.getElementById("divTZ_" + idTipoZona).className = "Item ItemActive";

    var strAjax = "AJAX_SHOW_UNIDADES";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
                "&verTodo=" + verTodo +
              "&idTipoZona=" + idTipoZona,
        datatype: "xml",
        success: function (xml)
        {
            $('#div_unidades').xslt({
                dataTypeXML: true,
                xml: xml,
                xslUrl: 'Xsl/unidadesList.xsl'
            });

            showInfoTipoZona(idTipoZona);
            loadAlerts("TIPO_ZONA", idTipoZona);
            GetNumAlerts();
           // changeMetasFacebook(idTipoZona);
        }
    });
     document.getElementById("div_unidades").style.visibility = "visible";
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showInfoTipoZonaOld(idTipoZona)
{
    var strAjax = "AJAX_SHOW_INFO_TIPOZONA";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
              "&idTipoZona=" + idTipoZona,
        datatype: "xml",
        success: function (xml)
        {
            $('#div_tipoZona_info').xslt({
                dataTypeXML: true,
                xml: xml,
                xslUrl: 'Xsl/tipoZonaInfo2.xsl'
            });
            document.getElementById("BuldingArchives").innerHTML = "";
        }
    });
    document.getElementById("div_tipoZona_info").style.visibility = "visible";

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showInfoTipoZona(idTipoZona)
{
    var strAjax = "AJAX_SHOW_INFO_TIPOZONA";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
              "&idTipoZona=" + idTipoZona,
        datatype: "xml",
        success: function (xml)
        {
            var objXml = xml;
            var est = objXml.getElementsByTagName("TiposZona");

            var strName = "";
            var strDesc = "";
            var strTipoPrec = "";
            var strPrecio = "";
            if (isExplorer)
            {
                try { strName = est[0].getElementsByTagName("Nombre")[0].text; } catch (e) { }
                try { strDesc = est[0].getElementsByTagName("Descripcion")[0].text; } catch (e) { }
                try { strTipoPrec = est[0].getElementsByTagName("TipoPrecio")[0].text; } catch (e) { }
                try { strPrecio = est[0].getElementsByTagName("Precio")[0].text; } catch (e) { }
            }
            else
            {
                try { strName = est[0].getElementsByTagName("Nombre")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strDesc = est[0].getElementsByTagName("Descripcion")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strTipoPrec = est[0].getElementsByTagName("TipoPrecio")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strPrecio = est[0].getElementsByTagName("Precio")[0].childNodes[0].nodeValue; } catch (e) { }
            }

            var strText = " <h1><span class='Paso'>PASO 3</span>Información y Reservas. Alertas</h1><div id='BuildingInfo'>";
            strText += "<div class='Label'>TIPO</div><div class='Value'>" + strName + "</div>";
            strText += "<div class='Label'>DESCRIPCIÓN</div><div class='Value'>" + decodeURIComponent(strDesc) + "</div>";
            if (strPrecio != "")
            {
                strText += "<div class='Label'>PRECIO</div>";
                if (strTipoPrec == "EXACTO")
                    strText += "<div class='Value'>Desde " + strPrecio + " euros/mes</div>";
                else
                    strText += "<div class='Value'>Entre " + strPrecio + " euros/mes</div>";

                strText += "</div>";
            }
            document.getElementById("div_tipoZona_info").innerHTML = strText;
            document.getElementById("BuldingArchives").innerHTML = "";
            document.getElementById("div_tipoZona_info").style.visibility = "visible";

            loadFilesByEstructura(-1, idTipoZona, -1, "Img_Dispo");
        }
    });
    

}





//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MOSTRAR UNIDADES INMOBILIARIAS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showInfoUnidadOld(idUnidad)
{

    document.getElementById("hdCurrentUnidad").value = idUnidad;
    document.getElementById("AlertsConfig").style.display = "none";
 

    var arrDiv = document.getElementsByTagName("div");
    if (arrDiv != null && arrDiv.length > 0)
    {
        for (var a = 0; a < arrDiv.length; a++)
        {
            if (arrDiv[a].id.indexOf("divUD_") > -1)
                document.getElementById("divUD_" + arrDiv[a].id.split("_")[1]).className = "Item ItemNormal";
        }
    }

    document.getElementById("divUD_" + idUnidad).className = "Item ItemActive";

    var strAjax = "AJAX_SHOW_INFO_UNIDAD";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
              "&idUnidad=" + idUnidad,
        datatype: "xml",
        success: function (xml)
        {
            $('#div_tipoZona_info').xslt({
                dataTypeXML: true,
                xml: xml,
                xslUrl: 'Xsl/unidadInfo.xsl'
            });
            loadAlerts("UNIDAD", idUnidad);
        }
    });
    document.getElementById("div_tipoZona_info").style.visibility = "visible";

}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showInfoUnidad(idUnidad)
{

    document.getElementById("hdCurrentUnidad").value = idUnidad;
    document.getElementById("AlertsConfig").style.display = "none";


    var arrDiv = document.getElementsByTagName("div");
    if (arrDiv != null && arrDiv.length > 0)
    {
        for (var a = 0; a < arrDiv.length; a++)
        {
            if (arrDiv[a].id.indexOf("divUD_") > -1)
                document.getElementById("divUD_" + arrDiv[a].id.split("_")[1]).className = "Item ItemNormal";
        }
    }

    document.getElementById("divUD_" + idUnidad).className = "Item ItemActive";

    var strAjax = "AJAX_SHOW_INFO_UNIDAD";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
              "&idUnidad=" + idUnidad,
        datatype: "xml",
        success: function (xml)
        {
            var objXml = xml;
            var est = objXml.getElementsByTagName("Unidad");

            var strName = "";
            var strNameUnidad = "";
            var strMetrosCuadrados = "";
            var strDesc = "";
            var strDescUnidad = "";
            var strTipoPrec = "";
            var strPrecio = "";
            var strKeyTipoZona = "";

            if (isExplorer)
            {
                try { strNameUnidad = est[0].getElementsByTagName("Nombre")[0].text; } catch (e) { }
                try { strDescUnidad = est[0].getElementsByTagName("Descripcion")[0].text; } catch (e) { }
                try { strMetrosCuadrados = est[0].getElementsByTagName("Metros")[0].text; } catch (e) { }


                var tz = est[0].getElementsByTagName("TipoZona");
                try { strKeyTipoZona = tz[0].getElementsByTagName("TipoZonaID")[0].text; } catch (e) { }
                try { strName = tz[0].getElementsByTagName("Nombre")[0].text; } catch (e) { }
                try { strDesc = tz[0].getElementsByTagName("Descripcion")[0].text; } catch (e) { }
                try { strTipoPrec = tz[0].getElementsByTagName("TipoPrecio")[0].text; } catch (e) { }
                try { strPrecio = tz[0].getElementsByTagName("Precio")[0].text; } catch (e) { }

            }
            else
            {
                try { strNameUnidad = est[0].getElementsByTagName("Nombre")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strDescUnidad = est[0].getElementsByTagName("Descripcion")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strMetrosCuadrados = est[0].getElementsByTagName("Metros")[0].childNodes[0].nodeValue; } catch (e) { }
                var tz = est[0].getElementsByTagName("TipoZona");
                try { strKeyTipoZona = tz[0].getElementsByTagName("TipoZonaID")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strName = tz[0].getElementsByTagName("Nombre")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strDesc = tz[0].getElementsByTagName("Descripcion")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strTipoPrec = tz[0].getElementsByTagName("TipoPrecio")[0].childNodes[0].nodeValue; } catch (e) { }
                try { strPrecio = tz[0].getElementsByTagName("Precio")[0].childNodes[0].nodeValue; } catch (e) { }

            }

            var strText = " <h1><span class='Paso'>PASO 3</span>Información y Reservas. Alertas</h1><div id='BuildingInfo'>";
            strText += "<div class='Label'>TIPO</div><div class='Value'>" + strName + "</div>";
            strText += "<div class='Label'>UNIDAD</div><div class='Value'>" + strNameUnidad + "</div>";
            if (strMetrosCuadrados != "")
                strText += "<div class='Label'>SUPERFICIE</div><div class='Value'>" + strMetrosCuadrados + " m2</div>";

            strText += "<div class='Label'>DESCRIPCIÓN</div><div class='Value'>";
            if (strDescUnidad != "")
            {
                strText += decodeURIComponent(strDescUnidad);
                strText += "<p>" + decodeURIComponent(strDesc) + "</p>";
            }
            else
                strText += decodeURIComponent(strDesc);

            strText += "</div>";
            if (strPrecio != "")
            {
                strText += "<div class='Label'>PRECIO</div>";
                if (strTipoPrec == "EXACTO")
                    strText += "<div class='Value'>Desde " + strPrecio + " euros/mes</div>";
                else
                    strText += "<div class='Value'>Entre " + strPrecio + " euros/mes</div>";

                strText += "</div>";
            }
            document.getElementById("div_tipoZona_info").innerHTML = strText;
            document.getElementById("BuldingArchives").innerHTML = "";
            document.getElementById("div_tipoZona_info").style.visibility = "visible";

            loadFilesByEstructura(-1, strKeyTipoZona, idUnidad, "Img_Dispo");
            loadAlerts("UNIDAD", idUnidad);
        }
    });
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  ALERTAS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadAlerts(tipo, ident)
{
 
    document.getElementById("divAlerta").innerHTML = "";
   var strAjax = "AJAX_LOAD_ALERTS";

   $.ajax({
       type: "POST",
       url: document.location.href,
       data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
               "&tipo=" + tipo +
               "&id=" + ident,
       datatype: "xml",
       success: function (xml)
       {
           var strIdAlerts = "";
           var objXml = xml;
           var arrAlerts = objXml.getElementsByTagName("alerta");

           var check1Sel = "NO";
           var check2Sel = "NO";
           var check3Sel = "NO";
           var check4Sel = "NO";

           if (arrAlerts != null && arrAlerts.length > 0)
           {
               for (var a = 0; a < arrAlerts.length; a++)
               {
                   var numAlert = "";
                   if (isExplorer)
                       numAlert = arrAlerts[a].getElementsByTagName("keyAlerta")[0].text;
                   else
                       numAlert = arrAlerts[a].getElementsByTagName("keyAlerta")[0].childNodes[0].nodeValue;

                   if (eval(numAlert) == 1)
                       check1Sel = "SI";
                   if (eval(numAlert) == 2)
                       check2Sel = "SI";
                   if (eval(numAlert) == 3)
                       check3Sel = "SI";
                   if (eval(numAlert) == 4)
                       check4Sel = "SI";
               }
           }

           if (tipo == "TIPO_ZONA")
           {
               var strStyle = "Item Check";
               if (check1Sel == "SI")
                   strStyle = "Item Checked";
               strH = "<ul style='margin-top:10px;margin-bottom:10px;'>";
               strH += "<span onclick='javascript:UXalertsCheck(1,\"OCUPACION\"," + ident + ",-1)'><li id='alertsCheck1' class='" + strStyle + "'>";
               strH += "<a class='linkNull'>La ocupación esta cercana al 100%</a>";
               strH += "</li></span>";

               strStyle = "Item Check";
               if (check2Sel == "SI")
                   strStyle = "Item Checked";

               strH += "<span onclick='javascript:UXalertsCheck(2,\"PRECIO_TIPO_ZONA\"," + ident + ",-1)'><li id='alertsCheck2' class='" + strStyle + "'>";
               strH += "<a class='linkNull'>Cambie el precio</a>";
               strH += "</li></span>";

               strH += "</ul>";
           }
           else
           {
               strStyle = "Item Check";
               if (check3Sel == "SI")
                   strStyle = "Item Checked";
               strH = "<ul style='margin-top:10px;margin-bottom:10px;'>";
               strH += "<span onclick='javascript:UXalertsCheck(2,\"PRECIO_UNIDAD\",-1," + ident + ")'><li id='alertsCheck2' class='" + strStyle + "'>";
               strH += "<a class='linkNull'>Cambie el precio</a>";
               strH += "</li></span>";


               strStyle = "Item Check";
               if (check4Sel == "SI")
                   strStyle = "Item Checked";

               strH += "<span onclick='javascript:UXalertsCheck(3,\"ESTADO_UNIDAD\",-1," + ident + ")'><li id='alertsCheck3' class='" + strStyle + "'>";
               strH += "<a class='linkNull'>Cambie el estado (En Reforma/Reservado/Alquilado/Libre)</a>";
               strH += "</li></span>";

               strH += "</ul>";
           }

           document.getElementById("divAlerta").innerHTML = strH;
       }
   });

   document.getElementById("divNumAlertas").style.visibility = "visible";
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showAlerts()
{
    if( document.getElementById("icoPlanosF"))
        document.getElementById("icoPlanosF").className = "Folder";
    if (document.getElementById("icoOtrosF"))
        document.getElementById("icoOtrosF").className = "Folder";

    
    document.getElementById("icoAlertasF").className = "Folder Active";

    if (document.getElementById("icoCompartirF"))
        document.getElementById("icoCompartirF").className = "Folder";

    document.getElementById("BuldingArchives").innerHTML = "";
 
    document.getElementById("AlertsConfig").style.display = "";
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showEmailAlert(tipoAlerta, idTipoZona, idUnidad, tipoAccion)
{
    document.getElementById("hdAlertaTipo").value = tipoAlerta;
    document.getElementById("hdAlertaTipoZona").value = idTipoZona;
    document.getElementById("hdAlertaUnidad").value = idUnidad;
    if (tipoAccion == "INSERTAR")
        insertAlert();
    else
        deleteOneAlert(tipoAlerta, idTipoZona, idUnidad);
    
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function insertAlert()
{
    if (validateForm())
    {
        var strAjax = "AJAX_ALERTS_SAVE";

        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true"
                    + "&email=" + encodeURIComponent($("#emailAlert").val())
                            + "&tipo=" + encodeURIComponent($("#hdAlertaTipo").val())
                            + "&tipoZona=" + encodeURIComponent($("#hdAlertaTipoZona").val())
                            + "&unidad=" + encodeURIComponent($("#hdAlertaUnidad").val()),
            datatype: "xml",
            success: function (xml)
            {
                var id = $(xml).find("ID").text();
                if (eval(id) == -1000)
                {
                    alert("No se puede insertar la alerta porque ya estaba suscrita a ella. ");
                }
                if (id < 1 || !id || id == "")
                {
                    alert("Ha ocurrido un error al insertar la alerta. Por favor, inténtelo de nuevo");
                }
                else
                {
                    if ($("#hdAlertaTipoZona").val() != "-1")
                    {
                        if (document.getElementById("spn_Alert_" + $("#hdAlertaTipoZona").val() + "_-1"))
                            document.getElementById("spn_Alert_" + $("#hdAlertaTipoZona").val() + "_-1").className = "AlertActive";
                    }
                    else
                    {
                        if (document.getElementById("spn_Alert_-1_" + $("#hdAlertaUnidad").val()))
                            document.getElementById("spn_Alert_-1_" + $("#hdAlertaUnidad").val()).className = "AlertActive";
                    }
                    document.getElementById("hdAlertaTipo").value = "";
                    document.getElementById("hdAlertaTipoZona").value = "";
                    document.getElementById("hdAlertaUnidad").value = "";
                    GetNumAlerts();
                    //  alert("La alerta se insertó correctamente.");
                }
            }
        });
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function deleteAlerts(tipo, idTip)
{
    if (confirm("¿Está seguro de eliminar las alertas?"))
    {

        var strAjax = "AJAX_ALERTS_DELETE";

        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&tipo=" + tipo +
            "&idT=" + idTip,
            datatype: "xml",
            success: function (xml)
            {
                var id = $(xml).find("ID").text();

                if (id < 1 || !id || id == "")
                {
                    alert("Ha ocurrido un error al eliminar las alertas. Por favor, inténtelo de nuevo");
                    returnValue = false;
                }
                else
                {



                    document.getElementById("hdAlertaTipo").value = "";
                    document.getElementById("hdAlertaTipoZona").value = "";
                    document.getElementById("hdAlertaUnidad").value = "";
                    if (tipo == "ALL")
                    {
                        document.getElementById("emailAlert").value = "";

                        var arr1 = document.getElementsByTagName("span");
                        if (arr1 != null && arr1.length > 0)
                        {
                            for (var a = 0; a < arr1.length; a++)
                                if (arr1[a].id.indexOf("spn_Alert_") > -1)
                                    document.getElementById(arr1[a].id).className = "AlertActiveNull";
                        }
                    }
                    else if (tipo == "TIPO_ZONA")
                        document.getElementById("spn_Alert_" + idTip + "_-1").className = "AlertActiveNull";
                    else if (tipo == "UNIDAD")
                        document.getElementById("spn_Alert_-1_" + idTip).className = "AlertActiveNull";


                    GetNumAlerts();
                    //   alert("La alertas se eliminaron correctamente.");
                }
            }
        });
    }
    
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function deleteOneAlert(tipoAlerta, idTipoZona, idUnidad)
{
    if (confirm("¿Está seguro de eliminar esta alerta?"))
    {
        var strAjax = "AJAX_ALERTS_DELETE_ONE_TYPE";

        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&tipo=" + tipoAlerta +
            "&idT=" + idTipoZona +
            "&idUd=" + idUnidad,
            datatype: "xml",
            success: function (xml)
            {
                var id = $(xml).find("ID").text();

                if (!id || id == "" || id == "-1")
                {
                    alert("Ha ocurrido un error al eliminar las alertas. Por favor, inténtelo de nuevo");
                    returnValue = false;
                }
                else
                {
                    document.getElementById("hdAlertaTipo").value = "";
                    document.getElementById("hdAlertaTipoZona").value = "";
                    document.getElementById("hdAlertaUnidad").value = "";

                    if (id == "0")
                    {
                        if (idUnidad != "-1")
                            document.getElementById("spn_Alert_-1_" + idUnidad).className = "AlertActiveNull";
                        else
                            document.getElementById("spn_Alert_" + idTipoZona + "_-1").className = "AlertActiveNull";
                    }
                    GetNumAlerts();
                    //   alert("La alertas se eliminaron correctamente.");
                }
            }
        });
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function GetNumAlerts()
{
    var strAjax = "AJAX_SHOW_NUM_ALERTS";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true",
        datatype: "xml",
        success: function (xml)
        {
            var strHtml = "";
            var objXml = xml;
            var arrAlerts = objXml.getElementsByTagName("alerta");

            var numAlerts = "0";
            if (arrAlerts.length > 0)
            {
                if (isExplorer)
                    numAlerts = arrAlerts[0].getElementsByTagName("numero")[0].text;
                else
                    numAlerts = arrAlerts[0].getElementsByTagName("numero")[0].childNodes[0].nodeValue;
            }
            if (numAlerts == "0")
                strHtml += " Usted no tiene alertas activas.";
            else
                strHtml += " Usted tiene <span class='ResaltaCifra'>" + numAlerts + "</span> alertas activas. <a href='javascript:deleteAlerts(\"ALL\",-1);'>Eliminar todas las alertas</a>";

            document.getElementById("divNumAlertas").innerHTML = strHtml;
        }
    });
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function validateForm()
{
    if (document.getElementById("emailAlert").value == "")
    {
        alert("Debe insertar un email válido para continuar");
        return false;
    }
  return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showPlanos()
{
    if (document.getElementById("icoPlanos").className == "Folder")
    {
        document.getElementById("icoPlanos").className = "Folder Active";
        if (document.getElementById("icoOtros"))
            document.getElementById("icoOtros").className = "Folder";

        document.getElementById("BuldingArchives").innerHTML = decodeURIComponent(document.getElementById("hdPlanos").value);
    }
    else
    {
        document.getElementById("icoPlanos").className = "Folder";
        document.getElementById("BuldingArchives").innerHTML = "";
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showOtros()
{
    if (document.getElementById("icoOtros").className == "Folder")
    {
        document.getElementById("icoOtros").className = "Folder Active";
        if (document.getElementById("icoPlanos"))
            document.getElementById("icoPlanos").className = "Folder";
        document.getElementById("BuldingArchives").innerHTML = decodeURIComponent(document.getElementById("hdArchivos").value);
    }
    else
    {
        document.getElementById("icoOtros").className = "Folder";
        document.getElementById("BuldingArchives").innerHTML = "";
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadSocialShare(strPath, strTitle, strTextTwitter)
{
    var strHtml = "<br/><br/><script type='IN/Share' data-url='" + strPath + "' data-counter='right'></script><br/>";

    strHtml += "<br/><a id='btn_tw' href='http://twitter.com/share' class='twitter-share-button' ";
    strHtml += "data-count='horizontal' data-text='" + strTextTwitter + "' data-url='" + strPath + "'>Tweet</a><br /><br />";
    strHtml += "<fb:like href='" + strPath + "' layout='button_count' show_faces='false' send='true' font=''></fb:like><br />";
    document.getElementById("social").innerHTML = strHtml;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadSocialShareTipoZ(strPath, strTitle, strTipoZona)
{
 
    var arrPath = strPath.split(",");
    var arrTitle = strTitle.split(",");
    var arrTipoZona = strTipoZona.split(",");
    var strZonaS = document.getElementById("hdCurrentTipoZona").value;

    var strHtml = "";
    if (arrPath != null && arrPath.length > 0)
    {
        for (var a = 0; a < arrPath.length; a++)
        {
            var strDisplay = "none";
            if (eval(strZonaS) > 0 && eval(strZonaS) == eval(arrTipoZona[a]))
                strDisplay = "inline";

            strHtml += "<div id='social_" + arrTipoZona[a] + "' style='display:" + strDisplay + "' style='width:450px'><br/>";
            var strUrl = arrPath[a].replace("&", "&amp;");
            strHtml += "<iframe src='http://www.facebook.com/plugins/like.php?api_key=205861249433491&amp;href=" + strUrl + "&amp;locale=es_ES&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:450px; height:21px;' allowTransparency='true' width='450px'></iframe>";

            strHtml += "<br /><br />";
            strHtml += "<a id='btn_tw' href='http://twitter.com/share' class='twitter-share-button' ";
            strHtml += "data-count='horizontal' data-url='" + strUrl + "' data-text='" + arrTitle[a] + "'>Tweet</a><br /></div>";
        }
    }
    document.getElementById("social").innerHTML = strHtml;
 
    if (strZonaS == "" || eval(strZonaS) <= 0)
        document.getElementById("social_0").style.display = "inline";
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function changeMetasFacebook(idTipoZona)
{
    var arrD = document.getElementsByTagName("div");
    if (arrD.length > 0)
        for (var a = 0; a < arrD.length; a++)
            if( arrD[a].id.indexOf("social_") > -1 )
                document.getElementById(arrD[a].id).style.display = "none";


    document.getElementById("social_" + idTipoZona).style.display = "inline";

   /* var strAjax = "AJAX_META_FACEBOOK";

    $.ajax({
        type: "POST",
        url: document.location.href,
        data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
        "&idTipoZona=" + idTipoZona,
        datatype: "xml",
        success: function (xml)
        {
            var strHtml = "";
            var objXml = xml;
            var tipoZona = objXml.getElementsByTagName("tipoZona");
            var strTitle = "";
            var strDescripcion = "";
            var strImageFace = "";
            var strPath = "";
            if (isExplorer)
            {
                strTitle += tipoZona[0].getElementsByTagName("empresa")[0].text + " - " + tipoZona[0].getElementsByTagName("edificio")[0].text;
                strTitle += ".- " + tipoZona[0].getElementsByTagName("nombre")[0].text + ". ";
                if (tipoZona[0].getElementsByTagName("tipoPrecio")[0].text == "EXACTO")
                    strTitle += "Desde ";
                else
                    strTitle += "Entre ";

                strTitle += tipoZona[0].getElementsByTagName("precio")[0].text + " euros/mes";

                strDescripcion = tipoZona[0].getElementsByTagName("descripcion")[0].text;
                strImageFace = tipoZona[0].getElementsByTagName("imagen")[0].text;
                strPath = tipoZona[0].getElementsByTagName("path")[0].text;
            }
            else
            {
                strTitle += tipoZona[0].getElementsByTagName("empresa")[0].childNodes[0].nodeValue + " - " + tipoZona[0].getElementsByTagName("edificio")[0].childNodes[0].nodeValue;
                strTitle += ".- " + tipoZona[0].getElementsByTagName("nombre")[0].childNodes[0].nodeValue + ". ";
                if (tipoZona[0].getElementsByTagName("tipoPrecio")[0].childNodes[0].nodeValue == "EXACTO")
                    strTitle += "Desde ";
                else
                    strTitle += "Entre ";

                strTitle += tipoZona[0].getElementsByTagName("precio")[0].childNodes[0].nodeValue + " euros/mes";

                strDescripcion = tipoZona[0].getElementsByTagName("descripcion")[0].childNodes[0].nodeValue;
                strImageFace = tipoZona[0].getElementsByTagName("imagen")[0].childNodes[0].nodeValue;
                strPath = tipoZona[0].getElementsByTagName("path")[0].childNodes[0].nodeValue;
            }


          /*  strHtml += "<meta property='og:title' content='" + strTitle + "' />";
            strHtml += "<meta property='og:description' content='" + strDescripcion + "' />";
            strHtml += "<meta property='og:image' content='" + strImageFace + "' />";
            strHtml += "<meta property='og:url' content='" + strPath.replace("**", "&").replace("**", "&") + "' />";

            document.getElementById("<%=MetaFace.ClientID%>").innerHTML = strHtml;*/
     /*   }
    });
    */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function sendEmailShare()
{
 
    if (validateShare())
    {
        var strEdiObj = document.getElementById("hdCurrentEdificio");
        var strEdiVal = "-1";
        if (strEdiObj != null && strEdiObj.value != "")
            strEdiVal = strEdiObj.value;

        var strZonaObj = document.getElementById("hdCurrentZona");
        var strZonaVal = "-1";
        if (strZonaObj != null && strZonaObj.value != "")
            strZonaVal = strZonaObj.value;

        var strTipoZonaObj = document.getElementById("hdCurrentTipoZona");
        var strTipoZonaVal = "-1";
        if (strTipoZonaObj != null && strTipoZonaObj.value != "")
            strTipoZonaVal = strTipoZonaObj.value;


        var strPageObj = document.getElementById("hdCurrentPage");
        var strPageVal = "-1";
        if (strPageObj != null && strPageObj.value != "")
            strPageVal = strPageObj.value;

        

        var strAjax = "AJAX_SEND_MAIL_SHARE";

      
        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&mailFrom=" + encodeURIComponent(document.getElementById("shareEmailFrom").value) +
            "&mailTo=" + encodeURIComponent(document.getElementById("shareEmailTo").value) +
            "&mailBody=" + encodeURIComponent(document.getElementById("shareEmailBody").value) +
            "&edificio=" + strEdiVal +
            "&zona=" + strZonaVal +
            "&page=" + strPageVal +
            "&idTipoZona=" + strTipoZonaVal,
            datatype: "xml",
            success: function (xml)
            {
                if ($(xml).find("status").text() != "1")
                {
                    document.getElementById("emailResp").innerHTML = "Se ha producido un error y el email no se ha podido enviar.";
                }
                else
                {
                    document.getElementById("emailResp").innerHTML = "El email se ha enviado correctamente.";
                }
                document.getElementById("eMailShare").style.visibility = "hidden";
                document.getElementById("emailResp").style.visibility = "visible";
            }
        });
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function validarEmail(valor)
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor))
    { return true; }
    else { return false; }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function validateShare()
{
    var msg = "";
    if ($("#shareEmailTo").val() == "" || !validarEmail($("#shareEmailTo").val()))
    {
        msg += "\n - Inserte una dirección de correo de destinatario válida .";
        $("#shareEmailTo").focus();
    }


    if ($("#shareEmailFrom").val() == "" || !validarEmail($("#shareEmailFrom").val()))
    {
        msg += "\n - Inserte una dirección de correo de origen válida.";
        $("#shareEmailFrom").focus();
    }

    if (msg != "")
    {
        alert("Corrija lo siguientes errores para poder enviar:" + msg);
        return false;
    }
    else
        return true;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function sendEmailForm()
{

    if (validateEmailForm())
    {
        var strEdiObj = document.getElementById("hdCurrentEdificio");
        var strEdiVal = "-1";
        if (strEdiObj != null && strEdiObj.value != "")
            strEdiVal = strEdiObj.value;

        var strZonaObj = document.getElementById("hdCurrentZona");
        var strZonaVal = "-1";
        if (strZonaObj != null && strZonaObj.value != "")
            strZonaVal = strZonaObj.value;


        var strTipoZonaObj = document.getElementById("hdCurrentTipoZona");
        var strTipoZonaVal = "-1";
        if (strTipoZonaObj != null && strTipoZonaObj.value != "")
            strTipoZonaVal = strTipoZonaObj.value;

        var strUnidadObj = document.getElementById("hdCurrentUnidad");
        var strUnidadVal = "-1";
        if (strUnidadObj != null && strUnidadObj.value != "")
            strUnidadVal = strUnidadObj.value;

        var strTZSelected = "0";
        if (document.getElementById("ddlTipoZonaForm") != null && document.getElementById("ddlTipoZonaForm").value != "0")
            strTZSelected = encodeURIComponent(document.getElementById("ddlTipoZonaForm").value);

        var strModoContacto = "EMAIL";

        if (document.getElementById("rdMail").checked)
            strModoContacto = "EMAIL";
        else if (document.getElementById("rdTelefono").checked)
            strModoContacto = "TELEFONO";
        
        var strAjax = "AJAX_SEND_MAIL_FORM";


        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&name=" + encodeURIComponent(document.getElementById("tbxNameForm").value) +
            "&email=" + encodeURIComponent(document.getElementById("tbxEmailForm").value) +
            "&telefono=" + encodeURIComponent(document.getElementById("tbxTelefonoForm").value) +
            "&modoContacto=" + strModoContacto +
            "&comentarios=" + encodeURIComponent(document.getElementById("tbxComentariosForm").value) +
            "&tipoZonaInteres=" + strTZSelected +
            "&edificio=" + strEdiVal +
            "&zona=" + strZonaVal +
            "&unidad=" + strUnidadVal +
            "&idTipoZona=" + strTipoZonaVal,
            datatype: "xml",
            success: function (xml)
            {
                if ($(xml).find("status").text() != "1")
                {
                    document.getElementById("divEmailFormResp").innerHTML = "Se ha producido un error y el email no se ha podido enviar.<br/>Por favor, inténtelo más tarde.";
                }
                else
                {
                    document.getElementById("divEmailFormResp").innerHTML = "El email se ha enviado correctamente.";
                }
                document.getElementById("divEmailForm").style.visibility = "hidden";
                document.getElementById("divEmailFormResp").style.visibility = "visible";
                UXInterestNoVisible();
            }
        });
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function sendEmailFormNew()
{

    if (validateEmailForm())
    {
        var strEdiObj = document.getElementById("hdCurrentEdificio");
        var strEdiVal = "-1";
        if (strEdiObj != null && strEdiObj.value != "")
            strEdiVal = strEdiObj.value;

        var strZonaObj = document.getElementById("hdCurrentZona");
        var strZonaVal = "-1";
        if (strZonaObj != null && strZonaObj.value != "")
            strZonaVal = strZonaObj.value;


        var strTipoZonaObj = document.getElementById("hdCurrentTipoZona");
        var strTipoZonaVal = "-1";
        if (strTipoZonaObj != null && strTipoZonaObj.value != "")
            strTipoZonaVal = strTipoZonaObj.value;

        var strUnidadObj = document.getElementById("hdCurrentUnidad");
        var strUnidadVal = "-1";
        if (strUnidadObj != null && strUnidadObj.value != "")
            strUnidadVal = strUnidadObj.value;

        var strTZSelected = "0";
        if (document.getElementById("ddlTipoZonaForm") != null && document.getElementById("ddlTipoZonaForm").value != "0")
            strTZSelected = encodeURIComponent(document.getElementById("ddlTipoZonaForm").value);

        var strModoContacto = "EMAIL";

        if (document.getElementById("rdMail").checked)
            strModoContacto = "EMAIL";
        else if (document.getElementById("rdTelefono").checked)
            strModoContacto = "TELEFONO";


     
        var strAjax = "AJAX_SEND_MAIL_FORM_NEW";


        $.ajax({
            type: "POST",
            url: document.location.href,
            data: "ajaxRequest=" + strAjax + "&xmlhttp=true" +
            "&name=" + encodeURIComponent(document.getElementById("tbxNameForm").value) +
            "&email=" + encodeURIComponent(document.getElementById("tbxEmailForm").value) +
            "&telefono=" + encodeURIComponent(document.getElementById("tbxTelefonoForm").value) +
            "&modoContacto=" + strModoContacto +
            "&comentarios=" + encodeURIComponent(document.getElementById("tbxComentariosForm").value) +
            "&tipoZonaInteres=" + strTZSelected +
            "&edificio=" + strEdiVal +
            "&zona=" + strZonaVal +
            "&unidad=" + strUnidadVal +
            "&page=" + document.getElementById("hdCurrentPage").value +
            "&idTipoZona=" + strTipoZonaVal,
            datatype: "xml",
            success: function (xml)
            {
                if ($(xml).find("status").text() != "1")
                    document.getElementById("divEmailFormResp").innerHTML = "Se ha producido un error y el email no se ha podido enviar.<br/>Por favor, inténtelo más tarde.";
                else
                    document.getElementById("divEmailFormResp").innerHTML = "El email se ha enviado correctamente.";
             
                document.getElementById("divEmailForm").style.display = "none";
                document.getElementById("divEmailFormResp").style.display = "block";
            }
        });
    }
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function validateEmailForm()
{
    var msg = "";
    if ($("#tbxNameForm").val() == "" )
    {
        msg += "\n - Inserte un nombre válido.";
        $("#tbxNameForm").focus();
    }

    if (document.getElementById("rdMail").checked)
    {
        if ($("#tbxEmailForm").val() == "" || !validarEmail($("#tbxEmailForm").val()))
        {
            msg += "\n - Inserte una dirección de correo válida.";
            $("#tbxEmailForm").focus();
        }
    }
    else if (document.getElementById("rdTelefono").checked)
    {
        if ($("#tbxTelefonoForm").val() == "")
        {
            msg += "\n - Inserte un teléfono de contacto válido.";
            $("#tbxTelefonoForm").focus();
        }
    }
    if (msg != "")
    {
        alert("Corrija lo siguientes errores para poder enviar:" + msg);
        return false;
    }
    else
        return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showMoreNews(numeroMaximoActual, numTotalNews)
{
    if (numTotalNews > numeroMaximoActual)
    {
        var numNewTotalNews = eval(numTotalNews) + eval(document.getElementById("hdNumListNews").value);
        for (var a = 1; a <= numNewTotalNews; a++)
        {
            if (document.getElementById("noticia_" + a))
                document.getElementById("noticia_" + a).style.display = "inline";
        }
        if( numNewTotalNews >= numTotalNews )
            if (document.getElementById("verMasNoticias"))
                document.getElementById("verMasNoticias").style.display = "none";
    }
    else
    {
        if (document.getElementById("verMasNoticias"))
            document.getElementById("verMasNoticias").style.display = "none";
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function goToPage(pageName)
{
    window.location.href = "http://" + document.getElementById("hdDomain").value + "/" + pageName;
}

