////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									/**Funções em JavaScript*/

/*Somente Numeros*/
function somenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}



/* Se for validado dataValor no formato dd/mm/yyyy a função retorna null senão retorna String da mensagem de erro. */
function valida_ValorData(dataValor) {	
	var meses = new Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho",
	"Agosto","Setembro","Outubro","Novembro","Dezembro");
	var input = dataValor;
	var monthMax = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var re = /\b(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[0-2])[\/]((19|20)\d{2})/
	var matchArray = re.exec(input)

	if (matchArray) {
		// Se for um ano bisexto então mês de fevereiro pode conter 29 dias 
		if (matchArray[3] % 4 == 0)
			monthMax[1] = 29;
		if (matchArray[1] > monthMax[matchArray[2]-1]){
			return "inválida, mês "+meses[matchArray[2]-1]+" máximo "+monthMax[matchArray[2]-1]+" dias!!!";							
		} else	
			return null;
	} else 	
		return "inválida, não está no formato dd/mm/aaaa";		
}


/**
      * Formata o Campo de acordo com a mascara informada.
      * Ex de uso: onkeyup="AplicaMascara('00:00:00', this);".
      * @author Igor Escobar (blog@igorescobar.com)
      * @param Mascara String que possui a mascara de formatação do campo.
      * @param elemento Campo que será formatado de acordo com a mascara, voce pode informar o id direto ou o próprio elemento usando o this.
      * @returns {void}
      */
      
      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;
      }


/**
	função Mostrar Data
*/

function mostraDataAtual(){
		var mydate=new Date()
		var year=mydate.getYear()
		if (year < 1000)
		year+=1900
		var day=mydate.getDay()
		var month=mydate.getMonth()
		var daym=mydate.getDate()
		if (daym<10)
		daym="0"+daym
		var dayarray=new Array("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","Sábado")
		var montharray=new
		Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
		document.write("<small><font color='000000' face='Arial' size='2'><b>"+dayarray[day]+", "+daym+" de "+montharray[month]+", de "+year+"</b></font></small>")
	}

/*
	Função de cumprimento de bom dia, boa tarde ou boa noite
*/

function bomDia(){
day = new Date()
hr = day.getHours()
if ((hr==1)||(hr==2)||(hr==3)||(hr==4) || (hr==5))
document.write("<font color='gray' face='verdana,tahoma' size=1><b>Boa Noite</b></font>")
if (((hr==6) || (hr==7) || (hr==8) || (hr==9) || (hr==10))
|| (hr==11)) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Bom dia!</b></font>")
if (hr==12) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Bom Dia!</b></font>")
if ((hr==13) || ((hr==14) || (hr==15) || (hr==16)) || (hr==17)) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Boa tarde!</b></font>")
if ((hr==18) || (hr==19)) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Bom tarde!</b></font>")
if ((hr==20) || (hr==21) || (hr==22)) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Boa noite!</b></font>")
if (hr==23) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Boa noite!</b></font>")
if (hr==0) document.write("<font color='gray' face='verdana,tahoma' size=1><b>Boa noite!</b></font>")
}


/*
	função formata moeda
	ex: onkeypress="return formatar_moeda(this,',','.',event);"
*/

function formatar_moeda(campo, separador_milhar, separador_decimal, tecla) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;
}

/*
 Função de Fomrato de valores
 exemplo: value="0.00" onkeydown="valida_moeda('PlanoValor')" onkeyup="valida_moeda('PlanoValor')
*/
function valida_moeda ( Element )
{
	var objCampo = document.getElementById( Element );
	len = 20;
	cur = objCampo;
	n   = '0123456789';
	d   = objCampo.value;
	l   = d.length;
	r   = '';
	
	if ( l > 0 ){
		z = d.substr(0,l);
		s = '';
		a = 0;
		
		for ( i=0; i < l; i++ ){
			c = d.charAt(i);
			if ( n.indexOf(c) > a ){
				a  = -1;
				s += c;
			};
		};
		l = s.length;
		t = len - 1;
		if ( l > t ){
			l = t;
			s = s.substr(0,t);
		}
		if ( l > 2 ){
			r = s.substr(0,l-2)+'.'+s.substr(l-2,2);
		} else {
			if ( l == 2 ){
				r='0.'+s;
			}else{
				if ( l == 1 ){
					r = '0.0'+s;
				}
			}
		}
		if ( r == '' ){
			r = '0.00';
		} else {
			l=r.length;
			if (l > 6){
				j  = l%3;
				w  = r.substr(0,j);
				wa = r.substr(j,l-j-6);
				wb = r.substr(l-6,6);
				if ( j > 0 ){
					w+='.';
				};
				k = (l-j)/3-2;
				for ( i=0; i < k; i++ ){
					w += wa.substr(i*3,3)+'.';
				};
				r = w + wb;
			}
		}
	}
	if ( cur.value.length == len || cur.value.length > len ){
		cur.value = cur.value.substring(0 ,len);
		return false;
	} else {
			if ( r.length <= len ){
				cur.value = r;
			}else{
				cur.value = z;
			};
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									/**MENSAGENS DE BOTÕES*/


/* Mensagem botão excluir */
function confirmaDeletar(form, acao){
    if (confirm("Deseja excluir esse registro?")){
        form.system_action.value = acao;
        form.submit();
    }
}

function submete(form, acao, offset) {
	form.indTipoNaveg.value = acao;
	form.offset.value = offset;
	form.submit();
}

/* Mensagens Erro/Ok botão salvar */
function valida(campo, msgErro, msgOk) {
	if (campo.value == '') {
		msgOk.style.display = 'none';
		msgErro.style.display = '';
	} else {
		msgOk.style.display = '';
		msgErro.style.display = 'none';                            
	}
}

/* Mensagem botão desfazer */
function confirmaDesfazer(form) { 
    if (confirm('Deseja desfazer as ações realizadas na página atual?')) {
        form.reset();
    }    
    return true;
}

/* Mensagem botão logout */
function confirmaLogout(acao) {
    if (confirm("Deseja sair do sistema ?")) {
        location.href = acao;
        return true;
    }
    return false;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
										/*OUTRAS CONFIGURAÇÔES*/

/* Chamada das telas de ajuda */
function OpenNewWindow(Picture,Breit,Hoch,tittle)
{
xsize = Breit+55;
ysize = Hoch+145; 
    
ScreenWidth = screen.width;
ScreenHeight = screen.height;

xpos = (ScreenWidth/2)-(xsize/2);
ypos = (ScreenHeight/2)-(ysize/2);

	NewWindow=window.open("","Picture","height="+ysize+",width="+xsize+",scrollbars=yes,resizable=yes,top="+ypos+",left="+xpos+"");
	if (getCookie("arq_css") == null){
		NewWindow.document.write("<LINK href='css/padrao_azul.css' type='text/css' rel='stylesheet'>");
	} else {
		NewWindow.document.write("<LINK href='css/"+getCookie("arq_css")+"' type='text/css' rel='stylesheet'>"); 
	}
	NewWindow.document.write ("<html><head><title>Ajuda");
	NewWindow.document.write ("</title></head>");
	NewWindow.document.write ("<body bgcolor='#FFFFFF' topmargin='0'>");
	NewWindow.document.write ("<table align='center'><tr>");
	NewWindow.document.write ("<td align='left' valign='top' width='50%'>");
	if (getCookie("arq_logo") == null){
		NewWindow.document.write("<IMG src='img/logo.gif' border='0' alt='P&aacute;gina Principal'>");
	} else {
		NewWindow.document.write("<IMG src='"+getCookie("arq_logo")+"' border='0' alt='P&aacute;gina Principal'>");
	}
	NewWindow.document.write ("</td></tr> <TR height='4'> ");
    NewWindow.document.write ("<TD class='td-03'></TD> ");
	NewWindow.document.write ("</TR><tr><td height='30' valign='top' align='center'><label class='ft-03'>");
	NewWindow.document.write (tittle);
	NewWindow.document.write ("</label>");
	NewWindow.document.write ("</td></tr>");
	NewWindow.document.write ("<tr><td height='30' valign='top' align='left'><label class='ft-01'>");
	NewWindow.document.write ('Segue abaixo um fluxomagra das ações que podem ser realizadas neste tipo de cadastro:');
	NewWindow.document.write ("</label></td></tr>");
	NewWindow.document.write ("<tr><td align='center' valign='top'>");
	NewWindow.document.write ("<table border='1' bgcolor='#000000' cellpadding='0' cellspacing='1'><tr><td align='center'>");
	NewWindow.document.write ("<img src=");
	NewWindow.document.write (Picture);
	NewWindow.document.write (">");
	NewWindow.document.write ("</tr></table>");
	NewWindow.document.write ("<tr><td align='center' valign='top'><label class='ft-03'>");
	NewWindow.document.write ('Legenda');
	NewWindow.document.write ("</label></td></tr>");
	NewWindow.document.write ("<tr><td><table border='1' bgcolor='#000000' cellpadding='0' cellspacing='1' align='center'><tr>");
	NewWindow.document.write ("<td align='center' valign='top'>");
	NewWindow.document.write ("<img src='help/img/legenda.jpg'>");
	NewWindow.document.write ("</td></tr></table></td></tr>");
	NewWindow.document.write ("</td></tr><tr>");
	NewWindow.document.write ("<td align='center' valign='bottom'>");
	NewWindow.document.write ("<br><center><form><input type='button' name='fechar' value='Fechar Janela' class='bt-01' onClick='self.close()' title='Fechar Janela'><br><br>");
	NewWindow.document.write ("</td></tr></table>");
	NewWindow.document.write ("</form></body></html>");
	NewWindow.document.close();
}


/* Retorna o valor do cookie pela posição */
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);

    if (endstr == -1) {
        endstr = document.cookie.length;
    }

    var strCookie = document.cookie.toString();
    return unescape(strCookie.substring(parseInt(offset), parseInt(endstr)));
}

/* Retorna o valor do cookie pelo nome */
function getCookie(name) {
    var arg = name + "=";
    var argLen = arg.length;
    var ckLen = document.cookie.length;
    var i = 0;

    while (i < ckLen) {
        var j = i + argLen;

        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        
        if (i == 0) {
            break;
        }
    }
    return null;
}

/* Seta o cookie para a página */
function setCookie(name, value, expires, path, domain, secure) {    
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") + 
        ((path) ? "; path=" + path : "") + 
        ((domain) ? "; domain=" + domain : "") + 
        ((secure) ? "; secure=" + secure : "");
}

/* Atualiza o cookie */
function atualizaCookie(pform, logo, estilo){
    if (logo == '') {
        if (estilo == 'padrao_verde.css') {    
            logo = './img/logo_verde.gif';
        } else if (estilo == 'padrao_laranja.css') {    
            logo = './img/logo_laranja.gif';
        } else if (estilo == 'padrao_cinza.css') {    
            logo = './img/logo_cinza.gif';
        } else {
            logo = './img/logo.gif';    
        }
    }

    setCookie("arq_css", estilo);
    setCookie("arq_logo", logo);
	pform.submit();
}

/* Retorna o valor selecionado */
function retornaEstilo(){
  for (i=0;i<document.frmConfig.p_tema.length;i++){
	  if (document.frmConfig.p_tema[i].checked)
	  {
		  return document.frmConfig.p_tema[i].value;
	  }
  }
}

function estiloCookie(caminho){
	if (getCookie("arq_css") == null){
		document.write("<LINK href='"+caminho+"padrao_azul.css' type='text/css' rel='stylesheet'>");
	} else {
		document.write("<LINK href='"+caminho+getCookie("arq_css")+"' type='text/css' rel='stylesheet'>"); 
	}    
} 

function imageCookie(){
	if (getCookie("arq_logo") == null){
		document.write("<IMG src='img/logo.gif' border='0' alt='P&aacute;gina Principal'>");
	} else {
		document.write("<IMG src='"+getCookie("arq_logo")+"' border='0' alt='P&aacute;gina Principal'>");
	}
} 

function estiloCss(caminho){
		document.write("<LINK href='"+caminho+"itsystems.css' type='text/css' rel='stylesheet'>");
} 

function atualizaImagem(){
    if (getCookie("arq_css") == 'padrao_verde.css'){
		document.write("<IMG src='img/centro_verde.gif' width='600' height='321' border='0'>");
	} else if (getCookie("arq_css") == 'padrao_laranja.css'){
		document.write("<IMG src='img/centro_laranja.gif' width='600' height='321' border='0'>");
	} else if (getCookie("arq_css") == 'padrao_cinza.css'){
		document.write("<IMG src='img/centro_cinza.gif' width='600' height='321' border='0'>");
	} else {
		document.write("<IMG src='img/centro_azul.gif'width='600' height='321' border='0'>");
	}
} 

function setaRadioEstilo() {
    pform = document.frmConfig;
    estilo = getCookie("arq_css");

    // seta o radio
    if (estilo == 'padrao_cinza.css') {    
        pform.p_tema01.checked = true;
    } else if (estilo == 'padrao_laranja.css') {    
        pform.p_tema02.checked = true;
    } else if (estilo == 'padrao_verde.css') {    
        pform.p_tema03.checked = true;
    } else {
        pform.p_tema04.checked = true;
    }
}

function abrirPagina(url) {
	
	if(url != null && url != ""){
		void window.open(url,"JPnaFesta","width=800,height=600,scrollbars=yes,status=yes") 
	}
}


