
//<script language="javascript">

$(document).ready(function() {
						   
		$(function() {
        	$("#slider").slider(
             { 
				 step: 1,
				 min: 1,
				 max: 3,
				 value: 2,
				 start: function(event, ui){ 
            	 	if (ui.value == 2) 
            	 		document.getElementById('Produto_cbRecheioValue').value = "50000";
            	 	
            	 	if (ui.value == 1) 
            	 		document.getElementById('Produto_cbRecheioValue').value = "25000";
            	 	
            	 	if (ui.value == 3) 
            	 		document.getElementById('Produto_cbRecheioValue').value = "100000";
             	},
				change: function(event, ui) {
					 var myValue; 
					 var myOutput;
					 
					 if (ui.value == 2) { 
						myValue = "50000";
						myOutput = "50.000€";
						$("#myDesc1").css("display","none");
						$("#myDesc2").css("display","block");
						$("#myDesc3").css("display","none");
					}
					
					if (ui.value == 1) {
						myValue = "25000";
						myOutput = "25.000€";
						$("#myDesc1").css("display","block");
						$("#myDesc2").css("display","none");
						$("#myDesc3").css("display","none");
					} 
					
					if (ui.value == 3) {
						myValue = "100000";
						myOutput = "100.000€";
						$("#myDesc1").css("display","none");
						$("#myDesc2").css("display","none");
						$("#myDesc3").css("display","block");
					}
					document.getElementById('myValue').innerHTML = myOutput;
					document.getElementById('Produto_cbRecheioValue').value = myValue;
					//alert( document.getElementById('Produto_cbRecheioValue').value );
             	}
			 });
        });
		
		$("#Produto_cbParedesN").bind("click",function(){			
			$("#divFranquia").css("display","none");
		});
		
		$("#Produto_cbParedesS").bind("click",function(){
			$("#divFranquia").css("display","block");
		});
		
		$("#Pessoais_cbClienteLogoN").bind("click",function(){			
			$("#divClLogoNif").css("display","none");
			$("#Pessoais_txtNIFDivError").css("display","none");			
		});
		
		$("#Pessoais_cbClienteLogoS").bind("click",function(){
			$("#divClLogoNif").css("display","block");
			$("#Pessoais_txtNIF").val($("#Pessoais_txtContribuinte").val());
		});
		
		$("#SimDetalhadoTabBt1").bind("click",function(){
			myOutput = validateTwo();
			if (myOutput == true) {
				resetWindows();
				$(this).removeClass("SimDetalhadoTab"); 
				$(this).addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt1Box").css("display","block");
			}
		});
		
		$("#mySendBTN1").bind("click",function(){
			myOutput = validateOne();
			if (myOutput == true) {
				resetWindows();
				$("#SimDetalhadoTabBt2").removeClass("SimDetalhadoTab"); 
				$("#SimDetalhadoTabBt2").addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt2Box").css("display","block");
			}
		});

		$("#SimDetalhadoTabBt2").bind("click",function(){
			myOutput = validateOne();
			if (myOutput == true) {
				resetWindows();
				$(this).removeClass("SimDetalhadoTab"); 
				$(this).addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt2Box").css("display","block");
			}
		});
		
		$("#mySendBTN2").bind("click",function(){
			myOutput = validateOne();
			myOutput2 = validateTwo()
			if (myOutput == true && myOutput2 == true) {
				resetWindows();
				$("#SimDetalhadoTabBt3").removeClass("SimDetalhadoTab"); 
				$("#SimDetalhadoTabBt3").addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt3Box").css("display","block");
			}
		});
		
		$("#SimDetalhadoTabBt3").bind("click",function(){
			myOutput = validateOne();
			myOutput2 = validateTwo()
			if (myOutput == true && myOutput2 == true) {
				resetWindows();
				$(this).removeClass("SimDetalhadoTab"); 
				$(this).addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt3Box").css("display","block");
			}
		});
	});	

	function changeSlider() {
		if( document.getElementById('Produto_cbRecheioValue').value == "0" ){
			var numAss = $("#Imovel_txtNumAssoalhadas").val();
			var areaBruta = $("#Imovel_txtAreaBruta").val();
			if (numAss >= 6 || areaBruta >= 300) {
				$("#slider").slider('value',3);
			} else if (numAss <= 3 || areaBruta <= 100) {
				$("#slider").slider('value',1);
			}else {
				$("#slider").slider('value',2);
			}
		}
	}
	
	function validateOne() {
		clearAllErrors();
		changeSlider();
		var blnValid = true;
			
		if ($('#Imovel_cmbAnoConstrucao').val() == "") {
			blnValid = false;
			errorMessage = "O preenchimento do Ano de Construção é obrigatório.";
			elem = $('#Imovel_cmbAnoConstrucao');
			elemDiv = $('#Imovel_cmbAnoConstrucaoDivError');
		}
		
		if ($('#Imovel_txtAreaBruta').val() == "" && blnValid == true) {
			blnValid = false;
			errorMessage = "O preenchimento da Área Bruta é obrigatório.";
			elem = $('#Imovel_txtAreaBruta');
			elemDiv = $('#Imovel_txtAreaBrutaDivError');
		}
		
		if ($('#Imovel_txtAreaBruta').val() > 600 && blnValid == true) {
			blnValid = false;
			errorMessage = "Em função da área bruta, agradecemos o favor de contactar a Linha LOGO (808 200 360).";
			elem = $('#Imovel_txtAreaBruta');
			elemDiv = $('#Imovel_txtAreaBrutaDivError');
		}
		
		if ($('#Imovel_txtNumAssoalhadas').val() == "" && blnValid == true) {
			blnValid = false;
			errorMessage = "O preenchimento do Número de <br>Assoalhadas é obrigatório.";
			elem = $('#Imovel_txtNumAssoalhadas');
			elemDiv = $('#Imovel_txtNumAssoalhadasDivError');			
		}
		
		if ($('#Imovel_txtNumAssoalhadas').val() > 12 && blnValid == true) {
			blnValid = false;
			errorMessage = "Em função do número de assoalhadas, agradecemos o favor de contactar a Linha LOGO (808 200 360).";
			elem = $('#Imovel_txtNumAssoalhadas');
			elemDiv = $('#Imovel_txtNumAssoalhadasDivError');
		}
		
		if ($('#Imovel_txtCodPostal').val() == "" && blnValid == true ) {
			blnValid = false;	
			errorMessage = "Preencha o Código Postal correctamente.";
			elem = $('#Imovel_txtCodPostal');	
			elemDiv = $('#Imovel_txtCodPostalDivError');
		}
		
		
		if ($('#Imovel_txtCodPostal').val() != "" && blnValid == true ) {
			var filter = /^[0-9]{4}$/;
			if( ! filter.test( $('#Imovel_txtCodPostal').val() ) ) blnValid = false;
			if( blnValid ) blnValid = formValidation_validateZip_PT( $('#Imovel_txtCodPostal').val() );	
			errorMessage = "Preencha o Código Postal correctamente.";
			elem = $('#Imovel_txtCodPostal');	
			elemDiv = $('#Imovel_txtCodPostalDivError');
		}
		
		if ($('#Imovel_txtCodRua').val() == "" && blnValid == true ) {
			blnValid = false;	
			errorMessage = "Preencha o Código Postal correctamente.";
			elem = $('#Imovel_txtCodRua');	
			elemDiv = $('#Imovel_txtCodPostalDivError');
		}
		
		if ($('#Imovel_txtCodRua').val() != "" && blnValid == true ) {
			var filter = /^[0-9]{3}$/;
			if( ! filter.test( $('#Imovel_txtCodRua').val() ) ) blnValid = false;
			errorMessage = "Preencha o Código Postal correctamente.";
			elem = $('#Imovel_txtCodRua');
			elemDiv = $('#Imovel_txtCodPostalDivError');	
		}

		if( blnValid == false ){				
			$("#"+elemDiv.attr('id')+"").html(errorMessage);
			$("#"+elemDiv.attr('id')+"").css("display","block");			
			elem.focus();
			return false;
		} else {
			clearAllErrors();
			return true;
		}
	}
	
	function validateTwo() {
		var blnValid = true;
		
		if ($('#Produto_cbParedesN').attr('checked') && $('#Produto_cbRecheioN').attr('checked') && blnValid == true) {
			blnValid = false;
			errorMessage = "Seleccione o tipo de protecção que pretende.";
			elem = $('#Produto_cbParedesN');			
		}
		
		if( blnValid == false ){
			$("#errorProduto").html(errorMessage);
			$("#errorProduto").css("display","block");
			elem.focus();
			return false;
		} else {
			clearAllErrors();
			return true;
		}
	}
	
	function validateLast() {
		clearAllErrors();
		var blnValid = true;
			
		if ($('#Pessoais_txtNome').val() == "" || $('#Pessoais_txtNome').val().lenght < 3) {
			blnValid = false;
			errorMessage = "O campo Nome é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtNome');
			elemDiv = $('#Pessoais_txtNomeDivError');
		}
		
		if ($('#Pessoais_txtTelemovel').val() == "" && blnValid == true) {
			blnValid = false;
			errorMessage = "O campo Telefone é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtTelemovel');
			elemDiv = $('#Pessoais_txtTelemovelDivError');
		}		
			
		if ($('#Pessoais_txtTelemovel').val() != "" && blnValid == true) {
			errorMessage = "O campo Telefone é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtTelemovel');
			elemDiv = $('#Pessoais_txtTelemovelDivError');
			var filter = /^[0-9]{9}$/;
				if( ! filter.test( $('#Pessoais_txtTelemovel').val() ) )  blnValid = false;		
					if( blnValid ){
						if( $('#Pessoais_txtTelemovel').val().charAt(0) != 9 ) blnValid = false;
						if( $('#Pessoais_txtTelemovel').val().charAt(1) != 6 && $('#Pessoais_txtTelemovel').val().charAt(1) != 1 && $('#Pessoais_txtTelemovel').val().charAt(1) != 3 && $('#Pessoais_txtTelemovel').val().charAt(1) != 2 ) blnValid = false;
						if( blnValid ){
							if( formValidation_isInvalidPhoneNumbers( $('#Pessoais_txtTelemovel').val() ) ) blnValid = false;
						}
					}
		
		}
				
		if ($('#Pessoais_txtContribuinte').val() != "" && blnValid == true) {
			if( !formValidation_isValidNIF( $('#Pessoais_txtContribuinte').val() ) || $('#Pessoais_txtContribuinte').val() == "123456789"  ) blnValid = false;			
			errorMessage = "O campo Contribuinte deve ser preenchido com um número válido.";
			elem = $('#Pessoais_txtContribuinte');
			elemDiv = $('#Pessoais_txtContribuinteDivError');
		}
	
		if ($('#Pessoais_txtEmail').val() == "" && blnValid == true) {
			blnValid = false;
			errorMessage = "O campo Email é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtEmail');
			elemDiv = $('#Pessoais_txtEmailDivError');
		}
		
		if ($('#Pessoais_txtEmail').val() != "" && blnValid == true) {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if( ! filter.test( $('#Pessoais_txtEmail').val() ) ) blnValid = false;
			errorMessage = "O campo Email é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtEmail');
			elemDiv = $('#Pessoais_txtEmailDivError');
		}
		
		if ($('#Pessoais_txtDataNascimento').val() == "" && blnValid == true) {
			blnValid = false;
			errorMessage = "O campo Data Nascimento é de preenchimento obrigatório.";
			elem = $('#Pessoais_txtDataNascimento');
			elemDiv = $('#Pessoais_txtDataNascimentoDivError');
		}
		
		if ($('#Pessoais_txtDataNascimento').val() != "" && blnValid == true) {
			blnValid = formValidation_validateDate( $('#Pessoais_txtDataNascimento').val(), "adulto");
			errorMessage = "Ano de nascimento inválido. Por favor, insira uma nova data de nascimento.";
			elem = $('#Pessoais_txtDataNascimento');
			elemDiv = $('#Pessoais_txtDataNascimentoDivError');
		}
		
		if ($('#Pessoais_txtDataInicioSeguro').val() == "" && blnValid == true) {				
			blnValid = false;
			errorMessage = "A data deverá ser a de hoje ou posterior.";
			elem = $('#Pessoais_txtDataInicioSeguro');
			elemDiv = $('#Pessoais_txtDataInicioSeguroDivError');
		}
		
		if ($('#Pessoais_txtDataInicioSeguro').val() != "" && blnValid == true) {		
			blnValid = formValidation_validateDate( $('#Pessoais_txtDataInicioSeguro').val(), "posterior");
			errorMessage = "A data deverá ser a de hoje ou posterior.";
			elem = $('#Pessoais_txtDataInicioSeguro');
			elemDiv = $('#Pessoais_txtDataInicioSeguroDivError');
		}
		
		
		if ($('#Pessoais_cbClienteLogoS').attr('checked') && blnValid == true) {
			errorMessage = "O campo Contribuinte deve ser preenchido com um número válido.";
			elem = $('#Pessoais_txtNIF');
			elemDiv = $('#Pessoais_txtNIFDivError');
			if ($('#Pessoais_txtNIF').val() == "") {
				blnValid = false;
			} else {
				if( !formValidation_isValidNIF( $('#Pessoais_txtNIF').val() ) || $('#Pessoais_txtNIF').val() == "123456789"  ) blnValid = false;
			}
		}
		
		if( blnValid == false ){
			$("#"+elemDiv.attr('id')+"").html(errorMessage);
			$("#"+elemDiv.attr('id')+"").css("display","block");			
			elem.focus();
			return false;
		} else {
			clearAllErrors();
			loadingDiv("show");
			var str = $("form").serialize();			
			$.post("sendSimulationData.php",$("form").serialize(),function(data){
				if(parseInt(data) == 0 || data.indexOf('SDBoxResult') == -1){
					loadingDiv("hide");
					$("#errorServicoIndisponivel").html("Ocorreu um erro ao processar a sua simulação.");
					$("#errorServicoIndisponivel").css("display","block");
				} else{
					loadingDiv("hide");
					$("#SitePathway").html("<a href=\"http://www.logo.pt/\" id=\"A1\">Homepage</a> &gt; <a href=\"https://ww3.logo.pt/PORTAL/home.aspx\" id=\"A2\">ÁREA CLIENTE</a> &gt; Resultado");
					$("#divSimulation").html("<div class=\"ContentSubTitle1\"><img src=\"Resources/Images/logo_header_promocional.gif\" alt=\"10% Desconto na compra do pacote Imóvel + Recheio\" title=\"10% Desconto na compra do pacote Imóvel + Recheio\" /></div>");			 
					$("#SimDetalhadoTabBts").css("display","none");
					$("#SimDetalhadoTabBt1Box").css("display","none");
					$("#SimDetalhadoTabBt2Box").css("display","none");
					$("#SimDetalhadoTabBt3Box").css("display","none");
					$("#SimDetalhadoTabBt4Box").css("display","block");
					$("#SimDetalhadoTabBt4Box").html(data);
					
				}
			});																										 
		}
	}
	
	function sendSimulation(myType) {	
		clearAllErrors();
		loadingDiv("show");
		$.post("genDocSendMail.php?mail_type="+myType,{myType: myType},function(data){
				if(parseInt(data.charAt(0)) != 1){
					loadingDiv("hide");
					$("#errorServicoIndisponivel").html("Ocorreu um erro ao processar o seu pedido.");
					$("#errorServicoIndisponivel").css("display","block");
				} else{
					loadingDiv("hide");
					$("#SimDetalhadoTabBt4Box").css("display","none");
					$("#divSimulation").css("display","none");
					$("#SysNotes1").css("display","none");
					$("#SimDetalhadoTabBt5Box").css("display","block");
					
					if (myType == "email") {
						$("#SimDetalhadoTabBt5Box").html("<center><a href=\"http://www.logo.pt\"><img src=\"Resources/Images/logo_output_mail.gif\" alt=\"Logo Casa\" title=\"Logo Casa\" border=\"0\"/></a></center>");
					} else {
                        var returnData = data.split("|");
						$("#SimDetalhadoTabBt5Box").html("<iframe src=\"http://network.actualtrade.eu/conv.php?cpnid=77dcfff43da5f231e0d61e87ea90ee8b&arg="+ $('#Pessoais_txtEmail').val() +"&argmon=" + returnData[1] + "\" frameborder=\"0\" width=\"1\" height=\"1\"></iframe> <center><a href=\"http://www.logo.pt\"><img src=\"Resources/Images/logo_output_buy.gif\" alt=\"Logo Casa\" title=\"Logo Casa\" border=\"0\"/></a></center>");
					}
				}
			});			
	}
	
	function goBack() {
		$.post("goBack.php",function(data){
				$("#SitePathway").html("<a href=\"http://www.logo.pt/\" id=\"A1\">Homepage</a> &gt; <a href=\"https://ww3.logo.pt/PORTAL/home.aspx\" id=\"A2\">ÁREA CLIENTE</a> &gt; Simulações");
				$("#divSimulation").html("<div class=\"ContentSubTitle1\"><img src=\"Resources/Images/logo_header_casa.gif\" alt=\"Seguro Habitação, Simulação Grátis\" title=\"Seguro Habitação, Simulação Grátis\" /></div>");			 
				$("#SimDetalhadoTabBt1").removeClass("SimDetalhadoTab"); 
				$("#SimDetalhadoTabBt1").addClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt3").removeClass("SimDetalhadoTabSelected"); 
				$("#SimDetalhadoTabBt3").addClass("SimDetalhadoTab"); 
				$("#SimDetalhadoTabBts").css("display","block");
				$("#SimDetalhadoTabBt1Box").css("display","block");
				$("#SimDetalhadoTabBt2Box").css("display","none");
				$("#SimDetalhadoTabBt3Box").css("display","none");
				$("#SimDetalhadoTabBt4Box").css("display","none");
			});			
	}
	function loadingDiv(myFlag) {
		if (myFlag == "show") {
			$("#fade").css("display","block");
			$("#errorsDiv").css("display","block");
		} else {
			$("#fade").css("display","none");
			$("#errorsDiv").css("display","none");
		}
	}
	
	function clearAllErrors() {
		$("#Imovel_txtNumAssoalhadasDivError").css("display","none");
		$("#Imovel_cmbAnoConstrucaoDivError").css("display","none");
		$("#Imovel_txtAreaBrutaDivError").css("display","none");
		$("#Imovel_txtCodPostalDivError").css("display","none");
		$("#Pessoais_txtNomeDivError").css("display","none");
		$("#Pessoais_txtTelemovelDivError").css("display","none");
		$("#Pessoais_txtContribuinteDivError").css("display","none");
		$("#Pessoais_txtEmailDivError").css("display","none");
		$("#Pessoais_txtDataNascimentoDivError").css("display","none");
		$("#Pessoais_txtDataInicioSeguroDivError").css("display","none");
		$("#Pessoais_txtNIFDivError").css("display","none");
		$("#errorProduto").css("display","none");
		$("#errorServicoIndisponivel").css("display","none");
	}
	
	function formValidation_validateDate( strValue, myType) {
		var objRegExp = /^\d{2}(\-)\d{2}\1\d{4}$/;

		//check to see if in correct format
		if(!objRegExp.test(strValue))
			return false; //doesn't match pattern, bad date
			
		var strSeparator = strValue.substring(2,3);
		var arrayDate = strValue.split(strSeparator);
		var myDate=new Date();
		myDate.setDate(myDate.getDate());
		
		var myDay = myDate.getDate() -1;
		var myMonth = myDate.getMonth()+1;
		var myYear = myDate.getFullYear();
		
	
		var myReceivedDate = new Date();
		myReceivedDate.setFullYear(arrayDate[2],arrayDate[1]-1,arrayDate[0]);
		var myTodayDate = new Date();
		
		
		if (myType == "adulto") {
			if ((myYear-18) < arrayDate[2]) return false; 								
		} 
				
		if (myType == "posterior") {			
			if ((myTodayDate > myReceivedDate)) return false;
		}
		
		return formValidation_validateDateDays( arrayDate[0], arrayDate[1], arrayDate[2] );
	}
	
	function formValidation_validateDateDays( day_val, month_val, year_val ){
		
		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,'03' : 31, 
							'04' : 30,'05' : 31,
							'06' : 30,'07' : 31,
							'08' : 31,'09' : 30,
							'10' : 31,'11' : 30,
							'12' : 31 }
							
		var intDay = parseInt( day_val, 10 ); 
			
		//check if month value and day value agree
		if(arrayLookup[month_val] != null) {
		  if(intDay <= arrayLookup[month_val] && intDay != 0)
			return true; //found in lookup table, good date
		}
			
		// verify biss year
		var intMonth = parseInt(month_val,10);
		if (intMonth == 2) { 
			var intYear = parseInt(year_val);
		 	if (intDay > 0 && intDay < 29) {
				return true;
			}
			else if (intDay == 29) {
				 if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0)) {
					// year div by 4 and ((not div by 100) or div by 400) ->ok
				 	return true;
				 }   
			}
		}
		return false;
	}
	
	function formValidation_isValidNIF(nif){
		var c;
		var checkDigit = 0;
		//Check if is not null, is numeric and if has 9 numbers
		if( nif != null && nif == parseInt(nif) && nif.length == 9 ){
			//Get the first number of NIF
			var c = nif.charAt(0);
			//Check firt number is (1, 2, 5, 6, 8 or 9)
			if(c == '1' || c == '2' || c == '5' || c == '6' || c == '8' || c == '9')
			{
				//Perform CheckDigit calculations
				checkDigit = c * 9;
				var i = 0;
				for(i = 2; i <= 8; i++)
				{
					checkDigit += nif.charAt(i-1) * (10-i);
				}
				checkDigit = 11 - (checkDigit % 11);
				//if checkDigit is higher than ten set it to zero
				if(checkDigit >= 10)
					checkDigit = 0;
				//Compare checkDigit with the last number of NIF
				//If equal the NIF is Valid.           
				if(checkDigit == nif.charAt(8))
					return true;           
			}       
		}
		return false;
	} 
	
	function formValidation_isInvalidPhoneNumbers( phone ){		
		var invalidPhones = ['211234567','961234567','911234567','931234567','921234567','960000000','961111111','962222222','963333333','964444444','965555555','966666666','967777777','968888888','969999999','910000000','911111111','912222222','913333333','914444444','915555555','916666666','917777777','918888888','919999999','930000000','931111111','932222222','933333333','934444444','935555555','936666666','937777777','938888888','939999999','920000000','921111111','922222222','923333333','924444444','925555555','926666666','927777777','928888888','929999999','210000000','211111111','212222222','213333333','214444444','215555555','216666666','217777777','218888888','219999999','969696969','910101010'];
		
		for( var i=0; i < invalidPhones.length; ++i ){
			if( phone == invalidPhones[i] ) return true;
		}
		return false;
	}	
	
	function formValidation_validateZip_PT( elemValue ){
							
		var postalCodesArray = ['1000','1048','1049','1050','1066','1067','1068','1069','1070','1092','1098','1099','1100','1149','1150','1166','1167','1169','1170','1199','1200','1208','1209','1249','1250','1269','1300','1349','1350','1399','1400','1449','1495','1499','1500','1549','1600','1649','1675','1679','1685','1689','1700','1748','1749','1750','1769','1800','1849','1885','1886','1900','1949','1950','1959','1990','1998','2000','2004','2005','2009','2025','2040','2050','2054','2065','2070','2080','2090','2100','2120','2125','2130','2135','2139','2140','2150','2200','2205','2230','2240','2250','2260','2300','2305','2330','2350','2380','2384','2395','2400','2404','2405','2410','2414','2415','2419','2420','2424','2425','2430','2435','2440','2445','2450','2460','2461','2475','2480','2485','2490','2495','2499','2500','2504','2510','2520','2525','2530','2540','2550','2560','2565','2580','2581','2590','2594','2600','2601','2605','2609','2610','2614','2615','2616','2619','2620','2621','2625','2626','2630','2634','2635','2639','2640','2644','2645','2649','2650','2654','2655','2659','2660','2664','2665','2669','2670','2674','2675','2680','2681','2685','2689','2690','2691','2694','2695','2699','2700','2704','2705','2706','2709','2710','2714','2715','2719','2720','2724','2725','2729','2730','2734','2735','2739','2740','2744','2745','2749','2750','2754','2755','2756','2760','2761','2765','2769','2770','2774','2775','2779','2780','2784','2785','2789','2790','2794','2795','2799','2800','2804','2805','2809','2810','2814','2815','2819','2820','2821','2825','2829','2830','2834','2835','2839','2840','2844','2845','2855','2860','2864','2865','2870','2890','2894','2900','2904','2910','2914','2925','2929','2950','2951','2954','2955','2959','2965','2970','2975','2985','3000','3004','3020','3025','3030','3034','3040','3044','3045','3049','3050','3054','3060','3070','3080','3084','3090','3094','3100','3105','3130','3140','3150','3200','3220','3230','3240','3250','3260','3270','3280','3300','3305','3320','3330','3350','3360','3400','3405','3420','3430','3440','3450','3460','3464','3465','3475','3500','3504','3505','3510','3514','3515','3519','3520','3525','3530','3534','3550','3560','3570','3600','3610','3620','3624','3630','3640','3650','3660','3670','3680','3684','3700','3701','3720','3730','3740','3744','3750','3754','3770','3780','3800','3804','3810','3814','3830','3840','3850','3860','3864','3865','3870','3880','3884','3885','4000','4049','4050','4099','4100','4149','4150','4169','4199','4200','4249','4250','4269','4300','4349','4350','4369','4400','4404','4405','4409','4410','4414','4415','4420','4425','4430','4434','4435','4440','4445','4450','4454','4455','4460','4464','4465','4470','4471','4474','4475','4479','4480','4484','4485','4486','4490','4495','4500','4504','4505','4510','4515','4520','4525','4535','4540','4550','4560','4564','4570','4575','4580','4585','4590','4595','4599','4600','4605','4610','4615','4620','4625','4630','4635','4640','4650','4660','4690','4700','4704','4705','4709','4710','4714','4715','4719','4720','4730','4740','4745','4750','4755','4760','4764','4765','4770','4775','4780','4785','4795','4800','4804','4805','4809','4810','4814','4815','4820','4824','4825','4830','4835','4839','4840','4845','4850','4860','4870','4880','4890','4900','4904','4905','4910','4920','4925','4930','4935','4939','4940','4950','4960','4970','4974','4980','4990','5000','5004','5030','5040','5050','5054','5060','5070','5085','5090','5100','5110','5114','5120','5130','5140','5150','5155','5160','5180','5200','5210','5225','5230','5300','5301','5320','5335','5340','5350','5360','5370','5385','5400','5425','5430','5445','5450','5460','5470','6000','6004','6005','6030','6040','6050','6060','6090','6100','6110','6120','6150','6160','6185','6200','6201','6215','6225','6230','6250','6260','6270','6285','6290','6300','6301','6320','6324','6350','6355','6360','6370','6400','6420','6430','6440','7000','7004','7005','7009','7040','7050','7080','7090','7100','7150','7160','7170','7200','7220','7230','7240','7250','7300','7301','7320','7330','7340','7350','7354','7370','7374','7400','7425','7430','7440','7450','7460','7470','7480','7490','7500','7520','7540','7555','7565','7570','7580','7595','7600','7630','7645','7665','7670','7700','7750','7780','7800','7801','7830','7860','7875','7885','7900','7920','7940','7960','8000','8004','8005','8009','8100','8104','8125','8135','8136','8150','8200','8201','8300','8365','8375','8400','8401','8500','8501','8550','8600','8601','8650','8670','8700','8800','8801','8900','8950','8970','9000','9004','9020','9024','9030','9050','9054','9060','9064','9100','9125','9135','9200','9225','9230','9240','9270','9300','9304','9325','9350','9360','9370','9385','9400','9500','9504','9545','9555','9560','9580','9600','9625','9630','9650','9675','9680','9700','9701','9760','9800','9850','9875','9880','9900','9901','9904','9930','9940','9950','9960','9970','9980'];
							
		var zip4 = elemValue.substring(0,4);
		for ( var i=0; i < postalCodesArray.length; ++i ){
			if( zip4 == postalCodesArray[i] )
				return true;
		}
		return false;	
	}
	
	function resetWindows() {
		$("#SimDetalhadoTabBt1").removeClass("SimDetalhadoTabSelected");
		$("#SimDetalhadoTabBt2").removeClass("SimDetalhadoTabSelected");
		$("#SimDetalhadoTabBt3").removeClass("SimDetalhadoTabSelected");
		$("#SimDetalhadoTabBt1").addClass("SimDetalhadoTab");
		$("#SimDetalhadoTabBt2").addClass("SimDetalhadoTab");
		$("#SimDetalhadoTabBt3").addClass("SimDetalhadoTab");	
		$("#SimDetalhadoTabBt1Box").css("display","none");
		$("#SimDetalhadoTabBt2Box").css("display","none");
		$("#SimDetalhadoTabBt3Box").css("display","none");
		$("#SimDetalhadoTabBt4Box").css("display","none");
	}
	
	function numbersOnly(myfield, e, dec) {
		var key;
		var keychar;
		
		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;
		else
		   return true;
		keychar = String.fromCharCode(key);
		
		// control keys
		if ((key==null) || (key==0) || (key==8) ||
			(key==9) || (key==13) || (key==27) )
		   return true;
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
		   return true;
		
		// decimal point jump
		else if (dec && (keychar == ".")) {
		   myfield.form.elements[dec].focus();
		   return false;
		} else if (((keychar == ".")||(keychar == ",")) && dec && (dec==true)) {
		   return true;
		} else
		   return false;
	}
	
	/* highlight nos campos de texto não preenchidos BEGIN */
	function hlTxtFieldFocus(thistxtfield) {
			thistxtfield.className = thistxtfield.className.replace( ' InputTxtNoFill', '' );
			return true;
	}
	
	function hlTxtFieldBlur(thistxtfield) {
			thistxtfield.className = thistxtfield.className += ' InputTxtNoFill';
			return true;
	}
	
	function hlTxtField(thistxtfield) {
		if ( thistxtfield.value.length == 0 ) {
			hlTxtFieldBlur(thistxtfield);
		}
		else {
			hlTxtFieldFocus(thistxtfield);
		}
		return true;
	}
	
	/* highlight nos campos de texto não preenchidos END */
	
	function d_in( o ){_i=o;_i.vla=_i.value }
	
	var newwindow;
	function popup(url)
	{
		newwindow= window.open(url,'Tabela de Coberturas','height=600,width=750,scrollbars=1');
		if (window.focus) {newwindow.focus()}
	}	
	
	
	function toogleObjectProtection( show ){
		if( show ){
			$("#proprietaryDamagesDiv1").css("display", "block");
			$("#proprietaryDamagesDiv2").css("display", "block");
		}
		else{
			$("#proprietaryDamagesDiv1").css("display", "none");
			$("#proprietaryDamagesDiv2").css("display", "none");
		}
	}
	
	
	function updateNIF( box_updated ){
		if( box_updated == 1 ){
			$("#Pessoais_txtNIF").val( $("#Pessoais_txtContribuinte").val() );
		}
		else{
			$("#Pessoais_txtContribuinte").val( $("#Pessoais_txtNIF").val() );
		}
	}
