
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.Utility||typeof(SAPO.Utility)=='undefined'){SAPO.namespace('Utility');}
SAPO.Utility.Dumper={_tab:'\xA0\xA0\xA0\xA0',_formatParam:function(param)
{var formated='';switch(typeof(param)){case'string':formated='(string) '+param;break;case'number':formated='(number) '+param;break;case'boolean':formated='(boolean) '+param;break;case'object':if(param!=null){if(param.constructor==Array){formated='Array \n{\n'+this._outputFormat(param,0)+'\n}';}else if(param.constructor==Object){formated='Object \n{\n'+this._outputFormat(param,0)+'\n}';}}else{formated='null';}
break;default:formated=false;}
return formated;},_getTabs:function(numberOfTabs)
{var tabs='';for(var _i=0;_i<numberOfTabs;_i++){tabs+=this._tab;}
return tabs;},_outputFormat:function(param,dim)
{var formated='';var _strVal=false;var _typeof=false;for(var key in param){if(param[key]!=null){if(typeof(param[key])=='object'&&(param[key].constructor==Array||param[key].constructor==Object)){if(param[key].constructor==Array){_typeof='Array';}else if(param[key].constructor==Object){_typeof='Object';}
formated+=this._tab+this._getTabs(dim)+'['+key+'] => <b>'+_typeof+'</b>\n';formated+=this._tab+this._getTabs(dim)+'{\n';formated+=this._outputFormat(param[key],dim+1)+this._tab+this._getTabs(dim)+'}\n';}else if(param[key].constructor==Function){continue;}else{formated=formated+this._tab+this._getTabs(dim)+'['+key+'] => '+param[key]+'\n';}}else{formated=formated+this._tab+this._getTabs(dim)+'['+key+'] => null \n';}}
return formated;},printDump:function(param,target)
{if(!target||typeof(target)=='undefined'){document.write('<pre>'+this._formatParam(param)+'</pre>');}else{if(typeof(target)=='string'){document.getElementById(target).innerHTML='<pre>'+this._formatParam(param)+'</pre>';}else if(typeof(target)=='object'){target.innerHTML='<pre>'+this._formatParam(param)+'</pre>';}else{throw"TARGET must be an element or an element ID";}}},returnDump:function(param)
{return this._formatParam(param);},alertDump:function(param)
{alert(this._formatParam(param).replace(/(<b>)(Array|Object)(<\/b>)/g,"$2"));},windowDump:function(param)
{var dumperwindow='dumperwindow_'+(Math.random()*10000);var win=window.open('',dumperwindow,'width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');win.document.open();win.document.write('<pre>'+this._formatParam(param)+'</pre>');win.document.close();win.focus();}};
if(!SAPO.Widget||typeof(SAPO.Widget)=='undefined'){SAPO.namespace('Widget');}
SAPO.Widget.Blogthis={init:function()
{var options=Object.extend({text:'Blogar texto seleccionado',altText:'Blogar o texto seleccionado',button:0,divId:false,domain:'blogs.sapo.pt'},arguments[0]||{});this.options=options;this.options.text=this.options.text.replace(/\'/g,"\&#39;");this.options.text=this.options.text.replace(/\"/g,"\&#34;");this.options.altText=this.options.altText.replace(/\'/g,"\&#39;");this.options.altText=this.options.altText.replace(/\"/g,"\&#34;");this.writeJs();},__getSelected:function()
{var texto='';if(window.getSelection){texto=window.getSelection();}else if(document.getSelection){texto=document.getSelection();}else if(document.selection){texto=document.selection.createRange().text;}
return texto;},__setText:function()
{var url=location.href;var title=document.title;var texto=this.__getSelected();texto=texto+"";texto=texto.replace(/\n/g,"<br>");texto=texto.replace(/\r/g,"<br>");texto=texto.replace(/\'/g,"\&#39;");texto=texto.replace(/\"/g,"\&#34;");document.getElementById('__selected_url__').value=url;document.getElementById('__selected_title__').value=title;if(texto!=''){document.getElementById('__selected_text__').value=texto;}else{document.getElementById('__selected_text__').value='<a href="'+url+'">'+title+'</a>';}},postText:function()
{this.__setText();document.__204ab7e6c8cf80a631a7881c0a072022__.submit();return;},__setButton:function()
{var __buttonName=false;switch(Number(parseInt(this.options.button))){case 1:__buttonName='<a href="#" id="_blogthis_id_'+this.options.button+'_" onmousedown="SAPO.Widget.Blogthis.postText(); return false;" onclick="return false;"><img border="0" src="http://js.sapo.pt/Assets/Images/Blogthis/pipiButtonBlogarPagina.png" alt="'+this.options.altText+'" title="'+this.options.altText+'" /></a>';break;case 2:__buttonName='<a href="#" id="_blogthis_id_'+this.options.button+'_" onmousedown="SAPO.Widget.Blogthis.postText(); return false;" onclick="return false;"><img border="0" src="http://js.sapo.pt/Assets/Images/Blogthis/pixelButtonBlogarIsto.gif" alt="'+this.options.altText+'" title="'+this.options.altText+'" /></a>';break;case 3:__buttonName='<a href="#" id="_blogthis_id_'+this.options.button+'_" onmousedown="SAPO.Widget.Blogthis.postText(); return false;" onclick="return false;"><img border="0" src="http://js.sapo.pt/Assets/Images/Blogthis/80X15ButtonSAPOBlogs.gif" alt="'+this.options.altText+'" title="'+this.options.altText+'" /></a>';break;default:__buttonName='<a href="#" id="_blogthis_id_0_" onmousedown="SAPO.Widget.Blogthis.postText(); return false;" onclick="return false;" title="'+this.options.altText+'">'+this.options.text+'</a>';break;}
return __buttonName;},writeJs:function()
{var __action__='http:'+'//'+this.options.domain+'/lo'+'gin.bml?u'+'rl=ht'+'tp://'+this.options.domain+'/upd'+'ate.bml';var __form__='<div style="display:none;">';__form__+='<fo'+'rm name="__204ab7e6c8cf80a631a7881c0a072022__" method="post" action="'+__action__+'" />';__form__+='<in'+'put type="text" id="__sel'+'ected_url__" name="__sele'+'cted_url__" value="" /> <br />';__form__+='<in'+'put type="text" id="__sel'+'ected_title__" name="sub'+'ject" value="" /> <br />';__form__+='<in'+'put type="text" id="__sel'+'ected_text__" name="ev'+'ent" value="" /> <br />';__form__+='<in'+'put type="text" id="outer'+'text" name="outer'+'text" value="1" /> <br />';__form__+='</fo'+'rm>';__form__+='</div>';var __button__=this.__setButton();if(typeof(document.__204ab7e6c8cf80a631a7881c0a072022__)=='undefined'){document.write(__form__);}
if(!this.options.divId){document.write(__button__);}else{if(document.getElementById(this.options.divId)){document.getElementById(this.options.divId).innerHTML=__button__;}}},debug:function()
{}};
// parse query string
var params = SAPO.Utility.Url.getQueryString(SAPO.Utility.Url.currentScriptElement().src);

// call renderer
var options={};
if(params["b"]) { options.button=params["b"]; }
if(params["t"]) { options.text=decodeURIComponent(params["t"]).replace(/^\s+|\s+$|\n/g, '').replace(/(<[^>]>|\+)/g, ' '); }
if(params["alt"]) { options.altText=decodeURIComponent(params["alt"]).replace(/^\s+|\s+$|\n/g, '').replace(/(<[^>]>|\+)/g, ' '); }
if(params["divId"]) { options.divId=params["divId"]; }
if(params["domain"]) { options.domain=params["domain"]; }

SAPO.Widget.Blogthis.init(options);

