﻿//highlight function for searchmatching on a single familyproduct.
//highlights product in family with different backgroundcolor on search-hit.

//on the page http://localhost:2000/Dlx%20Develop/ProductSection/productlist_family.aspx?id=164864&highlight=1004854
function setFamilyProductHighlight() {
    //make sure we are on the right page:
    var url = document.location.toString(); //url
    var matchQuery = "&highlight=";
    if (url.match(matchQuery)) {
        //get the productIdentifier to highlight from querystring:
        var startIndex = url.indexOf(matchQuery);
        var highlightIdentifer = url.slice(startIndex+matchQuery.length, url.length);
        if (highlightIdentifer.length > 0) {
            
            //get panel with cssclass identifier from the highlightquery string:
            // cssclass highlightedFamilyItemDIV
            // attribute identifer

            var div = $(".highlightedFamilyItemDIV");

            if (div.length > 0) {
                //gets the first element (should be only) element in the array:
                div = div[0];
                //make sure to avoid js error that the querystring identifier matches the div identifier for product:
                var identifier = div.getAttribute("identifier");
                if (identifier == highlightIdentifer) {
                    //get the parentcontainer tr:
                    var parentElement = div.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
                    //change css class or background color on tr:
                    parentElement.className = "highlightedFamilyItemRow";
                    //scroll to ypos in browserwindow:
                    //$(parentTR).scrollTo();
                    yPos = getElementTop(parentElement)
                    window.scrollTo(0, yPos); //works in both ff & ie
                    var x = 0;
                }
            }
        }
    }
}

function getElementLeft(Elem) {
    xPos = elem.offsetLeft;
    tempEl = elem.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getElementTop(elem) {
    yPos = elem.offsetTop;
    tempEl = elem.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

