﻿function cmpr_reloadFilter(obj, url, idcat) {
    if (!idcat)
        window.location.href = url + '?ct_param_var=' + obj;
    else
        window.location.href = url + '?ct_param_var=' + obj + '&idcat=' + idcat;
}

function cmpr_loadProduct(obj,idcat) { 
    var oAjax = new WBE_AjaxClass();
    oAjax.addPostParameter('idProduct', obj);

    document.getElementById('hd_idcat').value = idcat;
	var olist;
	var i;
	olist = document.getElementsByTagName('a');
	for(i=0;i<olist.length;i++)
	{
		if(olist[i].id.split('_1') != null)
		{
			olist[i].style.fontWeight = "normal";
		}
	} 
	document.getElementById(obj+'_1').style.fontWeight = "bold";
	
   // this.savePre();
    xmlObj = oAjax.throwEventXML('cmpr_load_product');
    //this.savePost(xmlObj);
    if (xmlObj) {
        if (xmlObj.childNodes[0].firstChild.nodeValue == 'ok')
            alert("Producto añadido al comparador correctamente.");
        else
            alert("No se ha podido añadir el producto al comparador.");
    }
    else {
        alert("No se ha podido añadir el producto al comparador.");
    }
}

function cmpr_loadProduct3(obj,idcat) { 
    var oAjax = new WBE_AjaxClass();
    oAjax.addPostParameter('idProduct', obj);

    document.getElementById('hd_idcat').value = idcat;
	var olist;
	var i;
	olist = document.getElementsByTagName('a');
	for(i=0;i<olist.length;i++)
	{
		if(olist[i].id.split('_2') != null)
		{
			olist[i].style.fontWeight = "normal";
		}
		
	} 
	
	document.getElementById(obj+'_2').style.fontWeight = "bold";
   // this.savePre();
    xmlObj = oAjax.throwEventXML('cmpr_load_product');
    //this.savePost(xmlObj);
    if (xmlObj) {
        if (xmlObj.childNodes[0].firstChild.nodeValue == 'ok')
            alert("Producto añadido al comparador correctamente.");
        else
            alert("No se ha podido añadir el producto al comparador.");
    }
    else {
        alert("No se ha podido añadir el producto al comparador.");
    }
}
function cmpr_Reset() {
    var oAjax = new WBE_AjaxClass();
    xmlObj = oAjax.throwEventXML('cmpr_reset_comparer');
}

function cmpr_Compare(obj) {
    if (document.getElementById('hd_idcat').value == 0) {
        alert('Seleccione los productos a comparar.');
        return false;
    }
    var oAjax = new WBE_AjaxClass();
    xmlObj = oAjax.throwEventXML('cmpr_compare_product');
    if (xmlObj) {
        if (xmlObj.childNodes[0].firstChild.nodeValue == 'ok')
            window.location.href = 'comparador_resultado.html?ct_param_var=' + obj + '&idcat=' + document.getElementById('hd_idcat').value;
        else if (xmlObj.childNodes[0].firstChild.nodeValue == 'equal')
            alert("Ha seleccionado dos productos iguales.\nSeleccione dos productos distintos para realizar la comparación.");
        else 
            alert("Seleccione dos productos para realizar la comparación.");
    }
    else {
        alert("Seleccione dos productos para realizar la comparación.");
    }
}
 
function getValue(sElemName, bFailIfNotExists) {
    var oElem = eval('document.InmediaFrm.' + sElemName);
    var sValue = '';
    if ((bFailIfNotExists != undefined) && (bFailIfNotExists == false) && !(oElem)) {
    return '';
    }
    if (oElem.length) {
    for (var i = 0; i < oElem.length; i++) {
    if (oElem[i].checked) {
    if (sValue != '') sValue += ',';
    sValue += oElem[i].value;
    } else {
    if (oElem[i].selected) {
    if (sValue != '') sValue += ',';
    sValue += oElem[i].value;
    }
    }
    }
    }
    else
    {
    if (oElem.type == "checkbox" || oElem.type == "radio") sValue = (oElem.checked) ? oElem.value : "";
    else sValue = oElem.value;
    }
    return sValue;
}


function cmp() {
    var id = getValue('filterProductType', false);
    cmpr_Compare(id);
}

function cmpr_loadProduct2(obj) {
    var sel = getValue(obj, false);

    var idprod = sel.split("_")[0].toString();
    var idcat = sel.split("_")[1].toString();

    cmpr_loadProduct(idprod, idcat);
    cmpr_Compare(idprod);
    window.location.reload();
    
}
