var LISTARITENSENQUETE  = 1;
var MOVER				= 2;
var PREVIEW				= 3;
var ORDENAR				= 4;
var EDITAR				= 5;
var EXCLUIR				= 6;
var ADICIONAR	        = 7;
var PAGINA_ESPECIFICA   = 8;
var ALTERAR_IPP         = 9;
var HABILITAR			= 10;
var RESTRINGIRPERMISSAO = 11;
var LISTARPERMISSAO		= 12;
var ANEXAR				= 13;
var DETALHAR			= 14;
var VOLTAR				= 15;
var AJUDAR				= 16;
var VISUALIZAR_NOTICIA  = 17;
var UPLOAD			    = 20;
var CONFIRMAR           = 21;
var FECHAR				= 22;
var EXCLUIRCOMENTARIO				= 24;


var MSG_SELECIONAR_UM_ITEM = 'Selecione apenas um item';
var MSG_EMAIL_INCORRETO = 'Email digitado incorretamente';
var MSG_NENHUM_ITEM = 'Nenhum item foi selecionado';
var MSG_DATA_FORMATO = 'Formato de data incorreto';
var MSG_DATA_INFERIOR = 'Data com perído inferior ao necessário';
var MSG_SELECIONAR_ITEM = 'Selecione algum dos itens';


function criarMenu(nome)
{
	
<!--
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
//var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;

var sBasePath = '../fckeditor/';
var oFCKeditor = new FCKeditor( 'nome' ) ;
oFCKeditor.BasePath	= sBasePath ;
//oFCKeditor.Value	= 'This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.' ;
oFCKeditor.Create() ;
//-->
	
}



function removerImagem(){
	document.form1.DE_ARQ_IMAGEM.value = '';
	
} 

function submeterListaNova(nome,email)
     { 
	 
	   var doc = document.frmInformativo;
	   if (nome.value=='')
	     {
		   alert('Digite o seu nome de Contato');
		   nome.focus();
		   return false;
		 }
	    if (email.value=='')
	     {
		   alert('Digite o seu e-mail de Contato');
		  email.focus();
		   return false;
		 }
		if (email.value.indexOf('@') < 1 || email.value.indexOf('.') < 1)
			{
				alert("Preencha um e-mail do contato válido");
				email.focus();
				return false;
			}   

		doc.action = '../interface/CadastrarInformativos.asp?de_nome=' +nome.value+'&de_mail='+email.value;
		doc.submit(); 
	 }
function FormataData(objeto) {
	var tecla, tamanho;
	tecla = event.keyCode;

	if (tecla != 8) {
		tamanho = objeto.value.length;
		if (tamanho == 2 || tamanho == 5) {


			objeto.value = objeto.value + "/";
		}
	}

}

function DiminuirFonte(elemento) {
    switch (elemento.style.fontSize) {
        case '20px': {
            elemento.style.fontSize = '19px';
            break;
            }
		case '19px': {
            elemento.style.fontSize = '18px';
            break;
            }
		case '18px': {
            elemento.style.fontSize = '17px';
            break;
            }
		case '17px': {
            elemento.style.fontSize = '16px';
            break;
            }
		case '16px': {
            elemento.style.fontSize = '15px';
            break;
            }				
		case '15px': {
            elemento.style.fontSize = '14px';
            break;
            }
        case '14px': {
            elemento.style.fontSize = '13px';
            break;
            }
        case '13px': {
            elemento.style.fontSize = '12px';
            break;
            }
        case '12px': {
            elemento.style.fontSize = '11px';
            break;
            }
			
        default: {
            elemento.style.fontSize = '11px';
            break;
            }
    }
}
function AumentarFonte(elemento) {
    switch (elemento.style.fontSize) {
        case '11px': {
            elemento.style.fontSize = '12px';
            break;
            }
        case '12px': {
            elemento.style.fontSize = '13px';
            break;
            }
        case '13px': {
            elemento.style.fontSize = '14px';
            break;
            }
        case '14px': {
            elemento.style.fontSize = '15px';
            break;
            }
		case '15px': {
            elemento.style.fontSize = '16px';
            break;
            }
		case '17px': {
            elemento.style.fontSize = '18px';
            break;
            }
		case '19px': {
            elemento.style.fontSize = '20px';
            break;
            }			
        default: {
            if (elemento.style.fontSize != '20px') {
				elemento.style.fontSize = '11px';
				break; 
			}
			else
            	break;
            }
    }
}
function FormataHora(objeto) {
	var tecla, tamanho;
	tecla = event.keyCode;

	if (tecla != 8) {
		tamanho = objeto.value.length;
		if (tamanho == 2) {


			objeto.value = objeto.value + ":";
		}
	}

}


function validaData(objeto)
{
	var valor = objeto.value;
	var mValores = "312831303130313130313031";
	var retorno = false;
	var lastDate = 0;
	var dia;
	var mes;
	var ano;
	var arrayData;


   var reData = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
   if (!reData.test(valor))
	 {
	      alert('A data deve estar no formato DD/MM/AAAA');
		  objeto.focus();
      return false;
   }

	arrayData = valor.split("/");

	dia  = arrayData[0];
	mes  = arrayData[1];
	ano  = arrayData[2];

	if (ano < 2004)
	{

		alert('O sistema não trabalha com data inferiores a 2004');
		objeto.focus();
		objeto.select();
		return false;
	}

	if (mes == 2){
		if (anobissexto(ano)) {
			lastDate = 29
		}
		else {
			lastDate = 28
		}
	}
	else {
		lastDate = mValores.substring((mes-1)*2, (mes-1)*2+2)
	}

   if ( (mes > 12) || (mes <= 0) ){
		retorno = false
	}
	else if ( (dia > lastDate) || (dia <=0) ){
		retorno = false
	}
	else {
		retorno = true
	}

	if (!retorno){
		alert("Data inválida");
		objeto.focus();
		objeto.select();
	}
	return retorno;


}

function campoImagem(){

}
function selecionarTodos(objImg, objCheck) {
	var imgSelTodos  = "bt_check_on.jpg";
	var imgNenhumSel = "bt_check_off.jpg";
	var pChecked;
	var src, posImage

	if (objCheck == null)
	{
		alert("Nenhum item na lista.");
		return false;
	}
	src = objImg.src
	posImage = src.indexOf(imgSelTodos)
	
	if (posImage>0) {
		src = src.substring(0, posImage) + imgNenhumSel
		pChecked = true;
	}
	else {
		posImage = src.indexOf(imgNenhumSel)
		src = src.substring(0, posImage) + imgSelTodos
		pChecked = false;
	}
	
	objImg.src = src
	
	if (objCheck.length == null) {
		objCheck.checked = pChecked;
	}
	else {
	
		for (var i=0;i<objCheck.length;i++) {
			objCheck[i].checked = pChecked;
		}
	}
	
}


function verAlgunMarcado(objCheck){
	var existe = false;
	if (objCheck == null) {
		alert(MSG_NENHUM_ITEM);
		return false;
	}
	if (objCheck.length == null) {
		existe = objCheck.checked;
	}
	else {
		for (var i=0;i<objCheck.length;i++) {
			if (objCheck[i].checked) {
				existe=true;
				break;
				}
			}
	}
	if (!existe) {
		alert(MSG_SELECIONAR_ITEM);
		return false;
	}
	return true;
}

function verTodosMarcados(objCheck) {
	var countMarcados = 0;
	if (objCheck == null) {
		alert(MSG_NENHUM_ITEM);
		return false;
	}
	if (objCheck.length != null){
		for (var i=0;i<objCheck.length;i++) {
			if (objCheck[i].checked) {
				countMarcados = countMarcados + 1;
				}
			}
	}
	if (countMarcados>1) {
		alert(MSG_SELECIONAR_UM_ITEM);
		return false;
		}
	return true;
}

function jsTrim(pStr){
        var i;
        var strAux;
        var PosIni,PosFim;

        //PROCURA A PRIMEIRA POSIÇÃO VÁLIDA DIFERENTE DE ESPAÇO EM BRANCO
        i=0;
        while ((i < pStr.length) && (pStr.charAt(i)==" ")){
                i++;
        }
        PosIni = i;

        //PROCURA A ULTIMA POSIÇÃO VÁLIDA DIFERENTE DE ESPAÇO EM BRANCO
        i=pStr.length-1;
        while ((i >= 0) && (pStr.charAt(i)==" ")){
                i--;
        }
        PosFim = i + 1;

        // TESTA SE OS VALORES SE CRUZARAM
        if (PosIni < PosFim){
                strAux = pStr.substring(PosIni,PosFim);
        }
        else{
                strAux = "";
        }

        return strAux;
}
function popUp(sUrl, iLargura, iAltura, bScroll, nomeJanela){
 
 if (iLargura == 0) window.screen.width/2;
 if (iAltura  == 0) window.screen.height/2;
 
/* 
if (sUrl.indexOf(".rpt") > -1)
    nomeJanela = ""; //Janela com nome branco para permitir a exibição de várias
else
    nomeJanela = "detalhar";
*/
 return window.open (sUrl , nomeJanela,
                     "SCROLLBARS=" + bScroll + ", RESIZABLE=no, TOOLBAR=no, STATUS=yes, MENUBAR=no, WIDTH=" + iLargura +
                     ", HEIGHT=" +  iAltura + ", TOP=30, LEFT=100", true);
} //popUp

function valorChecado(check) {
  
  if (check.length == null){
   return check.value;
  }

  else
  {
     var tam   = check.length;
     for(i=0 ; i < tam ; i++){
       if (check[i].checked)
         return check[i].value;
     } //for
   } //if
   
  return 0;
} 
function adicionarSelect(objSelect, texto, valor) {
   var tamanho = objSelect.length;
   var newOption =  new Option(texto, valor);
   objSelect.options[tamanho] = newOption;
} 
function removerTodosSelect(obj)
{   /// Limpa o os itens do Objeto Select 
	if (obj.length > 0){	
		for (var i = obj.length-1; i>=0 ;i--){
    	  obj.options[i] = null;
    	}
	}
} //removerTodosSelect
//======================================\\
function as_stop(){clearTimeout(as_timer);}
function as_start(){as_scroll(valorcliptop);}
//\\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-//\\


		leftedge=590;  
	


//  seta lateral \\
topedge=160;    // lacalizacao do top \\
boxheight=180;   // height do novo box \\
boxwidth=160;      // width do novo box \\
scrollheight=400;    // Altura do scroll \\
//\\------------------------------------//\\
function as_scroll(cliptop) {
as_timer = null
valorcliptop = null
cliptop = (cliptop + 1) % (scrollheight + boxheight);
//==================\\
if (!document.all) {
newsDiv=document.getElementById("news").style; 
newsDiv.left = leftedge;
newsDiv.top = topedge - cliptop;
}else{
newsDiv=news.style;
newsDiv.pixelLeft = leftedge;
newsDiv.pixelTop = topedge - cliptop;
}
//===================================\\
newsDiv.clip = "rect(" + cliptop + "px " + (boxwidth + leftedge) + "px " + (cliptop + boxheight) + "px 0px)";
newsDiv.visibility='visible';
as_timer = setTimeout("as_scroll(" + cliptop + ")", 50);
valorcliptop = cliptop
//=================================\\
}


var FECHAR				= 22 ;

function validarBusca(mens)
{
	var doc = document.formbusca;
	if(doc.CO_BUSCA.value == "")
	{
		alert(mens);
		doc.CO_BUSCA.focus();
		return (false);
	} 
	doc.submit();
}

function mostrarConteudo(ref){
	document.location.href = '../interface/Exibir.asp?ref=' + ref;
	
} //mostrarConteudo

function mostrarConteudoNoticia(CO_NOTICIA){
	document.location.href = '../interface/ExibirNoticia.asp?CO_NOTICIA=' + CO_NOTICIA;
	document.location.target='mainFrame';
}
function mostrarConteudo2(ref){
	window.open('../interface/Exibir.asp?ref=' + ref,'_blank');

} //mostrarConteudo
function mostrarConteudoNoticia2(CO_NOTICIA){
	window.open('../interface/ExibirNoticia.asp?CO_NOTICIA=' + CO_NOTICIA,'_blank');

} //mostrarConteudo
function popUp(sUrl, iLargura, iAltura, bScroll, nomeJanela){
 
 if (iLargura == 0) window.screen.width/2;
 if (iAltura  == 0) window.screen.height/2;
 
/* 
if (sUrl.indexOf(".rpt") > -1)
    nomeJanela = ""; //Janela com nome branco para permitir a exibição de várias
else
    nomeJanela = "detalhar";
*/
 
 return window.open (sUrl , nomeJanela,
                     "SCROLLBARS=" + bScroll + ", RESIZABLE=no, TOOLBAR=no, STATUS=no, MENUBAR=no, WIDTH=" + iLargura +
                     ", HEIGHT=" +  iAltura + ", TOP=30, LEFT=100");

} //popUp

function jsTrim(pStr){
        var i;
        var strAux;
        var PosIni,PosFim;

        //PROCURA A PRIMEIRA POSIÇÃO VÁLIDA DIFERENTE DE ESPAÇO EM BRANCO
        i=0;
        while ((i < pStr.length) && (pStr.charAt(i)==" ")){
                i++;
        }
        PosIni = i;

        //PROCURA A ULTIMA POSIÇÃO VÁLIDA DIFERENTE DE ESPAÇO EM BRANCO
        i=pStr.length-1;
        while ((i >= 0) && (pStr.charAt(i)==" ")){
                i--;
        }
        PosFim = i + 1;

        // TESTA SE OS VALORES SE CRUZARAM
        if (PosIni < PosFim){
                strAux = pStr.substring(PosIni,PosFim);
        }
        else{
                strAux = "";
        }

        return strAux;
}

function DecodificarChrParaSQL(lsTexto)
{   
    lsTexto = jsReplace(lsTexto, CODIGO_ASPA_SIMPLES    , CHR_ASPA_SIMPLES    );
    lsTexto = jsReplace(lsTexto, CODIGO_ABRE_PARENTESES , CHR_ABRE_PARENTESES );
    lsTexto = jsReplace(lsTexto, CODIGO_FECHA_PARENTESES, CHR_FECHA_PARENTESES);
    
    return lsTexto;
}



var CHR_ASPA_SIMPLES        = "\'";
var CHR_ABRE_PARENTESES     = "\(";
var CHR_FECHA_PARENTESES    = "\)";
var CODIGO_ASPA_SIMPLES     = "ChrSQL[39]";
var CODIGO_ABRE_PARENTESES  = "ChrSQL[40]";
var CODIGO_FECHA_PARENTESES = "ChrSQL[41]";

//---------------------------------------------------------------------
//Nome: CodificarChrParaSQL
//
//Objetivo:
//Essa função transforma caracteres não suportados pelo
//banco de dados em códigos válidos.
//
//Ao ler esses dados do BD deve ser utilizado uma função que transforme
//esses códigos no seu respectivo caracter DecodificarChrParaSQL
//
function CodificarChrParaSQL(lsTexto)
{    
    lsTexto = jsReplace(lsTexto, CHR_ASPA_SIMPLES    , CODIGO_ASPA_SIMPLES    );
    lsTexto = jsReplace(lsTexto, CHR_ABRE_PARENTESES , CODIGO_ABRE_PARENTESES );
    lsTexto = jsReplace(lsTexto, CHR_FECHA_PARENTESES, CODIGO_FECHA_PARENTESES);
    
    return lsTexto;
}    
function jsReplace(strSource, strFind, strReplace)
{
	var result = strSource;
	
	while ( result.indexOf(strFind) >-1 )
	{
        result = result.replace(strFind, strReplace);
    }
	
    return result;
}

function popUp2(sUrl, iLargura, iAltura, bScroll, nomeJanela){
 
 if (iLargura == 0) window.screen.width/2;
 if (iAltura  == 0) window.screen.height/2;
 
/* 
if (sUrl.indexOf(".rpt") > -1)
    nomeJanela = ""; //Janela com nome branco para permitir a exibição de várias
else
    nomeJanela = "detalhar";
*/
 return window.open (sUrl , nomeJanela,
                     "SCROLLBARS=" + bScroll + ", RESIZABLE=no, TOOLBAR=no, STATUS=yes, MENUBAR=no, WIDTH=450, HEIGHT=450, TOP=30, LEFT=200", true);
} 


var v_obj;
var v_fun;
var v;
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}


function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function matricula(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{6})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function data(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1/$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\/(\d{2})(\d)/,"$1/$2/$3") //Coloca ponto entre o quinto e o sexto dígitos
  
    return v
}


function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}


function EhNumero(){
	var codigo;
	codigo = event.keyCode; 
	
	//O Código 46 é correspondente ao ponto(.) usado para casas decimais.
	//O Código 58 é correspondente ao dois pontos(:) para campos Hora.
	// 13 - <ENTER>
	// 46 - .
	// 58 - :
	if (codigo == 13) {
		return true;
	}
	
	if(codigo < 48 || codigo > 57){
		alert("Esse campo só aceita números !");
		event.keyCode = 0;
		return false;
	}
}
