function CacheImagens() {
	cacheArr = new Array(
					"../imagens/geral/menu-unidades-0-sel.gif",
					"../imagens/geral/menu-unidades-1-sel.gif",
					"../imagens/geral/menu-unidades-2-sel.gif",
					"../imagens/geral/lateral-menu-item-2-hover.gif",
					"../imagens/geral/lateral-menu-item-2-subs-hover.gif",
					"../imagens/geral/lateral-menu-item-hover.gif",
					"../imagens/geral/lateral-menu-item-subs-hover.gif",
					"../imagens/geral/enderecos-0-fundo-h.gif",
					"../imagens/geral/menu-niveis-0-sel.gif",
					"../imagens/geral/menu-niveis-1-sel.gif",
					"../imagens/geral/menu-niveis-2-sel.gif",
					"../imagens/geral/menu-niveis-3-sel.gif"
					);
	imageCache = new Array();
	
	for (a = 0; a < cacheArr.length; a++) {
		imageCache[a] = new Image();
		imageCache[a].src = cacheArr[a];
	}
}

CacheImagens();


function Janela(e, w, h, p, nome) {
	try {
		param = "";
		if (p != null)
			param = ", " + p;

		centrox = (screen.width / 2) - (w / 2);
		centroy = (screen.height / 2) - (h / 2);

		if (navigator.appName.indexOf("Opera") != -1) {
			test = (screen.height - (screen.height * 0.25));
			centroy = (test / 2) - (h / 2);
		}
		if (navigator.appName.indexOf("Explorer") != -1) {
			w += 20;
		}

		window.open(e.href, nome, "left=" + centrox + ", top=" + centroy + ", width=" + w + ", height=" + h + "" + param);

		if (window.event)
			event.returnValue = false;
	}
	catch(e) {
		if (window.event)
			event.returnValue = true;
		
	}
	return false;
}



function ValidarFormulario(Form) {
	Campos = Form.getElementsByTagName("input");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].type == "text" && Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("select");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].options[Campos[a].selectedIndex].value.length == "") {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("textarea");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	return true;
}



Delegate = {
	version: "1.0"
}
Delegate.create = function(obj, func, args){
	var f = function(){
		var target = arguments.callee.target;
		var func = arguments.callee.func;
		var args = arguments.callee.args;
		return func.apply(target, (args.length <1 ? arguments : args));
	};
	f.args = (args != undefined && args.length> 0 ? args : new Array());
	f.target = obj;
	f.func = func;
	return f;
}



function fechaRecarrega() {
	window.opener.location = window.opener.location;
	window.top.close();
}


var subMenusHover = new Array();

var subMenusHoverAtual = null;

function subMenus() {
    $("a[rel!='']").hover(
        function() {

            clearTimeout(this.timerSubmenus);

            //$(subMenusHoverAtual).css("display", "none");

            //subMenusHoverAtual = $("#" + this.id).attr("rel");

            this.idSubmenu = "#" + $("#" + this.id).attr("rel");
            this.classeInicial = this.className;

            //if (this.idSubmenu == "#uSub15") {
            //alert(this.idSubmenu);
            //}

            if (this.classeInicial != "" && this.classeInicial != null)
                $(this).addClass(this.id + "-Sel");
            else
                $(this).addClass("Sel");

            $(this.idSubmenu).css("display", "block");

            subMenusHover.push(this);

            subMenusHoverAtual = this;

            //subMenusOcultar();

            $(this.idSubmenu).hover(
                Delegate.create(this, function() {

                    clearTimeout(this.timerSubmenus);

                    if (this.classeInicial != "" && this.classeInicial != null)
                        $(this).addClass(this.id + "-Sel");
                    else
                        $(this).addClass("Sel");

                }
                                             )
                ,
                Delegate.create(this, function() {
                    clearTimeout(this.timerSubmenus);
                    this.className = this.classeInicial;
                    //$(this).addClass(this.classeInicial);

                    $(this.idSubmenu).css("display", "none");
                }
                                          )
            );
        },
        function() {
            this.idSubmenu = "#" + $("#" + this.id).attr("rel");
            this.timerSubmenus = setTimeout(
                                        Delegate.create(this, function() {
                                            subMenusHoverAtual = null;

                                            this.className = this.classeInicial;

                                            clearTimeout(this.timerSubmenus);

                                            $(this.idSubmenu).css("display", "none");
                                        }), 0);
        }
    );
}
function subMenusOcultar() {
    for (a = 0; a < subMenusHover.length; a++) {
    
        obj = subMenusHover[a];
               
        obj.className = obj.classeInicial;
        clearTimeout(obj.timerSubmenus);
        $(obj.idSubmenu).css("display", "none"); 
    
    }
    //subMenusHover = new 
}


function EnderecosSwitch(Nome, Link) {

    var ArrayDivs = new Array("Endereco0", "Endereco1", "Endereco2");
    var ArrayLinks = new Array("linkEndereco0", "linkEndereco1", "linkEndereco2");
    
    for (var a = 0; a < ArrayDivs.length; a++) {
        document.getElementById(ArrayDivs[a]).style.display = "none";
        document.getElementById(ArrayLinks[a]).className = ArrayDivs[a];
    }
    
    document.getElementById(Nome).style.display = "block";
    Link.className = Link.className + "-Sel";

}


function ListagemNoticiasHomeSwitch(Nome, Link) {

    var ArrayDivs = new Array("dvNoticiasAlbuns", "dvNoticiasAlunos");
    var ArrayLinks = new Array("lkDestaques0", "lkDestaques1");
    
    for (var a = 0; a < ArrayDivs.length; a++) {
        document.getElementById(ArrayDivs[a]).style.display = "none";
        document.getElementById(ArrayLinks[a]).className = null;
    }

    document.getElementById(Nome).style.display = "block";
    document.getElementById(Link).className = "Sel";

}

function fsize(size,unit,id){
	var vfontsize = document.getElementById(id);
	if(vfontsize){
		vfontsize.style.fontSize = size + unit;
	}
}


function DiarioOnline() {

    Formulario = document.getElementById("formDiarioOnline");
    
    login = document.getElementById("ctl00_campoMatricula").value;
    senha = document.getElementById("ctl00_campoSenha").value;
    
    if (login.length == 0 || senha.length == 0) {
        alert("Campo de Matrícula e Senha são obrigatórios!");
        return;    
    }
    
    document.getElementById("cd_pessoa").value = login;
    document.getElementById("ds_senha").value = senha;
    Formulario.submit();

}

// BANNERS

var imagensDestaqueHomeArray = new Array();
var imagensDestaqueHomeIndice = 1;

var banners0Array = new Array();
var banners0Indice = 0;

var banners1Array = new Array();
var banners1Indice = 1;

var banners2Array = new Array();
var banners2Indice = 1;

var banners3Array = new Array();
var banners3Indice = 1;

var banners4Array = new Array();
var banners4Indice = 1;

function BannersHomeClass() {

	this.link = null;
	this.imagem = null;
	this.itens = new Array();
	this.indice = 0;
	this.tempo = 0;

	this.tempoGet = function() {
		return this.tempo * 1000;
	}

	this.init = function() {

	    if (this.itens[0] == null)
	        return;
	        
	    var ms = this.itens[0][3];

	    this.intervalo(ms * 1000);
	}

	this.intervalo = function(ms) {

		var item = this.itens[this.indice];
		if (item != null) {
			this.imagem.src = item[0];
			this.imagem.alt = item[1];
			this.link.href = item[2];
			this.tempo = item[3];
			ms = this.tempo * 1000;
		}
		setTimeout(Delegate.create(this, function(){this.intervalo(0)}), ms);
		if ((this.indice + 1) <= this.itens.length) {
			this.indice++;
		}
		else {
			this.indice = 0;
		}
	}
	function BannersHomeClass(array) {
		this.itens = array;
	}
}



/* Oculta texto do campo */

function campoFocusValueClass(obj) {
	obj.onfocus = function() {

		if (this.campoFocusValor == null){
			this.campoFocusValor = this.value;
			this.value = "";
		}
		else {
			if (this.value == this.campoFocusValor)
				this.value = "";
		}
	}
	
	obj.onblur = function() {
		if (this.value == ""){
			this.value = this.campoFocusValor;
		}	
	}
}