var clinks = new Array(); function clshowprod(phrase) { var path = ""+document.location.pathname; var url = "http://www.tiscali.co.uk/shopping/products.php?keywords="+escape(phrase)+"&path="+escape(path); var sw = screen.width; var sh = screen.height; var x = (sw - 300)/2; var y = (sh - 250)/2; var win = window.open(url,'products','width=300,height=250,menubar=0,status=1,left='+x+',top='+y); win.focus(); } function makeoffer() { var o; o = document.createElement("IMG"); o.setAttribute("src","http://www.tiscali.co.uk/shopping/images/buy_icon.gif"); o.setAttribute("width","20"); o.setAttribute("height","11"); o.setAttribute("border","0"); o.setAttribute("align","absmiddle"); o.setAttribute("alt","Buy Now"); return o; } // Contextual links highlight. function clhl() { var path = ""+document.location.pathname; if(path == "/index.html") { return; } clignorenodes(); var els = new Array(document.body); var i; var res = ""; var buycount = 0; var maxbuys = 3; var lastTableLev = -1; while(els.length) { var obj = els[els.length-1]; var ch = obj.childNodes; els.length--; if(obj.nodeName.match(/^(A|B|OPTION|SCRIPT)$/)) { continue; } if(obj.nodeType == 3) { for (k in clinks) { var tn = obj.nodeValue; var tnlen = tn.length; var lctn = tn.toLowerCase(); var s = k.toLowerCase(); var slen = s.length; var spos = 0; var epos = lctn.indexOf(s); if(epos != -1) { var newnode = document.createElement('SPAN'); while(epos != -1) { // Check characters before and after match. var pchar = (epos > 0) ? lctn.charAt(epos-1) : ' '; var nchar = (epos+slen < tnlen) ? ""+lctn.charAt(epos+slen) : " "; if((pchar.match(/[a-z0-9\']/)) || (nchar.match(/[a-z0-9\']/))) { // This means the match was a substring. epos = lctn.indexOf(s,epos+slen); continue; } var url = clinks[k]; var buy = 0; if(url.indexOf("buy:") == 0) { url = "javascript:clshowprod('"+url.substring(4)+"');"; buy = 1; } if(buy && (buycount >= maxbuys)) { epos = lctn.indexOf(s,epos+slen); continue; } var link = document.createElement('A'); link.setAttribute('href',url); //link.className = "clbuy"; var linktext = document.createTextNode(tn.substring(epos,epos+slen)); link.appendChild(linktext); if(buy == 1) { // Offer. var offer = makeoffer(); link.appendChild(offer); buycount++; } newnode.appendChild(document.createTextNode(tn.substring(spos,epos))); newnode.appendChild(link); spos = epos+slen; epos = lctn.indexOf(s,spos); } var tmpobj = null; if(spos != lctn.length) { tmpobj = newnode.appendChild(document.createTextNode(tn.substring(spos))); } var par = obj.parentNode; if(par) { par.replaceChild(newnode,obj); if(tmpobj) { obj = tmpobj; } } } } } var len = els.length; for(i = ch.length-1;i >= 0 ;i--) { //for(i = 0;i < ch.length;i++) { if(!ch[i].ignore) { els[els.length] = ch[i]; } } } } function clcheckloaded() { if(document.getElementsByTagName) { var n = document.getElementsByTagName('*').length; if(numels == n) { clhl(); } else { numels = n; setTimeout('clcheckloaded();',1000); } } } function clignorenodes() { var els = new Array(document.body); var i; var r = ""; while(els.length) { var obj = els[els.length-1]; var ig = false; if((obj.nodeName == "INPUT") && (obj.type == "image") && obj.src.match(/(buy|vote)/)) { ig = true; } else if((obj.nodeName == "IMG") && obj.src.match(/(buy|vote)/)) { ig = true; } else if(obj.nodeValue && obj.nodeValue.match(/PRICES/)) { ig = true; } if(ig) { var t = getparenttable(obj); if(t) { t.ignore = true; } } els.length--; for(i = 0;i < obj.childNodes.length;i++) { els[els.length] = obj.childNodes[i]; } } } function getlevel(obj) { var lev = 0; var o = obj; while(o.parentNode) { lev++; o = o.parentNode; } return lev; } function getparenttable(obj) { while(obj.parentNode) { obj = obj.parentNode; if(obj.nodeName == "TABLE") { break; } } return obj; } var numels = 0; var havelinks = false; var x; for(x in clinks) { havelinks = true; break; } if(havelinks) { // Not using window.onload in case some other script uses it. setTimeout('clcheckloaded();',1000); }