/*window.onload = function () {
  
  var inc = document.getElementById("background");
  var _reg = YAHOO.util.Region.getRegion(document.body);
  //return true;
  //alert(_reg);
  
}*/

function hover(){
  var _pesq = document.getElementById('pesq');
  var _lupa = document.getElementById('lupa');
  _lupa.src= "sysimages/lupa_sel.jpg";
  _pesq.style.backgroundImage= "url('sysimages/bg_pesq_sel.jpg')";
  _pesq.style.border= "0px";
  _pesq.style.cursor= "pointer";
}
function out(){
  var _pesq = document.getElementById('pesq');
  var _lupa = document.getElementById('lupa');
  _lupa.src= "sysimages/lupa.jpg";
  _pesq.style.backgroundImage= "url('sysimages/bg_pesq.jpg')";
  _pesq.style.cursor= "default";
  _pesq.style.border= "0px";
}

function hover2(){
  var _pesq = document.getElementById('pesq2');
  var _lupa = document.getElementById('lupa2');
  _lupa.src= "sysimages/lupa_sel.jpg";
  _pesq.style.backgroundImage= "url('sysimages/bg_pesq_sel.jpg')";
  _pesq.style.border= "0px";
  _pesq.style.cursor= "pointer";
}
function out2(){
  var _pesq = document.getElementById('pesq2');
  var _lupa = document.getElementById('lupa2');
  _lupa.src= "sysimages/lupa.jpg";
  _pesq.style.backgroundImage= "url('sysimages/bg_pesq.jpg')";
  _pesq.style.cursor= "default";
  _pesq.style.border= "0px";
}

function mudaimg(src,div){

  var _div = document.getElementById(div);
  
  var divdoc = document.getElementsByTagName("div");
  
  for (var i=0; i < divdoc.length; i++){
   if (divdoc[i].className=="imgpeqvia_sel"){
    divdoc[i].className='imgpeqvia';
    }
  }
  
  _div.className='imgpeqvia_sel';
  
  document.getElementById('img_g').src = src;
  
}
function openfaq(resposta,faq){
  var _resposta = document.getElementById(resposta);
  var _faq = document.getElementById(faq);
  
  var divdoc = document.getElementsByTagName("div");
  
  for (var i=0; i < divdoc.length; i++){
   if (divdoc[i].className=="faq_open"){
    divdoc[i].className='faq';
    }
    
   if (divdoc[i].className=="resposta_faq"){
    divdoc[i].style.display='none';
    }
  }
  
  
  _resposta.style.display='block';
  _faq.className='faq_open';
  
  alturaResp = REG.getRegion(_resposta).height;
  doResize(alturaResp);
  
  /*
  
  
  if(alturaBody > alturaConteudo) {
    document.getElementById("content").style.height = alturaBody + alturaResp + "px";
  } else {
    document.getElementById("content").style.height = alturaConteudo + alturaResp + "px";
  }
  */
  
  
  
}
function dados(este,ids){
  var _ids = document.getElementById(ids);
  
  var divdoc = document.getElementsByTagName("div");
  
  for (var i=0; i < divdoc.length; i++){
   if (divdoc[i].className=="local"){
    divdoc[i].style.display='none';
    }
  }
  
  var diva = document.getElementsByTagName("a");
  
  for (var i=0; i < diva.length; i++){
   if (diva[i].className=="a_sel"){
    diva[i].className='';
    }
  }
  
  _ids.style.display = 'block';
  este.className = 'a_sel';
}
function muda_tabshome(mtab,tab){
  var _mtab = document.getElementById(mtab);
  var _tab = document.getElementById(tab);
  
  var divdoc = document.getElementsByTagName("div");
  
  for (var i=0; i < divdoc.length; i++){
   if (divdoc[i].className=="nada"){
    divdoc[i].style.display='none';
    }
    if (divdoc[i].className=="tabs_sel"){
    divdoc[i].className='tabs';
    }
  }
  

  _tab.style.display='block';
  _mtab.className='tabs_sel';
}

function RenderTTF()
{
  DATAFUNCS.RenderFonts('tit_h1',{
   fontSize         : '16.5',
   backgroundColor  : 'FEFEFE',
   color            : 'FF6600',
   fontFile         : 'fonts/MyriadWebPro.ttf',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h1_2',{
   fontSize         : '15',
   backgroundColor  : 'FEFEFE',
   color            : 'FF6600',
   fontFile         : 'fonts/MyriadWebPro.ttf',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h2',{
   fontSize         : '12.75',
   backgroundColor  : 'FEFEFE',
   color            : '666666',
   fontFile         : 'fonts/MyriadWebPro.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tab_tit',{
   fontSize         : '22.5',
   backgroundColor  : 'FFFFFF',
   color            : 'ff6600',
   fontFile         : 'fonts/helvetic.ttf',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('segundo_tit',{
   fontSize         : '15',
   backgroundColor  : '0D4F7F',
   color            : 'FFFFFF',
   fontFile         : 'fonts/helvetic.ttf',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('primeiro_tit',{
   fontSize         : '27',
   backgroundColor  : '0D4F7F',
   color            : 'FFFFFF',
   fontFile         : 'fonts/Helvetica_it.ttf',
   transparent      : '1'
  });
  
  
}    

var DOM = YAHOO.util.Dom;
var EVT = YAHOO.util.Event;

var errors = false;
function valida_pw(pw,elemento){
  if(pw!= elemento.value){
    elemento.style.border = '1px solid #FF0000';
    elemento.style.color = '#FF0000';
    if(errors == false) errors = true;
  }else{
    elemento.style.border = '1px solid #CCCCCC';
    elemento.style.color = '#999999';
    errors = false;
  }
}
function validate_form(_obj,valor){
  
  var errors = false;
  var maily = 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');

        
  			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 #FF0000';
  					e.style.color  = '#FF0000';
  					//e.value = 'Preenchimento obrigatório.';
            
  					//EVT.addListener(e, "focus", function(){ e.value = ''; });
  					
  					if(errors == false) errors = true;
  					
  				} else {
  				  var idinput =  e.getAttribute('id');
  				  if (idinput=='confpassword') {
  				    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 #FF0000';
      					e.style.color  = '#FF0000';
      					//e.value = 'Preenchimento obrigatório.';
      					
      					document.getElementById('password').style.border = '1px solid #FF0000';
      					document.getElementById('password').style.color  = '#FF0000';
      					//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 #CCCCCC';
      					e.style.color  = '#999999';
      					
      					document.getElementById('password').style.border = '1px solid #CCCCCC';
      					document.getElementById('password').style.color  = '#999999';
      					
              }
  				  
            } else {
             
    				  var _varid = e.getAttribute('id');
    				  e.style.border = '1px solid #CCCCCC';
    					e.style.color  = '#999999';
    				}
  				}
  				
  				if(_emai == 1){
  					if(verify_email(e.value) == false){
  						var _varid = e.getAttribute('id');
              e.style.border = '1px solid #FF0000';
    					e.style.color  = '#FF0000';
    					//e.value = 'Email inválido.';
              
  						//EVT.addListener(e, "focus", function(){ e.value = ''; });
  						
  						//if(errors == false) errors = true;
  						maily = true;
  					} else {
  					  var _varid = e.getAttribute('id');
      				e.style.border = '1px solid #CCCCCC';
    					e.style.color  = '#999999';
  					}
  				}
  			} else if(_fich == 1){
  			  if(e.value == ''){
            var _varid = e.getAttribute('id');
            e.style.border = '1px solid #FF0000';
  					e.style.color  = '#FF0000';
  					//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 #CCCCCC';
  					e.style.color  = '#999999';
  				}
  			} else if(_sel == 1) {
          if ((e.value=="") || (e.value==0)){
            var _varid = e.getAttribute('id');
            e.style.border = '1px solid #FF0000';
  					e.style.color  = '#FF0000';
						//EVT.addListener(e, "focus", function(){ e.value = ''; });
						if(errors == false) errors = true;
          } else {
            var _varid = e.getAttribute('id');
  				  e.style.border = '1px solid #CCCCCC';
  					e.style.color  = '#999999';
          }
  			} 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(maily == true && errors == false){
    alert("Email inválido.");
    return false;
  }else if(valor==1 && errors == true){
    alert("Insira os dados do login");
    return false;
  }else {
  	if(errors == true){
  	  alert("Verifique os campos obrigatórios");
  		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;
  }
}

function verify_number(field){
  if (isNaN(field.value)) 
  {
    alert("Só pode introduzir caracteres numéricos.");
    field.value='';
    field.focus();
  }
}
var contador = 0;
function ver_pesquisa(p){
  var _p = document.getElementById(p);

  if(contador == 1){
    if(_p.value.length<3){
      alert("Deve preencher a sua pesquisa com no minimo 3 letras");
      return false;
    } else {
      return true;
    } 
  }else if(contador == 0){
    if(_p.value.length<3 || _p.value=='Pesquisa' ){
      alert("Deve preencher a sua pesquisa com no minimo 3 letras");
      return false;
    } else {
      return true;
    } 
  
  }
}
function valida_news(){
  var _news = document.getElementById("news");
  
  if(valida_email(_news)== false || _news.value == ""){
  _news.style.backgroundImage='url(sysimages/bg_news_sel.jpg)';
  return false;
  }else{
  _news.style.backgroundImage='';
   return true
  }
  return false;
}
function valida_dados(pw){
  var _nova = document.getElementById('new_pw');
  var _pass = document.getElementById('password');
  var _confpass = document.getElementById('confpassword');
  var erros = false;
  
  if(_nova.value != pw ){
    _nova.style.border = '1px solid #FF0000';
  	_nova.style.color  = '#FF0000';
  	erros = true;
  	alert("Palavra-chave digitada não é igual a sua actual palavra-chave");
  }else{
   _nova.style.border = '1px solid #CCCCCC';
  	_nova.style.color  = '#999999';
  }
  
  if((_pass.value != _confpass.value) || (_pass.value == "") || (_confpass.value == "")){
    _pass.style.border = '1px solid #FF0000';
  	_pass.style.color  = '#FF0000';
  	_confpass.style.border = '1px solid #FF0000';
  	_confpass.style.color  = '#FF0000';
  	erros = true;
  	alert("Palavras-chaves não correspondem");
  }else{
   _pass.style.border = '1px solid #CCCCCC';
 	 _pass.style.color  = '#999999';
   _confpass.style.border = '1px solid #CCCCCC';
   _confpass.style.color  = '#999999';
 }
 
 if(erros == true){
  return false;
 }else{
  return true;
 }
}
