ie = (document.all)? true:false

function carrega_estudos(){
	ajax_carrega_nowait('ajax_chamada_home_canal.php?fk_id_canal=8','div_chamada_home');
	setTimeout("carrega_familia();", 30000);
}

function carrega_familia(){
	ajax_carrega_nowait('ajax_chamada_home_canal.php?fk_id_canal=29','div_chamada_home');
	setTimeout("carrega_jovem();", 30000);
}

function carrega_jovem(){
	ajax_carrega_nowait('ajax_chamada_home_canal.php?fk_id_canal=71','div_chamada_home');
	setTimeout("carrega_motivacional();", 30000);
}

function carrega_motivacional(){
	ajax_carrega_nowait('ajax_chamada_home_canal.php?fk_id_canal=9','div_chamada_home');
	setTimeout("carrega_testemunhos();", 30000);
}

function carrega_testemunhos(){
	ajax_carrega_nowait('ajax_chamada_home_canal.php?fk_id_canal=4','div_chamada_home');
	setTimeout("carrega_estudos();", 30000);
}

function carrega_canal_random(){
	ajax_carrega_nowait('ajax_canal_randomico_home.php?ajax=true','div_canal_random');
	setTimeout("carrega_canal_random();", 30000);
}

function textFormat(objField,evtKeyPress,mask) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

  if(ie) { // Internet Explorer
    nTecla = evtKeyPress.keyCode; }
  else  { // Nestcape
    nTecla = evtKeyPress.which;
  }
	
  //objField.form.procedimento_tabela_cd_tab_amb.value = nTecla+evtKeyPress.type;
  if ((nTecla==9)) 
      return true;
	if (evtKeyPress.type=='keydown'){ 
	   if ((nTecla==37) || (nTecla==39) || (nTecla==9)) //Seta para a direita seta para a esquerda
		    return false;
	return true;			
	}

  sValue = objField.value;
	
	var valor=false;
  if (mask.charAt(0)=='$'){
     mask = mask.substr(1);
		 valor = true;
	}	  
  
	if (evtKeyPress.type=='keypress') {
		 var digMask=mask.charAt(sValue.length);
     if ( digMask == "9") { // apenas números...
       return (( nTecla > 47) && (nTecla < 58));
		 } // números de 0 a 9
     else if (digMask == "a") { // alfa-numerico convertendo para minusculo...
		 if ( nTecla>=65 && nTecla<=90 ) 
       {
          key = String.fromCharCode(nTecla); 
          key = key.toLowerCase();
          if(ie) { // Internet Explorer
            event.keyCode=key.charCodeAt();}
          else {
            event.which=key.charCodeAt();
          }
       }
       return true; } 
    else if (digMask == "A") { // alfa-numerico convertendo para maiusculo...
		 if ( nTecla>=97 && nTecla<=122 ) 
       {
          key = String.fromCharCode(nTecla); 
          key = key.toUpperCase();
          if(ei) { // Internet Explorer
            event.keyCode=key.charCodeAt();}
          else {
            event.which=key.charCodeAt();
          }
       }
      return true; } 
    else if (digMask == "l") { // apenas letra convertendo para minusculo...
		 if (( nTecla>=65 && nTecla<=90 ) || ( nTecla>=97 && nTecla<=122 ))
       {
          key = String.fromCharCode(nTecla); 
          key = key.toLowerCase();
          if(ie) { // Internet Explorer
            event.keyCode=key.charCodeAt();}
          else {
            event.which=key.charCodeAt();
          }
      		return true;  
       }
       return false;}  
    else if (digMask == "L") { // apenas letra convertendo para maiusculo...
		 if (( nTecla>=65 && nTecla<=90 ) || ( nTecla>=97 && nTecla<=122 ))
       {
          key = String.fromCharCode(nTecla); 
          key = key.toUpperCase();
          if(ie) { // Internet Explorer
            event.keyCode=key.charCodeAt();}
          else {
            event.which=key.charCodeAt();
          }
      		return true;  
       }
       return false;}  
    else { // qualquer caracter...
      return true;
    } 
	}
  
	if(( nTecla <= 96) && (nTecla >= 105)){
		if(	((evtKeyPress.type=='keypress') || (evtKeyPress.type=='keyup')) ){
			var digMask = mask.charAt(sValue.length);
			if( digMask == '9' ){
				var typeMask = new RegExp("[qwertyuiopasdfghjklçzxcvbnmQWERTYUIOPASDFGHJKLÇZXCVBNM]");
				key = String.fromCharCode(nTecla);
				var retorno = typeMask.exec(key);
				if( retorno != null ){
					var ate = sValue.length - 1;
					sValue = sValue.substr(0,ate);
				}
			}
		}
	}
  // Limpa todos os caracteres de formatação que
  // já estiverem no campo.
	var sai;
	var typeMask = new RegExp ("[-.,\:;/()´`{}~^?+=_*&¨%$#@! ]");
	while ((sai=typeMask.exec(sValue)) != null) sValue = sValue.toString().replace( sai, "" );

  fldLen = sValue.length;
  mskLen = fldLen;

	if (nTecla == 8) mskLen--; //se for backspace tamanho-1

  sCod = "";
	if (!valor) {
    //formata deacordo com a mascara da esqueda para a direita
    nCount = 0;
  	for (var i=0; i<=mskLen; i++){
      if (typeMask.exec(mask.charAt(i))!=null) {
        sCod += mask.charAt(i);
        mskLen++; }
      else{
        sCod += sValue.charAt(nCount);
        nCount++;
      }
    }
	}else{
    //formata deacordo com a mascara da direita para a esqueda
		sValue *= 1;
		if (sValue==0) {
		   sValue = '';
		}else{
		   sValue += '';
		}
    fldLen = sValue.length;
		//objField.form.paciente_nr_ident.value = sValue+'-'+fldLen;
		/*if (fldLen==1){
		   sValue = '00'+sValue;
		}
		if (fldLen==2){
		   sValue = '0'+sValue;
		}*/
    fldLen = sValue.length-1;
		mskLen = mask.length-1;
  	for (var i=fldLen; i>=0; i--){
      if (typeMask.exec(mask.charAt(mskLen))!=null) {
        sCod = mask.charAt(mskLen)+sCod;
				i++;
			}else{
        sCod = sValue.charAt(i)+sCod;
			}
			mskLen--;
    }
	}
  objField.value = sCod;

  return true;
}