var incomeList;
var responseXML;
var netYearlyIncome 		= 0;
var woonQuote 				= 0;
var income1 				= 0;
var income2 				= 0;
var alimentationObliagations = 0; 
var monthlyBurden 			= 0; 
var maxMonthlyRepayment 	= 0;
	
var maximum_mortgage        = 0 ;
var maximum_monthlyRepayment = 0 ;
var str = "";
var mortgage 			;
var existingPropertyValue 	= 0;
var newPropertyValue 		= 0;
var savings 				= 0;
var strStep1_txtsubHead_subResult = '';
var txtsubHead_resultInfo = '';

function fillScreenContent_PreStep_HY(){
	updateComponent('txtPrescreen_heading',strStep1_Prescreen_heading);
	updateComponent('lblOutcome_maximumMortgage',strStep1_txtOutcome_maximumMortgage) ;
	updateComponent('step1_euro0',strEUR) ;
	updateComponent('infotittle_Hypotheek',strStep1_infotittle_Hypotheek) ;
	updateComponent('infotxt_Hypotheek',strStep1_infotxt_Hypotheek) ;
	updateComponent('post_hypotheek',strStep1_postLabel) ;
	updateComponent('lblRepayment_perMonth',strStep1_lblRepayment_perMonth) ;
	updateComponent('step1_euro1',strEUR) ;
	updateComponent('infotittle_Repayment_perMonth',strStep1_infotittleRepaymentPerMonth) ;
	updateComponent('infotxt_Repayment_perMonth',strStep1_infotxtRepaymentPerMonth) ;
	updateComponent('post_Repayment_perMonth',strStep1_postLabel) ;
	updateComponent('lblManipulate_mortgage',strStep1_lblManipulateMortgage) ;
	updateComponent('infotittle_Manipulate_mortgage',strStep1_infotittleManipulateMortgage) ;
	updateComponent('infotxt_Manipulate_mortgage',strStep1_infotxtManipulateMortgage) ;
	updateComponent('txtsubHead_resultHead',strStep1_txtsubHead_result) ;
	updateComponent('txtsubHead_resultInfo',strStep1_txtsubHead_subResult) ;
	updateComponent('lblEstimation_existingHouse',strStep1_lblEstimationExistingHouse) ;
	updateComponent('infotittle_Estimation_existingHouse',strStep1_infotittleEstimationEexistingHouse);
	updateComponent('infotxt_Estimation_existingHouse',strStep1_infotxtEstimationExistingHouse) ;
	updateComponent('step1_euro2',strEUR) ;
	updateComponent('lblEstimation_ToBeBuiltHouse',strStep1_EstimationToBeBuiltHouse) ;
	updateComponent('step1_euro3',strEUR) ;
	updateComponent('infotittle_Estimation_ToBeBuiltHouse',strStep1_infotittleEstimationToBeBuiltHouse);
	updateComponent('infotxt_Estimation_ToBeBuiltHouse',strStep1_infotxtEstimationToBeBuiltHouse) ;
	updateComponent('txtAdditional_information',strStep1_Additional_information) ;
	updateComponent('txtPreviousPage',strStep1_PreviousPage) ;
	document.getElementById('afspraak_maken').title=strText_afspraak_makenAlt;
	document.getElementById('OfferteAanvragen').title=strText_offerte_aanvragenAlt;
	document.getElementById('OfferteAanvragen').src=image_offerte_aanvragen;
	updateComponent('txtAdditional_information_2',strStep1_Additional_information_2) ;
	updateComponent('txt_sliderMin',strStep1_sliderMin) ;
	updateComponent('txt_sliderMax',strStep1_sliderMax) ;
	updateComponent('txtDisclaimer',strStep1_txtDisclaimer) ;
	hideComponent('errOutcome_Mortgage');
	hideComponent("errOutcome_Repayment");
	updateComponent('text_additionalHeading_form',strstep1_additionalHeading_form) ;
	updateComponent('text_additionalText_form',strstep1_additionalText_form) ;
}

function fillScreenContent_PreStep_HY_tab1(){

	retirveValueFromURL();
	updateClassName('iam_tab2','step_inactive_2');
	updateComponent('lblGross_yearleIncome',strStep1_Gross_yearleIncome) ;
	updateComponent('step1_euro0_tab1',strEUR) ;
	updateComponent('infotittle_Gross_yearleIncome',strStep1_infotittle_Gross_yearleIncome) ;
	updateComponent('infotxt_Gross_yearleIncome',strStep1_infotxt_Gross_yearleIncome) ;
	updateComponent('post_Gross_yearleIncome',strStep1_postLabel) ;
	updateComponent('lblGross_partnerIncome',strStep1_Gross_partnerIncome) ;
	updateComponent('step1_euro0_tab2',strEUR) ;
	updateComponent('infotittle_Gross_partnerIncome',strStep1_infotittleGross_partnerIncome) ;
	updateComponent('infotxt_Gross_partnerIncome',strStep1_infotxtGross_partnerIncome) ;
	updateComponent('post_Gross_partnerIncome',strStep1_postLabel) ;
	updateComponent('lblSaving_moneyAvailable',strStep1_Saving_moneyAvailable) ;
	updateComponent('step1_euro0_tab3',strEUR) ;
	updateComponent('infotittle_Saving_moneyAvailable',strStep1_infotittleSaving_moneyAvailable) ;
	updateComponent('infotxt_Saving_moneyAvailable',strStep1_infotxtSaving_moneyAvailable) ;
	updateComponent('post_Saving_moneyAvailable',strStep1_postLabel) ;
	updateComponent('lblMoneyPaid_WithInterest',strStep1_MoneyPaid_WithInterest) ;
	updateComponent('step1_euro0_tab4',strEUR) ;
	updateComponent('infotittle_MoneyPaid_WithInterest',strStep1_infotittleMoneyPaidWithInterest) ;
	updateComponent('infotxt_MoneyPaid_WithInterest',strStep1_infotxtMoneyPaidWithInterest) ;
	updateComponent('post_MoneyPaid_WithInterest',strStep1_postLabel) ;
	updateComponent('lblAlimentary_obligations',strStep1_Alimentary_obligations) ;
	updateComponent('step1_euro0_tab5',strEUR) ;
	updateComponent('infotittle_Alimentary_obligations',strStep1_infotittleAlimentaryObligations);
	updateComponent('infotxt_Alimentary_obligations',strStep1_infotxtAlimentaryObligations) ;
	updateComponent('post_Alimentary_obligations',strStep1_postLabel) ;
	updateComponent('txtDisclaimer_tab1',strStep1_txtDisclaimer) ;
	document.getElementById('Bereken').title=strText_BerekenAlt;
	hideComponent('errincome_1');
	hideComponent('errincome_2');
	hideComponent('err_Saving_moneyAvailable') ;
	hideComponent('err_MoneyPaid_WithInterest') ;
	hideComponent('err_Alimentary_obligations');
	hideComponent('err_Mortgagevalue') ;
	if(str[0] && (isNaN(str[0]) === false))
	{
		fo.txtSaving_moneyAvailable.value = str[0] ;
	}
	else
	{
		fo.txtSaving_moneyAvailable.value = '0' ;
	}
	if(str[1] && (isNaN(str[1]) === false))
	{
		fo.txtMoneyPaid_WithInterest.value = str[1] ;
	}
	else
	{
		fo.txtMoneyPaid_WithInterest.value = '0' ;
	}
	if(str[2] && (isNaN(str[2]) === false))
	{
		fo.txtAlimentary_obligations.value = str[2] ;
	}
	else
	{
		fo.txtAlimentary_obligations.value = '0' ;
	}
	hideComponent('errfinal_mortgage') ;
	
}
var tab_onclick = {
	init : function() {
		document.getElementById('iam_tab2').style.cursor="default";
		var el1 = document.getElementById('iam_tab2').parentNode ;
		el1.parentNode.setAttribute('id',"result_tag") ;
		var ele_tab1 = document.getElementById('iam_tab1').parentNode ;
		ele_tab1.parentNode.setAttribute('id',"result_tag1") ;
		document.getElementById("result_tag").className = 'step_inactive_2';
		document.getElementById("result_tag").disabled = true;
		YAHOO.util.Event.addListener('result_tag','click',this.tab2_click);
		YAHOO.util.Event.addListener('result_tag1','click',this.tab1_click);
	},
	tab2_click : function(e) {
	    if(!document.getElementById("result_tag").disabled || temp_count){
	    add_slider() ;
         	validate_Step1(e) ;            
		
		}
	},
	tab1_click : function(e) {
	   document.getElementById("result_tag1").className = 'selected' ;   
	   document.getElementById("result_tag").className = '' ; 
		document.getElementById("tab1").style.display = 'block' ;
		document.getElementById("tab2").style.display = 'none' ;
		remove_slider() ;
	}
}

function remove_slider(){
	var el = document.getElementById('slider-bg');
	el.parentNode.removeChild(el);
}

function add_slider(){
  oTD = document.getElementById('slider_column');
  oTD.innerHTML='<div id="slider-bg" tabindex="-1" title="Slider" height="5" style= "outline:none;"><span id="demo_highlight"></span><div id="slider-thumb" style="margin-left:0pt;"><img src="/nl/images/Systeem/abnamroNL/Content/Afbeelding/bttn/slider_thumb.gif" id="slider_image"></div></div> '; 
}

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;

function Slider_Init(){
    var slider_absoluteStart ;  
	slider = new YAHOO.widget.Slider.getHorizSlider("slider-bg", "slider-thumb",150,0); 
	document.getElementById('slider-thumb').style.left = 150+'px' ;
    document.getElementById('slider-thumb').title = strText_sliderAlt ;
    document.getElementById('demo_highlight').style.width = 150 + 'px' ;
  
	slider_absoluteStart = getPos(document.getElementById('slider-thumb')).x - 150 ;
	
   if(flag==false){
  
   slider_initial = slider_absoluteStart ;}
   else
    slider_initial = slider_initial ;
   
   
   slider.subscribe('change', after_update);
   flag = true ;
 }
 
 function mort_change(){
 
	 validate_Step2('txtOutcome_maximumMortgage') ;
	 return false;
 }

function repayment_change(){

	 validate_Step2('txtRepayment_perMonth') ;
	 return false;
 }
 
function after_update(){
    
	document.getElementById('slider-thumb').style.top = 0 ;
    if(input_box == false || (!IsHiddenComponent('errOutcome_Mortgage') && !IsHiddenComponent('errOutcome_Repayment'))){
	var pos  ;
	var obj_element = document.getElementById('slider-thumb') ;
    pos = parseInt(obj_element.style.left)  ;
	if(!isNaN(pos)){
	var v =  pos ;
	document.getElementById('demo_highlight').style.width = parseInt(v + 2) +'px' ;
    document.getElementById('txtOutcome_maximumMortgage').value = 5000+Math.round(((maximum_mortgage-5000)/150)*v);
    mortgage = document.getElementById('txtOutcome_maximumMortgage').value ;
	calcMonthlyRepayment2(mortgage) ;
	document.getElementById('txtRepayment_perMonth').value = (Math.round(maxMonthlyRepayment));
	calcPropertyValues() ;
	if(!IsHiddenComponent('errOutcome_Mortgage'))
				hideComponent('errOutcome_Mortgage');
			if(!IsHiddenComponent('errOutcome_Repayment'))
				hideComponent("errOutcome_Repayment");
		}
	}
	 input_box = false ;
	 }
	 
function slider_onmousedown(){
if(!IsHiddenComponent('errOutcome_Mortgage'))
				hideComponent('errOutcome_Mortgage');
			if(!IsHiddenComponent('errOutcome_Repayment'))
				hideComponent("errOutcome_Repayment");
				return false;
}
	
function validate_Step1(e){
	checkValue();
	var el1 = document.getElementById('iam_tab2').parentNode ;
	var el2 = document.getElementById('iam_tab1').parentNode ;
	el1.parentNode.setAttribute('id',"result_tag") ;
	el2.parentNode.setAttribute('id',"result_tag1") ;
	if(!IsHiddenComponent('err_Mortgagevalue'))
		hideComponent('err_Mortgagevalue');
	if(checkForm()){
		if(!document.getElementById('slider-thumb'))
			add_slider() ;
		var sData = "";
	    makeSimpleAJAXRequest(strURL_xmlCalcServlet,sData);
	

       setTimeout(function() { if(mortgage==0){
			ShwErr(document.getElementById('Bereken'),"err_Mortgagevalue",err_minMortgage_stap1);
			return false;
		}else{
		    hideComponent('err_Mortgagevalue') ;
			document.getElementById("result_tag").disabled = false ;
			updateClassName('iam_tab2','');
			document.getElementById("result_tag").className = 'selected' ;
			document.getElementById("result_tag1").className = '' ;
			document.getElementById("tab1").style.display = 'none' ;
			document.getElementById("tab2").style.display = 'block' ;
			document.getElementById('iam_tab1').style.cursor="pointer";
			Slider_Init() ;
			temp_count++ ;
			if(!IsHiddenComponent('errOutcome_Mortgage'))
				hideComponent('errOutcome_Mortgage');
			if(!IsHiddenComponent('errOutcome_Repayment'))
				hideComponent("errOutcome_Repayment");
			return false;
	   }}, 1000);
		
	   
	}else{
	    document.getElementById("result_tag").disabled = true ;
		updateClassName('iam_tab2','step_inactive_2');
		document.getElementById("result_tag").className = 'step_inactive_2' ;
		document.getElementById('iam_tab2').style.cursor="default";
		document.getElementById("result_tag1").className = 'selected' ;  
		return false;}
		
}

function validate_Step2(input){
     
	if(checkForm_2(input)){
		if(input == 'txtOutcome_maximumMortgage'){
		 	mortgage = element_maximumMortgage.value ;
			calcMonthlyRepayment2(mortgage) ;
			document.getElementById('txtRepayment_perMonth').value = (Math.round(maxMonthlyRepayment));
			calcPropertyValues() ;
		}else if(input == 'txtRepayment_perMonth'){
			monthlyRepayment = element_maximumRepayment.value ; 
			calcMortgage(monthlyRepayment) ;
			document.getElementById('txtOutcome_maximumMortgage').value = (Math.round(mortgage));
			calcPropertyValues() ;
		}
			update_slider() ;
			return false;
  }
  	else
    return false;
  
}

var new_pos ;
var new_pos_abs ;
var input_box=new Boolean(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 update_slider(){
       input_box = true ;
		var  new_mortgage = document.getElementById('txtOutcome_maximumMortgage').value;
       
		new_pos = Math.round((152/(maximum_mortgage-minMortgage))*(new_mortgage-minMortgage)) ;
		
		new_pos_abs = Math.round((slider_initial)+((152/(maximum_mortgage-minMortgage))*(new_mortgage-minMortgage))) ;
		
	 if(detectBrowser()){
			slider.moveThumb(new_pos_abs+3,getPos(document.getElementById('slider-bg')).y + 'px' );
			document.getElementById('slider-thumb').style.top = 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(new_pos>0 && new_pos<152){
			
			document.getElementById('demo_highlight').style.width = parseInt(new_pos-1) + 'px' ;}
		else if(new_pos==0 || new_pos==152){
		
			document.getElementById('demo_highlight').style.width = parseInt(new_pos) + 'px' ;}
    
   return false;
	}	
	
	
 function gotopreviousscreen(){
	  document.getElementById("result_tag1").className = 'selected' ;   
	  document.getElementById("result_tag").className = '' ; 
	  document.getElementById("tab1").style.display = 'block' ;
	  document.getElementById("tab2").style.display = 'none' ;
	  remove_slider() ;	  
 }
 
function IsMaxAmtValid(obj,errorDivID,errorMessage,maximum_mortgage){
     var limited_val = maximum_mortgage ;
	 var obj_val=parseInt(obj.value);
	 if (obj_val>limited_val){	
	 ShwErr(obj,errorDivID,errorMessage);
	 obj.value = limited_val ;
	 return false;
	}
	 return true;
}

function IsMinAmtValid(obj,errorDivID,errorMessage){
	var years=parseInt(obj.value);
	if (years<intMinpartnerage &&years>0){	
	ShwErr(obj,errorDivID,errorMessage);
	return false;
	}return true;
}
 
 
	var element_maximumMortgage ;
	var element_maximumRepayment ;

function checkForm_2(input){
	var count_2 = 0;
	element_maximumMortgage = document.getElementById("txtOutcome_maximumMortgage") ;
    element_maximumRepayment = document.getElementById("txtRepayment_perMonth") ;
	if(input == 'txtOutcome_maximumMortgage'){	
		element_maximumMortgage.value = stripPeriodsFromAmount(element_maximumMortgage);
		if (ReqFieldEmpty(element_maximumMortgage,"errOutcome_Mortgage",err_Mortgage_emptyField))
			{
			if (IsDigitsOnly(element_maximumMortgage,"errOutcome_Mortgage",err_Mortgage_NoDecimals)){
				if (element_maximumMortgage.value<minMortgage){
					ShwErr(element_maximumMortgage,"errOutcome_Mortgage",err_minMortgage);
					element_maximumMortgage.value = minMortgage ;
					count_2++;
				}else if(element_maximumMortgage.value>Math.round(maximum_mortgage)){
				     ShwErr(element_maximumMortgage,"errOutcome_Mortgage",err_maxMortgage);
					element_maximumMortgage.value = Math.round(maximum_mortgage) ;
					count_2++;}
					else{
					hideComponent("errOutcome_Mortgage");
					count_2++;
				}
		}
	}
}
     if(input == 'txtRepayment_perMonth'){
		element_maximumRepayment.value = stripPeriodsFromAmount(element_maximumRepayment);
		if (ReqFieldEmpty(element_maximumRepayment,"errOutcome_Repayment",err_Repayment_emptyField))
			{
			if (IsDigitsOnly(element_maximumRepayment,"errOutcome_Repayment",err_Repayment_NoDecimals)){
				if (element_maximumRepayment.value<minRepayment){
			
					ShwErr(element_maximumRepayment,"errOutcome_Repayment",err_minRepayment);
					element_maximumRepayment.value = minRepayment ;
					count_2++;
				}else if (element_maximumRepayment.value>Math.round(maximum_monthlyRepayment)){
				    ShwErr(element_maximumRepayment,"errOutcome_Repayment",err_maxRepayment);
					element_maximumRepayment.value = (Math.round(maximum_monthlyRepayment));
					count_2++;
				}else{
					hideComponent("errOutcome_Repayment");
					count_2++;
				}
			}
		}
	}
	if(count_2!=1)
		return false;
	else 
		return true;

}

var income1_check ;
var income2_check ;

function income1_income2FieldEmpty(obj,errorDivID,errorMessage){
    income1_check = (fo.txtGross_yearleIncome.value !='' && fo.txtGross_yearleIncome.value !=0 ) ;
	income2_check = (fo.txtGross_partnerIncome.value !='' && fo.txtGross_partnerIncome.value !=0 ) ; 
	if (!(income1_check || income2_check)){
		ShwErr(obj,errorDivID,errorMessage);	
		return false;
		}		
		return true;
	}
	
function checkForm(){
	var count = 0;
	fo.txtGross_yearleIncome.value = stripPeriodsFromAmount(fo.txtGross_yearleIncome);
	if (income1_income2FieldEmpty(fo.txtGross_yearleIncome,"errincome_1",errincome1_emptyField))
	{
		if (IsDigitsOnly(fo.txtGross_yearleIncome,"errincome_1",errincome1_digitsOnly)){
			if (fo.txtGross_yearleIncome.value<intIncome1_MinVal || fo.txtGross_yearleIncome.value>intincome1_MaxVal){
				ShwErr(fo.txtGross_yearleIncome,"errincome_1",err_notInRange);
			}
			else
				{
				fo.txtGross_yearleIncome.style.backgroundColor = "#FFF" ;
				hideComponent("errincome_1");
				count++;
				}
	}
}
	fo.txtGross_partnerIncome.value = stripPeriodsFromAmount(fo.txtGross_partnerIncome);
	if (income1_income2FieldEmpty(fo.txtGross_partnerIncome,"errincome_2",errincome2_emptyField))
	{   
		if(fo.txtGross_partnerIncome.value!=''){
			if (IsDigitsOnly(fo.txtGross_partnerIncome,"errincome_2",errincome2_digitsOnly)){
		    	if (fo.txtGross_partnerIncome.value<intIncome2_MinVal){
					ShwErr(fo.txtGross_partnerIncome,"errincome_2",err_notInRange);
			   }else{
			        fo.txtGross_partnerIncome.style.backgroundColor = "#FFF" ;
					hideComponent("errincome_2");
					count++;
					}
				}
			}else{  fo.txtGross_partnerIncome.style.backgroundColor = "#FFF" ;
					hideComponent("errincome_2");
					count++;
					}
}
	fo.txtSaving_moneyAvailable.value = stripPeriodsFromAmount(fo.txtSaving_moneyAvailable);
	if (IsDigitsOnly(fo.txtSaving_moneyAvailable,"err_Saving_moneyAvailable",err_saving_availableDigitsOnly)){
		if (fo.txtSaving_moneyAvailable.value<intMinVal){
			ShwErr(fo.txtSaving_moneyAvailable,"err_Saving_moneyAvailable",err_minSavings);
		}
		else if (fo.txtSaving_moneyAvailable.value>intMaxVal){
			ShwErr(fo.txtSaving_moneyAvailable,"err_Saving_moneyAvailable",err_maxSavings);
		}
		else
			{
			hideComponent("err_Saving_moneyAvailable");
			count++;
			}
	}
	fo.txtMoneyPaid_WithInterest.value = stripPeriodsFromAmount(fo.txtMoneyPaid_WithInterest);
	if (IsDigitsOnly(fo.txtMoneyPaid_WithInterest,"err_MoneyPaid_WithInterest",err_saving_availableDigitsOnly)){
		if (fo.txtMoneyPaid_WithInterest.value<intMinVal){
			ShwErr(fo.txtMoneyPaid_WithInterest,"err_MoneyPaid_WithInterest",err_minSavings);
		}
		else if (fo.txtMoneyPaid_WithInterest.value>intMaxVal){
			ShwErr(fo.txtMoneyPaid_WithInterest,"err_MoneyPaid_WithInterest",err_maxSavings);
		}
		else
			{
			hideComponent("err_MoneyPaid_WithInterest");
			count++;
			}
	}
    fo.txtAlimentary_obligations.value = stripPeriodsFromAmount(fo.txtAlimentary_obligations);
	if (IsDigitsOnly(fo.txtAlimentary_obligations,"err_Alimentary_obligations",err_saving_availableDigitsOnly)){
		if (fo.txtAlimentary_obligations.value<intMinVal){
			ShwErr(fo.txtAlimentary_obligations,"err_Alimentary_obligations",err_minSavings);
		}
		else if (fo.txtAlimentary_obligations.value>intMaxVal){
			ShwErr(fo.txtAlimentary_obligations,"err_Alimentary_obligations",err_maxSavings);
		}
		else
			{
			hideComponent("err_Alimentary_obligations");
			count++;
			}
	}
	
 if(count!=5)
    return false;
  else 
	 return true;
}

		
function processAJAXRequest(){

	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status==200)	{
		   
			incomeList = xmlHttp.responseXML.getElementsByTagName("INCOME");
			calcAll() ;
		
			}
	  }
	}
		
function calcWoonQuote(income1, income2){
	var index = 0;
	var tempWoonQuote = 0;
	var incomeUpperValue = 0;
	var incomeUpperValue2 = 0;
	var percUpperValue = 0;
	var percUpperValue2 = 0;
	
	var income_to_lookup = income1;
	if(parseInt(income2) > parseInt(income1)){
		income_to_lookup = income2;
	  }
	
	if(income_to_lookup > incomeUpperValue){
	
		for (var i=0;i<incomeList.length; i++){
			incomeUpperValue = parseInt(incomeList.item(i).getAttribute("uppervalue"));
			if (income_to_lookup < parseInt(incomeUpperValue) || isNaN(incomeUpperValue) || incomeUpperValue == undefined){
				var percentageList = incomeList.item(i).getElementsByTagName("PERCENTAGE");
				for(var j=0;j<percentageList.length; j++){
					percUpperValue = percentageList.item(j).getAttribute("uppervalue");
					if(percUpperValue > intInterestRate || percUpperValue == "" || percUpperValue == undefined){
						tempWoonQuote = percentageList.item(j).firstChild.nodeValue;
						
						break;
					}
					
				}
				break;
				
			}
		 }
	}
	return tempWoonQuote;
}
	
	
function calcAll(){
	if(fo.txtGross_yearleIncome.value!='')
		income1 = fo.txtGross_yearleIncome.value ;
	else
		income1 = 0 ;
	// Assign value from text field here.
	if(fo.txtGross_partnerIncome.value!='')
	 income2 = fo.txtGross_partnerIncome.value;  // Assign value from text field here.
	else
	  income2 = 0 ;
	if(fo.txtAlimentary_obligations.value!='')  
		alimentationObliagations = fo.txtAlimentary_obligations.value; // Assign value from text field here.
	else
	   alimentationObliagations = 0;
	if(fo.txtMoneyPaid_WithInterest.value!='')
		monthlyBurden = fo.txtMoneyPaid_WithInterest.value; // Assign value from text field here.
	else
		monthlyBurden = 0;
	if(fo.txtSaving_moneyAvailable.value!='')
		savings = fo.txtSaving_moneyAvailable.value;
	else
		savings = 0;
	
	 // Assign value from text field here.
	
	woonQuote = calcWoonQuote(income1, income2);
	
	calcNetYearlyIncome();
	calcMonthlyRepayment();
	calcMortgage((Math.round(maxMonthlyRepayment)));
	calcMaximum_mortgage((Math.round(maxMonthlyRepayment))) ;
	calcPropertyValues();
	document.getElementById('txtOutcome_maximumMortgage').value = (Math.round(mortgage));
	document.getElementById('txtRepayment_perMonth').value = (Math.round(maxMonthlyRepayment));
	}
	
function calcNetYearlyIncome(){
	netYearlyIncome = (woonQuote / 100) * (parseInt(income1) + parseInt(income2) - 12 * alimentationObliagations) - 12 * monthlyBurden;
	maximum_monthlyRepayment = netYearlyIncome/12;
	}
	
	
function calcMonthlyRepayment(){
	maxMonthlyRepayment = netYearlyIncome/12;
	}
		
function calcMortgage(monthlyRepayment){
	mortgage = monthlyRepayment * (1 - ( Math.pow(( 1 + monthlyInterest ) , ( -months )) )) / monthlyInterest;
	if (mortgage < minMortgage){
		mortgage = 0;
	}else if (mortgage > maxMortgage){
		mortgage = maxMortgage;
	   }
 }
	
function calcMaximum_mortgage(monthlyRepayment){
	maximum_mortgage = monthlyRepayment * (1 - ( Math.pow(( 1 + monthlyInterest ) , ( -months )) )) / monthlyInterest;
	if (maximum_mortgage < minMortgage){
		maximum_mortgage = 0;
	}else if (maximum_mortgage > maxMortgage){
		maximum_mortgage = maxMortgage;
	   }
	}
	
	// Calculate monthly repayment via mortgage
function calcMonthlyRepayment2(newMortgage){
		maxMonthlyRepayment = newMortgage *  monthlyInterest / (1 - ( Math.pow(( 1 + monthlyInterest ) , ( -months ))) );
	}
	
function calcPropertyValues(){
	
	existingPropertyValue = ((Math.round(mortgage)) + parseInt(savings)) / (existingProperyPerc / 100);
	newPropertyValue = ((Math.round(mortgage)) + parseInt(savings)) / (newProperyPerc / 100);
	updateComponent('val_existingHouse',formatValue(Math.round(existingPropertyValue))) ;
	updateComponent('val_newbuildHouse',formatValue(Math.round(newPropertyValue))) ;
	}
	
function activateHref() {
  	
	if (document.all){
	
			if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){
                    		
					validate_Step1();
					
				return false;
			}
	}
	return true;
}

function activateHref_tab2(id, aEvent) {
      try{  // Firefox, Opera 8.0+, Safari, IE7
            if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN) {
                  validate_Step2(id) ;
                  return false;
            }
      }catch(e){ // for  IE5 and IE6
            try{
                  if (document.all){
                        if ((event.which && event.which == 13) ||
(event.keyCode && event.keyCode == 13)){
                              validate_Step2(id) ;
                              return false;
                        }
                  }
            }catch(e){
                  alert ("Your browser does not support this Functionality!");
                  return;
            }
      }
      return true;
}

function checkValue()
{
	if(fo.txtSaving_moneyAvailable.value =='0' && fo.txtMoneyPaid_WithInterest.value =='0' &&  fo.txtAlimentary_obligations.value == '0')
	{
		strStep1_txtsubHead_subResult = result1_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value !='0' && fo.txtMoneyPaid_WithInterest.value =='0' &&  fo.txtAlimentary_obligations.value == '0')
	{
		strStep1_txtsubHead_subResult = result2_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value =='0' && fo.txtMoneyPaid_WithInterest.value !='0' &&  fo.txtAlimentary_obligations.value == '0')
	{
		strStep1_txtsubHead_subResult = result3_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value =='0' && fo.txtMoneyPaid_WithInterest.value =='0' &&  fo.txtAlimentary_obligations.value != '0')
	{
		strStep1_txtsubHead_subResult = result4_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value =='0' && fo.txtMoneyPaid_WithInterest.value !='0' &&  fo.txtAlimentary_obligations.value != '0')
	{
		strStep1_txtsubHead_subResult = result5_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value !='0' && fo.txtMoneyPaid_WithInterest.value =='0' &&  fo.txtAlimentary_obligations.value != '0')
	{
		strStep1_txtsubHead_subResult = result6_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value !='0' && fo.txtMoneyPaid_WithInterest.value !='0' &&  fo.txtAlimentary_obligations.value == '0')
	{
		strStep1_txtsubHead_subResult = result7_txtsubHead;
	}
	if(fo.txtSaving_moneyAvailable.value !='0' && fo.txtMoneyPaid_WithInterest.value !='0' &&  fo.txtAlimentary_obligations.value != '0')
	{
		strStep1_txtsubHead_subResult = result8_txtsubHead;
	}
	updateComponent('txtsubHead_resultHead',strStep1_txtsubHead_result) ;
	updateComponent('txtsubHead_resultInfo',strStep1_txtsubHead_subResult) ;
}

function retirveValueFromURL()
{
	str = location.href;
	str = str.replace(/%20/gi," ");
	var strIndex = str.indexOf("=");
	var strIndexHash = str.indexOf("#");
	if(strIndexHash !== -1)
	{
		str = "";
		fo.txtSaving_moneyAvailable.value = "" ;
		fo.txtMoneyPaid_WithInterest.value = "" ;
		fo.txtAlimentary_obligations.value = "" ;
	}
	else
	{
		if(strIndex !== -1)
		{
			str = str.slice(strIndex+1);
			str=str.split("&");
			if(str.length > 2)
			{
				str[1] = str[1].slice(str[1].indexOf("=")+1);
				str[2] = str[2].slice(str[2].indexOf("=")+1);
			}
			else
			{
				str = "";
				fo.txtSaving_moneyAvailable.value = "" ;
				fo.txtMoneyPaid_WithInterest.value = "" ;
				fo.txtAlimentary_obligations.value = "" ;
			}
		}
		else
		{
			str = "";
			fo.txtSaving_moneyAvailable.value = "" ;
			fo.txtMoneyPaid_WithInterest.value = "" ;
			fo.txtAlimentary_obligations.value = "" ;
		}
	}
}
