﻿function cOn1(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor="#AFDDF5";
    }
}

function cOut1(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor="#FFFFFF";
    }
}

function cOn2(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor="#DDF0FB";
    }
}

function cOut2(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor="#E0E8F3";
    }
}

function checkME1(obj){
    if(obj.value=='Pesquisa no glossário'){
        obj.value="";
    }
}

function checkME2(obj){
    if(obj.value=='Pesquisa nas notícias'){
        obj.value="";
    }
}

function checkME3(obj){
if(obj.value=='Nome de utilizador'){
obj.value="";
}}
function checkME4(obj){
if(obj.value=='Palavra-chave'){
obj.value="";
}}
function checkME5(obj){
if(obj.value=='Nome'){
obj.value="";
}}
function checkME6(obj){
if(obj.value=='Email'){
obj.value="";
}}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function check(obj){
	UserName = obj.usr.value;
	Pass = obj.pwd.value;
	if (UserName.length < 3 || Pass.length < 3){
		alert("Os campos estão mal preenchidos!!");
		return false;
	}
}

function checkNews(obj){
	var rules = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	UserName = obj.nome.value;
	Pass = obj.email.value;
	if (UserName.length < 3 || Pass.length < 3){
		alert("Os campos estão mal preenchidos!!");
		return false;
	}
	if (!rules.test(Pass)){
		alert("O seu email é inválido!");
		return false;
	}
}

function PopUp(page, myWidth, myHeight) {
	newWind=window.open(page,"popUp","width="+myWidth+",height="+myHeight+",toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,resizable=no");
	if(newWind.opener == null) {
		newWind.opener = window;
	}
	else {
		newWind.focus();
	}
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function validarString(){
	var i, r, re, str, atLeast;
	var strArr = new Array();
	str = document.forms.pesq.q.value;
	strArr = str.split(" ");
	str = "";
	atLeast = false;
	for(i=0; i < strArr.length; i++) {
		str += strArr[i] + " ";
		if(strArr[i].length > 2) atLeast = true;
	}
	if(!atLeast) {
		alert("Para realizar uma pesquisa deve escrever pelo menos uma palavra com três caracteres!");
		return false;
	}
	else {
		return true;
	}
}

var marqueewidth="150px"
var marqueeheight="200px"
var marqueespeed=1
var pauseit=1
	
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
var actualheight=''
var cross_marquee, ns_marquee

function populate(){
	try{
	    if (iedom){
		    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
		    cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
		    cross_marquee.innerHTML=marqueecontent
		    actualheight=cross_marquee.offsetHeight
	    }else if (document.layers){
		    ns_marquee=document.ns_marquee.document.ns_marquee2
		    ns_marquee.top=parseInt(marqueeheight)+8
		    ns_marquee.document.write(marqueecontent)
		    ns_marquee.document.close()
		    actualheight=ns_marquee.document.height
	    }
	
	    lefttime=setInterval("scrollmarquee()",20)
    }catch(e){}
}

//window.onload=populate

function scrollmarquee(){
	if (iedom){
		if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
			cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
		else
			cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
	}else if (document.layers){
		if (ns_marquee.top>(actualheight*(-1)+8))
			ns_marquee.top-=copyspeed
		else
			ns_marquee.top=parseInt(marqueeheight)+8
	}
}
function buildMarquee(){
    if (iedom||document.layers){
	    with (document){
		    if (iedom){
			    write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
			    write('<div id="iemarquee" style="position:absolute;left:0px;top:0px;width:100%;">')
			    write('</div></div>')
		    }else if (document.layers){
			    write('<ilayer width="+marqueewidth+" height="+marqueeheight+" name="ns_marquee">')
			    write('<layer name="ns_marquee2" width="+marqueewidth+" height="+marqueeheight+" left="0" top="0" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
			    write('</ilayer>')
		    }
	    }
    }
}

function PopNews(page, name, myWidth, myHeight, x, y) {
	popWind=window.open(page,name,"width=" + myWidth + ",height=" + myHeight + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y + ",toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,resizable=no");
	if(popWind.opener == null) {
		popWind.opener = window;
	}
	else {
		popWind.focus();
	}
	window.opener = popWind;
}

function checkChoice(frmName){
    obj = eval(document.getElementById(frmName));
    if (obj.rdChoice.checked)
        retorno = true;
    else {
        for (x = 0; x < obj.rdChoice.length; x++)
            if (obj.rdChoice[x].checked)
	            return true;
    }
}

function vote(inqID){
    myDv = eval(document.getElementById("div_"+inqID));
    obj = eval(document.getElementById("frmVotes_"+inqID));
    myDv.style.display="none";
    PopNews("inquerito.aspx", "Inquerito", 545, 400);
    obj.votar.disabled = true;
    obj.method = 'post';
    obj.action = "inquerito.aspx";
    obj.target = "Inquerito"
    obj.submit();
}

function giveMeMyPos(obj){
	try{
    	var oParent = obj.offsetParent; 
	    divID = obj.id;
	    divID = divID.replace("td_", "");
	    myDiv = eval(divID);
	    myDiv.style.top = obj.offsetTop + 170;
    }catch(e){}
}