
if(typeof(SAPO)=='undefined'){window.SAPO={};}else{window.SAPO=window.SAPO;}
SAPO.namespace=function(ns){if(!ns||!ns.length){return null;}
var levels=ns.split(".");var nsobj=SAPO;for(var i=(levels[0]=="SAPO")?1:0;i<levels.length;++i){nsobj[levels[i]]=nsobj[levels[i]]||{};nsobj=nsobj[levels[i]];}
return nsobj;};SAPO.extend=function(subclass,superclass){var f=function(){};f.prototype=superclass.prototype;subclass.prototype=new f();subclass.prototype.constructor=subclass;subclass.superclass=superclass.prototype;if(superclass.prototype.constructor==Object.prototype.constructor){superclass.prototype.constructor=superclass;}};function s$(element)
{if(arguments.length>1){for(var i=0,elements=[],length=arguments.length;i<length;i++){elements.push(s$(arguments[i]));}
return elements;}
if(typeof(element)=='string'){element=document.getElementById(element);}
return element;}
Function.prototype.createCallback=function(){var args=arguments;var method=this;return function(){return method.apply(window,args);}};Function.prototype.bindObj=function(obj,args){var method=this;return function(){return method.apply(obj,args||arguments);}};Object.extend=function(destination,source){for(var property in source){destination[property]=source[property];}
return destination;};if(typeof(SAPO.Browser)=='undefined'){SAPO.Browser={IE:false,GECKO:false,OPERA:false,SAFARI:false,KONQUEROR:false,model:false,version:false,userAgent:false,init:function()
{this.detectBrowser();this.setDimensions();this.setReferrer();},setDimensions:function()
{var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
this.windowWidth=myWidth;this.windowHeight=myHeight;},setReferrer:function()
{this.referrer=document.referrer!==undefined?document.referrer.length>0?escape(document.referrer):false:false;},detectBrowser:function()
{var sAgent=navigator.userAgent;this.userAgent=sAgent;sAgent=sAgent.toLowerCase();if((new RegExp("applewebkit\/")).test(sAgent)){this.SAFARI=true;this.model='safari';this.version=sAgent.replace(new RegExp("(.*)applewebkit\/([^\\s]+)(.*)"),"$2");}else if((new RegExp("opera")).test(sAgent)){this.OPERA=true;this.model='opera';this.version=sAgent.replace(new RegExp("(.*)opera.([^\\s$]+)(.*)"),"$2");}else if((new RegExp("konqueror")).test(sAgent)){this.KONQUEROR=true;this.model='konqueror';this.version=sAgent.replace(new RegExp("(.*)konqueror\/([^;]+);(.*)"),"$2");}else if((new RegExp("msie\ ")).test(sAgent)){this.IE=true;this.model='ie';this.version=sAgent.replace(new RegExp("(.*)\\smsie\\s([^;]+);(.*)"),"$2");}else if((new RegExp("gecko")).test(sAgent)){this.GECKO=true;var re=new RegExp("(camino|chimera|epiphany|minefield|firefox|firebird|phoenix|galeon|iceweasel|k\-meleon|seamonkey|netscape|songbird|sylera)");if(re.test(sAgent)){this.model=sAgent.match(re)[1];this.version=sAgent.replace(new RegExp("(.*)"+this.model+"\/([^;\\s$]+)(.*)"),"$2");}else{this.model='mozilla';var reVersion=new RegExp("(.*)rv\:([^\)]+)(.*)");if(reVersion.test(sAgent)){this.version=sAgent.replace(reVersion,"$2");}}}},debug:function()
{var str="known browsers: (ie, gecko, opera, safari, konqueror) \n";str+=[this.IE,this.GECKO,this.OPERA,this.SAFARI,this.KONQUEROR]+"\n";str+="model -> "+this.model+"\n";str+="version -> "+this.version+"\n";str+="\n";str+="original UA -> "+this.userAgent;alert(str);}};SAPO.Browser.init();}
SAPO.logReferer=function(classURL,options){var thisOptions={s:(typeof(options)=='object'&&options['s'])?options['s']:'js.sapo.pt',swakt:(typeof(options)=='object'&&options['swakt'])?options['swakt']:'59a97a5f-0924-3720-a62e-0c44d9ea4f16'};if(typeof(classURL)!='undefined'){var waURI='http://wa.sl.pt/wa.gif?';var aQuery=['pg='+encodeURIComponent(classURL),'swasection='+encodeURIComponent(classURL),'s='+thisOptions.s,'ref='+encodeURIComponent(location.href),'swakt='+thisOptions.swakt,'etype=libsapojs-view','swav=1','swauv=1','bcs=1','bsr=1','bul=1','bje=1','bfl=1',''];var img=new Image();img.src=waURI+aQuery.join('&');}};
SAPO.Exception=function(className)
{if(className){this.init(className);}};SAPO.Exception.prototype={init:function(className)
{try{this.uri='http://services.sapo.pt/Broker/JSExceptionLog';this.errorHandle=false;this.script=false;this.stoReq=false;this.timeoutToClear=3000;this.className=className||false;}catch(e){}},log:function(errorHandle,method)
{return;var errorObj=this.parseErrorHandle(errorHandle);var queryString='';queryString+='?type='+encodeURIComponent(errorObj.type);if(errorObj.className){if(method&&typeof(method)!='undefined'){queryString+='&class='+encodeURIComponent(errorObj.className+'->'+method);}else{queryString+='&class='+encodeURIComponent(errorObj.className);}}
if(errorObj.url){queryString+='&url='+encodeURIComponent(errorObj.url);}
if(errorObj.message){queryString+='&message='+encodeURIComponent(errorObj.message);}
if(errorObj.name){queryString+='&name='+encodeURIComponent(errorObj.name);}
if(errorObj.line){queryString+='&line='+encodeURIComponent(errorObj.line);}
if(errorObj.file){queryString+='&file='+encodeURIComponent(errorObj.file);}
if(errorObj.stack){queryString+='&stack='+encodeURIComponent(errorObj.stack);}
var uri=this.uri+queryString+'&randNum='+Math.round(1000000*Math.random());this.createScriptTag(uri);return(false);},parseErrorHandle:function(errorHandle)
{var errorObj={type:false,className:this.className||false,url:location.href,message:false,name:false,line:false,stack:false,file:false,creation:false};if(typeof(errorHandle)=='string'){errorObj.type='application';errorObj.message=errorHandle;}else if(typeof(errorHandle)=='object'){errorObj.type='library';if(typeof(errorHandle.name)!='undefined'){errorObj.name=errorHandle.name;}
if(typeof(errorHandle.message)!='undefined'){errorObj.message=errorHandle.message;}
if(typeof(errorHandle.line)!='undefined'||typeof(errorHandle.lineNumber)!='undefined'||typeof(errorHandle.number)!='undefined'){errorObj.line=errorHandle.line||errorHandle.lineNumber||errorHandle.number;}
if(typeof(errorHandle.sourceURL)!='undefined'||typeof(errorHandle.fileName)!='undefined'){errorObj.file=errorHandle.sourceURL||errorHandle.fileName;}
if(typeof(errorHandle.stack)!='undefined'){errorObj.stack=errorHandle.stack;}}
return errorObj;},createScriptTag:function(uri)
{try{this.script=document.createElement('SCRIPT');this.script.type='text/javascript';this.script.src=uri;this.script.charset='utf-8';document.getElementsByTagName('HEAD')[0].appendChild(this.script);this.callBack();}catch(e){}},removeScriptTag:function()
{if(this.script){this.script.parentNode.removeChild(this.script);this.script=null;}},callBack:function()
{this.stoReq=setTimeout(function(){this.removeScriptTag();if(this.stoReq){clearTimeout(this.stoReq);}}.bindObj(this),this.timeoutToClear);}};
if(!SAPO.Utility||typeof(SAPO.Utility)=='undefined'){SAPO.namespace('Utility');}
SAPO.Utility.Url={_keyStr:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',getUrl:function()
{var url=false;url=location.href;return url;},getQueryString:function(string)
{if(string&&typeof(string)!='undefined'){var url=string;}else{var url=this.getUrl();}
var aParams={};if(url.match(/\?(.+)/i)){var queryStr=url.replace(/^(.*)\?([^\#]+)(\#(.*))?/g,"$2");if(queryStr.length>0){var aQueryStr=queryStr.split(/[;&]/);for(var i=0;i<aQueryStr.length;i++){var pairVar=aQueryStr[i].split('=');aParams[decodeURIComponent(pairVar[0])]=(typeof(pairVar[1])!='undefined'&&pairVar[1])?decodeURIComponent(pairVar[1]):false;}}}
return aParams;},getAnchor:function(string)
{if(string&&typeof(string)!='undefined'){var url=string;}else{var url=this.getUrl();}
var anchor=false;if(url.match(/#(.+)/)){anchor=url.replace(/([^#]+)#(.*)/,"$2");}
return anchor;},getAnchorString:function(string)
{if(string&&typeof(string)!='undefined'){var url=string;}else{var url=this.getUrl();}
var aParams={};if(url.match(/#(.+)/i)){var anchorStr=url.replace(/^([^#]+)#(.*)?/g,"$2");if(anchorStr.length>0){var aAnchorStr=anchorStr.split(/[;&]/);for(var i=0;i<aAnchorStr.length;i++){var pairVar=aAnchorStr[i].split('=');aParams[decodeURIComponent(pairVar[0])]=(typeof(pairVar[1])!='undefined'&&pairVar[1])?decodeURIComponent(pairVar[1]):false;}}}
return aParams;},parseUrl:function(url)
{var aURL={};if(url&&typeof(url)!='undefined'&&typeof(url)=='string'){if(url.match(/^([^:]+):\/\//i)){var re1=new RegExp("^([^:]+)://([^/]+)/([^\\?]+)\\?([^#]+)#(.*)$","i");var re2=new RegExp("^([^:]+)://([^/]+)/([^\\?]+)\\?([^#]+)#?$","i");var re3=new RegExp("^([^:]+)://([^/]+)/([^\\?]+)\\??$","i");var re4=new RegExp("^([^:]+)://([^/]+)/?$","i");if(url.match(re1)){aURL['scheme']=url.replace(re1,"$1");aURL['host']=url.replace(re1,"$2");aURL['path']='/'+url.replace(re1,"$3");aURL['query']=url.replace(re1,"$4");aURL['fragment']=url.replace(re1,"$5");}else if(url.match(re2)){aURL['scheme']=url.replace(re2,"$1");aURL['host']=url.replace(re2,"$2");aURL['path']='/'+url.replace(re2,"$3");aURL['query']=url.replace(re2,"$4");aURL['fragment']=false;}else if(url.match(re3)){aURL['scheme']=url.replace(re3,"$1");aURL['host']=url.replace(re3,"$2");aURL['path']='/'+url.replace(re3,"$3");aURL['query']=false;aURL['fragment']=false;}else if(url.match(re4)){aURL['scheme']=url.replace(re4,"$1");aURL['host']=url.replace(re4,"$2");aURL['path']=false;aURL['query']=false;aURL['fragment']=false;}}else{var re1=new RegExp("^([^\\?]+)\\?([^#]+)#(.*)","i");var re2=new RegExp("^([^\\?]+)\\?([^#]+)#?","i");var re3=new RegExp("^([^\\?]+)\\??","i");if(url.match(re1)){aURL['scheme']=false;aURL['host']=false;aURL['path']=url.replace(re1,"$1");aURL['query']=url.replace(re1,"$2");aURL['fragment']=url.replace(re1,"$3");}else if(url.match(re2)){aURL['scheme']=false;aURL['host']=false;aURL['path']=url.replace(re2,"$1");aURL['query']=url.replace(re2,"$2");aURL['fragment']=false;}else if(url.match(re3)){aURL['scheme']=false;aURL['host']=false;aURL['path']=url.replace(re3,"$1");aURL['query']=false;aURL['fragment']=false;}}
if(aURL['host']){var regPort=new RegExp("^(.*)\\:(\\d+)$","i");if(aURL['host'].match(regPort)){var tmpHost1=aURL['host'];aURL['host']=tmpHost1.replace(regPort,"$1");aURL['port']=tmpHost1.replace(regPort,"$2");}else{aURL['port']=false;}
if(aURL['host'].match(/@/i)){var tmpHost2=aURL['host'];aURL['host']=tmpHost2.split('@')[1];var tmpUserPass=tmpHost2.split('@')[0];if(tmpUserPass.match(/\:/)){aURL['user']=tmpUserPass.split(':')[0];aURL['pass']=tmpUserPass.split(':')[1];}else{aURL['user']=tmpUserPass;aURL['pass']=false;}}}}
return aURL;},currentScriptElement:function()
{var aScripts=document.getElementsByTagName('script');if(aScripts.length>0){return aScripts[(aScripts.length-1)];}else{return false;}},base64Encode:function(string)
{if(!SAPO.Utility.String||typeof(SAPO.Utility.String)=='undefined'){throw"SAPO.Utility.Url.base64Encode depends of SAPO.Utility.String, which has not been referred.";return false;}
var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;var input=SAPO.Utility.String.utf8Encode(string);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}
output=output+
this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+
this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);}
return output;},base64Decode:function(string)
{if(!SAPO.Utility.String||typeof(SAPO.Utility.String)=='undefined'){throw"SAPO.Utility.Url.base64Decode depends of SAPO.Utility.String, which has not been referred.";return false;}
var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;var input=string.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}
if(enc4!=64){output=output+String.fromCharCode(chr3);}}
output=SAPO.Utility.String.utf8Decode(output);return output;}};
if(!SAPO.Widget||typeof(SAPO.Widget)=='undefined'){SAPO.namespace('Widget');}
SAPO.Widget.Tags=function(options)
{if(SAPO.Exception&&typeof(SAPO.Exception)!='undefined'){this.exception=new SAPO.Exception('SAPO::Widget.Tags');}else{this.exception=false;}
if(options!='undefined'){this.init(options);}else{this.init({});}};tagsShowImage=function(img){return(function(){img.style.display='inline';});};SAPO.Widget.Tags.prototype={init:function(options)
{options=Object.extend({url:false,instance:false},arguments[0]||{});this.options=options;if(this.options.instance===false){this.options.instance=Math.round(10000*Math.random());var cmd='tags'+this.options.instance+'=this';eval(cmd);}},getTagReferer:function(){var keywords='';var ref=document.referrer;if(ref&&ref!==''){var regSearchEng=new RegExp("\.google|\.sapo|\.yahoo","i");if(ref.match(regSearchEng)){var regSearch=new RegExp("(&|\\?)(q|p)=(.*?)&?","i");if(ref.match(regSearch)){var regKeywords=new RegExp("(.*)(&|\\?)(q|p)=([^&]+)?((&)?(.*)?)","ig");keywords=ref.replace(regKeywords,"$4");keywords=unescape(keywords);keywords=keywords.replace(/\+/g,' ');keywords=keywords.replace(/"/g,' ');keywords=keywords.replace(/(^\s+|\s+$|\n)/g,'');keywords=keywords.replace(/\s\s/g,' ');}}}
return keywords;},postTags:function(defaultTags,url){var obj=this.setTagVars(url);var urlTags=location.href;if(defaultTags===''){urlTags='http://'+this.options.printtagthis.baseurl+'/post?v=3&url='+encodeURIComponent(obj.url)+'&title='+encodeURIComponent(obj.title)+'&referer='+encodeURIComponent(obj.tags);}
else
{urlTags='http://'+this.options.printtagthis.baseurl+'/post?v=3&url='+encodeURIComponent(obj.url)+'&title='+encodeURIComponent(obj.title)+'&referer='+encodeURIComponent(obj.tags)+'&tags='+encodeURIComponent(defaultTags);}
location.href=urlTags;},setTagVars:function(turl)
{if(turl===''){url=location.href;}else{if(turl.match("http://")){url=turl;}else{url='http://'+turl;}}
url=url.replace(/\'/g,"%27;");url=url.replace(/\"/g,"%22");var title=document.title;title=title.replace(/\'/g,"%27");title=title.replace(/\"/g,"%22");var myvars={url:url,title:title,tags:this.getTagReferer()};return myvars;},getDefaultTags:function(jslocation){var tags='';if(jslocation){var mTags=new RegExp("(&|\\?)tags=([^&]*)($|&)","i");if(jslocation.match(mTags)){var reTags=new RegExp("(.*)(&|\\?)tags=([^&]*)&?(.*)","gm");tags=jslocation.replace(reTags,"$3");}}
return decodeURIComponent(tags).replace(/^\s+|\s+$|\n/g,'').replace(/(<[^>]>|\+)/g,' ');},printTagThis:function(options){options=Object.extend({b:3,baseurl:'links.sapo.pt',t:'Guardar esta p&aacute;gina',tags:'',url:''},arguments[0]||{});this.options.printtagthis=options;switch(parseInt(options.b,10)){case 1:buttonName='<a href="javascript:tags'+this.options.instance+'.postTags(\''+options.tags.replace(/(\'|\&\#39;)/g,"\\'")+'\',\''+options.url+'\');"><img border="0" src="http://js.sapo.pt/Assets/Images/Tags/pipi.png" alt="Guardar esta P&aacute;gina" title="Guardar esta P&aacute;gina" /></a>';break;case 2:buttonName='<a href="javascript:tags'+this.options.instance+'.postTags(\''+options.tags.replace(/(\'|\&\#39;)/g,"\\'")+'\',\''+options.url+'\');"><img border="0" src="http://js.sapo.pt/Assets/Images/Tags/pixel.gif" alt="Guardar esta P&aacute;gina" title="Guardar esta P&aacute;gina" /></a>';break;case 3:buttonName='<a href="javascript:tags'+this.options.instance+'.postTags(\''+options.tags.replace(/(\'|&#39;)/g,"\\'")+'\',\''+options.url+'\');"><img border="0" src="http://js.sapo.pt/Assets/Images/Tags/8015.gif" alt="Guardar esta P&aacute;gina" title="Guardar esta P&aacute;gina" /></a>';break;default:buttonName='<a href="javascript:tags'+this.options.instance+'.postTags(\''+options.tags.replace(/(\'|\&\#39;)/g,"\\'")+'\',\''+options.url+'\');">'+options.t+'</a>';break;}
document.write(buttonName);},newPrintBookmarks:function(feed,title,more,limit,uimg,width,cut){var html='<div class="bookmarks" style="width:'+width+'px;"><h3>'+title+'</h3><div class="bookmarkscnt">';var links=feed.rss.channel.item;for(var i=0,post;post=links[i];i++){if(uimg===1){html+='<img style="position:absolute;display:none;height:16px;width:16px;margin:0" onload="this.style.display=\'block\';" src="'+post.link.split('/').splice(0,3).join('/')+'/favicon.ico"/>';}
html+='<a style="overflow:hidden;margin-left:22px;" href="'+post.link+'">'+SAPO.Utility.String.shortString(unescape(post.title),cut)+'</a><br/>';if(i>limit)break;}
html+='<p style="float:right;"><a href="'+more+'">mais...</a>&nbsp;&nbsp;&nbsp;&nbsp;</p><div style="clear:both;"></div></div></div>';return(html);},printBookmarks:function(feed,options)
{var shortname='stags';options=Object.extend({'usefavicon':true,'faviconalign':'left','mediaiconalign':'right','divid':false,'boxclass':shortname,'maxitems':10,'width':0},arguments[1]||{});if(options.css===undefined){options.css={'.stags':{'margin':'0 0 0 0','padding':'0','background-color':'#fff'},'.stags img':{'position':'relative','border':'0px','margin':'0 5px 0 1%','display':'none'},'.stags a':{'background-color':'#fff','border-bottom-color':'#fff'}};}
if(options.boxclass===shortname){SAPO.Utility.CSS.set(options.css,options.boxclass);}
this.options.renderitems=options;var parsers=new SAPO.Widget.Parser();var items=parsers.jsonRSS2(feed);if(options.divid===false){document.write("<div class='"+options.boxclass+"' id='stags"+this.options.instance+"'></div>");divid=document.getElementById("stags"+this.options.instance);}
else
{divid=document.getElementById(options.divid);divid.className=options.boxclass;}
if(options.width!==0){divid.style.width=options.width+'px';}
if(items.length>0){list=document.createElement('ul');for(var i=0,post;(i<options.maxitems)&&(post=items[i]);i++){var bookmark=document.createElement('li');var link=document.createElement('a');link.setAttribute('href',post.link);if(post.title){if(options.usefavicon===true){var timg=document.createElement('img');timg.align=options.faviconalign;timg.height=timg.width=16;timg.src=post.link.split('/').splice(0,3).join('/')+'/favicon.ico';timg.onload=tagsShowImage(timg);bookmark.appendChild(timg);}
var taglist=post.category[0].split(' ');if(SAPO.Utility.Array.inArray('icon_audio',taglist)){var icon=document.createElement('img');icon.align=options.mediaiconalign;icon.height=icon.width=16;icon.src='http://js.sapo.pt/Assets/Images/Tags/audio.gif';bookmark.appendChild(icon);}
if(SAPO.Utility.Array.inArray('icon_video',taglist)){var icon=document.createElement('img');icon.align=options.mediaiconalign;icon.height=icon.width=16;icon.src='http://js.sapo.pt/Assets/Images/Tags/tv.gif';bookmark.appendChild(icon);}
link.appendChild(document.createTextNode(post.title));}
bookmark.appendChild(link);list.appendChild(bookmark);}
divid.appendChild(list);var br=document.createElement('br');br.setAttribute('clear','all');divid.appendChild(br);}}};
// parse query string
var params = SAPO.Utility.Url.getQueryString(SAPO.Utility.Url.currentScriptElement().src);

// call renderer
var options={};
if(params["b"]) { options.b=params["b"]; }
if(params["t"]) { options.t=decodeURIComponent(params["t"]).replace(/^\s+|\s+$|\n/g, '').replace(/(<[^>]>|\+)/g, ' '); }
if(params["tags"]) { options.tags=params["tags"]; }
if(params["url"]) { options.url=params["url"]; }
if(params["baseurl"]) { options.baseurl=params["baseurl"]; }
if(params["pop"]) { options.pop=params["pop"]; }
var tags=new SAPO.Widget.Tags();
tags.printTagThis(options);

