// JavaScript Document
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var mx,my,scl,sct;
var dobj;

function movemouse(e)
{
    
	scl = nn6 ? window.pageXOffset : document.body.scrollLeft;
	sct = nn6 ? window.pageYOffset : document.body.scrollTop;
	
	
    mx = nn6 ? e.clientX  :  event.clientX;
    my  = nn6 ?  e.clientY :  event.clientY;
	
	mx = mx + scl;
	my = my + sct;
    return false;
  
}

<!-- Begin


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var keyCode ; var filter;
function autoTab(input,len, e) {
keyCode = (isNN) ? e.which : e.keyCode; 
filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
return true;
}
//  End -->

function stripNaN( event ) { 
	if ( !event ){
		 var event = window.event; 
	}
	if ( event.keyCode ){
		     if ( event.keyCode <= 46 || event.keyCode > 57 ){
				   event.returnValue = false; 
			 }
	}else{ 
	    
		if ( (event.which < 45 || event.which > 57) ){
		        event.preventDefault();
	     }
	}
}


function enter_tab( event,frm,campo) { 
	if ( !event ) var event = window.event;
	//var oEvent = (oEvent)? oEvent : event;
	if ( event.keyCode==13 ) { 
	nome = campo.id;
	var c_forms;
	for (c_forms = 0; c_forms < frm.length; c_forms++) {
	   //alert(document.form.elements.length);
	    if(frm.elements[c_forms].id == nome){
          //alert(document.form.elements[i].id);
		  if(frm.elements[c_forms+1]){
			if(document.form.elements[c_forms+1]){
			   document.form.elements[c_forms+1].focus();
			}
		  }
        }
     }
	
	}
}


function enter_submit( event,frm,campo) { 
	if ( !event ) var event = window.event;
	//var oEvent = (oEvent)? oEvent : event;
	if ( event.keyCode==13 ) { 
	nome = campo.id;
	var c_forms;
	frm.submit();
	
	}
}

function enter( event,frm,campo,acao) { 
	if ( !event ) var event = window.event;
	//var oEvent = (oEvent)? oEvent : event;
	if ( event.keyCode==13 ) { 
	
	    setTimeout(acao,100);
	}
}

function enter_acao( event,acao,time) { 
	if ( !event ) var event = window.event;
	//var oEvent = (oEvent)? oEvent : event;
	if ( event.keyCode==13 ) { 
	
	    setTimeout(acao,time);
	}
}

function foco(id){
	if(document.getElementById(id)){
	   document.getElementById(id).focus();	
	}else{
	  //setTimeout("foco("+id+")",200);	
	}
}

function dividi_data(data,campo_dia,campo_mes,campo_ano) { 
	//alert('teste');
	document.getElementById(campo_dia).value  = data.substr(0,2);
	document.getElementById(campo_mes).value  = data.substr(3,2);
	document.getElementById(campo_ano).value  = data.substr(6,4);
	
}

function atualiza_data(campo_oculto,campo_dia,campo_mes,campo_ano) { 
	document.getElementById(campo_oculto).value = document.getElementById(campo_dia).value+"/"+document.getElementById(campo_mes).value+"/"+document.getElementById(campo_ano).value;	
}


function selecionar_todos(id,frm,checked){
var str = id;
for (var i = 0; i < frm.elements.length; i++) {
 if(frm.elements[i].id.substring(0,str.length) == str){
    frm.elements[i].checked = checked;
 }
}
}

function is_numeric(src) { 
  var numero = src.value;
  //alert(numero.length);
  numero = numero.substring(numero.length-1,numero.length);
  
  numero = numero.replace(/[^0-9]/g, "");
  
  var numero2 = src.value;
  src.value = numero2.substring(0,numero2.length - 1) + numero; 
}

function mascara_data(campo_data)
{
       var mydata = '';
       mydata = mydata + campo_data.value;
       if (mydata.length == 2)
           {
                mydata = mydata + '/';
              campo_data.value = mydata;
       }
       if (mydata.length == 5)
           {
                  mydata = mydata + '/';
                  campo_data.value = mydata;
       }
       if (mydata.length == 10)
           {
             //verifica_data(campo_data);
       }
}


function valida_data(data) 
{

	dia = (data.substring(0,2));
	mes = (data.substring(3,5));
	ano = (data.substring(6,10));
	situacao = "";
	
	// verifica o dia valido para cada mes
	if ((dia < 01)||((dia < 01) || (dia > 30)) && ((mes == '04') || (mes == '06') || (mes == '09') || (mes == '11') ) || dia > 31) 
	{
		situacao = "falsa";
	}
	
	// verifica se o mes e valido
	if (mes < 01 || mes > 12 ) 
	{
		situacao = "falsa";
	}
	
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) 
	{
		situacao = "falsa";
	}
	
	if (1900>ano || ano>2100) 
	{  
		situacao = "falsa";
	}
	
	if (data == "") 
	{
		situacao = "falsa";
	}
	
	if (situacao == "falsa") 
	{
	    return(false);
	}else{
	   return(true);
   }
	
}


function mascara_hora(hora)
{
	
  var myhora = '';
  myhora = myhora + hora;
  
  if (myhora.length == 2)
  {
	  myhora = myhora + ':';
	  hora.value = myhora;
  }
  
  if (myhora.length == 5)
  {
	  verifica_hora(hora);
  }
  
}

function verifica_hora(hora)
{
	
  hrs = (hora.value.substring(0,2));
  hrm = (hora.value.substring(3,5));
  
  situacao = "";
  
  // verifica data e hora
  if ((hrs < 00 ) || (hrs > 23) || ( hrm < 00) ||( hrm > 59))
  {
	  situacao = "falsa";
  }
  
  if (document.forms[0].hora.value == "") 
  {
	  situacao = "falsa";
  }

  if (situacao == "falsa") 
  {
	  alert("Hora inválida!");
	  hora.focus();
  }
  
}


function valida_cpf(numero) {
	//alert('teste');
	if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999"){
        alert("CPF inválido.");
		return(false);
    }
	var soma = resultado1 = resultado2 = 0;	
	numero = numero.replace(/[^0-9]/g, "");
	soma = 10 * parseInt(numero.substr(0,1)) + 9 * parseInt(numero.substr(1,1)) + 8 * parseInt(numero.substr(2,1)) + 7 * parseInt(numero.substr(3,1)) + 6 * parseInt(numero.substr(4,1)) + 5 * parseInt(numero.substr(5,1)) + 4 * parseInt(numero.substr(6,1)) + 3 * parseInt(numero.substr(7,1)) + 2 * parseInt(numero.substr(8,1));
	soma = soma - (11 * parseInt(soma / 11));
		(soma == 0 || soma == 1) ? resultado1 = 0 : resultado1 = 11 - soma;
	if (resultado1 == parseInt(numero.substr(9,1))) {
		soma = parseInt(numero.substr(0,1)) * 11 + parseInt(numero.substr(1,1)) * 10 + parseInt(numero.substr(2,1)) * 9 + parseInt(numero.substr(3,1)) * 8 + parseInt(numero.substr(4,1)) * 7 + parseInt(numero.substr(5,1)) * 6 + parseInt(numero.substr(6,1)) * 5 + parseInt(numero.substr(7,1)) * 4 + parseInt(numero.substr(8,1)) * 3 + parseInt(numero.substr(9,1)) * 2;
		soma = soma -(11 * parseInt(soma / 11));
		(soma == 0 || soma == 1) ? resultado2 = 0 : resultado2 = 11 - soma;
		if (resultado2 == parseInt(numero.substr(10,1))) {
			//alert("CPF válido.");
			return(true);
		} else {
			alert("CPF inválido.");
			return(false);
		}
	}
	else {
		alert("CPF inválido");
		return(false);
	}
}

function valida_cnpj(numero) {
	var soma = resultado1 = resultado2 = 0;
	numero = numero.replace(/[^0-9]/g, "");
	soma = 5 * parseInt(numero.substr(0,1)) + 4 * parseInt(numero.substr(1,1)) + 3 * parseInt(numero.substr(2,1)) + 2 * parseInt(numero.substr(3,1)) + 9 * parseInt(numero.substr(4,1)) + 8 * parseInt(numero.substr(5,1)) + 7 * parseInt(numero.substr(6,1)) + 6 * parseInt(numero.substr(7,1)) + 5 * parseInt(numero.substr(8,1)) + 4 * parseInt(numero.substr(9,1))+ 3 * parseInt(numero.substr(10,1))+ 2 * parseInt(numero.substr(11,1));
	soma = soma - (11 * parseInt(soma / 11));
	(soma == 0 || soma == 1) ?	resultado1 = 0 : resultado1 = 11 - soma;
	if (resultado1 == parseInt(numero.substr(12,1))) {
		soma = parseInt(numero.substr(0,1)) * 6 + parseInt(numero.substr(1,1)) * 5 + parseInt(numero.substr(2,1)) * 4 + parseInt(numero.substr(3,1)) * 3 + parseInt(numero.substr(4,1)) * 2 + parseInt(numero.substr(5,1)) * 9 + parseInt(numero.substr(6,1)) * 8 + parseInt(numero.substr(7,1)) * 7 + parseInt(numero.substr(8,1)) * 6 + parseInt(numero.substr(9,1)) * 5 + parseInt(numero.substr(10,1)) * 4 + parseInt(numero.substr(11,1)) * 3 + parseInt(numero.substr(12,1)) * 2;
		soma = soma - (11 * parseInt(soma / 11));
		(soma == 0 || soma == 1) ? resultado2 = 0 : resultado2 = 11 - soma;
		if (resultado2 == parseInt(numero.substr(13,1))) {
			//alert("CNPJ Válido");
			return(true);
		} else {
			alert("CNPJ inválido");
			return(false);
		}
	} else  {
		alert("CNPJ inválido");
		return(false);
	}
}


function scrollOver()
	  {
		if (document.form.cbScroller.checked)
		    {document.getElementById("scroller").scrollAmount='0'}
		else
		    {document.getElementById("scroller").scrollAmount='0'}
		document.getElementById("scroller").style.cursor='default'
	  }

function scrollOut()
	  {
		if (document.form.cbScroller.checked)
		    {document.getElementById("scroller").scrollAmount='0'}
		else
		    {document.getElementById("scroller").scrollAmount='2'}
	  }

function checkSBox(box)
	  {
		SBox = eval(box);
		SBox.checked = !SBox.checked;
		scrollOut();
	  }


function nova_janela(local,nomeJanela,w,h) {
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    path = local;
    janela = new Object();
    janela = window.open(path,nomeJanela,'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes');
    janela.focus();
}

//macromedia

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//fim macromedia

//funcoes Gerais
function foco(id){
 if(document.getElementById(id)){
	document.getElementById(id).focus(); 
 }	
  	
}

function muda_grande_grupo(){
   if(document.getElementById('grande_grupo').value!=""){
	  ajax('profissao.php?grande_grupo='+document.getElementById('grande_grupo').value,'div_subgrupo');
   }
}

function mostra_logo(id){
  document.onmousemove=movemouse;
  ajax('submit.php?acao=mostra_logo&id='+id+'&left='+mx+'&top='+my,'div_atualiza');
}
function mostra_foto(id){
  document.onmousemove=movemouse;
  ajax('submit.php?acao=mostra_foto&id='+id+'&left='+mx+'&top='+my,'div_atualiza');
}

function mostra_foto_site(foto, id){
  document.onmousemove=movemouse;
 
  		ajax('submit.php?acao=mostra_foto&id='+id+'&foto='+foto+'&left='+mx+'&top='+my,'div_atualiza');

}

function mostra_info(id){
    document.onmousemove=movemouse;
	ajax('submit.php?acao=mostra_info&id='+id+'&left='+mx+'&top='+my,'div_atualiza');
}

function limpa_div(id){
  setTimeout("document.getElementById('"+id+"').innerHTML = ''",100);
}
function mostra_cidades(id_estado,id_cidade,campo_cidade){
  if(!campo_cidade){
	 ajax('/intranet/estado_cidade/select_cidade.php?acao=mostra_cidades&id_estado='+id_estado+'&id_cidade='+id_cidade,'div_cidade');  
  }else{
	ajax('/intranet/estado_cidade/select_cidade.php?acao=mostra_cidades&id_estado='+id_estado+'&id_cidade='+id_cidade+'&name='+campo_cidade,'div_'+campo_cidade);
  }
}

function mostra_func(id_empresa,id_funcionario){
	
  if(!document.getElementById('funcionario') || document.getElementById('funcionario').value == ""){	
     ajax('/intranet/funcionario/select_funcionario.php?acao=mostra_funcionarios&id_empresa='+id_empresa+'&id_funcionario='+id_funcionario,'div_func');
   }else{
	   document.getElementById('funcionario').value = "";
	   document.form.submit();
   }
}

function limpa_campo(id){
	document.getElementById(id).value = '';
}


//fim funcoes Gerais
// Formata o campo valor
function float2moeda(num) {

   x = 0;

   if(num<0) {
      num = Math.abs(num);
      x = 1;
   }
    if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);

   num = Math.floor((num*100+0.5)/100).toString();

   if(cents < 10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
         num = num.substring(0,num.length-(4*i+3))+'.'
               +num.substring(num.length-(4*i+3));
			     ret = num + ',' + cents;
				   if (x == 1) ret = ' - ' + ret;return ret;

}


function formata_valor(valor){
  valor = float2moeda(valor);
  return(valor);
}


// Formata o campo valor
function formataValor(campo) {
	//campo.value = filtraCampo(campo);	
	
	vr = Limpar(campo.value, "0123456789");
	tam = vr.length;

	if ( tam <= 2 ){ 
 		campo.value = vr ; }
 	if ( (tam > 2) && (tam <= 5) ){
 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 6) && (tam <= 8) ){
 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 9) && (tam <= 11) ){
 		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) ){
 		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 <= 18) ){
 		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 ) ;}
 		
}



// Formata o campo valor
function verificaFormataValor(campo) {
	//campo.value = filtraCampo(campo);	
    if(campo.value.length==1 || campo.value.length==2){
	  campo.value = campo.value + "00";
	}
	
	formataValor(campo);

}



function Limpar(valor, validos) {
  // retira caracteres invalidos da string
  var result = "";
  var aux;
  for (var i=0; i<valor.length; i++)
  {
    aux = validos.indexOf(valor.substring(i, i+1));
    if (aux>=0)
    {
    	result += aux;
    }
  }
  return result;
}

function desformata_valor(valor){
	valor = valor.replace(".", "");
	valor = valor.replace(",", ".");
	return(parseFloat(valor));
}

function acerta_valor(valor){
	valor = valor.replace(".", "");
	valor = valor.replace(",", ".");
	return(parseFloat(valor));
}