//Insere "." e "," de um valor(reais)
function formataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1[campo].value;
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.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.form1[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form1[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form1[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form1[campo].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.form1[campo].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.form1[campo].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 ) ;}
	}			
}

//Deixa digitar somente números.
function somenteNumero(e){
	var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58) || tecla == "0" || tecla == "9") return true;
	    else{
    if (tecla != 8) return false;
    	else return true;
    }
}

//Mascar para preenchimento dos formulários
function aplicaMascara(Mascara, elemento){    
    // Seta o elemento
    var elemento = (elemento) ? elemento : document.getElementById(elemento); 
    if(!elemento) return false;
    
    // Método que busca um determinado caractere ou string dentro de uma Array
    function in_array( oque, onde ){
            for(var i = 0 ; i <onde.length; i++){
            if(oque == onde[i]){
                return true;
            }
        }
        return false;
    }
    // Informa o array com todos os caracteres que podem ser considerados caracteres de mascara
    var SpecialChars = [':', '-', '.', '(',')', '/', ',', '_'];
    var oValue = elemento.value;
    var novo_valor = '';
    for( i = 0 ; i <oValue.length; i++){
        //Recebe o caractere de mascara atual
        var nowMask = Mascara.charAt(i);
        //Recebe o caractere do campo atual
        var nowLetter = oValue.charAt(i);
        //Aplica a masca
        if(in_array(nowMask, SpecialChars) == true && nowLetter != nowMask){
            novo_valor +=  nowMask + '' + nowLetter;
        } else {
            novo_valor += nowLetter;
        }
        // Remove regras duplicadas
        var DuplicatedMasks = nowMask+''+nowMask;
        while (novo_valor.indexOf(DuplicatedMasks)>= 0) {
         novo_valor = novo_valor.replace(DuplicatedMasks, nowMask);
        }
    }
    // Retorna o valor do elemento com seu novo valor
    elemento.value = novo_valor;
}

//Apaga um curriculo pelo seqprofissional
function excluirCurriculo(seqProf) {	
	var ajaxRequest; 	

	if (confirm('Tem certeza que deseja excluir?')){

		url = "funcoes/curriculoAjax.asp?cod=apagar&seqProf="+seqProf
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Seu navegador não está funcionando corretamente!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete"){			
				var texto = ajaxRequest.responseText;				
				
				if (texto != ''){
					alert(texto);
					window.location = '../'
				}
				else {
					alert('Ocorreu um erro ao excluir.')
				}	
	}
		}	
		ajaxRequest.open("GET",url, true);	
		ajaxRequest.send(null);	
	}	
}

//Publica um curriculo pelo seqprofissional
function curriculo(seqProf) {	
	var ajaxRequest, msg, area,cont,i, campo; 	

	msg = '';	
	cont = 0;
	area = '';
		
	if (document.form1.experiencia.value == ''){
		msg = msg + 'O campo exepriência não foi preenchido.\n'
	}
	if (document.form1.telefone.value == ''){
		msg = msg + 'O campo telefone não foi preenchido.\n'
	}
	if (document.form1.salario.value == ''){
		msg = msg + 'O campo salário não foi preenchido.\n'
	}

	for (i=1 ; i <=14 ; i++){		
		if (document.form1['c'+i].checked)
			area = area + '1'
		else
			area = area + '0'		
	}
	
	if (area == '00000000000000'){
		msg = msg + 'Pelo menos uma área deverá ser selecionada.\n'		
	}
	
	if (msg != '') {
		alert(msg)
	}
	else{
		
		experiencia = document.form1.experiencia.value;
		telefone = document.form1.telefone.value;		
		salario = document.form1.salario.value;		
		mudar = (document.form1.mudar_0.checked) ? 'S' : 'N';		
		m = (document.form1.m.checked) ? '1' : '0'
		t = (document.form1.t.checked) ? '1' : '0'
		n = (document.form1.n.checked) ? '1' : '0' 
		horario = m+''+t+''+n
		combinarSalario = (document.form1.combinarSalario_0.checked) ? 'S' : 'N';
		cursos = document.form1.cursos.value;
		complemento = document.form1.complemento.value;

		if (document.form1.temCurriculo.value == 'sim') {		
			url = "funcoes/curriculoAjax.asp?cod=editar&seqProf="+seqProf+"&experiencia="+experiencia+"&telefone="+telefone+"&salario="+salario+"&mudar="+mudar+"&horario="+horario+"&combinarSalario="+combinarSalario+"&cursos="+cursos+"&complemento="+complemento+"&area="+area
		}
		else {
			url = "funcoes/curriculoAjax.asp?cod=novo&seqProf="+seqProf+"&experiencia="+experiencia+"&telefone="+telefone+"&salario="+salario+"&mudar="+mudar+"&horario="+horario+"&combinarSalario="+combinarSalario+"&cursos="+cursos+"&complemento="+complemento+"&area="+area
			
		}	
		
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Seu navegador não está funcionando corretamente!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete"){			
				var texto = ajaxRequest.responseText;				
				alert(texto)
			}
		}	
		ajaxRequest.open("GET",url, true);	
		ajaxRequest.send(null);			
	}
}

function procuraCurriculo(){
	var ajaxRequest; 
	var url, cont, sql, i, area;
	
	document.getElementById("msgCurriculo").innerHTML = '';
	
	area = '';	
	cont = 0;
	
	for (i=1 ; i <=14 ; i++){		
		if (document.form1['c'+i].checked){
			area = area + '1'
			cont++;
		}
		else{
			area = area + '0'		
		}
	}		
	
	if (cont == 0){
		alert('Selecione pelo menos uma área para a consulta.')		
	}
	else{						
		url = "busca.asp?cod=busca&area="+area
	}

	try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Seu navegador não está funcionando corretamente!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete"){			
				var texto = ajaxRequest.responseText;							
				document.getElementById("msgCurriculo").innerHTML = texto;		
			}
		}	
		ajaxRequest.open("GET",url, true);	
		ajaxRequest.send(null);		
}


function verCurriculo(seqProfissional){
	var ajaxRequest; 
	var url;	
		
	
	if(document.getElementById('Img'+seqProfissional).alt == "foto1") {
				
		document.getElementById('Img'+seqProfissional).src = "imagens/dif.png";
		document.getElementById('Img'+seqProfissional).alt = "foto2";		
		document.getElementById('Linha'+seqProfissional).style.color = '#F00';

		url = "funcoes/curriculoAjax.asp?cod=ver&seqProfissional="+seqProfissional

		try{
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e){
						// Something went wrong
						alert("Seu navegador não está funcionando corretamente!");
						return false;
					}
				}
			}
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4 || ajaxRequest.readyState=="complete"){			
					var texto = ajaxRequest.responseText;
					document.getElementById(seqProfissional).style.display = '';					
					document.getElementById('L'+seqProfissional).innerHTML = texto;									
				}
			}	
			ajaxRequest.open("GET",url, true);	
			ajaxRequest.send(null);		

			
	}
	else {		
		document.getElementById('Img'+seqProfissional).src="imagens/soma.png";
		document.getElementById('Img'+seqProfissional).alt = "foto1";		
		document.getElementById(seqProfissional).style.display = 'none';
		document.getElementById('Linha'+seqProfissional).style.color = '#000';
	}	
}