function TiiAolSponsorBox() {
this.stest = "off";
this.showBottom = true;
this.page = 1;
this.rv = "1.2";
this.nt = "";
this.render = TiiRenderSponsorBoxes;
this.renderPopup = TiiRenderSponsorPopup;
this.getQueryString = TiiAolSponsorGetQueryString;
window.sponsorConfig = this;
}
function TiiAolSponsorGetQueryString() {
var mykeys = new Array("query", "sch", "ssch", "sclient", "spch", "snum", "of", "page", "invType", "rv", "nt");
var s = "";
for (var i = 0; i < mykeys.length; i++) {
s += "&" + mykeys[i] + "=" + escape(this[mykeys[i]]);
}
return s;
}
////// SEARCH PAGE FUNCTIONS
function TiiRenderSponsorBoxes(query) {
this.query = unescape(query);
tiiCreateSponsorDivs();
tiiGetSponsoredLinks(this);
}
// Set up callbacks and request data
function tiiGetSponsoredLinks(config) {
google_afs_hl = 'en';
google_afs_adsafe = 'high';
google_afs_oe = 'utf8';
google_afs_adtest = config.stest;
google_afs_query = config.query;
google_afs_channel = config.ssch;
google_afs_client = config.sclient;
google_afs_adpage = config.page;
google_afs_ad = "n3";
if (document.getElementById('aolSponsorBoxBottom')) {
google_afs_ad = "n7";
}
// Source in the Google AFS library
window.google_afs_request_done = tiiSponsoredLinksDone;
tiiGoogleAfs();
}
function tiiGoogleAfs() {
// Create JS Link
var url = 'http://www.google.com/afsonline/show_afs_ads.js';
var text = '';
document.write(text);
}
function tiiGetWebOffers(config) {
if (config.query != "") {
var url = 'http://weboffer.timeinc.net/WebOffers/weboffers.js?source=weboffers_api&invocationType=' + config.invType + '&query=' + escape(config.query) + '&count=4';
var text = '';
document.write(text);
}
}
function tiiSponsoredLinksDone(google_ads) {
var sl1;
var sl2;
var topDiv = document.getElementById('aolSponsoredLinksTop');
var bottomDiv = document.getElementById('aolSponsoredLinksBottom');
if(google_ads.length!=0) {
if (topDiv != null) {
sl1 = tiiRenderLinks(google_ads, 1, 3);
topDiv.appendChild(sl1);
}
if (sponsorConfig.showBottom) {
if (bottomDiv != null) {
if (google_ads.length > 3) {
sl2 = tiiRenderLinks(google_ads, 4, 4);
bottomDiv.appendChild(sl2);
} else {
document.getElementById('aolSponsorBoxBottom').style.display = "none";
}
}
}
} else {
if (topDiv != null) {
document.getElementById('aolSponsorBoxTop').style.display = "none";
}
if (bottomDiv != null) {
document.getElementById('aolSponsorBoxBottom').style.display = "none";
}
}
}
function tiiWebOffersDone(webOffers) {
var wot = document.getElementById("aolWebOffersTop");
if (wot != null) {
if (typeof webOffers == "object" && webOffers.length > 0) {
wot.appendChild(document.createTextNode("See Sponsored Links For: "));
for (var i = 0; i < webOffers.length; i++) {
var term = webOffers[i][0];
var termHtml = webOffers[i][1];
sponsorConfig.query = term;
//sponsorConfig.page = 1;
var url = tiiSponsoredPopupUrl() + "?" + sponsorConfig.getQueryString();
var a = tii_dom_createElement('a', new Array(
["href", url],
["target", "_blank"]
));
a.innerHTML = termHtml;
wot.appendChild(a);
if (i < (webOffers.length -1)) {
wot.appendChild(document.createTextNode(", "));
}
}
}
}
var wob = document.getElementById("aolWebOffersBottom");
if (wob != null) {
if (typeof webOffers == "object" && webOffers.length > 0) {
wob.appendChild(document.createTextNode("See Sponsored Links For: "));
for (var i = 0; i < webOffers.length; i++) {
var term = webOffers[i][0];
var termHtml = webOffers[i][1];
sponsorConfig.query = term;
//sponsorConfig.page = 1;
var url = tiiSponsoredPopupUrl() + "?" + sponsorConfig.getQueryString();
var a = tii_dom_createElement('a', new Array(
["href", url],
["target", "_blank"]
));
a.innerHTML = termHtml;
wob.appendChild(a);
if (i < (webOffers.length -1)) {
wob.appendChild(document.createTextNode(", "));
}
}
}
}
}
////// POPUP FUNCTIONS
function TiiRenderSponsorPopup(query) {
this.query = query;
tiiGetSponsoredPopup(this);
}
function tiiGetSponsoredPopup(config) {
google_afs_hl = 'en';
google_afs_adsafe = 'high';
google_afs_adtest = config.stest;
google_afs_query = config.query;
google_afs_channel = config.ssch;
google_afs_client = config.sclient;
google_afs_adpage = config.page;
google_afs_ad = "n10";
// Source in the Google AFS library
window.google_afs_request_done = tiiSponsoredPopupDone;
tiiGoogleAfs();
}
function tiiSponsoredPopupDone(google_ads) {
var sl;
if(google_ads.length != 0) {
window.sponsorConfig.page++;
if (typeof(__slm_nt) != "undefined") window.sponsorConfig.nt = __slm_nt;
var url = tiiSponsoredPopupUrl() + "?" + sponsorConfig.getQueryString();
sl = tiiRenderPopupLinks(google_ads, 1, 10);
document.getElementById('offers').appendChild(sl);
// Next Link
var a = document.createElement("a");
a.setAttribute("href", url);
a.innerHTML = "Next »"
document.getElementById('prevnext').appendChild(a);
} else {
document.getElementById('offers').style.visibility = "hidden";
}
}
function tiiRenderPopupLinks(sponsorData, start, count) {
var ul = tii_dom_createElement('ul', new Array());
var start = start - 1;
var end = start + count - 1;
for (var i = start; i <= end; i++) {
if (sponsorData[i]) {
var li = tii_dom_createElement('li', new Array());
var hSpan = tii_dom_createElement('span', new Array(["class", "headline"]));
var dSpan = tii_dom_createElement('span', new Array(["class", "desc"]));
var uSpan = tii_dom_createElement('span', new Array(["class", "url"]));
var a1 = tii_dom_createElement('a', new Array(["href", sponsorData[i].url]));
tii_addEventHandler(a1, "mouseover", function() {window.status='Done'; return true;}, false);
tii_addEventHandler(a1, "mouseout", function() {window.status=''; return true;}, false);
var a2 = a1.cloneNode(false);
var a3 = a1.cloneNode(false);
var br1 = tii_dom_createElement('br', new Array());
var br2 = br1.cloneNode(false);
a1.innerHTML = sponsorData[i].line1;
var desc = " " + sponsorData[i].line2 + " " + sponsorData[i].line3;
a2.innerHTML = tiiAolSponsorBoldTerm(sponsorConfig.query, desc);
a3.innerHTML = tiiSponsorDecodeURI(sponsorData[i].visible_url);
hSpan.appendChild(a1);
dSpan.appendChild(a2);
uSpan.appendChild(a3);
li.appendChild(hSpan);
li.appendChild(br1);
li.appendChild(dSpan);
li.appendChild(br2);
li.appendChild(uSpan);
ul.appendChild(li);
}
}
return ul;
}
////// SUPPORT FUNCTIONS
// Turns Sponsored Links into DLs
function tiiRenderLinks(sponsorData, start, count) {
var dl = tii_dom_createElement('dl', new Array());
var start = start - 1;
var end = start + count - 1;
for (var i = start; i <= end; i++) {
if (sponsorData[i]) {
var a1 = tii_dom_createElement('a', new Array(["href", sponsorData[i].url]));
tii_addEventHandler(a1, "mouseover", function() {window.status='Done'; return true;}, false);
tii_addEventHandler(a1, "mouseout", function() {window.status=''; return true;}, false);
var a2 = a1.cloneNode(false);
a1.innerHTML = sponsorData[i].line1;
var urlSpan = tii_dom_createElement('span', new Array(["class", "url"]));
urlSpan.appendChild(document.createTextNode(tiiSponsorDecodeURI(sponsorData[i].visible_url)));
var descSpan = tii_dom_createElement('span', new Array());
var desc = " " + sponsorData[i].line2 + " " + sponsorData[i].line3;
descSpan.innerHTML = tiiAolSponsorBoldTerm(sponsorConfig.query, desc);
a2.appendChild(urlSpan);
a2.appendChild(descSpan);
var dt = tii_dom_createElement('dt', new Array());
dt.appendChild(a1);
var dd = tii_dom_createElement('dd', new Array());
dd.appendChild(a2);
dl.appendChild(dt);
dl.appendChild(dd);
}
}
return dl;
}
// Turns Sponsored Links into DLs
function tiiRenderBottomLinks(sponsorData, start, count) {
var dl = tii_dom_createElement('dl', new Array());
var start = start - 1;
var end = start + count - 1;
for (var i = start; i <= end; i++) {
if (sponsorData[i]) {
var a1 = tii_dom_createElement('a', new Array(
["href", sponsorData[i].redirect_url],
["target", "_blank"]
));
tii_addEventHandler(a1, "mouseover", function() {window.status='Done'; return true;}, false);
tii_addEventHandler(a1, "mouseout", function() {window.status=''; return true;}, false);
var a2 = a1.cloneNode(false);
a1.innerHTML = sponsorData[i].title;
var urlSpan = tii_dom_createElement('span', new Array(
["class", "url"]
));
urlSpan.appendChild(document.createTextNode(sponsorData[i].url));
var descSpan = tii_dom_createElement('span', new Array());
var desc = " " + sponsorData[i].d1 + " " + sponsorData[i].d2;
descSpan.innerHTML = tiiAolSponsorBoldTerm(sponsorConfig.query, desc);
var br1 = tii_dom_createElement('br', new Array());
a2.appendChild(descSpan);
a2.appendChild(br1);
a2.appendChild(urlSpan);
var dt = tii_dom_createElement('dt', new Array());
dt.appendChild(a1);
var dd = tii_dom_createElement('dd', new Array());
dd.appendChild(a2);
dl.appendChild(dt);
dl.appendChild(dd);
}
}
return dl;
}
// Set up the DIVs that are to be populated by other functions on client search pages
function tiiCreateSponsorDivs() {
var sb1 = document.getElementById('aolSponsorBoxTop');
var sb2 = document.getElementById('aolSponsorBoxBottom');
var sbTitle = tii_dom_createElement('div', new Array(["class", "aolTitle"]));
var titleDiv = tii_dom_createElement('div', new Array());
titleDiv.appendChild(document.createTextNode("Sponsored Links"));
sbTitle.appendChild(titleDiv);
var sb2Title = sbTitle.cloneNode(true);
if (sb1 != null) {
var sl1 = tii_dom_createElement('div', new Array(
["id", "aolSponsoredLinksTop"],
["class", "aolSponsorLinks"]
));
var wot = tii_dom_createElement('div', new Array(
["id", "aolWebOffersTop"],
["class", "webResults"]
));
sb1.setAttribute("class", "aolSponsoredLinks");
sb1.className = "aolSponsoredLinks";
sb1.appendChild(sbTitle);
sb1.appendChild(sl1);
sb1.appendChild(wot);
}
if (sb2 != null) {
if (sponsorConfig.showBottom) {
var sl2 = tii_dom_createElement('div', new Array(
["id", "aolSponsoredLinksBottom"],
["class", "aolSponsorLinks"]
));
var wob = tii_dom_createElement('div', new Array(
["id", "aolWebOffersBottom"],
["class", "webResults"]
));
sb2.setAttribute("class", "aolSponsoredLinks");
sb2.className = "aolSponsoredLinks";
sb2.appendChild(sb2Title);
sb2.appendChild(sl2);
sb2.appendChild(wob);
}
}
}
function tiiSponsorDecodeURI(string) {
pattern = new RegExp("(.*?)", "gi");
result = string.replace(pattern,"$1");
return result;
}
function tiiAolSponsorBoldTerm(term, message) {
pattern = new RegExp("(" + term + ")", "gi");
result = message.replace(pattern, "$1");
return result;
}
function tiiWebOffersPopup(url) {
window.open(url, "weboffers", "width=640,height=640,left=8,top=8,location=no,menubar=no,resizable=no,scrolllbars=yes,status=yes,toolbar=no", false);
return false;
}
function tiiSponsoredPopupUrl() {
return "http://www.timeinc.net/shared/vgn/aol_sponsored_links/popup/1,," + params.sch + "|" + params.ssch +",00.html";
}
// ### Array Helper Functions ###
function tiiArrayContains (array, value) {
if (array != null) {
var al = array.length;
for (var i = 0; i < al; i++) {
if (array[i] == value) return true;
}
}
return false;
}
// ### Key=Value; Functions ###
function tiiHashKeys(string) {
var keys = null;
if (string != null) {
var hash = string.split(';');
var hl = hash.length - 1;
if(hl > 0){
keys = new Array();
for(var i = 0; i < hl; i++){
var data = hash[i].split('=');
keys[i] = data[0].replace(' ', '');
}
}
}
return keys;
}
function tiiHashGet(string, key) {
var value = null;
if (string != null) {
var keyStart = key + '=';
var offset = string.indexOf(keyStart);
if (offset != -1) {
offset += keyStart.length;
var end = string.indexOf(';', offset);
if (end == -1) {
end = string.length;
}
value = string.substring(offset, end);
}
}
return value;
}
function tiiHashSet(string, key, value) {
var string = tiiHashDelete(string, key);
var newValue = key + '=' + value + ';';
if (string != null) newValue = newValue + string;
return newValue;
}
function tiiHashDelete(string, key) {
var oldValue = tiiHashGet(string, key);
var newString = string;
if (oldValue != null) {
var search = key + '=';
var start = string.indexOf(search);
var offset = start + search.length;
var end = string.indexOf(';', offset) + 1;
if (end == -1) end = string.length;
newString = string.slice(0,start) + string.slice(end,string.length);
return newString;
}
return newString;
}
function tiiGetQueryParamValue(param) {
var startIndex;
var endIndex;
var valueStart;
var qs = document.location.search;
var detectIndex = qs.indexOf( "?" + param + "=" );
var detectIndex2 = qs.indexOf( "&" + param + "=" );
var key = "&" + param + "=";
var keylen = key.length;
if (qs.length > 1) {
if (detectIndex != -1) {
startIndex = detectIndex;
} else if (detectIndex2 != -1) {
startIndex = detectIndex2;
} else {
return null;
}
valueStart = startIndex + keylen;
if (qs.indexOf("&", valueStart) != -1) {
endIndex = qs.indexOf("&", startIndex + 1)
} else {
endIndex = qs.length
}
return (qs.substring(qs.indexOf("=", startIndex) + 1, endIndex));
}
return null;
}
// ### Date/Time Functions ###
function tiiDateGetOffsetMinutes(minutes) { var today = new Date(); return today.getTime() + (60000) * minutes;}
function tiiDateGetOffsetHours(hours) { var today = new Date(); return today.getTime() + (3600000) * hours; }
function tiiDateGetOffsetDays(days) { var today = new Date(); return today.getTime() + (86400000) * days; }
function tiiDateGetOffsetWeeks(weeks) { var today = new Date(); return today.getTime() + (604800000) * weeks; }
function tiiDateGetOffsetMonths(months) { var today = new Date(); return today.getTime() + (259200000) * months; }
function tiiDateGetOffsetYears(years) { var today = new Date(); return today.getTime() + (31536000000) * years; }
function tii_dom_createElement (nodeName, attributes)
{
var isopera = typeof window.opera != 'undefined';
var isie = typeof document.all != 'undefined'
&& !isopera && navigator.vendor != 'KDE';
var newElement;
try
{
newElement = document.createElement (nodeName);
}
catch (error)
{
return null;
}
var attributesLength = attributes.length;
for (var i = 0; i < attributesLength; i++)
{
var attribute = attributes [i] [0];
var value = attributes [i] [1];
newElement.setAttribute (attribute, value);
switch (attribute)
{
case 'id':
newElement.id = value;
break;
case 'class':
if (isie)
{
newElement.setAttribute ('className', value);
}
newElement.className = value;
break;
case 'style':
newElement.style.cssText = newElement.style.cssText + ' ' + value;
break;
case 'for':
if (isie)
{
newElement.setAttribute ('htmlFor', value);
}
newElement.htmlFor = value;
}
}
return newElement;
}
function tii_dom_removeWhitespaceTextNodes (node)
{
for (var x = 0; x < node.childNodes.length; x++)
{
var child = node.childNodes [x];
if (child.nodeType == 3 && !/\S/.test (child.nodeValue))
{
node.removeChild (node.childNodes [x]);
x--;
}
if (child.nodeType == 1)
{
tii_dom_removeWhitespaceTextNodes (child);
}
}
}
function tii_callFunctionOnWindowLoad (functionToCall)
{
if (typeof window.addEventListener != 'undefined')
{
window.addEventListener ('load', functionToCall, false);
}
else if (typeof document.addEventListener != 'undefined')
{
document.addEventListener ('load', functionToCall, false);
}
else if (typeof window.attachEvent != 'undefined')
{
window.attachEvent ('onload', functionToCall);
}
else
{
var oldFunctionToCall = window.onload;
if (typeof window.onload != 'function')
{
window.onload = functionToCall;
}
else
{
window.onload = function ()
{
oldFunctionToCall ();
functionToCall ();
};
}
}
}
function tii_callFunctionOnElementLoad (targetId, functionToCall)
{
var myArguments = arguments;
tii_callFunctionOnWindowLoad (function ()
{
window.loaded = true;
});
var targetElement = document.getElementById (targetId);
if (targetElement == null && !window.loaded)
{
var pollingInterval = setInterval (function ()
{
if (window.loaded)
{
clearInterval (pollingInterval);
}
targetElement = document.getElementById (targetId);
if (targetElement != null)
{
clearInterval (pollingInterval);
var argumentsTemp = new Array ();
var argumentsTempLength = myArguments.length - 2;
for (var i = 0; i < argumentsTempLength; i++)
{
argumentsTemp [i] = myArguments [i + 2];
}
functionToCall.apply (this, argumentsTemp);
}
}, 10);
}
}
function tii_addEventHandlerOnElementLoad (targetId, eventType, functionToCall, bubbleEventUpDOMTree)
{
tii_callFunctionOnWindowLoad (function ()
{
window.loaded = true;
});
var targetElement = document.getElementById (targetId);
if (targetElement == null && !window.loaded)
{
var pollingInterval = setInterval (function ()
{
if (window.loaded)
{
clearInterval (pollingInterval);
}
targetElement = document.getElementById (targetId);
if (targetElement != null)
{
clearInterval (pollingInterval);
tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree);
}
}, 10);
}
}
function tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree)
{
if (typeof targetElement.addEventListener != 'undefined')
{
targetElement.addEventListener (eventType, functionToCall, bubbleEventUpDOMTree);
}
else if (typeof targetElement.attachEvent != 'undefined')
{
targetElement.attachEvent ('on' + eventType, functionToCall);
}
else
{
eventType = 'on' + eventType;
if (typeof targetElement [eventType] == 'function')
{
var oldListener = targetElement [eventType];
targetElement [eventType] = function ()
{
oldListener ();
return functionToCall ();
}
}
else
{
targetElement [eventType] = functionToCall;
}
}
return true;
}
function tii_removeEventHandler (targetElement, eventType, functionToRemove, bubbleEventUpDOMTree)
{
if (typeof targetElement.removeEventListener != "undefined")
{
targetElement.removeEventListener (eventType, functionToRemove, bubbleEventUpDOMTree);
}
else if (typeof targetElement.detachEvent != "undefined")
{
targetElement.detachEvent ("on" + eventType, functionToRemove);
}
else
{
targetElement ["on" + eventType] = null;
}
return true;
}