﻿var App = {};

//Função que simula o Request.QueryString
App.QueryString = function(variavel){
    var variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&");
    var nvar;
    
    if(variaveis!="")
    {
        var qs=[];
        for(var i=0;i<variaveis.length;i++){
            nvar=variaveis[i].split("=");
            qs[nvar[0]]=unescape(nvar[1]);
        }
        return qs[variavel];
    }
    return null;
}

//Centraliza controle da tela
App.CentralizaControle = function(ctrl)
{	
	ctrl.style.position = 'absolute';
	ctrl.style.display = '';
	
	var scrollTop = parseInt(document.documentElement.scrollTop) || parseInt(document.body.scrollTop);
	var scrollLeft = parseInt(document.documentElement.scrollLeft) || parseInt(document.body.scrollLeft);
    
	//ctrl.style.top = Math.max(scrollTop, scrollTop + document.documentElement.clientHeight - (ctrl.clientHeight) - ((document.documentElement.clientHeight - ctrl.clientHeight) / 2)) + 'px';
	//ctrl.style.left = ( document.documentElement.scrollLeft + (document.documentElement.clientWidth/2) - (ctrl.clientWidth / 2)) + 'px';  
	
	var windowHeight = (window.innerHeight ? window.innerHeight : document.body.clientHeight);
	var windowWidth = (window.innerWidth ? window.innerWidth : document.body.clientWidth);
    ctrl.style.top = ((windowHeight/2) - (ctrl.clientHeight/2)) + scrollTop;
    ctrl.style.left = ((windowWidth/2) - (ctrl.clientWidth/2)) + scrollLeft;
}

App.CentralizaBoxErroLogin = function(ctrl)
{	
	ctrl.style.position = 'absolute';
	ctrl.style.display = '';
	
	var scrollTop = parseInt(document.documentElement.scrollTop) || parseInt(document.body.scrollTop);
	var scrollLeft = parseInt(document.documentElement.scrollLeft) || parseInt(document.body.scrollLeft);
    
	//ctrl.style.top = Math.max(scrollTop, scrollTop + document.documentElement.clientHeight - (ctrl.clientHeight) - ((document.documentElement.clientHeight - ctrl.clientHeight) / 2)) + 'px';
	//ctrl.style.left = ( document.documentElement.scrollLeft + (document.documentElement.clientWidth/2) - (ctrl.clientWidth / 2)) + 'px';  
	
	var windowHeight = (window.innerHeight ? window.innerHeight : document.body.clientHeight);
	var windowWidth = (window.innerWidth ? window.innerWidth : document.body.clientWidth);
    //ctrl.style.top = ((windowHeight/2) - (ctrl.clientHeight/2)) + scrollTop;
    //ctrl.style.left = ((windowWidth/2) - (ctrl.clientWidth/2)) + scrollLeft - 500;
    ctrl.style.top = '40px';
    ctrl.style.left = '300px'
}


App.EscondeTela = function()
{
    App.divEscondeTela = document.getElementById("divEscondeTela");
    
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    
    
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

	App.divEscondeTela.style.position = 'absolute';
	App.divEscondeTela.style.top = '0px';
	App.divEscondeTela.style.left = '0px';
	App.divEscondeTela.style.height = pageHeight + 'px';
	App.divEscondeTela.style.width = pageWidth + 'px';
	App.divEscondeTela.style.display = '';

	if(App.Browser.IE6)
	{
	    var combos = document.getElementsByTagName("select");
	    for(var i = 0; i<=combos.length ; i++) 
	    {
	        if (combos[i] != null && combos[i].className.indexOf("NaoEsconda") == -1)
	           combos[i].style.display = 'none';
	    }
	}		
}

App.ExibeTela = function()
{
    App.divEscondeTela = document.getElementById("divEscondeTela");
    
	App.divEscondeTela.style.display = 'none';
	
	if(App.Browser.IE6)
	{
	    var combos = document.getElementsByTagName("select");
	    for(var i = 0; i<=combos.length; i++)
	    {
	        if (combos[i] != null)
	           combos[i].style.display = '';
	    }
	}	
}

App.Browser =
{
	IE8: /MSIE (\d+\.\d+);/.test(navigator.userAgent) && (new Number(RegExp.$1) == 8) ,
	IE7: /MSIE (\d+\.\d+);/.test(navigator.userAgent) && (new Number(RegExp.$1) == 7) ,
	IE6: /MSIE (\d+\.\d+);/.test(navigator.userAgent) && (new Number(RegExp.$1) == 6) ,
	IE5: /MSIE (\d+\.\d+);/.test(navigator.userAgent) && (new Number(RegExp.$1) == 5) 
}


App.GetElementsByClassName = function (className, tagName)
{
    var elem = document.getElementsByTagName(tagName || 'div');
    var ret = new Array();
    for (var i = 0; i < elem.length; i++)
    {
        if (elem[i].className && elem[i].className.toLowerCase().indexOf(className.toLowerCase()) >= 0)
        {
            ret.push(elem[i]);
        }
    }
    return ret;
}

App.ExibeErroLogin = function()
{
    App.DivErroLogin = document.getElementById('boxErroLogin');
    
    App.EscondeTela();

    App.DivErroLogin.style.position = 'absolute';
    App.DivErroLogin.style.display = '';
    App.CentralizaBoxErroLogin(App.DivErroLogin);
}

App.EscondeErroLogin = function()
{
    App.DivEscondeErroLogin = document.getElementById('boxErroLogin');
    App.DivEscondeErroLogin.style.display = 'none';
    
    App.ExibeTela();
}
