
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(){if(arguments.length<2&&arguments[0]===undefined){return this;}
var __method=this;var args=[];for(var i=0,total=arguments.length;i<total;i++){args.push(arguments[i]);}
var object=args.shift();return function(){return __method.apply(object,args.concat(function(tmpArgs){var args2=[];for(var j=0,total=tmpArgs.length;j<total;j++){args2.push(tmpArgs[j]);}
return args2;}(arguments)));}};Function.prototype.bindObjEvent=function(){var __method=this;var args=[];for(var i=0;i<arguments.length;i++){args.push(arguments[i]);}
var object=args.shift();return function(event){return __method.apply(object,[event||window.event].concat(args));}};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;}};
function showImage(img){return(function(){img.style.display='inline';});}
if(!SAPO.Widget||typeof(SAPO.Widget)=='undefined'){SAPO.namespace('Widget');}
SAPO.Widget.Search=function(options)
{if(SAPO.Exception&&typeof(SAPO.Exception)!='undefined'){this.exception=new SAPO.Exception('SAPO::Widget.Search');}else{this.exception=false;}
if(options!='undefined'){this.init(options);}else{this.init({});}};SAPO.Widget.Search.prototype={init:function(options)
{var months={1:'Janeiro',2:'Fevereiro',3:'Mar&ccedil;o',4:'Abril',5:'Maio',6:'Junho',7:'Julho',7:'Agosto',9:'Setembro',10:'Outubro',11:'Novembro',12:'Dezembro'};options=Object.extend({inputtip:'intr.termos',width:180,new_win:false,selfrender:false,domain:document.location.host,sitename:false,instance:false},arguments[0]||{});if(options.sitename===false){options.sitename=options.domain;}
try{this.months=months;this.options=options;}catch(e){if(this.exception){this.exception.log(e);}}
if(options.instance===false){this.instance=Math.round(10000*Math.random());var cmd='search'+this.instance+'=this';eval(cmd);}
if(this.options.selfrender===true){cmd='search'+this.instance+'.renderSearch()';eval(cmd);}},renderSearch:function(){var html='<div style="font-family: Helvetica, Arial, sans-serif !important;font-size: 10pt !important; border-style: none !important; color: #000 !important;width: '+this.options.width+'px">';html+='<a href="http://pesquisa.sapo.pt/"><img src="http://js.sapo.pt/Assets/Images/Search/smalllogo.png" style="width:100px;border:0;height:19px;margin-bottom:2px !important" alt="Pesquisa SAPO"/></a>';html+='<form id="form'+this.instance+'" accept-charset="utf-8" action="http://pesquisa.sapo.pt/search" onsubmit="search'+this.instance+'.startSearch();return false;">';html+='<fieldset style="border-style: none !important;margin: 0px !important;padding: 0px !important">';html+='<input type="text" name="qq" id="id_q" accesskey="p" style="font-family:Helvetica, Arial, sans-serif !important;font-size: 10pt !important;color: #c0c0c0;width: '+(this.options.width-90)+'px" onfocus="this.value=\'\';this.style.color=\'black\';" value="'+this.options.inputtip+'"/>';html+='<input type="button" value="Pesquisar" class="submit" style="font-family: Helvetica, Arial, sans-serif !important;font-size: 10pt !important" onclick="search'+this.instance+'.startSearch();return false;"/><br/>';html+='<input type="radio" name="searchWhat" value="" checked="checked"/><div style="display:inline !important" name="pesquisaSapoHostName">'+this.options.sitename+'</div>';html+='<input type="radio" name="searchWhat"/>Web';html+='</fieldset>';html+='</form>';html+='<form target="" id="formsub'+this.instance+'" action="http://pesquisa.sapo.pt/search" method="get" accept-charset="utf-8">';html+='<fieldset style="border-style: none !important">';html+='<input type="hidden" name="barra" id="barra" value="resumo"/>';html+='<input type="hidden" name="q"/>';html+='<input type="hidden" name="as_sitesearch"/>';html+='</fieldset>';html+='</form>';html+='</div>';if(this.options.searchspot){var spot=document.getElementById(this.options.searchspot);spot.innerHTML=html;}
else
{document.write(html);}},startSearch:function(){form=document.getElementById('form'+this.instance);formsub=document.getElementById('formsub'+this.instance);if(form.qq.value.length===0||form.qq.value==this.options.inputtip){form.qq.value=this.options.inputtip;form.qq.style.color='#c0c0c0';return false;}
formsub.barra.value='mundial';if(form.searchWhat[0].checked){formsub.q.value=form.qq.value;formsub.as_sitesearch.value=this.options.domain;}else{formsub.as_sitesearch.value='';formsub.q.value=form.qq.value;}
if(this.options.new_win){formsub.target=this.instance;}
formsub.submit();}};
// parse query string
var params = SAPO.Utility.Url.getQueryString(SAPO.Utility.Url.currentScriptElement().src);

// call renderer
var options={};
options.selfrender=true;
if(params["width"]) { options.width=params["width"]; }
if(params["searchspot"]) { options.searchspot=params["searchspot"]; }
if(params["domain"]) { options.domain=params["domain"]; }
if(params["sitename"]) { options.sitename=params["sitename"]; }
if(params["new_win"]) { options.new_win=params["new_win"]; }
if(params["inputtip"]) { options.inputtip=params["inputtip"]; }
new SAPO.Widget.Search(options);
