/* author: IBERBULEI, Lda */
/* Creation date: 10-03-2006 */
//------------------------------------------------------------------------
//	Verificação dos Campos que são de preenchimento obrigatorio
//------------------------------------------------------------------------
/* Nome do Cliente (Ecrã Geral,Sinal e Transferencia) */
function Preencher_Nome(tipo_index){
		if(tipo_index == 'sg'){
				if (document.Indice_Geral.txt_nome.value == ""){
				    alert('Por favor preencha o campo "Nome".');
				    return false;
				}else{ return true;}
				
		}else if(tipo_index == 'ss'){
				if (document.Indice_Sinal.txt_nome.value == ""){
				    alert('Por favor preencha o campo "Nome".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_nome.value == ""){
				    alert('Por favor preencha o campo "Nome".');
				    return false;
				}else{ return true;}
		}
}
/* Idades dos Titulares(Ecrã Geral,Sinal e Transferencia) */
function Preencher_Idades(tipo_index,ver){
var f_submit;
		if(tipo_index == 'sg')
		{
				if(document.Indice_Geral.sl_titulares.selectedIndex==0||document.Indice_Geral.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade está preenchida, senão valida a idade do campo				  
					if (document.Indice_Geral.txt_idade_1.value == " " || document.Indice_Geral.txt_idade_1.value == eval('0')){
				    	alert('Por favor preencha o campo "Idade do 1º Titular".');
						return false;
					}
				}
				if(document.Indice_Geral.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade e segunda idade está preenchida	
					if (ver=='1'){
						if (document.Indice_Geral.txt_idade_2.value == " " || document.Indice_Geral.txt_idade_2.value == eval('0')){
				   			alert('Por favor preencha o campo "Idade do 2º Titular".');
							return false;
						}
					}
				}
				f_submit = Validar_Max_Idade(tipo_index,ver);
				return f_submit;
		}else if(tipo_index == 'ss'){
				if(document.Indice_Sinal.sl_titulares.selectedIndex==0||document.Indice_Sinal.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade está preenchida, senão valida a idade do campo				  
					if (document.Indice_Sinal.txt_idade_1.value == " " || document.Indice_Sinal.txt_idade_1.value == eval('0')){
				    	alert('Por favor preencha o campo "Idade do 1º Titular".');
						return false;
					}
				}
				
				if(document.Indice_Sinal.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade e segunda idade está preenchida	
					if (ver=='1'){
						if (document.Indice_Sinal.txt_idade_2.value == " " || document.Indice_Sinal.txt_idade_2.value == eval('0')){
				   			alert('Por favor preencha o campo "Idade do 2º Titular".');
							return false;
						}
					}
				}
				f_submit = Validar_Max_Idade(tipo_index,ver);
				return f_submit;			
		}else if(tipo_index == 'st'){
				if(document.Indice_Transferencia.sl_titulares.selectedIndex==0 || document.Indice_Transferencia.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade está preenchida, senão valida a idade do campo				  
					if (document.Indice_Transferencia.txt_idade_1.value == " " || document.Indice_Transferencia.txt_idade_1.value == eval('0')){
				    	alert('Por favor preencha o campo "Idade do 1º Titular".');
						return false;
					}
				}
				if(document.Indice_Transferencia.sl_titulares.selectedIndex==1){
					//verifica se o campo da primeira idade e segunda idade está preenchida	
					if (ver=='1'){
						if (document.Indice_Transferencia.txt_idade_2.value == " " || document.Indice_Transferencia.txt_idade_2.value == eval('0')){
				   			alert('Por favor preencha o campo "Idade do 2º Titular".');
							return false;
						}
					}
				}
				f_submit = Validar_Max_Idade(tipo_index,ver);
				return f_submit;
		}	
}

/* Valor de Financiamento (Ecrã Geral,Sinal e Transferencia) */
function Preencher_ValFinanciamento(tipo_index){
//É chamada atraves da rotina de Validar valor dos Financiamentos
		if(tipo_index == 'sg'){
				if (document.Indice_Geral.txt_valor_financiamento.value == "" || document.Indice_Geral.txt_valor_financiamento.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Financiamento".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'ss'){
				if (document.Indice_Sinal.txt_valor_financiamento.value == "" || document.Indice_Sinal.txt_valor_financiamento.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Financiamento".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_valor_financiamento.value == "" || document.Indice_Transferencia.txt_valor_financiamento.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Financiamento".');
				    return false;
				}else{ return true;}
		}
}
/* Prazo em anos (Ecrã Geral,Sinal e Transferencia) */
function Preencher_ValPrazo(tipo_index){
//É chamada atraves da rotina de Validar valor dos Prazos
		if(tipo_index == 'sg'){
				if (document.Indice_Geral.txt_prazo_anos.value == "" || document.Indice_Geral.txt_prazo_anos.value == eval('0')){
				    alert('Por favor preencha o campo "Prazo".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'ss'){
				if (document.Indice_Sinal.txt_prazo_anos.value == "" || document.Indice_Sinal.txt_prazo_anos.value == eval('0')){
				    alert('Por favor preencha o campo "Prazo".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_prazo_anos.value == "" || document.Indice_Transferencia.txt_prazo_anos.value == eval('0')){
				    alert('Por favor preencha o campo "Prazo".');
				    return false;
				}else{ return true;}
		}
}
/* Prazo em anos decorridos do financiamento inicial(Transferencia) */
function Preencher_ValPrazoAnosDecorridos(tipo_index,passou){
//É chamada atraves da rotina de Validar valor dos Prazos
		if(tipo_index == 'sg'){
			return true;
		}else if(tipo_index == 'ss'){
			return true;
		}else if(tipo_index == 'st'){
			if(passou=='s'){
				if (document.Indice_Transferencia.txt_anos_decorridos.value == "" || document.Indice_Transferencia.txt_anos_decorridos.value == eval('0')){
				    alert('Por favor preencha o campo "Prazo decorrido".');
				    return false;
				}else{return true;}
			}
		}
}
/* Valor de Aquisição (Ecrã Geral e Transferencia) */
function Preencher_ValAquisicao(tipo_index){
		if(tipo_index == 'sg'){
				if (document.Indice_Geral.txt_valor_aquisicao.value == "" || document.Indice_Geral.txt_valor_aquisicao.value == eval('0')){
				    alert('Por favor preencha o campo "Valor da Aquisição".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'ss'){
				if (document.Indice_Sinal.txt_valor_aquisicao.value == "" || document.Indice_Sinal.txt_valor_aquisicao.value == eval('0')){
				    alert('Por favor preencha o campo "Valor da Aquisição".');
				    return false;
				}else{ return true;}					
		}else if(tipo_index == 'st'){
		/*
				if (document.Indice_Transferencia.txt_montante_inicial.value == "" || document.Indice_Transferencia.txt_montante_inicial.value == eval('0')){
				    alert('Por favor preencha o campo "Montante Inicial".');
				    return false;
				}else{ */
				return true;
		}
}
/* Valor de Imovel (Ecrã Geral e Transferencia) */
function Preencher_ValImovel(tipo_index){
		if(tipo_index == 'sg'){
				if (document.Indice_Geral.txt_valor_imovel.value == "" || document.Indice_Geral.txt_valor_imovel.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Imóvel".');
				    return false;
				}else{ return true;}
		}else if(tipo_index == 'ss'){
				if (document.Indice_Sinal.txt_valor_imovel.value == "" || document.Indice_Sinal.txt_valor_imovel.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Imóvel".');
				    return false;
				}else{ return true;}				
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_valor_imovel.value == "" || document.Indice_Transferencia.txt_valor_imovel.value == eval('0')){
				    alert('Por favor preencha o campo "Valor do Imóvel".');
				    return false;
				}else{ return true;}
		}
}
/* Valor de Montante INICIAL (Ecrã Transferencia) */
/*
function Preencher_ValMontanteInicial(tipo_index){
		if(tipo_index == 'sg'){
			return true;
		}else if(tipo_index == 'ss'){
			return true;
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_montante_inicial.value == "" || document.Indice_Transferencia.txt_montante_inicial.value == eval('0')){
				    alert('Por favor preencha o campo "Montante Inicial".');
				    return false;
				}else{ return true;}
		}
}*/
/* Valor de Capital em Dívida (Ecrã Transferencia) */
function Preencher_ValCapitalDivida(tipo_index){
		if(tipo_index == 'sg'){
			return true;
		}else if(tipo_index == 'ss'){
			return true;
		}else if(tipo_index == 'st'){
				if (document.Indice_Transferencia.txt_capital_divida.value == "" || document.Indice_Transferencia.txt_capital_divida.value == eval('0')){
				    alert('Por favor preencha o campo "Capital em Dívida".');
				    return false;
				}else{ return true;}
		}
}

/* Vai procurar todos os campos para ver se não existem zeros ou vazios no submit */
function Validar_Preenchimento_Geral(tipo_index,p_seg,f_submit){
	//fazer o das idades (por ser por combobox)
	var ver;
	if(tipo_index=='st'){f_submit = Validar_ValorFinanciamento_CapitalDivida();}else{f_submit=true;}
	
	if(f_submit==true){
	f_submit = Preencher_Nome(tipo_index);
	//alert('nome');	
	//alert(f_submit);	
	if(f_submit==true){
		//alert('idades preenchidas');			
		f_submit = Preencher_Idades(tipo_index,ver);
		//alert(f_submit);	
		if(f_submit==true){
			f_submit = Validar_Max_Idade(tipo_index,ver);
			//alert('max idades');		
			//alert(f_submit);	
			//if(f_submit==true){
				//f_submit = Preencher_ValMontanteInicial(tipo_index);
				//alert('mont inicical');			
				//alert(f_submit);			
				if(f_submit==true){
					f_submit = Preencher_ValCapitalDivida(tipo_index);
					//alert('c divida');		
					//alert(j_p);	
					if(f_submit==true){
						f_submit = Preencher_ValFinanciamento(tipo_index);
						//alert('v finan');		
						//alert(j_p);	
						//if(tipo_index=='st'){f_submit = Preencher_ValPrazoAnosDecorridos('st','s');}else{f_submit=true;}
						if(f_submit==true){
							f_submit = Preencher_ValPrazo(tipo_index);
							//alert('v prazo');		
							//alert(f_submit);								
							if(f_submit==true){
								f_submit = Preencher_ValAquisicao(tipo_index);
								//alert('v aquisicao');		
								//alert(f_submit);	
								if(f_submit==true){
								 	f_submit = Preencher_ValImovel(tipo_index);
									//alert('v imovel');		
									//alert(f_submit);	
									if(f_submit==true){
										f_submit = Validar_ValorFinanciamento_ValorAquisicao(tipo_index);
										if(f_submit==true){
											f_submit = Validar_Prazo_Anos(tipo_index,'','',true);
											//alert('prazo validacao');	
											//alert(f_submit);	
											if(f_submit==true){
												Faz_Submit(tipo_index);
											}												
										}	
									}	
								}	
							}	
						}	
					}	
				}		
			//}								Validar_ValorFinanciamento_CapitalDivida
			}			
		}	
	}
}

