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){	
  foto1= new Image();
  foto1.src=(img);
  Controlla(img,tit);
}
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><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>");
}

//************************************************************************************
//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;
		}
	} 
}
