function redireciona(pagina)
{
	location = pagina;	
}
function adicionarValor(idPrincipal,idDestino,idHidden)
{
	if(document.getElementById("emailComplementar").value=="")
	{
		alert("Preencha o campo email complementar para adicionar emails.");
	}
	else
	{
		var valorCampo = document.getElementById(idPrincipal).value;
		document.getElementById(idHidden).value = document.getElementById(idDestino).value;
	
		var valorHidden = document.getElementById(idHidden).value;
		if(valorHidden)
		{
			document.getElementById(idDestino).value = valorHidden+", "+valorCampo;
		}
		else
		{
			document.getElementById(idDestino).value = valorCampo;
		}
		document.getElementById(idPrincipal).value = "";
	}
}

function adicionarValor2(idPrincipal,idDestino,idHidden)
{
	if(document.getElementById("emailComplementarSinac").value=="")
	{
		alert("Preencha o campo email para adicionar emails.");
	}
	else
	{
		var valorCampo = document.getElementById(idPrincipal).value;
		document.getElementById(idHidden).value = document.getElementById(idDestino).value;
	
		var valorHidden = document.getElementById(idHidden).value;
		if(valorHidden)
		{
			document.getElementById(idDestino).value = valorHidden+", "+valorCampo;
		}
		else
		{
			document.getElementById(idDestino).value = valorCampo;
		}
		document.getElementById(idPrincipal).value = "";
	}
}

function adicionarValorEstado(estado,cidade)
{
	var idEstado = document.getElementById(estado).value;
	var idCidade = document.getElementById(cidade).value;
	
	if((!idEstado) || (!idCidade))
	{
		alert("Favor preencher os campos corretamente");
		return false;
	}
	else
	{
		url = '../listaCidadesEstados.inc.php?estado='+idEstado+'&cidade='+idCidade;
		req = null;
		// Procura por um objeto nativo (Mozilla/Safari)
		if (window.XMLHttpRequest) 
		{
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChangeCidadesEstado;
			req.open("GET",url,true);
			req.send(null);
			// Procura por uma versão ActiveX (IE)
		} 
		else if (window.ActiveXObject) 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) 
			{
				req.onreadystatechange = processReqChangeCidadesEstado;
				req.open("GET",url,true);
				req.send();
			}
		}
	}
}
function processReqChangeCidadesEstado()
{
	// apenas quando o estado for "completado"
	if (req.readyState == 4) 
	{
		// apenas se o servidor retornar "OK"
		if (req.status == 200) 
		{
			var string = req.responseText;
			var separaValor = string.split("!!!");
			
			//alert(string);
			
			if(document.getElementById("hiddenRelFiliais").value=="")
			{
				document.getElementById("relFiliais").value = separaValor[1]+" - "+separaValor[0]+"\n";
			}
			else
			{
				document.getElementById("relFiliais").value = document.getElementById("hiddenRelFiliais").value+separaValor[1]+" | "+separaValor[0]+"\n";	
			}
			document.getElementById("hiddenRelFiliais").value =document.getElementById("relFiliais").value;
		} 
		else
		{	
			alert("Houve um problema ao obter os dados:n" + req.statusText);
		}
	}
}
function pulaData(id,idProx)
{
	var data = document.getElementById(id).value;
	if(data.length==2)
	{
		document.getElementById(id).value = data+"/";		
	}
	if(data.length==5)
	{
		document.getElementById(id).value = data+"/";		
	}
	if(data.length==10)
	{
		document.getElementById(idProx).focus();
	}
}
function pulaDDD(idTel,Prox)
{
	var tel = document.getElementById(idTel).value;
	if(tel.length==2)
	{
		document.getElementById(Prox).focus();
	}	
}
function pulaTel(idTel,Prox)
{
	var tel = document.getElementById(idTel).value;
	if(tel.length==4)
	{
		document.getElementById(idTel).value = tel+"-";
	}
	if(tel.length==9)
	{
		document.getElementById(Prox).focus();
	}
}

function pulaTelAssociado(idTel,Prox)
{
	var tel = document.getElementById(idTel).value;
	if(tel.length==2)
	{
		document.getElementById(idTel).value = tel+" ";
	}
	if(tel.length==7)
	{
		document.getElementById(idTel).value = tel+"-";
	}
	if(tel.length==12)
	{
		document.getElementById(Prox).focus();
	}
}

