   function abrirPopup(url,w,h){ 
	   window.open(url,null,' left='+(screen.width - w)/2 +',top='+(screen.height - h)/2 +',height='+ h +',width='+ w +',scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	
   }
		
	function trim(obj1){
	    if(obj1.value==undefined){
	      str=obj1;
	    }
	    else{
	      str=obj1.value;
	    }
	    
		while (str.charAt(0) == " ")
		str = str.substr(1,str.length -1);
		
		while (str.charAt(str.length-1) == " ")
		str = str.substr(0,str.length-1);
		obj1.value=str;
		return str;
	} 
	function estaVazio(obj){	 
	  if((obj.type=="text"||obj.type=="textarea" ||obj.type=="password") && trim(obj)==''){
	    return true;  
	  }
	  else if(obj.type=="file" && trim(obj)==''){
	    return true;
	  }
	  else{
	    if(obj.type=='select-multiple' && obj.length==0){
	      return true;
	    }
	  }
	  return false;
	}
  function validarCamposForm(form){
	   for(var i=0;i<form.length;i++){
	     if(form[i].lang!="" && form[i].disabled==false){
	       vizinho=document.getElementById(form[i].name+"Label");	       
	       if(vizinho!=null){
	       	 escreverBlackLabel(vizinho);
	       }	 
		     if(form[i].type=='text'||form[i].type=='textarea' || form[i].type=='password'){
		       if(estaVazio(form[i])){		    	  
			       anexarMensagem("- O campo "+form[i].lang+" não pode estar vazio");
			       escreverRedLabel(vizinho);
			       continue;
			     } 
		     }	     
		     
		     if(form[i].type=='checkbox' && !form[i].checked){		    	
		    	 anexarMensagem("- A opção "+form[i].lang+" deve ser marcado.");
			     escreverRedLabel(vizinho);
			       continue;
		     }	 
		     
		     if(form[i].type=='select-multiple'||form[i].type=='select-one'){
		       mensagemLocal="- Selecione Pelo menos um(a)  ";
		       if(form[i].type=='select-multiple'&& !estaVazio(form[i])){
			       continue;
		       } 
		       if(form[i].type=='select-one' ){
             mensagemLocal="- Selecione um  ";
		         if(form[i].value!='-999' && form[i].value!='-995'){// o valor -995 é o valor do indice.zero,pois aqui 
		         //não é possível usar <message...
		           continue;
		         }  
		       }    
           escreverRedLabel(vizinho);
		       anexarMensagem(mensagemLocal+form[i].lang);
		    }
		    if(form[i].type=='file'){
		         if(form[i].type=='file' && estaVazio(form[i])){
		           anexarMensagem("- Adicione seu Curriculo");
		           escreverRedLabel(vizinho);
		           continue;
		         }
		         
		    }
		  }  
	   }
	 }
	 function escreverBlackLabel(vizinho){
	   if(vizinho!=null){
	     vizinho.style.cssText='color:black';		       
	   }
	 }  
	 function escreverRedLabel(vizinho){
	   if(vizinho!=null){
	     vizinho.style.cssText='color:red';		       
	   }
	 }
	 function anexarMensagem(anexo){
	   mensagem+=anexo+"\n";
	 
	 }
	 function validarCamposFormComAlert(form){
	    validarCamposForm(form);
	    if(mensagem!=""){
	       alert(mensagem)
	       mensagem="";
	  	   return false;
	  	} 
  	   return true;
	 }
	function soNumero(e){
		if (document.all) // Internet Explorer
		  var tecla = event.keyCode;
		else
		  if(document.layers) // Nestcape
		    var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		// if (tecla < 47 || tecla > 58) // letras de A a Z
		  return true;
		else{
		  if (tecla != 8) // backspace
		    event.keyCode = 0;//return false;
		  else
		   return true;
		  alert("Digite somente números");
		}
	}
  function 	mascararTelefone(obj,evento){
    soNumero(evento);
    txtBoxFormat(obj,'9999-9999',evento);
  }
	 
   function	mascararData(obj,evento){
    soNumero(evento);
    txtBoxFormat(obj,'dd/mm/aaaa',evento);
  }
	 
function isCpfValido(obj){
	 s =String(obj.value).replace(/\.|-/gi,"")
	  
	 if (isNaN(s)) {
	  return false;
	 }
	 var i;
	 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;
}
  // recebe um objeto tipo select e  retorna o valor do texto selectionado
	function getTextSelecionado(objSelect){
	    indice=objSelect.selectedIndex;
	    return objSelect.options[indice].text;
  }
    function selecionarMultiple(obj){
    for(var i=0;i<obj.length;i++){
      obj.options[i].selected=true;
    }
  }
  
  //Formata um valor numérico para moeda Ex:1500 para 15,00
  // Ex no Form <input id="valor" onKeyPress="formataValor(this.id, 10, event)" size="10" />      
  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 );}
}
}

//faz replace de .(ponto) para ,(vírgula)
    function tirarPonto(obj) {        
      obj.value = obj.value.replace('.', '');                
    }
    
 // Recebe um objeto tipo check 
 // os elementos a serem selecinados devem ter o mesmo nome até o que seleciona todos.
     function checarTodos(obj){
	       var form=obj.form;
		   for(i=0;i<form.length;i++){
		       if(form[i]!=obj && obj.name==form[i].name){
		          form[i].checked=obj.checked;
		       }
		   }
       }


  //valida email ex.: onBlur="validarEmail();"
  function validarEmail() {
	  if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) && form.email.value!="") {
			mensagem+="\n- É necessário o preenchimento de um endereço de e-mail válido.";
			return false;
	  }	
		return true;
  }
  
  	   function validarFormLink(form){	     
	   var retorno = validarCamposFormComAlert(form);	   
	     if(retorno){
	     	form.submit();	     	
	     }
	      
	   }
	   
	   
	  function limparCampos(form) {
		for(i=0;i<form.length;i++){
			var obj = form[i];
			if(obj.type=="text" || obj.type=="textarea"){
				obj.value='';		
		 	}   
	    }
	    		
		var todosSelect = document.getElementsByTagName("select");    	 	
    	for( x = 0; x < todosSelect.length; x++ ) {
        	todosSelect[x].selectedIndex = 0 ;
    	}
	  }
	  function preecherHoras(objSelect){
	      for(var i=0;i<24;i++){
	        texto=i>9?i:('0'+i)
	        objSelect.options[i+1]=new Option(texto,texto)
	      }  
	  }
	  function preecherMinutos(objSelect){
	      var j=1;
	      for(var i=0;i<60;i+=10){
	        texto=(i!=0)?i:('0'+i);        
	        objSelect.options[j++]=new Option(texto,texto)
	      }  
	  }
	  //#### recebe um objeto textArea ou text e a largura desejada, se tiver um contador no mesmo forme ele conta'.
	  function contadorTexarea(obj,maxLength) { 
	      if (maxLength !=0) { 
	         if (obj.value.length > maxLength)  {      
	            obj.value = obj.value.substring(0, maxLength); 
	            }
	      }
	      var contador=obj.form.contador;
	      if(contador!=null){
	         contador.value = obj.value.length +' /'+maxLength;          
	      }
	   } 
	   
	function abrirPopup2(url,w,h){ 
	   window.open(url,null,' left='+(screen.width - w)/2 +',top='+(screen.height - h)/2 +',height='+ h +',width='+ w +',scrollbars=no,status=no,toolbar=no,menubar=no,location=no,resizable=no');
	
    }
	