function marcarLinha(nome, mensagem){
	$('#li_'+nome).addClass('error');
	$('#notice_'+nome).html(mensagem);
	$('#notice_'+nome).addClass('error');
	$('#notice_'+nome).show();
}

function desmarcarLinha(nome){
    $('#li_'+nome).removeClass('error');
    $('#notice_'+nome).html('');
    $('#notice_'+nome).removeClass('error');
    $('#notice_'+nome).hide();
}

// Administry object setup
if (!Administry) var Administry = {}

// scrollToTop() - scroll window to the top
Administry.scrollToTop = function (e) {
    $(e).hide().removeAttr("href");
    if ($(window).scrollTop() != "0") {
        $(e).fadeIn("slow")
    }
    var scrollDiv = $(e);
    $(window).scroll(function () {
        if ($(window).scrollTop() == "0") {
            $(scrollDiv).fadeOut("slow")
        } else {
            $(scrollDiv).fadeIn("slow")
        }
    });
    $(e).click(function () {
        $("html, body").animate({
            scrollTop: 0
        }, "slow")
    })
}

$(document).ready(function(){
    
    $.ajaxSetup({
    		error:function(x,e){
    			if(x.status==0){
    			alert('Você está desconectado!!\n Por favor verifique a sua conexão com a internet.');
    			}else if(x.status==404){
    			alert('Página não encontrada.');
    			}else if(x.status==500){
    			alert('Erro ao acessar dados do servidor.');
    			}else if(e=='parsererror'){
    			alert('Error.\nParsing JSON Request failed.');
    			}else if(e=='timeout'){
    			alert('Request Time out.');
    			}else {
    			alert('Unknow Error.\n'+x.responseText);
    			}
    		}
    	});    
    
	$('ul#left-nav ul li ').hover(function() {
	 	$(this).css("background","#9bc6ea");
	}, function() {
	  	$(this).css("background","#fff");	
	});			

	$('#destaques .materia, #destaques .materia-last ').hover(function() {
	 	$(this).css("background-color","#FFFCEC");
	}, function() {
	    if ($(this).hasClass('odd')) {
	        $(this).css("background-color","#F3F3F3");
	    }else{
	        $(this).css("background-color","#FBFBFB");
	    }
	});		
	
	$('#materias .materia, #materias .materia-last ').hover(function() {
	 	$(this).css("background-color","#FFFCEC");
	}, function() {
	    if ($(this).hasClass('odd')) {
	        $(this).css("background-color","#F3F3F3");
	    }else{
	        $(this).css("background-color","#FBFBFB");
	    }
	  	
	});
	
	
	$.fmask.masks = {
	    'fone'      : { mask : '(99)9999-9999' },
	    'cpf'       : { mask : '999.999.999-99' },
	    'cnpj'      : { mask : '99.999.999/9999-99' },
	    'date'      : { mask : '99/99/9999' },
	    'cep'       : { mask : '99999-999' },
	    'time'      : { mask : '29:69' },
	    'codigo'    : { mask: '99999-*'}
	}
	
	$('input:text').setMask({autoTab:false});
	
	$('#menu-filtro').click(function(){
	    $("#filtro").toggle();
	});
	
	$("a[rel]").overlay({
		//effect: 'apple',
		expose: '#333',
		closeOnClick: false,
		fixed: 	false,
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}
	});
	
	$('.closed').click(function(){
		$("a[rel]").overlay().close();
	});
	
	if ($("a#totop").length) Administry.scrollToTop("a#totop");
	
	$('#loading').ajaxStart(function(){
		$(this).show();
	});
	
	$('#loading').ajaxStop(function(){
		$(this).hide();
	}); 	
})

function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }

function validarCNPJ(cnpj){
	var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = cnpj;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
    for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
	
}

function validarCPF(cpf){
	  var numeros, digitos, soma, i, resultado, digitos_iguais;
	  digitos_iguais = 1;
	  if (cpf.length < 11)
			return false;
	  for (i = 0; i < cpf.length - 1; i++)
			if (cpf.charAt(i) != cpf.charAt(i + 1))
				  {
				  digitos_iguais = 0;
				  break;
				  }
	  if (!digitos_iguais)
			{
			numeros = cpf.substring(0,9);
			digitos = cpf.substring(9);
			soma = 0;
			for (i = 10; i > 1; i--)
				  soma += numeros.charAt(10 - i) * i;
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(0))
				  return false;
			numeros = cpf.substring(0,10);
			soma = 0;
			for (i = 11; i > 1; i--)
				  soma += numeros.charAt(11 - i) * i;
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(1))
				  return false;
			return true;
			}
	  else
			return false;
}


