
// gerar caixa on-the-fly (dá para: tabs, slideshows, popups, ...)
var popbox_content = []; popbox_content[1] = []; popbox_content[2] = []; popbox_content[3] = []; popbox_content[4] = []; popbox_content[5] = [];
var popbox_num = [];
function popbox(tmp_content, tmp_trigger) {
	
	tmp_obj=document.getElementById("popbox"+tmp_content+"_content");
	
	if(tmp_trigger=="x"){//remove
		tmp_obj.style.display = "none";
		return;
	}else{
		tmp_quant=popbox_content[tmp_content].length-1;
		if(tmp_trigger=="-"){//prev
			popbox_num[tmp_content]--;
			if(popbox_num[tmp_content]<1) { popbox_num[tmp_content]=tmp_quant; }
		}else if(tmp_trigger=="+"){// next
			popbox_num[tmp_content]++;
			if(popbox_num[tmp_content]>tmp_quant) { popbox_num[tmp_content]=1; }
		}else if(tmp_trigger>0){// num exacto
			popbox_num[tmp_content]=tmp_trigger;
		}
		tmp_num=popbox_num[tmp_content];
		
		tmp_obj.innerHTML = popbox_content[tmp_content][tmp_num];
		tmp_obj.style.display = "block";
		
		// efeito de transição imagem
		/*
		document.getElementById("popbox_img").style.filter="blendTrans(duration=1)";
		document.getElementById("popbox_img").filters.blendTrans.Apply();
		document.getElementById("popbox_img").filters.blendTrans.Play();
		*/
	}
}

	// temporizador para a popbox (tipo slideshow automatico)
	function popbox_timer(tmp_content, tmp_time){
		popbox(tmp_content,'+');
		t=setTimeout("popbox_timer("+tmp_content+","+tmp_time+")",tmp_time*1000);
	}
	
	// menus em tabuladores: | tab1 | tab2 | tab3 |_____________
	function popbox_tabClick(tmp_content, tmp_trigger){// ao clicar no link, troca o tab
		tmp_quant=popbox_content[tmp_content].length-1;
		for(var j=1;j<=tmp_quant;j++){
			if(tmp_trigger!=j){
				//document.getElementById(i+j+"_body").style.display="none";
				document.getElementById("tab_"+j).className="";
			}else{
				//document.getElementById(i+j+"_body").style.display="inline";
				document.getElementById("tab_"+j).className="activo";
			}
		}
		popbox(tmp_content,tmp_trigger);
	}


// menus em tabuladores: | tab1 | tab2 | tab3 |_____________
	function tabClick(i,n,tabs){// ao clicar no link, troca o tab
		for(var j=1;j<=tabs;j++){
			if(n!=j){
				document.getElementById(i+j+"_body").style.display="none";
				document.getElementById(i+j+"_li").className="";
			}else{
				document.getElementById(i+j+"_body").style.display="inline";
				document.getElementById(i+j+"_li").className="activo";
			}
		}
	}


// ESCONDER / MOSTRAR ELEMENTOS HTML
	//var element_bak = 0;
	function expandCollapse(area, arrow) {
		var element = document.getElementById(area);
		/*
		if (element_bak!=0){
			if (element_bak!=element){
				element_bak.style.display = 'none';
			}
		}
		element_bak = element;
		*/
		element.style.display = (element.style.display == 'none') ? 'block' : 'none';
		
		if (arrow!=0){// permite esconder um e mostrar outro
			var element2 = document.getElementById(arrow);
			element2.style.display = (element2.style.display == 'none') ? 'block' : 'none';
		}
	}



// FUNÇõES GERAIS : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
	
	// contar caracteres (para caixas de texto)
		function textCounter(field, countfield, maxlimit) {// contar caracteres (para caixas de texto)
			if (field.value.length > maxlimit){
				field.value = field.value.substring(0, maxlimit);
			}else{
				countfield.value = maxlimit - field.value.length;
			}
		}
	
	
	// adicionar aos favoritos
		function addBookmark(title,url) {
			if (window.sidebar) {
				window.sidebar.addPanel(title, url,"");
			} else if( document.all ) {
				window.external.AddFavorite( url, title);
			} else if( window.opera && window.print ) {
				alert("Press Ctrl + T - Carregue em Ctrl + T");
			}
		}
	
	
	// nova janela
		function popUp(mypage){
			window.open (mypage);
		}
	
	
	// nova janela popup para Imagens
		function popUpimg(path) {
			var oImg = new Image();
			oImg.onload = function(){
			    xjan=oImg.width+20;
			    yjan=oImg.Height+20;   
				day = new Date();
				id = day.getTime();
				l = (screen.availWidth-10 - xjan) / 2;
				t = (screen.availHeight-20 - yjan) / 2;
				eval("page" + id + " = window.open(path, \'" + id + "\', \',toolbar=0,scrollbars=1,left='+l+',top='+t+',location=0,statusbar=0,menubar=0,resizable=0,width='+xjan+',height='+yjan+'\');");  
			}
			oImg.src = path;    
		}
	
	
	// alterar fotos seleccionadas através de miniaturas
		function mudar_imagem(tmp_foto, tmp_caption) {
			document.getElementById("imagemactiva").src = tmp_foto;
			if(tmp_caption!=""){
				document.getElementById("imagemactiva_legenda").innerHTML = "&nbsp;"+tmp_caption;
			}
		}
	
	
	// validar inputs básicos nas forms
		function form_validate(tmpObj, tmpMsg, tmpTp) {
			if(!tmpObj)
				return false;
			if(tmpObj.value.length<3 || tmpObj.value==null) {
				alert(tmpMsg);
				tmpObj.focus();
				return false;
			}
		}
	
	
	
	// object close/hide/show
		function obj_style(id, estilo) { 
			var style = document.getElementById(id).style; 
			style.display = estilo; 
		} 
	
	
	// Determine browser and version.
		function Browser() {
			var ua, s, i;
			
			this.isIE    = false;
			this.isNS    = false;
			this.version = null;
			
			ua = navigator.userAgent;
			
			s = "MSIE";
			if ((i = ua.indexOf(s)) >= 0) {
				this.isIE = true;
				this.version = parseFloat(ua.substr(i + s.length));
				return;
			}
			
			s = "Netscape6/";
			if ((i = ua.indexOf(s)) >= 0) {
				this.isNS = true;
				this.version = parseFloat(ua.substr(i + s.length));
				return;
			}
			
			// Treat any other "Gecko" browser as NS 6.1.
			s = "Gecko";
			if ((i = ua.indexOf(s)) >= 0) {
				this.isNS = true;
				this.version = 6.1;
				return;
			}
		}
		var browser = new Browser();
// FIM / FUNÇõES GERAIS : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :


// DRAG AND DROP DIVS : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
	// Global object to hold drag information.
		var dragObj = new Object();
		dragObj.zIndex = 0;

	// drag
		function dragStart(event, id) {
			var el;
			var x, y;
			
			// If an element id was given, find it. Otherwise use the element being
			// clicked on.
				if (id)
					dragObj.elNode = document.getElementById(id);
				else {
					if (browser.isIE)
					 dragObj.elNode = window.event.srcElement;
					if (browser.isNS)
					 dragObj.elNode = event.target;
				
					// If this is a text node, use its parent element.
				
					if (dragObj.elNode.nodeType == 3)
					 dragObj.elNode = dragObj.elNode.parentNode;
				}

			// Get cursor position with respect to the page.
				if (browser.isIE) {
					x = window.event.clientX + document.documentElement.scrollLeft
					 + document.body.scrollLeft;
					y = window.event.clientY + document.documentElement.scrollTop
					 + document.body.scrollTop;
				}
				if (browser.isNS) {
					x = event.clientX + window.scrollX;
					y = event.clientY + window.scrollY;
				}
			
			// Save starting positions of cursor and element.
				  dragObj.cursorStartX = x;
				  dragObj.cursorStartY = y;
				  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
				  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);
				
				  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
				  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

			// Update element's z-index.
				dragObj.elNode.style.zIndex = ++dragObj.zIndex;

			// Capture mousemove and mouseup events on the page.
				if (browser.isIE) {
					document.attachEvent("onmousemove", dragGo);
					document.attachEvent("onmouseup",   dragStop);
					window.event.cancelBubble = true;
					window.event.returnValue = false;
				}
				if (browser.isNS) {
					document.addEventListener("mousemove", dragGo,   true);
					document.addEventListener("mouseup",   dragStop, true);
					event.preventDefault();
				}
		}

	// Get cursor position with respect to the page.
		function dragGo(event) {
			var x, y;
			if (browser.isIE) {
				x = window.event.clientX + document.documentElement.scrollLeft
				 + document.body.scrollLeft;
				y = window.event.clientY + document.documentElement.scrollTop
				 + document.body.scrollTop;
			}
			if (browser.isNS) {
				x = event.clientX + window.scrollX;
				y = event.clientY + window.scrollY;
			}

			  // Move drag element by the same amount the cursor has moved.
				  dragObj.elNode.style.left =
				    (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
				  dragObj.elNode.style.top  =
				    (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
		}
	
	// Stop capturing mousemove and mouseup events.    
	function dragStop(event) {
		if (browser.isIE) {
			document.detachEvent("onmousemove", dragGo);
			document.detachEvent("onmouseup",   dragStop);
		}
		if (browser.isNS) {
			document.removeEventListener("mousemove", dragGo,   true);
			document.removeEventListener("mouseup",   dragStop, true);
		}
	}
// FIM / DRAG AND DROP DIVS : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
