function menuFunction (mostrar, esconder1, esconder2, esconder3)
      {
        oneVisible(esconder1,esconder2,esconder3);
        
        /*if (document.getElementById(esconder1).getStyle('display')!='none') 
        {
           //alert(document.getElementById(esconder1).getStyle('display'));
           Effect.toggle(esconder1, 'blind');
        }
        if (document.getElementById(esconder2).getStyle('display')!='none') 
        {
           Effect.toggle(esconder2, 'blind');
        }
        if (document.getElementById(esconder3).getStyle('display')!='none') 
        {
           Effect.toggle(esconder3, 'blind');
        }*/
      
        //document.getElementById('toggle_appear2').style.display='none'; 
        
        //Código do jQuery para mostrar os menus
        jQuery("#"+mostrar).slideToggle("slow", function() {
          oneVisible(esconder1,esconder2,esconder3);
        });
        //Código do Prototype para mostrar os menus 
        //Effect.toggle(mostrar, 'blind'); return false;
      }
      
      function notVisible(mostrar, esconder1, esconder2, esconder3)
      {
        document.getElementById(mostrar).style.display='none'; 
        document.getElementById(esconder1).style.display='none'; 
        document.getElementById(esconder2).style.display='none'; 
        document.getElementById(esconder3).style.display='none'; 
      }
      function oneVisible(esconder1, esconder2, esconder3)
      {
        document.getElementById(esconder1).style.display='none'; 
        document.getElementById(esconder2).style.display='none'; 
        document.getElementById(esconder3).style.display='none'; 
      }
      /*function lighten(id)
      {
        //document.getElementById(id).style.setProperty('background-color', 'rgb(200,200,200)', '')
        var el = document.getElementById(id); 
        if(el.currentStyle) { 
        // for msie 
          el.style.backgroundColor = "rgb(200,200,200)"; 
        } else { 
        // for real browsers ;) 
          el.style.setProperty("background-color", "rgb(200,200,200)", ""); 
        } 
      }
      function darken(id)
      {
        var el = document.getElementById(id); 
        if(el.currentStyle) { 
        // for msie 
          el.style.backgroundColor = "rgb(184,184,184)"; 
        } else { 
        // for real browsers ;) 
          el.style.setProperty("background-color", "rgb(184,184,184)", ""); 
        } 
      }*/
// JavaScript Document

/********************************************************************
  Drop down menus
********************************************************************/
var n;
var ie;

if (document.layers) 
{
	visible = 'show';
	hidden = 'hide';n=1;ie=0;
} 
else 
  if (document.all) 
  {
    visible = 'visible';
    hidden = 'hidden';n=0;ie=1;
  }
  else 
    if (document.getElementById && !document.all) 
    {
      visible = 'visible';
      hidden = 'hidden';n=0;ie=1;
    }

var ver = parseFloat (navigator.appVersion);
if ((navigator.appName.indexOf ("Netscape") == 0) && (ver >= 4))
{
} 
else
  if ((navigator.appName.indexOf ("Mozilla") == 0) && (ver >= 5))
  {
  }
  else
    if ((navigator.appName.indexOf ("Microsoft") == 0) && (ver >= 4))
    {
    }
    else
      if ((navigator.appName.indexOf ("Opera") == 0) && (ver >= 8))
      {
      }
      else
      {
        location="old_browser.html";
      }
    
function showDivs (divName,divNumber)
{
	var divsUsed = 18;    // this is the number of divs we have in the document for each element(topmenu, submenu, contentArea, contentImage)
	if (navigator.appName.indexOf ("Microsoft") == 0 || navigator.appName.indexOf ("Netscape") == 0 || navigator.appName.indexOf ("Opera") == 0)
  {
		if (parseInt (navigator.appVersion) >= 4)
    {
			var cnt = 0;
			for (cnt = 1; cnt <= divsUsed; cnt++)
      {
				var divCheck = divName + cnt;
				var divShow = divName + divNumber;
				if (ie)
        {
					if (divCheck == divShow) 
						//document.all(divShow).style.visibility = visible;
						document.getElementById(divShow).style.visibility = visible;
					else 
						//document.all(divCheck).style.visibility = hidden;
						document.getElementById(divCheck).style.visibility = hidden;
				}
				if (n)
        {
					if (divCheck == divShow) 
						document.layers[divShow].visibility = visible;
					else 
						document.layers[divCheck].visibility = hidden;
				}					
			}
		}
	}
}

function hideDivs (divName,divNumber)
{
	var divsUsed = 18;    // this is the number of divs we have in the document for each element(topmenu, submenu, contentArea, contentImage)
	if (navigator.appName.indexOf ("Microsoft") == 0 || navigator.appName.indexOf ("Netscape") == 0 || navigator.appName.indexOf ("Opera") == 0)
  {
		if (parseInt (navigator.appVersion) >= 4)
    {
			var cnt = 0;
			for (cnt = 1; cnt <= divsUsed; cnt++)
      {
				var divCheck = divName + cnt;
				var divShow = divName + divNumber;
				if (ie)
        {
					if (divCheck == divShow) 
						//document.all(divShow).style.visibility = hidden;
						document.getElementById(divShow).style.visibility = hidden;
				}
				if (n)
        {
					if (divCheck == divShow) 
						document.layers[divShow].visibility = hidden;
				}					
			}
		}
	}
}

/********************************************************************
  End of Drop Down Menus
********************************************************************/

/*** Shows Newsletter Cancelling Div ***/
function CancelarNewsletter(eliminar)
{
  Effect.toggle(eliminar, 'blind');
}
/*************************************/
contador=0;
maxi = 2;
function CheckComparacao(check) 
{
  value = document.getElementById(check);
  if (value.checked==true)
  {
    contador++;
    if (contador>maxi) 
    {
      //alert('Escolha no máximo dois produtos para comparação');
      //window.location.href = "";
      var url = "mensagem_provicos.php?KeepThis=true&TB_iframe=true&height=60&width=230&modal=true";
      tb_show("Escolha no máximo" + maxi + " produtos para comparação", url);
      value.checked=false;
      contador--;
    }
  }
  else
  {
      contador--;
  }
}

/********************************************************************
  Início do Suporte Online
********************************************************************/

/*function popup(mylink, windowname)
{
  if (! window.focus)return true;
    var href;
  if (typeof(mylink) == 'string')
     href=mylink;
  else
     href=mylink.href;
  
  window.open(href, windowname, 'width=600,height=600,scrollbars=yes');
  return false;
}*/

var win= null;
function OpenNewWindow(mypage,myname)
{
  var w = '710';
  var h = '548';
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,toolbar=no';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4)
  {
    win.window.focus();
  }
}

function isNumeric(valor)
{
  if(valor.length == 9)
  {
    validChar = '0123456789';
    for(var i=0;i<valor.length;i++)
      if(validChar.indexOf(valor.substr(i,1))<0)
        return false;
    return true;
  }
  else
  {
    document.getElementById('errorMessage').value = "Tem de introduzir um número válido";
    return false;
  }
}
function validateEmail(email) 
{
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  var address = email;
  //var address = document.forms[form_id].elements[email].value;
  if(reg.test(address) == false)
  {
    document.getElementById('errorMessage').value = "O e-mail introduzido não é válido";
    return false;
  }
  else
    return true;
}

/********************************************************************
  Fim do Suporte Online
********************************************************************/


/*Actualizar estado do assistente*/

var xmlhttpEstadoAssistente;

function AssistenteEstadoActualizarFrontend()
{
  xmlhttpEstadoAssistenteFrontend=GetXmlHttpObjectFrontend();
  if (xmlhttpEstadoAssistenteFrontend==null)
  {
    alert ("O seu browser não suporta HTTP Request.");
    return;
  }
  var url="getEstadoAssistente.php";
  url=url+"?sid="+Math.random();
  xmlhttpEstadoAssistenteFrontend.onreadystatechange=stateChangedEstadoAssistenteFrontend;
  xmlhttpEstadoAssistenteFrontend.open("GET",url,true);
  xmlhttpEstadoAssistenteFrontend.send(null);
}
  
function stateChangedEstadoAssistenteFrontend()
{
  if (xmlhttpEstadoAssistenteFrontend.readyState==4)
  {
    document.getElementById("assistenteOnlineDiv").innerHTML=xmlhttpEstadoAssistenteFrontend.responseText;
    mTimerEstadoFrontend = setTimeout('AssistenteEstadoActualizarFrontend();',1000); //Refresh our Support State in 1 seconds
  }
}
  
function GetXmlHttpObjectFrontend()
{
  if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}
/*************/
/* Código fadeIn FadeOut Notícias*/
jQuery.fn.fader = function(options) {
    if (!options.slideClass || options.slideClass == "") {
        var error = new Error();
        error.message = "No slide class has been supplied";
    }

    if (!options.slideDuration || !parseInt(options.slideDuration)) {
        options.slideDuration = 6000;
    }

    if (!options.fadeOutDuration || !parseInt(options.fadeOutDuration)) {
        options.fadeOutDuration = 2000;
    }


    if (!options.fadeInDuration || !parseInt(options.fadeInDuration)) {
        options.fadeInDuration = 1000;
    }

    return this.each(function() {
        $(options.slideClass, this).hide();
        $(options.slideClass + ":eq(0)", this).show();
        var currentIndex = 0;
        var obj = this;
        var t = setInterval(function() {
        $(options.slideClass + ":eq(" + currentIndex + ")", obj).fadeOut(options.fadeOutDuration, function() {
                currentIndex++;
                if (currentIndex > $(options.slideClass, obj).size() - 1)
                    currentIndex = 0;
                $(options.slideClass + ":eq(" + currentIndex + ")", obj).fadeIn(options.fadeInDuration);
            });
        }, options.slideDuration);
    });
};
/**************************/
/* Function to Retrieve the cookies for payment methods And Trainees*/
function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}
/**************************/
/* Function to Set the cookies for payment methods And Trainees */
function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
/*Used if we want a cookie to expire in 'n' minutes*/
function setCookieMinutes(c_name,value,pMinutes)
{
  var exdate=new Date();
  exdate.setTime(exdate.getTime()+pMinutes*60*1000);
  document.cookie=c_name+ "=" +escape(value)+((pMinutes==null) ? "" : ";expires="+exdate.toGMTString());
}
/*Funcions to Change button after click on checkbox*/
var timer1ChangeButton = timer2ChangeButton = timer3ChangeButton = 0;
  function funcao1ChangeButton()
  {
    document.getElementById('gerarPropostaId').className = 'gerar_proposta';
    document.getElementById('gerarPropostaIdImg').src = 'images/button_proposta.png';
    clearTimeout(timer1ChangeButton);
  }
  function funcao2ChangeButton()
  {
    document.getElementById('mostrarComparacaoId').className = 'mostrar_comparacao';
    clearTimeout(timer2ChangeButton);
  }
  function funcao3ChangeButton()
  {
    document.getElementById('adicionarCarrinhoId').className = 'adicionar_carrinho';
    clearTimeout(timer3ChangeButton);
  }
  function ChangeButton(buttonName)
  { 
    if(buttonName == 'gerar_proposta')
    {
      timer1ChangeButton = setTimeout('funcao1ChangeButton()', 500);
      document.getElementById('gerarPropostaId').className = 'gerar_proposta_active';
      document.getElementById('gerarPropostaIdImg').src = 'images/button_proposta_in.png';
    }
    else if(buttonName == 'mostrar_comparacao')
    {
      timer2ChangeButton = setTimeout('funcao2ChangeButton()', 500);
      document.getElementById('mostrarComparacaoId').className = 'mostrar_comparacao_active';
    }
    else if(buttonName == 'adicionar_carrinho')
    {
      timer3ChangeButton = setTimeout('funcao3ChangeButton()', 500);
      document.getElementById('adicionarCarrinhoId').className = 'adicionar_carrinho_active';
    }
  }
