////////////////////////////////////
/////////// REWEB 2007 /////////////
////////////////////////////////////

function tryAjax () {
	
	try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
      
      return ajax;
}

//--------------------------------------------
function getValor( objId ){ return document.getElementById( objId ).value }

//--------------------------------------------
function incluiExperiencia(acao,expId){
	
	var ajax = tryAjax();
	var obj  = document.getElementById('exp_cadastradas');
	var php  = "index.php?on=contato&in=ajax&etapa=experiencia";
	var parametros = "";
	
	parametros += "&ac=" + acao;
	parametros += "&experiencia_id=" + expId;
	
	if (acao == 'incluir'){
		parametros += "&empresa=" + getValor('empresa');
		parametros += "&cargo=" + getValor('cargo');
		parametros += "&setor=" + getValor('setor');
		parametros += "&contato=" + getValor('contato');
		parametros += "&desligamento=" + getValor('desligamento');
		parametros += "&atribuicoes=" + getValor('atribuicoes');
	}
	
	
	if(ajax) {
		
		ajax.open("POST", php, true); // TRUE PARA NÃO SER SÍNCRONO
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  
		ajax.onreadystatechange = function () {
			
			if (ajax.readyState == 4) {
				if (ajax.status != 200) 
					loading('divLoader');
				else {
					if (ajax.status == 200) {
						obj.innerHTML = ajax.responseText;
						ajustaAltura();
					} else {
						hideLoader('divLoader');
						alert('ERRO: '+ajax.statusText);
					}
				}
			}
		};
		ajax.send(parametros);	 
	}
}

//--------------------------------------------
function incluiFormacao(acao,formId){
	
	var ajax = tryAjax();
	var obj = document.getElementById('formacao');
	var php  = "index.php?on=contato&in=ajax&etapa=formacao";
	var parametros = "";
	
	parametros += "&ac=" + acao;
	parametros += "&formacao_id=" + formId;
	
	if (acao == "incluir"){
		parametros += "&grau=" + getValor('grau');
		parametros += "&curso=" + getValor('curso');
		parametros += "&entidade=" + getValor('entidade');
		parametros += "&outra_universidade=" + getValor('outra_universidade');
		parametros += "&status=" + getValor('status');
		parametros += "&mes=" + getValor('mes');
		parametros += "&ano=" + getValor('ano');
	}
	
	if(!getValor('grau') || !getValor('curso') || !getValor('entidade')) {
		document.getElementById('formacao_id').innerHTML = "<span style='color:#900'>Campos marcados com asterisco são de preenchimento obrigatório.</span>";
	} else {
		if (ajax){
			
			ajax.open("POST", php, true);	// TRUE PARA NAO SER SINCRONO
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.onreadystatechange = function (){
				
				if (ajax.readyState == 4) {
					if (ajax.status != 200) 
						loading('divLoader');
					else {
						if (ajax.status == 200) {
							//hideLoader('divLoader');
							document.getElementById('formacao_id').innerHTML = "";
							obj.innerHTML = ajax.responseText;
							ajustaAltura();
							location = "?on=contato&in=trabalhe&ac=formacao";
						} else {
							hideLoader('divLoader');
							alert('ERRO: '+ajax.statusText);
						}
					}
				}
			};
			ajax.send(parametros);
		}
	}
}

//--------------------------------------------
function reloadNoticia(irPara){
	
	var ajax = tryAjax();
	var php = "index.php?on=capa&in=ajax";
	var news_id = getValor('noticia_id');
	var alvo = document.getElementById('reload_noticia');
	
	var parametros = 'noticia_id='+news_id + '&goto='+irPara;
	
	if (ajax){
		
		ajax.open("POST", php, true);	// TRUE PARA NAO SER SINCRONO
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function (){
			
			if (ajax.readyState == 4) {
				if (ajax.status != 200) 
					loading('divLoader');
				else {
					if (ajax.status == 200) {
						alvo.innerHTML = ajax.responseText;
					} else {
						alert('ERRO: '+ajax.statusText);
					}
				}
			}
		};
		ajax.send(parametros);
	}
	
}