
$j(document).ready(function() {
    
        //Caixa de login - index
        $j('#setaSocio').click( function() {
            $j('#caixaDetexto2').toggle();
        });

        var slider;
        slider = $j('#slider1').bxSlider({
            controls: true,
            speed: 1000,
            //  pause: 6000,
            auto: false,
            pager: false,
            // randomStart: true,
             // displaySlideQty: 2,
             // moveSlideQty: 1
        });
	
        $j('.proposta-cnmac2014-part1 #evento_local').val($j('.proposta-cnmac2014-part1 .evento_local:checked').val()); 
        $j('.proposta-cnmac2014-part1 .evento_local').click(function(){
           $j('.proposta-cnmac2014-part1 #evento_local').val($j(this).val()); 
        });
	
        if($j('.proposta-cnmac2014-part1')){
            var campos_erro_parte1 = $j('.proposta-cnmac2014-part1 .erro_obrigatorio');
            var campos_erro_parte2 = $j('.proposta-cnmac2014-part2 .erro_obrigatorio');
            var campos_erro_parte3 = $j('.proposta-cnmac2014-part3 .erro_obrigatorio');
            var campos_erro_parte4 = $j('.proposta-cnmac2014-part4 .erro_obrigatorio');
            if(campos_erro_parte1.length==0){
                if(campos_erro_parte2.length > 0){
                   $j('.proposta-cnmac2014-part1').hide(1000);
                   $j('.proposta-cnmac2014-part2').show(1000); 
                }else if(campos_erro_parte3.length > 0){
                   $j('.proposta-cnmac2014-part1').hide(1000);
                   $j('.proposta-cnmac2014-part3').show(1000); 
                }else if(campos_erro_parte4.length > 0){
                   $j('.proposta-cnmac2014-part1').hide(1000);
                   $j('.proposta-cnmac2014-part4').show(1000); 
                }
            }
        }
        
	$j('.proposta-cnmac2014-link2').click(function(){		
		$j('.proposta-cnmac2014-part1 input, .proposta-cnmac2014-part1 textarea').each(function(){			
			//trim white spaces
			$j(this).val($j.trim($j(this).val()));
			
			//check if the value null and send error messages
			if (!$j(this).val()){	
				$j(this).addClass('error');	
				thisClass = 'span.'+$j(this).attr('name');		
				$j(thisClass).show(175);			

			//if they are not null
			}else{				
				if (($j('#evento_indicado_por').val()) && ($j('#evento_instituicao').val()) && ($j('#evento_email').val()) && ($j('#evento_organizadores').val()) && ($j('#evento_cidade').val())){			
				
					//get witch radio is checked
					var radioValue  = $j("#form_propostaCNMAC2014 input[type='radio']:checked").val();

					if (radioValue === 'Universidade'){
						$j(this).removeClass('error');	
						thisClass = 'span.'+$j(this).attr('name');
						$j(thisClass).hide(175);
						$j('.proposta-cnmac2014-part1').hide(1000);
						$j('.proposta-cnmac2014-part2').show(1000);						
						
					}else{
						$j(this).removeClass('error');	
						thisClass = 'span.'+$j(this).attr('name');
						$j(thisClass).hide(175);
						$j('.proposta-cnmac2014-part1').hide(1000);
						$j('.proposta-cnmac2014-part3').show(1000);						
					}
				
				}else{					
					$j(this).removeClass('error');
				}				
			}	
		});
	});
	
	$j('.proposta-cnmac2014-back').click(function(){	
		$j('.proposta-cnmac2014-part2').hide(1000);
		$j('.proposta-cnmac2014-part3').hide(1000);
		$j('.proposta-cnmac2014-part4').hide(1000);
		$j('.proposta-cnmac2014-part1').show(1000);	
	});
	
	$j('.proposta-cnmac2014-link4').click(function(){	
		$j('.proposta-cnmac2014-part2').hide(1000);
		$j('.proposta-cnmac2014-part3').hide(1000);
		$j('.proposta-cnmac2014-part4').show(1000);	
	});
	

	$j('.proposta-cnmac2014-part1 input, .proposta-cnmac2014-part1 textarea').blur(function(){
		$j(this).val($j.trim($j(this).val()));
		
		if (!$j(this).val()){	
			$j(this).addClass('error');	
			thisClass = 'span.'+$j(this).attr('name');		
			$j(thisClass).show(175);	

		//if they are not null
		}else{
			$j(this).removeClass('error');	
			thisClass = 'span.'+$j(this).attr('name');
			$j(thisClass).hide(175);				
		}
	});
});

Event.observe(window, 'load', inicio);

function inicio(){
    //menus
    //menus();
    //link boletos não pagos
    if($('deposito_npg')){
        //alert('Tem link para Depositos')
        //cursor
        Element.addClassName($('deposito_npg'), 'deposito_npg');
        //funcao
        Event.observe($('deposito_npg'), 'click', function(){
            DepositoInfos($('deposito_npg'))
            }, false);
    }

    //filtros da superbusca
    if($('superbusca')){
        Element.hide($('sb_filtros'));
        Event.observe($('sb_link'), 'click', function(){
            Element.toggle($('sb_filtros'))
        }, false);
    }


    //Form do Envio de Arquivo de Retorno
    if($('form_bbt')){
        Element.hide($('form_bbt'));
        Event.observe($('form_bbt_label'), 'click', function(){
            Element.toggle($('form_bbt'))
        }, false);
    }
	
    //Esconde Membros das Chapas - ADM
    if($('tab_chapas')){
        //esconde
        chapaMembros();
		
    //para fechar
    //Event.observe($('total_adm'), 'click', function(){ chapaMembros(); }, false);
    }
	
    //Esconde Membros das Chapas - VOTACAO
    if($('form_votacao')){
        //esconde
        //chapaMembros();
		
        //Observa Conselheiros
        var cons = document.getElementsByClassName('votoConselheiro');
        var consArray = $A(cons);
        consArray.each(function(con){
	    	
            Event.observe($(con), 'click', function(){
                conselheirosLimite(this);
            }, false);
	    	
        });
        //para fechar
        //Event.observe($('total'), 'click', function(){ chapaMembros(); }, false);
	    

        //Observa opçao BRANCO & NULO em conselheiros
        Event.observe($('consB'), 'click', function(){
            unSelectCons();
        }, false);
        Event.observe($('consN'), 'click', function(){
            unSelectCons();
        }, false);

	    		
    }//if
	
	
    //Ajusta form da eleicao, conforme seu tipo
    if($('eleicao_form')){
		
		
        eleicaoFormTipo($('tipo'));
        Event.observe($('tipo'), 'change', function(){
            eleicaoFormTipo($('tipo'));
        }, false);
		
    }
	
	


}//INICIO

function refAno(anoGet){
		
    var url = String(document.location);
	var urlNew = "";
    // verifica se o parametro e um numero, que vira atraves do $_GET
    if(isFinite(anoGet)==true){
			
        //substitui
        if(anoGet>0){
            urlNew = url.replace("refAno="+anoGet, "refAno="+$F("refAno"));
        }else{
				
            urlNew = url + "&refAno="+$F("refAno");
        }
			
        //redireciona
        window.location = urlNew;

    }else{
        //erro
        alert('O parametro refAno, não é um numero válido!')
    }
		
}


function eleicaoFormTipo(tipo){
		
    if(tipo.value=="simples"){
			
        Element.show($('label_titulo'));
        Element.hide($('label_ano'));
			
        Element.show($('label_eleitos'));
        Element.show($('label_votados'));

        Element.hide($('label_cad_ini'));
        Element.hide($('label_cad_fim'));
			
        Element.show($('label_vot_ini'));
        Element.show($('label_vot_fim'));
			
        Element.hide($('label_apuracao'));
        Element.show($('txt_apuracao'));
			
    }else if(tipo.value=="geral"){

        Element.hide($('label_titulo'));
        Element.show($('label_ano'));
			
        Element.hide($('label_eleitos'));
        Element.hide($('label_votados'));

        Element.show($('label_cad_ini'));
        Element.show($('label_cad_fim'));
			
        Element.show($('label_vot_ini'));
        Element.show($('label_vot_fim'));
			
        Element.show($('label_apuracao'));
        Element.hide($('txt_apuracao'));
			
    }
    else{

        Element.hide($('label_titulo'));
        Element.hide($('label_ano'));
			
        Element.hide($('label_eleitos'));
        Element.hide($('label_votados'));

        Element.hide($('label_cad_ini'));
        Element.hide($('label_cad_fim'));
			
        Element.hide($('label_vot_ini'));
        Element.hide($('label_vot_fim'));
			
        Element.hide($('label_apuracao'));
        Element.hide($('txt_apuracao'));
			
    }
		
}
	

function boxEmails(){
    window.open('../admin/envia_emails.php?popup=1','emails','top=100, left=100, width=160, height=150, channelmode=0, directories=0, fullscreen=0, location=0, menubar=0, resizable=1, scrollbars=0, titlebar=0, toolbar=0,  status=1, dialog=1, minimizable=1');
}


function unSelectCons(){
    var cons = document.getElementsByClassName('votoConselheiro');
    var consArray = $A(cons);
    consArray.each(function(con){
        if($(con).checked==true){
            $(con).checked = false;
        }
    });
}//function




function conselheirosLimite(obj){
	
    //alert(obj.id);
    //alert(obj.value);
		
    //Desmarca BRANCO se tiver selecionado
    if($('consB').checked){
        $('consB').checked = false;
    }
    //Desmarca NULO se tiver selecionado
    if($('consN').checked){
        $('consN').checked = false;
    }
		
    //limite
    var limite = ($('ele_votados'))? $('ele_votados').innerHTML : 10;
    //alert('LIMITE: '+limite);
		
	
    //zera
    var count = 0;
		
    var cons = document.getElementsByClassName('votoConselheiro');
    var consArray = $A(cons);
    consArray.each(function(con){
	    	
        if($(con).checked==true){
            //soma no contador
            count++;
            //alert(count);
            if(count>limite){
                $(obj).checked = false;
                alert('Você pode selecionar somente '+ ((limite>1)?'até '+limite+' candidatos':'1 candidato') +'!');
            }//else
        }

    });
	

}//funcao	
	


function chapaMembros(chapa_id){
    /*
		var chapas = document.getElementsByClassName('membrosChapa');
	    var chapasArray = $A(chapas);
	    chapasArray.each(function(chapa){
	    	Element.hide($(chapa));
	    });
	    //if($(chapa_id)){
	    if(chapa_id>0){
    		Element.show($('membrosChapa'+chapa_id));	
	    }
	    */
		
    if($('membrosChapa'+chapa_id)){
        Element.toggle($('membrosChapa'+chapa_id));
    }else{
        //pega todos elementos com a classe e faz um loop
        $A($$('.membrosChapa')).each(function(chapa){
            Element.hide($(chapa));
        }//function
        )//each
    ;//fim
    }//else
	    
}//chapaMembros()


function gerarCedulas(ele_id){
    if(confirm('Você tem certeza que deseja Gerar as Células desta eleição?\n\nObs.: Este processo pode demomorar alguns minutos, não feche e nem atualize esta página!')){
        window.open('bot/eleicoes_cedulas.php?ele_id='+ele_id, '_self');
    }
}//fucntion



function DepositoInfos(obj){

    //alert('Function DepositoInfos();');
    //alert(obj.id);

    //janela
    window.open('deposito_infos.php','deposito_infos','top=150, left=300, width=500, height=600, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no');
}



function menus(){

    var navegador = navigator.appName

    if (navegador == "Microsoft Internet Explorer"){
        navHoverIE();
    }else{
        navHover();
    }

}


//Menu Principal - IE
function navHoverIE() {

    //	alert(navigator.appName);

    var lis = document.getElementById("navmenu").getElementsByTagName("LI");
    for (var i=0; i<lis.length; i++) {
        lis[i].onmouseover=function() {
            this.className+=" iehover";
        }
        lis[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" iehover\\b"), "");
        /*this.className= addClassName(this, " iehover");*/
        }
        lis[i].onclick=function() {
            if(this.firstChild.target == '_self') {
                window.location=this.firstChild.href;
            }
        }
    }
}

//Menu Principal - Outros Navegadores
function navHover() {

    //	alert(navigator.appName);

    var lis = document.getElementById("navmenu").getElementsByTagName("LI");
    for (var i=0; i<lis.length; i++) {
        //		lis[i].onmouseover=function() {
        //			this.className+=" iehover";
        //		}
        //		lis[i].onmouseout=function() {
        //			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
        //		}
        lis[i].onclick=function() {
            if(this.firstChild.target == '_self') {
                window.location=this.firstChild.href;
            }
        }
    }
}



//Jump Menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu2(targ,selObj,restore,url){ //v3.0
    eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

//pop up window
function openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}
