// declarations and definitions var overtureDataArray; var overtureError; function buildOvertureURL(overtureID, maxAdCount, isSearch) { var url = 'http://cmhtml.overture.com/d/search/p/guardian/js/uk/ctxt/'; url += '?maxCount=' + maxAdCount + '&keywordCharEnc=latin1&outputCharEnc=latin1'; var mkt; switch ('nld') { case 'gbr': mkt = 'uk'; break; case 'fr': mkt = 'fr'; break; case 'de': mkt = 'de'; break; case 'usa': case 'ca': mkt = 'us'; break; default: mkt = 'row'; } var sitename if (isSearch == 1) { sitename = 'search'; } else { sitename = 'Guardian'; } url += '&Partner=' + buildPartnerCode(mkt, sitename); url += '&mkt=' + mkt; url += '&ctxtId=' + overtureID; return url; } function buildPartnerCode(mkt, site) { // For the rest of the world we send a mkt value of 'row', but use 'uk' in the partner code if ( mkt == 'row' ) { mkt = 'uk'; } var partnerCode = 'guardian_'; partnerCode += mkt; partnerCode += '_ctxt_'; partnerCode += site.toLowerCase(); return partnerCode } // Replace the portion of the string after last space before the trimPoint with ellipses function trimAndEllipses(string, trimPoint) { if (string.length > trimPoint) { var spaceBeforeTrimPoint = string.lastIndexOf(" ", trimPoint); var trimmedString = string.substring(0, spaceBeforeTrimPoint); return trimmedString.concat("..."); } else { return string; } } // abstraction for element containing Overture results table function OvertureDocument() { // properties this.htmlText = new String(); if(overtureIsIECompatible) { // writing to iframe this.document = parent.document; } else if(overtureIsDOM) { // will be in iframe at this point this.document = parent.document; } else { // will be in main body this.document = document; } // methods this.inspect = function() { alert(this.htmlText); }; this.writeln = function(text) { this.htmlText += text + '\n'; }; this.write = function(text) { this.htmlText += text; }; this.flush = function(isSearch) { parent.setOvertureContent(this.htmlText, isSearch); this.htmlText = ''; }; this.getElementById = function(name) { if(overtureIsDOM) { return this.document.getElementById(name); } else { if(overtureIsIECompatible) { return this.document.all[name]; } else { return eval('this.document.'+name); } } }; } var overtureDocument = new OvertureDocument(); // // OvertureData // // The following function is used for the old drop-down display method, no longer used // render the text of overture result function overtureDataRenderFunction(mouseOverId) { overtureDocument.write(''); if(overtureCanDoMouseovers) overtureDocument.write('
'); if(overtureIsNetscape4Compatible) { // Netscape et al. overtureDocument.write(this.title+'
'+this.trimmedHost+''); } else { overtureDocument.write(this.title+'
'+this.trimmedHost+''); } if(overtureCanDoMouseovers) { overtureDocument.write('
'); overtureDocument.write(''); } overtureDocument.write('
'); return 0; } // OvertureData constructor function OvertureData(title, description, siteHost, clickURL) { this.title = title; this.description = description; this.siteHost = siteHost; this.clickURL = clickURL; if (this.siteHost.indexOf('www.') == 0) { this.trimmedHost = this.siteHost.substring(4); } else { this.trimmedHost = this.siteHost; } // Trim overly long descriptions this.description = trimAndEllipses(this.description, 60); // Methods this.renderData = overtureDataRenderFunction; return 0; } // // OvertureError // function overtureErrorRenderFunction() { overtureDocument.writeln(''); return 0; } // Overture Error constructor function OvertureError(errorMessage) { this.errorMessage = errorMessage; // methods this.renderData = overtureErrorRenderFunction; return 0; } // // functions // // this function is called by the code generated by the Overture CGI function renderOvertureDataArray(overtureDataArray, isSearch, displayMode) { switch(displayMode) { case 'dropdown' : // CSS for other browsers // unfortunately IE 5 doesn't do the right things with table cellpadding in CSS... overtureDocument.writeln(''); overtureDocument.writeln(''); var mouseOverId; for (var i=0;i < overtureDataArray.length;i++) { var data = overtureDataArray[i]; overtureDocument.writeln(''); overtureDocument.writeln(''); overtureDocument.write(''); overtureDocument.writeln(''); if(i < overtureDataArray.length-1) { overtureDocument.writeln(''); } } overtureDocument.writeln('
Advertiser links
'); mouseOverId = 'overtureResult' + i; data.renderData(mouseOverId); overtureDocument.writeln('
'); break; case 'trail': if (overtureDataArray.length > 1) { overtureDocument.writeln('

Advertiser links

'); // Start index at 0 instead of 1, as slot 0 always contains an Overture 'house ad', which we don't display for (var i=1; i < overtureDataArray.length; i++) { var data = overtureDataArray[i]; overtureDocument.writeln('

' + data.title + '

'); overtureDocument.writeln('

' + data.description + '

'); overtureDocument.writeln('' + data.trimmedHost + ''); } overtureDocument.writeln(''); } break; } return 0; } function createOvertureDataArray (originalArray) { var newArray = new Array(); var counter = 0; var title = ''; var description = ''; var siteHost = ''; var clickURL = ''; for (i in originalArray) { switch (counter) { case 0: description = originalArray[i]; break; case 2: clickURL = originalArray[i]; break; case 3: title = originalArray[i]; break; case 4: siteHost = originalArray[i]; break; case 5: var overtureObj = new OvertureData(title, description, siteHost, clickURL); newArray[newArray.length] = overtureObj; counter = -1; } counter++; } return newArray; } function overtureMouseOver(name) { if(overtureCanDoMouseovers) { overtureShow(name); if(overtureIsBadIEVersion) overtureResize(name,true); } return 0; } function overtureMouseOut(name) { if(overtureCanDoMouseovers) { overtureHide(name); if(overtureIsBadIEVersion) overtureResize(name,false); } return 0; } // called by iframe to set content of overture div var overtureText; function setOvertureContent(text, isSearch) { // Don't bother doing anything if there's no content to set if (text != '') { overtureText = text; if(overtureIsBadIEVersion) { window.setTimeout('setOvertureContent2(' + isSearch + ')',500); } else { setOvertureContent2(isSearch); } } } function setOvertureContent2(isSearch) { var obj = overtureGetElementById('OvertureDiv'); var hldobj = overtureGetElementById('OvertureDivHolder'); // Rendering after the event in Mac IE causes problems, so don't! if (!overtureIsMacIEVersion) { obj.innerHTML = overtureText; hldobj.style.display = 'block'; hldobj.style.visibility = 'visible'; } } function overtureFindPosY(obj) { var curtop = 0; if (document.getElementById || document.all) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (document.layers) curtop += obj.y; return curtop; } // fix-up for IE 5.x's inability to have elements overlap frames var overtureOriginalHeight = 0; function overtureResize(name,expand) { var x = document.getElementById('overture'); var y = document.getElementById(name); if(expand) { overtureOriginalHeight = x.offsetHeight; var xoff = overtureFindPosY(x); var yoff = overtureFindPosY(y); var diff = (yoff+y.offsetHeight) - (xoff+x.offsetHeight); if(diff > 0) { x.style.height = (x.offsetHeight + diff) + 'px'; } } else { x.style.height = overtureOriginalHeight + 'px'; } } // render iframe and script tags for creation of Overture box function renderOvertureBox(overtureID, isSearch, displayMode, maxAdCount) { if( !overtureIsFatalOperaVersion && !overtureIsFatalMacIEVersion && !overtureIsNetscape4Compatible) { document.writeln('
'); // Use explicit host in CURL as we're calling this from other domains (e.g. search) than where this file lives var iframeSrc = "http://www.guardian.co.uk/external/overture/iframe/0,14478,,00.html?overtureID=" + overtureID + "&displayMode=" + displayMode + '&maxAdCount=' + maxAdCount + '&isSearch=' + isSearch; document.writeln(''); } return 0; } var overtureIsNetscape4Compatible = (document.layers ? 1 : 0) == 1; var overtureIsNetscape4 = overtureIsNetscape4Compatible && (navigator.userAgent.indexOf('Mozilla/4.') != -1) && (navigator.userAgent.indexOf('OmniWeb/4.') == -1); var overtureIsIECompatible = (document.all ? 1 : 0) == 1; var overtureIsBadIEVersion = overtureIsIECompatible && (navigator.userAgent.indexOf('MSIE 5') != -1); var overtureIsMacIEVersion = overtureIsIECompatible && (navigator.platform.indexOf('Mac') != -1) && (navigator.userAgent.indexOf('MSIE 5') != -1) ; var overtureIsFatalMacIEVersion = overtureIsIECompatible && (navigator.platform.indexOf('Mac') != -1) && ((navigator.userAgent.indexOf('MSIE 4.5') != -1)); var overtureIsFatalOperaVersion = (navigator.userAgent.indexOf('Opera') != -1); var overtureIsDOM = !overtureIsIECompatible && (document.getElementById ? 1 : 0) == 1; var overtureCanDoMouseovers = 0; var overtureIsBadMacIEVersion = false; if(overtureIsBadMacIEVersion) { // render simple version without rollovers overtureIsIECompatible = false; overtureIsNetscape4Compatible = true; } if (overtureIsDOM) { // use W3C DOM standards (or at least as much as is needed) overtureGetElementById = function(name) { return document.getElementById(name); } } else { if(overtureIsIECompatible) { // use Microsoft IE 5 'standards' overtureGetElementById = function(name) { return document.all[name]; } } else { if(overtureIsNetscape4Compatible) { overtureGetElementById = function(name) { return eval('document.'+name); } } } } if (overtureIsDOM || overtureIsIECompatible) { overtureHide = function(name) { overtureGetElementById(name).style.visibility = 'hidden'; } overtureShow = function(name) { overtureGetElementById(name).style.visibility = 'visible'; } overtureCanDoMouseovers = 1; } if(!overtureIsDOM && !overtureIsIECompatible) { // dummy functions for dummy browsers overtureHide = function(name) {return 0;} overtureShow = function(name) {return 0;} overtureGetElementById = function(name) {return 0;} overtureCanDoMouseovers = 0; }