// JavaScript Document
function alteraCampoCor(id,status) 
{
	//alert('ok');
	if(status=='on')
	{
		$D(id).style.backgroundColor="#EDECFF";
	}
	else
	{
		$D(id).style.backgroundColor="";
	}
}
function tiraDiv(id,divObriga,divValida)
{
	if(divObriga != 'off')
	{
		$D(divObriga).style.display = 'none';
	}
	if(divValida != 'off')
	{
		$D(divValida).style.display = 'none';
	}
}
//APARECE A DIV NA PAGINA INICIAL
function apareceDiv(idOn,idOn2,idOff,idOff2)
{
	$D(idOn).style.display = '';
	$D(idOn2).style.display = '';
	$D(idOff).style.display = 'none';
	$D(idOff2).style.display = 'none';
	$DN('publico')[0].checked  = false;
	$DN('publico')[1].checked  = false;
}
//COLOCA O VALOR NO HIDDEN
function valorHidden(id)
{
	$D(id).value = '1';
}

//APARECE CAMPO CPF OU PASSAPORT
function mostraCampo(id)
{
	if($D(id).value == '')
	{
		$D('trPassaport').style.display = 'none';
		$D('trCpf').style.display = 'none';
	}
	else if($D(id).value == 'Brasil')
	{
		$D('trCpf').style.display = '';
		$D('passaporte').value = '';
		$D('trPassaport').style.display = 'none';
	}
	else if($D(id).value != 'Brasil')
	{
		$D('cpf').value = '';
		$D('trCpf').style.display = 'none';
		$D('trPassaport').style.display = '';
	}
}
//PULA CPF
function cpfPula(id,nextId)
{
	var cpf = $D(id).value;
	if(cpf.length == 3)
	{
		$D(id).value = cpf+".";
	}
	if(cpf.length == 7 )
	{
		$D(id).value = cpf+".";	
	}
	if(cpf.length == 11 )	
	{
		$D(id).value = cpf+"-";
	}
	if(cpf.length == 14 )	
	{
		$D(nextId).focus();
	}
}
//PULA CNPJ
function cnpjPula(id,nextId) 
{
	var cnpj = $D(id).value;
	if(cnpj.length == 2)
	{
		$D(id).value = cnpj+".";
	}
	if(cnpj.length == 6 )
	{
		$D(id).value = cnpj+".";
	}
	if(cnpj.length == 10 )
	{
		$D(id).value = cnpj+"/";
	}
	if(cnpj.length == 15 )
	{
		$D(id).value = cnpj+"-";
	}
	if(cnpj.length == 18 )	
	{
		$D(nextId).focus();
	}
}
function cnpjPula2(id,nextId) 
{
	var cnpj = $D(id).value;
	if(cnpj.length == 4)
	{
		$D(id).value = cnpj+"-";
	}
	if(cnpj.length == 7 )	
	{
		$D(nextId).focus();
	}
}
//PULA DATA
function mudaData(id,nextId)
{	
	var data = $D(id).value;	
	if(data.length == 2)	
	{		
		$D(id).value = data+'/';	
	}	
	else if(data.length == 5)	
	{			
		$D(id).value = data+'/';
	}
	else if(data.length == 10)	
	{	
		$D(nextId).focus();	
	}
}

//MUDA TEL COMPLETO
function mudaTelCompleto(id,nextId,evento)
{	
	var nTecla = '';
	if(evento.keyCode) nTecla = evento.keyCode; 
	else if(document.layers && navigator.appName.indexOf("Mozilla") == -1) 	nTecla = evento.which; 	
	else 	nTecla = evento.which; 
	
	//alert(nTecla);
	if(nTecla != '8')
	{	
		var tel = $D(id).value;	 
		if((tel.length == 2) && (id=="telefone1"))
		{		
			$D(id).value = '('+tel+') ';	
			$D("telefone2").focus();	
		}
		else if((tel.length == 4) && (id=="telefone2"))	
		{			
			$D(id).value = tel;	
			$D("telefone3").focus();
		}
		else if((tel.length == 4) && (id=="telefone3"))	
		{			
			$D(nextId).focus();	
		}
	}
}
//APARECE CAMPO HIDDEN
function apareceCampo(id,idHid,valor,trHidden)
{
	if($D(id).value == valor)
	{
		$D(idHid).style.display = '';
		$D(trHidden).style.display = '';
	}
	else
	{
		$D(idHid).style.display = 'none';		
		$D(trHidden).style.display = 'none';
	}
}



//APAGA VALOR DO CAMPO
function apagaCampo(id)
{
	$D(id).value = '';
}


//AJAX
function enviarForm(url,campos) 
{	
	//Executa a função objetoXML()
	objetoXML(); 
	if(!xmlhttp) 
	{ 	//Se o objeto de 'xmlhttp' não estiver true
		//	elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.'; 
		//Insere no 'elemento' o texto atribuído
		alert('Impossivel iniciar o objeto XMLHttpRequest.');
		return;
	} 
	else 
	{ 
		//Senão
		//vaiCarregar();
		//	elemento.innerHTML = 'Carregando...'; //Insere no 'elemento' o texto atribuído
	}
	xmlhttp.onreadystatechange = function () 
	{
    	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) 
		{ //Se a requisição estiver completada
    		if (xmlhttp.status == 200) 
			{ //Se o status da requisição estiver OK
			//alert(xmlhttp.responseText);
    		//	elemento.innerHTML = xmlhttp.responseText; //Insere no 'elemento' a página postada
				//if(xmlhttp.responseText=='1')
				//{
					
					$D('divContatoFormularioBranco').style.display = 'none';
					$D('divContatoEnviado').style.display = '';
				//}
				//alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open('POST', url, true); //Abre a página que receberá os campos do formulário
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
    xmlhttp.setRequestHeader("Content-length", campos.length);
    xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(campos); //Envia o formulário com dados da variável 'campos' (passado por parâmetro)
}
