var agt = navigator.userAgent.toLowerCase();
var is_opera = agt.indexOf("opera") != -1;

var CR;
if(is_opera)
	CR = " / ";
else
	CR = "%0A";

mymail = 'saberes';
mymail = mymail + 'daterra';
mymail = (mymail + '&#x0040;' + 'netcabo' + '&#x002E;' + 'pt');

pdmail = 'pipe';
pdmail = pdmail + 'dream';
pdmail = (pdmail + '&#x0040;' + 'netcabo' + '&#x002E;' + 'pt');

var tc;
var tcMarginTop;
var tcInt;
var marginDelta;

function upTC() {
	tc = document.all.tableContactos;
	marginDelta = (154 + tcMarginTop) / 20 + 0.1;
	tcMarginTop = tcMarginTop - marginDelta;
	tc.style.marginTop = tcMarginTop;
	tc.style.clip = "rect(auto auto " + (1 - tcMarginTop) + "px auto)";
	if(Math.round(tcMarginTop) < -154)
		window.clearInterval(tcInt);
}

function downTC() {
	tc = document.all.tableContactos;
	marginDelta = tcMarginTop / 20 - 0.1;
	tcMarginTop = tcMarginTop - marginDelta;
	tc.style.marginTop = tcMarginTop;
	tc.style.clip = "rect(auto auto " + (1 - tcMarginTop) + "px auto)";
	if(tcMarginTop > 0) {
		window.clearInterval(tcInt);
		tc.style.display = "none";
	}
}

function toggleContactos() {
	tc = document.all.tableContactos;
	window.clearInterval(tcInt);
	if(tc.style.display == "none") {
		tcMarginTop = parseInt(tc.style.marginTop);
		tc.style.clip = "rect(auto auto 1px auto)";
		tc.style.display = "block";
		tcInt = window.setInterval(upTC, 1);
	}
	else {
		tcMarginTop = parseInt(tc.style.marginTop);
		tcInt = window.setInterval(downTC, 1);
	}
}

function checkEmail(email) {
	var filter  = /^([a-zA-Z0-9_\-]+(\.)?)+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z]{2,6}$/;

	if(email == "") {
		alert('Por favor, escreva o seu email na caixa de subscrição.');
	}
	else if(filter.test(email)) {
		return true;
	}
	else {
		alert('O email introduzido na caixa de subscrição não é válido.\n\nPor favor, verifique que está bem escrito e não contém\nespaços, acentos ou outros caracteres especiais.\n\nSe o erro persistir, envie-nos um email directamente.');
	}

	return false;	
}

function nav(navRoot) {
	for(var i=0; i < navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if(node.nodeName == "LI") {
			node.onmouseover=function() {
				this.className += " over";
				this.childNodes[0].className += " over";
			}
			node.onmouseout=function() {
				this.className = this.className.replace(" over", "");
				this.childNodes[0].className = this.childNodes[0].className.replace(" over", "");
			}
			for(var j=0; j < node.childNodes.length; j++)
				if(node.childNodes[j].nodeName == "UL")
					nav(node.childNodes[j]);
		}
	}
}

window.onload = function() {
	if(location.search == "?newsletter")
		alert("O seu pedido de subscrição da mailing list foi efectuado.\nPor favor, aguarde por uma resposta de confirmação.");

	if(agt.indexOf("msie") != -1)
		nav(document.getElementById("nav"));
}