//Inicialização do Objeto AJAX
function ObjetoXMLHttp()
{
	try{
		xmlhttp = new XMLHttpRequest();
	}
	catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E){
				xmlhttp = false;
			}
		}
	}
return xmlhttp;
}

function verEmail(email)
{
	var ok = "<span class=\"sucesso\"><img src=\"util/img/icones/sucesso.png\" width=\"16\" height=\"16\" border=\"0\" align=\"top\" /> E-mail válido.<span>";
	var nook = "<span class=\"erro\"><img src=\"util/img/icones/erro.png\" width=\"16\" height=\"16\" border=\"0\" align=\"top\" /> E-mail j&aacute; cadastrado.<span>";
	
	objb = window.document.getElementById("status_email");
	if(checkMail(email))
	{
		obj = ObjetoXMLHttp();
		obj.open("GET", "util/php/common/verEmail.php?email="+email,true);
		obj.onreadystatechange=function() 
		{
			if ((obj.readyState==1) || (obj.readyState==2) || (obj.readyState==3))
				objb.innerHTML = "<img src=\"util/img/icones/load.gif\" align=\"top\" border=\"0\"> Pesquisando, aguarde...";
			
			if (obj.readyState==4)
			{
				if(obj.responseText == '1')
				{
					objb.innerHTML = ok;
					document.getElementById("auxmail").value = 1;
				}
				else
				{
					objb.innerHTML = nook;
					document.getElementById("auxmail").value = 0;
				}
			}
		}
		obj.send(null);
	}
	else
	{
		objb.innerHTML = "<span class=\"erro\"><img src=\"util/img/icones/erro.png\" width=\"16\" height=\"16\" border=\"0\" align=\"top\" /> E-mail inválido.<span>";
		document.getElementById("auxmail").value = 0;
	}
}


function pegaCidades(estado)
{
	obj = ObjetoXMLHttp();
	obj.open("GET", "util/php/common/pega_cidades.php?estado="+estado,true);
	obj.onreadystatechange=function() 
	{
		if ((obj.readyState==1) || (obj.readyState==2) || (obj.readyState==3))
			window.document.getElementById("data").innerHTML = "<img src=\"util/img/icones/load.gif\" align=\"top\" border=\"0\"> Pesquisando, aguarde...";
		
		if (obj.readyState==4)
			window.document.getElementById("data").innerHTML = obj.responseText;
	}
	obj.send(null);
}


function candidatarVaga(iduser,idvaga,local)
{
	var ok = "<div class=\"interesseSucesso\">Interesse registrado com sucesso.</div>";
	var nook = "Ocorreu um erro. Tente novamente.";
	
	var objb = ObjetoXMLHttp();
	objb.open("GET", "util/php/common/vaga.php?iduser="+iduser+"&idvaga="+idvaga,true);
	objb.onreadystatechange = function() 
	{
		if ((objb.readyState==1) || (objb.readyState==2) || (objb.readyState==3))
			window.document.getElementById(local).innerHTML = "<img src=\"util/img/icones/load.gif\" align=\"top\" border=\"0\"> Em execução. Por favor aguarde...";
		
		if (objb.readyState==4)
		{
			window.document.getElementById(local).innerHTML = ok;
		}
	}
	objb.send(null);
}
