
function mOvr(src,clrOver) {if (!src.contains(event.fromElement))  {src.bgColor = clrOver;}}

function mOut(src,clrIn)   {if (!src.contains(event.toElement))    {src.style.cursor = 'default'; src.bgColor = clrIn;}}


//////////////////////////// navegação que tu tens de mexer :P

var ns6=document.getElementById&&!document.all?1:0



// botões
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ActivateObject()
{
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}



/************* GALERIA DE IMAGENS **********************/

initAr = 0;
function loadAr()
{
	document.getElementById("dest_imagem0").innerHTML = "<div>" + slideShow[initAr] +"</div>";
	
	if(initAr == slideShow.length - 1)
	{
		initAr = 0;
	}
	else
	{
		initAr = initAr + 1;
	}
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		//blendimage('slideShowDiv','slideShowTable','',1000);
		var obj = document.getElementById('slideShowTable');
		obj.style.filter = 'progid:DXImageTransform.Microsoft.Fade(duration=2)';
        
        if(obj.filters(0).status == 0) 
        {
        	obj.style.visibility = 'hidden';
            obj.filters(0).apply();
            obj.style.visibility = 'visible';
            obj.filters(0).play();
         }
         
	}
	else
	{
		blendimage('slideShowDiv','slideShowTable','',1000);
	}
	setTimeout('loadAr()',timeSleep);
}

initArEventos = 0;
function loadArEventos()
{
	//document.getElementById("dest_imagem0").innerHTML = "<img src=" + slideShow[initAr] +">";
	document.getElementById("dest_imagem0Eventos").innerHTML = "<div>" + slideShowEventos[initArEventos] +"</div>";
	
	//DOSTAT
	if (ArrEventosDoStat[initArEventos] != "")
	{
	    var DoStatParams = ArrEventosDoStat[initArEventos].split("_");
	    
        $.get("../UTILS/Utils.ashx",
          {method:"dostat",contentType:"MakeWise.WebPlatform.Common.ContentObjects.Events.Event",contentID:DoStatParams[0],action:"listed",VersionID:DoStatParams[1],rand:new Date()},
          function(data)
          {
              //receiveResponse(guid, data, splitedID[0], "folow");
          }
         );
        ArrEventosDoStat[initArEventos] = "";
    }
	//FIM DOSTAT
	
	if(initArEventos == slideShowEventos.length - 1)
	{
		initArEventos = 0;
	}
	else
	{
		initArEventos = initArEventos + 1;
	}
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		//blendimage('slideShowDivEventos','slideShowTableEventos','',1000);
		var obj = document.getElementById('slideShowTableEventos');
		obj.style.filter = 'progid:DXImageTransform.Microsoft.Fade(duration=2)';
        
        if(obj.filters(0).status == 0) 
        {
        	obj.style.visibility = 'hidden';
            obj.filters(0).apply();
            obj.style.visibility = 'visible';
            obj.filters(0).play();
         }
	}
	else
	{
		blendimage('slideShowDivEventos','slideShowTableEventos','',1000);
	}
	setTimeout('loadArEventos()',timeSleepEventos);
}
/**********************************************/
/* BLEND - PERMITE O FADER ENTRE OS DESTAQUES */
/**********************************************/
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
/************* GALERIA DE IMAGENS **********************/



/* Nivel 3 */

// JavaScript Menu Document

// NECESSARIO PARA O IE
over = function() 
{
	if (document.getElementById("menu") != null)
	{
		var sfEls = document.getElementById("menu").getElementsByTagName("LI");
		var total = sfEls.length;
		for (var i=0; i<total; i++) 
		{
			sfEls[i].onmouseover=function() 
			{
				this.className+=" over";
			}
			sfEls[i].onclick=function() 
			{
				if(this.className+=" over")
				{
				this.className=this.className.replace(new RegExp(" over\\b"), "");
				}
				else
				{
				this.className+=" over"
				}
			}
			
			sfEls[i].onmouseout=function() 
			{
				this.className=this.className.replace(new RegExp(" over\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", over);

// EXPANDE ITEM NIVEL 1

var folder=''

var currentFolder = null
function openMenu(id)
{
	
	if(homeArr != "")
	{
		var totArr = homeArr.length;
		for(i=0;i<totArr;i++)
		{
			if(homeArr[i] != undefined)
			{
			//alert(homeArr[i])
			document.getElementById(homeArr[i]).style.display = "none";
			}
		}
		
		for(j=-1;j<totArr;j++)
		{
			homeArr.pop()
		}
		document.getElementById(id).style.display = "block";
		currentFolder = document.getElementById(id).style;
	}
	else
	{
		
		if(openLin != "")
		{
			document.getElementById(openLin).style.display = "none";
			openLin = "";
		}
		var curobj = document.getElementById(id);
		//alert(id);
		
		//folder=ns6?curobj.nextSibling.style:document.all[curobj.sourceIndex+1].style
		folder=curobj.style;
		
		if (folder.display=="none")
		{
			folder.display="block";
			
		}
		else
		{
			folder.display="none";
		}
		
		if (currentFolder != null && currentFolder != folder)
			currentFolder.display = "none";
		
		currentFolder = folder;
	}	
}
var homeArr = new Array();
var openLin = "";
// EXPANDE OU MARCA ITEM NIVEL 1 E SELECCIONA ITEM NIVEL 2
function detect(id,array)
{
	//alert("entrei;");
	if(array == "yes")
	{	
		var arrTot = id.length;
		
		for(i=0; i<arrTot;i++)
		{
			var str = id[i];
			var sel = str.substring(1);
			var sel1 = "s" + sel;
			if (document.getElementById(sel1) != null)
			{
				document.getElementById(sel1).style.display = "block";
				homeArr[i] = sel1;
			}
		}
	}
	else
	{
		var detectItem = id;
		var nivel1 = detectItem.indexOf('a')
		var nivel2 = detectItem.indexOf('b')
	
		if(nivel1 == 0)
		{
			//alert("1")
			document.getElementById(id).getElementsByTagName('a')[0].className = "menu1Sel";
			
			// NOVO CODIGO PARA O FIREFOX //
			if(navigator.appName == "Netscape")
			{
				//alert("Entrei NS");
				endBrother = getNextSibling(document.getElementById(id).nextSibling);
				if(endBrother == null)
				{return;}
			}
			else if(navigator.appName == "Opera")
			{
				//alert("Opera");
				endBrother = getNextSibling(document.getElementById(id).nextSibling);
				if(endBrother == null)
				{return;}
			}
			else{
				//alert("Entrei IE");
				endBrother = document.getElementById(id).nextSibling;
				//alert(endBrother)
				if(endBrother == null)
				{return;}
			}
						
			if(endBrother.id)
			{	
				document.getElementById(endBrother.id).style.display = "block";
			}
			// FIM NOVO CODIGO FF //
		}
		if(nivel2 == 0)
		{
			//alert("2")
			var openSpan = document.getElementById(id).parentNode.id;
			document.getElementById(id).getElementsByTagName('a')[0].innerHTML = document.getElementById(id).getElementsByTagName('a')[0].innerHTML + " &bull;"
			openMenu(openSpan)
		}
	}
}

/* #####################################     EVENTOS      ############################################*/
function Eventos_MostraBloco(id,imgName,dvName,Mostrar)
{
    if(Mostrar)
    {
        var cont = document.getElementById(imgName+id).src.indexOf('mais.gif');
        
        if(cont>0)
        {
            document.getElementById(imgName+id).src = '../_IMG/fileico/menos.gif';
            document.getElementById(dvName+id).style.display = 'block';
        }
        else
        {
            document.getElementById(imgName+id).src = '../_IMG/fileico/mais.gif';
            document.getElementById(dvName+id).style.display = 'none';
        }
    }
}


function getNextSibling(startBrother){
	endBrother=startBrother.nextSibling;
	if(endBrother != null)
	{while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
	}
  }
  return endBrother;
}


function Open(id)
{
	window.open("../CALENDAR/Calendar.aspx?id=" + id, "tiny", "width=175,height=136,top=400,left=550,toolbars=no,scrollbars=no,status=no,resizable=no");
  
}  
    

function treeViewCheck(event) 
{ 
	// obj gives us the node on which check or uncheck operation has performed 
	//var obj = window.event.srcElement; 
	
	var obj = event.srcElement || event.target; 

	var treeNodeFound = false; 

	var checkedState; 


	//checking whether obj consists of checkbox to avoid exception 

	if (obj.tagName == "INPUT" && obj.type == "checkbox") 
	{ 
		var treeNode = obj; 
		checkedState = treeNode.checked; 

		//work our way back to the parent <table> element 

		do 
		{ 
			obj = obj.parentNode;
			//obj = obj.parentElement; 
		} 
		while (obj.tagName != "TABLE") 

		var parentTreeLevel = obj.rows[0].cells.length; 
		var parentTreeNode = obj.rows[0].cells[0]; 

		//get all the TreeNodes inside the TreeView (the parent <div>) 
		var tables = obj.parentNode.getElementsByTagName("TABLE"); 

		//checking for any node is checked or unchecked during operation 
		if(obj.tagName == "TABLE") 
		{ 

			//total number of TreeNodes 
			var numTables = tables.length 

			if (numTables >= 1) 
			{ 
				//cycle through all the TreeNodes 
				//until we find the TreeNode we checked 

				for (i=0; i < numTables; i++) 
				{ 
					if (tables[i] == obj) 
					{ 
						treeNodeFound = true; 
						i++; 
						if (i == numTables) 
						{ 
							//if we're on the last TreeNode, we are done 
							break; 
						} 
					} 
					if (treeNodeFound == true) 
					{ 

						var childTreeLevel = tables[i].rows[0].cells.length; 
						if (childTreeLevel > parentTreeLevel) 
						{ 
							var cell = tables[i].rows[0].cells[childTreeLevel - 1]; 
							//set the checkbox to match the checkedState 

							var inputs = cell.getElementsByTagName("INPUT"); 
							inputs[0].checked = checkedState; 

						} 

						else 
						{ 
							//if any of the preceding TreeNodes are not deeper stop 
							break; 

						} 
					} //end if 

				}//end for 
			} //end if - numTables >= 1 

			//Modified - If all child nodes are unchecked then their parent node is unchecked 

		} //end if - tagName = TABLE 

	} //end if 

} //end function 


// SLIDE PANEL
var maxChanges;
var thisImg;
// shuffle images so each time page loads, the photos show in different order
var do_shuffle = true;
var do_randomly = true;
var seconds_between_photos = 10;
var div_name = "painel";
var changes = 0;
var timer;

function nextImage ()
{
	var low = 0;
	var high = listRandomImages.length - 1;
	var rand_no = Math.floor((high-(low - 1))*Math.random()) + low;
	thisImg++;
	changes++;
	if (thisImg==listRandomImages.length) {
		thisImg = 0;
	}
	if (changes==maxChanges) {
		clearInterval(timer);
	}
	if (do_randomly) {
		thisImg = rand_no;
		return listRandomImages[rand_no];
	} else {
		return listRandomImages[thisImg];
	}
}

function changeImage () {
	if(listRandomImages.length > 1)
	{
		var t = listRandomImages[thisImg];
		var nnn = nextImage();
	
		if (t != nnn) 
		{
			$("#"+div_name).addClass("loading");
			showImage(nnn);
		}else{ 
			changeImage();
		}
	}
	else
	{
		showImage(listRandomImages[0]);
	}
}

function showImage(src)
{
	$("#"+div_name+" img").fadeOut("normal").remove();
	var largeImage = new Image();
	$(largeImage).load(
		function()
        {
			$(this).hide();
			$("#"+div_name).append(this).removeClass("loading");
             $(this).fadeIn("slow");              
         });    
	$(largeImage).attr("src", src);                                                                               
}

function checkForLoaded () {
	if (document.getElementById(div_name) != null) 
	{
		clearInterval(timer);
		changeImage();
		if(listRandomImages.length > 1)
			timer = setInterval(changeImage, (seconds_between_photos * 1000));
	}
}
// END SLIDE PANEL

function Banners_OnClick(id, url, type, imageId)
{
    linkTo = '../BannerClick.aspx?id=' + id + '&url=' + url;
    
    if (url == '')
    {
        document.getElementById(imageId).src = linkTo;
    }
    else
    {
        if(type == '_self')
            window.location = linkTo;
        else
            window.open(linkTo);
            
    }
}
