﻿
function replaceAll(text, str1, str2) {
    var command = "text.replace(/" + str1 + "/g,\"" + str2 + "\")";
    return eval(command);
}

//Funcion para reemplazar los acentos
function replaceAcents(cad) {
    cad = replaceAll(cad, "À", "A");
    cad = replaceAll(cad, "Á", "A");
    cad = replaceAll(cad, "Â", "A");
    cad = replaceAll(cad, "Ã", "A");
    cad = replaceAll(cad, "Ä", "A");
    cad = replaceAll(cad, "Å", "A");
    cad = replaceAll(cad, "à", "a");
    cad = replaceAll(cad, "á", "a");
    cad = replaceAll(cad, "â", "a");
    cad = replaceAll(cad, "ã", "a");
    cad = replaceAll(cad, "ä", "a");
    cad = replaceAll(cad, "å", "a");

    cad = replaceAll(cad, "È", "E");
    cad = replaceAll(cad, "É", "E");
    cad = replaceAll(cad, "Ê", "E");
    cad = replaceAll(cad, "Ë", "E");
    cad = replaceAll(cad, "è", "e");
    cad = replaceAll(cad, "é", "e");
    cad = replaceAll(cad, "ê", "e");
    cad = replaceAll(cad, "ë", "e");

    cad = replaceAll(cad, "Ì", "I");
    cad = replaceAll(cad, "Í", "I");
    cad = replaceAll(cad, "Î", "I");
    cad = replaceAll(cad, "Ï", "I");
    cad = replaceAll(cad, "ì", "i");
    cad = replaceAll(cad, "í", "i");
    cad = replaceAll(cad, "î", "i");
    cad = replaceAll(cad, "ï", "i");

    cad = replaceAll(cad, "Ò", "O");
    cad = replaceAll(cad, "Ó", "O");
    cad = replaceAll(cad, "Ô", "O");
    cad = replaceAll(cad, "Õ", "O");
    cad = replaceAll(cad, "Ö", "O");
    cad = replaceAll(cad, 'ò', 'o');
    cad = replaceAll(cad, 'ó', 'o');
    cad = replaceAll(cad, 'ô', 'o');
    cad = replaceAll(cad, 'õ', 'o');
    cad = replaceAll(cad, 'ö', 'o');

    cad = replaceAll(cad, "Ù", "U");
    cad = replaceAll(cad, "Ú", "U");
    cad = replaceAll(cad, "Û", "U");
    cad = replaceAll(cad, "Ü", "U");
    cad = replaceAll(cad, "ù", "u");
    cad = replaceAll(cad, "ú", "u");
    cad = replaceAll(cad, "û", "u");
    cad = replaceAll(cad, "ü", "u");

    cad = replaceAll(cad, "Ý", "Y");
    cad = replaceAll(cad, "Ÿ", "Y");
    cad = replaceAll(cad, "ý", "y");
    cad = replaceAll(cad, "ÿ", "y");
    cad = replaceAll(cad, "Ñ", "N");
    cad = replaceAll(cad, "ñ", "n");
    cad = replaceAll(cad, "Ž", "Z");
    cad = replaceAll(cad, "ž", "z");
    cad = replaceAll(cad, "Š", "S");
    cad = replaceAll(cad, "š", "s");
    cad = replaceAll(cad, "Ç", "C");
    cad = replaceAll(cad, "ç", "c");

    cad = replaceAll(cad, ",", " ");
    //cad = replaceAll(cad, "-", " ");
    cad = replaceAll(cad, ";", " ");
    cad = replaceAll(cad, ":", " ");
    cad = replaceAll(cad, "!", " ");
    cad = replaceAll(cad, "\"", " ");

    return cad;
}

function trim(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return (sString);
}
function cut(sString, sCarac) {
    var vars = sString.split(sCarac);
    return (vars);
}

function validaOnKeyDown(keynum) {
    //|| (keynum == 13)
    if ((keynum >= 65 && keynum <= 90) || (keynum == 27) || (keynum == 13)
        || (keynum == 40) || (keynum == 38) || (keynum == 8) || (keynum == 32)
        || (keynum == 189) || (keynum == 192)) {
        return true;
    }
    else {
        return false;
    }
}

function validaOnKeyPress(e) {
    var keynum = (document.all) ? e.keyCode : e.which;
    keynum = parseInt(keynum);
    //|| (keynum == 13)
    if ((keynum >= 97 && keynum <= 122) || (keynum >= 65 && keynum <= 90)
         || (keynum == 27) || (keynum == 8) || (keynum == 32) 
         || (keynum == 225) || (keynum == 233) || (keynum == 237) || (keynum == 243)
         || (keynum == 250) || (keynum == 45) || (keynum == 241) || (keynum == 209) || (keynum == 0)) {
        return true;
    }
    else {
        return false;
    }
}

function getWinSize() {
    var size = new Object();
    size.w = document.documentElement.clientWidth;
    size.h = document.documentElement.clientHeight;
    return size;
}

function AddToFavorites(obj, title, url) {
    jLogServicio('FA');
    var agt = navigator.userAgent.toLowerCase();
    var app = navigator.appName.toLowerCase();
    if (window.sidebar) {
        // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
        return false;
    } else if (window.external) {
        if (app == 'netscape' && agt.indexOf('chrome')) {//Chrome
            alert("Presione Crtl+D para agregar este sitio en sus Bookmarks");
        }
        else {
            // IE Favorite
            window.external.AddFavorite(url, title);
        }
        return false;
    } else if (window.opera && window.print) {
        alert("Presione Crtl+T para agregar este sitio en sus Bookmarks");
        return false;
    } else if (agt.indexOf('safari')){
        alert("Presione Crtl+D para agregar este sitio en sus Bookmarks");
    }
    
}

function getImagePtdGuia() {
    var cod = $('#dlstGuias option:selected').val();
    var url = "http://www.qdqlaguiautil.com/guias/" + cod + "/images/th/" + cod + "_ptd.gif";
    $('#imgPtdView2').attr('src', url);
    $('#imgPtdView2').css('display', '');
}

function jsCargando(que) {
    var texto = 'Cargando';
    
    if (que == 'mc') { combobox = document.getElementById("ctl00_CPH_ddlMunicipio1"); }
    if (que == 'ma') { combobox = document.getElementById("ctl00_CPH_ddlMunicipio1"); }
    if (que == 'la') { combobox = document.getElementById("ctl00_CPH_ddlLocalidad1"); }
    if (que == 'mfa') { combobox = document.getElementById("ctl00_CPH_ddlMunicipio"); }
    if (que == 'lfa') { combobox = document.getElementById("ctl00_CPH_ddlLocalidad"); }
    if (que == 'map') { combobox = document.getElementById("ctl00_CPH_ddlMunicipio2"); }
    if (que == 'lap') { combobox = document.getElementById("ctl00_CPH_ddlLocalidad2"); }
    if (que == 'ddlMunicipio') { combobox = document.getElementById("ddlMunicipio"); }

    for (var i = (combobox.options.length - 1); i >= 0; i--) { combobox.options[i] = null; }
    combobox.options.add(new Option(texto, 1));
}

function popUpsBlocked() {
    var mine = window.open('', '', 'width=0,height=0,left=0,top=0,scrollbars=no,toolbar=no,menubar=no,location=no');
    var rnt = false;
    if (!mine || mine.closed || typeof mine.closed == 'undefined' || mine == 'undefined')
        rnt = true;
    else {
        rnt = false;
        mine.close();
    }
    return rnt;
}