function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve ser valido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' so deve conter valores numericos.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é um campo obrigatorio.\n'; }
  } if (errors) alert('Erro(s) ocorrido(s):\n'+errors);
  document.MM_returnValue = (errors == '');
}

function activa(id) {
if (id.checked==true) {
document.getElementById("tiposociedade1").disabled = false; 
document.getElementById("tiposociedade2").disabled = false; 
document.getElementById("tiposociedade3").disabled = false; 
} else {
document.getElementById("tiposociedade1").disabled = true;
document.getElementById("tiposociedade2").disabled = true;
document.getElementById("tiposociedade3").disabled = true;
}
}

function desactiva() {
document.getElementById("radio2").checked
document.form.tiposociedade1.checked = false;
document.form.tiposociedade1.disabled = true;
document.form.tiposociedade2.checked = false;
document.form.tiposociedade2.disabled = true;
document.form.tiposociedade3.checked = false;
document.form.tiposociedade3.disabled = true;
document.form.outra.value = "";
document.form.outra.disabled = true;
}

function habilitar(valor){
var check = document.getElementById("tiposociedade3");
if (check.checked) {
var campo = document.getElementById('outra').disabled=false; document.getElementById('outra').focus();
} else {
	        document.getElementById('outra').value="";
var campo = document.getElementById('outra').disabled=true;
}
}


function substit(valor){
if (valor == "Substituir ficheiro") {
document.getElementById("valoracaofich").disabled = false;
document.getElementById("botao1").value = 'Manter ficheiro';
}
if (valor == "Manter ficheiro") {
document.getElementById("valoracaofich").disabled = true;
document.getElementById("botao1").value = 'Substituir ficheiro';
}
}

function substitituir(valor){
if (valor == "Substituir ficheiro") {
document.getElementById("fich").disabled = false;
document.getElementById("botao").value = 'Manter ficheiro';
}
if (valor == "Manter ficheiro") {
document.getElementById("fich").disabled = true;
document.getElementById("botao").value = 'Substituir ficheiro';
}
}

function concess(field,valor){
if (valor.checked==true) {
for (i = 0; i < field.length; i++) {
    field[i].disabled = false;
}
} else {
for (i = 0; i < field.length; i++) {
    field[i].disabled = true;
}
}
}

function concessdisab(field,valor){
var outro = document.getElementById("outro")
if (valor.checked==true) {
for (i = 0; i < field.length; i++) {
	field[i].checked = false;
    field[i].disabled = true;
}
outro.value = '';
outro.disabled = true;
} 
}

function disoutro() {
var check = document.getElementById("conces");
var outro = document.getElementById("outro")
if (check.checked == true) {
	outro.disabled = false;
} else {
	outro.value='';
	outro.disabled=true;
	}
	}
	
	
function hab() {
var opcao1 = document.getElementById("radio1");	
var opcao2 = document.getElementById("radio2");
var participacao = document.getElementById("participacao");
var valor = document.getElementById("valor");
var precototal = document.getElementById("precototal");
var accoes = document.getElementById("accoes");
var accao = document.getElementById("accao");
var total = document.getElementById("total");
if(opcao1.checked==true) {
	participacao.disabled=false;
	valor.disabled=false;
	precototal.disabled=false;
	}
if(opcao1.checked==false) {
	participacao.value='';
	valor.value='';
	precototal.value='0';
	participacao.disabled=true;
	valor.disabled=true;
	precototal.disabled=true;
	}
if(opcao2.checked==true) {
	accoes.disabled=false;
	accao.disabled=false;
	total.disabled=false;
	}
if(opcao2.checked==false) {
	accoes.value='';
	accao.value='';
	total.value='0';
	accoes.disabled=true;
	accao.disabled=true;
	total.disabled=true;
	}
}


function somar(){
var participacao = document.getElementById("participacao").value;
var valor = document.getElementById("valor").value;
if (isNaN(participacao) || isNaN(valor)) {
alert("Preencha os campos com valores numericos!");
return false; 
} else if (Number(participacao) > 100) {
alert("A percentagem de participacao nao pode ultrapassar os 100%");
document.form.participacao.focus();
document.form.participacao.select();
return false; 
} else {
var precototal = (Number(participacao) * Number(valor))/100;
document.getElementById("precototal").value = precototal;
//document.getElementById("precototal").value = precototal.toFixed(2);
}
}

function soma(){
var accoes = document.getElementById("accoes").value;
var accao = document.getElementById("accao").value;
if (isNaN(accoes) || isNaN(accao)) {
alert("Preencha os campos com valores numericos!");
return false; 
} 
else {
var total = (Number(accoes) * Number(accao));
document.getElementById("total").value = total;
//document.getElementById("precototal").value = precototal.toFixed(2);
}
}