//This page needs to be configured for each site

//Base url for content match.  Each site must configure its own.
var g_baseOvertureCMUrl = "http://cm.comedycentral.overture.com/js_flat_1_0/";

//source paramater for content match.  Each site must configure its own.
var g_overtureCMSource = "viacom_comedycentral_ctxt"

//Config code for each site.  Each site must configure its own.
var g_overtureCMConfig = "3580706933"

//Base url for partner search.  Each site must configure its own.
var g_baseOvertureSearchUrl = "http://html.overture.com/d/search/p/mtv/js/flat/";

//partner paramater for search.  Each site must configure its own.
var g_overtureSearchPartner = "viacom_comedycentral_ls_search";

//this variable is set in sponsored.jhtml
var linkspotId = 'comedycentral_tvshows';

//Base url for the linkspot feed. .This is the same for all sites.
var g_baseOvertureLinkspotUrl = "http://cmls.overture.com/ls_js_1_0/?linkspotId=" + linkspotId + "&NKw=10&NGrp=1";

//default linkspot id.
var g_defaultLinkspotId = "mtv_games";

//source paramater for linkspots.  Each site must configure its own.
var g_overtureLinkspotSource = "viacom_comedycentral_ctxt";

//Config code for each site.  Each site must configure its own.
var g_overtureLinkspotConfig = "3580706933";

//This is a mapping of urls to ctxtIds. IDs are to be provided by Yahoo
var g_contextIdMap = new Object();
g_contextIdMap["/music"] = "music";
g_contextIdMap["/news"] = "news";
g_contextIdMap["/movies"] = "movies";
g_contextIdMap["/shared/white_pages"] = "music";

//This is a mapping of urls to linkspotIds. IDs are to be provided by Yahoo
var g_linkspotIdMap = new Object();
g_linkspotIdMap["/music"] = "music";
g_linkspotIdMap["/news"] = "news";
g_linkspotIdMap["/movies"] = "movies";
g_linkspotIdMap["/shared/white_pages"] = "diet";


//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 content match sponsored links with linksposts
//added Xiomara : THIS IS THE FUNCTION THAT IS CALLED IN SPONSORED.JHTML AND THE ONE WE WILL BE MANIPULATING

function showCMWithLinkspots(linkData, startIndex, endIndex, linkspotData, rowIndex, maxLinks ) {
	if (startIndex == undefined) {
		startIndex = 0;
  	}
  	
	var links = linkData.getItems();
 	var outString = '<ul class="contentMatch">';
  	var arrLength = links.length;
  	
	if (endIndex == undefined || endIndex == 0) {
    	endIndex = arrLength;
	} else {
		if (endIndex > arrLength) {
			endIndex = arrLength;
    	}
  	}

  	var emptyText = "<li><b>doh! not links to show</b></li>";
  	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];
		var liClass = '';
		if (i == startIndex) {
			liClass = 'first';
		}
		outString +='<li class='+liClass+'>';
			outString +='<a class="sponsored-search-title" href=' + currItem.getClickUrl() + '>' + currItem.getTitle() + '</a>';			
			outString +='<a class="sponsored-search-description-inline" target="_blank" href=' + currItem.getClickUrl() + '>'+ currItem.getDescription() +'</a>';
			outString +='<a class="sponsored-search-url" target="_blank" href=' + currItem.getClickUrl() + '>' + currItem.getSitehost() + '</a>';
		outString +='</li>';
   		i++;
  	} 
 
  	outString += '<li class="linkspot">' + showLinkspotRow(linkspotData, rowIndex, maxLinks) + '</li>\n';
	outString += '<li class="slTitle">Sponsored Links</li>\n';
  	outString += "</ul>";
  	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 = "";
  var isEmpty = false;
  var keywords;

  if (linkspot == undefined) {
    isEmpty = true;
  } else {
    keywords = linkspot.getKeywords();
  }

  var len = keywords.length;
  if (len <= 0) {
    isEmpty = true;
  }

  var emptyText = "<div><b>doh! not link spots to show</b></div>";
  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 += "<a href=\"http://" + window.location.hostname + "/search/gsa/index.jhtml?usecm=1&searchterm=" + urlEncode(keyword) + "&Partner=viacom_comedycentral_ls_search&urlFilters=" + urlFilters + "&urlFilters=" + termFilters + "&serveUrl=encoded_url&maxCount=10" + "&isLS=1" + "\">" + keyword +  "</a>\n";
  }
  return outString;
}

