function hidediv(divId)
{
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById(divId).style.visibility = 'hidden';
	}
}
function showdiv(divId)
{
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById(divId).style.visibility = 'visible';
	}
}
function openPrintWindow(theURL)
{
	var features = 'scrollbars=yes,resizable=yes,width=650,height=500';
	window.open(theURL, 'print', features);
}
function getParameter(queryString, parameterName)
{
	var parameterName = parameterName + "=";
	if (queryString.length > 0)
	{
		begin = queryString.indexOf(parameterName);
		if (begin != -1)
		{
			begin += parameterName.length;
			end = queryString.indexOf("&", begin);
			if (end == -1)
			{
				end = queryString.length
			}
			return unescape(queryString.substring(begin, end));
		}
		return "";
	}
}

function changeAction()
{
	if (document.forms.length > 1)
	{
		rExp = /\/template.MAXIMIZE/g;
		var newAction = document.forms[1].action.replace(rExp, "/template.PAGE");
		var vgnextoid = getParameter(location.search, "vgnextoid");
		var vgnextchannel = getParameter(location.search, "vgnextchannel");
		var vgnextfmt = getParameter(location.search, "vgnextfmt");
		if (vgnextoid.length > 0)
			newAction = newAction + "&vgnextoid=" + vgnextoid;
		if (vgnextchannel.length > 0)
			newAction = newAction + "&vgnextchannel=" + vgnextchannel;
		if (vgnextfmt.length > 0)
			newAction = newAction + "&vgnextfmt=" + vgnextfmt;
		document.forms[1].action = newAction;
	}
}
function validateSearch(f, act)
{
	var min = 3;
	var o = f.PSqueryPesquisa;
	var isToEscape = false;
	var reg = /\x2a/g;//Verifica se existem asteriscos (*)
	var valor_pesquisa = o.value.trim();
	
	if (f.search != null)
	{
		o = f.search;
		isToEscape = true;
	}
	if(valor_pesquisa==o.getAttribute('msg')){
		alert('Por favor indique um crit\ério de pesquisa.');
		o.focus();
	}else
	if (eval(valor_pesquisa.length) < min)
	{
		alert('Por favor indique um crit\ério de pesquisa com no min\ímo de 3 caracteres.');
		o.value='';
		o.focus();
	}
	else if (reg.test(valor_pesquisa)) {
		alert('Não são permitidos \'*\' no campo da pesquisa');
		o.focus();
	}
	else
	{
		if (isToEscape)
		{
			f.PSqueryPesquisa.value = escape(o.value);
		}
		else
		{
			f.PSqueryPesquisa.value = o.value;
		}
		f.action = act;
		f.submit();
	}
}
function changeimg(elementId, urlToChange)
{
	var o = document.getElementById(elementId);
	o.src = urlToChange;
}

function bold(id, max)
{
	for (i = 1; i <= max; i++)
	{
		if (i != id)
		{
			document.getElementById('img' + i).style.fontWeight = 'normal';
		}
	}
	document.getElementById('img' + id).style.fontWeight = 'bolder';
}
function isPositiveInteger(s)
{
	if (s == 'undefined' || s == null || s.length == 0) return false;
	var charpos = s.search("[^0-9]");
	if (s.length > 0 && charpos >= 0)
	{
		return false;
	}//if
	return true;
}
//numeric
function isNumeroContribuinte(s)
{
	if (s.length != 9 || !isPositiveInteger(s))
	{
		return false;
	}
	var soma,resto,digi;
	var nif = new Array(9);
	for (var i = 0; i < 9; i++)
	{
		nif[i] = Number(s.substring(i, i + 1));
	}
	for (var i = 0,soma = 0; i < 8; i++)
	{
		soma += nif[i] * (9 - i);
	}
	resto = soma % 11;
	digi = 11 - resto;
	if (digi > 9) digi = 0;
	return (digi == nif[8]);
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
