function focusformulario(obj){obj(0).focus();}

function ValidaForm(obj)
{
	// constantes
	var Vnumelements = 0;
	var objeto = "";
	var nomedocampo = "";
	var mensagem = "";

	// variaveis de texto
	var texto1 = "";
	var texto2 = "";
	var texto3 = "";
	var texto4 = "";
	var texto5 = "";
	
	// variáveis numéricas
	var numero1 = 0;
	var numero2 = 0;
	var numero3 = 0;
	var numero4 = 0;
	var numero5 = 0;
	var numero6 = 0;
	var numero7 = 0;
	
	
	Vnumelements = obj.elements.length;
	
	var y = 0;
	for(y=0;y<Vnumelements;y++)
	{
		objeto = "";
		objeto = obj.elements[y];
		
		if(objeto.getAttribute("tipo") != undefined ||  objeto.getAttribute("vazio") != undefined)
		{
			nomedocampo = "";
			nomedocampo = objeto.getAttribute("name");
			nomedocampo2 = "";
			nomedocampo2 = objeto.getAttribute("nome");
			
			if (nomedocampo2 == null)
			{
				nomedocampo2 = nomedocampo;
			}
			mensagem = "Atenção\n\nO campo " + nomedocampo2;
			
			if(nomedocampo == undefined || nomedocampo == "")
			{
				alert("Atenção\n\nNão foi possivel resgatar o nome do campo " + y + ".\n\nPor favor, contate o administrador do sistema informando esta mensagem.");
				objeto.focus();
				return false;
			}
			
			if(objeto.getAttribute("vazio") == "nao")
			{
				if(objeto.value == "")
				{
					alert(mensagem + " não pode ficar em branco.");
					objeto.focus();
					return false;
				}
			}
			
			if(objeto.value != "" || objeto.getAttribute("tipo") == "lista")
			{
				if(objeto.getAttribute("tipo") != undefined)
				{
					switch (objeto.getAttribute("tipo"))
					{
						
						case "lista":
							
							if (objeto.selectedIndex == -1)
							{
								alert("Atenção!\n\n" + "Selecione pelo menos um item do campo " + objeto.getAttribute("nome"));
								return false;
							}
							break;
						
						case "email":
							
							texto1 = (objeto.value.indexOf("@"));
							
							if(texto1 < 2 || objeto.value.indexOf(".") < 1 || objeto.value.indexOf(".@") > 0 ||objeto.value.indexOf("@.") > 0 || objeto.value.indexOf(".com.br.") > 0 || objeto.value.indexOf("..") > 0)
							{
								alert(mensagem + " não parece estar correto.");
								objeto.focus();
								return false;
							}
							texto2 = " /|!#$%¨&*()+='´`{}:?,;áéíóúýÁÉÍÓÚÝÀÈÌÒÙàèìòùâêîôûÂÊÎÔÛäëïöüÿÄËÏÖÜ";
							
							for(numero1=0;numero1<objeto.value.length;numero1++)
							{
								texto3 = objeto.value.substring(numero1,numero1+1);
								if(texto2.indexOf(texto3) != -1)
								{
									alert(mensagem + " não parece estar correto.");
									objeto.focus();
									return false;
								}
							}
							texto1 = "";
							texto2 = "";
							texto3 = "";
							numero1 = 0;
						break;
						
						
						
						
						case "moeda":
							texto1 = "1234567890,";
							
							numero1 = (objeto.value.indexOf(","));
							
							texto2 = objeto.value;
							
							if(numero1 == -1)
							{
								objeto.value = objeto.value + ",00";
								texto2 = objeto.value;
								numero1 = texto2.indexOf(",");
								
							}
							if(numero1 == (texto2.length)-2)
							{
								objeto.value = objeto.value + "0";
								texto2 = objeto.value;
								numero1 = texto2.indexOf(",");
							}
							if(numero1 == (texto2.length)-1)
							{
								objeto.value = objeto.value + "00";
								texto2 = objeto.value;
								numero1 = texto2.indexOf(",");
							}
							if(numero1 == 0)
							{
								objeto.value = "0" + objeto.value;
								texto2 = objeto.value;
								numero1 = texto2.indexOf(",");
							}
							if(numero1 != (texto2.length)-3)
							{
								alert(mensagem + " foi preenchido incorretamente.\n\nVocê pode preenchê-lo em seu formato inteiro ou no formato xx,xx, usando somente dígitos numéricos e/ou vírgula, com duas casas decimais.");
								objeto.focus();
								return false;
							}
							
							for(numero2=0;numero2<texto2.length;numero2++)
							{
								texto3 = texto2.substring(numero2,numero2+1);
								
								if(texto3 == ",")
								{
									numero3 += 1;
								}
								if(numero3 > 1 || texto1.indexOf(texto3) == -1)
								{
									alert(mensagem + " foi preenchido incorretamente.\n\nVocê deve preenchê-lo em seu formato inteiro ou no formato xx,xx, usando somente dígitos numéricos e/ou vírgula, com duas casas decimais.");
									objeto.focus();
									return false;
								}
								
								while(texto2.indexOf("0") == 0 && texto2.indexOf(",") > 1)
								{
									objeto.value = texto2.substring(1,(objeto.length));
									texto2 = objeto.value;
								}
							}
							
							texto1 = "";
							texto2 = "";
							texto3 = "";
							
							numero1 = 0;
							numero2 = 0;
							numero3 = 0;
							
							
						break;
						
						
						
						
						case "cep":
							
							texto1 = "1234567890-";
							if(objeto.value.length < 8 || objeto.value.length > 9)
							{
								alert(mensagem + " deve conter de 8 ou 9 dígitos.");
								objeto.focus();
								return false;
							}
							if(objeto.value.length == 8 && objeto.value.indexOf("-") == -1)
							{
								objeto.value = (objeto.value.substring(0,5) + "-" + objeto.value.substring(5,objeto.value.lenght));
							}
							for(numero1=0;numero1<objeto.value.length;numero1++)
							{
								texto2 = objeto.value.substring(numero1,numero1+1);
								
								if(texto1.indexOf(texto2) == -1)
								{
									alert(mensagem + " foi digitado incorretamente. Preencha-o somente com números e -");
									objeto.focus();
									return false;
								}
								if(texto2 == "-"){
									
									numero2 += 1;
									if(numero2 > 1)
									{
										alert(mensagem + " não pode conter mais que um hífen.");
										objeto.focus();
										return false;
									}
									if(numero1 != 6)
									{
										alert(mensagem + " não foi preenchido corretamente.");
										objeto.focus();
										return false;
									}
								}
							}
							
							texto1 = "";
							texto2 = "";
							numero1 = 0;
							numero2 = 0;
							
						break;
						
						
						
						
						case "hora":
							
							texto1 = "1234567890:";
							
							if(objeto.value.length != 5 && objeto.value.length != 4 || objeto.value.length == 5 && objeto.value.substring(2,3) != ":" || objeto.value.length == 4 && objeto.value.indexOf(":") != -1)
							{
								alert(mensagem + " deve ser preenchido no formato xxxx ou xx:xx, apenas com números e/ou :, usando apenas números e :");
								objeto.focus();
								return false;
							}
							if(objeto.value.length == 4){objeto.value = objeto.value.substring(0,2) + ":" + objeto.value.substring(2,4);}
							
							for(numero1=0;numero1<objeto.value.length;numero1++)
							{
								texto2 = objeto.value.substring(numero1,numero1+1);
								if(texto1.indexOf(texto2) == -1)
								{
									alert(mensagem + " deve ser preenchido no formato xxxx ou xx:xx, apenas com números e/ou :, usando apenas números e :");
									objeto.focus();
									return false;
								}
								if(texto2 == ":")
								{
									numero2 += 1;
									if(numero2 > 1)
									{
										alert(mensagem + " deve ser preenchido no formato xxxx ou xx:xx, apenas com números e/ou :, usando apenas números e :");
										objeto.focus();
										return false;
									}
								}
							}

							numero3 = parseInt(objeto.value.substring(0,2), 10);
							numero4 = parseInt(objeto.value.substring(3,5), 10);
							
							if(numero3 > 24 || numero4 > 59)
							{
								alert(mensagem + " não parece estar válido.");
								objeto.focus();
								return false;
							}
							
							texto1 = "";
							texto2 = "";
							
							numero1 = 0;
							numero2 = 0;
							numero3 = 0;
							numero4 = 0;
							
						break;
						
						
						
						
						case "data":
							
							texto1 = "1234567890/";
							
							if(objeto.value.length != 10 && objeto.value.length != 8 || objeto.value.length == 8 && objeto.value.indexOf("/") != -1 || objeto.value.length == 10 && objeto.value.substring(2,3) != "/" || objeto.value.length == 10 && objeto.value.substring(5,6) != "/")
							{
								alert(mensagem + " só pode ter 8 ou 10 dígitos e deve ser preenchido no formato ddmmaa ou dd/mm/aaaa");
								objeto.focus();
								return false;
							}

							if(objeto.value.length == 8)
							{
								objeto.value = objeto.value.substring(0,2) + "/" + objeto.value.substring(4,2) + "/" + objeto.value.substring(4,8);
							}
							
							
							numero1 = parseInt(objeto.value.substring(0,3), 10);
							numero2 = parseInt(objeto.value.substring(3,5), 10);
							numero3 = parseInt(objeto.value.substring(6,10), 10);
							numero4 = numero3 % 4;
							
							
							for(numero5=0;numero5<objeto.value.length;numero5++)
							{
								texto2 = objeto.value.substring(numero5,numero5+1);
								if(texto1.indexOf(texto2) == -1)
								{
									alert(mensagem + " foi digitado incorretamente. Preencha-o somente com números e /, no formato ddmmaa ou dd/mm/aaaa");
									objeto.focus();
									return false;
								}
								if(texto2 == "/")
								{
									numero6 += 1;
								}
								if(numero6 > 2)
								{
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa");
									objeto.focus();
									return false;
								}
								if(numero3 == 0){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o ano deve ser maior que 0.");
									objeto.focus();
									return false;
								}
								if(numero2 > 12 || numero2 == 0 ){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o mês não deve ser maior que 12 ou igual a zero.");
									objeto.focus();
									return false;
								}
								if(numero1 < 1 || numero1 > 31){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o dia não deve ser menor que 1 ou maior que 31.");
									objeto.focus();
									return false;
								}
								if(numero1 > 30 && numero2 == 4 || numero1 > 30 && numero2 == 6 || numero1 > 30 && numero2 == 9 || numero1 > 30 && numero2 == 11 ){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o dia não deve ser maior que 30 para o mês digitado.");
									objeto.focus();
									return false;
								}
								if(numero1 > 31 && numero2 == 1 || numero1 > 31 && numero2 == 3 || numero1 > 31 && numero2 == 5 || numero1 > 31 && numero2 == 7 || numero1 > 31 && numero2 == 8 || numero1 > 31 && numero2 == 10 || numero1 > 31 && numero2 == 12 ){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o dia não deve ser maior que 31 para o mês digitado.");
									objeto.focus();
									return false;
								}
								if(numero1 > 28 && numero2 == 2 && numero4 > 0){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o dia não deve ser maior que 28 para o mês digitado.");
									objeto.focus();
									return false;
								}
								if(numero1 > 29 && numero2 == 2){
									alert(mensagem + " deve ser preenchido no formato ddmmaa ou dd/mm/aaaa, sendo que o dia não deve ser maior que 29 para o mês digitado.");
									objeto.focus();
									return false;
								}
							}
							
							texto1 = "";
							texto2 = "";
							
							numero1 = 0;
							numero2 = 0;
							numero3 = 0;
							numero4 = 0;
							numero5 = 0;
							numero6 = 0;
							
						break;
						
						
						
						
						case "numero":
							texto1 = "1234567890";
							
							for(numero1=0;numero1<objeto.value.length;numero1++)
							{
								texto2 = objeto.value.substring(numero1,numero1+1);
								if(texto1.indexOf(texto2) == -1)
								{
									alert(mensagem + " deve ser preenchido somente com números");
									objeto.focus();
									return false;
								}
							}
							while(objeto.value.indexOf("0") == 0 && objeto.value.length > 1)
							{
								objeto.value = objeto.value.substring(1,(objeto.length));
							}
							
							texto1 = "";
							texto2 = "";
							
							numero1 = 0;
							
						break;
						
						
						
						
						case "cpfcnpj":

							texto1 = "1234567890./-"

							texto2 = objeto.value;
							
							
							for(numero1=0;numero1<texto2.length;numero1++)
							{
								texto3 = texto2.substring(numero1,numero1+1);
								if(texto3 == "." || texto3 == "-" || texto3 == "/")
								{
									texto2 = texto2.substring(0,numero1) + texto2.substring(numero1+1,texto2.length);
								}
								if(texto1.indexOf(texto3) == -1)
								{
									alert(mensagem + " foi preenchido com caracteres inválidos.");
									objeto.focus();
									return false;
								}
							}
							if(texto2.length == 11)
							{
								
								texto3 = texto2.substring(0,9);
								
								numero3 = 10;
								numero4 = 0

								for(numero3=10;numero3>1;numero3--)
								{
									numero2 = parseInt(texto3.substring(numero4,numero4 + 1));
									
									numero5 += numero3 * numero2;
									numero4 += 1;
								}

								
								numero4 = parseInt(numero5 / 11)*11;
								
								numero5 = numero5 - numero4;
								if(numero5 < 2)
								{
									numero2 = 0;
								}
								else
								{
									numero2 = 11 - numero5;
								}
								texto3 = texto3 + numero2.toString();
								
								numero3 = 11;
								numero4 = 0;
								numero5 = 0;
								for(numero3=11;numero3>1;numero3--)
								{
									numero2 = parseInt(texto3.substring(numero4,numero4 + 1));
									numero5 += numero3 * numero2;
									numero4 += 1;
								}	
								numero4 = parseInt(numero5 / 11)*11;
								numero5 = numero5 - numero4;

								if(numero5 < 2)
								{
									numero2 = 0;
								}
								else
								{
									numero2 = 11 - numero5;
								}
								texto3 = texto3 + numero2.toString();
								if(texto2 != texto3)
								{
									alert(mensagem + " não é um cpf válido.");
									objeto.focus();
									return false;
								}
							}
							else if(texto2.length == 14)
							{
								texto4 = texto2.substring(0,12);
								texto5 = "543298765432";
								
								for(numero2=0;numero2<12;numero2++)
								{
									numero3 = parseInt(texto4.substring(numero2,numero2+1));
									numero4 = parseInt(texto5.substring(numero2,numero2+1));
									numero5 += (numero3 * numero4);
								}
								numero6 = numero5 % 11;
								if(numero6 < 2){numero7 = 0}else{numero7 = 11 - numero6;}
								
								texto4 = texto4.toString() + numero7.toString();
								
								
								numero5 = 0;
								texto5 = "6543298765432";
								numero3 = 0;
								numero4 = 0;
								numero6 = 0;
								numero7 = 0;
								for(numero2=0;numero2<13;numero2++)
								{
									numero3 = parseInt(texto4.substring(numero2,numero2+1));
									numero4 = parseInt(texto5.substring(numero2,numero2+1));
									numero5 += (numero3 * numero4);
									
								}
								numero6 = 0;
								numero6 = numero5 % 11;
								if(numero6 < 2)
								{
									numero7 = 0
								}
								else
								{
									numero7 = 11 - numero6;
								}
										
								texto4 = texto4.toString() + numero7.toString();
																
								if(texto4 != texto2)
								{
									alert(mensagem + " não é um CNPJ válido.");
									objeto.focus();
									return false;
								}
								
							}else{
								alert(mensagem + " não existe.");
								objeto.focus();
								return false;
							}
							
							numero1 = 0;
							numero2 = 0;
							numero3 = 0;
							numero4 = 0;
							numero5 = 0;
							numero6 = 0;
							numero7 = 0;
							
							texto1 = "";
							texto2 = "";
							texto3 = "";
							texto4 = "";
							texto5 = "";
							break;
						
						case "senha_conf":
							if(objeto.value != obj.senha.value)
							{
								alert("Atenção\n\nAs senhas digitadas não conferem.");
								objeto.focus();
								return false;								
							}

							break;
					}
				}
			}
		}
	}
}
function ValidaMoeda(obj)
{
	valor = Replace(obj.value, ",", ".");
	if ((parseFloat(valor).toString() != "NaN") && (parseFloat(valor) == valor) && parseFloat(valor) != 0)
	{
		return true;
	}
	else if(parseFloat(valor) == 0)
	{
		alert("O campo " + obj.getAttribute("nome") + " não pode ser menor ou igual a zero.");
		obj.value = "";
		obj.focus();
		return false;
	}
	else
	{
		return false;
	}
}

function Replace(stringOriginal, stringA, stringB)
{
	if (stringOriginal.length > 0)
	{
		while (stringOriginal.indexOf(stringA) >= 0)
		{
			stringOriginal = stringOriginal.substring(0, stringOriginal.indexOf(stringA)) + stringB + stringOriginal.substring(stringOriginal.indexOf(stringA) + stringA.length, stringOriginal.length);
		}
		return stringOriginal;
	}
}

function soMoeda(objEvento)
{
	if (objEvento == null) objEvento = window.event;
	
	var keyCode = objEvento.keyCode;
	if ((!(keyCode > 47 && keyCode < 58)) && (keyCode != 44))
	{
		event.keyCode = 0;
	}
}
function soNumero(objEvento)
{
	if (objEvento == null) objEvento = window.event;
	
	var keyCode = objEvento.keyCode;
	if (!(keyCode > 47 && keyCode < 58))
	{
		event.keyCode = 0;
	}
}

function Centraliza(windowWidth, windowHeight)
{
	if (parseInt(navigator.appVersion, 10) >= 4)
	{
		window.moveTo((screen.width/2)-(windowWidth/2+10),(screen.height/2)-(windowHeight/2+20));
	}
}




//##########################################################################
//FUNÇÃO PARA REDIMENSIONAR A JANELA NO TAMANHO DA IMAGEM QUE ESTÁ ABRINDO
function reSizeImage() {
	//Pego o tamanho da tela Horizontal e Vertical
	var valorW = screen.width;
	var valorH = screen.height;
	//Pego o tamanho da imagem Horizontal e Vertical
	var width = document.getElementById('imagem').width;
	var height = document.getElementById('imagem').height;
	//Variavel que identifica se a imagem eh maior que a tela
	var estouro = false;
	//Se o tamanho Horizontal da imagem for maior que o tamanho da tela
	if ( width > valorW ) {
		//Calculo o tamanho vertical da imagem proporcional ao tamanho da tela
		height = retornaProporcional( width, height, valorW );
		width = valorW;
		//Redimensiono a imagem para o tamanho da tela
		//Diminuo um pouco a imagem para que ela seja exibida completa
		//Windows XP deixa uma barra maior na parte inferior do popup
		document.getElementById('imagem').width = width - 12;
		document.getElementById('imagem').height = height - 60;
		estouro = true;
	}
	//Se o tamanho Vertical da imagem for maior que o tamanho da tela
	if ( height > valorH ) {
		//Calculo o tamanho horizontal da imagem proporcional ao tamanho da tela
		width = retornaProporcional( height, width, valorH );
		height = valorH;
		//Redimensiono a imagem para o tamanho da tela
		//Diminuo um pouco a imagem para que ela seja exibida completa
		//Windows XP deixa uma barra maior na parte inferior do popup
		document.getElementById('imagem').width = width - 12;
		document.getElementById('imagem').height = height - 60;
		estouro = true;
	}
	if ( !estouro ) {
		width += 12;
		height += 60;
	}
	window.resizeTo(width+20,height+20);
	self.focus();
};

function doTitle(title) {
	//Altero o Titulo da janela
	document.title = title;
}

function retornaProporcional( x, y, valor ) {
	var retorno;
	//Calculo um valor proporcional para y de acordo com x e valor
	retorno = new Number( y / ( x / valor ) );
	return retorno.toFixed(0);
}

function openWindow(theURL,winName,winWidth,winHeight,features) {
  features = features+',width='+winWidth+',height='+winHeight+',top=0,left=0';
  window.open(theURL,winName,features);
}
//FIM REDIMENSIONA
//##########################################################################




///////////////////////////////////////  AJAX //////////////////////////////////////////////////////
fila=[];
ifila=0;
arrCache=[];
function initAd(){
	var ie = (document.all);
	if(!ie){return false;}
	adDiv=eval('document.all.carregando.style');
	randAd=Math.ceil(Math.random()*1);
	if(randAd==1) showAd();
}
function showAd(){
	documentWidth =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;
	adDiv.top =documentHeight+'px';
	setTimeout("showAd()",1);
}
function truebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function processaRetorno(url,data,cache){
	if(cache){
		var encontrou = false;
		for(x=0;x<arrCache.length;x++){
			if(arrCache[x][0] == url){
				encontrou = true;
				break;
			}
		}
		if(encontrou == false){
			arrCache[arrCache.length]=[url,data];
		}
	}
	data=unescape(data.replace(/\+/g," "));
	document.getElementById("carregando").style.display = "none";
	var temscript = false;
	expressao = /<script/;
	if(testarExpresao(expressao,data)){
		var ini = 0;
		while (ini!=-1){
			ini = data.indexOf('<script', ini);
			if (ini >=0){
				ini = data.indexOf('>', ini) + 1;
				var fim = data.indexOf('</script>', ini);
				var codigo = data.substring(ini,fim);
				var novo = document.createElement("script")
				novo.text = codigo;
				document.body.appendChild(novo);
				data = data.substring(0,data.indexOf('<script')) + data.substring(data.indexOf('</script>')+9);
				temscript = true;
			}
		}
	}
	if(fila[ifila][1].length > 0){
		retorno = document.getElementById(fila[ifila][1]);
		if(retorno.tagName.toLowerCase()=="input"){
			data=unescape(data.replace(/\+/g," "))
			retorno.value = data;
		}else if(retorno.tagName.toLowerCase()=="select"){        
			select_innerHTML(retorno,data)
		}else if(retorno.tagName){
			retorno.innerHTML = data;
		}
	}
	if(temscript){setTimeout("executaRetorno()",10);}
	ifila++;
	if(ifila<fila.length){
		if(fila[ifila][2]){
			document.getElementById("carregando").style.display = "block";
		}
		setTimeout("ajaxRun()",20)
	}
	function select_innerHTML(objeto,innerHTML){
		objeto.innerHTML = "";
		var selTemp = document.createElement("micoxselect");
		var opt;
		selTemp.id="micoxselect1";
		document.body.appendChild(selTemp);
		selTemp = document.getElementById("micoxselect1");
		selTemp.style.display="none";
		if(innerHTML.toLowerCase().indexOf("<option")<0){
			innerHTML = "<option>" + innerHTML + "</option>";
		}
		innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span");
		selTemp.innerHTML = innerHTML;
		for(var i=0;i<selTemp.childNodes.length;i++){
			if(selTemp.childNodes[i].tagName){
				opt = document.createElement("OPTION");
				for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
					opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true));
				}
				opt.value = selTemp.childNodes[i].getAttribute("value");
				opt.text = selTemp.childNodes[i].innerHTML;
				if(document.all){
					objeto.add(opt);
				}else{
					objeto.appendChild(opt);
				}                    
			}    
		}
		document.body.removeChild(selTemp);
		selTemp = null;
	}
	if(callback instanceof Function){ callback(); }
}
function solicitaAjax(url,retorno,carregando,cache,formulario){
	var taNaFila = false;
	for(x=ifila;x<fila.length;x++){
		if(fila[ifila][0] == url){
			taNaFila = true;
			break;
		}
	}
	if(taNaFila == false){
		if(formulario.length > 0){
			formulario = document.getElementById(formulario);
			if(formulario == null){alert("Atenção\n\nO formulário não foi encontrado.");}
			var send = new Array(); 
			var elementos = formulario.elements; 
			  
			for(var i = 0; i < elementos.length; i++) { 
				 var e = elementos[i]; 
				 if(!e.name) 
					 continue; 			  

				 var nVal = ""; 
          
				 for(var x = 0; x < e.value.length; x++) { 
					 codeA = e.value.charCodeAt(x); 
					 codeA = DecHex(codeA); 
					 nVal += "%" + codeA; 
				 }
				 
				 var tipo = e.type.toLowerCase();
				  
				if(tipo != "checkbox" && tipo != "radio") { 
				 	send[send.length] = e.id + "=" + nVal; 
				} else { 
					 if(e.checked) { 
						 send[send.length] = e.id + "=" + nVal; 
					 } 
				}
			 }
			 send = send.join("&");
		}
		
		fila[fila.length]=[url,retorno,carregando,cache,send];
	}
	if((ifila+1)==fila.length && taNaFila == false){
		 if(carregando){
				document.getElementById("carregando").style.display = "block";
		}
		ajaxRun();

	}
}

function DecHex(dec2) { 
 var hex_chars = "0123456789ABCDEF"; 

 var n1 = hex_chars.charAt(Math.floor(dec2 / 16)); 
 var n2 = hex_chars.charAt(dec2 % 16); 

 return n1 + n2; 
}
var callback;
function ajax(funcao,retorno,carregando,cache,formulario,parametros,pegaCallback){
	callback = pegaCallback;
	if(parametros != ""){
		url = ajaxFuncoes(funcao) + "&" + parametros;
	}else{
		url = ajaxFuncoes(funcao);
	}
	
	if(cache){
		if(arrCache.length>0){
			var encontrou = false;
			for(x=0;x<arrCache.length;x++){
				if(arrCache[x][0] == url){
					ifila -=1;
					processaRetorno(url,arrCache[x][1], false);
					encontrou = true;
					break;
				}
			}
			if(encontrou == false){
				solicitaAjax(url,retorno,carregando,cache,formulario);
			}
		}else{
			solicitaAjax(url,retorno,carregando,cache,formulario);
		}
	}else{
		solicitaAjax(url,retorno,carregando,cache,formulario);
	}
}
function ajaxRun(){
    var ajax1 = pegaAjax();
    if(ajax1){
		url = fila[ifila][0];
        ajax1.onreadystatechange = ajaxOnReady
		if(fila[ifila][4] != undefined){ 
			ajax1.open("POST", url, true); 
			ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		} else { 
			ajax1.open("GET", url ,true);
		}
        ajax1.setRequestHeader("Cache-Control", "no-cache");
        ajax1.setRequestHeader("Pragma", "no-cache");
	   if(fila[ifila][4] != undefined) { 
			 ajax1.send(fila[ifila][4]);
		 } else { 
			 ajax1.send(null); 
		 }
    }else{
        return false;
    }
    function ajaxOnReady(){
        if (ajax1.readyState==4){
			if(ajax1.status == 200){
				var data=ajax1.responseText;
				processaRetorno(fila[ifila][0],data, fila[ifila][3]);
			}else{
				if(fila[ifila][2]){
					document.getElementById("carregando").style.display = "none";
					if(callback instanceof Function){ callback(); }
					}
				alert(httpStatus(ajax1.status));
				ifila++;
            	if(ifila<fila.length){
					if(fila[ifila+1][2]){
						document.getElementById("carregando").style.display = "block";
					}
					setTimeout("ajaxRun()",20)
				}
			}
			ajax1 = null;
        }
    }
    function pegaAjax(){
        if(typeof(XMLHttpRequest)!='undefined'){return new XMLHttpRequest();}
        var axO=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
        for(var i=0;i<axO.length;i++){ try{ return new ActiveXObject(axO[i]);}catch(e){} }
        return null;
    }   
	
	function httpStatus(stat){
        switch(stat){
            case 0: return "Erro desconhecido de javascript";
            case 400: return "400: Solicitção incompreensível"; break;
            case 403: case 404: return "404: Não foi encontrada a URL solicitada"; break;
            case 405: return "405: O servidor não suporta o método solicitado"; break;
            case 500: return "500: Erro desconhecido de natureza do servidor"; break;
            case 503: return "503: Capacidade máxima do servidor alcançada"; break;
            default: return "Erro " + stat + ". Mais informações em http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"; break;
        }
    }
}
function testarExpresao(expressao,string){
	if(expressao.test(string) != true){
		return false;
	}else{
		return true;
	}
}
