Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

// SUBMENU
function showSub(id)
{
  document.getElementById(id).style.display = "block";
}

function hideSub(id){
  document.getElementById(id).style.display = "none";
}

String.prototype.trim = function()
{
  return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function popup(URL, _w, _h) {
				
		day = new Date();
		id = day.getTime();		
	     
	  	var _top =  parseInt((screen.width/2) - (_w/2));
	  	var _left = 200; 		  		
		  
		  if(scroll) scroll = "1"; else scroll = "0";
		  
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=" + scroll + ",location=0,statusbar=0,menubar=0,resizable=0,width=" + _w + ",height=" + _h + ",left = " + _top + ",top = " + _left + "');");
	}

function change_box(r,n,tr,tn) {
  if (r.style.display=='none') {
    n.style.display = 'none';
    tn.className = 'newsletter';
    tn.onmouseover="this.className='newsletterhover';"; 
    tn.onmouseout="this.className='newsletter';";
    
    r.style.display = 'block';
    tr.className = 'online';
    tr.onmouseover="this.className='onlinehover';"; 
    tr.onmouseout="this.className='online';";
  }
}

function RenderTTF()
{
  DATAFUNCS.RenderFonts('titH1',{
   fontSize         : '15',
   backgroundColor  : 'FFFFFF',
   color            : '3D3938',
   fontFile         : 'fonts/MyriadWebPro.ttf',
   transparent      : '1'
  });
  DATAFUNCS.RenderFonts('tprod',{
   fontSize         : '12',
   backgroundColor  : 'FFFFFF',
   color            : '3D3938',
   fontFile         : 'fonts/myriadMM700600.TTF',
   transparent      : '1'
  });
}

function familia(idp,id) {
  /*
  document.getElementById("ifr_lstprt").style.height='0px';
	var fam = document.getElementById("familia").value;
	document.getElementById("ifr_lstprt").src = 'arq_coleccoes.php?id='+fam;
	getRetry();
	*/
	var fam = document.getElementById("familia").value;
	location.href = 'index.php?id='+idp+'&col='+fam;
}

function familia_bricoideia(idp,id) {
  /*
  document.getElementById("ifr_lstprt").style.height='0px';
	var fam = document.getElementById("familia").value;
	document.getElementById("ifr_lstprt").src = 'bricoideias_archieve.php?id='+fam;
	getRetry();
  */
  var fam = document.getElementById("familia").value;
	location.href = 'index.php?id='+idp+'&brci='+fam;
}

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) {
    docHt = doc.height;
  } else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
  
function getReSize() {
  var iframeWin = window.frames['ifr_lstprt'];
  var iframeEl = window.document.getElementById? window.document.getElementById('ifr_lstprt'): document.all? document.all['ifr_lstprt']: null;
  if ( iframeEl && iframeWin ) {
    var docHt = getDocHeight(iframeWin.document);
    if (docHt != iframeEl.style.height) iframeEl.style.height = docHt + 'px';
    //alert(docHt)
  } else { // FireFox
    var docHt = window.document.getElementById('ifrm').contentDocument.height;
    window.document.getElementById('ifrm').style.height = docHt + 'px';
  }
}

function getRetry() {
  getReSize();
  setTimeout('getRetry()',500);
}

function show_marca(dep,id) {
	location.href = 'index.php?id='+id+'&dep='+dep;
}

function getXmlHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function mudaDep(dep) {
  var url ="gest/_change_dep.php"; 	
  var post_data="dep="+dep;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  if (document.getElementById('desc_dep'))
          document.getElementById('desc_dep').innerHTML = rs[2];

        document.getElementById('bloco_ima').src="show_bloco.php?bli="+dep;
      }
		}
	}
 	cmsajaxhttp.send(null);
}

var teste;

function add_carrinho(mycodigo,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			/*teste = rs[0];*/
			/*alert(rs[0]);*/
			if (rs[1]=="OK"){
			  alert("Produto adicionado ao carrinho.")
			  if(document.getElementById('items_car')){
          document.getElementById('items_car').innerHTML = rs[2];
        }
        if(document.getElementById('tot_car')) {
          document.getElementById('tot_car').innerHTML = rs[3]+" €";
        }
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_last(mycodigo,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var post_data=post_data+"&pm=1";
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			/*teste = rs[0];*/
			/*alert(rs[0]);*/
			if (rs[1]=="OK"){
			  alert("Produto adicionado ao carrinho.")
        if(document.getElementById('items_car')) {
        document.getElementById('items_car').innerHTML = rs[2];
        }
        if(document.getElementById('tot_car')) {
        document.getElementById('tot_car').innerHTML = rs[3]+" €";
        }
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho2(mycodigo,myref,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  //alert("Produtos adicionados ao carrinho.")
        document.getElementById('items_car').innerHTML = rs[2];
        document.getElementById('tot_car').innerHTML = rs[3]+" €";
      } else {
      	alert('O produto com a ref. '+myref+' não tem stock suficiente para adicioná-lo.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_novo(mycodigo,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add_novo.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			/*teste = rs[0];*/
			/*alert(rs[0]);*/
			if (rs[1]=="OK"){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car').innerHTML = rs[2];
        document.getElementById('tot_car').innerHTML = rs[3]+" €";
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_novo_last(mycodigo,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add_novo.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var post_data=post_data+"&pm=1";
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			/*teste = rs[0];*/
			/*alert(rs[0]);*/
			if (rs[1]=="OK"){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car').innerHTML = rs[2];
        document.getElementById('tot_car').innerHTML = rs[3]+" €";
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_nl(mycodigo)
{
  var codigo=mycodigo;
  var qnt=1;
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car2').innerHTML = rs[2];
        document.getElementById('tot_car2').innerHTML = rs[3]+" €";
        if (document.getElementById('freg1').style.display == 'block'){
          document.getElementById('freg1').style.display = 'none';
          document.getElementById('freg2').style.display = 'block';
        }
        location.href='index.php?id=227';
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_nl_last(mycodigo)
{
  var codigo=mycodigo;
  var qnt=1;
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var post_data=post_data+"&pm=1";
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car2').innerHTML = rs[2];
        document.getElementById('tot_car2').innerHTML = rs[3]+" €";
        if (document.getElementById('freg1').style.display == 'block'){
          document.getElementById('freg1').style.display = 'none';
          document.getElementById('freg2').style.display = 'block';
        }
        location.href='index.php?id=227';
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_nl2(mycodigo,q)
{
  var codigo=mycodigo;
  if (q > 0){
    var qnt=q;
  } else {
    var qnt=1;
  }
  var url ="gest/add.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  //alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car2').innerHTML = rs[2];
        document.getElementById('tot_car2').innerHTML = rs[3]+" €";
        if (document.getElementById('freg1').style.display == 'block'){
          document.getElementById('freg1').style.display = 'none';
          document.getElementById('freg2').style.display = 'block';
        }
        location.href='index.php?id=227';
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_nl_novo(mycodigo)
{
  var codigo=mycodigo;
  var qnt=1;
  var url ="gest/add_novo.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car2').innerHTML = rs[2];
        document.getElementById('tot_car2').innerHTML = rs[3]+" €";
        if (document.getElementById('freg1').style.display == 'block'){
          document.getElementById('freg1').style.display = 'none';
          document.getElementById('freg2').style.display = 'block';
        }
        location.href='index.php?id=227';
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_carrinho_nl_novo_last(mycodigo)
{
  var codigo=mycodigo;
  var qnt=1;
  var url ="gest/add_novo.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var post_data=post_data+"&pm=1";
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
			  alert("Produto adicionado ao carrinho.")
        document.getElementById('items_car2').innerHTML = rs[2];
        document.getElementById('tot_car2').innerHTML = rs[3]+" €";
        if (document.getElementById('freg1').style.display == 'block'){
          document.getElementById('freg1').style.display = 'none';
          document.getElementById('freg2').style.display = 'block';
        }
        location.href='index.php?id=227';
      } else {
      	alert('O produto que está a tentar adicionar não tem stock suficiente para o fazer.');
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function add_wish(mycodigo)
{
  var codigo=mycodigo;
  var qnt=1;
  var url ="gest/add_wish.php"; 	
  var post_data="codigo="+codigo;
  var post_data=post_data+"&qnt="+qnt;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			if (resultado=='OK'){
			  alert("Produto adicionado à sua wishlist.")
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function getTProj(dep){
  var url ="gest/gettproj.php"; 	
  var post_data="dep="+dep;
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			document.getElementById('seltipoproj').innerHTML=resultado;
		}
	}
 	cmsajaxhttp.send(null);
}

function show_dir(loj){
  var or = document.getElementById('partida').value;
  mywindow = window.open ("direccoes.php?id="+loj+"&or="+or+"","mywindow","location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=810,height=600");
  mywindow.moveTo(0,0);
}

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_log2(txtu,txtp){
  var u = document.getElementById('LC1').value.trim();
  var p = document.getElementById('LC2').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 show_frm(tpu){
  if (tpu == 1){
    //USER Individual
    document.getElementById('tipoform').value=1;
    document.getElementById('dp_ind').style.display='block';
    document.getElementById('dp_emp').style.display='none';
    document.getElementById('poss_ind1').style.display='block';
    document.getElementById('poss_ind2').style.display='block';
    document.getElementById('poss_ind3').style.display='block';
    document.getElementById('poss_ind4').style.display='block';
    document.getElementById('poss_ind5').style.display='block';
    document.getElementById('poss_ind6').style.display='block';
	document.getElementById('newsopt').style.display='block';
  } else if(tpu == 2){
    //USER Empresa
    document.getElementById('tipoform').value=2;
    document.getElementById('dp_ind').style.display='none';
    document.getElementById('dp_emp').style.display='block';
    document.getElementById('poss_ind1').style.display='none';
    document.getElementById('poss_ind2').style.display='none';
    document.getElementById('poss_ind3').style.display='none';
    document.getElementById('poss_ind4').style.display='none';
    document.getElementById('poss_ind5').style.display='none';
    document.getElementById('poss_ind6').style.display='none';
	document.getElementById('newsopt').style.display='none';
  }
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

var DOM = YAHOO.util.Dom;
var EVT = YAHOO.util.Event;

function validate_form(_obj){
	
  var errors = false;

	if (document.getElementById('same_data_reg') && document.getElementById('same_data_reg').value == 1) {
		return true;
	};

  if ((document.getElementById('tipoform').value==1) || (document.getElementById('tipoform').value==2)){
	 var aux = document.getElementById('tipoform').value;
	 if (aux==1) {
    var arr_aux = ['caixa14','caixa15','caixa16','caixa17','caixa18','caixa19','caixa20','caixa21','caixa31','caixa32_1','caixa32_2','caixa32_3'];
   } else {
    var arr_aux = ['caixa1','caixa2','caixa3','caixa4','caixa5','caixa6','caixa7','caixa8','caixa9_1','caixa9_2','caixa9_3','caixa10','caixa11','caixa12','caixa13','caixa29','caixa30_1','caixa30_2','caixa30_3'];
   }
	} else {
    var aux = 0;
  }

	DOM.getElementsByClassName(
		'required',
		null,
		_obj,
		function(e){
			/*
      se aux==1
        ignora id's -> caixa 14,15,16,17,18,19,20,21
      se aux==2
        ignora id's -> caixa 1,2,3,4,5,6,7,8,9_1,9_2,9_3,10,11,12,13
      */
      
      if (aux>0) {
        var _id = e.getAttribute('id');
        if (arr_aux.in_array(_id)){
          var _varerro = e.getAttribute('nomeerro');
          document.getElementById(_varerro).style.display='none';
        } else {
    			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(trim(e.value,'') == ''){
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='block';
              
    					EVT.addListener(e, "focus", function(){ e.value = ''; });
    					
    					if(errors == false) errors = true;
    					
    				} else {
    				  var idinput =  e.getAttribute('id');
    				  if (idinput=='caixa24') {
    				    var pass1 = document.getElementById('caixa23').value;
    
    				    if (pass1 != e.value){
                  alert("As passwords introduzidas não são iguais.")
                  
                  var _varerro = e.getAttribute('nomeerro');
                  document.getElementById(_varerro).style.display='block';
                  
                  EVT.addListener(e, "focus", function(){ e.value = ''; });
    					    if(errors == false) errors = true;
                } else {
                  var _varerro = e.getAttribute('nomeerro');
                  document.getElementById(_varerro).style.display='none';
                }
    				  
              } else {
      				  var _varerro = e.getAttribute('nomeerro');
                document.getElementById(_varerro).style.display='none';
      				}
    				}
    				
    				if(_emai == 1){
    					if(verify_email(e.value) == false){
    						var _varerro = e.getAttribute('nomeerro');
                document.getElementById(_varerro).style.display='block';
                
    						EVT.addListener(e, "focus", function(){ e.value = ''; });
    						
    						if(errors == false) errors = true;
    						
    					} else {
    					 var _varerro = e.getAttribute('nomeerro');
               document.getElementById(_varerro).style.display='none';
    					}
    				}
    			} else if(_fich == 1){
    			  if(e.value == ''){
              e.style.border = '1px solid #FF0000';
    					e.style.color  = '#FF0000';
    					EVT.addListener(e, "focus", function(){ e.value = ''; });
    					if(errors == false) errors = true;
            } else {
    					e.style.border = '1px solid #6587A2';
    					e.style.color  = '#666666';
    				}
    			} else if(_sel == 1) {
            if ((e.value=="") || (e.value==0)){
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='block';
  						EVT.addListener(e, "focus", function(){ e.value = ''; });
  						if(errors == false) errors = true;
            } else {
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='none';
            }
    			} 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;
    				}
    			}
    		}
		  } else {
    			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 == ''){
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='block';
              
    					EVT.addListener(e, "focus", function(){ e.value = ''; });
    					
    					if(errors == false) errors = true;
    					
    				} else {
    				  var idinput =  e.getAttribute('id');
    				  if (idinput=='caixa24') {
    				    var pass1 = document.getElementById('caixa23').value;
    
    				    if (pass1 != e.value){
                  alert("As passwords introduzidas não são iguais.")
                  
                  var _varerro = e.getAttribute('nomeerro');
                  document.getElementById(_varerro).style.display='block';
                  
                  EVT.addListener(e, "focus", function(){ e.value = ''; });
    					    if(errors == false) errors = true;
                } else {
                  var _varerro = e.getAttribute('nomeerro');
                  document.getElementById(_varerro).style.display='none';
                }
    				  
              } else {
      				  var _varerro = e.getAttribute('nomeerro');
                document.getElementById(_varerro).style.display='none';
      				}
    				}
    				
    				if(_emai == 1){
    					if(verify_email(e.value) == false){
    						var _varerro = e.getAttribute('nomeerro');
                document.getElementById(_varerro).style.display='block';
                
    						EVT.addListener(e, "focus", function(){ e.value = ''; });
    						
    						if(errors == false) errors = true;
    						
    					} else {
    					 var _varerro = e.getAttribute('nomeerro');
               document.getElementById(_varerro).style.display='none';
    					}
    				}
    			} else if(_fich == 1){
    			  if(e.value == ''){
              e.style.border = '1px solid #FF0000';
    					e.style.color  = '#FF0000';
    					EVT.addListener(e, "focus", function(){ e.value = ''; });
    					if(errors == false) errors = true;
            } else {
    					e.style.border = '1px solid #6587A2';
    					e.style.color  = '#666666';
    				}
    			} else if(_sel == 1) {
            if ((e.value=="") || (e.value==0)){
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='block';
  						EVT.addListener(e, "focus", function(){ e.value = ''; });
  						if(errors == false) errors = true;
            } else {
              var _varerro = e.getAttribute('nomeerro');
              document.getElementById(_varerro).style.display='none';
            }
    			} 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 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_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 muda_faq(id) {
  if (document.getElementById('f1_'+id).style.display=='block') {
    document.getElementById('f1_'+id).style.display='none';
    document.getElementById('f2_'+id).style.display='block';
    var url ="gest/countfaq.php";
    var post_data="faq="+id;
    var cmsajaxhttp = getXmlHttpRequest();
   	cmsajaxhttp.open("GET", url+'?'+post_data, true);
    cmsajaxhttp.onreadystatechange = function(){
  		if (cmsajaxhttp.readyState==4){
  			var resultado = cmsajaxhttp.responseText;
  			if (resultado=='OK'){
        }
  		}
  	}
   	cmsajaxhttp.send(null);
    
  } else {
    document.getElementById('f1_'+id).style.display='block';
    document.getElementById('f2_'+id).style.display='none';
  }
}

function calc_zona() {
  var cp = document.getElementById('cp').value;
  
  var url ="gest/calczona.php";
  var post_data="cp="+cp;
  var cmsajaxhttp = getXmlHttpRequest();
 	cmsajaxhttp.open("GET", url+'?'+post_data, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			var rs = resultado.split('||');
			if (rs[1]=='OK'){
        document.getElementById('res_area').innerHTML = "AREA "+rs[2];
      } else {
        alert("Código Postal não existente ou inválido!")
        document.getElementById('res_area').innerHTML = '';
      }
		}
	}
 	cmsajaxhttp.send(null);
}

function changeSO()
{
  var url ="gest/changeSO.php"; 	
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			document.getElementById('detso').innerHTML = resultado;
      $("#detso").ready(function(){
        $("#so1").show("slow");
      });
		}
	}
 	cmsajaxhttp.send(null);
}

 


function changeBRF()
{
  var url ="gest/changeBRF.php"; 	
  var cmsajaxhttp = getXmlHttpRequest();
      	
 	cmsajaxhttp.open("GET", url, true);
  cmsajaxhttp.onreadystatechange = function(){
		if (cmsajaxhttp.readyState==4){
			var resultado = cmsajaxhttp.responseText;
			
			document.getElementById('detbrico').innerHTML = resultado;
		}
	}
 	cmsajaxhttp.send(null);
}

