var oldBotoes = '';
function form2text()
{
// se tivesse algum sendo editado, fecha o formulario dele
inputOldId = document.getElementById( "agenda_rap_id" );
if( inputOldId != null )
{
compId = inputOldId.value;
}
// seleciona os DIVs
divConteudo = document.getElementById( "conteudo_" + compId );
divTitle = document.getElementById( "titulo_" + compId );
divBotoes = document.getElementById( "botoes_" + compId );
inputTitle = document.getElementById( "titulo_original_" + compId );
inputConteudo = document.getElementById( "conteudo_original_" + compId );
inputHoraIni = document.getElementById( "hora_original_ini_" + compId );
inputHoraFim = document.getElementById( "hora_original_fim_" + compId );
inputData = document.getElementById( "data_original_" + compId );
inputOpcoes = document.getElementById( "extras_original_" + compId );
if( inputTitle.value )
{
titulo = inputTitle.value;
}
else
{
arrTitle = inputConteudo.value.split( ' ' );
titulo = arrTitle.slice( 0, 6 ).join( ' ' );
}
titulo = inputHoraIni.value + ' - ' + titulo + ' - ' + inputHoraFim.value;
if( inputOpcoes.value & 1 && ! ( inputOpcoes.value & 4 ) )
{
titulo = '' + titulo + '';
}
divTitle.innerHTML = titulo;
divConteudo.innerHTML = inputConteudo.value.split( "\n" ).join( "
\n" );
divBotoes.innerHTML = oldBotoes;
if( document.getElementById( "aberto_" + compId ).value == 0 )
{
agenda_retrair( compId );
}
}
function text2form( compId )
{
// se tivesse algum sendo editado, fecha o formulario dele
inputOldId = document.getElementById( "agenda_rap_id" );
if( inputOldId != null )
{
form2text();
}
// seleciona os DIVs
divConteudo = document.getElementById( "conteudo_" + compId );
divTitle = document.getElementById( "titulo_" + compId );
divBotoes = document.getElementById( "botoes_" + compId );
inputTitle = document.getElementById( "titulo_original_" + compId );
inputConteudo = document.getElementById( "conteudo_original_" + compId );
inputHoraIni = document.getElementById( "hora_original_ini_" + compId );
inputHoraFim = document.getElementById( "hora_original_fim_" + compId );
inputData = document.getElementById( "data_original_" + compId );
inputOpcoes = document.getElementById( "extras_original_" + compId );
inputAberto = document.getElementById( "aberto_" + compId );
publica = document.getElementById( "agenda_publica" ).value;
divTitle.innerHTML = ' ';
document.getElementById( 'agenda_rap_titulo' ).value = inputTitle.value;
chck1 = ( inputOpcoes.value & 2 ) ? 'checked' : '';
chck2 = ( inputOpcoes.value & 1 ) ? 'checked' : '';
conteudo = '
';
conteudo += 'Fim do Compromisso: Data:
';
conteudo += 'Importante:';
if( publica == 1 )
{
conteudo += 'Público:';
}
conteudo += '
';
conteudo += ' ';
divConteudo.innerHTML = conteudo;
oldBotoes = divBotoes.innerHTML;
divBotoes.innerHTML = "";
}
function agenda_salva()
{
erros = '';
// descobre quem estava sendo editado
inputOldId = document.getElementById( "agenda_rap_id" );
if( inputOldId != null )
{
compId = inputOldId.value;
// seleciona os campos para verificar dados (data, hora, obrigatorio, etc)
inputTitle = document.getElementById( "agenda_rap_titulo" );
inputConteudo = document.getElementById( "agenda_rap_conteudo" );
inputHoraIni = document.getElementById( "agenda_rap_hora" );
inputHoraFim = document.getElementById( "agenda_rap_horafim" );
inputData = document.getElementById( "agenda_rap_data" );
// verifica integridade
if( !(/[0-9]{2}:[0-9]{2}/.test( inputHoraIni.value ) ) )
{
alert( 'Preencha o campo Hora de Inicio corretamente.\nFormato hora: hh:mm' );
inputHoraIni.focus();
return false;
}
if (!(/(((0[1-9]|[12][0-9])\/(02))|((0[1-9]|[12][0-9]|(30))\/(0[4689]|(11)))|((0[1-9]|[12][0-9]|3[01])\/(0[13578]|(10)|(12))))\/[1-2][0-9]{3}/.test( inputData.value )))
{
alert( 'Preencha o campo Data corretamente.\nFormato data: dd/mm/aaaa' );
inputData.focus();
return false;
}
if( !(/[^ ]/.test( inputTitle.value )) && !(/[^ ]/.test( inputConteudo.value )) )
{
alert( 'Preencha o campo Titulo ou o campo Descricao' );
inputConteudo.focus();
return false;
}
// se estiver ok envia o formulario
document.getElementById( "agenda_principal" ).submit();
return;
}
else
{
erros += 'Impossivel identificar compromisso editado.';
}
alert( erros );
}
function agenda_expandir( compId )
{
// descobre se alguem estava sendo editado
inputOldId = document.getElementById( "agenda_rap_id" );
if( inputOldId != null )
{
// tem alguem
if( inputOldId.value == compId )
{
// eh exatamente o que vamos expandir
form2text();
}
}
inputConteudo = document.getElementById( "conteudo_original_" + compId );
divConteudo = document.getElementById( "conteudo_" + compId );
divExpandir = document.getElementById( "agenda_expandir_" + compId );
divExpandir.innerHTML = '

';
divConteudo.innerHTML = inputConteudo.value.split( '\n' ).join( '
' );;
document.getElementById( "aberto_" + compId ).value = 1;
}
function agenda_retrair( compId )
{
// descobre se alguem estava sendo editado
inputOldId = document.getElementById( "agenda_rap_id" );
if( inputOldId != null )
{
// tem alguem
if( inputOldId.value == compId )
{
// eh exatamente o que vamos retrair
form2text();
}
}
inputConteudo = document.getElementById( "conteudo_original_" + compId );
divConteudo = document.getElementById( "conteudo_" + compId );
divExpandir = document.getElementById( "agenda_expandir_" + compId );
divExpandir.innerHTML = '
';
textoArr = inputConteudo.value.split( ' ' ).slice( 0, 21 ).join( ' ' ) + '...';
textoArr = textoArr.split( '\n' ).join( '
' );
divConteudo.innerHTML = textoArr;
document.getElementById( "aberto_" + compId ).value = 0;
}
function excluir( compId )
{
if( confirm( 'Deseja realmente excluir este compromisso?\nEsta e uma operacao irreversivel!' ) )
{
excluirSim( compId, location );
}
//showExpansivel( 400, 114, 'Deseja realmente excluir este compromisso?
Esta é uma operação irreversível.
' );
}
function excluirSim( compId )
{
expansivel = document.getElementById( "DOM_expansivel" );
expansivel.style.display = 'none';
document.location.href = 'agenda.php' + document.getElementById( "parametros" ).value + '&deletar=' + compId;
}
// Excluir compromisso dentro do sistema OpenJuris -- Higor 23/11/2005
function excluirJuris( compId )
{
if( confirm( 'Deseja realmente excluir este compromisso?\nEsta e uma operacao irreversivel!' ) )
{
excluirSim( compId, location );
}
//showExpansivel( 400, 114, 'Deseja realmente excluir este compromisso?
Esta é uma operação irreversível.
' );
}
function excluirSimJuris( compId )
{
expansivel = document.getElementById( "DOM_expansivel" );
expansivel.style.display = 'none';
document.location.href = 'juris_agenda_desenv.php' + document.getElementById( "parametros" ).value + '&deletar=' + compId;
}
function novoForm(array_compromissos)
{
acao = 'agenda.php';
if(typeof(array_compromissos) != "undefined")
{
select = "";
acao = 'juris_agenda_desenv.php';
}
publica = document.getElementById( "agenda_publica" ).value;
conteudo = '';
showExpansivel( 460, 360, conteudo, 'Cadastro de Compromisso' );
document.getElementById( "novo_hora_inicio" ).focus();
}
function salvaNota( compId )
{
conteudo = '';
showExpansivel( 270, 180, conteudo, 'Salvar como compromisso' );
document.getElementById( "grava_hora_fim" ).focus();
}
function checaEnvio()
{
if( !(/[0-9]{2}:[0-9]{2}/.test( document.getElementById( "novo_hora_inicio" ).value ) ) )
{
alert( 'Preencha o campo Inicio corretamente.\nFormato hora: hh:mm' );
document.getElementById( "novo_hora_inicio" ).focus();
return false;
}
if (!(/(((0[1-9]|[12][0-9])\/(02))|((0[1-9]|[12][0-9]|(30))\/(0[4689]|(11)))|((0[1-9]|[12][0-9]|3[01])\/(0[13578]|(10)|(12))))\/[1-2][0-9]{3}/.test( document.getElementById( "novo_data" ).value )))
{
alert( 'Preencha o campo Data corretamente.\nFormato data: dd/mm/aaaa' );
document.getElementById( "novo_data" ).focus();
return false;
}
//14-11-2005 -> inicio alteracao
if( document.getElementById( "novo_hora_fim" ).value != "" && !(/[0-9]{2}:[0-9]{2}/.test( document.getElementById( "novo_hora_fim" ).value ) ) )
{
alert( 'Preencha o campo fim corretamente.\nFormato hora: hh:mm' );
document.getElementById( "novo_hora_fim" ).focus();
return false;
}
//14-11-2005 -> fim alteracao
if( !(/[^ ]/.test( document.getElementById( "novo_titulo" ).value )) && !(/[^ ]/.test( document.getElementById( "novo_descricao" ).value )) )
{
alert( 'Preencha o campo Titulo ou o campo Descricao' );
document.getElementById( "novo_titulo" ).focus();
return false;
}
if(document.getElementById( "tipo_compromisso" ))
{
if( !(/[^ ]/.test( document.getElementById( "tipo_compromisso" ).value )))
{
alert( 'Selecione o Tipo de Compromisso' );
document.getElementById( "tipo_compromisso" ).focus();
return false;
}
}
document.getElementById( "novo_form" ).submit();
}
function checaGravacao()
{
if( !(/[0-9]{2}:[0-9]{2}/.test( document.getElementById( "grava_hora_fim" ).value ) ) )
{
alert( 'Preencha o campo Fim corretamente.\nFormato hora: hh:mm' );
document.getElementById( "grava_hora_fim" ).focus();
return false;
}
document.getElementById( "novo_form" ).submit();
}
function formataData(campo, e)
{
if( typeof window.event != "undefined")
{
if (window.event.keyCode != 47)
{
if ((campo.value.length == 2) || (campo.value.length == 5))
{
campo.value += '/';
}
}
}else
{
if (e.which != 47 && e.which != 45 && e.which != 46 && e.which != 8 && e.which != 32 && e.which != 13 && e.which != 0 )
{
if ((campo.value.length == 2) || (campo.value.length == 5))
{
campo.value += '/';
}
}
}
}
function formataHora(campo, e)
{
if( typeof window.event != "undefined" )
{
if (window.event.keyCode != 58)
{
if ((campo.value.length == 2))
{
campo.value += ':';
}
}
}else
{
if (e.which != 45 && e.which != 46 && e.which != 8 && e.which != 32 && e.which != 13 && e.which != 0 )
{
if ((campo.value.length == 2))
{
campo.value += ':';
}
}
}
}