﻿//start BFM

var dvSPD = document.getElementById('dvSPD');
var eM = "error loading specifications breakdown. please reload page.";
var theH = '';

function pageLoad() {
    if (document.getElementById("dvSPD") != null) {
        LoadSPBD();
    }
}

function LoadSPBD() {
    var ret;
    ret = ProductsSpecsBreakDown.GetRecordsKW(kw, kori, aoe, incats, inspecs, min, max, qp, fp, OnCompleteOneDV, OnTimeOutDV, OnErrorDV);
}

function OnCompleteOneDV(result) {
    var res = '';
    var m, sT, eT, mN;
    if (result.length > 0) {
        mN = result[0].MasterName;
        res += '<span class="spnBD">' + mN + '</span><br /> ';
        cnt = 0;
        iCnt = 0; hasiCnt = 0;
        for (var i = 0; i < result.length; i++) {

            if (mN != result[i].MasterName) {
                mN = result[i].MasterName;
                res += '<span class="spnBD">' + mN + '</span><br /> ';
                res += '<div class="dvBD">';
                cnt = 1;

            }
            else if (cnt == 0) {
                res += '<div class="dvBD">';
                cnt = 1;
            }

            if (iCnt == 2) {
                res += '<span class="spnI" onclick="haler(' + result[i].ID + ')" id="spnI' + result[i].ID + '"><img src="scripts/plus1.gif" />more</span><div class="dvI" id="dvI' + result[i].ID + '">';
                hasiCnt = 1;
            }

            HrefMe(result[i].ID);
            m = "<a " + theH + ">" + result[i].DetailName + " (" + result[i].Count + ")</a><br /> ";
            theH = "";
            res += m;
            iCnt++;

            if (((i + 1) < result.length) && (mN != result[i + 1].MasterName)) {
                if (hasiCnt == 1)
                    res += '</div>';
                res += '</div>';
                cnt = 0;
                iCnt = 0;
                hasiCnt = 0;
            }

        }
        if (hasiCnt == 1)
            res += '</div>';
        res += '</div>';
    }
    else {
        res = 'specifications were not defined for this query';
    }
    //alert(res);
    dvSPD.innerHTML = res;
}
function OnTimeOutDV(result) { dvSPD.innerHTML = eM; }
function OnErrorDV(result) { dvSPD.innerHTML = eM; }

function HrefMe(id) {
    var theS = id;
    theH = " href='filteredview.aspx?t=s"
    if (kw != '')
        theH += "&kw=" + kw;
    if (kori != '')
        theH += "&kori=" + kori;
    if (aoe != '')
        theH += "&aoe=" + aoe;
    if (fp != '')
        theH += "&fp=" + fp;
    if (min != '')
        theH += "&min=" + min;
    if (max != '')
        theH += "&max=" + max;
    if (qp != '')
        theH += "&qp=" + qp;
    if (incats != '')
        theH += "&c=" + incats;
    if (theS != '')
        theH += "&s=" + theS;

    theH += "' ";
}


function haler(x) {
    var h = x.toString();
    document.getElementById("spnI" + h).style.visibility = "hidden";
    document.getElementById("spnI" + h).style.display = "none";
    //document.getElementById("dvI" + h).style.visibility = "visible";
    //document.getElementById("dvI" + h).style.block = "block";
    document.getElementById("dvI" + h).className = "dvV";
}
//end BFM
