﻿
var reqArray = new Array(createInstance(), createInstance());
var result;

function visibleDiv(_d) {
    try {
        var _x = document.getElementById(_d);
        _x.style.display = _x.style.display == "none" ? "block" : "none";
    }
    catch (err) {
        return;
    }
}
function switchDiv(_d) {
    try {
        var _x = document.getElementById(_d);
        _x.style.display = _x.style.display == "none" ? "block" : "none";
    }
    catch (err) {
        return;
    }
}

var open2 = false;
var count = 0;
function switchImage(_d) {
    count++;
    if (count > 1) {
        try {
            var _x = document.getElementById(_d);
            if (!open2) {
                _x.className = "td_geo_tit";

                open2 = true;
            }
            else {
                _x.className = "td_geo_tit2";

                open2 = false;
            }
        }
        catch (err) {
            return;
        }
    }
}

// Funcion que genera el objeto xmlHttpRequest

function createInstance() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {

        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {

            xmlhttp = false;
        }
    }
    @else
  xmlhttp = false;
  @end
    @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

var AC = createInstance();
var actual;
var b = 0;
function Paginacion(PageNumber) {
    StartThinking();
	if (b == 0) {        
        Sys.Application.add_navigate(onNavigate);
    }    
    var historyPoint = { pageState: PageNumber };
    var title = "Browser History " + PageNumber;
    Sys.Application.addHistoryPoint(historyPoint, title);
	b = 1;
}
function Paginacion1(PageNumber) {
    StartThinking();
    var que = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtQue').value;
    var donde = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtDonde').value;
    var peticion = 'Listados.aspx?tipoLlamada=paginacion&que=' + que + '&donde=' + donde + '&numPag=' + PageNumber + '&rnd=' + Math.floor(Math.random() * (350 + 1));

    AC.open('get', peticion, true);
    AC.onreadystatechange = success;
    AC.send(null);
}


function PaginacionProx(PageNumber) {
    /*StartThinking();    
    AC.open('get', 'ProximitySearch.aspx?tipoLlamada=paginacion&numPag='+PageNumber+'&rnd='+Math.floor(Math.random( ) * (350+1)));
    AC.onreadystatechange = success;    
    AC.send(null);    */
    document.forms[0].iPageNumber.value = PageNumber;
    document.forms[0].action = "ProximitySearch.aspx";
    document.forms[0].submit();
}

function success() {
    if (AC.readyState == 4) {
        var response = AC.responseText;
        CallBack(response);
    }
}
function CallBack(response) {
    StopThinking();
    result = response;
    document.getElementById('resultadosListados').innerHTML = result;
}

function StartThinking() {
    try {
        var ventanaHeight = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
        ventanaHeight = ventanaHeight / 2;
        ventanaHeight = window.document.body.scrollTop + ventanaHeight;
        var comboHeight = FindPosition(document.getElementById('DelMunUP'))[1];
        var comboHeightFin = comboHeight + 30;
        comboHeight -= 60;

        if (ventanaHeight > comboHeight && ventanaHeight < comboHeightFin)
            ventanaHeight = comboHeight;

        comboHeight = FindPosition(document.getElementById('DelMunDown'))[1];
        comboHeightFin = comboHeight + 30;
        comboHeight -= 60;
        if (ventanaHeight > comboHeight && ventanaHeight < comboHeightFin)
            ventanaHeight = comboHeight;

        var ventanaWidth = FindPosition(document.getElementById('tablaContenedora'))[0]
        ventanaWidth += 585 / 2;
        ventanaWidth -= 48;
        document.getElementById('ajaxDiv').style.display = "block";
        document.getElementById('ajaxDiv').style.left = ventanaWidth;
	if(navigator.appName == "Microsoft Internet Explorer")
        	document.getElementById('ajaxDiv').style.top = 300;
    } catch (err) {
        return;
    }
}
function StopThinking() {
    window.scrollTo(0, 0);
    document.getElementById('ajaxDiv').style.display = "none";
}
function FindPosition(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
        while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}
function AbrirVentanaInformacion(idListado, nombreComercial, calle, colonia, cp, telefono, lat, lon, tipo) {
    if (lat == "") {
        lat = "0.00";
    }
    if (lon == "") {
        lon = "0.00";
    }

    document.forms[0].squery.value = idListado;
    document.forms[0].idListado.value = idListado;
    document.forms[0].nombreComercial.value = nombreComercial;
    document.forms[0].calle.value = calle;
    document.forms[0].colonia.value = colonia;
    document.forms[0].cp.value = cp;
    document.forms[0].telefono.value = telefono;
    document.forms[0].lat.value = lat;
    document.forms[0].lon.value = lon;
    calle = calle.replace(/#/g, "");
    if (tipo == 'Rate')
        document.forms[0].action = "Ventana.aspx?tipo=" + tipo;
    else
        document.forms[0].action = "Ventana.aspx?tipo=#" + tipo;
    document.forms[0].submit();
}
function FiltraResultado(tipoFiltro, identificador) {
    StartThinking();
    var que = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtQue').value;
    var donde = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtDonde').value;
    var delMun = document.getElementById('DelMun' + identificador).value;
    var colonia = document.getElementById('Colony' + identificador).value;
    var categoria = document.getElementById('Categorias' + identificador).value;
    var catName = document.getElementById('Categorias' + identificador).value;

    if (tipoFiltro == "delMun") {
        colonia = "";
        categoria = "";
        if (delMun == "0")
            delMun = "";
    }
    else if (tipoFiltro == "colonia") {
        delMun = "";
        categoria = "";
        if (colonia == "0")
            colonia = "";
    }
    else if (tipoFiltro == "categoria") {
        delMun = "";
        colonia = "";
        if (categoria == "0")
            categoria = "";
    }
    AC.open('get', 'Listados.aspx?tipoLlamada=filtro&que=' + que + '&donde=' + donde + '&tipoFiltro=' + tipoFiltro + '&delMun=' + delMun + '&colonia=' + colonia + '&categoria=' + categoria + '&catName=' + catName + '&rnd=' + Math.floor(Math.random() * (350 + 1)));
    AC.onreadystatechange = success;
    AC.send(null);
}
function BuscaPorCategoria(categoryId, categoryName) {
    StartThinking();
    var que = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtQue').value;
    var donde = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtDonde').value;
    AC.open('get', 'Listados.aspx?tipoLlamada=buscaCategoria&que=' + que + '&donde=' + donde + '&categoryId=' + categoryId + '&categoryName=' + categoryName + '&rnd=' + Math.floor(Math.random() * (350 + 1)));
    AC.onreadystatechange = success;
    AC.send(null);
}
function BuscaPorCategoriaSugerencias(categoryId, categoryName) {
    StartThinking();
    var que = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtQue').value;
    var donde = document.getElementById('ctl00_cphMenuHeader_HeaderListados1_txtDonde').value;
    AC.open('get', 'Listados.aspx?tipoLlamada=buscaCategoriaSugerencias&que=' + que + '&donde=' + donde + '&categoryId=' + categoryId + '&categoryName=' + categoryName + '&rnd=' + Math.floor(Math.random() * (350 + 1)));
    AC.onreadystatechange = success;
    AC.send(null);
}
function FiltraDidYouMean(que, donde) {
    StartThinking();
    CambiaQue(que);
    AC.open('get', 'Listados.aspx?tipoLlamada=didYouMean&que=' + que + '&donde=' + donde + '&rnd=' + Math.floor(Math.random() * (350 + 1)));
    AC.onreadystatechange = success;
    AC.send(null);
}
function ValidaBusqueda(DelMun, que, donde, ZipCode) {

    StartThinking();
    try {
        //document.getElementById('tdBackGeo').innerHTML = "";
        document.getElementById('resultadosGeo').innerHTML = "";
        document.getElementById('resultadosListados').innerHTML = "";
    }
    catch (err) {
        alert(err);
    }

    CambiaDonde(donde);
    AC.open('get', 'Listados.aspx?tipoLlamada=Geo&que=' + que + '&donde=' + donde + '&delmun=' + DelMun + '&zipcode=' + ZipCode + '&rnd=' + Math.floor(Math.random() * (350 + 1)));
    AC.onreadystatechange = success;
    AC.send(null);


}
function ReturnListado() {
    window.location = "Listados.aspx";
}

function setAsHomePage() {
    document.body.style.behavior = 'url(#default#homepage)';
    document.body.setHomePage(location.href);
}


function trim(strTexto) {
    var cont = 0, strNuevo = "", strVerifica;
    strVerifica = strTexto;
    longitud = strVerifica.length;
    bandera = 0;

    while (cont < longitud && strVerifica.substring(cont, cont + 1) == " ")
        cont++;

    while (longitud > 0 && strVerifica.substring(longitud, longitud - 1) == " ")
        longitud--;

    while (cont < longitud) {
        if (strVerifica.substring(cont, cont + 1) == " ") {
            if (bandera == 0) {
                strNuevo += strVerifica.substring(cont, cont + 1);
                bandera = 1;
            }
        }
        else {
            strNuevo += strVerifica.substring(cont, cont + 1);
            bandera = 0;
        }
        cont++;
    }
    return strNuevo;
}


function moveover() {
    window.status = "Mapa de Ubicación del Cliente";
}
function moveoverWeb() {
    window.status = "Liga a Pagina Web";

}
function moveoverEmail() {
    window.status = "Liga a Email";
}
function moveoverMini() {
    window.status = "Liga a MiniSitio";
}
function Ventana01800(IdListado)
{ window.open("Ventana01800.asp?IdListado=" + IdListado, 'neww1', 'scrollbars=yes,status=yes,width=500,height=550,left=20px,top=20px'); }

function AbreCupon(idCupon) {
    window.open("detalle_cupones.asp?IdCupon=" + idCupon, 'cupon', 'scrollbars=no,status=yes,width=553,height=290');
}

function LinkVideo(Liga)
{ window.open("http://" + Liga, 'Video', 'scrollbars=yes,status=yes,width=640,height=480,left=20px,top=20px'); }

function LinkAudio(Liga)
{ window.open("http://" + Liga, 'Audio', 'scrollbars=yes,status=yes,width=640,height=480,left=20px,top=20px'); }


function ListadoProducto(idListado, producto, valor, que, donde) {

    if (producto == "LKE")
        document.location.href = "mailto:" + valor;
    var url = "CountProducto.aspx?idListado=" + idListado + "&IdProd=" + producto + "&URL=" + valor + "&que=" + que + "&donde=" + donde;
    window.open(url, '', '');

}




function startMapFunction() {
    try {
        //window.alert('fsgdsfg');
Sys.Application.remove_navigate(onNavigate);
        startMap();
    }
    catch (err) {
        return;
    }
}