//This page needs to be configured for each site

//Base url for content match. Each site has a different hostname


// LINKSPOTS VARS BELOW

//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 = "rmp_education";
//source paramater for linkspots.  Each site must configure its own.
var g_overtureLinkspotSource = "viacom_rmp_revhare_ls_kwonly_ctxt_test";
//Config code for each site.  Each site must configure its own.
var g_overtureLinkspotConfig = "1501467592";
//***********************************************************************************************

//Base url for content match. Each site has a different hostname
//var g_baseOvertureCMUrl = "http://cm.rmp.overture.com/js_flat_1_0/";
var g_baseOvertureCMUrl = "http://cm.mtvu.overture.com/js_flat_1_0/";
//source paramater for content match. Each site has its own source code
// var g_overtureCMSource = "viacom_rmp_ctxt";
//var g_overtureCMSource = "viacom_mtvu_ctxt_test"; // 'test' used for testing
var g_overtureCMSource = "viacom_mtvu_ctxt";


//Config code for each site 
// var g_overtureCMConfig = "1501467592";
var g_overtureCMConfig = "1214014478";

//Base url for partner search.   
var g_baseOvertureSearchUrl = "http://html.viacom.overture.com/d/search/p/viacom/js/v2/";


//var g_overtureSearchPartner = "viacom_mtvu_search_test";// 'test' used for testing
var g_overtureSearchPartner = "viacom_mtvu_search"; // For live without 'test' //  Jeff's mail

//as per Jeff's email on 6/28/07
// var g_overtureContextId = "rmp";
var g_overtureContextId = "music";

var g_contextIdMap = new Object();
g_contextIdMap["/news/youtellus"] = "news";
g_contextIdMap["/music/artist"] = "music";
g_contextIdMap["/music/the_leak"] = "music";
g_contextIdMap["/news"] = "news";
g_contextIdMap["/mobile"] = "mobile";
g_contextIdMap["/ontv"] = "ontv";
g_contextIdMap["/music"] = "music";
g_contextIdMap["/movies"] = "movies";
g_contextIdMap["/games"] = "games";
g_contextIdMap["/thinkmtv"] = "think";

var g_typeIdMap = new Object();
g_typeIdMap["/news/youtellus"] = "youtellus";
g_typeIdMap["/music/artist"] = "artist_page";
g_typeIdMap["/music/the_leak"] = "theleak";
g_typeIdMap["/news"] = "news_article";
g_typeIdMap["/mobile"] = "mobile";
g_typeIdMap["/ontv"] = "ontv";
g_typeIdMap["/music"] = "music";
g_typeIdMap["/movies"] = "movies";
g_typeIdMap["/games"] = "games";
g_typeIdMap["/thinkmtv"] = "think";


//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;
var 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.

function titleCase(str) {
        return str.toLowerCase().replace(/\b\w+\b/g, cnvrt);
        function cnvrt() {
            if (arguments[arguments.length -2] == 0)
                return arguments[0].replace(/^[a-z]/, cnvrt2);
            else if (/^(a|about|after|an|and|at|by|for|from|in|into|nor|of|on|onto|over|the|to|up|with|within)$/.test(arguments[0]) )
                return arguments[0];
            else
                return arguments[0].replace(/^[a-z]/, cnvrt2);
        }
        function cnvrt2() {
            return arguments[0].toUpperCase();
        }
    }

//A function for drawing a set of sponsored links
function showLinks1(linkData, startIndex, endIndex, placement) 
{
  if (startIndex == undefined) {
	startIndex = 0;
  }
  var links = linkData.getItems();
  //alert("in showLinks1(..), linkData.length(): " + linkData.length());
  var arrLength = links.length;
  if (endIndex == undefined || endIndex == 0) {
    endIndex = arrLength;
  }
  else {
    if (endIndex > arrLength) {
	endIndex = arrLength;
    }
  }

  var emptyText = "";
  if (endIndex <= startIndex) {
     //If there are not links to show, then return an alternative text
     return emptyText;
  }
  
  var i = startIndex;
  var outString = "<table width=\"426px\" style='text-align:left;font: normal 78%/1.4em arial, helvetica, sans-serif;' >"; 
  while ( i <= endIndex) 
  {
	   var currItem = links[i];
	   if (!(currItem == undefined)) 
	   {
			outString += "<tr><td><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\" ><font color=\"#005295\" onmouseover=\"this.style.color='#FFFFFF'\" onmouseout=\"this.style.color='#005295'\" >" + currItem.getTitle() + "</font></a><br><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\" ><font color=\"#000000\">" + currItem.getDescription() + "</font></a><br><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\" ><font color=\"#000000\">" + currItem.getSitehost() + "</font></a></td></tr><tr style=\"height:10px\"><td></td></tr>";
	   }
	   i++;
  } 
  
  outString += "<tr><td>";
  
/* commented out - linkspots

  for (var i=0; i<mapkey.length; i++)
  {
	var keywords= mapkey[i].keywords.split(", ");

	for (var j=0; j<keywords.length; j++)
	{
		var lsSrchResultPage = "/gSearchResults.jsp?letter=" + keywords[j] + "&usecm=1";
		outString += "<a href='" + lsSrchResultPage + "'>" + keywords[j] + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
  	}
  }
*/

  //outString = outString.substring(0, outString.length-38); // removes the last row spacer appended (the <tr> with the height attr)
  outString += "</td></tr></table>";
  
 // alert("in showLinks1(..), outString: " + outString);
  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 = '<ol class="slat rich sponsored-results">\n';
  var arrLength = links.length;
  if (endIndex == undefined || endIndex == 0) {
    endIndex = arrLength;
  }
  else {
    if (endIndex > arrLength) {
	endIndex = arrLength;
    }
  }

  var emptyText = "";
  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];
   
   if (!(currItem == undefined)) {
     if (i == endIndex) outString += "<li class=\"last\">\n";
     else outString += "<li>\n";
     outString += "<p class=\"info\"><strong><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\">" + currItem.getTitle() + "</a></strong><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\">" + currItem.getDescription() + "</a></p>";
     outString += "<p class=\"meta\"><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\">" + currItem.getSitehost() + "</a></p>\n";
   	 outString += "</li>\n"
   }
   i++;
  }
  
  outString += '</ol>\n';
  outString += '<p class="spons-footer"><strong>Sponsored Links</strong></p>\n';
  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 loadOvertureSrchArray() {

	var conf = new overtureSearchConf();
  	conf.setKeywords(keywords);
  	conf.setOutputCharEnc("latin1");

	 if (!isEmpty(urlFilters)) {
    conf.setUrlFilters(urlFilters);
  		}
  	if (!isEmpty(termFilters)) {
    conf.setTermFilters(termFilters);
  		}
  	// var myUrl = createOvertureSearchLink(conf);
  	// document.writeln("<P>url = " + myUrl + "<BR>");
  	loadOvertureSearchInclude(conf);
  	
  	}
	
	
	function loadOvertureCMArray() 
	{
		var conf = new overtureContentMatchConf();
		 // conf.setCtxtKeywords(keywords);
		conf.setOutputCharEnc("latin1");
		 
		if (!isEmpty(ctxtId)) 
		{
			conf.setCtxtId(ctxtId);
		}
		else 
		{
			 //use the map to get the ctxtId
		    conf.setCtxtIdMap(g_contextIdMap);
		}
		if(!isEmpty(type)) 
		{
			conf.setType(type);
		}
		else 
		{  
			conf.setTypeMap(g_typeIdMap);  
	    }
		if(!isEmpty(keywordCharEnc))
			conf.setKeywordCharEnc(keywordCharEnc);
		if(!isEmpty(outputCharEnc))
			conf.setOutputCharEnc(outputCharEnc);
		if(!isEmpty(maxCount))
			conf.setMaxCount(maxCount);
	
		  // var myUrl = createOvertureCMLink(conf);
		//document.writeln("<P>url = " + myUrl + "<BR>");
		loadOvertureCMInclude(conf);
	}
  
 
 /*function generateOvertureArray() 
 {
    alert("in generateOvertureArray(), zSr: " + zSr);	
	if(zSr) 
	{
     	overture_links = populateOvertureLinks(zSr);
     	if (overture_links == undefined) 
			zSr = zSr_dummy;
  	}
  	else 
		zSr = zSr_dummy;
	
}*/
 
 function generateOvertureLSArray() 
 {	
	//alert("1. in generateOvertureLSArray(): ");
	if(mapkey) 
	{
		 overtureLinkspots = populateOvertureLinkspots(mapkey);
		 if(overtureLinkspots == undefined)
			mapkey = mapkey_dummy;
    }
    else 
	{
    	//If this in not populated use dummy data
    	mapkey = mapkey_dummy;
    }
 }
 
 function printOverture_1() 
 {
	 var arg = printOverture_1.arguments;
	 if(arg[0] != undefined) 
	 {
     	document.writeln(showLinks1(arg[0], arg[1], arg[2], arg[3]));
  	 }
 }
  
  function printOverture_ls() 
  {
 
	 var arg = printOverture_ls.arguments;
	 if(arg[0] != undefined) 
	 {
		 document.writeln(showCMWithLinkspots(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]));
	 }
  }
