var numbr=1;
var tipo="Appear";
var randDest;
var prodDest=new Array();

function random_dest(){


randDest = self.setInterval(function (){

if(numbr!=prodDest.length-1){
  numbr++;
}else{
  numbr=1;
}

Effect.Appear("banner", { duration: 60.0,from:1,to:1,afterFinishInternal:function (){Effect.Fade("banner", { duration: 60.0,from:1,to:1});}});




muda_img(prodDest[numbr]);
},"120000");
}

function muda_img(id){

 var nr = document.getElementById("nr_" + id);
  var seta = document.getElementById("seta" + id);
  var td = document.getElementsByTagName("td");
  
  for(i = 0; i <td.length; i++){
    	
        	if(td[i].className=="nr_sel"){
    				  
              td[i].className="nr";
      				
          }
          if(td[i].className=="seta_sel"){
    				  
              td[i].className="seta";
      				
          }
    	}
  
  if(nr!=null){
    nr.className='nr_sel';
  }
  if(seta!=null){
    seta.className='seta_sel';
  }

var flash = "flash/" + id;

var so2 = new SWFObject(flash, 'flash', "493","190", '9', '#000000');
so2.addParam("wmode", "transparent");
so2.addParam('scale', 'noScale');
so2.write('banner');

 

}

function escolhe_data() {


var arrDates = cal2.getSelectedDates(); 
for (var i = 0; i < arrDates.length; ++i) { 
  var date = arrDates[i]; 

	 
var mes = date.getMonth() + 1; 
var ano = date.getFullYear(); 
var dia = date.getDate(); 


document.getElementById("diaSS").value=dia;
document.getElementById("mesSS").value=mes;
document.getElementById("anoSS").value=ano;
cal2.hide();
}
}

function escolhe_data1() {

var arrDates = cal2.getSelectedDates(); 
for (var i = 0; i < arrDates.length; ++i) { 
  var date = arrDates[i]; 

	 
var mes = date.getMonth() + 1; 
var ano = date.getFullYear(); 
var dia = date.getDate(); 


document.getElementById("dia").value=dia;
document.getElementById("mes").value=mes;
document.getElementById("ano").value=ano;
cal2.hide();
}
}


/* VALIDAÇÃO DE FORMULÁRIOS */
var DOM = YAHOO.util.Dom;
var EVT = YAHOO.util.Event;

function validate_form(_obj){
  var errors = false;

	DOM.getElementsByClassName(
		'required',
		null,
		_obj,
		function(e){
  			var _tag  = e.tagName;
  			var _type = e.getAttribute('type');
  			var _emai = e.getAttribute('email');
  			var _fich = e.getAttribute('fich');
        var _sel  = e.getAttribute('selecta');
        
        //alert (_emai);
  			if(_tag == 'TEXTAREA' || _type == 'text' || _type == 'password'){
  				if ((e.value == '') || (e.value == 'Preenchimento obrigatório.')){
            var _varid = e.getAttribute('id');
            e.style.border = '1px solid #D20000';
  					e.style.color  = '#D20000';
  					//e.value = 'Preenchimento obrigatório.';
            document.getElementById('erroCampos').style.display='block';
            
  					EVT.addListener(e, "focus", function(){ e.value = '';e.style.border = '1px solid #D3D3D3';e.style.color  = '#999999';});
  					
  					if(errors == false) errors = true;
  					
  				} else {
  				  var idinput =  e.getAttribute('id');
  				  if (idinput=='confpass') {
  				    var pass1 = document.getElementById('password').value;
  
  				    if (pass1 != e.value){
                //alert("As passwords introduzidas não são iguais.")
                
                var _varid = e.getAttribute('id');
                e.style.border = '1px solid #D20000';
      					e.style.color  = '#D20000';
      					//e.value = 'Preenchimento obrigatório.';
      					
      					document.getElementById('password').style.border = '1px solid #D20000';
      					document.getElementById('password').style.color  = '#D20000';
      					//document.getElementById('password').value = 'Preenchimento obrigatório.';
                
      					//EVT.addListener(e, "focus", function(){ e.value = ''; });
      					
      					if(errors == false) errors = true;
              } else {
                var _varid = e.getAttribute('id');
      				  e.style.border = '1px solid #D3D3D3';
      					e.style.color  = '#5F5F5F';
      					
      					document.getElementById('password').style.border = '1px solid #D3D3D3';
      					document.getElementById('password').style.color  = '#5F5F5F';
      					
              }
  				  
            } else {
    				  var _varid = e.getAttribute('id');
    				  e.style.border = '1px solid #D3D3D3';
    					e.style.color  = '#5F5F5F';
    				}
  				}
  				
  				if(_emai == 1){
  					if(verify_email(e.value) == false){
  						var _varid = e.getAttribute('id');
              e.style.border = '1px solid #D20000';
    					e.style.color  = '#D20000';
    					alert('E-mail Inválido')
              
  						//EVT.addListener(e, "focus", function(){ e.value = ''; });
  						
  						if(errors == false) errors = true;
  						
  					} else {
  					  var _varid = e.getAttribute('id');
      				e.style.border = '1px solid #D3D3D3';
    					e.style.color  = '#5F5F5F';
  					}
  				}
  			} else if(_fich == 1){
  			  if(e.value == ''){
            var _varid = e.getAttribute('id');
            e.style.border = '1px solid #D20000';
  					e.style.color  = '#D20000';
  					//e.value = 'Preenchimento obrigatório.';
  					//EVT.addListener(e, "focus", function(){ e.value = ''; });
  					if(errors == false) errors = true;
          } else {
  					var _varid = e.getAttribute('id');
  				  e.style.border = '1px solid #D3D3D3';
  					e.style.color  = '#5F5F5F';
  				}
  			} else if(_sel == 1) {
          if ((e.value=="") || (e.value==0)){
            var _varid = e.getAttribute('id');
            e.style.border = '1px solid #D20000';
  					e.style.color  = '#D20000';
						//EVT.addListener(e, "focus", function(){ e.value = ''; });
						if(errors == false) errors = true;
          } else {
            var _varid = e.getAttribute('id');
  				  e.style.border = '1px solid #D3D3D3';
  					e.style.color  = '#5F5F5F';
          }
  			} else if(_type == 'checkbox') {
  				if(e.checked == false){
  					//alert('Tem de dizer se aceita os termos e condições de funcionamento do site.');
  					if(errors == false) errors = true;
  				}
  			}
  		
		}
	);
	
	if(errors == true){
		return false;
	} else {
		return true;
	}
	
}

function verify_email(_mail){
	
  var status = false;     
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
  if (_mail.search(emailRegEx) == -1) {
		status = false;
	} else {
		status = true;
	}
	return status;
}

function valida_email(email){
  var e = email.value;
  var erro = 0;
  if (e!=''){
    if (verify_email(e) == false){
      alert("Email inválido.");
      erro=1;
    }
  } else {
    alert("Tem que introduzir um email válido.");
    erro=1;
  }
  if(erro==1){  
    return false;
  } else {
    return true;
  }
}
/* VALIDAÇÃO DE FORMULÁRIOS */


function showHover(wish, x){
  var wishx = document.getElementById(wish);
  var xx = document.getElementById(x);
  wishx.style.display = "block";    
  xx.style.zIndex=15;
  
}

function hideHover(wish, x){
  var wishx = document.getElementById(wish);
  var xx = document.getElementById(x);
  wishx.style.display = "none"; 
  xx.style.zIndex=9;   
}



function simulador(x,y){
    var a = document.getElementById(x);
    var b = document.getElementById(y);
    var y = document.getElementById('i');
    var x = y.className;
    for (j=1;j<=x;j++){
      document.getElementById('label'+j+'on').style.display="none";
      document.getElementById('label'+j+'off').style.display="block";
    }
      a.style.display = "none";    
      b.style.display = "block";
}


function ppr(x){

    for(i=1;i<5;i++){ 
      document.getElementById('s'+i).style.display="none";
      document.getElementById('m'+i).className="menuSimuladorLinks";
    }
   var a = document.getElementById(x);
   a.style.display = "block";
   
   if(x == "s1") document.getElementById('m1').className="simuladorSelectedFirst";
   else if(x == "s2") document.getElementById('m2').className="simuladorSelected";
   else if(x == "s3") document.getElementById('m3').className="simuladorSelected";
   else if(x == "s4") document.getElementById('m4').className="simuladorSelected";
   
   
}

function subEsqShow(mais,menos,sub){
    var a = document.getElementById(mais);
    var b = document.getElementById(menos);
    var c = document.getElementById(sub);
    
    a.style.display = "none";    
    b.style.display = "block";
    c.style.display = "block";  
}

function subEsqHide(mais,menos,sub){
    var a = document.getElementById(mais);
    var b = document.getElementById(menos);
    var c = document.getElementById(sub);
    
    a.style.display = "block";    
    b.style.display = "none";
    c.style.display = "none";  
}


/*************** funçao perfil investidor *********************/
function perfil(){
    var x = 0;
    var k=0;
    //pergunta 1
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo1[i].checked==true)
       {
          if(i==0) x=3;
          else if(i==1) x=2;
          else if(i==2) x=1;
          k++;
       }
        
    } 
    
    //pergunta 2
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo2[i].checked==true)
       {
          if(i==0) x=x+1;
          else if(i==1) x=x+2;
          else if(i==2) x=x+3;
          k++;
       }
    }
    
    //pergunta 3
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo3[i].checked==true)
       {
          if(i==0) x=x+6;
          else if(i==1) x=x+4;
          else if(i==2) x=x+2;
          k++;
       }
    } 
    
    //pergunta 4
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo4[i].checked==true)
       {
          if(i==0) x=x+6;
          else if(i==1) x=x+4;
          else if(i==2) x=x+2;
          k++;
       }
    } 
   
    //pergunta 5
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo5[i].checked==true)
       {
          if(i==0) x=x+3;
          else if(i==1) x=x+2;
          else if(i==2) x=x+1;
          k++;
       }
    }
    
    //pergunta 6
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo6[i].checked==true)
       {
          if(i==0) x=x+2;
          else if(i==1) x=x+2;
          else if(i==2) x=x+1;
          k++;
       }
    }
   
    //pergunta 7
    for (i=0; i<3; i++)
    {
       if (document.myform.prazo7[i].checked==true)
       {
          if(i==0) x=x+6;
          else if(i==1) x=x+4;
          else if(i=2) x=x+2;
          
          k++;
       }
    }
    
    var text = document.getElementById('resPerfil');
    
    var y=0;
    y=document.myform.idade.value;
    
    if(y){
      if(y<36) x = x + 1;
      if(y>=36 && y<54) x = x+2;
      if(y>=54) x = x+3;
    }
    
    if(k==7){
        if(x>=25) perfilCandidato = "Investidor Defensivo";
        if(x<25 && x>=20) perfilCandidato = "Investidor Moderadamente Defensivo";
        if(x<20 && x>=15) perfilCandidato = "Investidor Moderadamente Dinâmico";
        if(x<15) perfilCandidato = "Investidor Dinâmico";
        
        text.innerHTML = perfilCandidato;
    }else alert("Para definir o seu perfil de investidor por favor responda a todas as questões.");

}
/************************************/





function madeSelection(selObj,x){
    var selectedValue = selObj.options[selObj.selectedIndex].value;
    var selectedText = selObj.options[selObj.selectedIndex].text;
    var a = document.getElementById(x);
    //if(selectedValue == 2) a.style.display = "block";
    //else a.style.display = "none";
    
    var fundoCaixa = document.getElementById('pdfs');
    var fundoCaixa2 = document.getElementById('resultadobg');
    
    if(selectedValue == 2){ a.style.display = "block";fundoCaixa.className='pdfs2';fundoCaixa2.className='resultadobg2';}
    else {a.style.display = "none";fundoCaixa.className='pdfs';fundoCaixa2.className='resultadobg';}
 
}

function RenderTTF(){
    
  
  DATAFUNCS.RenderFonts('tit_H1',{ 
        fontSize         : '22.50',
       backgroundColor  : 'FFFFFF',
       color            : '53A814',
       fontFile         : 'fonts/din_light_0.ttf',
       transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('legenda',{ 
       fontSize         : '6',
       backgroundColor  : 'FFFFFF',
       color            : '999999',
       fontFile         : 'fonts/kroeger 05.ttf',
       transparent      : '1'
    }); 
  
}

// AJAX
function getXmlHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function refreshCalculo(valor,posicao){    
  
  var calculo = parseInt(document.getElementById('percentagem').value);
  var calculo1 = parseInt(document.getElementById('percentagem1').value);
  var calculo2 = parseInt(document.getElementById('percentagem2').value);
  var calculo3 = parseInt(document.getElementById('percentagem3').value);
  
  var calc_fim = calculo + calculo1 +calculo2+calculo3;

  
 
  if (posicao>2){

    if(calc_fim!=100){
    //  alert('tem que investir 100%');
    document.getElementById('showTotal').style.display = 'block';
     document.getElementById('valor_final').style.display = 'none';
  }else{
    document.getElementById('showTotal').style.display = 'none';
     document.getElementById('valor_final').style.display = 'block';
  }
  
      var perc = document.getElementById(valor);

      var valor = perc.name;
      if (perc.value==""){
                
      } else {
        var post_data="valor="+valor+"&posicao="+posicao+"&ppr=1"+"&perc="+perc.value;  
        var url ="calculo_final.php"; 	  
        var cmsajaxhttp = getXmlHttpRequest();      	
       	cmsajaxhttp.open("GET", url+'?'+post_data, true);
      }
      
  } else {
  document.getElementById('valor_final').style.display = 'block';
    var post_data="valor="+valor+"&posicao="+posicao+"&ppr=1";
    var url ="calculo_final.php"; 	  
    var cmsajaxhttp = getXmlHttpRequest();      	
   	cmsajaxhttp.open("GET", url+'?'+post_data, true);
      
  }
  
  
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			//var rs = resultado.split('||');
                  
      document.getElementById('valor_final').innerHTML = resultado + "€  mês";					                                                
                              						 		        			  		        	        
      
		}
	}
	
 	cmsajaxhttp.send(null);
  
          
}

function checkValue(valor){
  if (valor>100){
    alert("Valor ERRO");
    return false;
  }
}


function verify_number(field){
  if (isNaN(field.value)) 
  {
    alert("Só pode introduzir caracteres numéricos.");
    field.value='';
    field.focus();
  }
}


function alertSS(x){
    if(x==2){
      alert("Brevemente disponível");
      document.getElementById('regime').value=1;
    }
  
}


function showRentabilidades(y){


  var text = document.getElementById('lj');

  document.getElementById('allLojas').style.display='none';

  text.innerHTML = y;

  
}

function mh(x){
  for(var i=1;i<=8;i++){
    document.getElementById('h'+i).style.display='none';
  }
  
  document.getElementById(x).style.display='block';
}

function hh(){
 for(var i=1;i<=8;i++){
    document.getElementById('h'+i).style.display='none';
  }
  
}
function ver_idade(){
var _idade = document.getElementById('idade');
if(_idade.value>=55){
return true;
}else {
alert("Não é possível antecipar a sua reforma para uma idade inferior a 55 anos. Por favor insira uma idade igual ou superior.");
return false;
}
}

function ver_diferenca(idade_reforma,ano_nasci){

if(idade_reforma>=65){

  var ano_desconto = document.getElementById("anoSS");
  
  var ano_final = (ano_nasci+idade_reforma); 
  var conta = (ano_final-ano_desconto.value);
  
  if(conta <15){
     alert("O número de anos de desconto para a Segurança Social deverá ser pelo menos 15. Reinicie, por favor, a sua simulação.");
     location.href='index.php?id=98';
     return false;
  }else{
     return true;
  }

} else if(idade_reforma<65 ){

  var ano_desconto = document.getElementById("anoSS");
  
  var ano_final = (ano_nasci+idade_reforma); 
  var conta = (ano_final-ano_desconto.value);

  var valor=30;
  for (var i=55;i<65;i++){
    if(idade_reforma == i){
      if(conta>=valor){
        return true;
      }else {
        alert("O número de anos de desconto para a Segurança Social deverá ser pelo menos " + valor + ". Reinicie, por favor, a sua simulação.");
        location.href='index.php?id=98';
        return false;
      } 
    }
    valor++;
  }
}  

}
