// function for business picker
function OnBusinessPickerDropDownChange(dropdown) {
    try {
        var index = dropdown.selectedIndex;
        if (index < 1)
            return;
        var selectedValue = dropdown.options[index].value;
        var selectedValues = selectedValue.split("||");
        var params = 'width=' + screen.width + ',height=' + screen.height + ',resizable=yes,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes';
        if (selectedValues[1] == "1") {
            window.open(selectedValues[0], "OpenInNewWindow", params);
        }
        else {
            top.location.href = selectedValues[0];
        }
    }
    catch (err) {
    }
}
//end

//function for where to by zip watermark

function WaterMark(txt, evt) {
    var defaultText = "Enter a Postal Code";
    if (txt.value.length == 0 && evt.type == "blur") {
        txt.style.color = "gray";
        txt.value = defaultText;
    }
    if (txt.value == defaultText && evt.type == "focus") {
        txt.style.color = "black";
        txt.value = "";
    }
}

//end
function eiaHideNonSelectedFacets() {
    // find the parent facet table
    // find children tr of that table, and hide any rows that do not contain the class 'FacetItemsActive'
    $('.FacetItemsActive').closest('table[facet]').find("tr:not(:has('.FacetItemsActive,.FacetHeader'))").hide();
}

function displayEndOfHierarchyField() {
    // Find specific facets of 'ProductCategory' and 'DocumentCategory' 
    $('table[facet=EiaDocumentCategory] a.FacetItems').add('table[facet=EiaProductCategory] a.FacetItems').each(function() {
        var atitle = $(this).attr('title');

        // reformat trancated view into hierarchical view.
        if (atitle.indexOf('>') >= 0) {
            // replace with leaft node
            var newHtml = atitle.split('>').pop();
            $(this).html(newHtml);
        }
    });
}

function removeContentTypeFromAllResultsLinkOnGeneralSearch() {
    var anchorTag = $('.ms-sctabcf a:first');
    var currentLink = anchorTag.attr('href');

    // remove the "contenttype" filter from the link on the "All Results" tab.
    var modifiedLink = currentLink.replace(/contenttype[^&]+&/i, '&');
    anchorTag.attr('href', modifiedLink);
}
