/* 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');
        
        
  			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=='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 #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 #9E9E9E';
      					e.style.color  = '#000000';
      					
      					document.getElementById('password').style.border = '1px solid #9E9E9E';
      					document.getElementById('password').style.color  = '#000000';
      					
              }
  				  
            } else {
    				  var _varid = e.getAttribute('id');
    				  e.style.border = '1px solid #9E9E9E';
    					e.style.color  = '#000000';
    				}
  				}
  				
  				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;
  						
  					} else {
  					  var _varid = e.getAttribute('id');
      				e.style.border = '1px solid #9E9E9E';
    					e.style.color  = '#000000';
  					}
  				}
  			} 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 #9E9E9E';
  					e.style.color  = '#000000';
  				}
  			} 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 #9E9E9E';
  					e.style.color  = '#000000';
          }
  			} 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;
	}
	
}
/* VALIDAÇÃO DE FORMULÁRIOS */

// SUBMENU
function showSub(id)
{
  document.getElementById(id).style.display = "block";
}

function hideSub(id){
  document.getElementById(id).style.display = "none";
}


function RenderTTF()
{
  DATAFUNCS.RenderFonts('tit1',{
   fontSize         : '18.75',
   backgroundColor  : '6B6B6B',
   color            : 'FFFFFF',
   fontFile         : 'fonts/NeoSansIntel-Medium.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('leftNSel',{
   fontSize         : '11.25',
   backgroundColor  : '7A7A7A',
   color            : 'FFFFFF',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('leftSel',{
   fontSize         : '11.25',
   backgroundColor  : 'E2E2E2',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit1_left',{
   fontSize         : '11.25',
   backgroundColor  : 'EAEAEA',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_notH',{
   fontSize         : '16.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('stit_notH',{
   fontSize         : '10.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_rub',{
   fontSize         : '17.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_rub2',{
   fontSize         : '11.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_H1',{
   fontSize         : '17.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_H2',{
   fontSize         : '11.25',
   backgroundColor  : 'FFFFFF',
   color            : '1C8226',
   fontFile         : 'fonts/NeoSansIntel.ttf',
   transparent      : '1'
  });
}

/* ADICIONAR AOS FAVORITOS */
function addFav(){
    var url        = "http://amerika/apporto";
    var title    = "Associação de Patinagem do Porto";
    
    //alert(navigator.appName);
  if(navigator.appName=='Netscape'){
    if (window.sidebar) {
      window.sidebar.addPanel(title, url,"");
    } else {
      alert("Pressione CTRL-D (Chrome) ou CTRL-T (Opera) para adicionar aos favoritos.");
      var mbm = document.createElement('a');
      mbm.setAttribute('rel','sidebar');
      mbm.setAttribute('href',url);
      mbm.setAttribute('title',title);
      mbm.click();
    }
  } else if(document.all){window.external.AddFavorite(url, title);}
}
/* ADICIONAR AOS FAVORITOS */

/* VALIDAÇÃO DE LOGIN ENEWSLETTER */
String.prototype.trim = function()
{
  return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function valida_log(txtu,txtp){
  var u = document.getElementById('L1').value.trim();
  var p = document.getElementById('L2').value.trim();
  if ((u!='') && (p!='') && (u!=txtu) && (p!=txtp)) {
    return 1;
  } else {
    return 0;
  }
}

function valida_newsl(txtu,txtp){
  var u = document.getElementById('N1').value.trim();
  var p = document.getElementById('N2').value.trim();
  
  if ((u!='') && (p!='') && (u!=txtu) && (p!=txtp) && (verify_email(document.getElementById('N2').value)==true)) {
    return 1;
  } else {
    return 0;
  }
}

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 LOGIN ENEWSLETTER */


function muda_ano(ano,id){
  if(ano>0){
    location.href = 'index.php?id='+id+'&ano='+ano;
  } else {
    location.href = 'index.php?id='+id;
  }
}
