
// 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";
		}
	}
}


// JAVASCRIPT MENU DROPDOWN FUNCTION ---------------------
//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){
		var element2 = document.getElementById(arrow);
		element2.style.display = (element2.style.display == 'none') ? 'block' : 'none';
	}
	//alert ("You clicked OK: "+arrow); 
	//var recentmenu = document.getElementById(arrow);
	//recentmenu.className = (element.style.display == 'none') ? 'collapsed first' : 'expanded first';
}


// 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;
	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;
	}
}
