var LoanAmount=0;
var EffectiveYearlyInterest=0;
var MonthlyCosts_PriveLimietPlus=0;
var MonthlyCosts_FlexibelKrediet =0;
var MonthlyCosts_PersoonlijkeLening=0;
var TotalPriceLoan_PriveLimietPlus=0;
var TotalPriceLoan_FlexibelKrediet=0;
var TotalPriceLoan_PersoonlijkeLening=0;
var EffectiveYearlyInterest_PriveLimietPlus=0;
var EffectiveYearlyInterest_FlexibelKrediet=0;
var EffectiveYearlyInterest_PersoonlijkeLening=0;
var flagKey = false;


var EffectiveYearlyInterestPLP=0;
var EffectiveYearlyInterestFK=0;
var EffectiveYearlyInterestPl=0;
var value_loanFinal = 0;
var sessionData = new SessionData();
function getSessionData_kort(){
	if(sessionData.hasVal('amt'))
		value_loanFinal=sessionData.getVal('amt');
	else value_loanFinal='';
	
	}
// Function for getting interest rate from the array
function getInterestRate(tempArray, tempLoanAmount){
	var tempYearlyInterestRate = 0;
	for ( i = 0 ; i < tempArray.length ; i++ ){
		for ( j = 0 ; j < tempArray[i].length ; j++ ){
			if ( (j != 2) && (tempLoanAmount >= tempArray[i][j] && tempLoanAmount < tempArray[i][j+1]) ){
				tempYearlyInterestRate = tempArray[i][2] ;
				break;
			}else if( tempLoanAmount == tempArray[i][j+1] ){
				tempYearlyInterestRate = tempArray[i][2];
				break;
			}
		}
	}
	return tempYearlyInterestRate;
}

function callingDefalutValues()
{
	updateComponent('val_yearlyInterest_PLP',strText_dots);
	updateComponent('val_yearlyInterest_FK',strText_dots);
	updateComponent('val_YearlyInterestPl',strText_dots);
	updateComponent('val_MonthlyCosts_PriveLimietPlus', strText_dots) ;
    updateComponent('val_MonthlyCosts_FlexibelKrediet',strText_dots) ;
    updateComponent('val_ MonthlyCosts_PersoonlijkeLening',strText_dots) ;
	updateComponent('val_TotalPriceLoan_PLP',strText_dots) ;
    updateComponent('val_TotalPriceLoan_FK',strText_dots) ;
    updateComponent('val_TotalPriceLoan_Pl',strText_dots) ;
	updateComponent('val_TheoreticalDuration_PLP',strText_dots) ;
    updateComponent('val_TheoreticalDuration_FK',strText_dots) ;
    updateComponent('val_TheoreticalDuration_Pl',strText_dots) ;
	updateComponent('val_AnnualCost_PLP',strText_dots) ;
	updateComponent('val_AnnualCost_FK',strText_dots) ;
	updateComponent('val_AnnualCost_Pl',strText_dots) ;
 }

function ChangePercentage(percentValue)
{
   var temPercVal = percentValue.split('.');
   var allZero = 1;
   
   for(i=0;i<temPercVal[1].length;i++)
   {
		if(temPercVal[1].substring(i,i+1) != 0)
		{
			allZero = 0;
			break;
		}
   }
   if(allZero == 1)
   {
		percentValue = temPercVal[0] + ".0";
   }
   return percentValue;
}
 
function EffectiveYearlyInterest_PLP(){
	LoanAmount=stripPeriodsFromAmount(document.getElementById('txtLoanAmount'));
	
	var yearlyInterest_PLP = 0;
	yearlyInterest_PLP = getInterestRate(arrEIP_PLP, LoanAmount);
	EffectiveYearlyInterestPLP = parseFloat(yearlyInterest_PLP);
	
	updateComponent('val_EffectiveYearlyInterestP',formatValue(Math.round(EffectiveYearlyInterestPLP))) ;
	if(yearlyInterest_PLP!=0)
	{
		updateComponent('val_yearlyInterest_PLP',formatAsPercentage(roundNumber(yearlyInterest_PLP, 1))) ;
	}
	else
	    updateComponent('val_yearlyInterest_PLP',strText_dots) ;
}

function EffectiveYearlyInterest_FK(){
	LoanAmount=stripPeriodsFromAmount(document.getElementById('txtLoanAmount'));
	var yearlyInterest_FK=0;
	yearlyInterest_FK = getInterestRate(arrEIP_FK, LoanAmount);
	EffectiveYearlyInterestFK = parseFloat(yearlyInterest_FK) ;
	
	updateComponent('val_EffectiveYearlyInterestFK',formatValue(Math.round(EffectiveYearlyInterestFK))) ;
	if(yearlyInterest_FK!=0)
	{	
		updateComponent('val_yearlyInterest_FK',formatAsPercentage(roundNumber(yearlyInterest_FK, 1))) ;
	}
	else
	    updateComponent('val_yearlyInterest_FK',strText_dots) ;
}



function EffectiveInterestPercentage_Pl()
{
	LoanAmount=stripPeriodsFromAmount(document.getElementById('txtLoanAmount'));
	var YearlyInterestPl=0;
   
	YearlyInterestPl = getInterestRate(arrEIP_Pl, LoanAmount);
    EffectiveYearlyInterestPl = parseFloat(YearlyInterestPl);
 
	updateComponent('val_EffectiveYearlyInterestPl',formatValue(Math.round(EffectiveYearlyInterestPl))) ;
	if(YearlyInterestPl!=0)
	{
		updateComponent('val_YearlyInterestPl',formatAsPercentage(roundNumber(YearlyInterestPl, 1))) ;
	}
	else
	    updateComponent('val_YearlyInterestPl',strText_dots) ;
		
}



function Monthly_Costs()
{
	 LoanAmount=stripPeriodsFromAmount(document.getElementById('txtLoanAmount'));
	 MonthlyCosts_PriveLimietPlus = (parseFloat(fltCreditLimit_PriveLimietPlusPerc) * parseFloat(LoanAmount))/100;
	 MonthlyCosts_FlexibelKrediet = (parseFloat(fltCreditLimit_FlexibelKredietPerc) * parseFloat(LoanAmount))/100;
	 MonthlyCosts_PersoonlijkeLening = (parseFloat(fltCreditLimit_PersoonlijkeLening) * parseFloat(LoanAmount))/100;
	 if(EffectiveYearlyInterestPLP!=0)
		updateComponent('val_MonthlyCosts_PriveLimietPlus', strEUR+" "+roundNumber1(MonthlyCosts_PriveLimietPlus,0) + strStep1_postLabel);
	 else
		updateComponent('val_MonthlyCosts_PriveLimietPlus', strText_dots) ;
	 if(EffectiveYearlyInterestFK!=0)
		updateComponent('val_MonthlyCosts_FlexibelKrediet',strEUR+" "+formatValue(MonthlyCosts_FlexibelKrediet.toFixed(0))) ;
	 else
	    updateComponent('val_MonthlyCosts_FlexibelKrediet',strText_dots) ;
	 if(EffectiveYearlyInterestPl!=0)
		updateComponent('val_ MonthlyCosts_PersoonlijkeLening',strEUR+" "+formatValue(MonthlyCosts_PersoonlijkeLening.toFixed(0))) ;
	 else
	    updateComponent('val_ MonthlyCosts_PersoonlijkeLening',strText_dots) ;
		
} 


function Monthly_Interest_Percentage()
{
	var EYI_PLP = EffectiveYearlyInterestPLP/100;
	MonthlyInterestPercentage_PriveLimietPlus = ((Math.pow((1+parseFloat(EYI_PLP)),(1/12)))-1)*100;
	MonthlyInterestPercentage_PriveLimietPlus = truncate(MonthlyInterestPercentage_PriveLimietPlus,4);
	
	var EYI_FK =   EffectiveYearlyInterestFK/100;
	MonthlyInterestPercentage_FlexibelKrediet = ((Math.pow((1+parseFloat(EYI_FK)),(1/12)))-1)*100;
	MonthlyInterestPercentage_FlexibelKrediet = truncate(MonthlyInterestPercentage_FlexibelKrediet,4);
	
	var EYI_Pl = EffectiveYearlyInterestPl/100;
	MonthlyInterestPercentage_PersoonlijkeLening =((Math.pow((1+parseFloat(EYI_Pl)),(1/12)))-1)*100;
    MonthlyInterestPercentage_PersoonlijkeLening = truncate( MonthlyInterestPercentage_PersoonlijkeLening,4);

}


function Theoretical_Duration()
{
Monthly_Interest_Percentage();

var MC_PLP = Math.round(MonthlyCosts_PriveLimietPlus);
var MIP_PLP = MonthlyInterestPercentage_PriveLimietPlus/100;
var LA = LoanAmount;
TheoreticalDuration_PriveLimietPlus = Math.log(parseFloat(MC_PLP)/(parseFloat(MC_PLP)-parseFloat(MIP_PLP)*parseFloat(LA)))/Math.log(1+parseFloat(MIP_PLP));

var MC_FK = Math.round(MonthlyCosts_FlexibelKrediet);
var MIP_FK = MonthlyInterestPercentage_FlexibelKrediet/100;
TheoreticalDuration_FlexibelKrediet = Math.log(parseFloat(MC_FK)/(parseFloat(MC_FK)-parseFloat(MIP_FK)*parseFloat(LA)))/Math.log(1+parseFloat(MIP_FK));

var MC_Pl = Math.round(MonthlyCosts_PersoonlijkeLening);
var MIP_Pl = MonthlyInterestPercentage_PersoonlijkeLening/100;
TheoreticalDuration_PlKrediet = Math.log(parseFloat(MC_Pl)/(parseFloat(MC_Pl)-parseFloat(MIP_Pl)*parseFloat(LA)))/Math.log(1+parseFloat(MIP_Pl));

if(!isNaN(TheoreticalDuration_PriveLimietPlus))
	updateComponent('val_TheoreticalDuration_PLP',(Math.ceil(TheoreticalDuration_PriveLimietPlus))+" "+strText_maanden) ;
else
   updateComponent('val_TheoreticalDuration_PLP',strText_dots) ;
        
if(!isNaN(TheoreticalDuration_FlexibelKrediet))
	updateComponent('val_TheoreticalDuration_FK',(Math.ceil(TheoreticalDuration_FlexibelKrediet))+" "+strText_maanden) ;
else
   updateComponent('val_TheoreticalDuration_FK',strText_dots) ;

if(!isNaN(TheoreticalDuration_PlKrediet))
	updateComponent('val_TheoreticalDuration_Pl',(Math.ceil(TheoreticalDuration_PlKrediet))+" "+strText_maanden) ;    
else
  updateComponent('val_TheoreticalDuration_Pl',strText_dots) ;
} 


function TotalPriceLoan()
{
var TotalPriceLoan_PLP = parseFloat((roundNumber(MonthlyCosts_PriveLimietPlus,1)) + MonthlyExtraCoast) * parseFloat(Math.ceil(TheoreticalDuration_PriveLimietPlus));

var TotalPriceLoan_FK = parseFloat(Math.round(MonthlyCosts_FlexibelKrediet)) * parseFloat(Math.ceil(TheoreticalDuration_FlexibelKrediet));

var TotalPriceLoan_Pl = parseFloat(Math.round(MonthlyCosts_PersoonlijkeLening)) * parseFloat(Math.ceil(TheoreticalDuration_PlKrediet));
    
if(!isNaN(TotalPriceLoan_PLP))
	updateComponent('val_TotalPriceLoan_PLP',strEUR+" "+formatAsCurrency(Math.round(TotalPriceLoan_PLP))) ;
else
   	updateComponent('val_TotalPriceLoan_PLP',strText_dots) ;
if(!isNaN(TotalPriceLoan_FK))
	updateComponent('val_TotalPriceLoan_FK',strEUR+" "+formatAsCurrency(Math.round(TotalPriceLoan_FK))) ;
else
    updateComponent('val_TotalPriceLoan_FK',strText_dots) ;
if(!isNaN(TotalPriceLoan_Pl))
	updateComponent('val_TotalPriceLoan_Pl',strEUR+" "+formatAsCurrency(Math.round(TotalPriceLoan_Pl))) ;
else
   updateComponent('val_TotalPriceLoan_Pl',strText_dots) ;

}
//New row
function AnnualCoastPercentage()
{  
var TotalAnnualCoast_PLP = CalculateVal_AnnualCost_PLP();
var TotalAnnualCost_FK = parseFloat(EffectiveYearlyInterestFK);
var TotalAnnualCost_Pl = parseFloat(EffectiveYearlyInterestPl);
    
if(!isNaN(TotalAnnualCoast_PLP) && (TotalAnnualCoast_PLP>0))
	updateComponent('val_AnnualCost_PLP',formatAsPercentage(roundNumber(TotalAnnualCoast_PLP, 1))) ;
else
   	updateComponent('val_AnnualCost_PLP',strText_dots) ;
if(!isNaN(TotalAnnualCost_FK) &&(TotalAnnualCost_FK>0))
	updateComponent('val_AnnualCost_FK',formatAsPercentage(roundNumber(TotalAnnualCost_FK, 1))) ;
else
    updateComponent('val_AnnualCost_FK',strText_dots) ;
if(!isNaN(TotalAnnualCost_Pl) && (TotalAnnualCost_Pl>0))
	updateComponent('val_AnnualCost_Pl',formatAsPercentage(roundNumber(TotalAnnualCost_Pl, 1))) ;
else
   updateComponent('val_AnnualCost_Pl',strText_dots) ;

}

function CalculateVal_AnnualCost_PLP()
{
	var s = new Array();
	var period;
	var redemption;
	var MonthlyInterestPer;
	var MonthlyExtraPay;
	var payment;
	var LoanAmount = stripPeriodsFromAmount(document.getElementById('txtLoanAmount'));
	var MonthlyMaxPay = fltCreditLimit_PriveLimietPlusPerc / 100;
	
	MonthlyExtraPay = MonthlyExtraCoast;
	var MonthlyCoast = LoanAmount * MonthlyMaxPay;
	
	MonthlyInterestPer = parseFloat(getInterestRate(arrMonthlyInterestPer, LoanAmount));
	var effective = (Math.pow((1 + MonthlyInterestPer), 12)) - 1;
	var principal = LoanAmount;
	payment = MonthlyMaxPay * LoanAmount;
	
    var w = 0;
    var counter = 0;
	do {
	   counter = counter + 1;
		
        var Cal_interest = MonthlyInterestPer * principal;
        redemption = payment - Cal_interest;
        principal = principal - redemption;
        s[counter] = Cal_interest + redemption + MonthlyExtraPay;
		if (principal * (1 + MonthlyInterestPer) <= payment)
			w = 1;
		}while (w == 0);
		
	counter = counter + 1;
    Cal_interest = MonthlyInterestPer * principal;
	
    redemption = principal;
    principal = principal - redemption;
	
   s[counter] = Cal_interest + redemption + MonthlyExtraPay;
	
	/*period[counter] = counter;
    principal[counter] = principal;
    redemption[counter] = redemption;
    MonthlyInterestPer[counter] = Cal_interest;
    MonthlyExtraPay[counter] = MonthlyExtraPay;
    payment[counter] = s[counter];*/
	var n = counter;
	var x = effective;
	
	var y = 0;
    var v3 = 0;
    var v2 = 0;
	do {
		var v1 = 0;
		var sum = 0;
		var t = 0;
		do {
			t = t + 1;
			
			var waarde = (s[t] / (Math.pow((1 + x + y), (t / 12))));
			
			 sum = sum + waarde;
			
			if (t == n)
				v1 = 1;
			}while (v1 == 0);
			
		var jkp = x + y;
		if ((sum - LoanAmount) <= 0)
			v2 = 1; 
		else
			y = y + 0.00001; 
		
		}while (v2 == 0);
	
	return jkp*100;
}

function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function roundNumber1(num, dec) 
{
	var a = roundNumber(num*Math.pow(10,dec),1);
	var result = Math.round(a*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function fillScreenContent_PreStep_HY(){
		getSessionData_kort();
	if(value_loanFinal != '')
		document.getElementById('txtLoanAmount').value=value_loanFinal;
	else
		document.getElementById('txtLoanAmount').value=initLoanAmount;

	if(document.getElementById('txtLoanAmount').value==0)
	document.getElementById('txtLoanAmount').value="";
    updateComponent('txtPrescreen_heading',strStep1_Prescreen_heading);
	updateComponent('lbl_txtLoanAmount',strStep1_txtLoanAmount) ;
	updateComponent('step1_euro0',strEUR) ;
	updateComponent('infotittle_txtLoanAmount',str_infotittle_txtLoanAmount) ;
	updateComponent('infotxt_txtLoanAmount',str_infotxt_txtLoanAmount) ;
	updateComponent('post_hypotheek',strStep1_postLabel) ;
	updateComponent('lbl_txtLeanbedrag',str_txtLeanbedrag) ;
	updateComponent('step1_euro1',strEUR) ;
	updateComponent('infotittle_txtLeanbedrag',str_infotittleLeanbedrag) ;
	updateComponent('infotxt_txtLeanbedrag',str_infotxtLeanbedrag) ;
	updateComponent('post_Repayment_perMonth',strStep1_postLabel) ;
	updateComponent('lblPriveLimietPlus',strStep1_lblPriveLimietPlus) ;
	updateComponent('lblFlexibelKrediet',strStep1_lblFlexibelKrediet) ;
	updateComponent('lblPersoonlijkeLening',strStep1_lblPersoonlijkeLening) ;
   	updateComponent('txt_sliderMin',strStep1_sliderMin) ;
	updateComponent('txt_sliderMax',strStep1_sliderMax) ;
	updateComponent('txtDisclaimer',strStep1_txtDisclaimer) ;
	hideComponent('errOutcome_Mortgage');
	updateComponent('lblMonthlyCosts',strStep1_MonthlyCosts) ;
	updateComponent('lblEffectiveYearlyInterest',strStep1_EffectiveYearlyInterest) ;
	updateComponent('lblTheoreticalDuration',strStep1_TheoreticalDuration) ;
	updateComponent('lblTotalPrice ',strStep1_TotalPrice ) ;
	updateComponent('lblAnnualCostPercent ',strAnnualCostPercent ) ;
	updateComponent('infotittle_MonthlyCosts',infotittle_MonthlyCosts) ;
	updateComponent('infotxt_MonthlyCosts',infotxt_MonthlyCosts) ;
	updateComponent('infotittle_EffectiveYearlyInterest',infotittleGross_EffectiveYearlyInterest) ;
	updateComponent('infotxt_EffectiveYearlyInterest',infotxtGross_EffectiveYearlyInterest) ;
	updateComponent('infotittle_TotalPrice',str_infotitle_TotalPrice) ;
	updateComponent('infotxt_TotalPrice',str_infotext_TotalPrice) ;
	updateComponent('infotittle_AnnualCost',str_infotittle_AnnualCost) ;
	updateComponent('infotxt_AnnualCost',str_infotxt_AnnualCost) ;
	updateComponent('infotittle_TheoreticalDuration',infotittle_TheoreticalDuration) ;
	updateComponent('infotxt_TheoreticalDuration',infotxt_TheoreticalDuration) ;
	hideComponent("errOutcome_LoanAmount");	
	document.onkeydown = checkKey;
	links_initial();
	callingDefalutValues();
	Slider_Init();
	document.getElementById('OK').title=strText_OkAlt;
	
}
var strBlank = '&nbsp;';
function links_initial(){
	updateComponent('txtPageofferte',strBlank);
	document.getElementById('txtPageofferte').style.textDecoration = 'none' ;
	updateComponent('txtPageofferte1',strBlank);
	document.getElementById('txtPageofferte1').style.textDecoration = 'none' ;
	updateComponent('txtPageofferte2',strBlank);
	document.getElementById('txtPageofferte2').style.textDecoration = 'none' ;
	updateComponent('txtPage',strBlank) ;
	document.getElementById('txtPage').style.textDecoration = 'none' ;
	updateComponent('txtPage1',strBlank) ;
	document.getElementById('txtPage1').style.textDecoration = 'none' ;
	updateComponent('txtPage2',strBlank) ;
	document.getElementById('txtPage2').style.textDecoration = 'none' ;
}

function links_afterload(){
   updateComponent('txtPage',strStep1_Page) ;
   document.getElementById('txtPageofferte').style.textDecoration = 'underline' ;
   updateComponent('txtPage1',strStep1_Page1) ;
   document.getElementById('txtPageofferte1').style.textDecoration = 'underline' ;
   updateComponent('txtPage2',strStep1_Page2) ;
   document.getElementById('txtPageofferte2').style.textDecoration = 'underline' ;
   updateComponent('txtPageofferte', strText_offer) ;
   document.getElementById('txtPage').style.textDecoration = 'underline' ;
   updateComponent('txtPageofferte1', strText_offer1) ;
   document.getElementById('txtPage1').style.textDecoration = 'underline' ;
   updateComponent('txtPageofferte2', strText_offer2) ;
   document.getElementById('txtPage2').style.textDecoration = 'underline' ;
}

function gotoRequestedPage(strURL){
	location.href = strURL;
	return false;
}

function gotoappointmentpage(){
   location.href = strURL_ApointmentForm;
   return false;
}

var slider_initial ;


function getPos(elm) {
for(var
zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
return {x:zx,y:zy}
}

var flag=new Boolean(false);
var slider;
var clicked=new Boolean(false);

function Slider_Init(){
    var slider_absoluteStart ;  
	slider = new YAHOO.widget.Slider.getHorizSlider("slider-bg", "slider-thumb",0,150); 
    document.getElementById('slider-thumb').style.left = 0+'px' ;
	slider_absoluteStart = getPos(document.getElementById('slider-thumb')).x  ;
   if(flag==false){
		slider_initial = slider_absoluteStart ;}
   else
		slider_initial = slider_initial ;
		if(document.getElementById('txtLoanAmount').value!="" || document.getElementById('txtLoanAmount').value!=0)
	{
				setTimeout(function() {
                                    	validate_Step();
                                	},200);
	}
    slider.subscribe('change', after_update);
    YAHOO.util.Event.addListener('LoanAmount','change',loan_change); 
   flag = true ;
   return false;
 }
 
 function loan_change(){
 
	 validate_Step() ;
	 return false;
 }


function after_update(){

    document.getElementById('slider-thumb').style.top = 0 ;
  	    var pos  ;
		var obj_element = document.getElementById('slider-thumb') ;
		pos = parseInt(obj_element.style.left)  ;
		
		if(!isNaN(pos) && clicked==true){
			var v =  pos ;
			document.getElementById('demo_highlight').style.width = parseInt(v+3) +'px' ;
			var loanAmount = document.getElementById('txtLoanAmount').value;
			
			var temp_loanAmount = 1000 + Math.round((49000/150)*v);
			
			 if(input_box ==false )
			 {
				document.getElementById('txtLoanAmount').value = (Math.round(temp_loanAmount/250)*250);
			}
			else
			{
			
			   	document.getElementById('txtLoanAmount').value = loanAmount;
				}
			formatUserInput("txtLoanAmount");
			EffectiveYearlyInterest_PLP();	
			EffectiveYearlyInterest_FK();
			EffectiveInterestPercentage_Pl();
			Monthly_Costs(); 
			Theoretical_Duration();
			TotalPriceLoan();
			AnnualCoastPercentage();
			if(!IsHiddenComponent('errOutcome_LoanAmount'))
				hideComponent('errOutcome_LoanAmount');
			links_afterload();
			}
     
	input_box = false  ;
	clicked = true;
	
	}
	
	
	function update_slider(){
    
		input_box = true ;
		var new_loanamt= document.getElementById('txtLoanAmount').value;
		
		new_pos =Math.round((152/(maxLoanAmount-minLoanAmount))*(new_loanamt-minLoanAmount));
		new_pos_abs = Math.round((getPos(document.getElementById('demo_highlight')).x)+(new_pos)) ;
		
		var temp = document.getElementById('slider-thumb').style.left ;
		if(detectBrowser()){
		if(new_pos!=0){
		
			slider.moveThumb((new_pos_abs-0.5),getPos(document.getElementById('slider-bg')).y + 'px' );
			document.getElementById('slider-thumb').style.top = 0 ;
		}
			else
			{
				document.getElementById('slider-thumb').style.left = 0 ;
			}
			}
		else if(!detectBrowser()){
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
				var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
				if (ieversion>=7){
					slider.moveThumb(new_pos_abs+3,getPos(document.getElementById('slider-bg')).y  );	
					document.getElementById('slider-thumb').style.top = 0 ;
				}else {
					
					slider.moveThumb(new_pos_abs+3,getPos(document.getElementById('slider-bg')).y  );}
			}
		
		}
		
		if(parseInt(temp.slice(-temp.length,-2)) == new_pos)
		  input_box = false ;
		    if(new_pos>0 && new_pos<150){
			
			document.getElementById('demo_highlight').style.width = parseInt(new_pos+2) + 'px' ;
			}
		else if(new_pos==0 || new_pos==150){
		
			document.getElementById('demo_highlight').style.width = parseInt(new_pos) + 'px' ;}
   
   return false;
	}
	
	
function slider_onmousedown(){

if(!IsHiddenComponent('errOutcome_LoanAmount'))
				hideComponent('errOutcome_LoanAmount');
						return false;
}


function validate_Step(){
   	if(checkForm())
	{
	
	update_slider();
	EffectiveYearlyInterest_PLP();	
	EffectiveYearlyInterest_FK();
	EffectiveInterestPercentage_Pl();
	Monthly_Costs(); 
	Theoretical_Duration();
	TotalPriceLoan();
	AnnualCoastPercentage();
	formatUserInput("txtLoanAmount");
	clicked = true;
	links_afterload();
	return true;
	}
	else {
		links_initial()
		return false;
	}
	
	 
}

	function formatUserInput(userValue)
	{ 	
		if(flagKey == false)
			document.getElementById(userValue).value = addDecimal(userValue);
	}
	 
	var temp = "";	
	function addDecimal(userValue)
	{	
		
		var strFinalValue ='';
		var LoanAmountValue = stripPeriodsFromAmount(document.getElementById(userValue));
		
		if(document.getElementById(userValue).value == 0)
		{
			return document.getElementById(userValue).value;
		}
		LoanAmountValue = LoanAmountValue.split(' ').join('');
		
		exp = /(^-?\d*\.\d*$)|(^-?\d*$)|(^-?\.\d*$)/;
		if (exp.test(LoanAmountValue) != true)
		{	       
			ShwErr(fo.txtLoanAmount,"errOutcome_LoanAmount",err_digitsOnly);
			return document.getElementById(userValue).value;
		}		
		else
		{
			if(LoanAmountValue <= maxLoanAmount && LoanAmountValue >= minLoanAmount)
				hideComponent("errOutcome_LoanAmount");
			strFinalValue = formatAsCurrency(LoanAmountValue);
			strFinalValue = strFinalValue.substring(0,strFinalValue.length - 2) ;
			if(strFinalValue == 0)
			{
				strFinalValue = '';
			}
					
		}	
			
		return strFinalValue;
		
	}
	

	function checkKey(evt)
	{
		flagKey= false;
		var nbr;  
         var nbr = (window.event)?event.keyCode:evt.which; 
		
		if(nbr==37 || nbr==38 || nbr==39 || nbr==40)
		 {
			flagKey = true;
	
		 }
		 
	}
	

	
	
function checkForm(){
     var count=0;
	
	fo.txtLoanAmount.value = stripPeriodsFromAmount(fo.txtLoanAmount);
	
	if(ReqFieldEmpty(fo.txtLoanAmount,"errOutcome_LoanAmount",err_emptyField)){
		if (IsDigitsOnly(fo.txtLoanAmount,"errOutcome_LoanAmount",err_digitsOnly)){
			if(fo.txtLoanAmount.value < minLoanAmount){
		
				ShwErr(fo.txtLoanAmount,"errOutcome_LoanAmount",err_minLoanAmount);
			}else if(fo.txtLoanAmount.value > maxLoanAmount){
		
						ShwErr( fo.txtLoanAmount,"errOutcome_LoanAmount", err_maxLoanAmount);
			}else{
			
			   hideComponent("errOutcome_LoanAmount");	
			   count++;
			}	
				}
					}
		
		
		
		if(count == 1)
          return true;
        else
		{formatUserInput("txtLoanAmount");
          return false;	
		
		  }
				
	
}	

function gotorequestedPage(id){
    if(id=='txtPageofferte'|| id=='txtPageofferte1'|| id=='txtPageofferte2')
		location.href = eval('strURL_'+id) ;
   else
      location.href = eval('strURL_'+id)+'?pos='+strOmniture_tech ;
   
   return false;

}


var new_pos ;
var new_pos_abs ;
var input_box=new Boolean(false);

function slider_onmousedown(){
 if(!IsHiddenComponent('errOutcome_LoanAmount'))
				hideComponent("errOutcome_LoanAmount");
			return false;

}

var browse = new Boolean();

function detectBrowser(){
	var browser=navigator.appName;
	
	if (browser=="Netscape")
		{
		browse = true ;
		}
	else if(browser=="Microsoft Internet Explorer")
		{
		browse = false ; 
		}
		return browse ;
}


	
function activateHref(evt) 

{	
	 var nbr;  
         var nbr = (window.event)?event.keyCode:evt.which; 
		 if(nbr==13)
            {   
			    validate_Step();
				formatUserInput("txtLoanAmount");
				
                 return false;
            }

        return true;
}

document.onkeypress = activateHref;

var flagNewWindow;
function gotoPrivelimietPlusPopUp(flagNewWindow)
{
	if(flagNewWindow == true)
		window.open(strURL_PrivelimietPopUpURL); 
	else
		location.href =	strURL_PrivelimietPopUpURL;
}

function gotoFlexibelKredietPopUp(flagNewWindow)
{
	if(flagNewWindow == true)
		window.open(strURL_FlexibelKredietPopUpURL); 
	else
		location.href =	strURL_FlexibelKredietPopUpURL;
}

function gotoPersoonlijkeLeningPopUp(flagNewWindow)
{
	if(flagNewWindow == true)
		window.open(strURL_PersoonlijkeLeningPopUpURL); 
	else
		location.href =	strURL_PersoonlijkeLeningPopUpURL;
	
}
