function val_num(camp){

document.getElementById(camp).value=parseFloat(document.getElementById(camp).value);

}


function submitenter(campo,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   campo.form.submit();
   return false;
   }
else
   return true;
}

function submitenter_sen(campo,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   validate_senha();
   return false;
   }
else
   return true;
}

function submitenter_sen_est(campo,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   validate_senha_est();
   return false;
   }
else
   return true;
}

function submitenter_pes(campo,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

   if (keycode == 13)
   {
   validate_peso();
   return false;
   }
else
   return true;
}

function val_numn(camp){
if((document.getElementById(camp).value!='') && (document.getElementById(camp).value!='F)')){ 

document.getElementById(camp).value=parseFloat(document.getElementById(camp).value);
if ((document.getElementById(camp).value>20) || (document.getElementById(camp).value<0)){
alert('A Nota deve estar entre 0 e 20');
document.getElementById(camp).value=0;
}}
if(document.getElementById(camp).value=='NaN')
document.getElementById(camp).value='';

}

function unformat(camp){
document.getElementById(camp).value=document.getElementById(camp).value.replace("-","").replace("-","").replace("(","").replace(")","");
}

function format(camp,ind){
if (ind==3)
document.getElementById(camp).value='('+document.getElementById(camp).value.substr(0,2)+')'+document.getElementById(camp).value.substr(2,2)+'-'+document.getElementById(camp).value.substr(4,2)+'-'+document.getElementById(camp).value.substr(6,3);

else
document.getElementById(camp).value='('+document.getElementById(camp).value.substr(0,3)+')'+document.getElementById(camp).value.substr(3,2)+'-'+document.getElementById(camp).value.substr(5,2)+'-'+document.getElementById(camp).value.substr(7,3);
}


function validate_senha(){

if ((document.getElementById('conf_senha').value=='') || (document.getElementById('senha_nova').value=='') || (document.getElementById('conf_senha_nova').value=='')){
alert('Introduza a Confirmação da Senha Actual, a Nova Senha e a Confimação da Nova Senha!');
exit();
} else if ((document.getElementById('conf_senha').value)!=(document.getElementById('senha').value))
{
alert('A Senha Actual introduzida não coincide com a Actual!');
exit();
}
else if ((document.getElementById('conf_senha_nova').value)!=(document.getElementById('senha_nova').value))
{
alert('A Confirmação da Nova Senha não coincide com a introduzida!');
exit();
}


document.form_senha.submit();
}

function validate_senha_est(){

if ((document.getElementById('conf_senha').value=='') || (document.getElementById('senha_nova').value=='') || (document.getElementById('conf_senha_nova').value=='')){
alert('Introduza a Confirmação da Senha Actual, a Nova Senha e a Confimação da Nova Senha!');
exit();
} else if ((document.getElementById('conf_senha').value)!=(document.getElementById('senha').value))
{
alert('A Senha Actual introduzida não coincide com a Actual!');
exit();
}
else if ((document.getElementById('conf_senha_nova').value)!=(document.getElementById('senha_nova').value))
{
alert('A Confirmação da Nova Senha não coincide com a introduzida!');
exit();
}


document.form_senha_est.submit();
}

function validate_peso(){
document.getElementById('key').value=prompt('Introduza sua Chave','<Chave>');
var t1 = new Number(parseFloat(document.getElementById('pesot1').value)*100);
var t2 = new Number(parseFloat(document.getElementById('pesot2').value)*100);
var t3 = new Number(parseFloat(document.getElementById('pesot3').value)*100);
var av1 = new Number(parseFloat(document.getElementById('pesoav1').value)*100);
var av2 = new Number(parseFloat(document.getElementById('pesoav2').value)*100);
var av3 = new Number(parseFloat(document.getElementById('pesoav3').value)*100);


if ((document.getElementById('pesot1').value=='') || (document.getElementById('pesot2').value=='') || (document.getElementById('pesot1').value=='') || (document.getElementById('pesoav1').value=='') || (document.getElementById('pesoav2').value=='') || (document.getElementById('pesoav3').value=='')){
alert('Deverá introduzir os Pesos dos Teste 1, Teste 2, Teste 3, Avaliaçao Contínua 1, Avaliaçao Contínua 2 e Avaliaçao Contínua 3!');
exit();
}

if ((parseFloat(document.getElementById('pesot1').value)*100+parseFloat(document.getElementById('pesot2').value)*100+parseFloat(document.getElementById('pesot3').value)*100+parseFloat(document.getElementById('pesoav1').value)*100+parseFloat(document.getElementById('pesoav2').value)*100+parseFloat(document.getElementById('pesoav3').value)*100)!=100){
alert('A Soma dos Pesos deverá ser igual a 1!');

exit();
}

document.form_peso.submit();
}

function validate_docente(){

document.getElementById('key').value=prompt('Introduza sua Chave','<Chave>');

if ((document.getElementById('nacional').value=='') || (document.getElementById('num_doc').value=='') || (document.getElementById('prov_mor').value=='') || (document.getElementById('mor').value=='')){
alert('Deverá indicar a Nacionalidade, o Número de Identificação, a Morada, a Província de residência e o E-mail do Docente!');
exit();
}


document.form_docente.submit();
}

function validate_estudante(){

if ((document.getElementById('nom').value=='') ||  (document.getElementById('apel').value=='') ||  (document.getElementById('nacional').value=='') || (document.getElementById('num_doc').value=='') || (document.getElementById('prov_mor').value=='') || (document.getElementById('mor').value=='')){
alert('Deverá indicar o Nome, o Apelido, a Nacionalidade, o Número de Identificação, a Morada, a Província de residência e o E-mail do Estudante!');
exit();
}


document.form_estudante.submit();
}

function validate_mail(){
if ((document.getElementById('ass').value=='') || (document.getElementById('mens').value=='') || (document.getElementById('inst').value=='') ){
alert('Deverá introduzir a Instituição, o Assunto e a Mensagem!');
exit();
}


document.form_mail.submit();
}


function validate_pauta(){

document.getElementById('key').value=prompt('Introduza sua Chave','<Chave>');

document.form_pauta.submit();
}

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_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];}
}