////////////////////////////////////////////////////////////////////////////////
// Funções "AJAX"  v.2                                                        //
// Breno Damas M. Ribeiro                                                     //
// M.M. Informática - Desenvolvimento Web                                     //
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Browser
MSIE=document.all?true:false;
OPERA=(navigator.userAgent.toUpperCase().indexOf('OPERA')>=0);

////////////////////////////////////////////////////////////////////////////////
//Globais
pronto=true;
semajax='/browser_antigo.asp';

atualiza='{}reload:';
js_eval='javascript:';
html_cmd='{}innerHTML:';
HTMLCarregando='Trabalhando... ({total} tarefas em execução)';
oCarrega=null;
sCampos='hidden,text,textarea,';
UltimoFormEnviado='';

function criaLoadDiv(t,m) {
	oCarrega=AdicionaTag('div','tudo','id="divCarregaAjax"');
	if(oCarrega!=null) {
		with (oCarrega.style) {
			visibility='hidden';
			display='none';
			backgroundColor='#FFB';
			padding='1px';
			border='1px solid #DD9';
			position='absolute';
			top='20px';
			right='20px';
			zIndex='999';
		}
		oCarrega.innerHTML='null';
		pronto=true;
	} else if(m>0) {
		pronto=false;
		setTimeout('criaLoadDiv('+t+','+(--m)+')',t);
	} else {
		if(!confirm('Problemas ao criar elementos de inteface...\nClique OK e tente atualizar a página ou Cancelar para ver uma lista de navegadores sugeridos...'))	location.href='/browser_antigo.asp';
	}
}

function MostraCarregando(id) {
	if(HTMLCarregando.length==0) {
		aux='';
		for(i=(fila.length+filab.length)%100;i>=0;--i) aux+='*';
		txLoad=aux;
	} else {
		txLoad=HTMLCarregando.replace('{total}',fila.length+filab.length);
	}

	if(oCarrega==null && (id.indexOf(atualiza)!=0 && id.indexOf(js_eval)!=0)) {
		document.getElementById(id).innerHTML=txLoad;
	} else if(oCarrega!=null) {
		if(fila.length<=0) {
			with (oCarrega.style) {
				visibility='hidden';
				display='none';
			}
		} else {
			with (oCarrega.style) {
				visibility='visible';
				display='block';
			}
		}
		oCarrega.innerHTML=txLoad;
	}
}
criaLoadDiv(100,100);

fila=new Array();
filab=new Array();
UltimaTarefa=new Array(2);

function criaXMLHTTP() {var r; try {r=new XMLHttpRequest();} catch(e) {try {r=new ActiveXObject("Msxml2.XMLHTTP");} catch(e) {try {r=new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {r=null;}}} return r;}
var xmlhttp=criaXMLHTTP();
if(xmlhttp==null) {
	xmlhttp = false;
	window.location.href=semajax;
} else {
}

bdEmpty=0
bdInt=2
bdLong=3
bdFloat=4
bdDouble=5
bdMoeda=6
bdData=7
bdBool=11
bdByte=16
bdTexto=202
bdMemo=203

document.cookie='cookieteste=true; path=/';

////////////////////////////////////////////////////////////////////////////////
//Funções de primeiro plano (resultados visíveis ao usuário)
// para chamar uma nova tarefa ao concluir esta, id=atualiza+'id;url'
function EnfileraTarefa(id,url) {
	fila.push([id,url]);

	MostraCarregando(id);

	if(fila.length==1) RequisitaDados();
}

function RequisitaDados() {
	if(xmlhttp) {
		if(fila.length>0 && pronto) {
			pronto=false;
			xmlhttp.open("GET",CacheMSIE(fila[0][1]),true);
			xmlhttp.onreadystatechange=function () {
				if (xmlhttp.readyState==4) {//alert(fila[0][0]);
					if(xmlhttp.status==200) {
						retorno=xmlhttp.responseText;
						// unescape(xmlhttp.responseText.replace(/\+/g," "));
					} else {
						retorno=xmlhttp.status+' '+xmlhttp.statusText;
					}
		
					x=fila.shift();
					UltimaTarefa=x;
					MostraCarregando(x[0]);
					cmd=new String(x[0]);
					if(cmd.indexOf(js_eval)==0) cmd=js_eval;
					else if(cmd.indexOf(atualiza)==0) cmd=atualiza;
					else cmd=html_cmd;
			//		alert(cmd+'~'+x[0]);
					switch(cmd) {
					case js_eval:
						if(xmlhttp.status==200) {
							eval(retorno);
							if(x[0].length>js_eval.length) eval(x[0].substr(js_eval.length));
						} else {
							alert(retorno);
						}
						break;
					case atualiza:
						erro=parseInt(retorno,10);
						if(!erro) {
							id=x[0].substring(atualiza.length,x[0].indexOf(";"));
							url=x[0].substr(x[0].indexOf(";")+1);
							//if(confirm('id:'+id+'\nurl:'+url+'\nx[0]:'+x[0]))
							EnfileraTarefa(id,url);
						} else {
							alert('Erro: '+erro);
						}
						break;
					default:
						var oC=document.getElementById(x[0]);
						if(oC!=null) oC.innerHTML=retorno;
					}
					pronto=true;
					if(fila.length>0) RequisitaDados();
					else LivreB();
				}
			}
			xmlhttp.send(null);
		} else if(fila.length>0) {
			setTimeout('RequisitaDados();',100);
		}// else alert(fila.length+'>'+pronto+'Erro na execução do script!\nEste alert não deveria aparecer...\nEnvie mensagem para: web@mminformatica.com.br');
	} else	window.location.href=semajax;
}

//Formulários
function EnviaForm(sID,onde,sRequerido) {
	objInfo=document.getElementById('info');
	objInfo.innerHTML='Processando...';
	if(xmlhttp) {
		if(pronto) {
			pronto=false;
			if(sRequerido.length>0) sRequerido=(sRequerido+',').replace(',,',',');
			objForm=document.getElementById(sID);
			total=objForm.elements.length;
			qs='';
			for(var i=0;i<total;++i) {
				tipo=(''+objForm.elements[i].type).toUpperCase();
				if(tipo=='RADIO' || objForm.elements[i].nodeName=='FIELDSET')
					if(!objForm.elements[i].checked) continue;
				nome=objForm.elements[i].name;
				valor=objForm.elements[i].value;
				if(sRequerido.length>0) {
					if(sRequerido.indexOf(nome+',')>=0 && valor=='') {
						pronto=true;
						objInfo.innerHTML+='Parado!';
						alert('Elemento requerido! Preencha o campo e tente novamente.');
						objInfo.innerHTML='';
						objForm.elements[i].focus();
						return;
					}
				}
				/*/if(!confirm(i+'#Tentando gravar:\n'+nome+'='+valor)) {
					pronto=true;
					return;
				}/*/
				qs+=nome+'='+URLEncode(valor);
				if(i<(total-1)) qs+='&';
			}
			objInfo.innerHTML='Gravando...';
//alert(qs);
			xmlhttp.open("GET",CacheMSIE(onde+'?'+qs),true);
			xmlhttp.onreadystatechange=function () {
				if(xmlhttp.readyState==4) {
					if(xmlhttp.status==200) {
						retorno=xmlhttp.responseText;
						if(retorno.charAt(0)=='?') {
							objInfo.innerHTML='Processando!';
							QSForm(retorno);
							objInfo.innerHTML='';
						} else {
							if(retorno.charAt(0)=='!') {
								LimpaForm(sID);
								retorno=retorno.substr(1);
							}
							objInfo.innerHTML=retorno;
						}
						UltimoFormEnviado=sID;
					} else {
						objInfo.innerHTML=xmlhttp.status+' '+xmlhttp.statusText;
					}
					pronto=true;
				}
			}
			xmlhttp.send(null);
		} else setTimeout('EnviaForm("'+sID+'","'+onde+'","'+sRequerido+'")',50);
	} else window.location.href=semajax;
}

function IniMascaras(de) {
	if(xmlhttp) {
		objInfo=document.getElementById('info');
		try {
			objInfo.innerHTML='Processando m&aacute;scaras...';
		} catch(e) {
			objInfo=false;
		}

		if(pronto && objInfo) {
			pronto=false;
			xmlhttp.open("GET",CacheMSIE(de),true);
			xmlhttp.onreadystatechange=function () {
				if(xmlhttp.readyState==4) {
					if(xmlhttp.status==200) {
						ss=xmlhttp.responseText;

						if(ss.charAt(0)=='?') {
							objInfo.innerHTML='Processando m&aacute;scaras.';
							QSEventos(ss);
							objInfo.innerHTML='';
						} else {
							objInfo.innerHTML=ss;
						}
					} else {
						objInfo.innerHTML=xmlhttp.status+' '+xmlhttp.statusText;
					}
					pronto=true;
				}
			}
			xmlhttp.send(null);
		} else setTimeout('IniMascaras("'+de+'")',250);
	} else window.location.href=semajax;
}

function QSForm(ss) {
	if(ss.charAt(0)=='?') {
		ss=ss.substr(1);
		while(ss.length>0) {
			pos=ss.indexOf('=');
			if(pos>0) {
				id=unescape(ss.substring(0,pos).replace(/\+/g," "));
				ss=ss.substr(pos+1);
				pos=ss.indexOf('&');
				if(pos>0) {
					valor=unescape(ss.substring(0,pos).replace(/\+/g," "));
					ss=ss.substr(pos+1);
				} else if(pos==0) {
					valor='';
					ss=ss.substr(1);
				} else {
					valor=unescape(ss.replace(/\+/g," "));
					ss='';
				}
				objCampo=document.getElementById(id);
				try {
					tipo=objCampo.type;
				} catch (e) {
					tipo=typeof(objCampo);
				}
				if(sCampos.indexOf(tipo+',')>=0) {
					objCampo.value=valor;
					try {
						objDiv=document.getElementById('div'+id);
						try {
							try {
								tdiv=typeof(objDiv.innerHTML);
								tdiv=true;
							} catch(e) {
								tdiv=false;
							}
							if(tdiv) objCampo.onkeyup();
						} catch(e) {
							objDiv.innerHTML='Dado n&atilde;o selecionado devido a restri&ccedil;&otilde;es de seu navegador!';
						}
					} catch(e) {
						objDiv=false;
					}
				} else if(tipo=='select-one') {
					total=objCampo.options.length;
					objCampo.selectedIndex=0;
					for(i=0;i<total;++i) {
						if(objCampo.options[i].value==valor) {
							objCampo.selectedIndex=i;
							i=total;
						}
					}
				} else if(tipo=='radio') {
					objCampo=document.getElementsByName(id);
					total=objCampo.length;
					for(i=0;i<total;++i) {
						try {
							tipo=objCampo[i].type;
						} catch (e) {
							tipo=typeof(objCampo[i]);
						}
						if(tipo=='radio') objCampo[i].checked=(objCampo[i].value==valor);
					}
				} else if(tipo=='checkbox') {
						objCampo.checked=eval(valor);
				} else if(tipo!='object') {
					alert('Tipo ['+tipo+'] não processado!\n'+id+':'+valor);
				}
			}
		}
	}
}

function QSEventos(ss) {
	if(ss.charAt(0)=='?') {
		ss=ss.substr(1);
		while(ss.length>0) {
			pos=ss.indexOf('=');
			if(pos>0) {
				id=unescape(ss.substring(0,pos).replace(/\+/g," "));
				ss=ss.substr(pos+1);
				pos=ss.indexOf('&');
				if(pos>0) {
					valor=unescape(ss.substring(0,pos).replace(/\+/g," "));
					ss=ss.substr(pos+1);
				} else if(pos==0) {
					valor='';
					ss=ss.substr(1);
				} else {
					valor=ss;
					ss='';
				}
				objCampo=document.getElementById(id);
				try {
					tipo=objCampo.type;
					//alert(objCampo.id);
				} catch (e) {
					tipo=typeof(objCampo);
				}
				if(sCampos.indexOf(tipo+',')>=0) {
					switch(parseInt(valor)) {
					case bdInt:
					case bdLong:
						try {
							objCampo.onblur=function () {
								v=this.value;
								if(isNaN(v) || v.indexOf('.')>=0 || v.indexOf(',')>=0) {
									alert("Dado inválido! O campo deve conter um número inteiro!");
									setTimeout('document.getElementById("'+this.id+'").focus()',10);
								}
							}
						} catch(e) {
							alert(tipo+'\n'+id);
						}
						break;
					case bdData:
						try {
							sBCampo=document.getElementById('b'+objCampo.id).id;
							bCalendario=true;
						} catch(e) {
							bCalendario=false;
						}
						if(bCalendario) {
							Calendar.setup ({inputField:objCampo.id,ifFormat:'%d/%m/%Y',// %H:%M:%S',
								button:sBCampo,showsTime:false,timeformat:'24',weekNumbers:false});
						}

						objCampo.onblur=function () {
							v=this.value;
							if((isNaN(Date.parse(v))||v.indexOf('/')==-1)&&v.length>0) {
								alert("Dado inválido! O campo deve conter uma data!\nEx.:\t27/11/1984\n\t03/04/1985 14:30:17");
								setTimeout('document.getElementById("'+this.id+'").focus()',10);
							}
						}
						break;
					case bdTexto:
					case bdMemo:
					case -1:
						break;
					default:
						alert('Tipo ['+tipo+'] não processado!\n'+id+':'+valor);
					}
				}
			}
		}
	}
}

function PreencheForm(de) {
	if(xmlhttp) {
		objInfo=document.getElementById('info');
		try {
			objInfo.innerHTML='Processando...';
		} catch(e) {
			objInfo=false;
		}

		if(pronto && objInfo) {
			pronto=false;
			//alert(de);
			xmlhttp.open("GET",CacheMSIE(de),true);
			xmlhttp.onreadystatechange=function () {
				if(xmlhttp.readyState==4) {
					if(xmlhttp.status==200) {
						ss=xmlhttp.responseText;

						if(ss.charAt(0)=='?') {
							objInfo.innerHTML='Processando!';
							QSForm(ss);
							objInfo.innerHTML='';
						} else {
							objInfo.innerHTML=ss;
						}
					} else {
						objInfo.innerHTML=xmlhttp.status+' '+xmlhttp.statusText;
					}
					pronto=true;
				}
			}
			xmlhttp.send(null);
		} else setTimeout('PreencheForm("'+de+'")',250);
	} else window.location.href=semajax;
}

function LimpaForm(sID) {
	objForm=document.getElementById(sID);
	total=objForm.elements.length;
	for(i=0;i<total;++i) {
		objCampo=objForm.elements[i];
		if(sCampos.indexOf(objCampo.type)>=0) {
			objCampo.value='';
			try {
				id=objCampo.id;
				objDiv=document.getElementById('div'+id);
				try {
					try {
						objDiv.innerHTML='';
						tdiv=true;
					} catch(e) {
						tdiv=false;
					}
					//if(tdiv) document.getElementById(id).onkeyup(); loop #INF
				} catch(e) {
					alert('Dado não selecionado devido a restrições de seu navegador!');
					window.location.href=semajax;
				}
			} catch(e) {
				objDiv=false;
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
function AdicionaTag(tag,idpai,atr) {
	if(!(document.createElement&&document.getElementById&&document.appendChild)) {
		alert('Seu browser possui algumas restrições inconvenientes...\nSiga as instruções da página seguinte, para atualizá-lo ou migrar para outro...');
		window.location.href=semajax;
		return null;
	}
	atr+=' ';
	atr=atr.replace('\t',' ')
	while(atr.indexOf('  ')>=0) atr=atr.replace('  ',' ');
	if(MSIE && !OPERA) {
		var el=document.createElement('<'+tag+' '+atr+'>');
	} else {
		var el=document.createElement(tag);
		if(atr.length>0) {
			if(!el.setAttribute) {
				alert('Seu browser possui algumas restrições inconvenientes...\nSiga as instruções da página seguinte, para atualizá-lo ou migrar para outro...');
				window.location.href=semajax;
				return;
			}
			var ia='="', fa='" ';
			while(atr.length>0) {
				pos=atr.indexOf(ia);
				if(pos>0) {
					aa=atr.substring(0,pos);
					atr=atr.substr(pos+ia.length);
					pos=atr.indexOf(fa);
					if(pos>0) {
						vl=atr.substring(0,pos);
						atr=atr.substr(pos+fa.length);
					} else if(pos==0) {
						vl='';
						atr=atr.substr(fa.length);
					} else {
						vl=atr;
						atr='';
					}
				} else atr='';
				el.setAttribute(aa,vl);
			}
		}
	}
	var pai=document.getElementById(idpai);
	if(pai!=null)
		pai.appendChild(el);
	else el=pai;
	return el;
}

function RemovePorId(id) {
	if(!document.getElementById) {
		alert('Seu browser possui algumas restrições inconvenientes...\nSiga as instruções da página seguinte, para atualizá-lo ou migrar para outro...');
		window.location.href=semajax;
		return;
	}
	el=document.getElementById(id);
	if(el==null) return null;
	if(!(el.removeChild&&el.parentNode)) {
		alert('Seu browser possui algumas restrições inconvenientes...\nSiga as instruções da página seguinte, para atualizá-lo ou migrar para outro...');
		window.location.href=semajax;
		return;
	}
	return el.parentNode.removeChild(el);
}

////////////////////////////////////////////////////////////////////////////////
//Funções de segundo plano (resultados invisíveis ao usuário)
function EnfileraTarefaB(url) {
	filab.push(url);
	LivreB();
}

function LivreB() {
	if(xmlhttp) {
		if(filab.length>0) {
			if(fila.length>0) {
				setTimeout('LivreB();',500);
			} else if(pronto) {
				pronto=false;
				xmlhttp.open("GET",CacheMSIE(filab[0]),true);
				xmlhttp.onreadystatechange=function () {
					if(xmlhttp.readyState==4) {
						x=filab.shift();
						pronto=true;
						setTimeout('LivreB();',500);
					}
				}
				xmlhttp.send(null);
			}
		}
	} else window.location.href=semajax;
}

function EnfileraTarefaQSB() {
	ss=window.location.search;
	if(ss.charAt(0)=='?') ss=ss.substr(1);
	while(ss.length>0) {
		pos=ss.indexOf('=');
		if(pos>0) {
			//id=ss.substring(0,pos);
			ss=ss.substr(pos+1);
			pos=ss.indexOf('&');
			if(pos>0) {
				url=ss.substring(0,pos);
				ss=ss.substr(pos+1);
			} else {
				url=ss;
				ss='';
			}
			EnfileraTarefaB(url);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// Utilidades
function strHex(num) {
	var str=''
	while(num>0) {
		alg=num%16;
		if(alg>9) {
			alg='ABCDEF'.charAt(alg-10);
		}
		str=alg+str+'';
		num=Math.floor(num/16);
	}
	return str;
}
function URLEncode(sS) {
	var r=''
	for(var i=0;i<sS.length;++i) {
		cod=sS.charCodeAt(i);
		if(cod>160 || cod==35 || cod==38 || cod==43) {
			r+='%'+strHex(cod);
		} else {
			try {
				r+=encodeURI(sS.charAt(i));
			} catch(e) {
				try {
					r+=escape(sS.charAt(i));
				} catch(e) {
					r+=sS.charAt(i);
				}
			}
		}
	}
	return r;
}
function chk(sid,txt,js) {
	try {
		iHTML=document.getElementById(sid).innerHTML;
	} catch(e) {
		alert('Ocorreu um erro desconhecido...');
		iHTML='';
	}
	if(iHTML.indexOf(txt)>=0) {
		eval(js);//alert(js.replace(';',';\n'));
	} else setTimeout('chk("'+sid+'","'+txt+'","'+js+'")',100);
}
function chkCookie(sid,txt,js) {
	res=leCookie(sid);
	if(res==null) return;
	if(res.indexOf(txt)>=0) {
		eval(js);//alert(js.replace(';',';\n'));
	} else setTimeout('chkCookie("'+sid+'","'+txt+'","'+js+'")',100);
}

function sAgora() {
	agora=new Date();
	dia=agora.getDate(); if(dia<10) dia='0'+dia;
	mes=agora.getMonth()+1; if(mes<10) mes='0'+mes;
	ano=agora.getYear(); if(ano<1900) ano+=1900;
	hora=agora.getHours(); if(hora<10) hora='0'+hora;
	mins=agora.getMinutes(); if(mins<10) mins='0'+mins;
	segs=agora.getSeconds(); if(segs<10) segs='0'+segs;
	return dia+'/'+mes+'/'+ano+' '+hora+':'+mins+':'+segs;
}

function AtualizaRelogio(sOnde) {
	texto=sAgora().replace(' ','&nbsp;');
	try {
		objRelogio=document.getElementById(sOnde);
		objRelogio.innerHTML=texto;
		setTimeout('AtualizaRelogio("'+sOnde+'")',500);
	} catch(e) {
		alert('Problemas com o relógio.\n'+texto);
	}
}

function leCookie(sn) {
	if(document.cookie.indexOf('cookieteste')<0) {
		alert('Seu browser não aceita cookies...\nPara ativar no Firefox:\n'+
					' - Vá em Ferramentas > Opções > Privacidade (cadeado) > Cookies\n'+
					' - Certifique-se de que este site tenha permissão para gerar cookies');
		return null;
	}
	var dc=document.cookie;
	var prefix=sn+"=";
	var begin=dc.indexOf("; "+prefix);
	if (begin==-1) {
		begin=dc.indexOf(prefix);
		if (begin!=0) return null;
	} else begin+=2;
	var end=dc.indexOf(";",begin);
	if (end==-1) end=dc.length;
	return unescape(dc.substring(begin+prefix.length,end));
}
function delCookie(sn) {
	if(leCookie(sn)) {
		var ag=new Date;
		ag.setTime(ag.getTime()-24*60*60*1000);
		document.cookie = sn+'=false; expires='+ag.toUTCString()+'; path=/';
	}
}
//printfHTML(dest,string,...)
//string: Formatar como ".bat", a partir do %1
//Para usar o símbolo '%': criatividade...
function printfHTML() {
	av=arguments;
	ac=arguments.length;
	if(ac<2) return;
	for(var i=2;i<ac;++i) {
		av[1]=av[1].replace('%'+(i-1),av[i]);
	}
	document.getElementById(av[0]).innerHTML=av[1];
}

////////////////////////////////////////////////////////////////////////////////
// Bugs do IE
function CacheMSIE(sURL) {
	if(navigator.userAgent.indexOf('MSIE')>=0) {
		if(sURL.indexOf('?')<0) {
			sURL+='?';
		} else {
			sURL+='&';
		}
		return sURL+'cid='+encodeURI(Math.random()).replace('.','');
	} else return sURL;
}

////////////////////////////////////////////////////////////////////////////////
//deletar
function Concluido(campo) {
	aux=document.getElementById('concluido');
	if(campo.value!='Concluido') {
		aux.value='';
	} else if(aux.value=='') {
		aux.value=sAgora();
	} else if(confirm('Nova data?')) {
		aux.value=sAgora();
	}
}

function Status(campo) {
	aux=document.getElementById('estado');
	if(campo.value=='' && aux.value=='Concluido') {
		indc=aux.selectedIndex;
		aux.selectedIndex=(indc>0)?--indc:++indc;
	} else if(campo.value!='' && aux.value!='Concluido') {
		total=aux.options.length;
		for(var i=0;i<total;++i) {
			if(aux.options[i].value=='Concluido') {
				aux.selectedIndex=i;
				i=total;
			}
		}
	}
}

function EnfileraTarefaQS() {
	ss=window.location.search;
	if(ss.charAt(0)=='?') ss=ss.substr(1);
	while(ss.length>0) {
		pos=ss.indexOf('=');
		if(pos>0) {
			id=ss.substring(0,pos);
			ss=ss.substr(pos+1);
			pos=ss.indexOf('&');
			if(pos>0) {
				url=ss.substring(0,pos);
				ss=ss.substr(pos+1);
			} else {
				url=ss;
				ss='';
			}
			EnfileraTarefa(id,url);
		}
	}
}

function Pagina(num) {
	if(UltimaTarefa[0]!='') {
		qs='';
		id=UltimaTarefa[0];
		url=UltimaTarefa[1];
		pos=url.indexOf('?')
		if(pos>0) {
			qs=url.substr(pos+1);
			url=url.substring(0,pos);
		}

		if(qs.length>1) {
			pos=qs.indexOf('pagina=');
			if(pos!=-1) {
				qs=qs.replace(/pagina=\d*/,'pagina='+num);
			} else {
				qs+='&pagina='+num;
			}
		} else {
			qs='pagina='+num;
		}

		//alert(id+':'+url+'?'+qs);
		EnfileraTarefa(id,url+'?'+qs);
		if(num>1) {
			qs=qs.replace(/pagina=\d+/,'pagina='+(num-1));
			EnfileraTarefaB(url+'?'+qs);
		}
		qs=qs.replace(/pagina=\d+/,'pagina='+(num+1));
		EnfileraTarefaB(url+'?'+qs);
	}
}
