
var site;
var geovotoObj;

var urlDesktop;

/*
CLASSE EUVOTO
*/

function euvoto(obj)
{
    this.objeto = obj;
    
    this.logado = false;
    
    this.screenH = this.objeto.screen.height;
    this.screenW = this.objeto.screen.width;
    this.contextoDesktop = "";
    
    this.carga = setUp;       
}


function iniciarSite(obj)
{
    this.site = new euvoto(obj);
    this.site.carga();

    divTexto = document.getElementById("boxGeovoto1_hdTextos");
    divTexto.value = "block";
       
    this.geovotoObj = new geovoto();
}

function trocaFerramenta(obj)
{
    divTexto = document.getElementById("boxGeovoto1_hdTextos");
    divTexto.value = "none";
    this.geovotoObj = new geovoto();
}

function setUp()
{
    detectaRes();
}

function detectaRes()
{
    screenH = this.site.screenH;
    screenW = this.site.screenW;
       
    urlDesktop = "geovoto/desktop.aspx?screenH="+ screenH +"&screenW="+ screenW;
    
    this.contextoDesktop = urlDesktop;
}



/*
CLASSE GEOVOTO
*/

function geovoto()
{   
    this.ferramenta = document.getElementById("boxGeovoto1_hFerramenta").value;
    this.ferramentaObj = null;
    
    this.textos = document.getElementById("boxGeovoto1_hdTextos");
    
    if (this.textos.value == "block")
    {
        manipulaDiv("TEXTOS");
        visibleBox("VOTODISTRITAL",'none');
        visibleBox("ANALISEVOTO",'none');
        
        switch (this.ferramenta)
        {
            case "VOTODISTRITAL":
            {
                this.ferramentaObj = new votoDistrital();
                manipulaDiv("VOTODISTRITAL");
                break;
            }
            
            case "ANALISEVOTO":
            {
                this.ferramentaObj = new analiseDoVoto();
                manipulaDiv("ANALISEVOTO");
                break;            
            }
            
            case "VAZIO":
            {
                visibleBox("VOTODISTRITAL",'none');
                visibleBox("ANALISEVOTO",'none');
            }
        }
    }
    else
    {
        switch (this.ferramenta)
        {
            case "VOTODISTRITAL":
            {
                this.ferramentaObj = new votoDistrital();
                visibleBox("textos",'none');
                visibleBox("analise",'none');
                visibleBox("distrital",'block');

                manipulaDiv("VOTODISTRITAL");
                break;
            }
            
            case "ANALISEVOTO":
            {
                this.ferramentaObj = new analiseDoVoto();
                visibleBox("textos",'none');
                visibleBox("analise",'block');
                visibleBox("distrital",'none');

                manipulaDiv("ANALISEVOTO");
                break;            
            }
        }
    }    
}

function iniciarDesktop()
{
    urlDesktop = urlDesktop.replace('desktopAnalise.aspx','desktop.aspx');
    window.open(urlDesktop + this.geovotoObj.ferramentaObj.query,"DESKTOP","fullscreen=1,resizable=0,status=0,titlebar=0,tollbar=0,menubar=0,location=0,directories=0,scrollbars=0");
}


/*
CLASSE ANALISEVOTO
*/
function analiseDoVoto()
{
    this.uf = document.getElementById("boxGeovoto1_dd2UF").value;
    this.ano = document.getElementById("boxGeovoto1_dd2Ano").value;
    this.cargo = document.getElementById("boxGeovoto1_dd2Cargo").value;
    varIr = document.getElementById("hdIr").value;

    this.query = "&ferramenta=ANALISEVOTO&uf="+ this.uf +"&idEleicao="+ this.cargo +"&cargo="+ this.cargo +"&mapa=0&ir="+ varIr;        
}


function iniciarDesktopAnalise()
{
    urlDesktop = urlDesktop.replace('desktop.aspx','desktopAnalise.aspx');
    window.open(urlDesktop + this.geovotoObj.ferramentaObj.query,"DESKTOPANALISE","fullscreen=1,resizable=0,status=0,titlebar=0,tollbar=0,menubar=0,location=0,directories=0,scrollbars=0");
}


/*
CLASSE VOTODISTRITAL
*/
function votoDistrital()
{
    this.tipo = document.getElementById("boxGeovoto1_ddTipo").value;
    this.uf = document.getElementById("boxGeovoto1_ddUF").value;
    this.ano = document.getElementById("boxGeovoto1_ddAno").value;
    this.cargo = document.getElementById("boxGeovoto1_ddCargo").value;
    this.tol = document.getElementById("boxGeovoto1_ddTol").value;
    this.mapa = document.getElementById("boxGeovoto1_ddMapa").value;
    varIr = document.getElementById("hdIr").value;
       
    this.query = "&ferramenta=VOTODISTRITAL&tipo="+ this.tipo +"&uf="+ this.uf +"&idEleicao="+ this.cargo +"&cargo="+ this.cargo +"&tol="+ this.tol +"&mapa="+ this.mapa +"&ir="+ varIr;
}

/*
FUNCTIONS COMUNS
*/
function exibe(obj)
{
    this.geovotoObj = new geovoto();
    
    var1 = obj.id.toString();
    var2 = obj.value.toString();
    
    //alert(var1 +' = '+ var2);
    //alert(urlDesktop + this.geovotoObj.ferramentaObj.query);
}

function atuObj(obj)
{
    this.geovotoObj = new geovoto();
    
    if (document.getElementById("boxGeovoto1_hFerramenta").value.toString() == "VOTODISTRITAL")
    {
        btnIniciar = document.getElementById("BoxGeovoto1_imgBtnIniciar");
        
        if ((obj.id == "BoxGeovoto1_ddUF") || (obj.id == "BoxGeovoto1_ddAno") || (obj.id == "BoxGeovoto1_ddCargo"))
        {    
            if ((btnIniciar != null) && (btnIniciar != 'undefined'))
            {
                btnIniciar.style.display = 'none';
            }
        }
    }
    
    if (document.getElementById("boxGeovoto1_hFerramenta").value.toString() == "ANALISEVOTO")
    {
        btnIniciar = document.getElementById("BoxGeovoto1_imgBtnIniciarAnaliseVoto");
        
        if ((obj.id == "BoxGeovoto1_dd2UF") || (obj.id == "BoxGeovoto1_dd2Ano"))
        {    
            if ((btnIniciar != null) && (btnIniciar != 'undefined'))
            {
                btnIniciar.style.display = 'none';
            }
        }
    }
    
}


function trocaImg(obj)
{
    eventoBtn = window.event.type;
    
    switch (eventoBtn)
    {
        case "mouseover":
        {
            obj.src = "images/"+ obj.id.substring(eval(obj.id.indexOf('_')+1)) +"_2.gif";            
            break;        
        }
        
        case "mouseout":
        {
            obj.src = "images/"+ obj.id.substring(eval(obj.id.indexOf('_')+1)) +".gif";                        
            break;
        }        
    }    
}

function resetForm(objStr)
{
    document.getElementById(objStr).reset();
}

function visibleBox(nomeObj,tipo)
{
    divObj = document.getElementById(nomeObj.toString());
    divObj.style.display = tipo; 
}

function manipulaDiv(nomeDiv)
{    
    if (nomeDiv.toString() == "VOTODISTRITAL")
    {
        visibleBox("VOTODISTRITAL",'block');
        visibleBox("ANALISEVOTO",'none');
        objFerramenta = document.getElementById("BoxGeovoto1_hFerramenta");
        objFerramenta.value = "VOTODISTRITAL";
        
        //objTextos = document.getElementById("boxGeovoto1_hdTextos");
        //objTextos.value = "none";               
    }
    
    if (nomeDiv.toString() == "ANALISEVOTO")
    {
        visibleBox("VOTODISTRITAL",'none');
        visibleBox("ANALISEVOTO",'block');
        objFerramenta = document.getElementById("BoxGeovoto1_hFerramenta");
        objFerramenta.value = "ANALISEVOTO";

        //objTextos = document.getElementById("boxGeovoto1_hdTextos");
        //objTextos.value = "none";      
    }           
        
    if (nomeDiv.toString() == "TEXTOS")
    {        
        visibleBox("textos",'block');
        visibleBox("analise",'none');
        visibleBox("distrital",'none');        
    }        
}