var 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;};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.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.Communication||SAPO.Communication=='undefined'){SAPO.namespace('Communication');}
SAPO.Communication.Syndication=function(url,options)
{if(SAPO.Exception&&typeof(SAPO.Exception)!='undefined'){this.exception=new SAPO.Exception('SAPO::Communication.Syndication');}else{this.exception=false;}
this.init(url,options);};SAPO.Communication.Syndication.prototype={init:function(url)
{this.feeds=[];if(url&&typeof(url)!='undefined'&&url!=null){var id=this.push(url,arguments[1]||{});if(id!==false&&typeof(id)!='undefined'){this.run(id);}}
this._doDebug=false;},push:function(url)
{if(!url||typeof(url)=='undefined'){if(this.exception){this.exception.log('Missed URL');}
throw"Missed URL in SAPO.Communication.Syndication";return false;}
try{var options=Object.extend({objectName:false,onComplete:false,onLoading:false,onTimeout:false,onExit:false,timeout:10,optOnComplete:false,optOnLoading:false,optOnTimeout:false,optOnExit:false,charset:'utf-8'},arguments[1]||{});this.feeds.push({});this.onStart=false;this.onEnd=false;var id=this.feeds.length-1;this.feeds[id].u=url;this.feeds[id].onComplete=options.onComplete;this.feeds[id].onLoading=options.onLoading;this.feeds[id].onTimeout=options.onTimeout;this.feeds[id].onExit=options.onExit;if(options.objectName){this.feeds[id].obj=options.objectName;}else{if(typeof(SAPO.Utility)!='undefined'&&typeof(SAPO.Utility.Crypto)!='undefined'){this.feeds[id].obj='json'+SAPO.Utility.Crypto.md5(this.feeds[id].u);}else{this.feeds[id].obj='json'+Math.round(1000000*Math.random());}}
this.feeds[id].urlJSON=false;this.feeds[id].urlImage=false;this.feeds[id].req=0;this.feeds[id].limitReq=parseInt((options.timeout*1000)/100);this.feeds[id].stoReq=false;this.feeds[id].charset=options.charset;this.feeds[id].optionsOnLoading=options.optOnLoading||false;this.feeds[id].optionsOnComplete=options.optOnComplete||false;this.feeds[id].optionsOnTimeout=options.optOnTimeout||false;this.feeds[id].optionsOnExit=options.optOnExit||false;return id;}catch(e){if(this.exception){this.exception.log(e,'push');}}
return false;},run:function(id)
{if(id!==false&&typeof(id)!='undefined'){try{if(this.feeds[id].onLoading){if(this.feeds[id].optionsOnLoading){this.feeds[id].onLoading(this.feeds[id].optionsOnLoading);}else{this.feeds[id].onLoading();}}
this._setUrl(id);this._createScriptTag(id);}catch(e){this.exception.log(e,'run (ID: '+id+')');}}},runAll:function()
{if(this.feeds.length>0){this.onStart=arguments[0]||false;if(this.onStart){this.onStart();}
var argToOnEnd=arguments[1]||false;this.iter=0;this.setInter=setInterval(function(arguments){this.run(this.iter);if(this.iter===(this.feeds.length-1)){this.onEnd=argToOnEnd;}
this.iter++;if(this.iter==this.feeds.length){clearInterval(this.setInter);}}.bindObj(this),300);}},remove:function(id)
{if(typeof(this.feeds[id])!='undefined'&&this.feeds[id]!=null){try{this.feeds[id]=null;}catch(e){this.exception.log(e,'delete (ID: '+id+')');}}},removeAll:function()
{if(this.feeds.length>0){for(var i=0;i<this.feeds.length;i++){this.remove(i);}}},destroy:function()
{for(var i in this){this[i]=null;}},_setUrl:function(id)
{var re=new RegExp("\\?(.+)");if(re.test(this.feeds[id].u)){this.feeds[id].urlJSON=this.feeds[id].u+'&jsonTag='+this.feeds[id].obj;}else{this.feeds[id].urlJSON=this.feeds[id].u+'?jsonTag='+this.feeds[id].obj;}},_createScriptTag:function(id)
{try{this.feeds[id].script=document.createElement('SCRIPT');this.feeds[id].script.type='text/javascript';this.feeds[id].script.src=this.feeds[id].urlJSON;this.feeds[id].script.charset=this.feeds[id].charset;document.getElementsByTagName('HEAD')[0].appendChild(this.feeds[id].script);this._callBack(id);}catch(e){if(this.exception){this.exception.log(e,'_createScriptTag');}}},_callBack:function(id)
{try{if(this.feeds[id].req<this.feeds[id].limitReq){if(this.feeds[id].onComplete){if(this.feeds[id].optionsOnComplete){this.feeds[id].onComplete(eval(this.feeds[id].obj),this.feeds[id].optionsOnComplete);this._removeScript(id);}else{this.feeds[id].onComplete(eval(this.feeds[id].obj));this._removeScript(id);}}
if(this.feeds[id].onExit){if(this.feeds[id].optionsOnExit){this.feeds[id].onExit(this.feeds[id].optionsOnExit);}else{this.feeds[id].onExit();}}
if(this.onEnd&&id==(this.feeds.length-1)){this.onEnd();}}else{throw"Time out ";}}catch(e){if(this.feeds[id].req<this.feeds[id].limitReq){if(this.feeds[id].stoReq){clearTimeout(this.feeds[id].stoReq);}
this.feeds[id].req++;this.feeds[id].stoReq=setTimeout(function(){this._callBack(id);}.bindObj(this),100);}else{if(this.exception){this.exception.log(e+' - URI: '+this.feeds[id].urlJSON,'_callBack');}
if(this.feeds[id].onTimeout){if(this.feeds[id].optionsOnTimeout){this.feeds[id].onTimeout(this.feeds[id].optionsOnTimeout);}else{this.feeds[id].onTimeout();}}
this._removeScript(id);if(this.feeds[id].onExit){if(this.feeds[id].optionsOnExit){this.feeds[id].onExit(this.feeds[id].optionsOnExit);}else{this.feeds[id].onExit();}}}}},_removeScript:function(id)
{try{if(this.feeds[id].script.parentNode&&typeof(this.feeds[id].script.parentNode)!='undefined'){this.feeds[id].script.parentNode.removeChild(this.feeds[id].script);}}catch(e){if(this.exception){this.exception.log(e,'_removeScript');}}},_debug:function(txt)
{if(this._doDebug){document.getElementById('debug').innerHTML+=txt+'<br/>';}}};
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.String={_chars:['&','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<','>','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾'],_entities:['amp','agrave','aacute','acirc','atilde','auml','aring','aelig','ccedil','egrave','eacute','ecirc','euml','igrave','iacute','icirc','iuml','eth','ntilde','ograve','oacute','ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc','uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc','Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute','Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde','Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave','Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig','lt','gt','cent','pound','curren','yen','brvbar','sect','uml','copy','ordf','laquo','not','shy','reg','macr','deg','plusmn','sup2','sup3','acute','micro','para','middot','cedil','sup1','ordm','raquo','frac14','frac12','frac34'],_accentedChars:['à','á','â','ã','ä','å','è','é','ê','ë','ì','í','î','ï','ò','ó','ô','õ','ö','ù','ú','û','ü','ç','ñ','À','Á','Â','Ã','Ä','Å','È','É','Ê','Ë','Ì','Í','Î','Ï','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ç','Ñ'],_accentedRemovedChars:['a','a','a','a','a','a','e','e','e','e','i','i','i','i','o','o','o','o','o','u','u','u','u','c','n','A','A','A','A','A','A','E','E','E','E','I','I','I','I','O','O','O','O','O','U','U','U','U','C','N'],ucFirst:function(string)
{var aStr=string.split(" ");var newStr='';var w1=false;var w2=false;var re=new RegExp("^(.)(.*)");if(aStr.length>0){for(var i=0;i<aStr.length;i++){if(aStr[i].length>2){aStr[i]=this.trim(aStr[i].toLowerCase());w1=aStr[i].replace(re,"$1");w2=aStr[i].replace(re,"$2");newStr+=w1.toUpperCase()+w2;if(i!=(aStr.length-1)){newStr+=' ';}}else{newStr+=aStr[i]+' ';}}}
return newStr;},trim:function(string)
{if(typeof(string)=='string'){return string.replace(/^\s+|\s+$|\n+$/g,'');}},stripTags:function(string,allowed)
{if(allowed&&typeof(allowed)!='undefined'){var aAllowed=this.trim(allowed).split(',');var aNewAllowed=[];var cleanedTag=false;for(var i=0;i<aAllowed.length;i++){if(this.trim(aAllowed[i])!=''){cleanedTag=this.trim(aAllowed[i].replace(/(\<|\>)/g,'').replace(/\s/,''));aNewAllowed.push('(<'+cleanedTag+'\\s[^>]+>|<(\\s|\\/)?(\\s|\\/)?'+cleanedTag+'>)');}}
var strAllowed=aNewAllowed.join('|');var reAllowed=new RegExp(strAllowed,"i");var aFoundTags=string.match(new RegExp("<[^>]*>","g"));for(var j=0;j<aFoundTags.length;j++){if(!aFoundTags[j].match(reAllowed)){string=string.replace((new RegExp(aFoundTags[j],"gm")),'');}}
return string;}else{return string.replace(/\<[^\>]+\>/g,'');}},htmlEntitiesEncode:function(string)
{var newString=string;var re=false;for(var i=0;i<this._chars.length;i++){re=new RegExp(this._chars[i],"gm");newString=newString.replace(re,'&'+this._entities[i]+';');}
return newString;},htmlEntitiesDecode:function(string)
{var newString=string;var re=false;for(var i=0;i<this._entities.length;i++){re=new RegExp("&"+this._entities[i]+";","gm");newString=newString.replace(re,this._chars[i]);}
return newString;},utf8Encode:function(string)
{string=string.replace(/\r\n/g,"\n");var utfstring="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utfstring+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utfstring+=String.fromCharCode((c>>6)|192);utfstring+=String.fromCharCode((c&63)|128);}
else{utfstring+=String.fromCharCode((c>>12)|224);utfstring+=String.fromCharCode(((c>>6)&63)|128);utfstring+=String.fromCharCode((c&63)|128);}}
return utfstring;},shortString:function(str,n){var words=str.split(' ');var resultstr='';for(var i=0;i<words.length;i++){if((resultstr+words[i]+' ').length>=n){resultstr+='&hellip;';break;}
resultstr+=words[i]+' ';}
return resultstr;},utf8Decode:function(utfstring)
{var string="";var i=0;var c=c1=c2=0;while(i<utfstring.length){c=utfstring.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utfstring.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utfstring.charCodeAt(i+1);c3=utfstring.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;},removeAccentedChars:function(string)
{var newString=string;var re=false;for(var i=0;i<this._accentedChars.length;i++){re=new RegExp(this._accentedChars[i],"gm");newString=newString.replace(re,''+this._accentedRemovedChars[i]+'');}
return newString;},debug:function(){}};
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=200,height=100,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.Utility||typeof(SAPO.Utility)=='undefined'){SAPO.namespace('Utility');}
SAPO.Utility.CSS={set:function(cssjson,jsonid,prefix)
{if(jsonid===undefined){jsonid='sapojson';}
else
{jsonid='sapojson'+jsonid;}
if(prefix===undefined){prefix='';}
else
{prefix="."+prefix+" ";}
var styleStr="";for(i in cssjson){styleStr+=prefix+i+" {\n";for(var j in cssjson[i]){if(j=="CSSJSON-INHERIT-SELECTOR"){for(var k in cssjson[cssjson[i][j]]){styleStr+="\t"+k+":"+cssjson[cssjson[i][j]][k]+";\n";}}else{styleStr+="\t"+j+":"+cssjson[i][j]+";\n";}}
styleStr+="}\n";}
if(styleStr.length>0){var head=document.getElementsByTagName('head');if(head.length>0){var last=document.getElementById(jsonid);if(last){last.parentNode.removeChild(last);}
var styleid=document.createElement('style');styleid.setAttribute('type','text/css');styleid.setAttribute('id',jsonid);if(styleid.styleSheet){styleid.styleSheet.cssText=styleStr;}else{styleid.appendChild(document.createTextNode(styleStr));}
head[0].appendChild(styleid);}}},debug:function()
{}};
if(!SAPO.Widget||typeof(SAPO.Widget)=='undefined'){SAPO.namespace('Widget');}
SAPO.Widget.Meteo=function(options)
{if(SAPO.Exception&&typeof(SAPO.Exception)!='undefined'){this.exception=new SAPO.Exception('SAPO::Widget.Meteo');}else{this.exception=false;}
if(options!='undefined'){this.init(options);}else{this.init({});}};SAPO.Widget.Meteo.prototype={init:function(options)
{this.classshortname='hw';options=Object.extend({instance:false},arguments[0]||{});this.options=options;if(this.options.instance===false){this.options.instance=Math.round(10000*Math.random());var cmd=this.classshortname+this.options.instance+'=this';eval(cmd);}},printForecast:function(feed)
{try{var shortname='sweather';var options=Object.extend({divid:false,boxclass:shortname,showactual:true,breakforecast:true,forecastdays:3,todaywidth:120,todayheight:105,forecastwidth:60,forecastheight:53,iconpath:'http://js.sapo.pt/Assets/Images/Meteo/',iconext:'.png',instance:Math.round(10000*Math.random())},arguments[1]||{});if(options.css===undefined){options.css={'':{'font-family':'Arial,Helvetica,Sans-serif'}};}
if(options.boxclass===shortname){SAPO.Utility.CSS.set(options.css,shortname,options.boxclass);}
this.options.printforecast=options;if(options.divid===false){document.write("<div class='"+options.boxclass+"' id='"+shortname+options.instance+"'></div>");var divid=document.getElementById(shortname+options.instance);}
else
{var divid=s$(options.divid);divid.className=options.boxclass;}
var weather=feed.GetWeatherForecastResponse.GetWeatherForecastResult;var today=weather.CurrentWeather;var container=document.createElement('div');container.className='weatherNow';var name=document.createElement('h1');var icon=document.createElement('div');icon.className='image';if(SAPO.Browser.IE===true&&SAPO.Browser.version==='6.0'){icon.style.width=options.todaywidth+'px';icon.style.height=options.todayheight+'px';icon.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+options.iconpath+today.WeatherCode+options.iconext+'\', sizingMethod=\'scale\')';}
else
{icon.innerHTML='<img width="'+options.todaywidth+'" height="'+options.todayheight+'" src="'+options.iconpath+today.WeatherCode+options.iconext+'">';}
var temp=document.createElement('div');temp.className='temp';var max=document.createElement('p');max.setAttribute('title',SAPO.Utility.String.htmlEntitiesDecode('Temperatura m&aacute;xima'));max.className='max';max.innerHTML=weather.Days.Day[0].High+'&deg;';var min=document.createElement('p');min.setAttribute('title',SAPO.Utility.String.htmlEntitiesDecode('Temperatura m&iacute;nima'));min.className='min';min.innerHTML=weather.Days.Day[0].Low+'&deg;';temp.appendChild(max);temp.appendChild(min);container.appendChild(name);container.appendChild(icon);container.appendChild(temp);var atemp=document.createElement('div');atemp.className='actualtemp';var actual=document.createElement('p');container.appendChild(atemp);divid.appendChild(container);wbr=document.createElement('br');if(options.breakforecast===true){wbr.setAttribute('clear','all');}
divid.appendChild(wbr);var day=false;if(weather.Days){for(var i=1,day;(i<(1+options.forecastdays))&&(day=weather.Days.Day[i]);i++){if(weather.Days.Day[i]!=null){day=weather.Days.Day[i];var container=document.createElement('div');container.className='weatherItem';var name=document.createElement('h1');name.innerHTML=day.Name.replace(/\*/,"&ordf;");var icon=document.createElement('div');icon.className='image';if(SAPO.Browser.IE===true&&SAPO.Browser.version==='6.0'){icon.style.width=options.forecastwidth+'px';icon.style.height=options.forecastheight+'px';icon.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+options.iconpath+day.WeatherCode+options.iconext+'\', sizingMethod=\'scale\')';}
else
{icon.innerHTML='<img width="'+options.forecastwidth+'" height="'+options.forecastheight+'" src="'+options.iconpath+day.WeatherCode+options.iconext+'">';}
var temp=document.createElement('div');temp.className='temp';var max=document.createElement('p');max.setAttribute('title',SAPO.Utility.String.htmlEntitiesDecode('Temperatura m&aacute;xima'));max.className='max';max.innerHTML=day.High+'&deg;';var min=document.createElement('p');min.setAttribute('title',SAPO.Utility.String.htmlEntitiesDecode('Temperatura m&iacute;nima'));min.className='min';min.innerHTML=day.Low+'&deg;';temp.appendChild(min);temp.appendChild(max);container.appendChild(name);container.appendChild(icon);container.appendChild(temp);divid.appendChild(container);}}}
return(true);}catch(e){return(this.exception.log(e));}}};
function runSnippet() {
  var params = SAPO.Utility.Url.getQueryString(SAPO.Utility.Url.currentScriptElement().src);
  params = Object.extend({c: "LPAV", w: 230, f: "left", sa: true, fd: 3, bg: "#F1F1F1" }, params || {});
  var css={
    '': {
       'background-color': params["bg"],
       'color':'#000000',
       'font-size':'9px',
       'font-family':'Arial, Helvetica, sans-serif'
       },
    'h1': {
       'margin':'0',
       'font-weight':'normal',
       'cursor':'normal'
       },
    'h2': {
       'margin':'0',
       'font-weight':'normal',
       'text-align':'center',
       'font-size':'13px',
       'cursor':'normal'
       },
    'p': {
       'margin':'0',
       'font-weight':'normal',
       'cursor':'normal'
       },
    '.weatherNow': {
       'background-color': params["bg"],
       'margin':'10px auto -10px auto'
       },
    '.weatherNow .image': {
       'float':'left',
       'margin':'0'
       },
    '.weatherNow .image img': {
       'background-color': params["bg"],
       'color':'#000000',
       'width':'100px',
       'height':'80px',
       'border':'0',
       'margin':'0 auto',
       'float':'none'
       },
    '.weatherNow .temp': {
       'background':'url(http://js.sapo.pt/Assets/Images/Meteo/tempIcon.gif) no-repeat left 2px',
       'width':'32px',
       'height':'20px',
       'float':'left',
       'margin':'0 0 0 9px'
       },
    '.weatherNow .temp p': {
       'text-align':'left',
       'clear':'right',
       'margin':'0 0 2px 22px'
       },
     '.weatherNow .temp p.max': {
       'font-size':'12px'
       },
     '.weatherNow .temp p.min': {
       'font-size':'10px'
       },
     '.weatherNow .actualtemp': {
       'margin-top':'-2px'
       },
     '.weatherNow .actualtemp p': {
       'font-size':'12px',
	   'margin-right':'12px',
       'margin':'0'
       },
     '.weatherNow h1': {
       'float':'right',
       'font-size':'16px',
       'margin':'14px 0 0 0',
       'text-align':'left',
       'width':'70px'
       },
     '.weatherItem': {
       'background-color':params["bg"],
       'color':'#000000',
       'margin':'0 auto',
       'padding':'0',
       'width':'60px',
       'float':'left',
       'color':'#333'
       },
     '.weatherItem h1': {
       'padding-left':'8px',
       'text-align':'left',
       'font-size':'10px',
       'height':'14px',
       'overflow':'hidden'
       },
     '.weatherItem .image': {
       'background-color':params["bg"],
       'color':'#000000',
       'width':'100%',
       'margin':'auto',
       'float':'none'
       },
     '.weatherItem .image img': {
       'background-color':params["bg"],
       'color':'#000000',
       'border':'0',
       'width':'54px',
       'height':'48px',
       'margin':'0 auto',
       'float':'none'
       },
     '.weatherItem .temp': {
       'margin':'-5px auto 0 auto',
        'text-align':'center',
       'clear':'both'
       },
     '.weatherItem .temp p': {
        'font-size':'12px',
        'cursor':'default',
        'display':'inline',
        'padding':'0 0 0 2px',
        'margin':'0'
        },
     '.weatherItem .temp p.min': {
        'margin-right':'2px',
       'font-size':'10px'
        },
     '.weatherItem .temp p.max': {
       'font-size':'12px'
        }
    };
  var i=Math.round(10000*Math.random());
  document.write('<div style="text-align:center;float:'+params["f"]+';width:'+params["w"]+'px;">');
  document.write('<div id="spot'+i+'" style="float:'+params["f"]+';width:'+params["w"]+'px;"></div>');
  if(params["f"]==='none') { document.write('<br clear="all"/>'); }
  document.write('<br/>');
  document.write('<a style="font-weight:normal;font-style:normal;font-family:Arial, Helvetica, sans-serif;font-size:9px;color:#000000;" href="http://tempo.sapo.pt"></a>');
  document.write('</div>');
  var feed="http://services.sl.pt/WeatherJSON/GetWeatherForecast?cityCode="+params["c"];
  var p = new SAPO.Communication.Syndication();
  var ppid=p.push(feed,{onComplete: function(obj){var meteo=new SAPO.Widget.Meteo();meteo.printForecast(obj,{showactual: params["sa"], forecastdays: parseInt(params["fd"]), divid: "spot"+i, css: css});}});
  p.run(ppid);
  }
runSnippet(); // this helps avoiding concurrency problems
