function SubmitAndRun(parRedirectOk,parRedirectNo,parType) {
	frmLogin.txtRedirectOk.value = parRedirectOk;
	frmLogin.txtRedirectNo.value = parRedirectNo;
	frmLogin.txtType.value = parType;
    frmLogin.submit();
}

function checkSubmitAndRun(parRedirectOk,parRedirectNo,parType) {
	if (window.event.keyCode == 13) {
		// Enter key is pressed
		frmLogin.txtRedirectOk.value = parRedirectOk
		frmLogin.txtRedirectNo.value = parRedirectNo
		frmLogin.txtType.value = parType
                frmLogin.submit()
	} else {
		// Other than  enter key pressed
		window.event.cancelBubble = true;
	       }
}
	
function doOK() 
	{    
		if (userName.value.length > 0)
		{
			if (userPwd.value.length > 0)   
			{      
				window.returnValue = userName.value + "!" + userPwd.value;
				window.close();
			} else {
				alert("Utilizador ou Password Inválida");
				userPwd.focus();
			}
		} else {
			alert("Utilizador ou Password Inválida");
			userName.focus();
		}
			
		return true;   
}
// *** POP-UP ***

    var optionString,mainWin;
    function dialogpopper(thisUrl,thisWidth,thisHeight,thisTop,thisLeft)
    {
    optionString = ('dialogWidth:' + thisWidth + ';dialogHeight:' + thisHeight + ';status:no');
    mainWin = showModalDialog(thisUrl,"",optionString);
    }
 
    function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,location=no'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    }

//-->

// *** Highlight Table Cells Script ***

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TD"&&source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if
(ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TR"||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}

function CaricaFoto(img,tit){
  conta=img.lastIndexOf('.')
  exten=img.substring(conta+1);
  exten=exten.toLowerCase();
  if (exten == "jpg" || exten == "gif" || exten == "bmp" || exten == "png"){
    foto1= new Image();
    foto1.src=(img);
    Controlla(img,tit);
  }
  else if(exten == "wmv" || exten == "mpeg" || exten == "avi"){
	viewVideo(img,tit);
  }
  else if(exten == "mov"){
	viewMovVideo(img,tit);
  }
  else if(exten == "flv"){
	viewFlvVideo(img,tit);
  }
  else if(exten == "swf"){
	viewSwf(img,tit);
  }
  else{
    window.open(img);
  }
}
function Controlla(img,tit){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img,tit);
  }
  else{
    funzione="Controlla('"+img+"')";
    intervallo=setTimeout(funzione,20);
  }
}
function viewFoto(img,tit){
  largh=foto1.width+20;
  altez=foto1.height+20;
  var winl = (screen.width - largh) / 2;
  var wint = (screen.height - altez) / 2;
  stringa="width="+largh+",height="+altez+",top="+wint+",left="+winl;
  finestra=window.open("","",stringa);

  finestra.document.write("<head><title>"+tit+"</title></head><body bgcolor='#f9f8fe' topmargin='8' leftmargin='0'><div align='center' valign='middle'><img src='");
  finestra.document.write(img);
  finestra.document.write("' border='1' bordercolor='#39437b'></div></body></html>");
}
function viewVideo(img,tit){
	var html;
	largh=320;
	altez=240;
	var winl = (screen.width - largh) / 2;
	var wint = (screen.height - altez) / 2;
	stringa="width="+largh+",height="+altez+",top="+wint+",left="+winl;
	finestra=window.open("","",stringa);

	html='<html>';
	html=html+'<head>';
	html=html+'<title>'+tit+'</title>';
	html=html+'<script type="text/javascript" src="../../../includes/javas.js"></script>';
	html=html+'</head>';
	html=html+'<body style="margin:0px;padding:0px;">';
	html=html+'<OBJECT id="video" type="application/x-oleobject" height="240" width="320" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" bgcolor="black" color="black" background="black">';
	html=html+'<PARAM name="url" value="'+img+'">';
	html=html+'<PARAM name="transparentatStart" value="false">';
	html=html+'<PARAM name="animationatStart" value="true">';
	html=html+'<PARAM name="showdisplay" value="false">';
	html=html+'<PARAM name="showcontrols" value="true">';
	html=html+'<PARAM name="showtracker" value="true">';
	html=html+'<PARAM name="showstatusbar" value="true">';
	html=html+'<PARAM name="autoStart" value="true">';
	html=html+'<PARAM name="autoSize" value="false">';
	html=html+'<PARAM name="EnableContextMenu" value="false">';
	html=html+'<EMBED type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" src="'+img+'" name="video" width="320" height="240" transparentatstart="0" showdisplay="0" showcontrols="1" showtracker="1" showstatusbar="1" animationatstart="1" autostart="1" enablecontextmenu="0"></EMBED>';
	html=html+'</OBJECT>';
	html=html+'</body>';
	html=html+'</html>';
	finestra.document.write(html);
}
function viewMovVideo(img,tit){
	var html;
	largh=320;
	altez=240;
	var winl = (screen.width - largh) / 2;
	var wint = (screen.height - altez) / 2;
	stringa="width="+largh+",height="+altez+",top="+wint+",left="+winl;
	finestra=window.open("","",stringa);

	html='<html>';
	html=html+'<head>';
	html=html+'<title>'+tit+'</title>';
	html=html+'<script type="text/javascript" src="../../../includes/javas.js"></script>';
	html=html+'</head>';
	html=html+'<body style="margin:0px;padding:0px;">';
	html=html+'<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" HEIGHT="240" WIDTH="320" >';
	html=html+'<PARAM name="src" value="'+img+'">';
	html=html+'<PARAM NAME="autoplay" VALUE="true" >';
	html=html+'<PARAM NAME="scale" VALUE="tofit" >';
	html=html+'<PARAM NAME="kioskmode" VALUE="true" >';
	html=html+'<EMBED SRC="'+img+'" HEIGHT="240" WIDTH="320" TYPE="video/quicktime" PLUGINSPAGE="http://www.apple.com/quicktime/download/" AUTOPLAY="true" scale="tofit" kioskmode="true"/>';
	html=html+'</OBJECT>';
	html=html+'</body>';
	html=html+'</html>';
	finestra.document.write(html);
}
function viewSwf(img,tit){
	var html;
	var url;
	largh=1;
	altez=1;
	stringa="width="+largh+",height="+altez+",top=10,left=10";
	img=img.replace("&","");
	url="../../../includes/viewswf.asp?ficheiro="+img+"&titulo="+tit+"&ridcache="+Math.random();
	finestra=window.open(url,"",stringa);
}
function viewFlvVideo(img,tit){
	var html;
	largh=320;
	altez=240;
	img=img.replace('../../../','../');
	img=img.replace('../../','../');
	var winl = (screen.width - largh) / 2;
	var wint = (screen.height - altez) / 2;
	stringa="width="+largh+",height="+altez+",top="+wint+",left="+winl;
	finestra=window.open("","",stringa);

	html='<html>';
	html=html+'<head>';
	html=html+'<title>'+tit+'</title>';
	html=html+'<script type="text/javascript" src="../../../includes/javas.js"></script>';
	html=html+'</head>';
	html=html+'<body style="margin:0px;padding:0px;">';
	html=html+'<script>MM_CheckFlashVersion("8,0,0,0","Content on this page requires a newer version of Adobe Flash Player. Do you want to download it now?");</script>';
	html=html+'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="240" id="FLVPlayer">';
	html=html+'<param name="movie" value="../../../images/FLVPlayer_Progressive.swf" />';
	html=html+'<param name="salign" value="lt" />';
	html=html+'<param name="quality" value="high" />';
	html=html+'<param name="scale" value="noscale" />';
	html=html+'<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=../../../images/Corona_Skin_3&streamName='+img+'&autoPlay=true&autoRewind=false" />';
	html=html+'<embed src="../../../images/FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=../../../images/Corona_Skin_3&streamName='+img+'&autoPlay=true&autoRewind=false" quality="high" scale="noscale" width="320" height="240" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" />';
	html=html+'</object>';
	html=html+'</body>';
	html=html+'</html>';
	finestra.document.write(html);
}

//************************************************************************************
//Valida Search
//************************************************************************************
function val_search(){
	if (document.pesquisa.pesquisa.value.length == 0){
		alert("Por favor introduza um valor para pesquisar\n");
		return false;
	}else{
		return true;
	}
}

function submitSearch(){
    if (val_search() == false){ 
    	return false; 
    }
    return true;    	
}
function changeHeight(){
	if(document.getElementById && !(document.all)) {
		h = document.getElementById('imain').contentDocument.body.scrollHeight;
		if (h > 517){
			document.getElementById('imain').height = h;
		} else {
			document.getElementById('imain').height = 517;
		}
	}
	else if(document.all) {
		h = document.frames('imain').document.body.scrollHeight;
		if (h > 407){
			document.all.imain.style.height = h;
		} else {
		
			document.all.imain.style.height = 407;
		}
	} 
}
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
function getDimensions(movie,img,div) {
	var movieObj = getFlashObj(movie);
	// alert(movieObj)
	width = movieObj.TGetProperty("/", 8);
	height= movieObj.TGetProperty("/", 9);
	
	setswf(width,height,movie,div,img);
	resize(width,height);
}
function getFlashObj(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
	

function setswf(width,height,movie,divid,img){
	var html;
	html='<object id="'+movie+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">';
	html=html+'<param name="movie" value="'+img+'" />';
  	html=html+'<param name="quality" value="high" />';
  	html=html+'<param name="scale" value="noscale" />';
	html=html+'<param name="wmode" value="transparent" />';
	html=html+'<param name="salign" value="1" />';
  	html=html+'<embed swliveconnect="true" name="'+movie+'" scale="noscale" src="'+img+'" quality="high" scale="noscale" wmode="transparent" salign="1" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
	html=html+'</object>';
	divid.innerHTML = html;
}
function isIE(){
  var strBrwsr= navigator.userAgent.toLowerCase();
  if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0){
    if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6){
      return false;
    }
    if(strBrwsr.indexOf("win98") > -1 ||
       strBrwsr.indexOf("win 9x 4.90") > -1 ||
       strBrwsr.indexOf("winnt4.0") > -1 ||
       strBrwsr.indexOf("windows nt 5.0") > -1)
    {
      return false;
    }
    return true;
  }else{
    return false;
  }
}
function resize(width,height){
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	self.resizeTo(width,height)
	if (isIE()){
		self.resizeBy(width-document.getElementById("body").offsetWidth,height-document.getElementById("body").offsetHeight);
		self.moveTo(winl,wint)
	}else{
		self.resizeBy(width-document.getElementById("body").clientWidth,height-document.getElementById("body").clientHeight);
		self.moveTo(winl,wint)
	}
}
