//This page needs to be configured for each site
//Base url for content match. Each site has a different hostname
var g_baseOvertureCMUrl = "http://cm.mtv.overture.com/js_flat_1_0/";
//source paramater for content match. Each site has its own source code
var g_overtureCMSource = "viacom_mtv_ctxt";
//Config code for each site
var g_overtureCMConfig = "1458724563";
//Base url for partner search. 
var g_baseOvertureSearchUrl = "http://html.overture.com/d/search/p/mtv/js/flat/";
//partner paramater for search. 
var g_overtureSearchPartner = "viacom_mtv_search";
var g_baseOvertureLinkspotUrl = "http://cmls.overture.com/ls_js_1_0/";
//default linkspot id.
var g_defaultLinkspotId = "mtv_games";
//source paramater for linkspots.  Each site must configure its own.
var g_overtureLinkspotSource = "mtv_games_ls_ctxt_test";
//Config code for each site.  Each site must configure its own.
var g_overtureLinkspotConfig = "1458724563";
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();
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;
var oneKeyword = keywords.split("/")[0];
while ( i <= endIndex && links[i] != null){
var currItem = links[i];
var ctText = currItem.getTitle().replace(eval('/' + oneKeyword.toUpperCase() + '/g'), '<eM>' + oneKeyword.toUpperCase() + '</eM>');
ctText = ctText.replace(eval('/' + oneKeyword.toLowerCase() + '/g'), '<eM>' + oneKeyword.toLowerCase() + '</eM>');
ctText = ctText.replace(eval('/' + titleCase(oneKeyword) + '/g'), '<eM>' + titleCase(oneKeyword) + '</eM>');
var cdText = currItem.getDescription().replace(eval('/' + oneKeyword.toUpperCase() + '/g'), '<em>' + oneKeyword.toUpperCase() + '</eM>');
cdText = cdText.replace(eval('/' + oneKeyword.toLowerCase() + '/g'), '<eM>' + oneKeyword.toLowerCase() + '</eM>');
cdText = cdText.replace(eval('/' + titleCase(oneKeyword) + '/g'), '<eM>' + titleCase(oneKeyword) + '</eM>');
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\">" + ctText + "</a></strong><a href=\"" + currItem.getClickUrl() + "\" target=\"_blank\">" + cdText + "</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 Results</strong></p>\n';
	return outString;
}
//An example function for drawing a set of content match sponsored links with linksposts
function showCMWithLinkspots(linkData, startIndex, endIndex, linkspotData, rowIndex, maxLinks, version ){
if (startIndex == undefined){
	startIndex = 0;
}
var links = linkData.getItems();
var olClass = (version == 'charlie') ? 'lst' : 'slat';
var outString = '<ol class="' + olClass + ' 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);
}
loadOvertureCMInclude(conf);
	}
 function generateOvertureArray(){
	if(zSr){
		overture_links = populateOvertureLinks(zSr);
		if (overture_links == undefined){
		//If this in not populated use dummy data
			zSr = zSr_dummy;
		}
	}
	else{
	//If this in not populated use dummy data
		zSr = zSr_dummy;
	}
	}
function generateOvertureLSArray(){
if(mapkey){
	overtureLinkspots = populateOvertureLinkspots(mapkey);
if (overtureLinkspots == undefined){
	//If this in not populated use dummy data
	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_search(){
	var arg = printOverture_search.arguments;
	var links = arg[0].getItems();
	if (links[arg[1]]!= null){
		document.writeln("<div class=\"overture-results\">");
		if(arg[0] != undefined){
			document.writeln(showLinks1(arg[0], arg[1], arg[2], arg[3]));
		}
		document.writeln("</div>");
	}
}
function printOverture_search_column(){
	var arg = printOverture_search_column.arguments;
	var links = arg[0].getItems();
		if(links[arg[1]]!= null){
		document.writeln("<div class=\"mdl overture-wrap\">");
			if(arg[0] != undefined){
				document.writeln(showLinks1(arg[0], arg[1], arg[2], arg[3]));
				}
			document.writeln("</div>");
		}
	}
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], arg[6]));
	}
}
