var xmlHttp = new Object();
var idCont;

function _jsPage() {
	if (_jsPage.arguments.length == 1) idCont = "tdCont";
	else idCont = _jsPage.arguments[1];
	page = _jsPage.arguments[0];

	if (window.XMLHttpRequest) xmlHttp=new XMLHttpRequest()
	else if (window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	xmlHttp.onreadystatechange = _jsDone
	xmlHttp.open("GET", page, true)
	xmlHttp.send(null)
}

function _jsDone() { 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById(idCont).innerHTML = xmlHttp.responseText;
	}
	else {
		document.getElementById(idCont).innerHTML = "<img src=\"../img/imgCarregando.gif\" style=\"margin:2px 2px 2px 2px;\">";
	}
}

function _jsGeraSelect(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("../inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}

function _jsPreview03(imgSrc,displayType,divName,imgName) {
	document.getElementById(divName).style.display = displayType;	
	document.getElementById(imgName).src = imgSrc;	
}

function allLeft2Right() {
  var listOri = document.getElementById("listOrigem")
  var listDest = document.getElementById("listDestino");
  for(var i = 0; i < listOri.length; i++) {
    var opcao = listOri.options[i];
    var novaOpcao = new Option(opcao.text, listDest.length);
    novaOpcao.value = opcao.value;
    listOri.remove(i);
    try {
      listDest.add(novaOpcao,null);
    } catch (e) {
      listDest.add(novaOpcao);
    }
    i--;
  }
}

function allRight2Left() {
  var listOri = document.getElementById("listOrigem")
  var listDest = document.getElementById("listDestino");
  for(var i = 0; i < listDest.length; i++) {
    var opcao = listDest.options[i];
    var novaOpcao = new Option(opcao.text, listOri.length);
    novaOpcao.value = opcao.value;
    listDest.remove(i);
    try {
      listOri.add(novaOpcao,null);
    } catch (e) {
      listOri.add(novaOpcao);
    }
    i--;
  }
}

function left2Right() {
  var listOri = document.getElementById("listOrigem")
  var listDest = document.getElementById("listDestino");
  for(var i = 0; i < listOri.length; i++) {
    var opcao = listOri.options[i];
    if(opcao.selected) {
      var novaOpcao = new Option(opcao.text, listDest.length);
      novaOpcao.value = opcao.value;
      listOri.remove(i);
      try {
        listDest.add(novaOpcao,null); //Firefox
      } catch(e) {
        listDest.add(novaOpcao); //IE
      }
      i--;
    }
  }
}

function right2Left() {
  var listOri = document.getElementById("listOrigem")
  var listDest = document.getElementById("listDestino");
  for(var i = 0; i < listDest.length; i++) {
    var opcao = listDest.options[i];
    if(opcao.selected) {
      var novaOpcao = new Option(opcao.text, listOri.length);
      novaOpcao.value = opcao.value;
      listDest.remove(i);
      try {
        listOri.add(novaOpcao,null);
      } catch (e) {
        listOri.add(novaOpcao);
      }
      i--;
    }
  }
}

function _jsDocumentos(OrderBy) {
	if (!OrderBy) document.getElementById("listOrigem").options.length = 0;
	else {
		page = "acoes.php?Acao=23&OrderBy="+OrderBy;
		if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest()
		else if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
		xmlHttp.onreadystatechange = _jsDone2
		xmlHttp.open("GET", page, true)
		xmlHttp.send(null)
	}
}

function _jsDone2() { 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("listOrigem").options.length = 0;
		var varDocumentos = xmlHttp.responseText.split(";");
		for(i=0;i<=(varDocumentos.length-1);i++) {
			if (varDocumentos[i]) {
				var varDoc = varDocumentos[i].split(",")
				option = new Option(varDoc[0],varDoc[1]);
				try {
					document.getElementById("listOrigem").add(option,null);
				} catch (e) {
					document.getElementById("listOrigem").add(option);
				}
			}
		}
	}
}

function popup(x,n,w,h,s) {
    var l = ( (window.screen.width  - w) / 2 );
    var t = ( (window.screen.height - h) / 2 );
   janelinha = window.open(x,n,'leftmargin=-15,topmargin=-15,marginheight=0,marginwidth=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
}
/*
function _jsAnotarCurriculo(Curriculo_Id) {
	popup('curriculoAnotacao.php?Curriculo_Id='+Curriculo_Id, '', '450', '550', 'yes');
}
*/

function estatisticaCurriculo(Curriculo_Id){
	popup('/php/popCurriculoEstatisticas.php?Curriculo_Id='+Curriculo_Id, '', '250', '300', 'yes');	
}

function _jsVerCurriculo(Curriculo_Id) {
	popup('/php/curriculoVer.php?Curriculo_Id='+Curriculo_Id, '', '450', '550', 'yes');
}

function _jsCurriculoDetalhe(Curriculo_Id) {
	popup('/php/curriculoDetalhe.php?Curriculo_Id='+Curriculo_Id, '', '700', '545', 'yes');
}

function _jsVagaDetalhe(Vaga_Id) {
	popup('/php/vagasDetalhe.php?Vaga_Id='+Vaga_Id, '', '700', '545', 'yes');
}

function _jsMostraArquivos(Arquivo) {
	if(document.getElementById(Arquivo).style.display == 'none')
		document.getElementById(Arquivo).style.display = '';
	else
		document.getElementById(Arquivo).style.display = 'none';
}

function _jsValContato() {
	if (document.frm1.Fale_Nome.value == '') {
		alert('Você deve preencher o seu nome completo');	
		document.frm1.Fale_Nome.focus();
		return false;
	}
	
	if (document.frm1.Fale_DDD.value == '') {
		alert('Você deve preencher o DDD do seu telefone');	
		document.frm1.Fale_DDD.focus();
		return false;
	}

	if (document.frm1.Fale_Telefone.value == '') {
		alert('Você deve preencher o número do seu telefone');	
		document.frm1.Fale_Telefone.focus();
		return false;
	}

	if (document.frm1.Fale_Email.value == '' || document.frm1.Fale_Email.value.indexOf("@") == -1 || document.frm1.Fale_Email.value.indexOf(".") == -1) {
		alert('Você deve preencher o seu e-mail corretamente');	
		document.frm1.Fale_Email.focus();
		return false;
	}

	if (document.frm1.Fale_Cidade.value == '') {
		alert('Você deve preencher o nome de sua cidade');	
		document.frm1.Fale_Cidade.focus();
		return false;
	}
	
	if (document.frm1.Fale_Estado.value == '') {
		alert('Você deve preencher o estado');	
		document.frm1.Fale_Estado.focus();
		return false;
	}

	if (document.frm1.Fale_Mensagem.value == '') {
		alert('Você deve preencher a mensagem');	
		document.frm1.Fale_Mensagem.focus();
		return false;
	}	
}

function mascaraData(campoData, id){
	var campo = campoData;
	var data = campoData.value;
	if (data.length == 2){
		data = data + '/';
		document.getElementById(id).value = data;
		return true;
	}              
	if (data.length == 5){
		data = data + '/';
		document.getElementById(id).value = data;
		return true;
	}         
}


function FormataValor(id,tammax,teclapres) {
   
    if(window.event) 
	{ // Internet Explorer
	 var tecla = teclapres.keyCode; 
	}
	else if(teclapres.which) 
	{ // Nestcape / firefox
	 var tecla = teclapres.which;
    }
	vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
		if (tecla == 8 ){ tam = tam - 1; }
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
		document.getElementById(id).value = vr; }
		if ( (tam > 2) && (tam <= 5) ){
		document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 6) && (tam <= 8) ){
		document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 9) && (tam <= 11) ){
		document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 12) && (tam <= 14) ){
		document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 15) && (tam <= 17) ){
		document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}

function Mascara (formato, keypress, objeto){
	campo = eval (objeto);
	
    if(window.event) 
	{ // Internet Explorer
	 var tecla = teclapres.keyCode; 
	}
	else if(teclapres.which) 
	{ // Nestcape / firefox
	 var tecla = teclapres.which;
    }
	
	
	// cep
	if (formato=='cep'){
		separador = '-';
		conjunto1 = 5;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}
	}
	
	// cpf
	if (formato=='cpf'){
		separador1 = '.'; 
		separador2 = '-'; 
		conjunto1 = 3;
		conjunto2 = 7;
		conjunto3 = 11;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador1;
		}
		if (campo.value.length == conjunto2){
		 	campo.value = campo.value + separador1;
		}
		if (campo.value.length == conjunto3){
		 	campo.value = campo.value + separador2;
		}
	}
	
	// nascimento
	if (formato=='nascimento'){
		separador = '/'; 
		conjunto1 = 2;
		conjunto2 = 5;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador;
		}
	}
	
	// telefone
	if (formato=='telefone'){
		separador1 = '(';
		separador2 = ')';
		separador3 = '-';
		conjunto1 = 0;
		conjunto2 = 3;
		conjunto3 = 8;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador1;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador2;
		}
		if (campo.value.length == conjunto3){
			campo.value = campo.value + separador3;
		}
	}
}


function _jsImagemPreview(imgSrc,displayType,divName,imgName) {
	document.getElementById(divName).style.display = displayType;	
	document.getElementById(imgName).src = imgSrc;	
}

function _jsValidaCPF(CPF){ 
 	var i; 
	s = CPF  
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(10-i); 
	} 
	 
	if (d1 == 0) { 
		return false; 
	} 
	  
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) { 
 		return false;   
	} 
	  
	d1 *= 2; 	  
	for (i = 0; i < 9; i++)  {   
		d1 += c.charAt(i)*(11-i); 
	} 
	  
	d1 = 11 - (d1 % 11); 

	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) { 
		return false; 
	} 
	  
	return true; 
}

function valida_cnpj(cnpj){
	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;
	if (cnpj.length != 14) 
		  return false;
	for (i = 0; i < cnpj.length - 1; i++)
		  if (cnpj.charAt(i) != cnpj.charAt(i + 1))
				{
				digitos_iguais = 0;
				break;
				}
	if (!digitos_iguais)
		  {
		  tamanho = cnpj.length - 2
		  numeros = cnpj.substring(0,tamanho);
		  digitos = cnpj.substring(tamanho);
		  soma = 0;
		  pos = tamanho - 7;
		  for (i = tamanho; i >= 1; i--)
				{
				soma += numeros.charAt(tamanho - i) * pos--;
				if (pos < 2)
					  pos = 9;
				}
		  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		  if (resultado != digitos.charAt(0))
				return false;
		  tamanho = tamanho + 1;
		  numeros = cnpj.substring(0,tamanho);
		  soma = 0;
		  pos = tamanho - 7;
		  for (i = tamanho; i >= 1; i--)
				{
				soma += numeros.charAt(tamanho - i) * pos--;
				if (pos < 2)
					  pos = 9;
				}
		  resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		  if (resultado != digitos.charAt(1))
				return false;
		  return true;
		  }
	else
		  return false;
} 


function _jsSubmitPlano(id) {
	if (document.getElementById(id).value == '' || document.getElementById(id).value.indexOf("@") == -1 || document.getElementById(id).value.indexOf(".") == -1) {
		alert('Voce deve digitar um e-mail valido.');
		document.getElementById(id).value = '';
		document.getElementById(id).focus();
		return false;
	}
}

function _jsSubmitPlanoEmpresa(id) {
	if (document.getElementById(id).value == '' || document.getElementById(id).value.indexOf("@") == -1 || document.getElementById(id).value.indexOf(".") == -1) {
		alert('Voce deve digitar um e-mail valido.');
		document.getElementById(id).value = '';
		document.getElementById(id).focus();
		return false;
	}
}

function _jsBuscaCargo(area, cargo, idCont){
	_jsPage("acoes.php?Acao=76&Vaga_Nome="+cargo+"&Vaga_Area="+area,idCont);
}

function _jsBuscaCargoPhp(area, cargo, idCont){
	_jsPage("acoes.php?Acao=24&Vaga_Nome="+cargo+"&Vaga_Area="+area,idCont);
}

function _jsChangeCargo(area, cargo, idCont){
	_jsPage("acoes.php?Acao=77&Area_Id="+area+"&Cargo_Id="+cargo, idCont);	
}


function _jsChangeCargoInterno(area, cargo, idCont){
	_jsPage("acoes.php?Acao=50&Area_Id="+area+"&Cargo_Id="+cargo, idCont);	
}

function _jsChangeCargoPhp(area, cargo, idCont){
	_jsPage("acoes.php?Acao=25&Area_Id="+area+"&Cargo_Id="+cargo, idCont);		
}