// JavaScript Document
var corDestaque = '#CEDCE8';
// AJAX
var ajax = new sack();
function ajaxLoadPage(divId, url){  
	ajax.requestFile = url;
    ajax.onCompletion = function(){ document.getElementById(divId).innerHTML = ajax.response; };  
    ajax.runAJAX();
}
//
function aparece(id){
	document.getElementById(id).style.display='inline';
}
function esconde(id){
	document.getElementById(id).style.display='none'
}
function verdiv(id){
	if(document.getElementById(id).style.display=='inline'){
		esconde(id);
	}else{
		aparece(id);
	}
}
function menuSeleciona(what) {
	what.style.background='#00529C';
	what.style.color='#FFFFFF';
}
function menuNormal(what,i) 	 {
	what.style.background=corDestaque;
	what.style.color='#333333';
}
//Formatação de campo
function apenasNumero(e){ //Aceita apenas entrada de numeros
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador){
		var tecla = event.keyCode;
	}else{
		var tecla = e.which;
	}
	if((tecla > 47 && tecla < 58) || (tecla == 0)){ // numeros de 0 a 9
		return true;
	}else{
		if (tecla != 8){ // backspace 8 e TAB 9
			return false;
		}else{
			return true;
		}
	}
}
function formataData(e,objeto){ //EX.: formataData(event,this);return apenasNumero(event);
    navegador = /msie/i.test(navigator.userAgent);
	if (navegador){
		var tecla = event.keyCode;
	}else{
		var tecla = e.which;
	}
	if(tecla > 47 && tecla < 58){ // numeros de 0 a 9  
        if(objeto.value.length == 2 || objeto.value.length == 5)  
            objeto.value = objeto.value+"/"; 
    }else{  
        return(tecla == 8 || tecla == 9); // backspace e tab  
    }
}
//Validação de Formulário
function validarLogin(form){
	if (form.c_usuario.value == ""){
		form.c_usuario.style.background=corDestaque;
		form.c_usuario.focus();
		return false;
	}
	if (form.c_senha.value == ""){
		form.c_senha.style.background=corDestaque;
		form.c_senha.focus();
		return false;
	}
}
function verificaCadastroProjeto(form){
	if (form.c_codigo.value == ''){
		form.c_codigo.style.background=corDestaque;
		alert('Insira o código do projeto!');
		form.c_codigo.focus();
		return false;
	}
	if (form.c_nome.value == ''){
		form.c_nome.style.background=corDestaque;
		alert('Insira o nome do projeto!');
		form.c_nome.focus();
		return false;
	}
	if (form.c_cliente.value == '0'){
		alert('Selecione o cliente!');
		form.c_cliente.focus();
		return false;
	}
	if (form.c_comercial.value == '0'){
		alert('Selecione o contato comercial com o cliente!');
		form.c_comercial.focus();
		return false;
	}
	if (form.c_midia.value == '0'){
		alert('Selecione a mídia!');
		form.c_midia.focus();
		return false;
	}
	if (form.c_modelo.value == '0'){
		alert('Selecione o modelo do projeto!');
		form.c_modelo.focus();
		return false;
	}
	if (form.c_coordenador.value == '0'){
		alert('Selecione o coordenador para o projeto!');
		form.c_coordenador.focus();
		return false;
	}
	if (form.c_status.value == '0'){
		alert('Selecione o status do projeto!');
		form.c_status.focus();
		return false;
	}
}
function verificaServiceDesk(form){
	if (!form.c_comentario.value){
		form.c_comentario.style.background=corDestaque;
		alert('Insira um comentário para o chamado!');
		form.c_comentario.focus();
		return false;
	}
	return confirm('Deseja realmente salvar estas alterações?');
}
function verificaProjetos(form){
	if (!form.c_comentario.value){
		form.c_comentario.style.background=corDestaque;
		alert('É necessário inserir um comentário sobre esta alteração!');
		form.c_comentario.focus();
		return false;
	}
	return confirm('Deseja realmente salvar estas alterações?');
}
function verificaAtividades(form){
	if (!form.data.value){
		form.data.style.background=corDestaque;
		alert('É necessário inserir uma data para esta atividade!');
		form.data.focus();
		return false;
	}
	if (!form.descricao.value){
		form.descricao.style.background=corDestaque;
		alert('É necessário inserir uma descrição para esta atividade!');
		form.descricao.focus();
		return false;
	}
	return confirm('Deseja realmente inserir esta prioridade?');
}
function verificaExcluirAtividade(form){
	if(confirm('Deseja realmente excluir esta prioridade?')){
		return form.submit();
	}
}
function verificaSalvar(form){
	if(confirm('Deseja realmente salvar estas alterações?')){
		return form.submit();
	}
}
function insereDado(form){
	if (form.texto1.value){
		return confirm('Deseja realmente inserir?');
	}
}
