//get url parameters
var query = window.location.search;
var queryPairs = query.substring(1).split("&");
var params = new Array();
for (var i in queryPairs) {
  var keyValue = queryPairs[i].split("=");
  params[keyValue[0]] = keyValue[1];
}

// extract useful parameters
var hsPath = params.path;
var hsService = params.service;
var hsChannel = params.channel;
var hsPage = params.page;
var hsContent = params.content;
var hsFrames = params.frames;
var hsBodyframe = params.bodyframe;
var hsDirectory = params.directory;
var hsTarget = params.target;
var hsTransform = params.transform;
var hsSearch_1 = params.search_1;
var hsCompany_status = params.company_status;
var hsNews = params.news;
var hsStorySource = params.storySource;
var hsStoryTypes = params.storyTypes;
var hsTracker = params.tracker;
var hsType = params.type;
var hsItem = params.item;
  
var wtChannel = "";
var wtSubsection = "";
var wtPage = "";
var wtTitle = "";

if (params.invite) {wtChannel = "Home"; wtSubsection = "Invite";}
else if ("home" == hsService) {wtChannel = "Home";}
else if ("getWebProfile" == hsService) {wtChannel = "Home"; wtSubsection = "Your%20Profile";}
else if ("getStockTracker" == hsService) {wtChannel = "Tools"; wtSubsection = "Stock%20Tracker";}
else if ("getScrGiltsOverview" == hsService) {wtChannel = "Prices"; wtSubsection = "Gilts";}
else if ("getCorporateDiaryXml" == hsService) {wtChannel = "Companies"; wtSubsection = "Corporate%20Calendar ";}
else if ("getAllMergersAndAcquisitions" == hsService) {wtChannel = "Companies"; wtSubsection = "Mergers%20and%20Acquisitions";}
else if ("getAllNameChanges" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Name%20Changes";}
else if ("getAllDeletions" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Deletions";}
else if ("getAllShares7Days" == hsService) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Director%20Dealings";}
else if ("getCompanyMap" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Company%20Map";}
else if ("getSummaryDetails" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Company%20Summary";}
else if ("getContactDetails" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Contact%20Details";}
else if ("getKeyDates" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Key%20Dates";}
else if ("getAdvisors" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Advisers";}
else if ("getDirectors" == hsService) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Directors";}
else if ("getRatios" == hsService) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Ratios";}
else if ("getDividends" == hsService) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Dividends";}
else if ("getDirectorsShareDealings" == hsService) {wtChannel = "Companies"; wtSubsection = "Forecasts%20and%20Deals"; wtPage = "Director%20Dealings";}
else if ("getMajorShareholders" == hsService) {wtChannel = "Companies"; wtSubsection = "Forecasts%20and%20Deals"; wtPage = "Shareholders";}
else if ("getShareTrades" == hsService) {wtChannel = "Companies"; wtSubsection = "Live%20Prices%20and%20News"; wtPage = "Live%20Trades";}
else if ("getNewsByCompanyId" == hsService) {wtChannel = "Companies"; wtSubsection = "Live%20Prices%20and%20News"; wtPage = "Company%20News";}
else if ("getNewsDigest" == hsService) {wtChannel = "Companies"; wtSubsection = "Live%20Prices%20and%20News"; wtPage = "News%20Abstract";}
else if ("getNewsEventsAndFireData" == hsService) {wtChannel = "Companies"; wtSubsection = "Graphs"; wtPage = "News%20Graph";}
else if ("getSubscriptions" == hsService) {wtChannel = "Home"; wtSubsection = "Subscription%20Signup";}
else if ("getWarrantsOverview" == hsService) {wtChannel = "Prices"; wtSubsection = "Warrant%20Overview";}

else if ("getSharePrices" == hsService) {
  if ("giltsprices" == hsTarget) {wtChannel = "Prices"; wtSubsection = "Gilts"; wtPage = "Gilts%20Prices";}
  else {wtChannel = "Companies"; wtSubsection = "Live%20Prices%20and%20News"; wtPage = "Live%20Prices";}
}

else if ("getShareGraph" == hsService) {
  if ("giltsgraphs" == hsTarget) {wtChannel = "Prices"; wtSubsection = "Gilts"; wtPage = "Gilts%20Graph";}
  else if ("comparative" == hsTransform) {wtChannel = "Companies"; wtSubsection = "Graphs"; wtPage = "Comparison%20Graph";}
  else {wtChannel = "Companies"; wtSubsection = "Graphs"; wtPage = "Share%20Price%20Graph";}
}

else if ("getForecasts" == hsService) {
  if ("brokerforecast" == hsType) {wtChannel = "Companies"; wtSubsection = "Forecasts%20and%20Deals"; wtPage = "Broker%20Forecast";}
  else if ("brokerrecommendation" == hsType) {wtChannel = "Companies"; wtSubsection = "Forecasts%20and%20Deals"; wtPage = "Broker%20Sentiment";}
}

else if ("getAnnualAndTransientReports" == hsService) {
  if ("consolidatedaccounts" == hsTransform) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Financial%20Overview";}
  else if ("profitandloss" == hsTransform) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Profit%20and%20Loss%20Account";}
  else if ("balancesheet" == hsTransform) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Balance%20Sheet";}
  else if ("cashflowstatement" == hsTransform) {wtChannel = "Companies"; wtSubsection = "Financial%20Data"; wtPage = "Cash%20Flow%20Statement";}
}

else if ("getCompanyAtoZ" == hsService) {
  if ("prices" == hsChannel) {wtChannel = "Prices"; wtSubsection = "A-Z%20Search";}
  else {wtChannel = "Companies"; wtSubsection = "A-Z%20Search";}
}

else if ("getHsCompanySearch" == hsService) {
  if ("AFL" == hsCompany_status) {wtChannel = "Companies"; wtSubsection = "Companies%20Listed%20in%20Advance%20of%20Flotation";}
  else {wtChannel = "Companies"; wtSubsection = "Index%20Search";}
}

else if ("getIndex" == hsService) {
  if ("prices" == hsChannel) {wtChannel = "Investment%20Ideas"; wtSubsection = "Streaming%20Prices"; wtPage = "Streaming%20Prices";}
}

else if ("getScr18ShowAllSectors" == hsService) {
  if ("companies" == hsChannel) {wtChannel = "Companies"; wtSubsection = "Sector%20Search";}
  else if ("detailednewssearch" == hsTarget) {wtChannel = "News"; wtSubsection = "Archive"; wtPage = "Advanced%20Search";}
  else if ("newssectorlist" == hsTarget) {wtChannel = "News"; wtSubsection = "Sector%20News"; wtPage = "All%20Sectors";}
  else {wtChannel = "Prices"; wtSubsection = "Sector%20Prices";}
}

else if ("getTopListStringInput" == hsService) {
  if ("percentgainers" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Percentage%20Gainers";}
  else if ("percentfallers" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Percentage%20Fallers";}
  else if ("volumeleaders" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Volume%20Leaders";}
  else if ("pricevolumeleaders" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Price%20Volume%20Leaders";}
  else if ("marketcapturnover" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Market%20Cap%20Turnover";}
  else if ("marketcap" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Market%20Cap";}
  else if ("constantgainers" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Constant%20Gainers";}
  else if ("constantfallers" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Constant%20Fallers";}
  else if ("bolowprice" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Low%20Price%20Breakouts";}
  else if ("bohighprice" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "High%20Price%20Breakouts";}
  else if ("bidofferspreadlargest" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Largest%20Bid%20Offer%20Spread";}
  else if ("bidofferspreadsmallest" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Smallest%20Bid%20Offer%20Spread";}
  else if ("liquidity" == hsTransform) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Liquidity";}
  else if ("risersandfallers" == hsTransform) {wtChannel = "Prices"; wtSubsection = "Risers%20and%20Fallers"; wtPage = "Risers%20and%20Fallers";}
}

else if ("getSrchScr01Searching" == hsService) {
  if ("22" == hsSearch_1) {wtChannel = "Investment%20Ideas"; wtSubsection = "Stock%20Selector"; wtPage = "Income%20Stocks";}
  else if ("24" == hsSearch_1) {wtChannel = "Investment%20Ideas"; wtSubsection = "Stock%20Selector"; wtPage = "Value%20Stocks";}
  else if ("23" == hsSearch_1) {wtChannel = "Investment%20Ideas"; wtSubsection = "Stock%20Selector"; wtPage = "Momentum%20Stocks";}
  else if ("21" == hsSearch_1) {wtChannel = "Investment%20Ideas"; wtSubsection = "Stock%20Selector"; wtPage = "Growth%20Stocks";}
}

else if ("getPriceInfoXml" == hsService) {
  if ("HeatMapCompaniesInIndex" == hsTarget) {wtChannel = "Tools"; wtSubsection = "Heat%20Maps";}
  if ("prices" == hsChannel) {wtChannel = "Prices"; wtSubsection = "Index%20Prices";}
}

else if ("getWarrantCompanySearch" == hsService) {
  if ("prices" == hsChannel) {wtChannel = "Prices"; wtSubsection = "Covered%20Warrants"; wtPage = "Company%20Search";}
}

else if ("newsBySource" == hsService) {
  if ("EXT" == hsStorySource) {wtChannel = "News"; wtSubsection = "AFX%20News";}
  else if ("RNS" == hsStorySource) {wtChannel = "News"; wtSubsection = "Regulatory%20News";}
  else {wtChannel = "News"; wtSubsection = "News"; wtPage = "News";}
}

else if ("newsByType" == hsService) {
  if ("AGM" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "AGM%20EGM";}
  else if ("ERN" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Results";}
  else if ("TRS" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Trading%20Statements";}
  else if ("MNA" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Mergers%20and%20Acquisitions";}
  else if ("DIV" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Dividends";}
  else if ("MGT" == hsStoryTypes) {wtChannel = "News"; wtSubsection = "Company%20News"; wtPage = "Board%20Changes";}
}

else if ("getTrackerNews" == hsService) { 
  if ("ALL_SHARE" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20All-Share";}
  else if ("100" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20100";}
  else if ("MID_250" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20250";}
  else if ("SMALL_CAP" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20Small%20Cap";}
  else if ("TECH_100" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20techMARK%20100";}
  else if ("AXX" == hsTracker) {wtChannel = "News"; wtSubsection = "UK%20Market%20News"; wtPage = "FTSE%20AIM%20All%20Share";}
}

else if ("getPage" == hsService) {

  if ("newsstream" == hsTarget) {
    if ("ALL" == hsNews) {wtChannel = "News"; wtSubsection = "Streaming%20News"; wtPage = "Latest%20News";}
    else if ("AFX" == hsNews) {wtChannel = "News"; wtSubsection = "Streaming%20News"; wtPage = "AFX%20News";}
    else if ("RNS" == hsNews) {wtChannel = "News"; wtSubsection = "Streaming%20News"; wtPage = "Regulatory%20News";}
  }
  
  else if ("premiumincludenews" == hsPage) {wtChannel = "News"; wtSubsection = "Archive"; wtPage = "News%20Archive";}
  else if ("investideas" == hsPage) {wtChannel = "Investment%20Ideas"; wtSubsection = "Investment%20Ideas";}

  else if ("includexslframeset" == hsPage) {
    if ("advisersindex" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Advisers";}
    else if ("tiptracker" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Tip%20Tracker";}
    else if ("digthedata" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Dig%20The%20Data";}
    else if ("weekahead" == hsFrames) {wtChannel = "Comment"; wtSubsection = "The%20Week%20Ahead";}
    else if ("comment" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Latest";}
    else if ("commentarchive" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Archive";}
    else if ("todayscomment" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Company";}
    else if ("todayscomment" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Company";}
  }

  else if ("premiumincludeitrusts" == hsPage) {
    if ("itsnews" == hsContent) {wtChannel = "Comment"; wtSubsection = "Investment%20Trusts";}
  }

  else if ("warrantsinclude" == hsPage) {
    if ("home" == hsContent) {wtChannel = "Comment"; wtSubsection = "Covered%20Warrants";}
  }

  else if ("calculators" == hsPage) {
    if ("shareprice" == hsContent) {wtChannel = "Tools"; wtSubsection = "Calculators"; wtPage = "Share%20Price%20Calculator";}
    else if ("sharepricelookup" == hsContent) {wtChannel = "Tools"; wtSubsection = "Calculators"; wtPage = "Share%20Price%20Lookup%20Calculator";}
    else if ("historicshareprice" == hsContent) {wtChannel = "Tools"; wtSubsection = "Calculators"; wtPage = "Historic%20Share%20Price%20Calculator";}
    else if ("accumulatedshareprice" == hsContent) {wtChannel = "Tools"; wtSubsection = "Calculators"; wtPage = "Accumulated%20Share%20Price%20Calculator";}
  }

  else if ("premiuminclude" == hsPage) {
    if ("alertshp" == hsContent) {wtChannel = "Tools"; wtSubsection = "Alerts";}
    else if ("stockselectorhp" == hsContent) {wtChannel = "Investment%20Ideas"; wtSubsection = "Stock%20Selector"; wtPage = "Stock%20Selector";}
  }

  else if ("premiumincludedir" == hsPage) {
    if ("calculators" == hsDirectory) {wtChannel = "Tools"; wtSubsection = "Calculators"; wtPage = "Calculators";}
    else if ("toplists" == hsDirectory) {wtChannel = "Investment%20Ideas"; wtSubsection = "Toplists"; wtPage = "Toplists";}
  }
  
  else if ("premiumstaticdir" == hsPage) {
    if ("facts" == hsContent) {wtChannel = "Companies"; wtSubsection = "Company%20Overview"; wtPage = "Facts%20Report";}
  }

  else if ("premiumstatic" == hsPage) {
    if ("premiumframeset" == hsContent) {
      if ("infoex" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Postings%20Page";}
      else if ("infoex_search" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Search";}
      else if ("infoex_post" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Post%20Message";}
      else if ("infoex_password" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "request%20Password";}
      else if ("infoex_archives" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Archives";}
      else if ("infoex_100" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Latest%20Messages";}
      else if ("infoex_threads" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Latest%20Messages";}
      else if ("infoex_rules" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Rules";}
      else if ("infoex_intro" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Intro";}
      else if ("infoex_advice" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Advice";}
      else if ("infoex_faq" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "FAQ";}
      else if ("infoex_disclaimer" == hsFrames) {wtChannel = "Tools"; wtSubsection = "Info%20Exchange"; wtPage = "Disclaimer";}
      else if ("tiptracker" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Tip%20Tracker";}
      else if ("digthedata" == hsFrames) {wtChannel = "Comment"; wtSubsection = "Dig%20The%20Data";}
      else if ("auditors" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Auditors";}
      else if ("advisersindex" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Advisers";}
      else if ("financialadvisers" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Financial%20Advisers";}
      else if ("financialprs" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Financial%20PR%20Advisers";}
      else if ("lawfirms" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Law%20Firms";}
      else if ("registrars" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Registrars";}
      else if ("stockbrokers" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Stockbrokers";}
      else if ("venturecapitalists" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Private%20Equity%20Companies";}
      else if ("adviserrankings" == hsFrames) {wtChannel = "Advisers"; wtSubsection = "Adviser%20Rankings";}
    }

    else if ("itrusts_stories" == hsFrames) {
      if ("splits_itrusts_160702.htm" == hsBodyFrame) {wtChannel = "Comment"; wtSubsection = "Investment%20trusts"; wtPage = "Splits%20Update";}
      else if ("property_1007_2002.htm" == hsBodyFrame) {wtChannel = "Comment"; wtSubsection = "Investment%20trusts"; wtPage = "Property%20Investment%20Trusts";}
      else if ("smallcosreview_0907_2002.htm" == hsBodyFrame) {wtChannel = "Comment"; wtSubsection = "Investment%20Trusts"; wtPage = "Smaller%20Companies";}
      else if ("hedgefunds_0807_2002.htm" == hsBodyFrame) {wtChannel = "Comment"; wtSubsection = "Investment%20Trusts"; wtPage = "Hedge%20Funds";}
      else if ("itrust_archive.htm" == hsBodyFrame) {wtChannel = "Comment"; wtSubsection = "Investment%20Trusts"; wtPage = "Archive";}    
    }
  }
}

else if ("getChannel" == hsService) {
  if ("companies" == hsChannel) {wtChannel = "Companies"; wtSubsection = "A-Z%20Search";}
  else if ("prices" == hsChannel) {wtChannel = "Prices"; wtSubsection = "A-Z%20Search";}
  else if ("comment" == hsChannel) {
    wtChannel = "Comment";
    if (typeof(hsItem) != "undefined") wtSubsection = "Comment%20Item";
    else if ("archive" == hsPage) wtSubsection = "Comment%20Archive";
    else if ("company" == hsPage) wtSubsection = "Company%0Comment";
    else if ("digthedata" == hsPage) wtSubsection = "Dig%20The%20Data";
    else if ("tiptracker" == hsPage) wtSubsection = "Tip%20Tracker";
    else wtSubsection = "Latest%20Comment";
  }
  else if ("advisers" == hsChannel) {
    wtChannel = "Advisers";
    if ("auditors" == hsPage) wtSubsection = "Auditors";
    else if ("financialadvisers" == hsPage) wtSubsection = "Financial%20Advisers";
    else if ("financialprs" == hsPage) wtSubsection = "Financial%20PRs";
    else if ("lawfirms" == hsPage) wtSubsection = "Law%20Firms";
    else if ("registrars" == hsPage) wtSubsection = "Registrars";
    else if ("stockbrokers" == hsPage) wtSubsection = "Stockbrokers";
    else if ("venturecaptitalists" == hsPage) wtSubsection = "Private%20Equity";
    else if ("adviserrankings" == hsPage) wtSubsection = "Adviser%20Rankings";
    else wtSubsection = "Advisers%20Home";
  }
  else if ("toolbox" == hsChannel) {wtChannel = "Tools"; wtSubsection = "Resources"; wtPage = "Resources";}
}

if (wtChannel=="") wtTitle=wtChannel;
if (wtSubsection=="") wtTitle=wtSubsection;
if (wtPage=="") wtTitle=wtPage;

function getAdTitle(title) {
  switch (title) {
  case '':
    return '';
  case 'Tools':
    return 'toolbox';
  case 'Investment%20Ideas':
    return 'investideas';
  default:
    return title.toLowerCase().replace(/%20/g,'-');
  }
}

var adChan = getAdTitle(wtChannel);
var adSect = getAdTitle(wtSubsection);
var adPage = getAdTitle(wtPage);

var adTags = (adChan)? 'chan=' + adChan + ';' : '';
adTags += (adSect)? 'sect=' + adSect + ';' : '';
adTags += (adPage)? 'page=' + adPage + ';' : '';
adTags += 'premiumplus=' + inPremiumPlus + ';';
adTags += (params.testAds)? 'test=testfiller;' : '';

if (typeof(params.showTrendsTags) != 'undefined') alert("wtChannel=" + wtChannel + ";wtSubsection=" + wtSubsection + ";wtPage=" + wtPage + ";wtTitle=" + wtTitle);
if (typeof(params.showAdTags) != 'undefined') alert(adTags);
