/* 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 #D20000';
  					e.style.color  = '#D20000';
  					//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 #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';
    					//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 #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 */

var _xpannel;
function ModalPopUp(phpfile, _title, _mensagem, _width, xclose)
{
  _xpannel = new YAHOO.widget.Panel("xpannel", 
      {  
      width:_width, 
      fixedcenter:true, 
      close:false, 
      draggable:true, 
      zindex:99999, 
      modal:true, 
      visible:false
      } );
    
  var abrejanela = {
  		success: function(oResponse) {
  			var oResults = oResponse.responseText;
        _xpannel.setHeader(_title);
        _xpannel.setBody(oResults);
        _xpannel.render(document.body);
        _xpannel.show();
  		},
  		
  		failure: function(oResponse) {
  		  alert('(1) Erro ao carregar informação. Por favor volte a tentar!');
  		},
  		
  		timeout: 20000
  };
  
  
  YAHOO.util.Connect.asyncRequest('GET', phpfile, abrejanela);
  
}

function ModalIframePopUp(phpfile, _title, _mensagem, _height, _width, xclose)
{
  _xpannel = new YAHOO.widget.Panel("xpannel", 
      {
      width:_width, 
      fixedcenter:true, 
      close:false, 
      draggable:true, 
      zindex:99999, 
      modal:true, 
      visible:false
      } );

    var HTML_BODY = '<iframe src="'+ phpfile +'" style="width:100%;height:' + _height + ';background-color:transparent;margin: 0px !important; padding: 0px !important;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%" hspace="0"></iframe>';
    //_xpannel.setHeader(_title);
    _xpannel.setBody(HTML_BODY);
    _xpannel.render(document.body);
    _xpannel.show();
}

function showSub(id)
{
  document.getElementById('eqp'+id).onmouseover="";
  document.getElementById('eqp'+id).onmouseout="";
  document.getElementById('eqp'+id).className='equipaHover';
  document.getElementById('cargo'+id).src='sysimages/transparente.png';
  document.getElementById('descrcargo'+id).style.display = "block";
}

var totalE;
function showSubTeste(id)
{ 

  totalE=parseInt(totalE);
  //alert(totalE);
  for(j=1;j<=totalE;j++){
    //alert(j);
   
    obj1=document.getElementById('cargo'+j);
    obj2=document.getElementById('eqp'+j);
    obj3=document.getElementById('descrcargo'+j);
    
    if(obj1!=null){
      document.getElementById('cargo'+j).src='sysimages/backequipa2.jpg';
    }
    if(obj2!=null){
       document.getElementById('eqp'+j).className='equipa';
       document.getElementById('eqp'+j).onmouseover= function() { var nid = document.getElementById('eqp'+j).id.substr(3); document.getElementById('eqp'+j).className='equipaHover';document.getElementById('cargo'+nid).src='sysimages/transparente.png';};
       document.getElementById('eqp'+j).onmouseout= function() { var nid = parseInt(document.getElementById('eqp'+j).id.substr(3));document.getElementById('eqp'+j).className='equipa';document.getElementById('cargo'+nid).src='sysimages/backequipa2.jpg';};
    }
    if(obj3!=null){
       document.getElementById('descrcargo'+j).style.visibility = "hidden";
    }
    
    obj4=document.getElementById('cargo'+id);
    obj5=document.getElementById('eqp'+id);
    obj6=document.getElementById('descrcargo'+id);
    
    if(obj4!=null){
       document.getElementById('descrcargo'+id).style.visibility = "visible";
    }
    if(obj5!=null){
      document.getElementById('eqp'+id).onmouseover="";
      document.getElementById('eqp'+id).onmouseout="";
      document.getElementById('eqp'+id).className='equipaHover';
    }
    if(obj6!=null){
      document.getElementById('cargo'+id).src='sysimages/transparente.png';
    }
    
    
  }
  
  
  
}

function closeSub()
{ 

  totalE=parseInt(totalE);
  //alert(totalE);
  for(j=1;j<=totalE;j++){
    //alert(j);
   
    obj1=document.getElementById('cargo'+j);
    obj2=document.getElementById('eqp'+j);
    obj3=document.getElementById('descrcargo'+j);
    
    if(obj1!=null){
      document.getElementById('cargo'+j).src='sysimages/backequipa2.jpg';
    }
    if(obj2!=null){
       document.getElementById('eqp'+j).className='equipa';
       document.getElementById('eqp'+j).onmouseover= function() { var nid = document.getElementById('eqp'+j).id.substr(3); document.getElementById('eqp'+j).className='equipaHover';document.getElementById('cargo'+nid).src='sysimages/transparente.png';};
       document.getElementById('eqp'+j).onmouseout= function() { var nid = parseInt(document.getElementById('eqp'+j).id.substr(3));document.getElementById('eqp'+j).className='equipa';document.getElementById('cargo'+nid).src='sysimages/backequipa2.jpg';};
    }
    if(obj3!=null){
       document.getElementById('descrcargo'+j).style.visibility = "hidden";
    }
  }
  
  
  
}

function montavideo(lg,id) {
  // <![CDATA[
  if(debug==1){
  for(i=1;i<subpF.length;i++){
      document.getElementById("menu"+subpP[i]).style.display='none';
      
    for(j=1;j<subpF[i].length;j++){
      var obj1=document.getElementById("flash3_Mov"+subpF[i][j]);
      var obj2=document.getElementById("video"+subpF[i][j]);
      if(obj1!=null){
        document.getElementById("flash3_Mov"+subpF[i][j]).style.display='none';
      }
      if(obj2!=null){
        document.getElementById("video"+subpF[i][j]).style.display='none';
      }
    }
  }
   document.getElementById("flash3_Mov"+id).style.display='';
   document.getElementById("video"+id).style.display='block';
  }
  
  
	var fo2 = new FlashObject("flash/video1.swf", "movie"+id, "620", "310", "9", "000000");
	//fo2.addParam("wmode", "transparent");
	fo2.addParam("allowFullScreen", "true");
	fo2.addVariable("servidor", "http://www.vitrimedia.com");
  fo2.addVariable("videoID", lg+"_"+id);
  fo2.addVariable("typePlay", true);
	fo2.write("flash3_Mov"+id);
	// ]]>
}

function desmontavideo(id) {
  document.getElementById('flash3_Mov'+id).innerHTML = '';
}

function RenderTTF()
{
  DATAFUNCS.RenderFonts('nome_eqp',{
   fontSize         : '18.75',
   backgroundColor  : 'F8F8F8',
   color            : '666666',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_pag',{
   fontSize         : '26.25',
   backgroundColor  : 'F8F8F8',
   color            : '000000',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_H1',{
   fontSize         : '26.25',
   backgroundColor  : 'F8F8F8',
   color            : '000000',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_H2',{
   fontSize         : '18.75',
   backgroundColor  : 'F8F8F8',
   color            : '666666',
   fontFile         : 'fonts/MUSEO300.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_home',{
   fontSize         : '15',
   backgroundColor  : 'F8F8F8',
   color            : '000000',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('tit_onde',{
   fontSize         : '18.75',
   backgroundColor  : 'F8F8F8',
   color            : '666666',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
  
  DATAFUNCS.RenderFonts('onde_down',{
   fontSize         : '11.25',
   backgroundColor  : 'F8F8F8',
   color            : '333333',
   fontFile         : 'fonts/MUSEO700.TTF',
   transparent      : '1'
  });
}

