function TreeNodeClick(params) {
    SetMediaSearchDefaultValues();
    SetSearchParams(params);
    var p = eval(params);
    UsePressReleases(p.UsePressReleases);
    UseMyLocalCompany(p.UseExtendedEntitlements);
    UsePhotoArchive(p.UsePhotoArchive);
    document.fire("TreeNodeClick:MediaSearch", { Params: eval(params) });
    document.fire("TreeNodeClick:BreadCrumbEvent", { Params: eval(params) });
    if (p.SearchType == "Product") {
        _wt.dcsMultiTrack('DCS.dcsuri', '/pages/portal.aspx', 'WT.ti', p.SearchName, 'WT.dl', '0','DCSext.area','Scan News Topics');
    }
}
function OpenInternalURL(url) {
    window.location = url;
}
function PopUpExternalUrl(Url) {
    var h = 750;
    var w = 800;
    var lp = (screen.width) ? (screen.width - w) / 2 : 0;
    var tp = (screen.height) ? (screen.height - h) / 2 : 0;
    window.open(Url, null, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=' + w + ',height=' + h + ',left=' + lp + ',top=' + tp);
}
function TreeNodeClickEmptyFilter() {
    return;
}
function TreeNodeClick1(params) {
    params = unescape(params);
    var chk = document.getElementById("_chk");  
    SetMediaSearchDefaultValues();
    SetSearchParams(params);
    var p = eval(params);
    chk.checked=false;
    if (p.WithinItems != null) 
    {
        p.WithinItems.length > 1 ? chk.checked = true : chk.checked = false;
        for (i = 0; i < p.WithinItems.length; i++) {
            if (p.WithinItems[i] != null) {
                p.WithinItems[i] = p.WithinItems[i].replace("+", " ");
            }
        }
    }
    if (p.SearchName != null) {
        var intIndexOfMatch = p.SearchName.indexOf("+");
        // Loop over the p.SearchName value to replace "+" with " " 
        while (intIndexOfMatch != -1) {
            p.SearchName = p.SearchName.replace("+", " ")
            intIndexOfMatch = p.SearchName.indexOf("+");
        }
    }
    UsePressReleases(p.UsePressReleases);
    UseMyLocalCompany(p.UseExtendedEntitlements);
    UsePhotoArchive(p.UsePhotoArchive);
    document.fire("TreeNodeClick:MediaSearch", { Params: p });
    document.fire("TreeNodeClick:BreadCrumbEvent", { Params: p });
}
function WatchListManageClick(watchListID, watchListName, userID) {
    SetMediaSearchDefaultValues();
    var SearchParamsObj = new __JsonSearchParamsObject();
    SearchParamsObj.SearchItem = watchListID + "$" + userID;
    SearchParamsObj.MediaType = "Auto";
    SearchParamsObj.SearchName = watchListName;
    SearchParamsObj.SearchType = "WatchList";
    SetJsonParams(SearchParamsObj);
    document.fire("TreeNodeClick:MediaSearch", { Params: SearchParamsObj });
}
function SetMediaSearchDefaultValues() {
    Text.IsRendered = false;
    Photo.IsRendered = false;
    Graphic.IsRendered = false;
    Video.IsRendered = false;
    Interactive.IsRendered = false;
    Audio.IsRendered = false;
    Text.ShowAnimation(false);
    Photo.ShowAnimation(false);
    Graphic.ShowAnimation(false);
    Video.ShowAnimation(false);
    Interactive.ShowAnimation(false);
    Audio.ShowAnimation(false);
    Photo.SearchParams.MediaType = "Photo";
    Text.SearchParams.MediaType = "Text";
    Graphic.SearchParams.MediaType = "Graphic";
    Video.SearchParams.MediaType = "Video";
    Interactive.SearchParams.MediaType = "Interactive";
    Audio.SearchParams.MediaType = "Audio";
}
function SetSearchParams(params) {
    var x = eval(params);
    SetJsonParams(x);
}
function SetJsonParams(jsonObj) {
    Text.SetSearchParams(jsonObj);
    Photo.SetSearchParams(jsonObj);
    Graphic.SetSearchParams(jsonObj);
    Video.SetSearchParams(jsonObj);
    Interactive.SetSearchParams(jsonObj);
    Audio.SetSearchParams(jsonObj);
}
function SpellCheckSearch(value) {
    var _WithinItems = null;
    var SearchParamsObj = new __JsonSearchParamsObject();
    Text.SearchParams.WithinItems.splice(Text.SearchParams.WithinItems.length - 1, 1, value);
    Text.IsRendered = false;
    Photo.SearchParams.WithinItems.splice(Photo.SearchParams.WithinItems.length - 1, 1, value);
    Photo.IsRendered = false;
    Graphic.SearchParams.WithinItems.splice(Graphic.SearchParams.WithinItems.length - 1, 1, value);
    Graphic.IsRendered = false;
    Video.SearchParams.WithinItems.splice(Video.SearchParams.WithinItems.length - 1, 1, value);
    Video.IsRendered = false;
    Interactive.SearchParams.WithinItems.splice(Interactive.SearchParams.WithinItems.length - 1, 1, value);
    Interactive.IsRendered = false;
    Audio.SearchParams.WithinItems.splice(Audio.SearchParams.WithinItems.length - 1, 1, value);
    Audio.IsRendered = false;
    if (IsVisible('text')) {
        SearchParamsObj = Text.SearchParams;
    }
    else if (IsVisible('photos')) {
        SearchParamsObj = Photo.SearchParams;
    }
    else if (IsVisible('graphics')) {
        SearchParamsObj = Graphic.SearchParams;
    }
    else if (IsVisible('video')) {
        SearchParamsObj = Video.SearchParams;
    }
    else if (IsVisible('interactive')) {
        SearchParamsObj = Interactive.SearchParams;
    }
    else if (IsVisible('audio')) {
        SearchParamsObj = Audio.SearchParams;
    }
    PublishMediaSearch(SearchParamsObj);
    return (false);

}
function ShowHide30DayText(dvId, lstId, dvaudioId) {
    var dvMax30Day = document.which(dvId);
    var dv3DAudioDay = document.which(dvaudioId);
    var lstInterval = document.which(lstId);
    var lstSelectedValue = lstInterval.options[lstInterval.selectedIndex].value;
    if (lstSelectedValue == "Max") {
        dvMax30Day.style.display = "block";
        dv3DAudioDay.style.display = "none";
    }
    else if (lstSelectedValue != "OneDay" && lstSelectedValue != "ThreeDays") {
        dvMax30Day.style.display = "none";
        dv3DAudioDay.style.display = "block";
    }
    else {
        dvMax30Day.style.display = "none";
        dv3DAudioDay.style.display = "none";
    }
}
function BreadCrumbSearch(index) {
    var _WithinItems = null;
    var SearchParamsObj = new __JsonSearchParamsObject();
    Text.SearchParams.WithinItems = SpliceWithinItems(Text.SearchParams.WithinItems, index);
    Text.IsRendered = false;
    Photo.SearchParams.WithinItems = SpliceWithinItems(Photo.SearchParams.WithinItems, index);
    Photo.IsRendered = false;
    Graphic.SearchParams.WithinItems = SpliceWithinItems(Graphic.SearchParams.WithinItems, index);
    Graphic.IsRendered = false;
    Video.SearchParams.WithinItems = SpliceWithinItems(Video.SearchParams.WithinItems, index);
    Video.IsRendered = false;
    Interactive.SearchParams.WithinItems = SpliceWithinItems(Interactive.SearchParams.WithinItems, index);
    Interactive.IsRendered = false;
    Audio.SearchParams.WithinItems = SpliceWithinItems(Audio.SearchParams.WithinItems, index);
    Audio.IsRendered = false;
    if (IsVisible('text')) {
        SearchParamsObj = Text.SearchParams;
    }
    else if (IsVisible('photos')) {
        SearchParamsObj = Photo.SearchParams;
    }
    else if (IsVisible('graphics')) {
        SearchParamsObj = Graphic.SearchParams;
    }
    else if (IsVisible('video')) {
        SearchParamsObj = Video.SearchParams;
    }
    else if (IsVisible('interactive')) {
        SearchParamsObj = Interactive.SearchParams;
    }
    else if (IsVisible('audio')) {
        SearchParamsObj = Audio.SearchParams;
    }
    PublishMediaSearch(SearchParamsObj);
    return (false);
}
function SpliceWithinItems(_WithinItems, index) {
    var _NewWithinItems = new Array();
    for (var i = 0; i < _WithinItems.length; i++) {
        if (i <= index)
            _NewWithinItems.push(_WithinItems[i]);
        else
            break;
    }
    return _NewWithinItems;
}
function SetWithinList(wArr) {
    if (Text.SearchParams != null) {
        if (Text.SearchParams.WithinItems != null && ItemExists(Text.SearchParams.WithinItems, wArr) == false)
            Text.SearchParams.WithinItems.push(wArr);
        else if (Text.SearchParams.WithinItems == null)
            Text.SearchParams.WithinItems = new Array(wArr);
        Text.IsRendered = false;
    }
    if (Photo.SearchParams != null) {
        if (Photo.SearchParams.WithinItems != null && ItemExists(Photo.SearchParams.WithinItems, wArr) == false)
            Photo.SearchParams.WithinItems.push(wArr);
        else if (Photo.SearchParams.WithinItems == null)
            Photo.SearchParams.WithinItems = new Array(wArr);
        Photo.IsRendered = false;
    }
    if (Graphic.SearchParams != null) {
        if (Graphic.SearchParams.WithinItems != null && ItemExists(Graphic.SearchParams.WithinItems, wArr) == false)
            Graphic.SearchParams.WithinItems.push(wArr);
        else if (Graphic.SearchParams.WithinItems == null)
            Graphic.SearchParams.WithinItems = new Array(wArr);
        Graphic.IsRendered = false;
    }
    if (Video.SearchParams != null) {
        if (Video.SearchParams.WithinItems != null && ItemExists(Video.SearchParams.WithinItems, wArr) == false)
            Video.SearchParams.WithinItems.push(wArr);
        else if (Video.SearchParams.WithinItems == null)
            Video.SearchParams.WithinItems = new Array(wArr);
        Video.IsRendered = false;
    }
    if (Interactive.SearchParams != null) {
        if (Interactive.SearchParams.WithinItems != null && ItemExists(Interactive.SearchParams.WithinItems, wArr) == false)
            Interactive.SearchParams.WithinItems.push(wArr);
        else if (Interactive.SearchParams.WithinItems == null)
            Interactive.SearchParams.WithinItems = new Array(wArr);
        Interactive.IsRendered = false;
    }
    if (Audio.SearchParams != null) {
        if (Audio.SearchParams.WithinItems != null && ItemExists(Audio.SearchParams.WithinItems, wArr) == false)
            Audio.SearchParams.WithinItems.push(wArr);
        else if (Audio.SearchParams.WithinItems == null)
            Audio.SearchParams.WithinItems = new Array(wArr);
        Audio.IsRendered = false;
    }
}
function ItemExists(ItemArray, Item) {
    var status = false;
    for (var i = 0; i < ItemArray.length; i++) {
        if (ItemArray[i].toString().toUpperCase() == Item.toUpperCase())
            status = true;
    }
    return status;
}
function SpellSuggestionValue() {
    var hdnSpellSuggestion = "";
    var newValue = "";
    if (IsVisible('text')) {
        hdnSpellSuggestion = document.which('text').getElementsByTagName('INPUT')[0].value;
    }
    else if (IsVisible('photos')) {
        hdnSpellSuggestion = document.which('photos').getElementsByTagName('INPUT')[0].value;
    }
    else if (IsVisible('graphics')) {
        hdnSpellSuggestion = document.which('graphic').getElementsByTagName('INPUT')[0].value;
    }
    else if (IsVisible('video')) {
        hdnSpellSuggestion = document.which('video').getElementsByTagName('INPUT')[0].value;
    }
    else if (IsVisible('interactive')) {
        hdnSpellSuggestion = document.which('interactive').getElementsByTagName('INPUT')[0].value;
    }
    else if (IsVisible('audio')) {
        hdnSpellSuggestion = document.which('audio').getElementsByTagName('INPUT')[0].value;
    }
    if (hdnSpellSuggestion != null && hdnSpellSuggestion.length > 0) {
        var temp = new Array();
        var date1RegEx = /m[0-9][0-9]d[0-9][0-9]y[0-9][0-9][0-9][0-9]/i;
        var date2RegEx = /m[0-9]d[0-9][0-9]y[0-9][0-9][0-9][0-9]/i;
        var date3RegEx = /m[0-9][0-9]d[0-9]y[0-9][0-9][0-9][0-9]/i;
        var date4RegEx = /m[0-9]d[0-9]y[0-9][0-9][0-9][0-9]/i;
        var date5RegEx = /wk[0-9][0-9]y[0-9][0-9][0-9][0-9]/i;
        var date6RegEx = /wk[0-9]y[0-9][0-9][0-9][0-9]/i;
        var date7RegEx = /m[0-9][0-9]y[0-9][0-9][0-9][0-9]/i;
        var date8RegEx = /m[0-9]y[0-9][0-9][0-9][0-9]/i;
        var isDate = true;
        temp = hdnSpellSuggestion.split(',');
        if (temp.length >= 1) {
            isDate = date1RegEx.test(temp[0]);
            if (!isDate)
                isDate = date2RegEx.test(temp[0]);
            if (!isDate)
                isDate = date3RegEx.test(temp[0]);
            if (!isDate)
                isDate = date4RegEx.test(temp[0]);
            if (!isDate)
                isDate = date5RegEx.test(temp[0]);
            if (!isDate)
                isDate = date6RegEx.test(temp[0]);
            if (!isDate)
                isDate = date7RegEx.test(temp[0]);
            if (!isDate)
                isDate = date8RegEx.test(temp[0]);
            if (temp[0].toUpperCase() != "NEW" && !isDate)
                newValue = temp[0];
        }
    }
    return newValue;
}
function ChkOnlick() {
    var chk = document.getElementById('_chk');
    if (chk.value != "on") {
        Text.SearchParams.WithinItems = null;
        Photo.SearchParams.WithinItems = null;
        Graphic.SearchParams.WithinItems = null;
        Video.SearchParams.WithinItems = null;
        Interactive.SearchParams.WithinItems = null;
        Audio.SearchParams.WithinItems = null;
        Text.IsRendered = false;
        Photo.IsRendered = false;
        Graphic.IsRendered = false;
        Video.IsRendered = false;
        Interactive.IsRendered = false;
        Audio.IsRendered = false;
    }
}
function PhotoArchiveOnclick() {
    var chk = document.getElementById('_ppa');
    if (chk.value != "on") {
        Text.SearchParams.UsePhotoArchive = false;
        Photo.SearchParams.UsePhotoArchive = false;
        Graphic.SearchParams.UsePhotoArchive = false;
        Video.SearchParams.UsePhotoArchive = false;
        Interactive.SearchParams.UsePhotoArchive = false;
        Audio.SearchParams.UsePhotoArchive = false;
        Text.IsRendered = false;
        Photo.IsRendered = false;
        Graphic.IsRendered = false;
        Video.IsRendered = false;
        Interactive.IsRendered = false;
        Audio.IsRendered = false;
    }
}
function PressReleasesOnlick() {
    var chk = document.getElementById('_prl');
    if (chk.value != "on") {
        Text.SearchParams.UsePressReleases = false;
        Photo.SearchParams.UsePressReleases = false;
        Graphic.SearchParams.UsePressReleases = false;
        Video.SearchParams.UsePressReleases = false;
        Interactive.SearchParams.UsePressReleases = false;
        Audio.SearchParams.UsePressReleases = false;
        Text.IsRendered = false;
        Photo.IsRendered = false;
        Graphic.IsRendered = false;
        Video.IsRendered = false;
        Interactive.IsRendered = false;
        Audio.IsRendered = false;
    }
}
function UsePressReleases(val) {
    var chk = document.getElementById('_prl');
    chk.checked = val;
}
function UsePhotoArchive(val) {
    var chk = document.getElementById('_ppa');
    chk.checked = val;
}
function UseMyLocalCompany(val) {
    var chk = document.getElementById('_pmlc');
    chk.checked = val;
}
function GetWinthList(qry, add) {
    if (add != false)
        add = true;
    var params;
    if (IsVisible("text"))
        return GetMediaTypeWithinItems(Text, qry, add, "Text");
    if (IsVisible("photos"))
        return GetMediaTypeWithinItems(Photo, qry, add, "Photo");
    if (IsVisible("graphics"))
        return GetMediaTypeWithinItems(Graphic, qry, add, "Graphic");
    if (IsVisible("video"))
        return GetMediaTypeWithinItems(Video, qry, add, "Video");
    if (IsVisible("interactive"))
        return GetMediaTypeWithinItems(Interactive, qry, add, "Interactive");
    if (IsVisible("audio"))
        return GetMediaTypeWithinItems(Audio, qry, add, "Audio");
}
function GetMediaTypeWithinItems(media, qry, add, type) {
    var params = media.SearchParams;
    if (!qry || qry.length == 0)
        return params;
    if (params.WithinItems && ItemExists(params.WithinItems, qry) == false) {
        if (!add && params.WithinItems.length > 0)
            params.WithinItems.pop();
        params.WithinItems.push(qry);
    }
    if (params.WithinItems)
        Text.SearchParams.WithinItems = Photo.SearchParams.WithinItems = Graphic.SearchParams.WithinItems = Video.SearchParams.WithinItems = Interactive.SearchParams.WithinItems = Audio.SearchParams.WithinItems = params.WithinItems;
    if (type)
        params.MediaType = type;
    return params;
}
function IsValidKeyword(keyword) {
    var ItemArray = new Array("and", "or", "trim");
    var status = false;
    for (var i = 0; i < ItemArray.length; i++) {
        if (ItemArray[i].toString().toUpperCase() == keyword.toUpperCase())
            status = true;
    }
    return status;
}
function KeywordSearch() {
    var e = document.getElementById("_k");
    var chk = document.getElementById("_chk");
    var wList = document.getElementById("hWithinList");
    if (e == null || e.value.length == 0) {
        alert("Please enter a search keyword.");
        return false;
    }
    else if (IsValidKeyword(e.value)) {
        alert("Please enter a valid search keyword.");
        return false;
    }
    else {
        SetMediaSearchDefaultValues();
        var jspObj = new __JsonSearchParamsObject();

        if (chk != null && chk.checked) {
            jspObj = GetWinthList(e.value);
            UsePressReleases(jspObj.UsePressReleases);
            UseMyLocalCompany(jspObj.UseExtendedEntitlements);
            UsePhotoArchive(jspObj.UsePhotoArchive);
            chk.checked = false;
        }
        else {
            jspObj.SearchType = "Keyword";
            wList.value = "";
            jspObj.WithinItems = new Array(e.value);
            var prl = document.getElementById("_prl");
            if (prl != null && prl.checked)
                jspObj.UsePressReleases = true;
            var pmlc = document.getElementById("_pmlc");
            if (pmlc != null && pmlc.checked)
                jspObj.UseExtendedEntitlements = true;
            var ppa = document.getElementById("_ppa");
            if (ppa != null && ppa.checked)
                jspObj.UsePhotoArchive = true;
            UsePressReleases(jspObj.UsePressReleases);
            UseMyLocalCompany(jspObj.UseExtendedEntitlements);
            UsePhotoArchive(jspObj.UsePhotoArchive);
            SetJsonParams(jspObj);
        }
        jspObj.PageType = "First";
        if (jspObj != null) {
            jspObj.MediaType = "Auto";
            document.fire("TreeNodeClick:MediaSearch", { Params: jspObj });
            //make call to put the webparams in session and refresh the search history iframe
            // uncomment in future - krishna - 02/20/2007
            // updatekeywordsinSession(jspObj);            
            updateSearchHistory(jspObj);
            document.getElementById("_k").value = "";
        }
        return (false);
    }
}
function BrowseSearch(qry,FullPath) {
    SetMediaSearchDefaultValues();
    var jspObj = new __JsonSearchParamsObject();
    jspObj.SearchType = "Keyword";
    if (qry == "*") {
        jspObj.WithinItems = new Array(qry);
        FullPath="NAV/SHOW ALL";
    }
    else {
        var add = true;
        if (!$("browseCheck").checked) {
            var arr = GetWinthList().WithinItems;
            if (arr && arr.length > 0 && arr[arr.length - 1].indexOf("SUBJECTNAME=") != -1)
                add = false;
        }
        jspObj = GetWinthList('SUBJECTNAME="' + qry + '"', add);
    }
    _wt.dcsMultiTrack('DCS.dcsuri', '/pages/portal.aspx', 'WT.ti', FullPath, 'WT.dl', '0','DCSext.area','BrowseTopics');
    SetJsonParams(jspObj);
    jspObj.PageType = "First";
    if (jspObj) {
        //jspObj.MediaType = "Auto";
        document.fire("TreeNodeClick:MediaSearch", { Params: jspObj });
    }
    return (false);
}
//New functions for search history - uncomment in future - krishna - 02/20/2007
function ClearSelectedItems() {
    frames["dwnloadIFrame"].location.href = "searchHistory.aspx?action=clear";
}
function updateSearchHistory(b) {
    frames["dwnloadIFrame"].location.href = "searchHistory.aspx?action=update&jsp=" + escape(Object.toJSON(b));
}
function SetSearchHistory() {
    var hdiv = frames["dwnloadIFrame"].document.getElementById("kwh_sHistorydiv");
    if (hdiv) {
        var elm = document.getElementById("ctl00_ctl00_ctl00_ctl00_ctl00_ctl00_body_body_body_main_body_main_body_main_body_main_kwh_sHistorydiv");
        if (elm) {
            elm.innerHTML = hdiv.innerHTML;
        }
    }
}
function updatekeywordsinSession(b) {
    try {
        var options = {
            method: "POST",
            postBody: Object.toQueryString({ Action: "updateKeyWords", websearchParams: Object.toJSON(b) }),
            onSuccess: function(transport) { historyHandler_cb(transport.status) }
        };
        new Ajax.Request('UtilHandler.ashx', options)
    }
    catch (e) {
    }
}
function historyHandler_cb(type, data, evt) {
    if (type == "200") {
        sHistoryFrame = window.parent.frames[0];
        sHistoryFrame.location.href = "searchHistory.aspx";
    }
    else {
        alert("Error:");
    }
}
function PublishBreadCrumbEvent(params) {
    document.fire("TreeNodeClick:BreadCrumbEvent", { Params: params });
}
function processBreadCrumb(WebSearchParamsObj) {
    var _wsParams = null;
    var _Title = "";
    // TODO: when spellcheck is turned on uncomment these lines
    // var _SpellCheckValue=SpellSuggestionValue();
    // var _SpellSuggestedValue="<font color='red'><i>Did you mean: </i><a href=\"#\" onClick=\"return SpellCheckSearch('"+_SpellCheckValue+"')\">"+_SpellCheckValue+"?</a></font>";
    var _SpellCheckValue = "";
    var _SpellSuggestedValue = "";
    if (WebSearchParamsObj != null) {
        _wsParams = WebSearchParamsObj;
    }
    var _BreadCrumb = "";
    if (_wsParams.SearchName != "" && _wsParams.WithinItems != null && _wsParams.WithinItems.length == 0) {
        _BreadCrumb = _wsParams.SearchName;
        if (_wsParams.SearchType == "WatchList") {
            _BreadCrumb = "<img src=\"../images/grid/watchlist.png\" align=\"absmiddle\" title=\"Watchlist\" /> " + _BreadCrumb;
        }
    }
    else if (_wsParams.SearchName != "" && _wsParams.WithinItems != null && _wsParams.WithinItems.length > 0) {
        _BreadCrumb = "<a href=\"#\" onClick=\"return BreadCrumbSearch('-1')\">" + _wsParams.SearchName + "</a> <font color='gray' weight='normal'>and</font>  ";
        if (_wsParams.SearchType == "WatchList") {
            _BreadCrumb = "<img src=\"../images/grid/watchlist.png\" align=\"absmiddle\" title=\"Watchlist\" /> " + _BreadCrumb;
        }
    }
    if (_wsParams.WithinItems != null) {
        for (i = 0; i < _wsParams.WithinItems.length; i++) {
            var _Name = _wsParams.WithinItems[i];
            if (_Name != null && _Name != "") {
                var subject = 'SUBJECTNAME="';
                if (_Name.indexOf(subject) == 0) {
                    _Name = _Name.substr(subject.length);
                    _Name = "<img src=\"../images/grid/browse.png\" align=\"absmiddle\" title=\"Category\" /> " + _Name.substring(0, _Name.length - 1);
                }
                if (i == 0 && _wsParams.WithinItems.length == 1 && (_wsParams.SearchName == null || _wsParams.SearchName == "")) {
                    if (_SpellCheckValue != "")
                        _BreadCrumb = _SpellSuggestedValue;
                    else
                        _BreadCrumb = _wsParams.WithinItems[i];
                }
                else if (i == _wsParams.WithinItems.length - 1) {
                    if (_SpellCheckValue != "")
                        _BreadCrumb += _SpellSuggestedValue;
                    else
                        _BreadCrumb += _Name;
                }
                else {
                    _BreadCrumb += "<a href=\"#\" onClick=\"return BreadCrumbSearch('" + i.toString() + "')\">" + _Name + "</a> <font color='gray' weight='normal'>and</font> ";
                }
            }
        }
    }
    if (_wsParams.SearchName != "")
        _Title += " Criteria: " + _wsParams.SearchName;
    if (_wsParams.WithinItems.join('') != "")
        _Title += "\n KeyWords: " + _wsParams.WithinItems.join('+');
    _Title += "\n Posted in the Last " + _wsParams.SearchInterval;
    MediaButton.SetBreadCrumbs(_BreadCrumb);
    MediaButton.SetSearchCriteria(_Title);
}

document.observe("TreeNodeClick:BreadCrumbEvent", function(event) {if(event.memo!=null) processBreadCrumb(event.memo.Params); });
document.observe("TreeNodeClick:MediaSearch", function(event) { if(event.memo!=null)MediaSearch(event.memo.Params); });
/*WebSearchAsyncHandler IHttpAsyncHandler Calls*/
function tracking(Wspobj) {
    try {
        var options = {
            method: "POST",
            postBody: Object.toQueryString({ Action: "tracking", websearchParams: Object.toJSON(Wspobj) })
        };
        new Ajax.Request('UtilHandler.ashx', options);
    }
    catch (e) {
    }
}
function MediaSearch(WebSearchParamsObj) {
    var SearchParamsObj = new __JsonSearchParamsObject();
    if (WebSearchParamsObj != null) {
        //SearchParamsObj=WebSearchParamsObj.Params;
        SearchParamsObj = WebSearchParamsObj;
    }

   
    shwhd('warning');
    //make a call here for tracking - new lines- 02/23/2007
    tracking(SearchParamsObj);
    if (SearchParamsObj.MediaType == "Auto") {
        if (IsVisible('text')) {
            if (!Text.IsRendered) {
                Text.IsRendered = true;
                Text.ShowAnimation(true);
                SearchParamsObj.MediaType = "Text";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }
        else if (IsVisible('photos')) {
            if (!Photo.IsRendered) {
                Photo.IsRendered = true;
                Photo.ShowAnimation(true);
                SearchParamsObj.MediaType = "Photo";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }
        else if (IsVisible('graphics')) {
            if (!Graphic.IsRendered) {
                Graphic.IsRendered = true;
                Graphic.ShowAnimation(true);
                SearchParamsObj.MediaType = "Graphic";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }
        else if (IsVisible('video')) {
            if (!Video.IsRendered) {
                Video.IsRendered = true;
                Video.ShowAnimation(true);
                SearchParamsObj.MediaType = "Video";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }
        else if (IsVisible('interactive')) {
            if (!Interactive.IsRendered) {
                Interactive.IsRendered = true;
                Interactive.ShowAnimation(true);
                SearchParamsObj.MediaType = "Interactive";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }
        else if (IsVisible('audio')) {
            if (!Video.IsRendered) {
                Audio.IsRendered = true;
                Audio.ShowAnimation(true);
                SearchParamsObj.MediaType = "Audio";
                SearchParamsObj.GetCounts = true;
                AsyncSearch(SearchParamsObj);
            }
        }

    }
    else if (SearchParamsObj.MediaType == "Text") {
        if (!Text.IsRendered) {
            Text.IsRendered = true;
            Text.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    else if (SearchParamsObj.MediaType == "Photo") {
        if (!Photo.IsRendered) {
            Photo.IsRendered = true;
            Photo.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    else if (SearchParamsObj.MediaType == "Graphic") {
        if (!Graphic.IsRendered) {
            Graphic.IsRendered = true;
            Graphic.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    else if (SearchParamsObj.MediaType == "Video") {
        if (!Video.IsRendered) {
            Video.IsRendered = true;
            Video.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    else if (SearchParamsObj.MediaType == "Interactive") {
        if (!Interactive.IsRendered) {
            Interactive.IsRendered = true;
            Interactive.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    else if (SearchParamsObj.MediaType == "Audio") {
        if (!Audio.IsRendered) {
            Audio.IsRendered = true;
            Audio.ShowAnimation(true);
            SearchParamsObj.GetCounts = true;
            AsyncSearch(SearchParamsObj);
        }
    }
    if (BrowseTree) 
    {
        BrowseTree.setMedia(SearchParamsObj);
    }
}
function AsyncSearch(SearchParamsObj) {
    var tmp = SearchParamsObj.MediaType.split(",");
    for (var i = 0; i < tmp.length; i++) {
        SearchParamsObj.MediaType = tmp[i];
        var options = {
            method: "POST",
            postBody: Object.toQueryString({ SearchParams: Object.toJSON(SearchParamsObj) }),
            onFailure: function(transport) { error_cb(transport.status, transport.statusText) },
            onSuccess: function(transport) { WebSearchHandler_cb(transport.status, transport.responseText, transport); }
        };
        new Ajax.Request("WebSearchAsyncHandler.ashx", options);
    }
}
function error_cb(type, error) {
    var msg = "Unable to process search - " + error;
    msg = msg.replace("'", "\"");
    shwmsg('warning', msg);
}
function SetBreadCrumb(data) {
    var jsonResults = eval(data);
    var jspObj = null;
    for (var i = 0; i <= jsonResults.Results.length - 1; i++) {
        jspObj = jsonResults.Results[i].SearchParams;
        break;
    }
    if (jspObj != null) {
        document.fire("TreeNodeClick:BreadCrumbEvent", { Params: jspObj });
    }
}
function WebSearchHandler_cb(type, data, evt) {
    if (type == '200') {
        __WebSearchDisplayOnSuccess(data, "");
        SetBreadCrumb(data);
    }
    else {
        alert("Error: WebSearchHandler_cb");
    }
}
function PublishMediaSearch(params) {
    document.fire("TreeNodeClick:MediaSearch", { Params: params });
}
var SubScribeMediaSearch = new function() {
    this.init = function() {
        document.observe('TreeNodeClick:MediaSearch', function(event) { MediaSearch });
    }
}
SubScribeMediaSearch.init();
/*WebSearchAsyncHandler IHttpAsyncHandler Calls*/
function ShowHideMediaControls(ctrl) {
    var identifier = ctrl.getAttribute('id').slice(0, ctrl.getAttribute('id').indexOf('-'));
    Photo.SearchParams.MediaType = "Photo";
    Text.SearchParams.MediaType = "Text";
    Video.SearchParams.MediaType = "Video";
    Graphic.SearchParams.MediaType = "Graphic";
    Interactive.SearchParams.MediaType = "Interactive";
    Audio.SearchParams.MediaType = "Audio";
    Text.ShowAnimation(false);
    Photo.ShowAnimation(false);
    Graphic.ShowAnimation(false);
    Video.ShowAnimation(false);
    Interactive.ShowAnimation(false);
    Audio.ShowAnimation(false);
    if (identifier == 'text') {
        Text.SetVisibility(true);
        Photo.SetVisibility(false);
        Graphic.SetVisibility(false);
        Video.SetVisibility(false);
        Interactive.SetVisibility(false);
        Audio.SetVisibility(false);
        Text.SearchParams.MediaType = "Text";
        PublishMediaSearch(Text.SearchParams);
    }
    else if (identifier == 'photos') {
        Text.SetVisibility(false);
        Photo.SetVisibility(true);
        Graphic.SetVisibility(false);
        Video.SetVisibility(false);
        Interactive.SetVisibility(false);
        Audio.SetVisibility(false);
        Photo.SearchParams.MediaType = "Photo";
        PublishMediaSearch(Photo.SearchParams);
    }
    else if (identifier == 'graphics') {
        Text.SetVisibility(false);
        Photo.SetVisibility(false);
        Graphic.SetVisibility(true);
        Video.SetVisibility(false);
        Interactive.SetVisibility(false);
        Audio.SetVisibility(false);
        Graphic.SearchParams.MediaType = "Graphic";
        PublishMediaSearch(Graphic.SearchParams);
    }
    else if (identifier == 'video') {
        Text.SetVisibility(false);
        Photo.SetVisibility(false);
        Graphic.SetVisibility(false);
        Video.SetVisibility(true);
        Interactive.SetVisibility(false);
        Audio.SetVisibility(false);
        Video.SearchParams.MediaType = "Video";
        PublishMediaSearch(Video.SearchParams);
    }
    else if (identifier == 'interactive') {
        Text.SetVisibility(false);
        Photo.SetVisibility(false);
        Graphic.SetVisibility(false);
        Video.SetVisibility(false);
        Interactive.SetVisibility(true);
        Audio.SetVisibility(false);
        Interactive.SearchParams.MediaType = "Interactive";
        PublishMediaSearch(Interactive.SearchParams);
    }
    else if (identifier == 'audio') {
        Text.SetVisibility(false);
        Photo.SetVisibility(false);
        Graphic.SetVisibility(false);
        Video.SetVisibility(false);
        Interactive.SetVisibility(false);
        Audio.SetVisibility(true);
        Audio.SearchParams.MediaType = "Audio";
        PublishMediaSearch(Audio.SearchParams);
    }
    MediaButton.SetParams(identifier + "=true");
    if (identifier == 'summary' || identifier == 'headline') {
        Text.summary = identifier;
        Text.setSummaryHeadlineToggle(identifier);
    }
    else {
        ToggleMediaButtons(ctrl);
    }
}
function IsVisible(media) {
    if (media != null) {
        var ctrl = document.which(media + "-button");
        if(ctrl!=null)
        {
            if (ctrl.style.fontWeight == "bold")
                return true;
        }
        return false;
    }
    return false;
}
function ToggleMediaButtons(ctrl) {
    var identifier = ctrl.getAttribute('id').slice(0, ctrl.getAttribute('id').indexOf('-button'));
    var media = document.which('media-controls');
    if (media) {
        var mediaButtons = media.getElementsByTagName('a');
        var mediaPanels = new Array();
        //make an array of all the elements referred to by the media control links
        for (var i = 0; i < mediaButtons.length; i++) {
            if (mediaButtons[i].getAttribute('id') != null)
                mediaPanels.push(mediaButtons[i].getAttribute('id').slice(0, mediaButtons[i].getAttribute('id').indexOf('-button')));
        }
        //loop through the buttons themselves and change the className
        for (var j = 0; j < mediaButtons.length; j++) {
            mediaButtons[j].style.fontWeight = "normal";
            mediaButtons[j].style.color = "#CC6600";
            mediaButtons[j].style.cursor = "pointer";
        }
        ctrl.style.fontWeight = "bold";
        ctrl.style.color = "#333";
        ctrl.style.cursor = "default";
    }
}
function ToggleMediaButtons2(identifier) {
    var ctrl = document.which(identifier + '-button');
    ToggleMediaButtons(ctrl);
}
function SetMediaCounts(mc) {
    var p = "text=" + Text.Hits + ";photos=" + Photo.Hits + ";graphics=" + Graphic.Hits + ";interactive=" + Interactive.Hits + ";video=" + Video.Hits + ";audio=" + Audio.Hits;
    var tempCDataButton = "";
    var tempCDataCount = "";
    if (mc.length > 0)
        p = mc;
    var p_arr = p.split(';');
    //var all_ctrl = document.which('all-button');
    for (var i = 0; i < p_arr.length; i++) {
        var p_media = p_arr[i].split('=');
        if (p_media[0] == "complexdata") {
            tempCDataButton = "complexdata";
            tempCDataCount = parseInt(p_media[1]);
        }
    }
    for (var i = 0; i < p_arr.length; i++) {
        var p_media = p_arr[i].split('=');
        var ctrl = document.which(p_media[0] + '-button');
        if (ctrl) {
            var t = ctrl.title;
            var idx = ctrl.title.indexOf('(');
            if (idx != -1) {
                t = ctrl.title.substring(0, idx - 1);
            }
            var rows = 0;
            if (p_media[0] == "text")
                rows = MediaButton.TextRows;
            else if (p_media[0] == "photos")
                rows = MediaButton.PhotoRows;
            else if (p_media[0] == "graphics")
                rows = MediaButton.GraphicRows;
            else if (p_media[0] == "video")
                rows = MediaButton.VideoRows;
            else if (p_media[0] == "audio")
                rows = MediaButton.AudioRows;
            else if (p_media[0] == "Interactive") {
                rows = MediaButton.InteractiveRows;
                //Hack to fix interative count
                p_media[1] = tempCDataCount;
            }
            if (parseInt(p_media[1]) > parseInt(rows))
                ctrl.title = t + " (" + rows + ")";
            else
                ctrl.title = t + " (" + p_media[1] + ")";
            if (parseInt(p_media[1]) > 0) {
                ctrl.className = 'fakeClass';
                //all_ctrl.className = 'fakeClass';                
            } else {
                ctrl.className = '';
            }
        }
    }
}
function SetColumnControls(ctrl) {
    var alerts = $('alerts');
    if (alerts) {
        var alertsalt = $('alertsalt');
        if (alertsalt) {
            alertsalt.innerHTML = alerts.innerHTML;
            alrt_show_all_salt(); //call to show all the alerts
        }
    }
    if (ctrl != null) {
        layout(ctrl);
    }
}
function SetTextControls(ctrl) {
    textControl(ctrl);
}
function setViewSource(media) {
    var SearchParamsObj = new __JsonSearchParamsObject();
    if (media == "Text") {
        SearchParamsObj = Text.SearchParams;
    }
    else if (media == "Photo") {
        SearchParamsObj = Photo.SearchParams;
    }
    else if (media == "Graphic") {
        SearchParamsObj = Graphic.SearchParams;
    }
    else if (media == "Video") {
        SearchParamsObj = Video.SearchParams;
    }
    else if (media == "Interactive") {
        SearchParamsObj = Interactive.SearchParams;
    }
    else if (media == "Audio") {
        SearchParamsObj = Audio.SearchParams;
    }
    else if (media = "NewsAlerts") {
        SearchParamsObj = divNewsAlerts.SearchParams;
    }
    var a = Object.toJSON(SearchParamsObj);
    var URL = "ViewSource.aspx?SearchParams=" + a;
    var h = 700;
    var w = 600;
    var lp = (screen.width) ? (screen.width - w) / 2 : 0;
    var tp = (screen.height) ? (screen.height - h) / 2 : 0;
    newwindow = window.open(URL, null, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + w + ',height=' + h + ',left=' + lp + ',top=' + tp);
    if (window.focus) { newwindow.focus() }
    return false;
}
function RefreshResults() {
    if (IsVisible('text')) {
        Text.IsRendered = false;
        Text.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Text.SearchParams });
    }
    else if (IsVisible('photos')) {
        Photo.IsRendered = false;
        Photo.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Photo.SearchParams });
    }
    else if (IsVisible('graphics')) {
        Graphic.IsRendered = false;
        Graphic.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Graphic.SearchParams });
    }
    else if (IsVisible('video')) {
        Video.IsRendered = false;
        Video.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Video.SearchParams });
    }
    else if (IsVisible('interactive')) {
        Interactive.IsRendered = false;
        Interactive.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Interactive.SearchParams });
    }
    else if (IsVisible('audio')) {
        Audio.IsRendered = false;
        Audio.SearchParams.PageType = "First";
        document.fire("TreeNodeClick:MediaSearch", { Params: Audio.SearchParams });
    }
}
function setSearchParams(params) {
    var search = new __JsonSearchParamsObject();
    if (!params)
        return search;
    if (!params.WithinItems || params.WithinItems.length == 0) {
        if (Text && Text.SearchParams && Text.SearchParams.WithinItems.length > 0)
            params.WithinItems = Text.SearchParams.WithinItems;
        else if (Photo && Photo.SearchParams && Photo.SearchParams.WithinItems.length > 0)
            params.WithinItems = Photo.SearchParams.WithinItems;
        else if (Graphic && Graphic.SearchParams && Graphic.SearchParams.WithinItems.length > 0)
            params.WithinItems = Graphic.SearchParams.WithinItems;
        else if (Video && Video.SearchParams && Video.SearchParams.WithinItems.length > 0)
            params.WithinItems = Video.SearchParams.WithinItems;
        else if (Interactive && Interactive.SearchParams && Interactive.SearchParams.WithinItems.length > 0)
            params.WithinItems = Interactive.SearchParams.WithinItems;
        else if (Audio && Audio.SearchParams && Audio.SearchParams.WithinItems.length > 0)
            params.WithinItems = Audio.SearchParams.WithinItems;
    }
    search.SearchParams = params;
    return search;
}
function ViewSelected() {
    var params = "({\"SearchType\":\"Selected\", \"MediaType\":\"Auto\"\, \"SearchName\":\"Selected Items\"\});";
    SetSearchParams(params);
    SetMediaSearchDefaultValues();
    var media = document.which('media-controls');
    if (media) {
        var mediaButtons = media.getElementsByTagName('a');
        for (var j = 0; j < mediaButtons.length; j++) {
            if (mediaButtons[j].style.fontWeight == "bold")
                ShowHideMediaControls(mediaButtons[j]);
        }
    }
    else //Safe side else block
        ShowHideMediaControls($("text-button")); //all-button 
}
function ClearSelected() {
    var action = "clear";
    var record_id = "0";
    //clear selectedvariable
    if (SelectedCount) {
        SelectedCount = "0";
    }
    try {
        var options = {
            method: "POST",
            postBody: Object.toQueryString({ a: action, guids: record_id, Selectedashx: 1 }),
            onSuccess: function(transport) { SelectedCountCallback(transport.status, transport.responseText) }
        };
        new Ajax.Request('Selected.ashx', options)
    }
    catch (e) { }
    var check_boxes = $$('.show-content input[type=checkbox]');
    var box;
    for (var i = 0; i < check_boxes.length; i++) {
        var box = check_boxes[i];
        if (box.checked == true) {
            box.checked = false;
            var box_id = box.id.split("_");
            var record_id = box_id[1];
            var item_box = $("item_box_" + record_id);
            Element.removeClassName(item_box, "selected");
        }
    }
}

