//This page needs to be configured for each site

///////////////CONTENT MATCH/////////////////////////////
//Base url for content match.  Each site must configure its own.
var g_baseOvertureCMUrl = "http://cm.logoonline.overture.com/js_flat_1_0/";
//source paramater for content match.  Each site must configure its own.
var g_overtureCMSource = "viacom_logoonline_ctxt"
//Config code for each site.  Each site must configure its own.
var g_overtureCMConfig = "1167076674"
///////////////////////////////////////////////////////////

//////////////////LINKSPOTS////////////////////////////////
//Base url for the linkspot feed. .This is the same for all sites.
var g_baseOvertureLinkspotUrl = "http://cmls.overture.com/ls_js_1_0/";
//default linkspot id.
var g_defaultLinkspotId = "logoonline_tvschedule";
//source paramater for linkspots.  Each site must configure its own.
var g_overtureLinkspotSource = "viacom_logoonline_ls_kwonly_ctxt";
//Config code for each site.  Each site must configure its own.
var g_overtureLinkspotConfig = "1167076674";
////////////////////////////////////////////////////////////

///////////////////SEARCH///////////////////////////////////
//Base url for partner search.  Each site must configure its own.
var g_baseOvertureSearchUrl = "http://html.overture.com/d/search/p/viacom/js/v2/";
//partner paramater for search.  Each site must configure its own.
var g_overtureSearchPartner = "viacom_logoonline_search";
////////////////////////////////////////////////////////////

//This is a mapping of urls to ctxtIds. IDs are to be provided by Yahoo
var g_contextIdMap = new Object();
g_contextIdMap["/documentaries"] = "logoonline_documentaries";
g_contextIdMap["/movies"] = "logoonline_films";
g_contextIdMap["/music"] = "logoonline_music";
g_contextIdMap["/news"] = "logoonline_news";
g_contextIdMap["/shows"] = "logoonline_seriesandspecials";
g_contextIdMap["shop.logoonline.com"] = "logoonline_shop";
g_contextIdMap["/travel"] = "logoonline_travel";
g_contextIdMap["/schedule"] = "logoonline_tvschedule";


//This is a mapping of urls to linkspotIds. IDs are to be provided by Yahoo
var g_linkspotIdMap = new Object();
g_linkspotIdMap["/documentaries"] = "logoonline_documentaries";
g_linkspotIdMap["/movies"] = "logoonline_films";
g_linkspotIdMap["/music"] = "logoonline_music";
g_linkspotIdMap["/news"] = "logoonline_news";
g_linkspotIdMap["/shows"] = "logoonline_seriesandspecials";
g_linkspotIdMap["shop.logoonline.com"] = "logoonline_shop";
g_linkspotIdMap["/travel"] = "logoonline_travel";
g_linkspotIdMap["/schedule"] = "logoonline_tvschedule";
 


//Default links to use in case we don't get results back.
zSr_dummy = new Array("Reach 80% of active Internet users with Overture.","","","List your site with Overture","http://www.overture.com/","",
"See the latest Accord offers at the Honda Official Site.",
"",
"http://ypn-100.overture.com/d/sr/?xargs=SjGTYHM2WSfAwg8ep-u2ASFl94ZiTOXSU7PrBi34b0dkMRpxIz_DgoDqDHPG_NIidq9XtjihuvhsnU-qzNGWIEpI0WYkcoPdGWF6vHcW_pmyJkWX7VREKmh2o6lFQdzPF1NYiCCDFPBMzTW1E9ywARKkbBHDxtdkScwJOM-imi-fb8Z061AriZIDa1EDdkfqf3QyaFsV2ZtTR7fzb3-6K7zuu9vXH0AppemWRteQ9SJW7Z1IuIHVxAIrOsp7BDr91kty-i4Ghjhbnh_NMBWcNKIHMwuOzg_br8ZdyL97n9w8jcEZNvfaURyWMRn97xi0YtD5kOy-QPA",
"Honda Vehicles",
"www.honda.com",
"",
"Save up to 40% JVC, Pioneer, Clarion, Alpine, Kenwood.",
"",
"http://ypn-100.overture.com/d/sr/?xargs=k-vWdwvJp78awRZ3Qhx-bNIsqKMyFJwxG5e0pmbgOXJ8w7TZD_t_g3yvErHu8Xl4I3_x8ptDV3A0LIMF7OlPTj5IkMVeVfJ7YImiuZU1-p7rVyQOV4pyMgRkXrvbW_C6knIw1bUvr88gdVHsT-HA77YeNJVDGHkfjWgmNwyqxub9CYdDO8qHDr1b2pamYZbeIy8ZdhbSa1DvmkyROP-YJHS26-bDnYiyF5Aqyi-iI6d3UaXPeWNhzBfWVqBbIRd7wn767p7eqywIgT6oNriUfKJKA9YnOYxl9msgYv75FJF4Yrr5i8pEpPbf8orxrGg5OiPTaHCp4Qw",
"Car Audio/Multimedia SALE",
"carsaudio.co.uk",
"",
"Electronics, Games, Toys, Digital Cameras, and more.",
"",
"http://ypn-100.overture.com/d/sr/?xargs=cc9OZjd2BnLDSEYSO0xFQYOLbyfpbe27TqGUg90i-jKS-gcU8lXMkhuNGMm3DJcx2oriBHlOMItEsUbii_mZooTh1ploLYXV4BBkox4A4Qm4e-UnspwI6DfPw1Y_7s2sDBsD0wcAgFkwVB-VviXebuFDhuCZJseHhCWH6u2I3yH5D1X0OIGIQdhCQIYNL7WVQvzPz69wffyUTyqnItDPX1OFjCZ3Kqnwomn_TFmZeibU291SbvoyNP4mMKIn6VmD3D4rOoid-bTxDP63P19rs3ZAqnClMlJZXOimusbL77w3hK72W7aVtG2VBll-pXPpohzEDJ2nt8A",
"Hundreds of Products at Low Prices",
"www.advancedtechtoys.com",
"");

//zSr is the array that is populated by the javacsript call to Overture
var zSr;

//mapkey is the variable yahoo fills in to provide linkspot data
var mapkey;

//dummy data for the mapkey.
var mapkey_dummy=[{title: 'placeholder', keywords: 'fitness equipment, fitness, diet program, weight loss program, home gyms, vitamin, exercise bike, nutrition, healthy diet, fitness program'}];

//Below are some example funtions to draw the acutall link boxes
//Each site can use this same pattern to define new functions that can draw the links
//in various ways. Note that each site will need to define their own functions for
//drawing the links.

//An example function for drawing a set of sponsored links
function showLinks1(linkData, startIndex, endIndex) {
  if (startIndex == undefined) {
	startIndex = 0;
  }
  var links = linkData.getItems();
  var outString = "<table class=sponsor-box border=0 width=100%>";
  var arrLength = links.length;
  if (endIndex == undefined || endIndex == 0) {
    endIndex = arrLength;
  }
  else {
    if (endIndex > arrLength) {
	endIndex = arrLength;
    }
  }

  var emptyText = "<table border=1><tr><td><b></b></td></tr></table>";
  if (endIndex <= startIndex) {
     //If there are not links to show, then return an alternative text
     return emptyText;
  }

  var i = startIndex;
  while ( i < endIndex) {
   var currItem = links[i];
   outString += "<tr><td><a class=sponsor-text href=\"" + currItem.getClickUrl() + "\">" + currItem.getTitle().toUpperCase() + "</a><br /><a class=not-link href=\"" + currItem.getClickUrl() + "\"> " + currItem.getDescription() + "</a></span><br /><em><a class=url-text href=\"" + currItem.getClickUrl() + "\">" + currItem.getSitehost() + "</a></em><br /><div class=half-line>&nbsp;</div></td></tr>\n";
   i++;
  } 
 outString += "</table>";
  outString += "<div class=online><strong>SPONSORED RESULTS</strong></div>";
  return outString;
}

//A second example function for drawing a set of sponsored links
function showLinks2(linkData, startIndex, endIndex) {
  if (startIndex == undefined) {
	startIndex = 0;
  }
  var links = linkData.getItems();
  var outString = "<table class=sponsor-box border=0 width=100%>";
  var arrLength = links.length;
  if (endIndex == undefined || endIndex == 0) {
    endIndex = arrLength;
  }
  else {
    if (endIndex > arrLength) {
	endIndex = arrLength;
    }
  }

  var emptyText = "<table border=1><tr><td><b></b></td></tr></table>";
  if (endIndex <= startIndex) {
     //If there are not links to show, then return an alternative text
     return emptyText;
  }

  var i = startIndex;
  while ( i < endIndex) {
   var currItem = links[i];
    outString += "<tr><td><a class=searchText href=\"" + currItem.getClickUrl() + "\">" + currItem.getTitle().toUpperCase() + "</a><br /><a class=search_Text_link href=\"" + currItem.getClickUrl() + "\">" + currItem.getDescription() + "</a><br /><em><a class=url-text href=\"" + currItem.getClickUrl() + "\">" + currItem.getSitehost() + "</a></em><br /><div class=half-line>&nbsp;</div></td></tr>\n";
   i++;
  } 
  outString += "</table>";
  outString += "<div class=online><strong>SPONSORED RESULTS</strong></div>";
  return outString;
}

//An example function for drawing a set of content match sponsored links with linksposts
function showCMWithLinkspots(linkData, startIndex, endIndex, linkspotData, rowIndex, maxLinks ) {
  if (startIndex == undefined) {
	startIndex = 0;
  }
  var links = linkData.getItems();
  var outString = "<table class=sponsor-box border=0 width=100%>";
 outString += "<tr><td width='75%'><table>";
  var arrLength = links.length;
  if (endIndex == undefined || endIndex == 0) {
    endIndex = arrLength;
  }
  else {
    if (endIndex > arrLength) {
	endIndex = arrLength;
    }
  }

  var emptyText = "<table class=sponsor-box border=0><tr><td><b></b></td></tr></table>";
  if (endIndex <= startIndex) {
     //If there are not links to show, then return an alternative text
     return emptyText;
  }

  var i = startIndex;
  while ( i < endIndex) {
   var currItem = links[i];
   outString += "<tr class=cm><td class=searchText><a href=\"" + currItem.getClickUrl() + "\">" + currItem.getTitle() + "</a></td></tr><tr><td class=text>" + "<a href=\"" + currItem.getClickUrl() + "\">" + currItem.getDescription() + "</a>" + "</td></tr><tr class=cm><td class=search_Text_link><a href=\"" + currItem.getClickUrl() + "\">" + currItem.getSitehost() + "</a><br/><br/></td></tr>\n";
   i++;
  } 
  outString += "</table></td><td><table><tr><td>" + showLinkspotRow(linkspotData, rowIndex, maxLinks) + "</td></tr></table></td></tr></table>\n";
  //outString += "</table>";  //temp
    outString += "<div class=online><strong>SPONSORED LINKS</strong></div>";
  return outString;
}


//An example function for drawing one row of linkspots. pass in the linkData, index of the row you want
//(we will pretty much always be using index 0 for the first row), and the max number of link
//that we want to show.
function showLinkspotRow(linkData, rowIndex, maxLinks) {

  var linkspot = linkData.getItem(rowIndex);
  var outString = "<table width=100% border=0>";
  var isEmpty = false;
  var keywords;

  if (linkspot == undefined) {
    isEmpty = true;
  }
  else {
//alert(mapkey[0]['keywords']);
    keywords = linkspot.getKeywords();
  }

  var len = keywords.length;

  if (len <= 0) {
    isEmpty = true;
  }

  var emptyText = "<table border=0><tr><td><b></b></td></tr></table>";
  if (isEmpty) {
     //If there are not links to show, then return an alternative text
     return emptyText;
  }

  var endIndex;
  if (len > maxLinks) {
     endIndex = maxLinks;
  }
  else {
     endIndex = len;
  }
   for (var i=0; i < endIndex; i++) {
   var keyword = keywords[i];
   outString += "<tr><td class=\"suggestedWord\"><a href=\"http://" + window.location.hostname + "/search/?usecm=1&searchterm=" + urlEncode(keyword) + "\">" + keyword + "</a></td></tr>\n<tr><td>&nbsp;</td></tr>\n";
  } 
  outString += "</table>";
  return outString;
}

