///* --------------------------------------------------------------
//
//   Arquivo do Plugin Jquery: CalendarioCuca
//
//   Basiado Nos Padrões W3C
//   http://www.w3schools.com/
//
//-------------------------------------------------------------- */
//
///* Calendário: Cuca_Compromissos_Fiscais v1.0 | - @author: Departamento Web Cuca Fresca */
//
function tela(){
    alert($(document.body).height());
}

function pos(){
    alert(window.scrollY);
}
 
$(document).ready(function(){    
    $("#calendario").fadeIn();
   $(window).scroll(function(){
        //pega a posição do scroll top
        scr = window.scrollY;
        rodape = $(document.body).height();        
        //se não funcionar
        if(!scr > 0){
            //pega a posição do scroll top de outra maneira
            scr = document.body.parentNode.scrollTop;
        }

        if(scr <= 200){            
            $("#calendario").css("position","inherit");
            $("#calendario").css("top","auto");
        }

        if(scr > 387){
            $("#calendario").fadeIn().stop();
            $("#calendario").css("position","fixed");
            $("#calendario").css("top","40%");
        }else{            
            $("#calendario").css("position","inherit");
            $("#calendario").css("top","auto");
        }                     
                
       if(scr >=rodape-650){
            $("#calendario").fadeOut().stop();
            $("#calendario").css("position","inherit");
            $("#calendario").css("top","auto");
       }
     });
   
   $("#calendario").css("position","inherit");
   $("#calendario").css("top","auto");
   
        


     
        
        
    $(".tc").click(function(){        
        var mes = $(".meseano").text();
        
        var localizacao = location;                      
        var pos = localizacao.toString().lastIndexOf("estado");        
        var estado = localizacao.toString().substr(pos+7, 2);               
                
        var dia   = $(this).text();                
        $(".compromisso-inicial").text("");
        $(".compromisso-inicial").html("<div id='carregar'><img src='http://www.cucafresca.com.br/public/img/carregar.gif' /><p>Carregando</p></div>");
//        Local
//        $(".compromisso-inicial").html("<div id='carregar'><img src='http://localhost/cucazend/public/img/carregar.gif' /><p>Carregando</p></div>");
//         
//         

        if(estado != "sp" && estado != "ms"){
            estado = "";
        }
        var envio = "dia="+dia+"&mes="+mes+"&estado="+estado;
        
        http = new XMLHttpRequest();
        http.onreadystatechange = retornaCompromissos;    
//        Local
//        http.open("POST","http://localhost/cucazend/agenda/ajax",true);    
// 
        http.open("POST","http://www.cucafresca.com.br/agenda/ajax",true);    
        http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        http.send(envio);    
    });
    
    $("#mostarCompromissos").click(function(){
        var mes = $(".meseano").text();
        $(".compromisso-inicial").text("");
        $(".compromisso-inicial").html("<div id='carregar'><img src='http://www.cucafresca.com.br/public/img/carregar.gif' /><p>Carregando</p></div>");
//        $(".compromisso-inicial").html("<div id='carregar'><img src='http://locahost/cucazend/public/img/carregar.gif' /><p>Carregando</p></div>");
        
        var envio = "dia=todos&mes="+mes;
        
        http = new XMLHttpRequest();
        http.onreadystatechange = retornaCompromissos;    
        http.open("POST","http://www.cucafresca.com.br/agenda/ajax",true);    
//        Local
//        http.open("POST","http://localhost/cucazend/agenda/ajax",true);    
//        http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
// 
//        http.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");        
        http.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=iso-8859-1");        
        http.send(envio);    
        
    });
    
    $(".tday").click(function(){        
        var mes = $(".meseano").text();
        
        var localizacao = location;                      
        var pos = localizacao.toString().lastIndexOf("estado");        
        var estado = localizacao.toString().substr(pos+7, 2);        
        
        if(estado != "sp" && estado != "ms"){
            estado = "";
        }
        
        mes =  (mes);
                
        var dia   = $(this).text();                
        $(".compromisso-inicial").text("");
//        Local        
//        $(".compromisso-inicial").html("<div id='carregar'><img src='http://localhost/cucazend/public/img/carregar.gif' /><p>Carregando</p></div>");
// 
        $(".compromisso-inicial").html("<div id='carregar'><img src='http://www.cucafresca.com.br/public/img/carregar.gif' /><p>Carregando</p></div>");
        
        var envio = "dia="+dia+"&mes="+mes+"&estado="+estado;
        
        http = new XMLHttpRequest();
        http.onreadystatechange = retornaCompromissos;    
//        Local
//        http.open("POST","http://localhost/cucazend/agenda/ajax",true);    
// 
        http.open("POST","http://www.cucafresca.com.br/agenda/ajax",true);    
        http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        http.send(envio);    
    });
    
    $("#mostarCompromissos").click(function(){
        var mes = $(".meseano").text();
        $(".compromisso-inicial").text("");
//        Local
//        $(".compromisso-inicial").html("<div id='carregar'><img src='http://localhost/cucazend/public/img/carregar.gif' /><p>Carregando</p></div>");
// 
        $(".compromisso-inicial").html("<div id='carregar'><img src='http://www.cucafresca.com.br/public/img/carregar.gif' /><p>Carregando</p></div>");
        
        var envio = "dia=todos&mes="+mes;
        
        http = new XMLHttpRequest();
        http.onreadystatechange = retornaCompromissos;    
//        Local
//        http.open("POST","http://localhost/cucazend/agenda/ajax",true);    
// 
        http.open("POST","http://www.cucafresca.com.br/agenda/ajax",true);    
        http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        http.send(envio);    
        
    });    
    
    function retornaCompromissos(){                
        if(http.readyState == 4 ){
            //document.getElementById("retornoErro").innerHTML = http.responseText;
            $(".compromisso-inicial").text("");
            $(".compromisso-inicial").html(http.responseText);          
            $("#todos").css("background","url(../public/img/tab.png) no-repeat");            
            
//            $("#aba").html("<div id='todos' class='tabCompromisso' onclick=\"filtro('todos');\">Todos</div><div id='saoPaulo' class='tabCompromisso' onclick=\"filtro('saoPaulo');\">São Paulo</div><div id='matoGrosso' class='tabCompromisso' onclick=\"filtro('matoGrosso');\">Mato Grosso do Sul</div><div id='federal' class='tabCompromisso' onclick=\"filtro('federal');\">Federal</div>");
//            $(".compromisso-inicial").text(http.responseText);            
        }else{            
//            $(".compromisso-inicial").text(http.readyState+' - '+http.status);
//            $document.getElementById("respostaEmail").innerHTML = http.readyState+' - '+http.status;
        }     
    }
    
    

     });
