function abreJanela(URL) {
  var width = 504;
  var height = 300;
  var left = 50;
  var top = 10
  window.open(URL, 'noticias', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

function popup(URL,width,height,descricao) {
  var left = 50;
  var top = 10
  window.open(URL, 'descricao', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

//Ajax

carregandoHTML = '<div id="Carregando"><img src="images/loading.gif">&nbsp;<span>Carregando...</span></div>';
carregandoNews = '<br/><br/><br/><div id="Carregando"><span style="margin-left:20px">Enviando...</span></div>';

try{
	xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 }catch(e){
		 try{
			 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		 }catch(E){
			 xmlhttp = false;
		 }
	 }
 }

var ajax = {

	camposForm : function(idForm) {
		var aForm = document.getElementById(idForm);
		var elementosFormulario = aForm.elements;
		var qtdElementos = elementosFormulario.length;
		var queryString = "";
		var elemento;

		this.ConcatenaElemento = function(nome,valor) {
			if (queryString.length>0) {
				queryString += "&";
			}
			queryString += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
		};

		for (var i=0; i<qtdElementos; i++) {
			elemento = elementosFormulario[i];
			if (!elemento.disabled) {
				switch(elemento.type) {
					case 'text': case 'password': case 'hidden': case 'textarea':
							this.ConcatenaElemento(elemento.name,elemento.value);
					break;
					case 'select-one':
							if (elemento.selectedIndex>=0) {
						this.ConcatenaElemento(elemento.name,elemento.options[elemento.selectedIndex].value);
							}
							break;
					case 'select-multiple':
							for (var j=0; j<elemento.options.length; j++) {
						if (elemento.options[j].selected) {
							this.ConcatenaElemento(elemento.name,elemento.options[j].value);
						}
							}
							break;
					case 'checkbox': case 'radio':
							if (elemento.checked) {
						this.ConcatenaElemento(elemento.name,elemento.value);
							}
							break;
				}
			}
		}
//		aForm.reset();
		return queryString;
	},

	cadNewsletter : function(idform){
		param = ajax.camposForm(idform);

		xmlhttp.open('POST', '_newsletter.php', true);
		xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajax.resNewsletter;
		xmlhttp.send(param);
	},

	vdNewsletter : function(idform){
		 d = document.getElementById(idform);
		 if (d.news_nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.news_nome.focus();
		 	return false;
		 }
		 if (d.news_mail.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.news_mail.focus();
			 return false;
		 }
		 ajax.cadNewsletter(idform);
	 	 return true;
	 },

	resNewsletter : function(){

		 mensagens = document.getElementById('telaNewsletter');
		 mensagens.className='newsletterok';
		 
		 if(xmlhttp.readyState == 1)
		 mensagens.innerHTML = carregandoNews;

		 if(xmlhttp.readyState == 4) {
			 if(xmlhttp.status == 200) {
				 mensagens.innerHTML = xmlhttp.responseText;
			 }
		 }
	 },

	enviaEmail : function(idform){
		 param = ajax.camposForm(idform);

		 xmlhttp.open('POST', '_faleconosco.php', true);
		 xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		 xmlhttp.onreadystatechange = ajax.repostasAcao;
		 xmlhttp.send(param);
		 document.getElementById(idform).reset();
	},
	 
	vdContato : function(idform){
		 d = document.getElementById(idform);
		 if (d.nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.nome.focus();
		 	return false;
		 }
		 if (d.email.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.email.focus();
			 return false;
		 }
		 if (d.telefone.value == ""){
			 alert("O campo - Telefone - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.telefone.focus();
			 return false;
		 }
		 if (d.mensagem.value == ""){
			 alert("O campo - Mensagem - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.mensagem.focus();
			 return false;
		 }
		 ajax.enviaEmail(idform);
	 	 return true;
	 },

	cadCurriculum : function(idform){
		 param = ajax.camposForm(idform);

		 xmlhttp.open('POST', '_cadastro_talentoshumanos.php', true);
		 xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		 xmlhttp.onreadystatechange = ajax.repostasAcao;
		 xmlhttp.send(param);
		 document.getElementById(idform).reset();
	},

	vdCurriculum : function(idform){
		 d = document.getElementById(idform);
		 if (d.nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.nome.focus();
		 	return false;
		 }
		 if (d.cpf.value == ""){
			 alert("O campo - CPF - deve ser preenchido!");
			 d.cpf.className = 'formcontatoerro';
			 d.cpf.focus();
		 	return false;
		 }
		 if (d.data_nascimento.value == ""){
			 alert("O campo - Data Nascimento - deve ser preenchido!");
			 d.data_nascimento.className = 'formcontatoerro';
			 d.data_nascimento.focus();
			 return false;
		 }

		 if (d.endereco.value == ""){
			 alert("O campo - Endereço - deve ser preenchido!");
			 d.endereco.className = 'formcontatoerro';
			 d.endereco.focus();
			 return false;
		 }

		 if (d.bairro.value == ""){
			 alert("O campo - Bairro - deve ser preenchido!");
			 d.bairro.className = 'formcontatoerro';
			 d.bairro.focus();
			 return false;
		 }

		 if (d.cidade.value == ""){
			 alert("O campo - Cidade - deve ser preenchido!");
			 d.cidade.className = 'formcontatoerro';
			 d.cidade.focus();
			 return false;
		 }

		 if (d.cep.value == ""){
			 alert("O campo - CEP - deve ser preenchido!");
			 d.cep.className = 'formcontatoerro';
			 d.cep.focus();
			 return false;
		 }

		 if (d.email.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.email.focus();
			 return false;
		 }
		 if (d.telefone.value == ""){
			 alert("O campo - Telefone - deve ser preenchido!");
			 d.telefone.className = 'formcontatoerro';
			 d.telefone.focus();
			 return false;
		 }

		 if (d.curso_atual.value == ""){
			 alert("O campo - Curso Atual - deve ser preenchido!");
			 d.curso_atual.className = 'formcontatoerro';
			 d.curso_atual.focus();
			 return false;
		 }

		 if (d.curso_instituicao.value == ""){
			 alert("O campo - Instituicao - deve ser preenchido!");
			 d.curso_instituicao.className = 'formcontatoerro';
			 d.curso_instituicao.focus();
			 return false;
		 }

		 ajax.cadCurriculum(idform);
	 	 return true;
	 },

	 repostasAcao : function(){

		 mensagens = document.getElementById('verConteudo');
		 
		 if(xmlhttp.readyState == 1)
		 mensagens.innerHTML = carregandoHTML;

		 if(xmlhttp.readyState == 4) {
			 if(xmlhttp.status == 200) {
				 mensagens.innerHTML = xmlhttp.responseText;
			 }
		 }
	 },

	 abreLink : function(div,url){

		 local = document.getElementById(div);

		 xmlhttp.open('GET', url, true);
		 xmlhttp.onreadystatechange = function(){
			 if(xmlhttp.readyState == 1) {
				 local.innerHTML = carregandoHTML;
			 }
			 if(xmlhttp.readyState == 4) {
				 if(xmlhttp.status == 200){
					 local.innerHTML = xmlhttp.responseText;
				 }
			 }
		 }
		 xmlhttp.send(null);
	 }

}
