function SetPaymentPeriods(GE_ID)
{var i;var Added=0;var PaymentOptions=new Array();PaymentOptions[0]="6";PaymentOptions[1]="9";PaymentOptions[2]="12";PaymentOptions[3]="24";PaymentOptions[4]="36";PaymentOptions[5]="48";PaymentOptions[6]="60";var FinancingPaymentPeriodControl=document.getElementById("FinancingPayment"+GE_ID);FinancingPaymentPeriodControl.setAttribute("onfocus","");var LoanAmount=Number(document.getElementById("FinancingInternalPriceDIV"+GE_ID).childNodes[0].nodeValue);var NumberOfMonths=GECalculator_GetMaxPeriod(LoanAmount);for(i=0;i<7;i++)
{if(NumberOfMonths>PaymentOptions[i])
{var option=document.createElement("option");option.value=PaymentOptions[i];option.text=PaymentOptions[i]+" mnd";FinancingPaymentPeriodControl.options.add(option,i);Added+=1;}}
var option2=document.createElement("option");option2.value=NumberOfMonths;option2.text=NumberOfMonths+" mnd";option2.setAttribute("selected","selected");FinancingPaymentPeriodControl.options.add(option2,Added);Calculate(NumberOfMonths,true,GE_ID);}
function popitup(url)
{newwindow=window.open(url,'GECalculator','height=420,width=400');if(window.focus)
{newwindow.focus()}
return false;}
function Calculate(value,overridecalculatedvalue,GE_ID)
{var FinancingErrorText="";var NumberOfMonths=value;var MonthlyPayment=new Array(0);var TotalFinancingCost=new Array(0);var EffectiveInterestRate=new Array(0);var TotalFinancingCostAfterTax=new Array(0);var DownPaymentPeriod=new Array(0);var LoanAmount=Number(document.getElementById("FinancingInternalPriceDIV"+GE_ID).childNodes[0].nodeValue);if(LoanAmount<GECalculator_MinLoanAmount)
{FinancingErrorText="Dersom du velger flere produkter slik at summen overstiger kr "+GECalculator_MinLoanAmount+",- vil kjøpet være finansierbart.";}
if(LoanAmount>GECalculator_MaxLoanAmount)
{FinancingErrorText="Maximalt lånebeløp er kr. "+GECalculator_MaxLoanAmount+",-";}
if(FinancingErrorText=="")
{if(((LoanAmount*GECalculator_PercentageCreditLimit)<GECalculator_MinMonthlyPayment)&&overridecalculatedvalue)
{GECalculator_GetPayOffPeriod(LoanAmount,GECalculator_MinMonthlyPayment,DownPaymentPeriod,TotalFinancingCost,EffectiveInterestRate,TotalFinancingCostAfterTax);var FinancingPaymentPeriodControl=document.getElementById("FinancingPayment"+GE_ID);var i,DontAdd=false;for(i=0;i<FinancingPaymentPeriodControl.options.length;i++)
{if(DownPaymentPeriod[0]<FinancingPaymentPeriodControl.options[i].value)
{break;}
if(DownPaymentPeriod[0]==FinancingPaymentPeriodControl.options[i].value)
{DontAdd=true;break;}}
if(!DontAdd)
{var option2=document.createElement("option");option2.value=DownPaymentPeriod[0];option2.text=DownPaymentPeriod[0]+" mnd";option2.setAttribute("selected","selected");FinancingPaymentPeriodControl.options.add(option2,i);}
if(MonthlyPayment[0]<=GECalculator_MinMonthlyPayment){MonthlyPayment[0]=GECalculator_FormatToCurrency(GECalculator_MinMonthlyPayment);}
else{MonthlyPayment[0]=GECalculator_FormatToCurrency(GECalculator_MinMonthlyPayment);}}
else
{NumberOfMonths=value;GECalculator_GetMonthlyPayment(LoanAmount,NumberOfMonths,MonthlyPayment,TotalFinancingCost,EffectiveInterestRate,TotalFinancingCostAfterTax);if(overridecalculatedvalue){MonthlyPayment[0]=Math.ceil(LoanAmount*GECalculator_PercentageCreditLimit);if(MonthlyPayment[0]<=GECalculator_MinMonthlyPayment){MonthlyPayment[0]=GECalculator_FormatToCurrency(GECalculator_MinMonthlyPayment);}}
x=MonthlyPayment[0].toString()
x=x.replace(/\,\-/,'');x=x.replace(/\./,'');y=parseFloat(x);MonthlyPayment[0]=y;if(MonthlyPayment[0]<=GECalculator_MinMonthlyPayment){MonthlyPayment[0]=GECalculator_FormatToCurrency(GECalculator_MinMonthlyPayment);}
else{MonthlyPayment[0]=GECalculator_FormatToCurrency(MonthlyPayment[0]);}}
document.getElementById("FinancingErrorDIV"+GE_ID).childNodes[0].nodeValue="";document.getElementById("FinancingAmountDIV"+GE_ID).childNodes[0].nodeValue=MonthlyPayment[0];document.getElementById("FinancingCostDIV"+GE_ID).childNodes[0].nodeValue=TotalFinancingCost[0];document.getElementById("FinancingInternalInterestDIV"+GE_ID).childNodes[0].nodeValue=EffectiveInterestRate[0]+'%';}
else
{document.getElementById("FinancingErrorDIV"+GE_ID).childNodes[0].nodeValue=FinancingErrorText;document.getElementById("FinancingAmountDIV"+GE_ID).childNodes[0].nodeValue=" ";document.getElementById("FinancingCostDIV"+GE_ID).childNodes[0].nodeValue=" ";document.getElementById("FinancingInternalInterestDIV"+GE_ID).childNodes[0].nodeValue=" ";}}