// JavaScript Document

function show(id)  // funcção genérica para esconder e mostrar objectos simples pelo ID
{
     if (document.getElementById(id).style.display == 'none')
     {
          document.getElementById(id).style.display = '';
     }
}

function myFuncPrint()
{

	document.getElementById('actual').style.display='';
    document.getElementById('percent1').style.display = '';
    document.getElementById('percent2').style.display = '';
    	
	window.print();
	
	document.getElementById('actual').style.display = '';
	document.getElementById('percent1').style.display= 'none';
	document.getElementById('percent2').style.display= 'none';
	
	return false;
	
}
//-->

<!--
function hide(id)
{
          document.getElementById(id).style.display = 'none';

}

function mostra(strNomeMostrar) {
	document.getElementById(strNomeMostrar).style.display="";
}

function esconde(strNomeEsconder) {

	document.getElementById(strNomeEsconder).style.display="none";
}


function finalidade(input){  //função para mostrar/esconder objectos pelo botao de select e para retornar caso nao seja selecionado a transferencia
	
	if ( (input.value == '5') )  // este 5 é o value do select da transferencia
		mostra('tblTransferencia');  // o tblTranferencia é o nome da div com os campos que entram na transferencia
	else	
		esconde('tblTransferencia');
	
		}


function tipoHabitacao(input){  //função para mostrar/esconder objectos pelo botao de select e para retornar caso nao seja selecionado a habitação propia
	matchelement('txtCompraTerreno').value='';
	if (input.value == '1')  //  values do select quem mostram o objecto com o id emprestimoTerreno
		mostra('_ctl0_emprestimoTerreno');  // o emprestimoTerreno é o nome da div com o campo para ineserir valor do emprestimo do terreno
		
	else	
		esconde('_ctl0_emprestimoTerreno');
		
		}		
		
		
function tipoTaxa(input){  //função para mostrar/esconder objectos pelo botao de select e para retornar caso nao seja selecionado a habitação propia
	
	if ( IDEuribor.indexOf(input.value) <0 )  // values do select quem mostram o objecto com o id taxaPeriodoSeguinte
		mostra('taxaPeriodoSeguinte');  
	else
	{	
		esconde('taxaPeriodoSeguinte');
		
		var cboEuribor = matchelement('cbotaxaeuribor');
		cboEuribor.value=0;
	}
		
}	
				
		
function out(id) {

  id.style.backgroundColor='#FFFFFF';}



function over(id) {

  id.style.backgroundColor='#999999';
}


function __ValidateEcran1 ( source, args )
{
	var ret = true;
	var html = "";
	var summary = "";
	var oEmprestimo= matchelement('emprestimo');
	var oDt1= matchelement('dt1');
	var oDt2= matchelement('dt2');
	var trfsValorMensal= matchelement('trfsValorMensal');
	var trfsRemanescente = matchelement('trfsRemanescente');
	var emprestimoMinimo = 0;
	var minimoRemanescente =0 ;
	
	setCorrigirSpan ( 'corrigirEmprestimo', false );
	setCorrigirSpan ( 'corrigirDt1', false );
	setCorrigirSpan ( 'corrigirDt2', false );
	setCorrigirSpan ( 'corrigirValorMensal', false );
	setCorrigirSpan ( 'corrigirRemanescente', false );
	
	var ocboFinalidade = matchelement( 'cboFinalidade' );
	
	
	emprestimoMinimo  = aEmprestimoMinimo[ocboFinalidade.value-1];
	
	minimoRemanescente = aRemanescente[ocboFinalidade.value-1];
	
	if ( ( matchNumber( 'emprestimo' ) == false ) || ( oEmprestimo.value.length==0 ) )
	{
		
		html = html + "<li>Por favor indique o valor de empr%E9stimo.</li>";	
		setCorrigirSpan ( 'corrigirEmprestimo', true );
		ret = false;
		
	}else
	{
		if ( parseInt(oEmprestimo.value)<emprestimoMinimo) 
		{
			html = html + "<li>O valor do empr%E9stimo ter%E1 que ser igual ou superior que " + emprestimoMinimo + " %u20AC.</li>";
			setCorrigirSpan ( 'corrigirEmprestimo', true );
			ret = false
		}
	}
	
	var nretIdade = 0;
	var nretIdade2 =0;
	nretIdade = __CalcIdade( oDt1.value, 'txtIdade1', 1 );
	switch  ( nretIdade ) 
	{
		case -2:
		{
			html = html + "<li>Por favor indique a idade do 1%BA proponente entre " + idadeMinima + " e " + idadeMaxima + " anos.</li>";	
			setCorrigirSpan ( 'corrigirDt1', true );
			ret = false;
			break;
		}
		case -1:
		{
			html = html + "<li>Data inv%E1lida, formato correcto : dd/mm/aaaa ou dd-mm-aaaa.</li>";	
			setCorrigirSpan ( 'corrigirDt1', true );
			ret = false;
			break;
		}
	}
	
	if (matchelement('nprop1').checked==false) 
	{
		matchelement('txtIdade2').value='';
		nretIdade2= __CalcIdade( oDt2.value, 'txtIdade2', 0 );
	
		switch  ( nretIdade2 ) 
		{
			case -2:
			{
				html = html + "<li>Por favor indique a idade do 2%BA proponente entre " + idadeMinima + " e " + idadeMaxima + " anos.</li>";	
				setCorrigirSpan ( 'corrigirDt2', true );
				ret = false;
				break;
			}
			case -1:
			{
				html = html + "<li>Data inv%E1lida, formato correcto : dd/mm/aaaa ou dd-mm-aaaa.</li>";	
				setCorrigirSpan ( 'corrigirDt2', true );
				ret = false;
				break;
			}
		}
		
	}
	
	if ( nretIdade2>nretIdade )  { nretIdade = nretIdade2 ;}
	
	if ( matchelement('cboFinalidade').value==5)
	{
		if ( ( matchNumber( 'trfsValorMensal' ) == false ) || ( trfsValorMensal.value.length==0 ) )
		{
			html = html + "<li>Por favor indique o valor da presta%E7%E3o.</li>";	
			setCorrigirSpan ( 'corrigirValorMensal', true );
			ret = false;
		}else
		{
			if ( parseInt( trfsValorMensal.value ) <= 0 ) {
				html = html + "<li>O valor da presta%E7%E3o ter%E1 que ser maior que zero.</li>";	
				setCorrigirSpan ( 'corrigirValorMensal', true );
				ret = false;
			}
		}
		
		
		if ( ( matchNumber( 'trfsRemanescente' ) == false ) || ( trfsRemanescente.value.length==0 ))
		{
			html = html + "<li>Por favor indique o prazo do remanescente do empr%E9stimo.</li>";	
			setCorrigirSpan ( 'corrigirRemanescente', true );
			ret = false;
		}else
		{
			if ( parseInt( trfsRemanescente.value ) < minimoRemanescente ) {
				html = html + "<li>O prazo remanescente ter%E1 que ser igual ou superior que " + minimoRemanescente + " anos.</li>";	
				setCorrigirSpan ( 'corrigirRemanescente', true );
				ret = false;
			}
			
			// 30 anos 
			if ( nretIdade<30 ) { nretIdade=30 }
			
			if ( ( ret == true ) && ( parseInt(trfsRemanescente.value) > ( parseInt(idadeMaxima) + 1 - nretIdade )  ) ) 
			{
			
				html = html + "<li>O prazo remanescente ter%E1 que ser inferior ou igual a " + (idadeMaxima + 1 - nretIdade )+ " anos .</li>";	
				setCorrigirSpan ( 'corrigirRemanescente', true );
				ret = false;
				
			}
		}
	}
	
	
	summary = "validationSummary1";
	
	if (!ret)
	{
		
		html = returnMsgHeader(html)
		
		document.getElementById(summary).style.display = "";
		document.getElementById(summary).innerHTML = unescape( html );
	}
	
	args.IsValid = ret;
}



function __CalcIdade(sDate1, sObjName, iReqValidation){
	var now;
	var sDateField1, sDateField2;
	var idade=0;
	var fOk = true;
	var msg;
		
	msg='';
	if (sDate1 != '' || iReqValidation == 1 ) {
	
		sDateField1 = Date.parse(sDate1);
		if (isNaN(sDateField1))
		{
			msg = "A data %E9 um campo obrigat%F3rio, num%E9rico e em formato dd/mm/aaaa ou dd-mm-aaaa.";
			idade=-1;
			fOk = false;		
		}
		else
		{
		
			idade = CheckDateMinMax(sDate1);
			
			if ( idade == -1) {
				msg = "Data inv%e1lida, formato correcto : dd/mm/aaaa ou dd-mm-aaaa.";
				
				fOk=false;
			}
			if ( idade == -2) {
			
				msg = "";
				
				fOk=false;
			}
		}
		if (fOk==true) {
			
			matchelement(sObjName).value=idade;
			}
			
	}
	else
	{
			msg = "A data %E9 um campo obrigat%F3rio, num%E9rico e em formato dd/mm/aaaa ou dd-mm-aaaa.";
			fOk = ( iReqValidation != 1 )
	}
	
	if  ( ( fOk == false )  &&  ( msg != '' ) ) 
	{
	//	alertUnescape(msg);
	}
	
	
	return idade;
	
}


function CheckDateMinMax(dateStr) 
{
	var now = new Date();
	var returnDate=0;
	var dayField, monthField, yearField;
	
	dateArr = dateStr.split('/');
	if (dateArr.length != 3) dateArr = dateStr.split('-');
	
	dayField = dateArr[0];
	monthField = dateArr[1];
	yearField = dateArr[2];
	
	if (isNaN(dayField) || isNaN(monthField) || isNaN(yearField)) returnDate = -1;
	if ((monthField < 0) || (monthField > 12)) returnDate = -1;
	if (dayField < 0) returnDate = -1;
	if (dayField > MonthDays(monthField, yearField)) returnDate = -1;
	
	if ( returnDate==0 ) 
	{
		returnDate = now.getYear() - yearField;
		
		if ( ( monthField>(now.getMonth() + 1) ) )
		{
			
			returnDate = returnDate - 1
			
		}
	}	
	
	if ( ( parseInt(returnDate)<idadeMinima ) || ( parseInt(returnDate)>idadeMaxima ) )  returnDate=-2;
	
	return returnDate;
	
}


function MonthDays(inMonth, inYear) {
	switch (inMonth) {
		case '1','3','5','7','8','10','12':
			return 31;
		case '4', '6', '9', '11':
			return 30;
		case '2':
			if ((inYear % 4) == 0)
				return 29;
			else
				return 28;			
		default:
				return 31;
	}
}


/* ecran simulador */
// begin obras projectadas 
function __ValidateEcran3 ( source, args )
{
	var ret = true;
	var emprestimo = matchelement('txtEmprestimo');
	var escritura = matchelement('txtEscritura');
	var avaliacao = matchelement('txtAvaliacao');
	var prazo  = matchelement('txtPrazo');
	var prazoDecorrido = matchelement( 'txtPrazoDecorrido' );
	var txtRAB = matchelement('txtRAB');
	var cbocaixa = matchelement('cboCaixa');
	var cbotaxa = matchelement ( 'cbotaxa' );
	var cbotaxaeuribor = matchelement('cbotaxaeuribor');
	var html = "";
	var emprestimoMinimo = 0;
	var tipoHabitacao = matchelement('tipoHabitacao');
	var msgEmprestimo = true;
	
	
	emprestimo = parseFloat( emprestimo.value.replace(',','.') );
	escritura = parseFloat( escritura.value.replace(',','.') );
	avaliacao = parseFloat( avaliacao.value.replace(',','.') );
	
	
	if ( finalidade == 3 ) 
	{
		var ValorObrasProj = matchelement('txtValorObrasProj');	
		ValorObrasProj = parseFloat( ValorObrasProj.value.replace(',','.') );
		setCorrigirSpan ( 'corrigirValorObrasProjectadas', false );
	}
	
	emprestimoMinimo  = aEmprestimoMinimo[var_finalidade - 1];
	
	if ( var_finalidade == 2 ) 
	{
		setCorrigirSpan ( 'corrigirTxtCompraTerreno', false );
	}
	
	setCorrigirSpan ( 'corrigirTxtEmprestimo', false );
	setCorrigirSpan ( 'corrigirTxtEscritura', false );
	setCorrigirSpan ( 'corrigirTxtAvaliacao', false );
	
	setCorrigirSpan ( 'corrigirTxtPrazo', false );
	setCorrigirSpan ( 'corrigirTxtRAB', false );
	setCorrigirSpan ( 'corrigirCboCaixa', false );
	
	if ( matchelement('txtDespesas') != 'undefined' )
	{
		setCorrigirSpan ( 'corrigirTxtDespesas', false );
		if ( matchelement('txtDespesas').value.length>0 ) 
		{
			if ( matchNumber( 'txtDespesas' ) == false  ) 
			{
				html = html + "<li>Por favor indique o valor das Despesas Adicionias Anuais.</li>";	
				setCorrigirSpan ( 'corrigirTxtDespesas', true );
				ret = false;
			}
		}
	}
	
	if ( ( matchNumber( 'txtEmprestimo' ) == false ) || ( matchelement('txtEmprestimo').value.length==0 ) )
	{
		html = html + "<li>Por favor indique o valor de empr%E9stimo.</li>";	
		setCorrigirSpan ( 'corrigirTxtEmprestimo', true );
		ret = false;
		
	}else
	{
	
		if ( emprestimo < emprestimoMinimo ) 
		{

			if ( var_finalidade == 5 )  
			{
				if ( tipoHabitacao.value != 3 )
				{
					msgEmprestimo = false;
				}
			}
			if ( msgEmprestimo == true ) 
			{
				html = html + "<li>O valor do empr%E9stimo ter%E1 que ser igual ou superior que " + emprestimoMinimo + ".</li>";
				setCorrigirSpan ( 'corrigirTxtEmprestimo', true );
				ret = false
			}
		}
	}
	
	if ( var_finalidade==2 )
	{
		if ( ( matchNumber( 'txtCompraTerreno' ) == false )  )
		{
		
			html = html + "<li>Por favor indique o valor do terreno.</li>";	
			setCorrigirSpan ( 'corrigirTxtCompraTerreno', true );
			ret = false;
			
		}
	}
	
	if ( ( matchNumber( 'txtEscritura' ) == false ) || ( matchelement('txtEscritura').value.length==0 ) )
	{
		html = html + "<li>Por favor indique o valor da escritura.</li>";	
		setCorrigirSpan ( 'corrigirTxtEscritura', true );
		ret = false;
		
	}else
	{
		if ( escritura < emprestimo )
		{
			html = html + "<li>O valor da escritura ter%E1 que ser superior ou igual ao valor do empr%E9stimo.</li>";
			setCorrigirSpan ( 'corrigirTxtEscritura', true );
			ret = false
		}
	}
	
	if ( ( matchNumber( 'txtAvaliacao' ) == false ) || ( matchelement('txtAvaliacao').value.length==0 ) )
	{
		html = html + "<li>Por favor indique o valor da avalia%E7%E3o.</li>";	
		setCorrigirSpan ( 'corrigirTxtAvaliacao', true );
		ret = false;
		
	}else
	{
		if	( var_finalidade == 3 )  //finalidade obras
		{
			
			if ( ( matchNumber( 'txtValorObrasProj' ) == false ) || ( matchelement('txtValorObrasProj').value.length==0 ) )
			{
				html = html + "<li>Por favor indique o valor da obras projectadas.</li>";
				setCorrigirSpan ( 'corrigirValorObrasProjectadas', true );
				ret = false
			}else
			{
				var percEmprestimo=aPercEmprestimo[var_finalidade-1];
				var valorMinimoObras = ( ( emprestimoMinimo  * 100 ) / percEmprestimo );
				if ( ValorObrasProj  <  valorMinimoObras )
				{
					html = html + "<li>O valor das obras projectadas ter%E1 que ser superior ou igual " + valorMinimoObras + " %u20AC.</li>";
					setCorrigirSpan ( 'corrigirValorObrasProjectadas', true );
					ret = false 
				}
			}
			
			if ( avaliacao < escritura ) 
			{
				html = html + "<li>O valor da avalia%E7%E3o ter%E1 que ser superior ou igual ao valor da escritura.</li>";
				setCorrigirSpan ( 'corrigirTxtAvaliacao', true );
				ret = false
			}
			
			if ( ( emprestimo * 100 / percEmprestimo ) > avaliacao ) 
			{
				html = html + "<li>O valor da avalia%E7%E3o ter%E1 que ser superior ou igual a " + emprestimo * 100 / percEmprestimo + " %u20AC.</li>";
					setCorrigirSpan ( 'corrigirTxtAvaliacao', true );
				ret = false 
			}
			
			
		}
		
		if ( ( avaliacao < emprestimo  ) && ( var_finalidade != 3 )  )// obras
		{
			html = html + "<li>O valor da avalia%E7%E3o ter%E1 que ser superior ou igual ao valor do empr%E9stimo.</li>";
			setCorrigirSpan ( 'corrigirTxtAvaliacao', true );
			ret = false
		}
	}
	
	if ( var_finalidade== 5 ) // transferencias 
	{
		// { prazo, valor };
		var aLimites;
		var aLimitesPrazo;
		var aLimitesValor;
		
		setCorrigirSpan ( 'corrigirPrazoDecorrido', false );
		
		if ( ( matchNumber( 'txtPrazoDecorrido' ) == false ) || ( prazoDecorrido.value.length==0 ) )
		{
			html = html + "<li>Por favor indique o prazo decorrido.</li>";	
			setCorrigirSpan ( 'corrigirPrazoDecorrido', true );
			ret = false;
		
		}else
		{
			if (  tipoHabitacao.value == 3 )  // transferencia geral 
			{
				aLimites = aLimitesTransf[0]; 
				aLimitesValor = aLimites[0];
				aLimitesPrazo = aLimites[1];
				
				
			}else  
			{
				// transferencias bonificadas
				aLimites = aLimitesTransf[1]; 
				aLimitesValor = aLimites[0];
				aLimitesPrazo = aLimites[1];
				
				
			}
			
			if ( ( ret == true)  && ( parseInt(prazoDecorrido.value) + parseInt(prazo.value) ) > aLimitesPrazo[1] )
			{
				html = html + "<li>O prazo decorrido mais o prazo do empr%E9stimo n%E3o pode ser superior a " + aLimitesPrazo[1] + " anos.</li>";
				setCorrigirSpan ( 'corrigirPrazoDecorrido', true );
				ret = false
			}
		
			
			if ( parseInt(prazo.value) > parseInt(aLimitesPrazo[1]) )
			{
				html = html + "<li>O prazo do empr%E9stimo n%E3o pode ser superior a " + aLimitesPrazo[1] + " anos.</li>";
				setCorrigirSpan ( 'corrigirTxtPrazo', true );
				ret = false
			}
			if ( parseInt(prazo.value) < parseInt(aLimitesPrazo[0]) )
			{
				html = html + "<li>O prazo do empr%E9stimo n%E3o pode ser inferior a " + aLimitesPrazo[0] + " anos.</li>";
				setCorrigirSpan ( 'corrigirTxtPrazo', true );
				ret = false
			}
			
			if (emprestimo > parseInt(aLimitesValor[1]))
			{
				html = html + "<li>O emprestimo n%E3o pode ser superior a " + aLimitesValor[1] + " euros.</li>";
				setCorrigirSpan('corrigirTxtEmprestimo', true);
				ret = false;
			}
			if (emprestimo < parseInt(aLimitesValor[0]))
			{
			
				html = html + "<li>O emprestimo n%E3o pode ser inferior a " + aLimitesValor[0] + " euros.</li>";
				setCorrigirSpan('corrigirTxtEmprestimo', true);
				ret = false;
				
			}
			
			// transf. bonificados
			
			if ( ( tipoHabitacao.value == 1 )  || (tipoHabitacao.value == 2) )
			{	
			
				setCorrigirSpan ( 'corrigirNumElem', false );
				var NumElem = matchelement('txtNumElem');
				if ( ( matchNumber( 'txtNumElem' ) == false ) || ( NumElem.value.length==0 ) )
				{
					html = html + "<li>Por favor indique o n%BA de elementos do agregado familiar.</li>";	
					setCorrigirSpan ( 'corrigirNumElem', true );
					ret = false;
				
				}else
				{
					if (NumElem.value<=0)
					{
						html = html + "<li>O n%BA de elementos do agregado familiar ter%E1 que ser maior que zero.</li>";	
						setCorrigirSpan ( 'corrigirNumElem', true );
						ret = false;
					}
				}
			}
		}
		
		if ( ( matchNumber( 'txtPrazo' ) == false ) || ( prazo.value.length==0 ) )
		{
			html = html + "<li>Por favor indique um prazo para o empr%E9stimo.</li>";	
			setCorrigirSpan ( 'corrigirTxtPrazo', true );
			ret = false;
			
		}else
		{
			
			if ( parseInt( prazo.value ) < aTaxaPrazo[cbotaxa.selectedIndex] )
			{
				html = html + "<li>O prazo de empr%E9stimo ter%E1 que ser superior ou igual ao periodo da taxa fixa.</li>";	
				setCorrigirSpan ( 'corrigirTxtPrazo', true );
				ret = false;
			}
		}
		
	}else
	{
		//outras finalidades excepto transferencias
		if ( ( matchNumber( 'txtPrazo' ) == false ) || ( prazo.value.length==0 ) )
		{
			html = html + "<li>Por favor indique um prazo para o empr%E9stimo.</li>";	
			setCorrigirSpan ( 'corrigirTxtPrazo', true );
			ret = false;
			
		}else
		{
			
			if ( parseInt(prazo.value) > prazoMaximo )
			{
			
				html = html + "<li>Por favor indique o prazo do empr%E9stimo at%E9 " + prazoMaximo + " anos.</li>";
				setCorrigirSpan ( 'corrigirTxtPrazo', true );
				ret = false
			}
			if ( parseInt( prazo.value ) < aTaxaPrazo[cbotaxa.selectedIndex] )
			{
				html = html + "<li>O prazo de empr%E9stimo ter%E1 que ser superior ou igual ao periodo da taxa fixa.</li>";	
				setCorrigirSpan ( 'corrigirTxtPrazo', true );
				ret = false;
			}
		}
		
	}
	
	// carencia 
	var nRetCarencia =0;
	var CarenciaPerc = parseInt( aCarencia[1] );
	var CarenciaMeses = parseInt( aCarencia[0] );
	
	if ( CarenciaPerc > 0 ) 
	{
	   nRetCarencia = (CarenciaPerc / 100) * (prazo.value * 12);
       if ( ( nRetCarencia > CarenciaMeses )  && ( CarenciaMeses > 0 ) )
			nRetCarencia = CarenciaMeses;
       
	}else
	{
		nRetCarencia = CarenciaMeses;
	}
	
	if  ( ( matchelement( 'cboCarencia' ).value > nRetCarencia  ) && ( nRetCarencia >0 )  )
	{
		html = html + "<li>A carencia ter%E1 que ser menor ou igual a " + nRetCarencia + " meses.</li>";	
		setCorrigirSpan ( 'corrigirCarencia', true );
		ret = false;
	}
	

	
	if ( IDEuribor.indexOf(cbotaxa.value) <0 ) 
	{
		if ( cbotaxaeuribor.value==0)
		{
			html = html + "<li>Por favor indique uma taxa euribor.</li>";	
			setCorrigirSpan ( 'corrigirTaxaEuribor', true );
			ret = false;
		}
	}
	
	
	if ( ( matchNumber( 'txtRAB' ) == false ) || ( txtRAB.value.length==0 ) )
	{
		html = html + "<li>Por favor indique o valor do Rendimento Anual.</li>";	
		setCorrigirSpan ( 'corrigirTxtRAB', true );
		ret = false;
		
	}else
	{
			
		if ( parseInt(txtRAB.value) == 0 )
		{
			html = html + "<li>O valor Rendimento Anual ter%E1 que ser maior que zero.</li>";				
			setCorrigirSpan ( 'corrigirTxtRAB', true );
			ret = false
		}
	}
	
	if ( cbocaixa.value==0 ) 
	{
		html = html + "<li>Por favor seleccione a caixa associada %E0 simula%E7%E3o.</li>";
		setCorrigirSpan ( 'corrigirCboCaixa', true );
		ret = false;
	}
	
	
	summary = "validationSummary1";
	
	if (!ret)
	{
		
		html = returnMsgHeader(html)
		
		document.getElementById(summary).style.display = "";
		document.getElementById(summary).innerHTML = unescape( html );
	}
	else
	{
		switch ( var_finalidade )
		{
		case 3:
			{
			
			__avisoObras( var_finalidade ) ;
			break;
			
			}
			
		default:
			{
			__aviso( var_finalidade ) ;
			break;
			}
		}	
		
		
		
	}
	
	args.IsValid = ret;
	
}

function _ChangeEmprestimoObras()
{
	var percEmprestimo = aPercEmprestimo[3-1];
	var emprestimo = matchelement('txtEmprestimo');
	
	matchelement('txtEscritura').value = emprestimo.value;
	matchelement( 'txtValorObrasProj' ).value = emprestimo.value * 100 / percEmprestimo ;
	matchelement( 'txtAvaliacao' ).value = emprestimo.value * 100 / percEmprestimo ;
	
}

// end obras projectadas.

function __ValidateEcran3Multi ( source, args )
{
	var ret = true;
	var emprestimo = matchelement('emprestimoMulti');
	var escritura = matchelement('escrituraMulti');
	var prazo  = matchelement('prazoMulti');
	var spread = matchelement('spreadMulti');
	var html = "";
	
	setCorrigirSpan ( 'corrigirEmprestimoMulti', false );
	setCorrigirSpan ( 'corrigirEscrituraMulti', false );
	setCorrigirSpan ( 'corrigirPrazoMulti', false );
	
	if ( ( matchNumber( 'emprestimoMulti' ) == false ) || ( emprestimo.value.length==0 ) || ( emprestimo.value==0 ) )
	{
	
		html = html + "<li>Por favor indique o valor de empr%E9stimo.</li>";	
		setCorrigirSpan ( 'corrigirEmprestimoMulti', true );
		ret = false;
		
	}else
	{
		if ( parseInt(emprestimo.value) > parseInt(emprestimo.value) )
		{
			html = html + "<li>O valor do empr%E9stimo pretendido ultrapassa o valor da escritura, deve ser igual ou inferior.</li>";
			setCorrigirSpan ( 'corrigirEmprestimoMulti', true );
			ret = false
		}
	}
	
	if ( ( matchNumber( 'escrituraMulti' ) == false ) || ( escritura.value.length==0 ) || ( escritura.value==0 ) )
	{
		html = html + "<li>Por favor indique o valor da escritura.</li>";	
		setCorrigirSpan ( 'corrigirEscrituraMulti', true );
		ret = false;
		
	}
	
	if ( ( matchNumber( 'prazoMulti' ) == false ) || ( prazo.value.length==0 ) || ( prazo.value==0 ) )
	{
		html = html + "<li>Por favor indique um prazo para o empr%E9stimo.</li>";	
		setCorrigirSpan ( 'corrigirPrazoMulti', true );
		ret = false;
		
	}else
	{
		if ( parseInt(prazo.value) > prazoMaximo )
		{
			html = html + "<li>Por favor indique o prazo do empr%E9stimo at%E9 " + prazoMaximo + " anos.</li>";
			setCorrigirSpan ( 'corrigirPrazoMulti', true );
			ret = false
		}
		
	}
	
	if ( ( matchNumber( 'spreadMulti' ) == false ) || ( spread.value.length==0 ) || ( spread.value==0 ) )
	{
	
		html = html + "<li>Por favor indique o valor do spread.</li>";	
		setCorrigirSpan ( 'corrigirSpreadMulti', true );
		ret = false;
		
	}
	
	summary = "validationSummary1";
	
	if (!ret)
	{
		
		html = returnMsgHeader(html)
		
		document.getElementById(summary).style.display = "";
		document.getElementById(summary).innerHTML = unescape( html );
	}
	
	//ret=false;
	args.IsValid = ret;
	
}

// begin obras projectadas
function __avisoObras(vfinalidade)
{
	var emprestimo = matchelement( 'txtEmprestimo' );
	var escritura = matchelement( 'txtEscritura' );
	var objAvaliacao = matchelement( 'txtAvaliacao' );
	var msgAlerta = "";
	var percEmprestimo=aPercEmprestimo[vfinalidade-1];
	var ObjValorObrasProjectadas=matchelement( 'txtValorObrasProj' );
	var ValorObrasProjectadas=0;
	var fValida=false;
	
	emprestimo = parseFloat(emprestimo.value);
	escritura = parseFloat(escritura.value);
	avaliacao = parseFloat(objAvaliacao.value);
	
	valorObrasProjectadas = parseFloat( ObjValorObrasProjectadas.value );
	valorObrasProjectadas = valorObrasProjectadas * ( percEmprestimo / 100 );
	
	if ( emprestimo > valorObrasProjectadas ) 
	{
		msgAlerta = 'O montante para o empr%E9stimo n%E3o pode ultrapassar ' + percEmprestimo + '% do valor das obras projectadas. Neste caso, o valor das obras projectadas dever%E1 ser de ' + emprestimo * 100 / percEmprestimo + ' %u20AC.';
		fValida = ( emprestimo > valorObrasProjectadas ) 
	}
	
	if ( fValida == true  ) 
	{
		alertUnescape ( msgAlerta );
		matchelement( 'txtValorObrasProj' ).value  = emprestimo * 100 / percEmprestimo;
		
	}
	
	matchelement( 'txtEscritura' ).value = matchelement( 'txtEscritura' ).value.replace('.', ',');
	matchelement( 'txtEmprestimo' ).value = matchelement( 'txtEmprestimo' ).value.replace('.', ',');
	matchelement( 'txtAvaliacao' ).value = matchelement( 'txtAvaliacao' ).value.replace('.', ',');
	matchelement( 'txtValorObrasProj' ).value = matchelement( 'txtValorObrasProj' ).value.replace('.', ',');
	
	
}



function __aviso(vfinalidade)
{
	var emprestimo = matchelement( 'txtEmprestimo' );
	var escritura = matchelement( 'txtEscritura' );
	var objAvaliacao = matchelement( 'txtAvaliacao' );
	var msgAlerta = ""; msgAlerta2 = "";
	var valorComp=0;
	var percEmprestimo=aPercEmprestimo[vfinalidade-1];
	var fValida = false;
	emprestimo = parseFloat(emprestimo.value);
	escritura = parseFloat(escritura.value);
	avaliacao = parseFloat(objAvaliacao.value);
	valorComp = parseFloat(avaliacao);
	
	valorComp = valorComp * ( percEmprestimo / 100 )
	
	var isJovem = false;
	
	if ( document.Form1.hcboRegime.value=='G' )
	{
		
		isJovem=( parseInt(document.Form1.hIdade1.value) <= 30 ) ;
		
		if ( ( isJovem==false ) && ( document.Form1.hIdade2.value != 'undefined' ) )
		{
			isJovem=( parseInt(document.Form1.hIdade2.value) <= 30 ) ;
		}
	}
	
			
	if ( isJovem == false ) 
	{
		if ( intranet == 1 ) 
		{
			msgAlerta = 'O valor do empr%E9stimo pretendido ultrapassa '+ percEmprestimo +  '% do valor da avalia%E7%E3o. Confirme com o respons%E1vel do seu balc%E3o a disponibilidade para a concretiza%E7%E3o do empr%E9stimo nestas condi%E7%F5es.';
			fValida = ( emprestimo >= valorComp ) 		
			
		}else
		{
			
			msgAlerta = 'O montante para o empr%E9stimo n%E3o pode ultrapassar ' + percEmprestimo + '% do valor da avalia%E7%E3o. Neste caso dever%E1 ser de ' + valorComp  + ' %u20AC.';
			msgAlerta2 = 'Se pretende informa%E7%F5es de financiamento at%E9 100% do valor de avalia%E7%E3o, agradecemos que contacte a sua Caixa Associada.' ;		
			fValida = ( emprestimo > valorComp ) 
		}
		
	}
	
	if ( fValida == true  ) 
	{
		alertUnescape ( msgAlerta );
		if ( msgAlerta2 != '' ) 
		{
			alertUnescape ( msgAlerta2 );
		}
		
		if ( intranet != 1 ) {	
			matchelement( 'txtEmprestimo' ).value = valorComp.toString();
		}
	
		
	}
	
	matchelement( 'txtEscritura' ).value = matchelement( 'txtEscritura' ).value.replace('.', ',');
	matchelement( 'txtEmprestimo' ).value = matchelement( 'txtEmprestimo' ).value.replace('.', ',');
	matchelement( 'txtAvaliacao' ).value = matchelement( 'txtAvaliacao' ).value.replace('.', ',');
		
	
}

// end obras

function __ValidateEcran4 ( source, args )
{
	var ret = true;
	var taxa = matchelement('txtTaxa');
	var html='';
	var summary = "validationSummary1";
	
	setCorrigirSpan ( 'corrigirTaxa', false );
	
	if ( ( matchNumber( 'txtTaxa' ) == false ) || ( taxa.value.length==0 ) )
	{
		html = html + "<li>Por favor indique o valor da taxa juros.</li>";	
		setCorrigirSpan ( 'corrigirTaxa', true );
		ret = false;
		
	}else
	{
		if ( parseInt(taxa.value)<=0 ) 
		{
			html = html + "<li>A taxa ter%E1 que ser maior que zero.</li>";	
			setCorrigirSpan ( 'corrigirTaxa', true );
			ret = false;
		}
	}
	
	if ( ret == true )
	{
		matchelement('txtTaxa').value =taxa.value.replace('.', ',');
	}
	
	if (!ret)
	{
		
		html = returnMsgHeader(html)
		
		document.getElementById(summary).style.display = "";
		document.getElementById(summary).innerHTML = unescape( html );
	}
	
	
	args.IsValid = ret;	
		
}

function writeDebug(s)
{
	alert(s);
}