// 
// Impostos.Net: funções genéricas
//

function BrowserType(){
	if (navigator.appName.indexOf("Netscape") > -1) {return "NS";}
	if (navigator.appName.indexOf("Explorer") > -1) {return "IE";}
	return "Unknown";
}

function get_random(numOfObjects) {
	var ranNum = Math.round(Math.random() * numOfObjects);
	return ranNum;
}

function GetCookie(sName, sItem) {
	var aCookie = document.cookie.split("; ");
	
	for (var i=0; i < aCookie.length; i++)
	{
		var sCookieName = aCookie[i].substring(0, aCookie[i].indexOf("="));
		var sValue = aCookie[i].substring(aCookie[i].indexOf("=") + 1, aCookie[i].length);
		
		if (sName == sCookieName) {
			var aCrumb = sValue.split("&");
			for (var j=0; j < aCrumb.length; j++)
			{
				var aItem = aCrumb[j].split("=");
				if (sItem == aItem[0])
					return unescape(aItem[1]);
			}
		}
	}
	return "";
}

function GetUserData(txtUsername, txtPassword) {
	var sUserName = new String(GetCookie("ImpostosNetUserData", "Username"));
	if (sUserName != "") {
		txtUsername.value = sUserName;
		txtPassword.value = GetCookie("ImpostosNetUserData", "Password");
	}
}

function clearText(thefield) {
	if (thefield.defaultValue == thefield.value)
		thefield.value = ""
	else 
	{
		if (thefield.value == "")
			thefield.value = thefield.defaultValue
	}
}

function checkEmail(addr) {
	if ((addr.indexOf(";") != -1) || (addr.indexOf(",") != -1) || (addr.indexOf(" ") != -1))
		return false;
	mail = addr.split("@");
	if (mail.length != 2)
		return false;
	if (mail[1].indexOf(".") == -1)
		return false;
	mailRight = mail[1].split(".");
	for (i = 0; i < mailRight.length; i++) {
		if (mailRight[i].length == 0)
			return false;
	}
	return true;
}

function checkSubmit(ev, form) {
	if (ev.keyCode == 13) 
		document.forms[form].btSearch.click();
}

function validateSearch(oForm) {
	var keyWords = new String(oForm.keyWords.value);
	
	if (keyWords.length < 3) {
		alert("Por favor, introduza palavras-chave com pelo menos 3 caracteres.")
		return false;
	}

	keyWords = keyWords.replace('.', ' ');
	if (keyWords.length < 3) {
		alert("Por favor, introduza palavras-chave com pelo menos 3 caracteres.")
		return false;
	}

	var arKeyWords = keyWords.split(' ');
	for (i = 0; i < arKeyWords.length; i++) {
		if (arKeyWords[i].length <= 1) {
			alert("Por favor, introduza palavras-chave com pelo menos 3 caracteres.")
			return false;
		}
	}

	return true;
}

function showCreditsInfo() {
	var obj = top.document.getElementById('creditsLabel')
	if (obj != null) {		
		obj.style.display = 'block'
		top.document.all('creditsLabelTopic').style.display = 'block'
	}
}

function HideLinksForSignatures() {
	var obj = top.document.getElementById('divLinks18')
	if (obj != null)
		obj.style.display = 'none'

	var obj = top.document.getElementById('divLinks7')
	if (obj != null)
		obj.style.display = 'none'
		
	var obj = top.document.getElementById('divLinks8')
	if (obj != null)
		obj.style.display = 'none'

	var obj = top.document.getElementById('divLinks63')
	if (obj != null)
		obj.style.display = 'none'

	var obj = top.document.getElementById('divLinks64')
	if (obj != null)
		obj.style.display = 'none'

	var obj = top.document.getElementById('divLinks66')
	if (obj != null)
		obj.style.display = 'none'

	var obj = top.document.getElementById('divLinks68')
	if (obj != null)
		obj.style.display = 'none'
}
