/* Global Javascript */

// FIX Hover IE6
function fixIE6Hover(selector, cssClass){
	if (Browser.Engine.trident4) {
		$$(selector).each(function(el) {
			el.addEvents({
				'mouseenter':function() {
					el.toggleClass(cssClass);
				},
				'mouseleave':function() {
					el.toggleClass(cssClass);
				}
			});	
		});
	}
}
// end FIX Hover IE6


// CLEAR DEFAULTS
function clearDefault(el) {
	if (el.defaultValue==el.value) { el.value = ""; }
}
function restoreDefault(el) {
	if (el.value == "") { el.value = el.defaultValue; }
}

function initClearDefaults() {
	$$('input.cleardefault').each(function(el, i) {
		el.addEvent("focus",function(event) {
			clearDefault(el);
		});
		el.addEvent("blur",function(event) {
			restoreDefault(el);
		});
	});
}
// end CLEAR DEFAULTS


// PRINT
function createPrint() {
	$$('.printicon').each(function(el,i) {
		new Element('img', {
			'class':'imprimir fixIE6hover',
			'src':Paths.SITE_URL_DESIGN + 'print.gif',
			'alt':Resources.print,
			'title':Resources.print,
			'events': {
				'click': function() {
					window.print();
				},
				'mouseenter':function(){
					this.set('src',Paths.SITE_URL_DESIGN + 'printHover.gif');
				},
				'mouseleave':function(){
					this.set('src',Paths.SITE_URL_DESIGN + 'print.gif');
				}
			}
		}).inject(el);
	});
}
// end PRINT

	function Objecto()
	{
		this.value = "";
	}

	function getLocalId () 	{
		
		if (document.getElementById("localid")==undefined) {
			return "131";
		}
		else {
			return document.getElementById("localid").value;
		}
	}

	function mostra_chk_Cobertura(tp_capital){
		pagina = "MC2009_Plano_Personalizado.aspx?localid=" + getLocalId() + "&capital=" + tp_capital + "&Idade_Personal=" + document.getElementById("Idade_personal").value;
		window.location.href = pagina+"#escolhe_capital";
	}

	function mostra_chk_CoberturaPME(tp_capital){
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		var parametros = new Objecto();
		if (ValidaColaboradores_PME(parametros)&&ValidaAgregados_PME(parametros)) {
			pagina = "MC2009_Plano_PersonalizadoPME.aspx?localid=" + getLocalId() + "&capital="+tp_capital+parametros.value;
			window.location.href = pagina+"#escolhe_capital";
		}
	}

	function ValidaContacto()
	{
		var padraoEmail = new RegExp($('PadraoMail').value);
		var padraoTelefone = new RegExp($('PadraoTelefone').value);
        var Email = $('txtEmail').value;
        var Telefone = $('txtTelefone').value;
        var Nome = $('txtNome').value;
        var chkContacto = $('chkContacto').checked;
        if (chkContacto)
        {
			if (Nome.length <= 0 || Email.length <= 0 || Telefone.length <= 0)
			{
				MensagemErro('simulador multicare', 'Todos os campos para contacto s&atilde;o obrigat&oacute;rios');
				Shadowbox.open(document.getElementById('CaixaErro'));
				return false;
			}
			else
			{
				if ($('txtEmail').value.match(padraoEmail))
				{
					if (!$('txtTelefone').value.match(padraoTelefone))
					{
						MensagemErro('simulador multicare', 'Telefone Inv&aacute;lido');
						Shadowbox.open(document.getElementById('CaixaErro'));
						return false;
					}
				}
				else
				{
					MensagemErro('simulador multicare', 'E-mail inv&aacute;lido');
					Shadowbox.open(document.getElementById('CaixaErro'));
					return false;
				}
			}
        }
        return true;
	}
	function EnviaSimulaPlanos(Pagina_target,googleTrackcategory,idade_familiar) {
		var localid;
		var erro = false;

		idade = document.getElementById("Idade_personal").value;
		if (idade == "" || idade == null)
		{
		   MensagemErro('simulador multicare', 'Idade &eacute; campo de preenchimento obrigat&oacute;rio');
		   document.getElementById("Idade_personal").focus();
		   return;
		}
		else 
		{
		  if (idade != parseInt(idade)) 
		  {
		    document.getElementById("Idade_personal").value = "";
	 	    document.getElementById("Idade_personal").focus();
			MensagemErro('simulador multicare', 'Idade &eacute; um campo num&eacute;rico');
			Shadowbox.open(document.getElementById('CaixaErro'));
			return;
		  }
		  else 
		  {
			if (parseInt(idade) > 60)
			{
			  MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 0 e os 60 anos');
			  Shadowbox.open(document.getElementById('CaixaErro'));
	 	      document.getElementById("Idade_personal").focus();
			  return;
			}
		  }
		}
		/*if (!ValidaContacto())
		{
			return;
		}*/
		localid = document.getElementById("localid").value;
		CodProd = document.getElementById("codProd").value;
		Capital = document.getElementById("capital").value;
		Cobertura = document.getElementById("cobertura").value;
		//pagina = Pagina_target+"?localid=" + getLocalId() + "&idade_1="+idade+"&codProd="+CodProd+"&nr_pessoas=1&capital="+Capital+"&cobertura="+Cobertura+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value+"#agregados";
		pagina = Pagina_target+"?localid=" + getLocalId() + "&idade_1="+idade+"&codProd="+CodProd+"&nr_pessoas=1&capital="+Capital+"&cobertura="+Cobertura+"#agregados";
		if (!erro) 
		{
			if((googleTrackcategory!=undefined)&&(googleTrackcategory!='')&&(idade_familiar!=undefined)&&(idade_familiar!=''))
			{
				pageTracker._trackEvent(googleTrackcategory, 'simulation_anui', idade_familiar);
			}			
			window.location.href = pagina;
		}
	}

	function EnviaSimulaActivcare_PME() {
		var localid;
		var erro = false;
		var QtdColab = document.getElementById("Qtd_Colab").value;
		var capital = document.getElementById("capital").value;
		var cobertura = document.getElementById("cobertura").value;
		if (QtdColab == "" || QtdColab == null)
		{
		   MensagemErro('simulador multicare', 'Informe o n&uacute;mero de colaboradores.');
		   document.getElementById("Qtd_Colab").focus();
		   return;
		}
		else 
		{
		  if (QtdColab != parseInt(QtdColab)) 
		  {
		    document.getElementById("Qtd_Colab").value = "";
	 	    document.getElementById("Qtd_Colab").focus();
			MensagemErro('simulador multicare', 'N&uacute;mero de colaboradores &eacute; um campo num&eacute;rico');
			Shadowbox.open(document.getElementById('CaixaErro'));
			return;
		  }
		  else 
		  {
			if (parseInt(QtdColab) > 250 || parseInt(QtdColab) < 3)
			{
			  MensagemErro('simulador multicare', 'Para simular, dever&aacute; indicar, no m&iacute;nimo, 3  e no m&aacute;ximo 250 colaboradores.');
			  Shadowbox.open(document.getElementById('CaixaErro'));
	 	      document.getElementById("QtdColab").focus();
			  return;
			}
		  }
		  
		}
		/*if (!ValidaContacto())
		{
			return;
		}
		*/



		
		localid = document.getElementById("localid").value;
		CodProd = document.getElementById("codProd").value;
		//pagina = "MC2009_ActivcaregeralPME.aspx?localid=" + getLocalId() + "&Qtd_Colab="+QtdColab+"&codProd="+CodProd+"&capital="+capital+"&cobertura="+cobertura+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value+"#agregados";
		pagina = "MC2009_ActivcaregeralPME.aspx?localid=" + getLocalId() + "&Qtd_Colab="+QtdColab+"&codProd="+CodProd+"&capital="+capital+"&cobertura="+cobertura+"#agregados";
		window.location.href = pagina;
	}

	function ValidaColaboradores_PME(parametros) {
		var cont=0;
		var fieldIndex = 0;
		var Qtd_Colab = 0;
		for(i=0; i<document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].name != undefined)
			{
				nm_campo = document.forms[0].elements[i].name;
				if (nm_campo.substr(0,9) == "Qtd_Colab")
				{
					fieldIndex++;
					if (document.forms[0].elements[i].value != null && document.forms[0].elements[i].value != "" && document.forms[0].elements[i].value != "0" )
					{
						if (document.forms[0].elements[i].value == parseInt(document.forms[0].elements[i].value))
						{
							FieldIndex = "Idade_Colab"+fieldIndex;
							idadeColab = document.getElementById(FieldIndex);
							if (idadeColab.value != null && idadeColab.value != "" && idadeColab.value != "0" )
							{
								if (idadeColab.value == parseInt(idadeColab.value))
								{
									if (parseInt(idadeColab.value) > 65)
									{
										MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 16 e os 65 anos');
										Shadowbox.open(document.getElementById('CaixaErro'));
										idadeColab.value = "";
 										idadeColab.focus();
										//erro = true;
										return false;
									}
									else
									{
										if (parseInt(idadeColab.value) < 16)
										{
											MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 16 e os 65 anos');
											Shadowbox.open(document.getElementById('CaixaErro'));
											idadeColab.value = "";
 											idadeColab.focus();
											//erro = true;
											return false;
										}
										else
										{
											cont++;
											Qtd_Colab += parseInt(document.forms[0].elements[i].value);
											parametros.value+="&Qtd_Colab"+cont+"="+document.forms[0].elements[i].value+"&Idade_Colab"+cont+"="+idadeColab.value;
										}
									}
								}
								else
								{
										MensagemErro('simulador multicare', 'Idade &eacute; um campo num&eacute;rico');
										Shadowbox.open(document.getElementById('CaixaErro'));
										idadeColab.value = "";
 										idadeColab.focus();
										//erro = true;
										return false;
								}
							}
							else
							{
								MensagemErro('simulador multicare', 'Ao informar o n&uacute;mero de colaboradores, informe tamb&eacute;m a idade dos mesmos.');
								Shadowbox.open(document.getElementById('CaixaErro'));
								idadeColab.value = "";
 								idadeColab.focus();
								//erro = true;
								return false;
							}
						}
						else
						{
							MensagemErro('simulador multicare', 'O campo n&uacute;mero de colaboradores &eacute; num&eacute;rico.');
							Shadowbox.open(document.getElementById('CaixaErro'));
							document.forms[0].elements[i].value = "";
 							document.forms[0].elements[i].focus();
							//erro = true;
							return false;
						}
					}
				}
			}
		}
					
		//window.location.href = pagina;
		if (Qtd_Colab > 2)
		{
			if (Qtd_Colab > 50)
			{
				MensagemErro('simulador multicare', 'Se tem mais de 50 colaboradores, sugerimos que seja desenvolvida uma Proposta de Condi&ccedil;&otilde;es de Seguro de Sa&uacute;de feita &agrave; medida da sua Empresa.');
				Shadowbox.open(document.getElementById('CaixaErro'));
				//erro = true;
				return false;
			}
			else
			{
				parametros.value+="&nr_grupo_colab="+cont;
				return true;
			}
		}
		else
		{
			MensagemErro('simulador multicare', 'Para simular, dever&aacute; indicar as idades de, no m&iacute;nimo, 3 colaboradores.');
			Shadowbox.open(document.getElementById('CaixaErro'));
			//erro = true;
			return false;
		}
	}
	
	function ValidaAgregados_PME(parametros) {
		var cont=0;
		var fieldIndex = 0;
		for(i=0; i<document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].name != undefined)
			{
				nm_campo = document.forms[0].elements[i].name;
				if (nm_campo.substr(0,13) == "Qtd_Agregados")
				{
					fieldIndex++;
					if (document.forms[0].elements[i].value != null && document.forms[0].elements[i].value != "" && document.forms[0].elements[i].value != "0" )
					{
						if (document.forms[0].elements[i].value == parseInt(document.forms[0].elements[i].value))
						{
							FieldIndex = "Idade_Agregados"+fieldIndex;
							idadeAgregados = document.getElementById(FieldIndex);
							if (idadeAgregados.value != null && idadeAgregados.value != "" && idadeAgregados.value != "0" )
							{
								if (idadeAgregados.value == parseInt(idadeAgregados.value))
								{
									if (parseInt(idadeAgregados.value) > 65)
									{
										MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 16 e os 65 anos');
										Shadowbox.open(document.getElementById('CaixaErro'));
										idadeAgregados.value = "";
 										idadeAgregados.focus();
										//erro = true;
										return false;
									}
									else
									{
										if (parseInt(idadeColab.value) < 16)
										{
											MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 16 e os 65 anos');
											Shadowbox.open(document.getElementById('CaixaErro'));
											idadeColab.value = "";
 											idadeColab.focus();
											//erro = true;
											return false;
										}
										else
										{
											cont++;
											parametros.value+="&Qtd_Agregados"+cont+"="+document.forms[0].elements[i].value+"&Idade_Agregados"+cont+"="+idadeAgregados.value;
										}
									}
								}
								else
								{
										MensagemErro('simulador multicare', 'Idade &eacute; um campo num&eacute;rico');
										Shadowbox.open(document.getElementById('CaixaErro'));
										idadeAgregados.value = "";
 										idadeAgregados.focus();
										//erro = true;
										return false;
								}
							}
							else
							{
								MensagemErro('simulador multicare', 'Ao informar o n&uacute;mero de Agregados, informe tamb&eacute;m a idade dos mesmos.');
								Shadowbox.open(document.getElementById('CaixaErro'));
								idadeAgregados.value = "";
 								idadeAgregados.focus();
								//erro = true;
								return false;
							}
						}
						else
						{
							MensagemErro('simulador multicare', 'O campo N&uacute;mero de Agregados &eacute; num&eacute;rico.');
							Shadowbox.open(document.getElementById('CaixaErro'));
							document.forms[0].elements[i].value = "";
 							document.forms[0].elements[i].focus();
							//erro = true;
							return false;
						}
					}
				}
			}
		}
					
		
		parametros.value += "&nr_grupo_agregados="+cont;
		return true;
	}

	function EnviaSimulaPlanos_PME(pagina_target,googleTrackcategory)
	{
		var parametros = new Objecto();
		//if (ValidaColaboradores_PME(parametros)&&ValidaAgregados_PME(parametros)&&ValidaContacto())
		if (ValidaColaboradores_PME(parametros)&&ValidaAgregados_PME(parametros))
		{
			localid = document.getElementById("localid").value;
			var CodProd = document.getElementById("codProd").value;
			//pagina = pagina_target+"?localid=" + getLocalId() + "&capital="+document.getElementById("capital").value+"&cobertura="+document.getElementById("cobertura").value+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value+"&CodProd="+CodProd+parametros.value;
			pagina = pagina_target+"?localid=" + getLocalId() + "&capital="+document.getElementById("capital").value+"&cobertura="+document.getElementById("cobertura").value+"&CodProd="+CodProd+parametros.value;
			window.location.href = pagina;
			
		}
	}
	function EnviaPersonal(){
		var idade;
		var capital;
		var cont;
		var cobertura;
		var erro = false;
		var localid;
		capital = document.getElementById("capital").value;
		idade = document.getElementById("Idade_personal").value;
		if (idade == "" || idade == null){
		   document.getElementById("Idade_personal").focus();
		   erro = true;
		   MensagemErro('simulador multicare', 'Idade &eacute; campo de preenchimento obrigat&oacute;rio');
		   Shadowbox.open(document.getElementById('CaixaErro'));
		}
		else {
		  if (idade != parseInt(idade)) {
		    MensagemErro('simulador multicare', 'Idade &eacute; um campo num&eacute;rico');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("Idade_personal").value = "";
	 	    document.getElementById("Idade_personal").focus();
			erro = true;
		  }
		  else {
			if (parseInt(idade) > 60){
				document.getElementById("Idade_personal").value = "";
	 			document.getElementById("Idade_personal").focus();
			    MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 0 e os 60 anos');
			    Shadowbox.open(document.getElementById('CaixaErro'));
				return;
			}
		  }
		}
		localid = document.getElementById("localid").value;
		if (capital == "20000"){
			cont=3;
		}
		else {
		   if (capital == "50000"){
			  cont=5;
			  
		   }
		   else {
		      cont=7;
		   }
		}
		pagina = "MC2009_Plano_Personalizado_Resposta.aspx?localid=" + getLocalId() + "&idade_1="+idade+"&capital="+capital+"&nr_pessoas=1";
		cobertura = "0";
		for(i=0; i<cont; i++){
			contr_chk = i+1;
			if (document.getElementById("chk_"+contr_chk).checked) {
				
				var valor_chk = document.getElementById("chk_"+contr_chk).value.split(',');
				cobertura = valor_chk[0];
				CodProd = valor_chk[1];
			}
		}
		if (capital == "20000" && cobertura == "0"){
			CodProd = "9094";
		}

		if (capital == "50000" && cobertura == "0"){
			CodProd = "9097";
		}
		if (capital == "75000" && cobertura == "0"){
			CodProd = "9103";
		}


		//pagina += "&cobertura="+cobertura+"&CodProd="+CodProd+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value;
		//if (!erro && ValidaContacto()) {
		pagina += "&cobertura="+cobertura+"&CodProd="+CodProd;
		if (!erro) {
		window.location.href = pagina;
		}

	}
	function adiciona_agregado(nr_pessoa){
		var id_prox_div = nr_pessoa+1;
		var d = document.getElementById("div_pessoa_agregada"+nr_pessoa);
		var olddiv = document.getElementById("div_adicionar_agregado"+nr_pessoa);
		if (nr_pessoa>1)
			d.removeChild(olddiv);
		
		var div_contentor_agregado = document.createElement("div");
		div_contentor_agregado.id = "div_pessoa_agregada"+id_prox_div;
		div_contentor_agregado.className ="contentor_pessoa_agregada";
		document.getElementById("div_contentor_agregado_familiar").appendChild(div_contentor_agregado); 


		var contentor_idade_personal = document.createElement("div");
		contentor_idade_personal.id = "contentor_idade_personal"+id_prox_div;
		contentor_idade_personal.className ="contentor_idade_personal";
		contentor_idade_personal.innerHTML = "<label for=\"Idade_personal"+id_prox_div+"\" class=\"Pequeno\"><strong>PESSOA "+id_prox_div+"&nbsp;&nbsp;&nbsp;</strong>IDADE <input id=\"Idade_personal"+id_prox_div+"\" class=\"txtIdade_Pers\" name=\"Idade_personal"+id_prox_div+"\" width=\"10px\"></label>"; 
		document.getElementById(div_contentor_agregado.id).appendChild(contentor_idade_personal); 

		var adiccionar_agregado = document.createElement("div");
		adiccionar_agregado.id = "div_adicionar_agregado"+id_prox_div;
		adiccionar_agregado.className ="adiccionar_agregado";
		adiccionar_agregado.innerHTML = "<a href=\"#agregados\" onclick=\"adiciona_agregado("+id_prox_div+")\"><img src=\"Resources_2009/1/design/btn_mais_laranja.gif\" border=\"0\"/></a>"; 
		document.getElementById(div_contentor_agregado.id).appendChild(adiccionar_agregado); 
	}

	function adiciona_colaboradores(nr_pessoa, DivId){
		var id_prox_div = nr_pessoa+1;
		var d = document.getElementById("contentor_colaboradores"+nr_pessoa);
		if (DivId == undefined)
			DivId = "";
		oldDivId = DivId+"div_adicionar_colaboradores";
		var olddiv = document.getElementById(oldDivId+nr_pessoa);
		if (nr_pessoa>0)
			d.removeChild(olddiv);
		
		var div_contentor_colaborador = document.createElement("div");
		div_contentor_colaborador.id = "contentor_colaboradores"+id_prox_div;
		div_contentor_colaborador.className ="contentor_pessoa_agregada";
		document.getElementById("div_contentor_colaboradores").appendChild(div_contentor_colaborador); 

		var contentor_idade_colab = document.createElement("div");
		contentor_idade_colab.id = "contentor_idade_colab"+id_prox_div;
		contentor_idade_colab.className ="contentor_idade_personal";
		contentor_idade_colab.innerHTML = "<label class=\"Pequeno\" for=\"Qtd_Colab"+id_prox_div+"\">N&uacute;mero de Colaboradores <input class=\"txtIdade_Pers\" id=\"Qtd_Colab"+id_prox_div+"\" name=\"Qtd_Colab"+id_prox_div+"\" width=\"10px\"/></label>"; 
		contentor_idade_colab.innerHTML = contentor_idade_colab.innerHTML+"<label for=\"Idade_Colab"+id_prox_div+"\" class=\"Pequeno\">&nbsp;&nbsp;&nbsp;Idade <input id=\"Idade_Colab"+id_prox_div+"\" class=\"txtIdade_Pers\" name=\"Idade_Colab"+id_prox_div+"\" width=\"10px\"/></label>"; 
		document.getElementById(div_contentor_colaborador.id).appendChild(contentor_idade_colab); 


		var adiccionar_colaborador = document.createElement("div");
		adiccionar_colaborador.id = "div_adicionar_colaboradores"+id_prox_div;
		adiccionar_colaborador.className ="adiccionar_agregado";
		adiccionar_colaborador.innerHTML = "<a href=\"#agregados\" onclick=\"adiciona_colaboradores("+id_prox_div+")\"><img src=\"Resources_2009/2/design/btn_mais_laranja.gif\" border=\"0\"/></a>"; 
		document.getElementById(div_contentor_colaborador.id).appendChild(adiccionar_colaborador); 
	}

	function adiciona_agregados_PME(nr_pessoa){
		var id_prox_div = nr_pessoa+1;
		var id_ant_div  = nr_pessoa-1;
		var d = document.getElementById("div_pessoa_agregada"+id_ant_div);
		var olddiv = document.getElementById("div_adicionar_agregado"+id_ant_div);
		if (nr_pessoa>1)
			d.removeChild(olddiv);
		
		var div_pessoa_agregada = document.createElement("div");
		div_pessoa_agregada.id = "div_pessoa_agregada"+nr_pessoa;
		div_pessoa_agregada.className ="contentor_pessoa_agregada";
		document.getElementById("div_contentor_agregado_familiar").appendChild(div_pessoa_agregada); 

		var contentor_idade_agregados = document.createElement("div");
		contentor_idade_agregados.id = "div_contentor_idade_personal"+nr_pessoa;
		contentor_idade_agregados.className ="contentor_idade_personal";
		contentor_idade_agregados.innerHTML = "<label class=\"Pequeno\" for=\"Qtd_Agregados"+nr_pessoa+"\">N&uacute;mero de Agregados <input class=\"txtIdade_Pers\" id=\"Qtd_Agregados"+nr_pessoa+"\" name=\"Qtd_Agregados"+nr_pessoa+"\" width=\"10px\"/></label>"; 
		contentor_idade_agregados.innerHTML = contentor_idade_agregados.innerHTML+"<label for=\"Idade_Agregados"+nr_pessoa+"\" class=\"Pequeno\">&nbsp;&nbsp;&nbsp;Idade <input id=\"Idade_Agregados"+nr_pessoa+"\" class=\"txtIdade_Pers\" name=\"Idade_Agregados"+nr_pessoa+"\" width=\"10px\"/></label>"; 
		document.getElementById(div_pessoa_agregada.id).appendChild(contentor_idade_agregados); 


		var adiccionar_agregados = document.createElement("div");
		adiccionar_agregados.id = "div_adicionar_agregado"+nr_pessoa;
		adiccionar_agregados.className ="adiccionar_agregado";
		adiccionar_agregados.innerHTML = "<a href=\"#agregados\" onclick=\"adiciona_agregados_PME("+id_prox_div+")\"><img src=\"Resources_2009/2/design/btn_mais_laranja.gif\" border=\"0\"/></a>"; 
		document.getElementById(div_pessoa_agregada.id).appendChild(adiccionar_agregados); 
	}

	function mostra_agregados(id_checkbox){
	   var divs = document.getElementsByTagName("div");
	   var d;
	   window.location.hash="agregados";
	   if (document.getElementById(id_checkbox).checked){
	        if (document.getElementById("div_pessoa_agregada2") == undefined)
				adiciona_agregado(1);
	   }
	   else 
	   {
			for (var i = 0; i < divs.length; i++)
			{
				var divname = divs[i].id;
				if (divname.substr(0,19) == "div_pessoa_agregada")
				{
					if (parseInt(divname.substr(19, 1)) > 1) 
					{
						d = document.getElementById(divs[i].id).parentNode;
						d.removeChild(divs[i]);
						i--;
					}
				}
			}
		}
	}

	function mostra_agregados_PME(id_checkbox){
	   var divs = document.getElementsByTagName("div");
	   var d;
	   var div_btn = document.getElementById("div_continua_agregado")
	   window.location.hash="agregados";
	   if (document.getElementById(id_checkbox).checked){
			div_btn.style.display = "block";
	        if (document.getElementById("div_pessoa_agregada1") == undefined)
				adiciona_agregados_PME(1);
	   }
	   else 
	   {
			div_btn.style.display = "none";
			for (var i = 0; i < divs.length; i++)
			{
				var divname = divs[i].id;
				if (divname.substr(0,19) == "div_pessoa_agregada")
				{
					if (parseInt(divname.substr(19, 1)) > 0) 
					{
						d = document.getElementById(divs[i].id).parentNode;
						d.removeChild(divs[i]);
						i--;
					}
				}
			}
		}
	}
	
	function mostra_contacto(){
		$$('.Contacto fieldset').toggleClass('displayNone');
	}

	function envia_agregado(pagina_target,googleTrackcategory,idade_familiar){
		var pagina;
		var cont = 0;
		var localid;
		var erro=false;
		var txt_erro="";
		localid = document.getElementById("localid").value;
		var CodProd = document.getElementById("codProd").value;
		pagina = pagina_target+"?localid=" + getLocalId() + "&capital="+document.getElementById("capital").value+"&cobertura="+document.getElementById("cobertura").value+"&CodProd="+CodProd;
		for(i=0; i<document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].name != undefined)
			{
				nm_campo = document.forms[0].elements[i].name;
				if (nm_campo.substr(0,14) == "Idade_personal")
				{
					if (document.forms[0].elements[i].value != null && document.forms[0].elements[i].value != "")
					{
						if (parseInt(document.forms[0].elements[i].value) > 60)
						{
							MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 0 e os 60 anos');
							Shadowbox.open(document.getElementById('CaixaErro'));
							document.forms[0].elements[i].value = "";
 							document.forms[0].elements[i].focus();
							//erro = true;
							return;
						}
						cont++;
						pagina+="&idade_"+cont+"="+document.forms[0].elements[i].value;
						if (document.forms[0].elements[i].value != parseInt(document.forms[0].elements[i].value))
						{
							erro=true;	
							txt_erro += "Idade da Pessoa "+cont+" &eacute; inv&aacute;lida<br/>";
						}
					}
				}
			}
		}
		pagina +="&nr_pessoas="+cont;
		if (!erro){
			if((googleTrackcategory!=undefined)&&(googleTrackcategory!='')&&(idade_familiar!=undefined)&&(idade_familiar!='')){				
				pageTracker._trackEvent(googleTrackcategory, 'simulation_fam', idade_familiar);
			}
			/*if ($('chkContacto').checked)
				sQueryContacto = "&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value;
			else
				sQueryContacto = "";
			window.location.href = pagina+sQueryContacto+"#agregados";*/
			window.location.href = pagina+"#agregados";
		}
		else {
		    MensagemErro('simulador multicare', txt_erro);
		    Shadowbox.open(document.getElementById('CaixaErro'));
			window.location.hash="agregados";
		}
	}
	
	function novaSimulacaoPME()
	{
		var pagina;
		var cont = 0;
		var localid;
		var erro=false;
		var txt_erro="";
		localid = document.getElementById("localid").value;
		var CodProd = document.getElementById("codProd").value;
		var parametros = new Objecto();
		//if (ValidaColaboradores_PME(parametros)&&ValidaAgregados_PME(parametros)&&ValidaContacto())
		if (ValidaColaboradores_PME(parametros)&&ValidaAgregados_PME(parametros))
		{
			//pagina = "MC2009_Plano_Personalizado_RespostaPME.aspx?localid=" + getLocalId() + "&capital="+document.getElementById("capital").value+"&cobertura="+document.getElementById("cobertura").value+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value+"&CodProd="+CodProd+parametros.value;
			pagina = "MC2009_Plano_Personalizado_RespostaPME.aspx?localid=" + getLocalId() + "&capital="+document.getElementById("capital").value+"&cobertura="+document.getElementById("cobertura").value+"&CodProd="+CodProd+parametros.value;
			window.location.href = pagina;
			
		}
		

	}	
	function actualizaCoberturas(nr_cobertura){

	    var cont = 0;
		for(i=0; i<document.forms[0].elements.length; i++){
			if (document.forms[0].elements[i].name != undefined){
				var nm_elemento = document.forms[0].elements[i].name;
				if (nm_elemento.substr(0,3) == "chk"){
					cont++;
					if (cont < nr_cobertura){ 
						document.forms[0].elements[i].checked = true;
					}
					else
					if (cont > nr_cobertura){ 
						document.forms[0].elements[i].checked = false;
					}
				}
			}
		}
		if (nr_cobertura == 3) {
			if (document.getElementById("chk_3").checked) {
				document.getElementById("chk_2").checked = true;
				document.getElementById("chk_1").checked = true;
			}
			else {
				document.getElementById("chk_2").checked = false;
				document.getElementById("chk_1").checked = false;
			}
		}
	}

	function mostraCobertura(tp_capital){
		document.getElementById("div_coberturas").style.display = "block";
		document.getElementById("div_continua").style.display = "block";
	    var cont = 0;
		var divs = document.getElementsByTagName("div");
		for (var i = 0; i < divs.length; i++){
			var divname = divs[i].id;
			if (divname.substr(0,7) == "div_chk"){
			    cont++;
				if (cont > tp_capital){ 
				   document.getElementById(divname).style.display = "none";
				}
				if (cont <= tp_capital){ 
				   document.getElementById(divname).style.display = "block";
				}
			}
		}
		cont = 0;
		for(i=0; i<document.forms[0].elements.length; i++){
			if (document.forms[0].elements[i].name != undefined){
				var nm_elemento = document.forms[0].elements[i].name;
				if (nm_elemento.substr(0,3) == "chk"){
				   cont++;
				   if (cont > tp_capital){
					  document.forms[0].elementIs[i].checked = false;
				   }
				}
			}
		}	
		

	}


	function EnviaSimulacao(){
		var idade;
		var sexo;
		var pagina;
		var erro = false;
		idade = document.getElementById("drpIdade").value;
		if (idade != parseInt(idade)) {
		    MensagemErro('simulador multicare', 'Idade &eacute; campo de preenchimento obrigat&oacute;rio');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("drpIdade").value = "";
 			document.getElementById("drpIdade").focus();
			//erro = true;
			return;
		}

		if (document.getElementById("CFI2009_cx_simulador1_CFI2009_cx_simulador_Individual1_SexoFem").checked){
			sexo = "F"
		}
		else if (document.getElementById("CFI2009_cx_simulador1_CFI2009_cx_simulador_Individual1_SexoMasc").checked) {
			sexo = "M";
		}
		else {
		    MensagemErro('simulador multicare', 'Sexo &eacute; campo de preenchimento obrigat&oacute;rio');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			return;
		}
		
		pagina = "MC2009_Simulador_Sugestao.aspx?idade="+idade+"&sexo="+sexo

		//if (!erro)
			window.location.href = pagina;
	}

	function EnviaSimulacaoPME(){
		var idade;
		var QtdColab;
		var pagina;
		var erro = false;
		idade = document.getElementById("drpIdade").value;
		QtdColab = document.getElementById("drpColab").value;
		if (idade != parseInt(idade)) {
		    MensagemErro('simulador multicare', 'Idade &eacute; campo num&eacute;rico');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("drpIdade").value = "";
 			document.getElementById("drpIdade").focus();
			//erro = true;
			return;
		}
		
		if (parseInt(idade) < 16 || parseInt(idade) > 65) {
			MensagemErro('simulador multicare', 'Para os Planos de Sa&uacute;de, a idade de subscri&ccedil;&atilde;o varia entre os 16 e os 65 anos');
			Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("drpIdade").value = "";
 			document.getElementById("drpIdade").focus();
			//erro = true;
			return;
		}
		

		if (QtdColab != parseInt(QtdColab)) {
		    MensagemErro('simulador multicare', 'N&uacute;mero de Colaboradores &eacute; campo num&eacute;rico');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("drpColab").value = "";
 			document.getElementById("drpColab").focus();
			//erro = true;
			return;
		}

		if (parseInt(QtdColab) < 3) {
		    MensagemErro('simulador multicare', 'Para simular, dever&aacute; indicar as idades de, no m&iacute;nimo, 3 colaboradores.');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			document.getElementById("drpColab").value = "";
 			document.getElementById("drpColab").focus();
			//erro = true;
			return;
		}
		else
		{
			if (parseInt(QtdColab) > 250) {
				MensagemErro('simulador multicare', 'Para simular, dever&aacute; indicar, no m&iacute;nimo, 3  e no m&aacute;ximo 250 colaboradores.');
				Shadowbox.open(document.getElementById('CaixaErro'));
				document.getElementById("drpColab").value = "";
 				document.getElementById("drpColab").focus();
				//erro = true;
				return;
			}
		}		
		pagina = "MC2009_Simulador_SugestaoPME.aspx?localid=179&QtdColab="+QtdColab+"&Idade="+idade

		//if (!erro)
			window.location.href = pagina;
	}

	function enviaPesquisa(){
		var search;
		search = document.getElementById("frmPesquisa").value;
		if (search=='Pesquisar' ){
			return;
		}
		if (search.length < 3 ){
		    MensagemErro('Pesquisa', 'Indique uma palavra com, pelo menos, 3 caract&eacute;res');
		    Shadowbox.open(document.getElementById('CaixaErro'));
			return;
		}
		pagina = "MC2009_Pesquisa.aspx?search="+search;
		window.location.href = pagina;
	}


	function MensagemErro(sTitulo, sMsg)
	{
		document.getElementById("titErro").innerHTML = sTitulo; 
		document.getElementById("msgErro").innerHTML = sMsg; 
	    Shadowbox.open(document.getElementById('CaixaErro'));
	}
	
	function EnviaPersonalPME(){
		var idade;
		var capital;
		var cont;
		var cobertura;
		var erro = false;
		var localid;
		capital = document.getElementById("capital").value;
		localid = document.getElementById("localid").value;
		if (capital == "50000")
		{
			cont=4;
		}
		else 
		{
		    cont=7;
		}
		pagina = "MC2009_Plano_Personalizado_RespostaPME.aspx?localid=" + getLocalId() + "&capital=" +capital;
		cobertura = "0";
		for(i=0; i<cont; i++)
		{
			contr_chk = i+1;
			if (document.getElementById("chk_"+contr_chk).checked) 
			{
				var valor_chk = document.getElementById("chk_"+contr_chk).value.split(',');
				cobertura = valor_chk[0];
				CodProd = valor_chk[1];
			}
		}
		if (capital == "50000" && cobertura == "0")
		{
			CodProd = "9177";
		}
		if (capital == "75000" && cobertura == "0")
		{
			CodProd = "9180";
		}


		//pagina += "&cobertura="+cobertura+"&CodProd="+CodProd+"&chkContacto="+$('chkContacto').checked+"&txtNome="+$('txtNome').value+"&txtEmail="+$('txtEmail').value+"&txtTelefone="+$('txtTelefone').value;
		pagina += "&cobertura="+cobertura+"&CodProd="+CodProd;
		var parametros = new Objecto();
		//if (ValidaColaboradores_PME(parametros) && ValidaAgregados_PME(parametros) && ValidaContacto())
		if (ValidaColaboradores_PME(parametros) && ValidaAgregados_PME(parametros))
		{
			window.location.href = pagina+parametros.value;
		}

	}
	

// INICIALIZACAO DO ACCORDION DAS FAQS
function accordionFaqs() {
	if ($$('.faqs') != null) {
		// Adaptation IE6
		if(window.ie6) var heightValue='100%';
		else var heightValue='';
		
		// Selectors switch for the container and contents
		var togglerName='.accordion_toggler_';
		var contentName='.accordion_content_';
		
		// Selectors set
		var counter=1;
		var toggler=$$(togglerName+counter);
		var content=$$(contentName+counter);
		
		while(toggler.length>=1) {
			// Accordion apply
			new Accordion(toggler, content, {
				opacity: false,
				display: -1,
				alwaysHide: true,
				onComplete: function(request) {
					var element=$(this.elements[this.previous]);
					//var open = request.getStyle('margin-top').toInt();
					if(element && element.offsetHeight>0) element.setStyle('height', heightValue);
					//if(open >= 0) new Fx.Scroll(window).toElement(content);
				},
				onActive: function(toggler, content) {
					if (Browser.Engine.trident4) {
						toggler.addClass('ActivoFix');
					} else {
						toggler.addClass('Activo');
					}
//alert("ss");
//window.location.href = "http://localhost/multicare/PresentationLayer/MC2009_faq.aspx?localid=92&faqtemaid=1#teste";
				},
				onBackground: function(toggler, content) {
					if (Browser.Engine.trident4) {
						toggler.removeClass('ActivoFix');
					} else {
						toggler.removeClass('Activo');
					}
				}
			});
			
			// Selectors set for next level
			counter++;
			toggler=$$(togglerName+counter);
			content=$$(contentName+counter);
		}
	}
}

/*
vertical: function(){
	var list = $$('#vertical li div.collapse');
	var headings = $$('#vertical li h3');
	var collapsibles = new Array();
	
	headings.each( function(heading, i) {

		var collapsible = new Fx.Slide(list[i], { 
			duration: 500, 
			transition: Fx.Transitions.linear,
			onComplete: function(request){ 
				var open = request.getStyle('margin-top').toInt();
				if(open >= 0) new Fx.Scroll(window).toElement(headings[i]);
			}
		});
		
		collapsibles[i] = collapsible;
		
		heading.onclick = function(){
			collapsible.toggle();
			return false;
		}
		
		collapsible.hide();
		
	});	
}*/


// end INICIALIZACAO DO ACCORDION DAS FAQS


// INITIALIZER
window.addEvent('load',function() {
	accordionFaqs();
	
	if (Browser.Engine.trident4) {
		$$('.contentor_cx_pergunta_faq').addEvents({
			'mouseenter':function() {
				this.addClass('MouseEnter');
			},
			'mouseleave':function() {
				if (!this.hasClass('Open')) {
					this.removeClass('MouseEnter');
				}
			}
		});
	}
	
	if (Browser.Engine.trident4) {
		$$('.t1').addEvents({
			'mouseenter':function() {
				this.addClass('ActivoFix');
			},
			'mouseleave':function() {
				if (!this.hasClass('Open')) {
					this.removeClass('ActivoFix');
				}
			},
			'click':function() {
				this.toggleClass('Open');
			}
		});
	}
});



function CopiarDadosProponente()
{
	$(GetClientId('txtNome')).value = $(GetClientId('frm_prop_nome')).value;
	$(GetClientId('txtDataNascimento')).value = $(GetClientId('frm_prop_datanascimento')).value;
	//$(GetClientId('optionMasculino')).value = $(GetClientId('frm_prop_sexo')).value;
	$(GetClientId('txtNIF')).value = $(GetClientId('frm_prop_nif')).value;
	if ($(GetClientId('frm_prop_telefone')).value != "" && $(GetClientId('frm_prop_telefone')).value != null)
		$(GetClientId('txtTelefone')).value = $(GetClientId('frm_prop_telefone')).value;
	if ($(GetClientId('frm_prop_telemovel')).value != "" && $(GetClientId('frm_prop_telemovel')).value != null)
		$(GetClientId('txtTelemovel')).value = $(GetClientId('frm_prop_telemovel')).value;
	if ($(GetClientId('frm_prop_email')).value != "" && $(GetClientId('frm_prop_email')).value != null)
		$(GetClientId('txtEmail')).value = $(GetClientId('frm_prop_email')).value;
	var src = $(GetClientId('txtNome'));
	if(src!=null){														   
		getNomeAbreviado($(GetClientId('txtNomeAbreviado')), src.value, 26);
	}
}

function getNomeAbreviado(objname, val, len) 
{
	var obj = $(objname);
	if(obj==null){
	return;
	}			  
	
	if(obj.value!=""){
	return;
	}
	if(val!=null&&val.length<len){	
		obj.value=val;
		return;
	}
	
    var i,sMiddle,iNameLen,icurrlen;                                    
    val=val.replace(/\s+$/, ''); //Trim function
    if(val.split(' ')[0].length>len) {
            obj.value= val.split(' ')[0].substring(0,len);
            return;
    }
    sMiddle="";
    i=val.split(' ').length-1;
    iNameLen=val.split(' ')[0].length;
    while(i>0) {
        if(i==0) break;
        icurrlen=val.split(' ')[i].length;
        if(icurrlen<=len && (val.split(' ')[0].length+icurrlen+sMiddle.length)<len) {
            iNameLen+=icurrlen;
            sMiddle=val.split(' ')[i]+" "+sMiddle;
        }
        else { break; }
        i-=1;
    }                       
    obj.value=val.split(' ')[0]+" "+sMiddle.replace(/\s+$/, '');
}



//retorna o elemento sem a necessidade de adicionar o UserControl ID
function GetClientId(strid)
{
     var count=document.forms [ 0 ] . length ;
     var i = 0 ;
     var eleName;
     for (i = 0 ;  i < count ;  i++ )
     {
       eleName = document.forms [ 0 ] . elements [ i ] .id;
       pos=eleName.indexOf ( strid ) ;
       if(pos >= 0)  break;          
     }
    return eleName;
 }


/*
 * Funções de validação do questionário individual de saúde
 */
function Valida_DeclaroLeitura_Client(sender, e)
{
    e.IsValid = $(GetClientId('CHK_DeclaroLeitura')).checked;
}

/*Create / read / erase cookies */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function RoutineImagedisplay() {
	var sval;
	if(readCookie("MulticareImg")==null) {
		createCookie("MulticareImg",0,10000);
	}
	sval = readCookie("MulticareImg");
	
	if(sval==0) {
		document.getElementById('divTV2').style.display="";
		document.getElementById('divTV3').style.display="none";
		document.getElementById('divTV4').style.display="none";
		document.getElementById('divTV5').style.display="none";
		createCookie("MulticareImg",1,10000);
	}
	else if(sval==1) {
		document.getElementById('divTV2').style.display="none";
		document.getElementById('divTV3').style.display="";
		document.getElementById('divTV4').style.display="none";
		document.getElementById('divTV5').style.display="none";
		createCookie("MulticareImg",2,10000);
	}
	else if(sval==2) {
		document.getElementById('divTV2').style.display="none";
		document.getElementById('divTV3').style.display="none";
		document.getElementById('divTV4').style.display="";
		document.getElementById('divTV5').style.display="none";
		createCookie("MulticareImg",3,10000);
	}
	else {
		document.getElementById('divTV2').style.display="none";
		document.getElementById('divTV3').style.display="none";
		document.getElementById('divTV4').style.display="none";
		document.getElementById('divTV5').style.display="";
		createCookie("MulticareImg",0,10000);
	}
	return sval;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}