// written by Dean Edwards, 2005 with input from Tino Zijdel
// http://dean.edwards.name/weblog/2005/10/add-event/
function addEvent(element, type, handler) {
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	if (!element.events) element.events = {};
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	handlers[handler.$$guid] = handler;
	element["on" + type] = handleEvent;
};
addEvent.guid = 1;
function removeEvent(element, type, handler) {
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};
function handleEvent(event) {
	var returnValue = true;
	event = event || fixEvent(window.event);
	var handlers = this.events[event.type];
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};
function fixEvent(event) {
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

// Main Regular Expressions 
var re = {
	imgResult: /\bimgresult\b/,
	fixMinWidth: /\bfixIeMinWidth\b/g,
	textResult: /\btextresult\b/,
	detalhada: /\bdetalhada\b/g,
	tipo: /\btipo(\w*)\b/,
	homes: /\bchome\b/,
	recPages: /\btextpages\b/
}

/* REMOVER: FUNÇÃO PARA DEBUGAR */
teste = function(obj){
	var sTeste = "[" + obj.nodeName.toLowerCase() + "]\nid=" + document.getElementsByTagName("body").item(0).id + "\nclass=" + document.getElementsByTagName("body").item(0).className;
	return sTeste;
}

// Busca Simples
var bSimples = {
	www: {
		action: "http://busca.uol.com.br/www/index.html",
		param: ["q"]
	},
	br: {
		action: "http://busca.uol.com.br/br/index.html",
		param: ["q"]
	},
	uol: {
		action: "http://busca.uol.com.br/uol/index.html",
		param: ["q"]
	},
	img: {
		action: "http://busca.uol.com.br/imagem/index.html",
		param: ["q"]
	},
	vid: {
		action: "http://busca.uol.com.br/video/index.html",
		param: ["q"]
	},
	not: {
		action: "http://noticias.busca.uol.com.br/uol/index.html",
		param: ["q","id","rd"]
	},
	pre: {
		action: "http://precos.busca.uol.com.br/result.html",
		param: ["q","group","t"]
	},
	rec: {
		action: "http://dir.busca.uol.com.br/MDIbot.html",
		param: ["keyword","condition","RequestType"]
	},
	rad: {
		action: "http://musica.busca.uol.com.br/radio/index.php",
		param: ["busca","param1","check"]
	},
	mai: {
		action: "http://busca.uol.com.br/mais/",
		param: ["q"]
	},
	check: function(tipo, enviar){
		if(!document.getElementById("simples")) return;
		var oSimples = document.getElementById("simples");
		if(document.getElementsByTagName("body").item(0).id == "bpre" || document.getElementsByTagName("body").item(0).id == "bprec") {
			oSimples.q.value = document.precos.q.value;
		}
		if(document.getElementsByTagName("body").item(0).id == "bmais") {
			oSimples.q.value = document.maisbuscas.q.value;
		}
		if(enviar){
			if(oSimples.q.value == ""){
				enviar = 0;
				var bHomeCheck = bSimples.homeCheck(tipo);
				if (!bHomeCheck) return;
			}
		}
		if(document.getElementsByTagName("body").item(0).id=="bhome" && tipo == "mai") {
			var sURL = "http://busca.uol.com.br/mais/" + ((oSimples.q.value == "")? "" : "&q="+ oSimples.q.value);
			document.location = sURL;
		}
		document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.tipo,"") + " tipo" + lib.sBuscaAtiva;
		var oElements = document.getElementById("simples").elements;
		for(var i=0, oElm; oElm=oElements[i]; i++){
			if (oElm.type.toLowerCase() != "submit") oElm.disabled="disabled";
			for(var j=0, sName; sName = bSimples[tipo].param[j]; j++){
				if(oElm.name == sName) oElm.disabled="";
			}
		}
		//aqui entram as regras especiais
		switch(tipo){
			case "rec":
				oSimples.keyword.value = oSimples.q.value;
				if(!enviar && document.getElementsByTagName("body").item(0).id=="bhome") {
					oSimples.q.disabled = "";
				}
				break;
			case "rad":
				document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.detalhada,"");
				oSimples.busca.value = oSimples.q.value.replace(/\"/g,'');
				if(!enviar && document.getElementsByTagName("body").item(0).id=="bhome") {
					oSimples.q.disabled = "";
				}
				if (oSimples.check && oSimples.check.nodeName && (oSimples.check.nodeName.toLowerCase() == "input")){
					oSimples.check.value = "musica";
				} else if (oSimples.check) {
					for (var i=0, oInputRadio; oInputRadio=oSimples.check[i]; i++){
						if(oInputRadio.value == "musica"){
							oInputRadio.checked = "checked";
						}
					}
				}
				break;
			case "not":
				document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.detalhada,"");
				oSimples.id.value = "1";
				break;
			case "img":
				document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.detalhada,"");
				break;
			case "vid":
				document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.detalhada,"");
				break;
		}
		oSimples.action = bSimples[tipo].action;
		if(enviar){
			oSimples.submit();
			oSimples.q.disabled = "";
		}
	},
	homeCheck: function(tipo) {
		var sBodyId = document.getElementsByTagName("body").item(0).id;
		switch(sBodyId){
			case "bhome":
				enviar = 0;
				if(tipo != "pre" && tipo != "mai" && tipo != "rec"){
					document.location.hash = "#op" + tipo;
				}
				if(tipo == "pre"){
					document.location = "http://precos.busca.uol.com.br/";
				}
				if(tipo == "mai"){
					document.location = "http://busca.uol.com.br/mais/";
				}
				if(tipo == "rec"){
					document.location = "http://mdi.busca.uol.com.br/";
				}
				break;
			case "bprec":
				if(tipo != "pre" && tipo != "mai" && tipo != "rec"){
					document.location = "http://busca.uol.com.br/#op" + tipo;
				}
				if(tipo == "mai"){
					document.location = "http://busca.uol.com.br/mais/";
				}
				if(tipo == "rec"){
					document.location = "http://mdi.busca.uol.com.br/";
				}
				break;
			case "bmais":
				if(tipo != "pre" && tipo != "mai" && tipo != "rec"){
					document.location = "http://busca.uol.com.br/#op" + tipo;
				}
				if(tipo == "pre"){
					document.location = "http://precos.busca.uol.com.br/";
				}
				if(tipo == "rec"){
					document.location = "http://mdi.busca.uol.com.br/";
				}
				break;
			case "breco":
				if(tipo != "pre" && tipo != "mai" && tipo != "rec"){
					document.location = "http://busca.uol.com.br/#op" + tipo;
				}
				if(tipo == "pre"){
					document.location = "http://precos.busca.uol.com.br/";
				}
				if(tipo == "mai"){
					document.location = "http://busca.uol.com.br/mais/";
				}
				break;
			case "brec":
				if(document.getElementsByTagName("body").item(0).className.match(re.recPages)){
					if(tipo != "pre" && tipo != "mai" && tipo != "rec"){
						document.location = "http://busca.uol.com.br/#op" + tipo;
					}
					if(tipo == "pre"){
						document.location = "http://precos.busca.uol.com.br/";
					}
					if(tipo == "mai"){
						document.location = "http://busca.uol.com.br/mais/";
					}
					if(tipo == "rec"){
						document.location = "http://mdi.busca.uol.com.br/";
					}
				}
				break;
			default: 
				lib.fnFillField();
				return false;
		}
		return true;
	}
}

// Busca no UOL, opções
var buscaNoUOL = {
	ids: [" > ","Notícias","Esporte","Guerra no Iraque","Sites pessoais","Viagem","Folha Online","Saúde","Tecnologia","Economia","Jogos","Educação","Gay","Humor","Sexo","Televisão","Música","Pelé.Net","Lição de Casa"]
}


// Global Library 
lib = {
	sBuscaAtiva: "",
	iUlSize: 0,
	fnFillField: function(){
		alert("O campo da busca deve ser preenchido")
	},
	fnSetFocus: function(obj){
		if(typeof obj.value != "undefined" && typeof obj.defaultValue != "undefined" && (obj.defaultValue == obj.value) && obj.type == "text"){
			obj.focus();
		}
	},
	fnBodyLoad: function(){
		document.getElementsByTagName("body").item(0).className +=" loaded";
		if(!document.getElementById("simples")) return;
		var aForms = ["simples","bottom","precos"];
		for (var i=0, sForm; sForm = aForms[i]; i++){
			if(document.getElementById(sForm)){
				addEvent(document.getElementById(sForm),"submit",lib.fnCheckEmpty);
			}
		}
	},
	fnCheckEmpty: function(e){
		var target = window.event? window.event.srcElement : e ? e.target : null;
		if (!target) return;

		target = lib.fnAscendDOM(target, "form");
		if (!target) return;
		if(target.q && target.q.value !="") {
			if(document.getElementsByTagName("body").item(0).id == "brad"){
				target.busca.value = target.q.value.replace(/\"/g,"");
				target.q.disabled = "disabled";
			}
			if(document.getElementsByTagName("body").item(0).className.match(/\btiporec\b/)){
				target.keyword.value = target.q.value;
				target.q.disabled = "disabled";
			}
			if(document.getElementsByTagName("body").item(0).className.match(/\btiporad\b/)){
				target.busca.value = target.q.value;
				target.q.disabled = "disabled";
			}
			return true;
		} else {
			lib.fnFillField();
			return false;
		}
	},
	fnAscendDOM: function (obj, targetNode) {
		while (obj.nodeName.toLowerCase() != targetNode && obj.nodeName.toLowerCase() != 'html') {
			obj = obj.parentNode;
		}
		return (obj.nodeName.toLowerCase() == 'html') ? null : obj;
	},
	fnSelecionaTipo: function(sTipo,bSubmit){
		lib.sBuscaAtiva = sTipo.substring(1,sTipo.length);
		bSimples.check(lib.sBuscaAtiva,bSubmit)
	},
	fnTotalResults: function() {
		/* acerta frase informativa sobre os resultados */
		if(!document.getElementById('info') || !document.getElementById('total-results').firstChild) return;
		var sNumResults = document.getElementById('total-results').firstChild.nodeValue;
		if(sNumResults.length > 3){
			var aNumResults = new Array();
			for(var i=1, iNum = sNumResults.length; i<=iNum; i++){
				aNumResults.push(sNumResults.substring(i-1, i));
				if((iNum - i > 0) && ((iNum - i)%3 == 0)) {aNumResults.push(".")};
			}
			document.getElementById('total-results').firstChild.nodeValue = aNumResults.join("");
		}
		if(!document.getElementById('resultados')) return;
		var oDL = document.getElementById('resultados');
		var colDT = oDL.getElementsByTagName('dt');
		var oInfo = document.getElementById('info');
		if(oInfo.hasChildNodes){
			var colChilds = oInfo.childNodes;
			if(!document.createDocumentFragment) return;
			var oFragment = document.createDocumentFragment();
			var oStrong = document.createElement('strong');
			var sText = "";
			var oSpanFirst = colDT[0].getElementsByTagName("span").item(0);
			sText += parseInt(oSpanFirst.firstChild.nodeValue);
			if(colDT.length > 1){
				var oSpanLast = colDT[colDT.length-1].getElementsByTagName("span").item(0);
				sText += " a " + parseInt(oSpanLast.firstChild.nodeValue);
			}
			for(var i=0, iCIlen = colChilds.length; i<iCIlen; i++){
				if(colChilds[i].nodeType == 3){
					if(sNumResults=="1" && colChilds[i].nodeValue.match(/ encontrados/)) {
						colChilds[i].nodeValue = colChilds[i].nodeValue.replace(/ encontrados/," encontrado");
						break;
					}
					if(colDT.length > 1){
						colChilds[i].nodeValue = colChilds[i].nodeValue.replace(/\bResultados:/," Resultados de ");
					} else {
						colChilds[i].nodeValue = colChilds[i].nodeValue.replace(/\bResultados:/," Resultado ");
					}
				}
			}
			var oText = document.createTextNode(sText);
			oStrong.appendChild(oText);
			var oDeText = document.createTextNode(" de ");
			oFragment.appendChild(oStrong);
			oFragment.appendChild(oDeText);
			document.getElementById('info').insertBefore(oFragment,document.getElementById('total-results'));
		}
	},
	fnPaginacao: function() {
		/* limita paginação */
		if(!document.getElementById('paginas')) return;
		var oUL = document.getElementById('paginas');
		var colLi = oUL.getElementsByTagName('li');
		var iLiLen = colLi.length;
		if(iLiLen <= 0) return;
		var iActiveLi = -1;
		for(var i=0, oLi; oLi = colLi[i]; i++){
			if (oLi.className.match(/\bactive\b/)){
				activeLi = i;
				break;
			}
		}
		if(activeLi == -1) return;
		for (var j=iLiLen-1; j>=activeLi+10; j--){ $$temp = oUL.removeChild(colLi[j]);}
		for (var k=0; k<=activeLi-11; k++){ $$temp = oUL.removeChild(colLi[0]);}
	},
	fnOpenNewWindow: function(){
		/* cria ícone de abrir em nova janela */
		if(!document.getElementById('resultados')) return;
		var oDL = document.getElementById('resultados');
		var colDT = oDL.getElementsByTagName('dt');
		for(var i=0, oDT; oDT = colDT[i]; i++){
			var oLink = document.createElement("a");
			var oImg = document.createElement("img");
			var oSrc = oImg.src = "http://r.i.uol.com.br/c/ico_novajanela.gif";
			oLink.href = oDT.getElementsByTagName("a").item(0).href;
			oLink.appendChild(oImg);
			addEvent(oLink,"click",lib.fnClickNewWin);
			oDT.appendChild(oLink);
		}
	},
	fnClickNewWin: function(e){
		/* abre link em nova janela */
		e.stopPropagation();
		e.preventDefault();
		var target = window.event? window.event.srcElement : e ? e.target : null;
		if (!target) return;
		target = lib.fnAscendDOM(target, "a");
		if (!target) return;
		var oWin = window.open(target)
	},
	fnSendDetalhada: function(e){
		/* verifica detalhada */
		var target = window.event? window.event.srcElement : e ? e.target : null;
		if (!target) return false;

		target = lib.fnAscendDOM(target, "form");
		if (!target) return;
		if (target.fe && (target.fe.value != "")){
			if(target.q) {
				target.q.value += ' "'+target.fe.value+'"'; 
			}
			if(target.as_q) {
				target.as_q.value += ' "'+target.fe.value+'"';
			}
			target.fe.value = "";
			target.fe.disabled = "disabled";
			return true;
		}
		return true;
	},
	fnAddDetalhada: function(){
		if(!document.getElementById("detalhada")) return;
		var oDet = document.getElementById("detalhada");
		var colForms = oDet.getElementsByTagName("form");
		for(var i=0, oForm; oForm = colForms[i]; i++){
			addEvent(oForm,"submit",lib.fnSendDetalhada)
			if(oForm.fe){oForm.fe.disabled = ""}
		}
	},
	fnDetalhada: function(){
		/* eventos para abrir e fechar buscas detalhadas */
		lib.fnAddDetalhada();
		if(!document.getElementById("det-link")) return;
		addEvent(document.getElementById("det-link"),"click",lib.fnShowDetalhada);
		var colDetForm = document.getElementById("detalhada").getElementsByTagName("form");
		for(var i=0, oForm; oForm=colDetForm[i]; i++){
			var colP = oForm.getElementsByTagName("p");
			for(var j=0, oP; oP=colP[j]; j++){
				if(oP.className.match(/\bdsubmit\b/)){
					var oLink = oP.getElementsByTagName("a").item(0);
					if(oLink){
						addEvent(oLink,"click",lib.fnHideDetalhada);
					}
				}
			}
		}
	},
	fnShowDetalhada: function (e){
		/* insere estilo de busca detalhada */
		e.stopPropagation();
		e.preventDefault();
		document.getElementsByTagName("body").item(0).className += (document.getElementsByTagName("body").item(0).className.match(re.detalhada))? "": " detalhada";
	},
	fnHideDetalhada: function (e){
		/* remove estilo de busca detalhada */
		e.stopPropagation();
		e.preventDefault();
		document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.detalhada,"");
	},
	fnOpcoesBusca: function(){
		/* ativa eventos nas opções principais da busca */
		if(!document.getElementById("opcoes").getElementsByTagName("a")) return;
		var colLink = document.getElementById("opcoes").getElementsByTagName("a");
		for(var i=0, oLink; oLink=colLink[i]; i++){
			addEvent(oLink,"click",lib.fnSelecionaBusca)
		}
		if(!document.getElementById("weboptions") || !document.getElementById("weboptions").getElementsByTagName("input")) return;
		var colInput = document.getElementById("weboptions").getElementsByTagName("input");
		for(var i=0, oInput; oInput=colInput[i]; i++){
			if(oInput.type.toLowerCase() == "radio") {
				addEvent(oInput,"focus",lib.fnSelecionaRadio);
				if(navigator.userAgent.indexOf("Safari") > -1) {
					addEvent(oInput,"click",lib.fnSelecionaRadio);
				}
			}
		}
	},
	fnSelecionaBusca: function(e){
		/* seleciona a busca, e manda formulário para validação */
		e.stopPropagation();
		e.preventDefault();
		var target = window.event? window.event.srcElement : e ? e.target : null;
		if (!target) return;
		var oLi = lib.fnAscendDOM(target,"li");
		if(!oLi) return;
		lib.fnSelecionaTipo(oLi.id,true)
	},
	fnSelecionaRadio: function(e){
		/* seleciona a busca, mas não manda formulário para validação */
		e.stopPropagation();
		e.preventDefault();
		var target = window.event? window.event.srcElement : e ? e.target : null;

		if (!target) return;
		var oInput = lib.fnAscendDOM(target,"input");
		lib.fnSelecionaTipo(oInput.value,false)
	},
	fnAdjustUl: function() {
		/* alinhamento para resultados de imagem e vídeo */
		if(!document.getElementById("result-set")) return;
		var oUl = document.getElementById("result-set");
		if(lib.iUlSize != oUl.offsetWidth){
			lib.iUlSize = oUl.offsetWidth;
			var colLi = oUl.getElementsByTagName("li");
			lib.fnZeraLi(colLi);
			for(var i=1; i<colLi.length; i++){
				if (colLi[i].offsetTop > colLi[i-1].offsetTop) {
					lib.fnCreateClearLi(colLi[i])
					i++;
				}
			}
		}
	},
	fnAdjustImgLink: function() {
		/* alinhamento para resultados de imagem e vídeo */
		if(!document.getElementById("result-set")) return;
		var oRS = document.getElementById("result-set");
		var colP = oRS.getElementsByTagName("p");
		for (var i=0, oP; oP = colP[i]; i++){
			if(oP.className == "link") {
				var oLink = oP.getElementsByTagName("a")[0];
				if(oLink) {
					var oText = oLink.innerHTML;
					if (oText){
						var aTextSplit = oText.split("");
						var aTemp = [];
						for(var j=0, aNewText; aNewText = aTextSplit[j]; j++){
							aTemp.push(aNewText);
							if(j%26 == 25) {aTemp.push("<br>")};
						}
						oLink.innerHTML = aTemp.join("");
					}
				}
			}
			if(oP.className == "nome") {
				var oNomeText = oP.innerHTML;
				if (oNomeText){
					var aTextSplit = oNomeText.split("");
					var aTemp = [];
					for(var j=0, aNewText; aNewText = aTextSplit[j]; j++){
						aTemp.push(aNewText);
						if(j%26 == 25) {aTemp.push("<br>")};
					}
					oP.innerHTML = aTemp.join("");
				}
			}
		}
	},
	fnIeMinWidth: function(){
		/* simula MinWidth para IE forçando estilo CSS (e max-width para um caso específico */
		if(typeof document.all == 'undefined') return;
		if(document.getElementsByTagName("body").item(0).clientWidth < 761){
			document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.match(re.fixMinWidth)? document.getElementsByTagName("body").item(0).className : document.getElementsByTagName("body").item(0).className + " fixIeMinWidth";
		} else {
			document.getElementsByTagName("body").item(0).className = document.getElementsByTagName("body").item(0).className.replace(re.fixMinWidth,"");
		}
	},
	fnCreateClearLi: function(obj){
		/* cria elementos li extras para quebra de linha nas páginas de thumbnails */
		var li = document.createElement('li');
		var txt = document.createTextNode('&nbsp;');
		li.className="newcol";
		li.appendChild(txt);
		obj.parentNode.insertBefore(li,obj);
	},
	fnZeraLi: function(col){
		/* remove elementos li extras para quebra de linha nas páginas de thumbnails */
		for (var i=0; i<col.length; i++){
			if(col[i].className.match(/\bnewcol\b/)){
				col[i].parentNode.removeChild(col[i]);
			}
		}
	},
	fnMarcaEstacaoUOL: function(){
		var sLocation = document.location.toString();
		if (!sLocation.match(/\&id=(\d+)/)) return;
		numerodoid = RegExp.$1;
		if(!numerodoid || numerodoid == 0) return;
		if(!buscaNoUOL.ids[numerodoid] || !document.getElementById("area")) return;
		var oText = document.createTextNode(buscaNoUOL.ids[0] + buscaNoUOL.ids[numerodoid])
		document.getElementById("area").appendChild(oText)
	},
	fnMarcarLinkUOL: function(){
		/* acrescenta class linkuol para páginas de conteúdo UOL */
		if(!document.getElementById('resultados')) return;
		var oDL = document.getElementById('resultados');
		var colDD = oDL.getElementsByTagName('dd');
		for (var i=0, oDD; oDD=colDD[i]; i++){
			if(oDD.className.match(/\blink\b/) && oDD.firstChild.firstChild.nodeValue.match(/\.uol\.com\.br/)){
				if(/(\.bol|\.sites|\.vilabol|\.fotoblog|\.blog)\.\uol.com\.br/.test(oDD.firstChild.nodeValue) == 0){
					oDD.className+=" linkuol";
				}
			}
		}
	},
	fnMarcarLinkBlog: function(){
		/* acrescenta "[blog] " antes de links para alguns blogs */
		if(!document.getElementById('resultados')) return;
		var oDL = document.getElementById('resultados');
		var colDD = oDL.getElementsByTagName('dd');
		for (var i=0, oDD; oDD=colDD[i]; i++){
			if(oDD.className.match(/\blink\b/) && oDD.firstChild.firstChild.nodeValue.match(/\.fotoblog\.uol|\.blog\.uol|theblog|weblogger(\.terra?)|blogger|blig|fotologs|photolog|flogs|photopage|floog|fotoaki|blogs|blog\.aol\.com\.br|\.zip\.net|\.blogspot\.com|\.turmadobar\.com|\.blogger\.com/g)){
				var oSpan = document.createElement("span")
				var sSpan = document.createTextNode("[blog] ")
				oSpan.className+="linkblog";
				oSpan.appendChild(sSpan);
				oDD.insertBefore(oSpan,oDD.firstChild);
				oDD.className=oDD.className.replace("linkuol","");
			}
		}
	},
	fnCreateInputHidden: function(sName,sValue){
		var oInput = document.createElement("input");
		oInput.type = "hidden";
		oInput.name = sName;
		oInput.value = sValue;
		return oInput;
	},
	fnObjInnerHTML: function(oID, sCode){
		if(!document.getElementById(oID)) return;
		document.getElementById(oID).innerHTML = sCode;
	},
	fnChecarCensura: function(){
		var sLocation = document.location.toString();
		if(sLocation.match(/fi\=3/)){
			if(document.simples.fi) lib.fnMarcarRadio(document.simples.fi,"3");
			if(document.getElementById("det-img") && document.getElementById("det-img").fi) lib.fnMarcarRadio(document.getElementById("det-img").fi,"3");
			if(document.getElementById("det-vid") && document.getElementById("det-vid").fi) lib.fnMarcarRadio(document.getElementById("det-vid").fi,"3");
		} else {
			lib.fnMarcarRadio(document.simples.fi,"1");
			if(document.getElementById("det-img") && document.getElementById("det-img").fi) lib.fnMarcarRadio(document.getElementById("det-img").fi,"1");
			if(document.getElementById("det-vid") && document.getElementById("det-vid").fi) lib.fnMarcarRadio(document.getElementById("det-vid").fi,"1");
		}
	},
	fnMarcarRadio: function(oRadio,sValue){
		for(var i=0, oRad; oRad = oRadio[i]; i++){
			if (oRad.value == sValue){
				oRad.checked = "checked";
				break;
			}
		}
	},
	fnOpcoesOrdenacao: function(){
		if(!document.getElementById("resultados")) return;
		var oResults = document.getElementById("resultados");
		var oTxtOrdem = document.createTextNode("Ordenação: ");
		var oTxtPipe = document.createTextNode(" | ");
		var oTxtData = document.createTextNode("data");
		var oTxtRelev = document.createTextNode("relevância");
		var sLocation = document.location.toString();
		var oLink = document.createElement("a");
		var sLink = sLocation.replace(/\&rd=1/,"")
		var oP = document.createElement("p");
		var oStrong = document.createElement("strong");
		oP.id = "ordenacao";
		oP.appendChild(oTxtOrdem);
		if(sLocation.match(/\&rd=1/)){
			oLink.href = sLink;
			oLink.appendChild(oTxtRelev);
			oP.appendChild(oLink);
			oP.appendChild(oTxtPipe);
			oStrong.appendChild(oTxtData)
			oP.appendChild(oStrong);
		} else {
			oLink.href = sLink + "&rd=1";
			oLink.appendChild(oTxtData);
			oStrong.appendChild(oTxtRelev);
			oP.appendChild(oStrong);
			oP.appendChild(oTxtPipe);
			oP.appendChild(oLink);
		}
		oResults.parentNode.insertBefore(oP,oResults);
	},
	fnHideFooter: function(){
		if(document.getElementById("results") && document.getElementById("results").firstChild && (document.getElementById("results").firstChild.nodeType == 3) && document.getElementById("results").firstChild.nodeValue.match(/Nenhum resultado encontrado para/)){
			document.getElementsByTagName("body").item(0).className += " semresultados";
		}
	}
}


var bMais = {
	blg: {
		action: "http://blog.busca.uol.com.br/uol/index.html",
		param: ["q"]
	},
	fbl: {
		action: "http://fotoblog.busca.uol.com.br/uol/index.html",
		param: ["q"]
	},
	sit: {
		action: "http://sites.busca.uol.com.br/uol/index.html",
		param: ["q"]
	},
	esp: {
		action: "http://busca.uol.com.br/uol/index.html",
		param: ["q","id"]
	},
	mus: {
		action: "http://busca.uol.com.br/uol/index.html",
		param: ["q","id"]
	},
	sex: {
		action: "http://busca.uol.com.br/uol/index.html",
		param: ["q","id"]
	},
	tel: {
		action: "http://busca.uol.com.br/uol/index.html",
		param: ["q","id"]
	},
	tvu: {
		action: "http://app.uol.com.br/tvuol/search.php",
		param: ["pdescri","desc","titu","copy"]
	},
	check: function(){
		if(!document.getElementById("maisbuscas")) return;
		var oMais = document.getElementById("maisbuscas");
		var tipo = oMais.tipo[oMais.tipo.selectedIndex].value;
		if(oMais.q.value == ""){
			lib.fnFillField();
			return;
		}
		var oElements = document.getElementById("maisbuscas").elements;
		for(var i=0, oElm; oElm=oElements[i]; i++){
			if (oElm.type.toLowerCase() != "submit") oElm.disabled="disabled";
			for(var j=0, sName; sName = bMais[tipo].param[j]; j++){
				if(oElm.name == sName) oElm.disabled="";
			}
		}
		switch(tipo){
			case "esp":
				oMais.id.value = "2";
				break;
			case "mus":
				oMais.id.value = "16";
				break;
			case "sex":
				oMais.id.value = "14";
				break;
			case "tel":
				oMais.id.value = "15";
				break;
			case "tvu":
				oMais.pdescri.value = oMais.q.value;
				break;
		}
		oMais.action = bMais[tipo].action;
		oMais.submit();
		oMais.q.disabled = "";
	}
}


var overture = {
	cab: '<h2><a href="http://br.yahoo.com/info/overture/2/overture_pm_landing_1.html">Overture Links Patrocinados</a></h2>',
	noa: '<p id="informe" class="nolp">INFORME PUBLICITÁRIO <a href="http://br.yahoo.com/info/overture/2/overture_pm_landing_1.html" target="_blank">Cadastre seu site na Overture</a></p>',
	fot: '<p id="anuncie"><a href="http://br.yahoo.com/info/overture/2/overture_pm_landing_1.html" target="_blank">Cadastre seu site na Overture</a></p>',
	fnNoAds: function(){
		if(!document.getElementById("links-patrocinados")) return;
		document.getElementById("links-patrocinados").innerHTML = overture.noa;
	},
	fnShow: function(){
		if(!document.getElementById("links-patrocinados")) return;
		var sCode = "";
		if(showAd>0){
			sCode += overture.cab;
			sCode += "\n<dl>";
			for (var i = iniTRnum; i < adArray.length; i++) {
				if (adArray[i]!=null){
					sCode += '<dt><span class="num numlp">'+ i +'.</span> <a href="' + adArray[i][0] + '" onmouseover="window.status=\'' + adArray[i][1] + '\'; return true;" onmouseout="window.status=\'\'" target="_blank">' + adArray[i][2] + '</a></dt>\n';
					sCode += '<dd class="descricao descricaolp">' + adArray[i][3] + '</dd>\n';
					sCode += '<dd class="link linklp"><a href="' + adArray[i][0] + '" onmouseover="window.status=\'' + adArray[i][1] + '\'; return true;" onmouseout="window.status=\'\'" target="_blank">' + adArray[i][1] + '</a></dd>\n';
				}
			}
			sCode += '</dl>\n';
			sCode += overture.fot;
			document.getElementById("links-patrocinados").innerHTML = sCode;
		}
	}
}
