function getHTTPObject() {
	var req;
	req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	return req;
}
var req = getHTTPObject();
var req1 = getHTTPObject();
var req2 = getHTTPObject();


function convertTextToHTML(s) {
	s = s.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br />").replace(/  /g, "&nbsp; ");
	return s;
}

function BuscaPais(id_continente)
{

	req.open("POST", "a2c_cms/modules/assistencia/php/carrega_pais.php?id_continente="+id_continente, true);
	req.onreadystatechange = function() 
	{
		if(req.readyState == 4) 
		{
			var html = req.responseText
			var lista = document.getElementById("htm_id_pais")
			lista.innerHTML = html;
			BuscaEstado('');
			BuscaCidade('');
		}
	};
	
	req.setRequestHeader('Content-Type', 'text/html; charset=iso-8859-1');
	req.send("");
}

function BuscaEstado(id_pais)
{

	req1.open("POST", "a2c_cms/modules/assistencia/php/carrega_estado.php?id_pais="+id_pais, true);
	req1.onreadystatechange = function() 
	{
		if(req1.readyState == 4) 
		{
			var html = req1.responseText
			var lista = document.getElementById("htm_id_estados")
			lista.innerHTML = html;
			BuscaCidade('');
		}
	};
	
	req1.setRequestHeader('Content-Type', 'text/html; charset=iso-8859-1');
	req1.send("");
}

function BuscaCidade(id_estados)
{

	req2.open("POST", "a2c_cms/modules/assistencia/php/carrega_cidade.php?id_estados="+id_estados, true);
	req2.onreadystatechange = function() 
	{
		if(req2.readyState == 4) 
		{
			var html = req2.responseText
			var lista = document.getElementById("htm_id_cidades")
			lista.innerHTML = html;
		}
	};
	
	req2.setRequestHeader('Content-Type', 'text/html; charset=iso-8859-1');
	req2.send("");
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function ValidAuto() {
	var form = document.getElementById("form");
	var id_continente = document.getElementById("id_continente");
	var id_pais = document.getElementById("id_pais");
	var id_estados = document.getElementById("id_estados");
	var id_cidades = document.getElementById("id_cidades");
	
	
	// Regra para a validação de e-mail.
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if(removeSpaces(id_continente.value) == "") {
		alert("Selecione o continente");
		id_continente.focus();
		return;
	}
	/*
	if(removeSpaces(id_pais.value) == "") {
		alert("Selecione o País");
		id_pais.focus();
		return;
	}
	
	if(removeSpaces(id_estados.value) == "") {
		alert("Selecione o Estado");
		id_estados.focus();
		return;
	}
	
	if(removeSpaces(id_cidades.value) == "") {
		alert("Selecione a Cidade");
		id_cidades.focus();
		return;
	}
		*/
	form.submit();
}


