// global functions

function selectObj(obj, state, clName)
{
	if (state == 'on')	{
		obj.className=clName;
	} else if (state == 'off')	{
		obj.className='';
	}
}

function showObj(objName)
{
	var obj = document.getElementById(objName);
	
	if (obj.style.display == "block") {
		obj.style.display = "none";
	} else {
		obj.style.display = "block";
	}
}

// form functions

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	}
	return true;
}

function isFoneKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 45) {
		return false;
	}
	return true;
}

// text functions

function zoomIn(objName)
{
	var obj = document.getElementById(objName);
	if (obj.style.fontSize == "") obj.style.fontSize = 10;
	
	var value = parseInt(obj.style.fontSize);
	value = value + 2;

	if (value > 16) value = 16;
	obj.style.fontSize = value + "pt";
}

function zoomOut(objName)
{
	var obj = document.getElementById(objName);
	if (obj.style.fontSize == "") obj.style.fontSize = 10;
	
	var value = parseInt(obj.style.fontSize);
	value = value - 2;

	if (value < 8) value = 8;
	obj.style.fontSize = value + "pt";
}

function openWindow(url,w,h)
{
	
	if (url == "") return false;
	
	w = parseInt(w);
	h = parseInt(h);
	
	if (w > screen.availWidth) w = screen.availWidth;
	if (h > screen.availHeight) h = screen.availHeight;
	
	popupWindow = window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + w + ",height=" + h)
	errorMsg = "Desative seu bloqueador de pop-ups!";
	
	if(popupWindow == null) { alert(errorMsg); return; }
	popupWindow.moveTo((screen.availWidth/2)-(w/2),(screen.availHeight/2)-(h/2));
	
}

function imprimir()
{
	if (window.print) window.print();
	else alert("Desculpa, seu navegador não suporta esta opção.");
}

// slide-show functions

var imgTime = 0;

function pause(img)
{
	if (img.alt == "pausar")
	{
		clearTimeout(imgTime);
		img.src = "./img/btn_play.gif";
		img.alt = "continuar";
		img.title = "continuar";
	}
	else if (img.alt == "continuar")
	{
		imageTimer();
		img.src = "./img/btn_pause.gif";
		img.alt = "pausar";
		img.title = "pausar";
	}	
}

function imageTimer()
{
   	imgTime = setTimeout("imageRotate('next');imageTimer()",10000);
}

function imageRotate(dir)
{
	new Effect.Opacity('slideshow', { duration: 0.5, transition: Effect.Transitions.linear, from: 1.0, to: 0.1 });
	new Effect.Opacity('slideshow_legend', { duration: 0.5, transition: Effect.Transitions.linear, from: 1.0, to: 0.1 });
	setTimeout("imageChange('"+dir+"')", 500);
}

function imageChange(dir)
{

	if (dir == "next") { imgPos = imgPos + 1; }
	if (dir == "prev") { imgPos = imgPos - 1; }

	if (imgPos == images.length) { imgPos = 0; }
	if (imgPos < 0) { imgPos = (images.length - 1); }

	document.getElementById('slideshow').innerHTML = "<a href=\""+images[imgPos][4]+"\"><img src=\""+images[imgPos][0]+images[imgPos][1]+"\" border=0></a>";
	document.getElementById('slideshow_legend').innerHTML = "<a href=\""+images[imgPos][4]+"\">" + images[imgPos][3] + "</a>";
	
	new Effect.Opacity('slideshow', { duration: 0.5, transition: Effect.Transitions.linear, from: 0.1, to: 1.0 });
	new Effect.Opacity('slideshow_legend', { duration: 0.5, transition: Effect.Transitions.linear, from: 0.1, to: 1.0 });
	
}
