// JavaScript Document

function popshow(popup,img){
  _obj=document.getElementById('popup');
  _img=document.getElementById('img');
  if (_obj.style.display=='block')
  {
  _obj.style.display='none';
  _img.className = "img_menu";
  }
else
  {
  _obj.style.display='block';
  _img.className = "img_menu3";
  }
}

function ver_pesq(ps){
var _ps = document.getElementById(ps);
if(_ps.value.length>=3 && _ps.value!="Pesquisar"){
return true;
}else{
alert("Insira no minimo 3 caracteres de pesquisa");
return false;
}

}

function Psq(ps){
  _ps=document.getElementById('ps');
  if (_ps.value=='')
  {
  _ps.value='Pesquisar';
  }
else
  {
  _ps.style.display='block';
  }
}

function Psq2(ps){
  _ps=document.getElementById(ps);
  if (_ps.value=='Pesquisar')
  {
  _ps.value='';
  }
else
  {
  _ps.style.display='block';
  }
}

function Psq_(ps_){
  _ps=document.getElementById(ps_);
  if (_ps.value=='')
  {
  _ps.value='Pesquisar';
  }
else
  {
  _ps.style.display='block';
  }
}

function Psq2_(ps_){
  _ps=document.getElementById('ps_');
  if (_ps.value=='Pesquisar')
  {
  _ps.value='';
  }
else
  {
  _ps.style.display='block';
  }
}

function RenderTTF()
{
  DATAFUNCS.RenderFonts('tits_home',{
   fontSize         : '11.25',
   backgroundColor  : '6B90AD',
   color            : 'FFFFFF',
   fontFile         : 'fonts/helt_bold.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tits_home_m',{
   fontSize         : '22.5',
   backgroundColor  : '6B90AD',
   color            : '1b3344',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h1',{
   fontSize         : '17.25',
   backgroundColor  : 'FFFFFF',
   color            : 'cc99cc',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h1G',{
   fontSize         : '22.5',
   backgroundColor  : 'FFFFFF',
   color            : 'cc99cc',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h1bloco',{
   fontSize         : '15.25',
   backgroundColor  : 'FFFFFF',
   color            : 'cc99cc',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_h2bloco',{
   fontSize         : '14',
   backgroundColor  : 'FFFFFF',
   color            : '333333',
   fontFile         : 'fonts/MUSEO500.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('opor',{
   fontSize         : '13',
   backgroundColor  : 'FFFFFF',
   color            : '333333',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('form',{
   fontSize         : '11.25',
   backgroundColor  : 'FFFFFF',
   color            : '333333',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h2G',{
   fontSize         : '12',
   backgroundColor  : 'FFFFFF',
   color            : '333333',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h6',{
   fontSize         : '22.5',
   backgroundColor  : 'D4DCE0',
   color            : '182f40',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tit_h7',{
   fontSize         : '30',
   backgroundColor  : 'D4DCE0',
   color            : '1b3344',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('pcidades',{
   fontSize         : '6',
   backgroundColor  : 'FFFFFF',
   color            : '333333',
   fontFile         : 'fonts/kroe0655.ttf',
   transparent      : '1'
  });
  
  
  
}

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');
        
        
  			if(_tag == 'TEXTAREA' || _type == 'text' || _type == 'password'){
  				if ((e.value == '') || (e.value == 'Preenchimento obrigatório.')){
            var _varid = e.getAttribute('id');
            e.className  = 'obrigaclick required';
  					//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.className  = 'obrigaclick required';
      					//e.value = 'Preenchimento obrigatório.';

      					//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.className  = 'obrigaclicks required';
      			
      					
              }
  				  
            } else {
    				  var _varid = e.getAttribute('id');
    				  e.className  = 'obrigaclicks required';
    				}
  				}
  				
  				if(_emai == 1){
  					if(verify_email(e.value) == false){
  						var _varid = e.getAttribute('id');
              e.className  = 'obrigaclick required';
    					//e.value = 'Email inválido.';
              
  						//EVT.addListener(e, "focus", function(){ e.value = ''; });
  						
  						if(errors == false) errors = true;
  						
  					} else {
  					  var _varid = e.getAttribute('id');
      				e.className  = 'obrigaclicks required';
  					}
  				}
  			} else if(_fich == 1){
  			  if(e.value == ''){
            var _varid = e.getAttribute('id');
            e.className  = 'obrigaclick required';
  					//e.value = 'Preenchimento obrigatório.';
  					//EVT.addListener(e, "focus", function(){ e.value = ''; });
  					if(errors == false) errors = true;
          } else {
  					var _varid = e.getAttribute('id');
  				  e.className  = 'obrigaclicks required';
  				}
  			} else if(_sel == 1) {
          if ((e.value=="") || (e.value==0)){
            var _varid = e.getAttribute('id');
            e.className  = 'obrigaclick required';
						//EVT.addListener(e, "focus", function(){ e.value = ''; });
						if(errors == false) errors = true;
          } else {
            var _varid = e.getAttribute('id');
  				  e.className  = 'obrigaclicks required';
          }
  			} 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){
	 if(document.getElementById('obriga')){
	   document.getElementById('obriga').src='sysimages/obrigaclick.jpg';
   }
   alert("Verifique os campos obrigatório");
		return false;
	} else {
	 if(document.getElementById('obriga')){
	   document.getElementById('obriga').src='sysimages/obriga.jpg';
   }
		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();
  }
}       
 
function openSel(){
    that = document.getElementById('selTopo');
    
    if(that.className=='selectbgSel'){
      that.className='selectbg';
      document.getElementById('opcoes').style.display='none';
    }else if(that.className=='selectbg'){
      that.className='selectbgSel';
      document.getElementById('opcoes').style.display='block';
    }
  
}
      
