function setActiveStyleSheet(title) {
	var i, a, main;
	
	for(i=0;(a=document.getElementsByTagName("link")[i]);i++){
		//alert(a.href + " -- " + a.getAttribute("rel").indexOf("style"))
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
     }
	 
	insereCookie('cor_site', title);
   }
}


var homeArray = ['azul','verde','amarelo','roxo'];
var recebeRand = 0;
var pegouCookie = 0;

function randNum (num) {
	var now = new Date();
	var rand = Math.round(num * Math.cos(now.getSeconds()));
	if (rand < 0) rand = - rand; //if (rand == 0) rand++;
	recebeRand = rand;
	return rand;
}

function insereCookie(nome, valor){
	document.cookie = nome + "=" + valor + ";  path=/";
	document.cookie = nome + "=" + valor + ";  path=/corporativo/";
}

function pegaCookie(nome){
	var cookies = document.cookie;
	var inicio = cookies.indexOf(nome);
	if (inicio == -1) return null;
	var fim = cookies.indexOf(";",inicio);
	if (fim == -1) fim = cookies.length;
	return unescape(cookies.substring(inicio+9,fim));
}

var novoindice = randNum(homeArray.length-1);
var estiloRandomizado = homeArray[novoindice];
//alert(novoindice + ' - ' + estiloRandomizado);

if(pegaCookie('cor_site')){
	setActiveStyleSheet(pegaCookie('cor_site'));
	pegouCookie = 1;
	//alert(1);
}
else{
	setActiveStyleSheet('verde');
	//setActiveStyleSheet(estiloRandomizado);
	
	//alert(2);
	//insereCookie('cor_site', estiloRandomizado);
	//alert('sem cookie');
}

// FUNCOES PARA ABRIR OS RESPECTIVOS PROGRAMAS
function excel(){
	var appExcel = new ActiveXObject("Excel.Application");
	appExcel.Visible = true;
}
function word(){
	var appWord = new ActiveXObject("Word.Application");
	appWord.Visible = true;
}
function power(){
	var appPowerPoint = new ActiveXObject("PowerPoint.Application");
	appPowerPoint.Visible = true;
}


// FUNÇOES DO MENU LATERAL INTERNO
function checkParent( src, tagName ) {
	while ( src != null ) {
		if (src.tagName == tagName) 
			return src;
		src = src.parentElement;
	}
	return null;
}
	
function checkContent( src, tagName ) {
	var pos = src.sourceIndex ;
	while ( src.contains( document.all[++pos] ) )
		if ( document.all[pos].tagName == tagName )
			return document.all[pos] ;
	return null ;
}
      
function outlineAction() {     
	var src = event.srcElement ;
	var item = checkParent( src, "LI" ) ;
	
	if ( parent != null ) {
		var content = checkContent( item, "UL" ) ;

		if ( content != null )
			if ( content.style.display == "" )
				content.style.display = "block" ;
			else
				content.style.display = "" ;
	}
	event.cancelBubble = true;
}

