
 var version = jQuery.browser.version.substr();

 jQuery(document).ready(function(){
    
    animacoesHome();
    animacoesPopup();
    
    tagcloud();
   
    if(version == "7.0") {
      jQuery(".bt_geral span").css("padding-left", "11px");
      jQuery(".unipub4").css("padding-bottom", "5px");
      jQuery(".lateral_direita").css("margin-top", "-2px");
      jQuery(".line65").css("margin-right", "6px");
      jQuery(".line65, .line64").css("margin-right", "6px");
      jQuery(".listagem_edicoes a").css("padding-top", "1px");
    }
    
    if(jQuery.browser.safari == true) {
      jQuery(".pesquisa_topo input[type=text]").css("margin-top", "3px");
    }
    
    if(jQuery('.rightselect span.selectvalue').text() == ''){
      jQuery('span.selectvalue').each(function(i){
          jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
      });
    }
    
    jQuery('.rightselect select').change(function(){
      jQuery('span.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
    });
    
    
    jQuery(".radios_registo input").click(function(){
      var idRadio = jQuery(this).attr("id");
      if(idRadio == "nao") {
        jQuery(".rightinputs").fadeOut(100);
        validaAssinante(0);
      } else if(jQuery(".rightinputs").css("display") == "none") {
        jQuery(".rightinputs").fadeIn(200);
        validaAssinante(1);
      }
    });
    
    /*jQuery(".line62").click(function(){
      if(jQuery(this).attr("class") == "line62"){
        
        var altura1 = jQuery(".infAdicional").height();
        jQuery(".informacaoAdicional").css("border-top", "2px solid #FFF");
        jQuery(".informacaoAdicional").animate({
          "height" : altura1 + "px",
          "padding-top" : "14px",
          "padding-bottom" : "10px"
        },500, function(){
          jQuery(".line62").css("display", "none");
          jQuery(".line64").css("display", "block");
        });
        
      }
    });*/
    
    var numeroClickss = 0;
    var filhos = 0;
    var variavel1 = 0;
    var newSize = 0;
    
    jQuery(".aumentar").click(function(){
      if(numeroClickss < 2) {
        filhos = jQuery(".bloc_rubrica").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) + 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        variavel1 = jQuery(".bloc_rubrica").css("font-size");
        newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) + 2;
        jQuery(".bloc_rubrica").css("font-size", newSize);
        
        filhos = jQuery(".desc_and_movie .left").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) + 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        filhos = jQuery(".desc_and_image .right").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) + 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        numeroClickss++;
      }
      
      
      
      
      
    });
    
    
     jQuery(".diminuir").click(function(){
      if(numeroClickss > 0) {
        filhos = jQuery(".bloc_rubrica").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) - 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        variavel1 = jQuery(".bloc_rubrica").css("font-size");
        newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) - 2;
        jQuery(".bloc_rubrica").css("font-size", newSize);
        
        filhos = jQuery(".desc_and_movie .left").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) - 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        filhos = jQuery(".desc_and_image .right").children();
        for(i=0; i<filhos.length; i++) {
          variavel1 = jQuery(filhos[i]).css("font-size");
          newSize = parseInt(variavel1.substring(0, variavel1.length - 2)) - 2;
          jQuery(filhos[i]).css("font-size", newSize);
        }
        
        numeroClickss--;
      }
    });
    
    
    });
 
 function tagcloud(){

  jQuery('#tagcloud').masonry({  
    columnWidth: 1, 
    itemSelector: '.lnk_tag' 
  });
  
}
 function animacoesHome() {
  
  //jQuery(".maisNoticias").click(function(){
    var altura = jQuery("#cnthome77").height();
    jQuery(".bloco_mais_not").animate({
      height : altura + 20,
      "padding-top" : "28px"
    },600, function(){
      jQuery(".bloco_mais_not").css("overflow", "visible");
      jQuery(".bloco_mais_not").css("margin-bottom", "-2px");
      jQuery(".line25_2").css("display", "block");
      //jQuery(".close_home").show(300);
      jQuery(".close_home").hide();
    });
  //});
  
  
 /* jQuery(".close_home").click(function(){
    jQuery(".bloco_mais_not").css("overflow", "hidden");
    jQuery(".bloco_mais_not").css("margin-bottom", "49px");
    jQuery(".line25_2").css("display", "none");
    jQuery(".close_home").hide(300);
    
    jQuery(".bloco_mais_not").animate({
      height : 0,
      "padding-top" : "0px"
    },600, function(){
      
    });
  });*/
  
  jQuery(".line16").mouseover(function(){
    
   
    
    var filhos = jQuery(".destaque_sel").children();
    var rel= jQuery(this).attr("rel");
    jQuery(".line16_sel").attr("class", "line16");
    jQuery(this).attr("class", "line16_sel");
    
    jQuery(filhos[rel]).css("z-index", "10");
    jQuery(filhos[rel]).fadeIn(200, function(){
      jQuery(filhos).css("display", "none");
      jQuery(filhos[rel]).css("display", "block");
      jQuery(filhos[rel]).css("z-index", "0");
    });
    
  });
  jQuery(".line16_sel").mouseover(function(){
    
   
    
    var filhos = jQuery(".destaque_sel").children();
    var rel= jQuery(this).attr("rel");
    jQuery(".line16_sel").attr("class", "line16");
    jQuery(this).attr("class", "line16_sel");
    
    jQuery(filhos[rel]).css("z-index", "10");
    jQuery(filhos[rel]).fadeIn(200, function(){
      jQuery(filhos).css("display", "none");
      jQuery(filhos[rel]).css("display", "block");
      jQuery(filhos[rel]).css("z-index", "0");
    });
    
  });
  
  
  
  jQuery(".menunot").live("click", function(){
    
    var filhos = jQuery(".conteudosDestaques2").children();
    var rel= jQuery(this).attr("rel");
    var rel2= jQuery(".selmenunot").attr("rel");
    jQuery(".selmenunot").attr("class", "menunot");
    jQuery(this).attr("class", "selmenunot");
    
    jQuery(filhos[rel2]).fadeOut(300, function(){
      
      
      jQuery(filhos[rel]).css("z-index", "10");
      jQuery(filhos[rel]).fadeIn(600, function(){
        jQuery(filhos).css("display", "none");
        jQuery(filhos[rel]).css("display", "block");
        jQuery(filhos[rel]).css("z-index", "0");
      });
      
      
    });
  });
  
  
 }
 
 function animacoesPopup() {
  
  jQuery(".line43").click(function(){
    var alturaSite = jQuery(document).height();
    jQuery(".pop_geral").css("height", alturaSite).fadeIn(500, function(){
      jQuery(".pop_video").animate({"width" : "661"}, 500,function(){ 
          
          var id = jQuery(".line43").attr('id');
          id = id.split("_");
          id =  id[1];
          
          var flash = "/flash/not_" + id + ".flv";
          
          var fo2 = new FlashObject("flash/video2.swf", "movie" + id,641,373, "9", "000000");
        	fo2.addParam("wmode", "transparent");
        	fo2.addParam("scale", "scale");
        	fo2.addParam("allowFullScreen", "true");
        	fo2.addVariable("videoID",slocation + "/" + flash);
          fo2.addVariable("typePlay", true);
        	fo2.write("video");
          
       });
    });
  });
  
  jQuery(".closepop").click(function(){
      jQuery(".pop_video").animate({"width" : "0"}, 500, function(){
        jQuery(".pop_geral").fadeOut(500,function(){
          jQuery("#video").html('');
        });
      });
  });
  
 }
 
 function PopupSugerir(idpagina,idnoticia) {
  
 
  
    
    var alturaSite = jQuery(document).height();
    
    $('html, body').animate({scrollTop: 0}, 1200);
    
    jQuery(".pop_video").css({"height" : "314px"}); 
    jQuery(".pop_geral").css("height", alturaSite).fadeIn(500, function(){
      jQuery(".pop_video").animate({"width" : "417px"}, 500,function(){ 
          
           $.ajax({
              url: 'ajax_frm_sugerir.php',
              type: 'POST',
              data:{idp:idpagina,idn:idnoticia},
              success: function(data) {
                  
                  jQuery(".pop_video").css("height","314px");
                  
                
                  $('#video').html(data);
                  jQuery("#div_sug").css("margin-left","247px");
                  jQuery("#div_sug").css("margin-bottom","-22px");
              }
          }); 
          
        
          
       });
    });
  
  
  jQuery(".closepop").click(function(){
      jQuery(".pop_video").animate({"width" : "0"}, 500, function(){
        jQuery(".pop_geral").fadeOut(500,function(){
          jQuery("#video").html('');
          jQuery(".pop_video").css({"height" : "433px"}); 
        });
      });
  });
  
 }
 
  
 function dologin(){
 
 var username = $('#username').val();
 var password = $('#password').val();
 
 if(username == ""){
    alert(unescape(json[1]));
    $('#username').css('border',"1px solid red");
    $('#username').focus(function() {
      $('#username').css('border',"1px solid #FFF");
    });
    return false;
 }else if(password == ""){
    alert(unescape(json[2]));
    $('#password').css('border',"1px solid red");
    $('#password').focus(function() {
      $('#password').css('border',"1px solid #FFF");
    }); 
    return false;   
 }
  $.ajax({
      url: 'ajax_dologin.php',
      type: 'POST',
      data:$('#frm_login').serializeArray(),
      success: function(data) {
        if(data != ""){
          $('#frm_login').html(data);
          $('.bloqueado').hide();
        }else{
          alert("Dados incorrectos.Por favor tente novamente.");
        }    
      }
  });
  return false;
 
} 

function comentar(){
 
 var titulo = $('#titulo').val();
 var comentario = $('#comentario').val();
 
 if(titulo == ""){
    alert(unescape(json[10]));
    $('#titulo').css('border',"1px solid red");
    $('#titulo').focus(function() {
      $('#titulo').css('border',"1px solid #FFF");
    });
    return false;
 }else if(comentario == ""){
    alert(unescape(json[11]));
    $('#comentario').css('border',"1px solid red");
    $('#comentario').focus(function() {
      $('#comentario').css('border',"1px solid #FFF");
    });  
    return false;   
 }
 
 $('#btn_comentar button').hide();
 
 $('#btn_comentar').css('background-image','url(sysimages/ajax-loader.gif)');
 $('#btn_comentar').css('background-repeat','no-repeat');
 $('#btn_comentar').css('background-position','center center');
 $('#btn_comentar').css('width','16px');
 $('#btn_comentar').css('height','16px');
 $('#btn_comentar').css('margin-top','20px');
 $('#btn_comentar').css('margin-right','20px');
  
  $.ajax({
      url: 'ajax_comentario.php',
      type: 'POST',
      data:$('#frm_coment').serializeArray(),
      success: function(data) {
        if(data == 1){
          $('#frm_coment').html("<p>" + unescape(json[12]) + "</p>");
          //$('.bloqueado').hide();
        }   
      }
  });
  return false;
 
}

function enviarsugestao(){
 
 var nome = $('#nome').val();
 var email = $('#email').val();
 
 var nome2 = $('#nome2').val();
 var email2 = $('#email2').val();
 
 if(nome == ""){
    alert("Por favor preencha o seu nome correctamente.");
    $('#nome').css('border',"1px solid red");
    $('#nome').focus(function() {
      $('#nome').css('border',"1px solid #FFF");
    });
    return false;
 }else if(email == "" || verify_email(email)==false){
    alert("Por favor preencha o seu endereço de e-mail correctamente.");
    $('#email').css('border',"1px solid red");
    $('#email').focus(function() {
      $('#email').css('border',"1px solid #FFF");
    });  
    return false;   
 }else if(nome2 == "" ){
    alert("Por favor preencha o nome para quem pretende enviar a noticia.");
    $('#nome2').css('border',"1px solid red");
    $('#nome2').focus(function() {
      $('#nome2').css('border',"1px solid #FFF");
    });
    return false;
 }else if(email2 == "" || verify_email(email2)==false ){
    alert("Por favor preencha o endereço de e-mail para quem pretende enviar a noticia correctamente.");
    $('#email2').css('border',"1px solid red");
    $('#email2').focus(function() {
      $('#email2').css('border',"1px solid #FFF");
    });  
    return false;   
 }
 
 $('#btn_sugerir button').hide();
 
 $('#btn_sugerir').css('background-image','url(sysimages/ajax-loader.gif)');
 $('#btn_sugerir').css('background-repeat','no-repeat');
 $('#btn_sugerir').css('background-position','center center');
 $('#btn_sugerir').css('width','16px');
 $('#btn_sugerir').css('height','16px');
 $('#btn_sugerir').css('margin-top','20px');
 $('#btn_sugerir').css('margin-right','20px');
  
  $.ajax({
      url: 'ajax_sugerir.php',
      type: 'POST',
      data:$('#frm_sugerir').serializeArray(),
      success: function(data) {
        if(data == 1){
          $('#div_sug').html("<p>" + unescape(json[50]) + "</p>");
          //$('.bloqueado').hide();
        }   
      }
  });
  return false;
 
}

function getEdicoes(){
 
 var mes = $('#m').val();
 var ano = $('#y').val();
 
 /*if(mes!= 0 && ano == 0){
  alert("Escolha o ano por favor.");
  return false;
 }else if(mes== 0 && ano != 0){
  alert("Escolha o mês que pretende ver por favor.");
  return false;
 }else if(mes!= 0 && ano != 0){*/
    
    $('.pesqRub').css('background-image','url(./sysimages/ajax-loader.gif)');
    $('.pesqRub').css('background-repeat','no-repeat');
    $('.pesqRub').css('background-position','190px center');
    
    //$('#list_ed').css('min-height','400px');
    
    $.ajax({
        url: 'ajax_edicoes.php',
        type: 'GET',
        data:$('#frm_flt').serializeArray(),
        success: function(data) {
          if(data == null){
            
            $('#list_ed').html("<p>" + unescape(json[19]) + "</p>");
            //$('.bloqueado').hide();
          }else {
            $('#list_ed').html(data);
            
            
            
            $.ajax({
                url:'ajax_paginacao.php',
                type: 'GET',
                data:$('#frm_flt').serializeArray(),
                success: function(data) {
                  $('.paginacao_rub').html(data);
                   
                }
            });
            
          }
          
          $('.pesqRub').css('background-image','');
          //$('#list_ed').css('min-height','400px');
          
          if(version == "7.0") {
            jQuery(".listagem_edicoes a").css("padding-top", "1px");
          }
             
        }
    });
    return false;
 //}
} 
  
function getEdicao(edicao,pgID){
 
  $('.rubrica').css('background-image','url(./sysimages/ajax-loader.gif)');
  $('.rubrica').css('background-repeat','no-repeat');
  $('.rubrica').css('background-position','center center');
  
  
 

  $.ajax({
      url: 'pflip2.php',
      type: 'GET',
      data:{id:edicao,pg:pgID},
      success: function(data) {
        
      	$('.rubrica').empty();
      	$('.rubrica').hide(function(){
      		$('.rubrica').html(data);
      		$('#flashcontent').css('height','565px');
      		$('#flashcontent').css('width','900px');
      		$('#flashcontent').css('margin-top','20px');
      		//$('#flashcontent').css('background-color','#1D6F7D');
      	//	$('#flashcontent').css('margin-left','50px');
      		//$('#pageflip_loader').css('height','680px');
      		//$('#pageflip_loader').css('width','910px');
      		$('.rubrica').show();
      		
      		
      		
      	});
        $('.rightSite').hide();
        $('.leftSite').css('width','995px');
        $('.leftSite').css('height','680px');
      	$('.rubrica').css('width','995px');
      
      
        
      }
  });
  return false;
 
}


function resposta(id){
  
  $('#comentario_id').attr('value',id);
  $('#comentario_id').focus();
  //var dh = document.getElementsByTagName('body')[0].offsetHeight;
  //window.scroll(0,dh);
  
  var altura = (($('body').height()) - 810);
  //alert(altura)
  $('html,body').animate({scrollTop: altura}, 1000);
  
  return false;
}


function verifica_pesq(formID) {

var form = document.getElementById(formID);
var txt = form.pesq;
var texto = txt.value;
var error;

  if((txt.value=="") || (txt.value==unescape(json[20]))){
      alert(unescape(json[21]));
      error=1;
  }else if(txt.value!="" &&  texto.length<3){
      alert(unescape(json[21]));
      error=2;
      //return false;
  }

  if((txt.value!=unescape(json[20])) && (txt.value!="") && (texto.length>=3)){
     error=0;
     //document.getElementById(form).submit();
      
  }
  
  if(error>0){
    return false;
  }else {
    return document.getElementById(formID).submit();
  }
}
  
  function validaAutorizacao(form){
      if(form.autorizo.checked == false){ 
        alert('Por favor confirme que autoriza o envio de informação.');
        return false;
      }else {
        return verify_form_data(form,'THISFORMNEWS');
      }
      
      
  }
  
  function alterarCidade(){
      $('.lnkcidade').hide(
        function(){
          $('.selcidade').show();
        }
      );
  }
function mudaTempo(id){
     $.ajax({
      url: 'inc_tempo.php',
      type: 'POST',
      data:{tempo:id,ajax:1},
      success: function(data) {
      	$('#tempo').html(data);
      }
  });
  return false;
}


function verificauser(){
  
  var length = $('#username').val().length;
  
  if(length <= 5){
    $('#info_username').attr('class','erro3');
    $('#info_username').html('<div>Nome de utilizador deverá ter mais do que 5 caracteres.<br><b style=\"color:#CC0000\">(Evitar caracteres acentuados e espaços)</b>.</div>');
    $('#info_username').css("width","300px");
    $('#info_username').css("height","38px");
    $('#form_registo').attr('action','#');
    $('#valuser').attr('value',0);
    $('#bloqueado1').attr('class','line62 _bloqueado');
    return false;
    //$('#form_registo')[0].setAttribute('onsubmit',"return validauser()");
    //return false;
  }else {
      $('#info_username').empty();
      $('#info_username').attr('class','erro3');
      $('#info_username').css("height","20px")
      $('#valuser').attr('value',1);
      $('#bloqueado1').attr('class','line62 _bloqueado'); 
      //$('#form_registo')[0].setAttribute('onsubmit',"return validauser()");
    
    
  }
  
  $.ajax({
      url: 'ajax_user.php',
      type: 'POST',
      data:{user:$('#username').val()},
      //data:$('#frm_flt').serializeArray(),
      success: function(data) {
      	
      	
        if(data == 1){
          $('#info_username').attr('class','erro3');
          $('#info_username').html('<div>Nome de utilizador já existe</div>');
          $('#form_registo').attr('action','#');
          $('#valuser').attr('value',0);
          $('#bloqueado1').attr('class','line62 _bloqueado'); 
          return false;
          //$('#form_registo').attr('onsubmit',"alert('Preencha um nome de utilizador válido');return false;");
        }else if(data == 3){
          $('#info_username').attr('class','erro3');
          $('#info_username').html('<div>Por favor preencha um nome de utilizador</div>');
          $('#form_registo').attr('action','#');
          $('#valuser').attr('value',0);
          $('#bloqueado1').attr('class','line62 _bloqueado'); 
          return false;
          //$('#form_registo').attr('onsubmit',"alert('Preencha um nome de utilizador válido');return false;");
        }else{
          $('#info_username').attr('class','ok');
          $('#info_username').empty();
           $('#form_registo').attr('action','#');
          //$('#form_registo').attr('action','add_cliente.php');
          $('#valuser').attr('value',1);
          $('#bloqueado1').attr('class','line62 _bloqueado'); 
          return false;
          //$('#form_registo').attr('onsubmit',"alert('Preencha um nome de utilizador válido');return false;");
        }
        
       
       
              
      }
  });
  
  
}

function validauser(){
  
  //alert("OK0");
  
  var username = $('#username').val();
  var password = $('#password').val();
  var conf_password = $('#confpassword').val();
  
 
  if(username.length <= 5){
     $('#info_username').attr('class','erro3');
    $('#info_username').html('<div>Nome de utilizador deverá ter mais do que 5 caracteres.<br><b style=\"color:#CC0000\">(Evitar caracteres acentuados e espaços)</b>.</div>');
    $('#info_username').css("width","300px");
    $('#info_username').css("height","38px");
    $('#form_registo').attr('action','#');
    $('#valuser').attr('value',0);
    return false;
    //$('#form_registo')[0].setAttribute('onsubmit',"return false;");
    //return false;
  }else {
      /*$('#info_username div').empty();
      $('#info_username').attr('class','erro3');
      $('#info_username').css("height","20px")
      $('#valuser').attr('value',1);
      $('#bloqueado1').attr('class','line62 _bloqueado'); */
    //$('#form_registo')[0].setAttribute('onsubmit',"return validauser()");
    
    
  }
  
  if(username == ""){
    $('#info_username').attr('class','erro3');
    $('#info_username').html('<div>Por favor preencha o nome de utilizador.</div>');
    $('#form_registo').attr('action','#');
    
    return false;
    
  }else if(password == "" ){
    $('#info_password').attr('class','erro3');
    $('#info_password').html('<div>Por favor preencha uma palavra-chave.</div>');
    $('#form_registo').attr('action','#');
    
    return false;  
  }else if(conf_password == ""  ){
    $('#info_cpassword').attr('class','erro3');
    $('#info_cpassword').html('<div>Por favor confirma a sua palavra-chave.</div>');
    $('#form_registo').attr('action','#');
    return false;  
  }
  
   if($('#valpass').attr('value') == 1 && $('#valuser').attr('value') == 1){
    $('#bloqueado1').attr('class','line62'); 
  }
  
  
  
   
  
  
}


function validapass(){
  
  
  
  var username = $('#username').val();
  var password = $('#password').val();
  var conf_password = $('#confpassword').val();
  
  var erros = 0;
  if(password != "" && $('#password').val().length >= 3){
    $('#info_palavra').attr('class','ok');
    $('#info_palavra').empty();
  }else if(password == "" && $('#password').val().length < 3){
    $('#info_palavra').attr('class','erro3');  
    $('#info_palavra').html('<div NOWRAP >Por favor preencha uma palavra-chave</div>');
    erros = 1;
  }
  
  if(password != "" && $('#password').val().length >= 3 && password!=conf_password){
    $('#info_cpalavra').attr('class','erro3');
    $('#info_cpalavra').html('<div>As palavras-chave não coincidem.</div>');
    erros = 2;
  }else if(password != "" && $('#password').val().length >= 3 && password==conf_password){
    $('#info_cpalavra').attr('class','ok');
    $('#info_cpalavra').empty();
  }
  
  
  
 
  if(erros == 0){
    
    $('#valpass').attr('value',1);
    //$('#valpass').attr('value',1);
   $('#bloqueado1').attr('class','line62 _bloqueado'); 
    //$('#form_registo').attr('onsubmit','return submeteRegisto();');
    
  }else if(erros > 0){
    $('#valpass').attr('value',0);
    //$('#form_registo')[0].setAttribute('onsubmit',"return false;");
    $('#bloqueado1').attr('class','line62 _bloqueado'); 
  }
  
  if($('#valpass').attr('value') == 1 && $('#valuser').attr('value') == 1){
    $('#bloqueado1').attr('class','line62'); 
  }
 //alert($('#form_registo')[0].getAttribute('onsubmit'));
  
  
}


function submeteRegisto(){
      
    // alert($('#valpass').attr('value') + ">>"+ $('#valuser').attr('value'));
      
    
      
    if($('#valpass').attr('value') == 1 && $('#valuser').attr('value') == 1){
     
    
      
  
     $.ajax({
      url: 'ajax_registo.php',
      type: 'POST',
      data:$('#form_registo').serializeArray(),
      success: function(data) {
      	$('#registo1').html(data);
      	
        
        $('#step').attr('value',2);
      	//$('#form_registo').attr('onsubmit','return submeteRegisto2();');
      	
         $('#form_registo')[0].setAttribute('onsubmit',"return submeteRegisto2();");
      	 
      	
        if(jQuery('.rightselect #selv_dia.selectvalue').text() == ''){
          
          jQuery('#selv_dia.selectvalue').each(function(i){
             
              jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
          });
        }
        
        jQuery('.rightselect select').change(function(){
          jQuery('#selv_dia.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
        });
        
        if(jQuery('.rightselect #selv_mes.selectvalue').text() == ''){
          jQuery('#selv_mes.selectvalue').each(function(i){
              jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
          });
        }
        
        jQuery('.rightselect select').change(function(){
          jQuery('#selv_mes.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
        });
        
         if(jQuery('.rightselect #selv_ano.selectvalue').text() == ''){
          jQuery('#selv_ano.selectvalue').each(function(i){
              jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
          });
        }
        
        jQuery('.rightselect select').change(function(){
          jQuery('#selv_ano.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
        });
        
        jQuery(".radios_registo input").click(function(){
          var idRadio = jQuery(this).attr("id");
          if(idRadio == "nao") {
            jQuery(".rightinputs").fadeOut(100);
          } else if(jQuery(".rightinputs").css("display") == "none") {
            jQuery(".rightinputs").fadeIn(200);
          }
        });
      	 
        //$('#form_registo').attr('onsubmit','return submeteRegisto2();');  
      	//$('#form_registo').attr('onsubmit',function(){ jQuery('.registado').css('display', 'block');return false; } );
      	
      	return false;
      }
  });
   
  }else {
    $('#form_registo')[0].setAttribute('onsubmit',"return submeteRegisto();");
    return false;
  }
  
}

function submeteRegisto2(){
    
    
    var nome = $('#nome').val();
    var email = $('#email').val();
    var sim = $('#sim').attr('checked');
    var numero = $('#numero').val();
    
    var dia = $('#selv_dia').val();
    var d = $('#dia').val();
    var mes = $('#selv_mes').val();
    var m = $('#mes').val();
    var ano = $('#selv_ano').val();
    var a = $('#ano').val();
    
    
    if(nome == ""){
      alert("Por favor preencha o seu nome antes de prosseguir");
      $('#nome').focus();
      return false;
    }
    if(email == "" ){
      alert("Por favor preencha um e-mail válido antes de prosseguir");
      $('#email').focus();
      return false;
    }
     if(email == "" || verify_email(email) == false ){
      alert("Por favor preencha um e-mail válido antes de prosseguir");
      $('#email').focus();
      return false;
    }
    
     if((dia == "" && d =="") || (mes == "" && m =="") || (ano == "" && a =="")){
      alert("Por favor preencha uma de nascimento válida antes de prosseguir");
      
      return false;
    }
    
    
    
    if(sim == true && numero == "" ){
      alert("Por favor preencha o seu número de assinatura antes de prosseguir");
      $('#numero').focus();
      return false;
    }
    
    
     $.ajax({
      url: 'ajax_registo.php',
      type: 'POST',
      async:true,
      data:$('#form_registo').serializeArray(),
      success: function(data) {
      
         var altura1 = jQuery(".infAdicional").height();
        jQuery(".informacaoAdicional").css("border-top", "2px solid #FFF");
        jQuery(".informacaoAdicional").animate({
          "height" : altura1 + "px",
          "padding-top" : "14px",
          "padding-bottom" : "10px"
        },500, function(){
            
            
        if(jQuery('.rightselect #div_sector.selectvalue').text() == ''){
          
          jQuery('#div_sector.selectvalue').each(function(i){
             
              jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
          });
        }
        
        jQuery('.rightselect select').change(function(){
          jQuery('#div_sector.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
        }); 
          
          
          //jQuery("#bloqueado1").show();
          jQuery(".line62").attr("class", "line64");
          $('#step').attr('value',3);
          $('#autorizo').attr('disabled',false);
           $('#form_registo')[0].onsubmit = function() { return submeteRegisto3() }
          
         return false;
         
          
        });
        
        
      }
  });
  return false;
}

function submeteRegisto3(){
    var sim = $('#sim').attr('checked');
    var numero = $('#numero').val();
    var autorizo = $('#autorizo').attr('checked');
    var telefone = $('#tel').val();
    
    //alert(autorizo);
    
    if(isNaN(telefone)){
      //$('#form_registo')[0].setAttribute('onsubmit',"alert('Por favor confirme que autoriza os termos de utilização antes de prosseguir.');return false;");
      alert('Por favor preencha um número de telefone válido antes de prosseguir.');
      return false;
    }
    
    if(autorizo == false){
      //$('#form_registo')[0].setAttribute('onsubmit',"alert('Por favor confirme que autoriza os termos de utilização antes de prosseguir.');return false;");
      alert('Por favor confirme que autoriza os termos de utilização antes de prosseguir.');
      return false;
    }
    
    
    if(sim == true && numero == "" ){
      alert("Por favor preencha o seu número de assinatura antes de prosseguir");
      $('#numero').focus();
      return false;
    }
    
    $('#bloqueado1').hide();
    $('#div_botao').css("background-image","url(sysimages/ajax-loader.gif)");
    $('#div_botao').css("width","16px");
    $('#div_botao').css("height","16px");
    $('#div_botao').css("float","right");
    $('#div_botao').css("margin","5px 20px 0px 0px");
    $.ajax({
        url: 'ajax_registo.php',
        type: 'POST',
        data:$('#form_registo').serializeArray(),
        success: function(data) {
        	$('#containerRegisto').html(data);
        	//$('#form_registo').attr('onsubmit','return submeteRegisto2();');  
        	//$('#form_registo').attr('onsubmit',function(){ jQuery('.registado').css('display', 'block');return false; } );
        }
    });
  
  
  return false;
}


function verify_number(field){
  if (isNaN(field.value)) 
  {
    alert("Só pode introduzir caracteres numéricos.");
    field.value='';
    field.focus();
  }
}

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 validaAlterar(form){
     /*if(form.autorizo.checked == false){ 
        alert('Por favor confirme que aceita os Termos de utilização.');
        return false;
      }else {
        return verify_form_data(form,'THISFORMALTERAR');
        return false;
      }*/
      
      return verify_form_data(form,'THISFORMALTERAR');
}
function validaAssinante(val){
  $.ajax({
        url: 'ajax_assinante.php',
        type: 'POST',
        data:{tipo:val},
        success: function(data) {
        	
        	
        }
  });
  
}


function verificaFiltro(form){
      
     
    
    
    
    
    var m1 = document.getElementById('m1').value;
    var a1 = document.getElementById('a1').value;
    
    var m2 = document.getElementById('m2').value;
    var a2 = document.getElementById('a2').value;
    
  
    
    var myDate1=new Date();
    myDate1.setFullYear(a1);
    myDate1.setMonth(m1-1);
    myDate1.setDate(1);
    
    
    var myDate2=new Date();
    myDate2.setFullYear(a2);
    myDate2.setMonth(m2-1);
    myDate2.setDate(1);
    
    
    
    
    var dia = 1000*60*60*24; 
    var diferenca = (myDate2.getTime() - myDate1.getTime())/dia;
    
    
    //alert(diferenca);
    if (myDate2<myDate1){
      alert("Data inicial não deverá será ser superior á data final");
      return false;
    }else {
        return verify_form_data(form,'THISFORMFLT');
        return false;
      }
      
      
}

