﻿var sActivePanel = '#pnlTransactions';
var ActiveSegment = null;

function FetchAnalysis(iListID, iNumMonths, lStart, lEnd) {
    if ($j('#hdnAccount').attr('value') == 0) { return; }
    var HasCharts = $j("input#hdnHasCharts").attr('value');
    if (HasCharts != 0) {
        var aURL = "/Charts/IIWAnalysis.aspx?ListID=" + (iListID > 0 ? iListID : 1) + "&StartDate=" + lStart
                    + "&EndDate=" + lEnd + "&NumMonths=" + iNumMonths;
        $j.ajax({
            url: aURL,
            cache: false,
            dataType: 'html',
            success: function(html) {
                SplitCharts(html);
            }

        });
    }
}

function FetchGeo(iListID, iNumMonths, lStart, lEnd) {
    if ($j('#hdnAccount').attr('value') == 0) {return;}
    var HasGeoMaps = $j("input#hdnHasGeoMaps").attr('value');
    if (HasGeoMaps != 0) {
        // Get Geo
        aURL = "/Charts/GeoDistribution.aspx?ListID=" + (iListID > 0 ? iListID : 1) + "&StartDate=" + lStart
                            + "&EndDate=" + lEnd + "&NumMonths=" + iNumMonths;
        $j.get(aURL, function(data) {
            $j("div#vtrans-geo").html(data);
        }, 'html');
        window.setTimeout(DoGeoAccordion, 3000);
    }
}

function DoGeoAccordion() {
    $j('#accGeo').accordion({ minheight: 380, alwaysOpen: false });  //{  }
    window.setTimeout(OpenUSGeoAccordion, 1000);
}

function OpenUSGeoAccordion() {
    $j('#geoUS').trigger('click');
    window.setTimeout("$j('#geoUS').trigger('click')" , 1000);
}


function SplitCharts(data) {
    var iStart = data.indexOf("<!-- Overview -->")
    var iEnd = data.indexOf("<!-- Highlights -->")
    $j("div#vtrans-overview").html(data.toString().substring(iStart, iEnd - 1));
    iStart = iEnd;
    iEnd = data.indexOf("<!-- Trends -->")
    $j("div#vtrans-highlights").html(data.toString().substring(iStart, iEnd - 1));
    iStart = iEnd;
    iEnd = data.indexOf("<!-- End -->")
    $j("div#vtrans-trends").html(data.toString().substring(iStart, iEnd - 1));
}

function LoadList(ListBar) {
    // Get Current List Attributes
    var ListID = $j(ListBar).attr('ListID');
    var HasCharts = $j(ListBar).attr('HasCharts');
    var HasGeoMaps = $j(ListBar).attr('HasGeoMaps');
    var HasCompanies = $j(ListBar).attr('HasCompanies');
    var Clipped = $j(ListBar).attr('Clipped');
    var ListStart = $j(ListBar).attr('ListStart');
    var ListEnd = $j(ListBar).attr('ListEnd');
    var TimeFrame = $j(ListBar).attr('TimeFrame');
    var AcqCount = $j(ListBar).attr('AcqCount');
    var CompCount = $j(ListBar).attr('CompCount');
    $j('#hdnListID').attr('value', ListID);
    $j('#hdnHasCharts').attr('value', HasCharts);
    $j('#hdnHasGeoMaps').attr('value', HasGeoMaps);
    $j('#hdnHasCompanies').attr('value', HasCompanies);
    $j('#hdnClipped').attr('value', Clipped);
    $j('#hdnListStart').attr('value', ListStart);
    $j('#hdnListEnd').attr('value', ListEnd);
    $j('#hdnTimeFrame').attr('value', TimeFrame);
    $j('#hdnAcqCount').attr('value', AcqCount);
    $j('#hdnCompCount').attr('value', CompCount);
    $j('#hdnAcqCount6M').attr('value', $j(ListBar).attr('AcqCountSixMonths'));
    $j('#hdnAcqCount2004').attr('value', $j(ListBar).attr('AcqCount2004'));

    // Show Company Tab if necessary
    if (HasCompanies != 0) {
        $j('#tabnav-7').show();
    }
    else {
        $j('#tabnav-7').hide();
    }
    
    // Show List Transactions
    // 0 indicates to wait on chart load, we do it later
    showAllTransactions(0); 
    
    // Load Charts
    var iNumMonths = $j("input#hdnNumMonths").attr('value');
    if (HasGeoMaps != 0) {

        $j('#tabnav-6').show();
        FetchGeo(ListID, iNumMonths, ListStart, ListEnd);
        //DoGeoAccordion();
    }
    else {
        $j('#tabnav-6').hide();
    }
    if (HasCharts != 0) {
        $j('#tabnav-3').show();
        $j('#tabnav-4').show();
        $j('#tabnav-5').show();
        var lStartChart = $j("input#hdnChartStart").attr('value');
        var lEndChart = $j("input#hdnChartEnd").attr('value');
        FetchAnalysis(ListID, iNumMonths, lStartChart, lEndChart);
    }
    else {
        $j('#tabnav-3').hide();
        $j('#tabnav-4').hide();
        $j('#tabnav-5').hide();
    }
}

function showAllTransactions(ReloadCharts) {

        var segmentdaterange = $j('#hdnTimeFrame').attr('value');
        var ListID = $j("input#hdnListID").attr('value');

        $j('#segmentDateRange').html(segmentdaterange);
        $j('#viewalltransactions').hide();
        $j('.transaction').hide();
        $j('.tombstone').hide();
        $j('.list' + ListID).show();
        $j('#hdnSelectedSegment').attr('value', -1);
        $j('.bargraphitem').removeClass('activesegment');
        if (ReloadCharts == 1) {
            var iNumMonths = $j("input#hdnNumMonths").attr('value');
            var ListStart = $j('#hdnListStart').attr('value', ListStart)
            var lStart = $j("input#hdnChartStart").attr('value');
            var lEnd = $j("input#hdnChartEnd").attr('value');
            FetchAnalysis(ListID, iNumMonths, lStart, lEnd);
            FetchGeo(ListID, iNumMonths, ListStart, lEnd);
        }

        ActiveSegment = null;
        DisplayHeaderTitle();
    }

    function DisplayHeaderTitle() {

    if (ActiveSegment == null) {
        $j('#segmentPageTitle').html('All Segments');
        if (sActivePanel == '#pnlOverview') {
            $j('#segmentDateRange').html('Since 2004');
            $j('#curSearchResultsCount').html('(' + $j('#hdnAcqCount2004').attr('value') + ' results)');
        }
        else if (sActivePanel == '#pnlTrends' || sActivePanel == '#pnlHighlights') {
            $j('#curSearchResultsCount').html('(' + $j('#hdnAcqCount6M').attr('value') + ' results)');
        }
        else if (sActivePanel == '#pnlCompanyInformation') {
            $j('#curSearchResultsCount').html('(' + $j('#hdnCompCount').attr('value') + ' results)');
        }
        else {//|| sActivePanel == '#pnlGeography'
            var segmentdealcount = $j('#hdnAcqCount').attr('value');
            $j('#curSearchResultsCount').html('(' + segmentdealcount + ' results)');
        }
    }
    else {
        $j('#segmentPageTitle').html($j(ActiveSegment).attr('segmentname'));
        if (sActivePanel == '#pnlGeography' || sActivePanel == '#pnlOverview') {
            $j('#segmentDateRange').html('Since 2004');
            $j('#curSearchResultsCount').html('(' + $j(ActiveSegment).attr('ACount2004') + ' results)');
        }
        else if (sActivePanel == '#pnlTrends' || sActivePanel == '#pnlHighlights') {
        $j('#curSearchResultsCount').html('(' + $j(ActiveSegment).attr('ACount6M') + ' results)');
        }
        else if (sActivePanel == '#pnlCompanyInformation') {
        $j('#curSearchResultsCount').html('(' + $j(ActiveSegment).attr('CompCount') + ' results)');
        }
        else {
            var segmentdealcount = $j('.bargraphdata', ActiveSegment).html();
            $j('#curSearchResultsCount').html('(' + segmentdealcount + ' results)');
        }

    }
}

$j(document).ready(function() {

    // Initialize Accordion
    $j('div.msAccSegments').accordion({ header: 'h2', autoheight: false });

    $j('h2.msListLink').click(function() {
        // Are we logged in?
        //        if ($j('#hdnAccount').attr('value') == 0) {
        //            // Force to login
        //            $j('#lblErrorMessage').text('To Access Weekly Breakout, you must Log in.');
        //            $j("#login_error").show();

        //            $j('#hypOrLogin').click();
        //        }
        //        else {
        LoadList(this);
        //}
    });

    if ($j('#hypOrLogin').length == 0) {
        //$j('.msLinkListTop').trigger('click');
        // Click on Segment if Exists
        window.setTimeout(AutoClick, 3000);
    }

    function AutoClick() {
        $j('#AutoClickSegment').trigger('click');
    }

    // Load Chart and Analysis on First Load
    if ($j('#hypOrLogin').length == 0) {
        $j('.msLinkListTop').click(); // This fires a login event
    }
    else {
        LoadList($j('.msLinkListTop'));
    }

    // Load tombstones - this delays the load
    $j('p.tombstone img').attr('src', function() {
        return '/Acquisition/Tombstone.ashx?AcquisitionID=' + $j(this).attr('transactionid');
    });

    $j('span.ntab span.m').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('#viewalltransactions').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('#pdfit').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('div.bargraphitem').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('h2.msListLink').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('div.SimilarDeals a').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('li.pressreleasemenuitem').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('li.watchmenuitem').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('li.bookmarkmenuitem').tooltip({ showURL: false, extraClass: "GoodLink" })

    $j('div.transaction a.GoodLink').tooltip({ showURL: false, extraClass: "GoodLink" })
    $j('div.transaction a.DeadLink').tooltip({ showURL: false, extraClass: "DeadLink" })
    $j('div.transaction a.DeadLink').click(function(e) {
        // Prevent clicks to work on deadlinks
        e.preventDefault();
    });


    // Rollover for Breadth Chart
    $j("div.BreadthTable div.Narrower").mouseover(function() {
        $j(this).removeClass().addClass("RNarrower");
    }).mouseout(function() {
        $j(this).removeClass().addClass("Narrower");
    });
    $j("div.BreadthTable div.Broader").mouseover(function() {
        $j(this).removeClass().addClass("RBroader");
    }).mouseout(function() {
        $j(this).removeClass().addClass("Broader");
    });

    $j("div.BreadthTable div.Broader").click(function() {
        DNASpinnerStart();
        var iListID = $j(this).attr('listid');
        var iBreadth = $j(this).attr('breadth');
        window.location = '/segmentview.aspx?ViewModes=2&ListID=' + iListID + '&Breadth=' + iBreadth;
    });
    $j("div.BreadthTable div.Narrower").click(function() {
        DNASpinnerStart();
        var iListID = $j(this).attr('listid');
        var iBreadth = $j(this).attr('breadth');
        window.location = '/segmentview.aspx?ViewModes=2&ListID=' + iListID + '&Breadth=' + iBreadth;
    });

    $j('#pdfit').click(function() {
        // Are we logged in?
        if ($j('#hdnAccount').attr('value') == 0) {
            // Force to login
            $j('#lblErrorMessage').text('To Access PDF, you must Log in.');
            $j("#login_error").show();
            $j('#hypOrLogin').click();
            return;
        } // Are we basic access
        else if ($j('#hdnAccount').attr('value') == 3) {
            // Show Upgrade message
            $j('#hypUpgrade').click();
            return;
        }

        DNASpinnerStart();

        var iListID = $j('#hdnListID').attr('value');
        var lStart = $j('#hdnListStart').attr('value');
        var lEnd = $j('#hdnListEnd').attr('value');
        var lClip = $j('#hdnClipped').attr('value');
        var lSelectedSegment = $j('#hdnSelectedSegment').attr('value');
        window.open('/Utility/PrintTransactions.aspx?ListID=' + (iListID > 0 ? iListID : 1) + '&StartDate=' + lStart + '&EndDate=' + lEnd + '&ClipResults=' + lClip + '&SegemntID=' + lSelectedSegment);

    });

    $j('div.SaveSearch').click(function() {
        var iListID = $j(this).attr('ListID'); //$j('#hdnListID').attr('value');
        window.location = '/Segments/SegmentEdit.aspx?ListID=' + iListID;
    });


    $j('.bargraphitem').click(function() {

        // Are we logged in?
        //        if ($j('#hdnAccount').attr('value') == 0) {
        //            // Force to login
        //            $j('#lblErrorMessage').text('To Access Segment Breakout, you must Log in.');
        //            $j("#login_error").show();
        //            $j('#hypOrLogin').click();
        //            return;
        //        }

        //startNavAnimation();
        $j('#viewalltransactions').show();
        var ListID = $j('#hdnListID').attr('value');
        var segmentid = $j(this).attr('segmentid');
        $j('#hdnSelectedSegment').attr('value', segmentid);
        $j('.bargraphitem').removeClass('activesegment');
        $j(this).addClass('activesegment');
        $j('.transaction').hide();
        $j('.tombstone').hide();
        // Show the intersection of segment and list classes
        $j('.segment' + segmentid + '.list' + ListID).show();
        var iNumMonths = $j("input#hdnNumMonths").attr('value');
        var iDBStart = $j("input#hdnDBStart").attr('value');
        var lStart = $j("input#hdnChartStart").attr('value');
        var lEnd = $j("input#hdnChartEnd").attr('value');
        FetchAnalysis(segmentid, iNumMonths, lStart, lEnd);
        FetchGeo(segmentid, iNumMonths, iDBStart, lEnd);
        ActiveSegment = this;
        DisplayHeaderTitle();
        //window.setTimeout(endNavAnimation, 9000);
    });

    $j('#viewalltransactions').click(function() {
        showAllTransactions(1);
    });

    function deactivateTabs() {

        $j('#tedpop').hide();
        for (var i = 1; i < 8; i++) {
            $j("#tabnav-" + i).removeClass("activetab");
        }

    }

    $j.showTrends = function showTrends() {
        ActivateTab("#pnlTrends", "#tabnav-3");
        $j('#segmentDateRange').html('Last 6 Months');
    }

    $j.showHighlights = function showHighlights() {
        ActivateTab("#pnlHighlights", "#tabnav-4");
        $j('#segmentDateRange').html('Last 6 Months');
    }

    $j.showOverview = function showOverview() {
        ActivateTab("#pnlOverview", "#tabnav-5");
        $j('#segmentDateRange').html('Since 2004');
    }

    $j.showGeography = function showGeography() {
        ActivateTab("#pnlGeography", "#tabnav-6");
        $j('#segmentDateRange').html('');
        $j('#hdnSelectedSegment').attr('value', -1)
        if ($j('#hdnSelectedSegment').attr('value') == -1) {
            $j('#segmentDateRange').html($j('#hdnTimeFrame').attr('value'));
        }
        else {
            $j('#segmentDateRange').html('Since 2004');
        }
    }

    $j.showCompany = function showCompany() {
        ActivateTab("#pnlCompanyInformation", "#tabnav-7");
        $j('#segmentDateRange').html('');
    }

    $j.showTombstones = function showTombstones() {
        ActivateTab("#pnlTombstones", "#tabnav-2");
        $j('#segmentDateRange').html($j('#hdnTimeFrame').attr('value'));
    }

    $j.showTransactions = function showTransactions() {
        ActivateTab("#pnlTransactions", "#tabnav-1");
        $j('#segmentDateRange').html($j('#hdnTimeFrame').attr('value'));
    }

    function ActivateTab(panelName, tabName) {
        // Don't do anything if panel already active
        if (panelName == sActivePanel) return;
        // Are we logged in?
        if ($j('#hdnAccount').attr('value') == 0) {
            // Force to login
            var Reason = 'this advanced feature';
            if ($j(tabName).attr('Reason').length > 0) {
                Reason = $j(tabName).attr('Reason');
            }
            $j('#lblErrorMessage').text('To Access ' + Reason + ' you must Log in.');
            $j("#login_error").show();

            $j('#hypOrLogin').click();
            return;
        }

        if (panelName == '#pnlTransactions') {
            $j('#pdfit').show();
        }
        else {
            $j('#pdfit').hide();
        }
        $j(panelName).show();

        if ($j(panelName).position().left > $j(sActivePanel).position().left)
            $j("#mainpanel").animate({ marginLeft: '-615px' }, 1250, "easeInOutQuart", function() { $j(sActivePanel).hide(); $j("#mainpanel").css("marginLeft", "0px"); sActivePanel = panelName; DisplayHeaderTitle(); });
        else {
            $j("#mainpanel").css("marginLeft", "-615px");
            $j("#mainpanel").animate({ marginLeft: '0px' }, 1250, "easeInOutQuart", function() { $j(sActivePanel).hide(); $j("#mainpanel").css("marginLeft", "0px"); sActivePanel = panelName; DisplayHeaderTitle(); });
        }
        deactivateTabs();
        $j(tabName).addClass("activetab");


    }


    //    $j("#ptlnTombstones").click(function() { $j.showTombstones(); });
    //    $j("#ptlnAnalysis").click(function() { $j.showAnalysis(); });
    //    $j("#ptlnTransactions").click(function() { $j.showTransactions(); });
    $j('#graphscrollablewindow').parent().css("paddingTop", "0px");
    $j('#graphscrollablewindow').parent().css("paddingBottom", "0px");

    $j('#tabnav-1').click(function() { $j.showTransactions(); });
    $j('#tabnav-2').click(function() { $j.showTombstones(); });
    $j('#tabnav-3').click(function() { $j.showTrends(); });
    $j('#tabnav-4').click(function() { $j.showHighlights(); });
    $j('#tabnav-5').click(function() { $j.showOverview(); });
    $j('#tabnav-6').click(function() { $j.showGeography(); });
    $j('#tabnav-7').click(function() { $j.showCompany(); });


    $j('#tombstoneoverlay').click(function() { deactivateTombstone(); });
    $j('#tedpop').mouseleave(function() { deactivateTombstone(); });
    $j('#tombstonewrapper img').mouseenter(function() { highlightTombstone(this); });

    var sSelectedTrans = '';

    $j('#tedReadMore').click(function() {
        GotoTransaction($j('#tedReadMore').attr("transactionid"));
    });
    $j('#tedImage').click(function() {
        GotoTransaction($j('#tedReadMore').attr("transactionid"));
    });


    function GotoTransaction(transactionid) {
        deactivateTombstone();
        $j.showTransactions();
        if (sSelectedTrans != '')
            $j(sSelectedTrans).removeClass('SelectedTrans');
        sSelectedTrans = ".transaction[transactionid='" + transactionid + "']";
        $j(sSelectedTrans).addClass('SelectedTrans');
        $j.scrollTo(sSelectedTrans, 1500);
    }

    function highlightTombstone(tombstone) {

        window.clearTimeout(tmrHTombstone);
        hTombstone = tombstone;
        tmrHTombstone = window.setTimeout(highlightSetTombstone, 50);

    }

    var tmrHTombstone;
    var hTombstone;
    var tombstomePopping = false; // prevents double execution

    function highlightSetTombstone() {

        if (tombstomePopping) return;
        tombstomePopping = true;
        var leftPos = $j(hTombstone).position().left;

        if ($j(hTombstone).position().left < 300) {
            leftPos += 295;
            $j('#tedImage').css({ 'float': 'left', 'marginRight': '10px', 'marginLeft': '0px' });
        }
        else {
            leftPos += -35;
            $j('#tedImage').css({ 'float': 'right', 'marginLeft': '10px', 'marginRight': '0px' });
        }

        $j('#tedpop').css("top", $j(hTombstone).position().top + 140);
        $j('#tedpop').css("left", leftPos);

        $j('#tedImage').empty().append($j(hTombstone).clone());

        $j('#tedTransTitle').empty().append($j(".transaction[transactionid='" + $j(hTombstone).attr("transactionid") + "']:first > .transactiontitle").clone());
        $j('#tedSynopsis').empty().append($j(".transaction[transactionid='" + $j(hTombstone).attr("transactionid") + "']:first > .synopsis").clone());

        $j('#tedReadMore').attr("transactionid", $j(hTombstone).attr("transactionid"));

        //$j('#tombstoneoverlay').show(); 
        $j('#tedpop').show();
        tombstomePopping = false;
    }

    function deactivateTombstone() {

        $j('#tedpop').hide(); //$j('#tombstoneoverlay').hide(); 

    }

    var tmrMenuFadeOut;

    function fadeoutsubmenus() {
        $j(".transsubmenu").fadeOut();
    }

    $j(".transmenu").mouseleave(function() { tmrMenuFadeOut = window.setTimeout(fadeoutsubmenus, 750); });

    $j(".transsubmenu").mouseleave(function() { $j(this).hide(); });

    $j(".transsubmenu").mouseenter(function() { window.clearTimeout(tmrMenuFadeOut); })

    $j(".pressreleasemenuitem").mouseenter(function() { $j(".transsubmenu").hide(); });
    $j(".watchmenuitem").mouseenter(function() { openSubMenu(this, "#mnuWatch", 1); });
    $j(".bookmarkmenuitem").mouseenter(function() { $j(".transsubmenu").hide(); });


    function openSubMenu(menuitem, menu, IsTrans) {

        var transMenus = (IsTrans == 1 ? '#Transactions' : '#Companies');

        if (IsTrans == 1)
            $j('#hdnActiveTransaction').attr("value", $j(menuitem).parent().attr("transactionid"));
        else
            $j('#hdnActiveCompany').attr("value", $j(menuitem).parent().attr("companyid"));

        window.clearTimeout(tmrMenuFadeOut);

        var toppos = $j(menuitem).offset().top - $j(transMenus).offset().top + (IsTrans == 1 ? 20 : 20);

        var leftpos = $j(menuitem).offset().left - $j(transMenus).offset().left; // - $j(menu).outerWidth() - 5;

        $j(menu).css({ 'top': toppos, 'left': leftpos });
        $j(".transsubmenu").hide();
        $j(menu).show();

    }

    function openURL(menu, newURL) {
        if ($j('#hdnAccount').attr('value') == 0) {
            $j('#hdnRedirect').attr('value', newURL);
            $j('#lblErrorMessage').text('To Access this feature, you must Log in.');
            $j("#login_error").show();
            $j('#hypOrLogin').click();
        } // Are we basic access
        else if ($j('#hdnAccount').attr('value') == 3) {
            // Show Upgrade message
            $j('#hypUpgrade').click();
            return;
        }
        else {
            DNASpinnerStart();
            window.location = newURL;
        }
    }

    //    $j(".SimilarDeals").click(function() {
    //        var transactionid = $j(this).attr("transactionid");
    //        var newURL = window.location.protocol + "//" + window.location.host //+ window.location.pathname
    //            + "/segmentview.aspx?ViewModes=1&AcquisitionID=" + transactionid;
    //        openURL(this, newURL);
    //    });

    $j("#tsubWatchSeller").click(function() {

        $j(".transsubmenu").hide();
        var transactionid = $j('#hdnActiveTransaction').attr("value");
        var companyid = $j(".transaction[transactionid='" + transactionid + "']").attr("sellerid");
        var newURL = window.location.protocol + "//" + window.location.host + '/MyAccount/Preferences.aspx?Activate=1&CompanyID=' + companyid;
        openURL(this, newURL);
    });

    $j("#tsubWatchBuyer").click(function() {

        $j(".transsubmenu").hide();
        var transactionid = $j('#hdnActiveTransaction').attr("value");
        var companyid = $j(".transaction[transactionid='" + transactionid + "']").attr("buyerid");
        var newURL = window.location.protocol + "//" + window.location.host + '/MyAccount/Preferences.aspx?Activate=1&CompanyID=' + companyid;
        openURL(this, newURL);
    });

    $j(".bookmarkmenuitem").click(function() {

        $j(".transsubmenu").hide();
        var transactionid = $j(this).parent().attr("transactionid");
        var addremove = $j(".transaction[transactionid='" + transactionid + "']").attr("addbookmarks");
        var newURL = window.location.protocol + "//" + window.location.host + //window.location.pathname +
            "/segmentview.aspx?ViewModes=3&Action=" + addremove + "&AcquisitionID=" + transactionid;
        openURL(this, newURL);
    });

    $j(".Compdrilldownmenuitem").click(function() {
        var companyid = $j(this).parent().attr("companyid"); //$j('#hdnActiveCompany').attr("value");
        var newURL = window.location.protocol + "//" + window.location.host; // +window.location.pathname;
        window.location = newURL + "/segmentview.aspx?ViewModes=1&CompanyID=" + companyid;
    });

    $j(".Compwatchmenuitem").click(function() {
        var companyid = $j(this).parent().attr("companyid"); //$j('#hdnActiveCompany').attr("value");
        var newURL = window.location.protocol + "//" + window.location.host + '/MyAccount/Preferences.aspx';
        window.location = newURL + "?Activate=1&CompanyID=" + companyid;
    });


});
    