function removeclasses(){
  
  var xclose = document.getElementsByTagName("a");
  
  for (var i=0; i<xclose.length; i++) {
    if (xclose[i].className == "links_design_01activo"){
      xclose[i].className = "links_design_01";
    }
    
  }
  
}

function open_chat() {

  window.open('chat_window.php', 'FitOnPaper', 'addressbar=0,toolbar=0, location=0, statusbar=0, menubar=0, resizable=no, width=260, height=330');

}

function open_app() {

  window.open('appui/index.php?doload=1', 'FitOnPaper Tool', 'fullscreen=yes,addressbar=0,toolbar=0, location=0, statusbar=0, menubar=0, resizable=no');

}

function verifyRegFields(obj, LG){

    if(!LG) var LG = 'pt';
    
    switch (LG) {
        case 'pt':
        var exp1 = 'O e-mail especificado não é correcto.';
        var exp3 = 'Os emails não são iguais, por favor confirme novamente.';
        var exp4 = 'Tem de preencher todos os campos de preenchimento obrigatório.';
        break;
        
        case 'gb':
        var exp1 = 'The email address specified is not correct.';
        var exp3 = 'Emails do not match, please check again.';
        var exp4 = 'You must fill in all required fields.';
        break;
        
        case 'sp':
        var exp1 = 'La dirección de correo electrónico especificada no es correcta.';
        var exp3 = 'Mensajes de correo electrónico no coinciden, por favor revise de nuevo.';
        var exp4 = 'Debe rellenar todos los campos requeridos.';
        break;
        
        case 'fr':
        var exp1 = "L'email adresse indiquée n'est pas correcte.";
        var exp3 = "E-mails ne correspondent pas, s'il vous plaît vérifiez à nouveau.";
        var exp4 = "Vous devez remplir tous les champs obligatoires.";
        break;
    }
    
  var cont = 0;
  
  var cont2 = 0;
  
  var cont3 = 0;
  
  var objele = obj.elements;
  
  for(i = 0; i < objele.length; i++){
    
    var xs = objele[i].name.substring(0,1);
    
    if(objele[i].value == '' && xs == 'R' && objele[i].name!="sbmt_btn" && objele[i].className.indexOf('notrequired') == -1){
    cont++;
     objele[i].style.borderLeft="2px solid #FB6E15";
    document.getElementById('email1').style.background="#f0f0f0";
   
    if(document.getElementById('email2')!=undefined){
    objele[i].style.borderLeft="2px solid #FB6E15";
    document.getElementById('email2').style.background="#f0f0f0";
    }
    if(document.getElementById('pass2')!=undefined){
    objele[i].style.borderLeft="2px solid #FB6E15";
     document.getElementById('pass1').style.background="#f0f0f0";
    document.getElementById('pass2').style.background="#f0f0f0";
    }

    }else if(xs == 'R' && objele[i].value != ''){
    
    document.getElementById('email1').style.background="#FFFFFF";
    if(document.getElementById('email2')!=undefined){
    objele[i].style.borderLeft="1px solid #CCCCCC";
    document.getElementById('email2').style.background="#FFFFFF";
    }
    if(document.getElementById('pass2')!=undefined){
    objele[i].style.borderLeft="1px solid #CCCCCC";
    document.getElementById('pass1').style.background="#FFFFFF";
    document.getElementById('pass2').style.background="#FFFFFF";
    }
    
    } else if (objele[i].className.indexOf('notrequired') != -1) {
        objele[i].style.borderLeft="1px solid #CCCCCC";
    }
      
  if(document.getElementById('email2')!=undefined){
    if(objele[i].name == 'R[email][2]' && document.getElementById('email2').value != document.getElementById('email1').value)
      cont2++;
   }
   if(document.getElementById('pass2')!=undefined){
    if(objele[i].name == 'R[pass][2]' && document.getElementById('pass2').value != document.getElementById('pass1').value)
      cont3++;
   }
  }
  
  if(document.getElementById('email1') && document.getElementById('email1').value!=''){
    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email1').value))){
        alert(exp1)
        document.getElementById('email1').focus()
        document.getElementById('email1').style.background="#f0f0f0";
         document.getElementById('email1').style.borderLeft="2px solid #FB6E15";
        return false;
    }else {
     document.getElementById('email1').style.background="#FFFFFF";
    document.getElementById('email1').style.borderLeft="1px solid #CCCCCC";
    }
  }
  if(document.getElementById('email2')  && document.getElementById('email2').value!=''){
    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email2').value))){
        alert(exp1)
        document.getElementById('email2').focus()
        document.getElementById('email2').style.background="#f0f0f0";
        document.getElementById('email2').style.borderLeft="2px solid #FB6E15"
        return false;
    }else {
    document.getElementById('email2').style.background="#FFFFFF";
    document.getElementById('email2').style.borderLeft="1px solid #CCCCCC";
    }
  }
  
  if(cont2 > 0){
    alert(exp3);
      
    return false;
  }
  
  
  if(cont > 0){
    alert(exp4);
    document.getElementById('obriga').style.display='block';
    return false;
  } else {
    return true;
  }
}


function verifyRegFields2(obj, LG){
    
    if(!LG) var LG = 'pt';
    
    switch (LG) {
        case 'pt':
        var exp3 = 'As passwords não são iguais, por favor confirme novamente.';
        var exp4 = 'Tem de preencher todos os campos de preenchimento obrigatório.';
        break;
        
        case 'gb':
        var exp3 = 'Passwords do not match, please check again.';
        var exp4 = 'You must fill in all required fields.';
        break;
        
        case 'sp':
        var exp3 = 'Passwords no coinciden, por favor revise de nuevo.';
        var exp4 = 'Debe rellenar todos los campos requeridos.';
        break;
        
        case 'fr':
        var exp3 = "Passwords ne correspondent pas, s'il vous plaît vérifiez à nouveau.";
        var exp4 = "Vous devez remplir tous les champs obligatoires.";
        break;
    }
    
  var cont = 0;
  
  var cont2 = 0;
  
  var cont3 = 0;
  
  var cont4 = 0;
  
  var objele = obj.elements;
  
  for(i = 0; i < objele.length; i++){
    
    var xs = objele[i].name.substring(0,1);
    
    if(objele[i].value == '' && xs == 'R' && objele[i].name!="sbmt_btn"){
    cont++;
     objele[i].style.borderLeft="2px solid #FB6E15";
    
   /*
    if(document.getElementById('email2')!=undefined){
    objele[i].style.borderLeft="2px solid #FB6E15";
    document.getElementById('email2').style.background="#f0f0f0";
    }*/
    if(document.getElementById('pass2')!=undefined){
    objele[i].style.borderLeft="2px solid #FB6E15";
     document.getElementById('pass1').style.background="#f0f0f0";
    document.getElementById('pass2').style.background="#f0f0f0";
    }
    
    }else if(xs == 'R' && objele[i].value != ''){
    /*
    document.getElementById('email1').style.background="#FFFFFF";
    if(document.getElementById('email2')!=undefined){
    objele[i].style.borderLeft="1px solid #CCCCCC";
    document.getElementById('email2').style.background="#FFFFFF";
    }*/
    if(document.getElementById('pass2')!=undefined){
    objele[i].style.borderLeft="1px solid #CCCCCC";
    document.getElementById('pass1').style.background="#FFFFFF";
    document.getElementById('pass2').style.background="#FFFFFF";
    }
    
    }
      
  /*if(document.getElementById('email2')!=undefined){
    if(objele[i].name == 'R[email][2]' && document.getElementById('email2').value != document.getElementById('email1').value)
      cont2++;
   }*/
   
   if(document.getElementById('pass2')!=undefined){
    if(objele[i].name == 'R[pass][2]' && document.getElementById('pass2').value != document.getElementById('pass1').value)
      cont4++;
   }
   
   if(document.getElementById('pass2')!=undefined){
    if(objele[i].name == 'R[pass][2]' && document.getElementById('pass2').value != document.getElementById('pass1').value)
      cont3++;
   }
  }
  
  if(cont4 > 0){
    alert(exp3);
      
    return false;
  }
  
  if(cont > 0){
    alert(exp4);
    document.getElementById('obriga').style.display='block';
    return false;
  } else {
    return true;
  }
}

function check(sid){

  var state = document.getElementById(sid).checked;
  
  if(state == true){
    document.getElementById('submitbut').style.display = 'block';
  } else {
    document.getElementById('submitbut').style.display = 'none';    
  }  

}

function getXmlHttpRequest() {
  		if (window.XMLHttpRequest) {
  			return new XMLHttpRequest();
  		} else if (window.ActiveXObject) {
  			return new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}



function actualiza_pagina(accao)
{
  
  var previous;
  var next;
  var acto;
  var total;
  
  acto=accao;
  
  previous=document.frm_pagina.previous_page.value;
  next=document.frm_pagina.next_page.value;
  total=document.frm_pagina.total.value;

  var url ="gest/actualiza_pagina.php"; 	
  			
		var post_data="previous="+previous;
		post_data=post_data+"&next="+next;
		post_data=post_data+"&accao="+acto;
		
		//alert(post_data);
		var cmsajaxhttp = getXmlHttpRequest();	//785
    
    cmsajaxhttp.open("GET", url + '?' + post_data, true);
  	 
  		cmsajaxhttp.onreadystatechange = function(){
  		
  			if (cmsajaxhttp.readyState==4){
  			
  				var resultado = cmsajaxhttp.responseText;

  				  if(resultado=="KO")
  				  {
  				    //document.getElementById("loading").style.display="none";
  				  } else {
  				    
  				    var linha = new Array();
  				    //alert(resultado);
    				  linha=resultado.split("|||*FITON*|||");
    				  
    				  document.getElementById("img_show").src=linha[0];
    				  document.frm_pagina.next_page.value=linha[1];
    				  document.frm_pagina.previous_page.value=linha[2];
    				  
    				  if(linha[2]!='-1')
    				  {
    				    document.getElementById("anterior").style.display='block';
    				  }else if(linha[2]=='-1'){
    				    document.getElementById("anterior").style.display='none';
    				  }
    				  if(linha[1]==total){    				  
    				    document.getElementById("seguinte").style.display='none';
    				    }  else if(linha[1]<total){
    				    document.getElementById("seguinte").style.display='block';
                }
              

              if (linha[3]) {
                document.getElementById('prv').href = linha[3];
              }
              
              /*document.getElementById("selectcondicao").innerHTML=(linha[0]);
    				  document.getElementById("descricao_produto").innerHTML=(linha[1]);
    				  document.getElementById("preco_produto").innerHTML=(linha[2]);*/
              
            }
  			}
  		}
  	cmsajaxhttp.send(null);
}


 	
function createQuery(form)
{
    var elements = form.elements;
    var pairs = new Array();

    for (var i = 0; i < elements.length; i++) {

        if ((name = elements[i].name) && (value = elements[i].value))
            pairs.push(name + "=" + encodeURIComponent(value));
        if ((name = elements[i].name) && (value = elements[i].checked))
            pairs.push(name + "=" + encodeURIComponent(value));
    }

    return pairs.join("&");
}


function updateemcurso(form){

  var query=createQuery(form);
  
  if(query!='')
  {
  
  document.getElementById('botaoemcurso').style.display='none';
  document.getElementById('loaderemcurso').style.display='block';
  
  var contentType = "application/x-www-form-urlencoded;";
  
  var url ="actualiza_emcurso.php";
  
  var cmsajaxhttp = getXmlHttpRequest();	//785
      	
 	cmsajaxhttp.open("POST", url, true);
 	cmsajaxhttp.setRequestHeader("Content-Type", contentType);
 	
  cmsajaxhttp.onreadystatechange = function(){
  
  		if (cmsajaxhttp.readyState==4){
  			
  				var resultado = cmsajaxhttp.responseText;
  				
  				if(resultado=="KO")
  				{
  				  document.getElementById('listaemcurso').style.display='none';
          return;
          } else {
            //alert(resultado);
    				document.getElementById('listaemcurso').innerHTML=resultado;
    				document.getElementById('loaderemcurso').style.display='none';
            document.getElementById('botaoemcurso').style.display='block';
          }
  				
          
          
  			}
  		}
  	cmsajaxhttp.send(query);
  } else {
    document.getElementById('loaderemcurso').style.display='none';
    document.getElementById('botaoemcurso').style.display='block';
  }
  
  
}
function updateconcluidos(form){

  var query=createQuery(form);
  
  if(query!='')
  {
  
  document.getElementById('botaoconcluidos').style.display='none';
  document.getElementById('loaderconcluidos').style.display='block';
  
  var contentType = "application/x-www-form-urlencoded;";
  
  var url ="actualiza_concluidos.php";
  
  var cmsajaxhttp = getXmlHttpRequest();	//785
      	
 	cmsajaxhttp.open("POST", url, true);
 	cmsajaxhttp.setRequestHeader("Content-Type", contentType);
 	
  cmsajaxhttp.onreadystatechange = function(){
  
  		if (cmsajaxhttp.readyState==4){
  			
  				var resultado = cmsajaxhttp.responseText;
  				
  				if(resultado=="KO")
  				{
  				  document.getElementById('listaconcluidos').style.display='none';
          return;
          } else {
            
    				document.getElementById('listaconcluidos').innerHTML=resultado;
    				document.getElementById('loaderconcluidos').style.display='none';
            document.getElementById('botaoconcluidos').style.display='block';
          }
  				
          
          
  			}
  		}
  	cmsajaxhttp.send(query);
  } else {
    document.getElementById('loaderconcluidos').style.display='none';
    document.getElementById('botaoconcluidos').style.display='block';
  }
  
  
}

function detectaBrowser() {
    if (navigator.appName.toLowerCase().indexOf('microsoft internet explorer') > -1)
    return('ie');
    else
    if (navigator.appName.toLowerCase().indexOf('netscape') > -1)
    return('firefox');
    }

function ajustaIframe() {
    browser = detectaBrowser();
    
    
    var alturajanela=parent.document.body.scrollHeight;
    
    if (browser == 'firefox') {
    
    var tamanho = parent.document.getElementById('conteudo').contentDocument.body.scrollHeight+10;
    var a;
    a=parseInt(parent.document.getElementById('conteudo').contentDocument.body.scrollWidth);
    var b;
    b=parseInt(parent.document.getElementById('conteudo').style.width);
    
      if(parent.document.getElementById('publi_main2').style.marginLeft=='' || (a>b) ){
      
       //ajusta altura do fade
        parent.document.getElementById('fundo_pub2').style.height = alturajanela+'px';
        
        
        var largura = parent.document.getElementById('conteudo').contentDocument.body.scrollWidth+100;
        
        var posicao=parent.document.getElementById('conteudo').contentDocument.body.scrollWidth/2;
        var posicao2=parent.document.getElementById('conteudo').contentDocument.body.scrollHeight/2;
        
        //centrar o DIV
          parent.document.getElementById('publi_main2').style.marginLeft = '-'+posicao;
          parent.document.getElementById('publi_main2').style.marginTop = '-'+posicao2;
        
        var larguraaux=largura-5;
         
          
          
          parent.document.getElementById('conteudo').style.width = (larguraaux)+'px';
          parent.document.getElementById('conteudo').width = '';
          parent.document.getElementById('publi_main2').style.width = (largura)+'px';
        }
        parent.document.getElementById('conteudo').style.height = (tamanho)+'px';
        parent.document.getElementById('conteudo').height = '';
        parent.document.getElementById('publi_main2').style.height = (tamanho)+'px';
        
    } else {
    if (browser == 'ie') {
    
    var tamanho = parent.conteudo.document.body.scrollHeight;
    
    var a;
    a=parseInt(parent.conteudo.document.body.scrollWidth);
    var b;
    b=parseInt(parent.document.getElementById('conteudo').style.width);
   
   
      if(parent.document.getElementById('publi_main2').style.marginLeft=='' || (a>b) ){
        //ajusta altura do fade
        parent.document.getElementById('fundo_pub2').style.height = alturajanela;
      
        
        var largura = parent.conteudo.document.body.scrollWidth+100;
        
        var posicao=parent.conteudo.document.body.scrollWidth/2;
        var posicao2=parent.conteudo.document.body.scrollHeight/2;
        
          //centrar o DIV
          parent.document.getElementById('publi_main2').style.marginLeft = '-'+posicao;
          parent.document.getElementById('publi_main2').style.marginTop = '-'+posicao2;
          
        var larguraaux=largura-5; 
          parent.document.getElementById('conteudo').style.width = larguraaux;
          parent.document.getElementById('conteudo').height = '';
          parent.document.getElementById('publi_main2').style.width = largura;
      }
      
      
          parent.document.getElementById('conteudo').style.height = tamanho;
          parent.document.getElementById('conteudo').height = '';
          parent.document.getElementById('publi_main2').style.height = tamanho;
          
      
    }
    }
    parent.document.getElementById('conteudo').style.visibility='visible';
    }


function close_pop(){
  
  if(parent.document.getElementById('select'))
  {
  var select=parent.document.getElementById('select');
  
  select.style.visibility = 'visible';
  }
    
  parent.document.getElementById('fundo_pub2').style.display='none';
  parent.document.getElementById('publi_main2').style.display='none';
  parent.document.getElementById('conteudo').style.visibility='hidden';
  parent.document.getElementById('conteudo').src='';
  
}

function show_div(elem){

document.getElementById(elem).style.display="block";
verifica_novamente();
}

function hide_div(elem){

document.getElementById(elem).style.display="none";
verifica_novamente();
}

function show_pop(link){

  if(parent.document.getElementById('select'))
  {
  var select=parent.document.getElementById('select');
  
  select.style.visibility = 'hidden';
  }
  
  document.getElementById("conteudo").src=link;
  
  document.getElementById("fundo_pub2").style.display="block";
  document.getElementById("publi_main2").style.display="block";
}

function mostra()
{ 

  
document.getElementById("fundo_pub2").style.display="block"; 

document.getElementById("publi_main2").style.display="block";

}
function popOpen(popup)
{
    //document.getElementById(popup).style.display='block';
    var height;
    var width;
    if(document.all)
    {
        height=document.body.offsetHeight;
        width=document.body.offsetWidth;
        divHeight=document.getElementById(popup).offsetHeight;
        divWidth=document.getElementById(popup).offsetWidth;
    }
    else
    {
        if(document.getElementById)
        {
            height=window.innerHeight;
            width=window.innerWidth;
            divHeight=document.getElementById(popup).offsetHeight;
            divWidth=document.getElementById(popup).offsetWidth;
        }
    }
    
    getViewportScrollY = function() {
      var scrollY = 0;
      if( document.documentElement && document.documentElement.scrollTop ) {
        scrollY = document.documentElement.scrollTop;
      }
      else if( document.body && document.body.scrollTop ) {
        scrollY = document.body.scrollTop;
      }
      else if( window.pageYOffset ) {
        scrollY = window.pageYOffset;
      }
      else if( window.scrollY ) {
        scrollY = window.scrollY;
      }
      return scrollY;
    };
    var newTop=getViewportScrollY()+(height/2)-(divHeight/2);
    var newLeft=(width/2)-(divWidth/2);
    document.getElementById(popup).style.top=newTop;
    document.getElementById(popup).style.left=newLeft;
}

function numpag(elem){
  var sel;
  var selObj = document.getElementById("npaginas"+elem); 
  
  sel=selObj.selectedIndex;
  
  if(sel>0)
  {
  
    document.getElementById("p").value=elem;    
    frmformato.submit();
  } else {
  
    show("div"+elem);
  }
}
/*
function numfaces(elem){
  var sel;
  var selObj = document.getElementById("nfaces"+elem); 
  
  sel=selObj.selectedIndex;
  
  if(sel>0)
  {
  
    document.getElementById("p").value=elem;    
    frmformato.submit();
  } else {
  
    show("facesdiv"+elem);
  }
}
*/
function numfaces(elem){
  var sel;
  var selObj = document.getElementById("nfaces"+elem); 
  
  sel=2;
  
  if(sel>0)
  {
  
    document.getElementById("p").value=elem;    
    frmformato.submit();
  } else {
  
    show("facesdiv"+elem);
  }
}

function show(divid)
{

	document.getElementById(divid).style.display="block";
}

function span10() {
	document.getElementById("span1").className="span_00_menu"
}

function span100() {
	document.getElementById("span2").className="span_00_menu"
}

function span11() {
	document.getElementById("span1").className="span_01_menu"
}

function span12() {
	document.getElementById("span2").className="span_02_menu"
}

function span20() {
	document.getElementById("span3").className="span_00_menu"
}

function span200() {
	document.getElementById("span4").className="span_00_menu"
}

function span21() {
	document.getElementById("span3").className="span_01_menu"
}

function span22() {
	document.getElementById("span4").className="span_02_menu"
}

function span30() {
	document.getElementById("span5").className="span_00_menu"
}

function span300() {
	document.getElementById("span6").className="span_00_menu"
}

function span31() {
	document.getElementById("span5").className="span_01_menu"
}

function span32() {
	document.getElementById("span6").className="span_02_menu"
}

