﻿

function CerrarSinRefresh() {
    window.location = window.location;
}

function CerrarConRefresh(urltogo) {
    if (urltogo)
        window.location = urltogo;
    else
        window.location = window.location;
    //self.close();
}

function removeHandler(controlId) {
    //  alert(controlId);
    
        var cbe = $find(controlId);
        //cbe.enabled = false;
        $removeHandler(cbe.get_element(), "click", cbe._clickHandler);
    

}
function attachHandler(controlId,txtElemente) {
if (document.getElementById(txtElemente).value.length > 0) {
    var cbe = $find(controlId);
    
    //$addHandlers(cbe.get_element(), "click", cbe._clickHandler);
    $addHandlers(cbe.get_element(), {
    click: cbe._clickHandler
    }, this);
    }


}
function ponerImagen(control, imagen) {
    var el = control
    if (el != null)
        el.src = imagen
}
function buscar(dominio) {
    var valor = document.getElementById("ctl00_buscador1_key").value
    if (valor.length > 0) {
        redirectPlus('key=' + valor, dominio)
    }
    else {
        var strHref = window.location.href
        if (strHref.indexOf("resultados.aspx") == -1) {
            strHref = dominio + "/resultados.aspx"
        }
        window.location = eliminarP(eliminarP(strHref, "pg"), "key")
    } 
}
function orderby(param) {
    redirectPlus(param, "")
}
function eliminarParam(strParamName) {
    var cadena = ""
    var strHref = window.location.href
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase()
    var aQueryString = strQueryString.split("&")
    for (var iParam = 0; iParam < aQueryString.length; iParam++) {
        var aParam = aQueryString[iParam].split("=")
        if (aParam[0] != strParamName)
            cadena = cadena + aQueryString[iParam] + "&"
    }
    return cadena.substr(0, cadena.length - 1)
}
function eliminarP(strval, strParamName) {
    var cadena = ""
    var strHref = strval
    var agregoQuestionMark = false
    if (strHref.indexOf('?') != -1) {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase()
        var strUrl = strHref.split('?')
        var aQueryString = strQueryString.split('&')
        cadena = strUrl[0]
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            var aParam = aQueryString[iParam].split('=')
            if (aParam[0].charAt(0) == '?')
                aParam[0] = aParam[0].substr(1, aParam[0].length - 1)
            if (aParam[0] != strParamName) {
                if (!agregoQuestionMark) {
                    cadena += "?"
                    agregoQuestionMark = true
                }
                cadena = cadena + aParam[0] + "=" + aParam[1] + "&"
            } 
        }
        if (cadena.charAt(cadena.length - 1) == '&') {
            return cadena.substr(0, cadena.length - 1)
        }
        else {
            return cadena
        } 
    }
    else {
        return strval
    } 
}
function redirectDDPlus(obj) {
    var idxval = obj.options[obj.selectedIndex].value
    var idx = idxval.split("=")
    if (idx[1] == "none") {
        var strHref = window.location.href
        var strQueryString = strHref.split("?")
        strHref = strQueryString[0] + eliminarParam("orden")
    }
    else {
        var strHref = window.location.href
        var strQueryString = strHref.split("?")
        strHref = strQueryString[0] + eliminarParam("orden") + "&" + obj.options[obj.selectedIndex].value
    }
    window.location = eliminarP(strHref, "p")
}
function urlRewrite(obj) { 

}
function redirectPlus(strP, dominio) {
    var campos = strP.split('=')
    var strHref = window.location.href
    if (strHref.indexOf("resultados.aspx") == -1) {
        strHref = dominio + "/resultados.aspx"
    }
    if (strHref.indexOf("key") != -1) {
        strHref = eliminarP(strHref, "key")
    }
    var strQueryString = strHref.split('?')
    if (strQueryString.length > 1) {
        strHref = eliminarP(strHref, campos[0]) + "&" + strP
    }
    else {
        strHref = eliminarP(strHref + "?" + strP, "pg")
    }
    window.location = strHref
}
function filtrarCategoria(idCat) {
    var strHref = window.location.href
    var startIndex = strHref.indexOf("?idcategoria=")
    startIndex = startIndex + 13
    var nextIndex = strHref.indexOf("&")
    if (nextIndex != -1) {
        window.location = eliminarP(strHref.substr(0, startIndex) + idCat + strHref.substr(nextIndex), "pg")
    }
    else {
        window.location = eliminarP(strHref.substr(0, startIndex) + idCat, "pg")
    } 
}
