// ##################### jQuery ######################

// Mapa em Flash

 $(document).ready(
    function () {
        $('#mapa').flash({
            width: 320,
            height: 320,
            swf: 'flash/Mapa.swf',
            flashvars: {
               RJ: 'clientes.php?uf=RJ',
               SP: 'clientes.php?uf=SP',
               RN: 'clientes.php?uf=RN'		   
            }
        });
    }
);
    
// Notícias
jQuery(document).ready(function() {
    jQuery('#slider').jcarousel({
	scroll: 1
	});
});

// Notícias com destaque - atual
$(document).ready(function(){
$('#slider1').bxSlider({
    auto: false,
    autoHover: false,
    tickerSpeed: 1000,
    speed: 800,
    pager: false,
    buttonNextHTML: true,
    buttonPrevHTML: true,
    ticker: false
    });
});

// Galeria de fotos
$(document).ready(function() {
    $("a.galeria").fancybox({
         'titleShow'        : false,
         'cyclic'           : true,
         'showNavArrows'    : true
    });
}); 

// Modal localização página de contato
$(document).ready(function() {
$("a.localizacao").fancybox({
    'width'		: '50%',
    'height'		: '75%',
    'autoScale'         : false,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'type'		: 'iframe',
    'titleShow'         : false
    }); 
});

// Modal geral com Iframe
$(document).ready(function() {
$("a.iframe").fancybox({
    'width'			: '40%',
    'height'			: '76%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'type'			: 'iframe',
    'titleShow'                 : false
    }); 
});

// Modal geral com Iframe
$(document).ready(function() {
$("a.cadastro_evento").fancybox({
    'width'			: '40%',
    'height'			: '84%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'type'			: 'iframe',
    'titleShow'                 : false
    }); 
});

// Barra lateral, acesso ao portal
$(document).ready(function() {
$("a.portal").fancybox({
    'width'			: '90%',
    'height'			: '100%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'type'			: 'iframe',
     'titleShow'                : false
    }); 
});

// Data
$(document).ready(function() {
$("a.data").fancybox({
    'width'			: '40%',
    'height'			: '76%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'titleShow'                 : false
    }); 
});

// Abertura dos iframe dos sistemas
$(document).ready(function() {
$("a.sistemas").fancybox({
    'width'			: '40%',
    'height'			: '76%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'type'			: 'iframe',
    'titleShow'                 : false
    }); 
});

$(document).ready(function() {
$("a.senha").fancybox({
    'width'			: '30%',
    'height'			: '38%',
    'autoScale'                 : false,
    'transitionIn'              : 'none',
    'transitionOut'             : 'none',
    'type'			: 'iframe',
    'titleShow'                 : false
    }); 
});

// Mascaras
jQuery(function($){  
   $("#data1").mask("99/99/9999");  
   $("#data2").mask("99/99/9999"); 
   $("#telefone").mask("(99) 9999-9999");  
   $("#tin").mask("99-9999999");  
   $("#ssn").mask("999-99-9999");  
   $("#cpf").mask("999.999.999-99");
});  

 //jWYSIWYG (editor)
$(function(){
    $('.wysiwyg').wysiwyg();
});

// Box login
$(function() {
    var button = $('#loginButton');
    var box = $('#loginBox');
    var form = $('#loginBox');
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#loginButton').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});


// Box Suporte
$(function() {
    var button = $('#suporteButton');
    var box = $('#suporteBox');
    var form = $('#suporteBox');
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#suporteButton').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});
  
// ################### Funções ####################  

function confirmaRemover(secao, nome, id){
	decisao = confirm("Deseja realmente excluir "+nome+"?");
		if (decisao){
			location.href="admin.php?secao="+secao+"&acao=remover&id="+id;
		}else{
			location.href="admin.php?secao="+secao;
		}
}

function confirmaRemoverIns(secao, nome, id, codigo_setor){
	decisao = confirm("Deseja realmente excluir "+nome+"?");
		if (decisao){
			location.href="admin/inscricao_remove.php?id="+id+"&codigo_setor="+codigo_setor;
		}else{
			location.href="admin.php?secao="+secao;
		}
}

function removeBox(secao, nome, id, end_img){
	decisao = confirm("Deseja realmente excluir "+nome+"? \n\n [Todos os sub-box relacionados a ele também serão removidos]");
		if (decisao){
			location.href="admin.php?secao="+secao+"&acao=remover&id="+id+"&end_img"+end_img;
		}else{
			location.href="admin.php?secao="+secao;
		}
}
function removeAlbum(secao, titulo, id, nome_pasta){
	decisao = confirm("Deseja realmente excluir o album "+titulo+"?");
		if (decisao){
			location.href="admin.php?secao="+secao+"&acao=remover&id="+id+"&nome_pasta="+nome_pasta;
		}else{
			location.href="admin.php?secao="+secao;
		}
}
function removeArquivo(secao, nome, id, end_img){
	decisao = confirm("Deseja realmente exluir "+nome+"?");
		if(decisao){
			location.href="admin.php?secao="+secao+"&acao=remover&id="+id+"&end_img="+end_img;
		}
		else{
			location.href="admin.php?secao="+secao;
		}
}
function removeNoticias(secao, nome, id, img, img_thumb, img_full){
	decisao = confirm("Deseja realmente exluir a notícia:\n\n "+nome+"?");
		if(decisao){
			location.href="admin.php?secao="+secao+"&acao=remover&id="+id+"&img="+img+"&img_thumb="+img_thumb+"&img_full="+img_full;
		}
		else{
			location.href="admin.php?secao="+secao;
		}
}

// Limpar campos (onblur onclick)
function limparPadrao(campo) {
    if (campo.value == campo.defaultValue)
        campo.value = "";
}

function escreverPadrao(campo) {
    if (campo.value == "") 
        campo.value = campo.defaultValue;    
}

// Imprimor
function imprimir(){
      if (!window.print){
         alert("Use Firefox, Chrome, Opera ou Internet Explorer \n em suas versões mais recentes!")
         return
      }
      window.print()
   }
   
// Função para validar formato do e-mail
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){
			return true;
		}
    }
	else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
			return true;
		}
    }else{
        return false;
    }
}

// Verificação dos campos preenchidos
function validaForm(i){
	if(i.email.value == "" || !checkMail(i.email.value)){
		alert('Por favor, você deve colocar um e-mail válido');
		i.email.focus();
		return false;
	}
	if(i.nome.value == ""){
		alert('Prencha o campo referente ao seu nome');
		i.nome.focus();
		return false;
	}
	if(i.estado.value == ""){
		alert('Por favor, informe o estado');
		i.estado.focus();
		return false;
	}
	if(i.telefone.value == ""){
		alert('Por favor, digite um telefone válido');
		i.assunto.focus();
		return false;
	}
	if(i.mensagem.value == ""){
		alert('Por favor, escreva uma mensagem.');
		i.mensagem.focus();
		return false;
	}
	return true;
}

// Janela com mapa da Fesp
function abrirFesp(URL) {
    
  var width = 950;
  var height = 630;
  var esquerda = 30;
  var direita = 30;

  window.open(URL,'janela', 'width='+width+', height='+height+', left='+esquerda+', right='+direita+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

// Função para adicionar aos favoritos

function addFav(){
    var url      = "http://www.emsventura.com.br";
    var title    = "EMS Ventura - Consultoria, assessoria e sistemas";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
}

function SoNumero(e) {
	var nav4 = window.Event ? true : false;
	if(nav4) {
		var whichCode = e.which;
	} else {
		var whichCode = e.keyCode;
	}
	if ( whichCode != 63 && ( (whichCode < 48 || whichCode > 57 ))   ) {
    	if(nav4 && whichCode == 8)  {
			return true;
		} else {
			return false;
		}
	} else {	
		return true;
      }
}

