var WIN_NAME = "financingDetails";
var WIN_PARAM = "scrollbars=yes,width=640,height=580,left=50,top=50,resizable=yes";

<!-- Loan Calculator Algorithm //-->
function calculateLoan(loanAmt){
	return getPayments(loanAmt);
}
function formatPrice(num){
	if(num == "NULL")
		return "NULL";
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) {
		num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function payment(rate, termPeriod , balance){
   var pow = 1;
   for (var j = 0; j < termPeriod; j++)
      pow = pow * (1 + rate);

   return (balance * pow * rate) / (pow - 1);
}

function openFinMarketingPage(){
   window.name = "sfsmainpage";
   popupWin = window.open(URL, WIN_NAME,  WIN_PARAM, "sfsmainpage");
   popupWin.focus();
}
//gets the payment in rate/number of payments
function getPayments(tprice) {
   tprice = qualifyPrice(tprice);
   //kam 6.20.02
   //added comma code, because eval(tprice) was only returning the price after the comma
   var comma = tprice.indexOf(',');
   if (comma != -1){
   var firststr = tprice.slice(0,comma);
   var secondstr = tprice.slice(comma+1,tprice.length);
   tprice = firststr.concat(secondstr);
   }
   //end changed code - kam
   tprice = eval(tprice);
   if(tprice <=10)
   		return formatPrice("NULL");
   payment = parseFloat(tprice) * .0250;

	if (payment < 10)
		payment = 10;
			
   payment = Math.ceil(payment);
   
   var paymentStr = formatPrice(payment);
   return  paymentStr;
}

<!-- For fomatting the price , to remove the prefixed and suffixed $ from the price //-->

function qualifyPrice(tprice) {
   tprice = "" + tprice;
   tprice=tprice.replace(/ /g,"");  // replace any space in the price
   var qprice = tprice;
   var index = tprice.indexOf("$");
   <!-- $ is prefixed -->
   //kam 6.20.02
   //changed substring start index to 2, because enfinity prices have a space between the $ and the first number
   if (index == 0) qprice = tprice.substring(1, tprice.length);
   <!-- $ is suffixed -->
   if (index > 0) qprice = tprice.substring(0, index);
   <!-- $ Not found -->
   if (index < 0) qprice = tprice;
   return qprice;
}

<!-- For VAIO/DI .shtml pages //-->

var price = 0;
function getPrice(p){
   if(eval(p)==-1) {
      document.write("Price N/A");
      return;
   }
   price = p + "";
    if(price){
      if((price.indexOf('.')) == -1){
         price = price + ".00";
      } else {
         if((price.indexOf('.') + 2) == price.length){
            price += "0";
         }
      }
     }

   document.write("$" + price);
}

var LOWAS = "as low as &#36;";
var FINANCING = "no payment for " + DAYS_INTEREST_FREE + " days";
var FINANCING_LINK = "Financing Details";
var PMTS = " mo";
//var PMTS_TERM = AMORT_TERM + " payments /";

var FONT_RED = "<font face=\"Arial, Helvetica, san-serif\" color=\"#CB0100\" size=\"1\">";
var FONT_GRAY = "<font face=\"Arial, Helvetica, san-serif\" color=\"#666666\" size=\"1\">";
var FONT_BLUE = "<font face=\"Arial, Helvetica, san-serif\" color=\"#3399C9\" size=\"1\">";
var FONT_BLACK = "<font face=\"Arial, Helvetica, san-serif\" color=\"#000000\" size=\"1\">";
var HREF_FIN = "<a href=\"javascript:openFinMarketingPage()\">";

var END_FONT = "</font>";
var END_HREF = "</a>";

function getQuote(formatstr, amt){
   if(amt) price = amt;
   if(price==-1) {
      return;
   }

   var priceval = getpayments(eval(price));
   var priceStr = new String(priceval);
   priceStr = priceStr.substr(0, priceStr.indexOf('.')+3);

   formatstr = formatstr.replace("@QW", LOWAS + priceStr + END_FONT);
   formatstr = formatstr.replace("@T", FONT_GRAY + "/ " + PMTS + END_FONT);
   formatstr = formatstr.replace("@Q", "&#36;" + priceStr + END_FONT);
   formatstr = formatstr.replace("@F", FINANCING);
   formatstr = formatstr.replace("@D", HREF_FIN + FONT_BLUE + FINANCING_LINK + END_FONT + END_HREF );
   formatstr = formatstr.replace("@P", FONT_BLACK +END_FONT);

   document.write(FONT_RED + formatstr);
}

<!-- --------------------------------------------- //-->
<!-- FOR SFS MARKETING PAGE on SS1.5 //-->
<!-- --------------------------------------------- //-->

function calculatePayments(totalPrice, termPeriod, interestRate, financeType){
   if(totalPrice) {
      var conv = new String(totalPrice);
      if(conv.indexOf(',')!=-1) {
         conv = conv.replace("," ,"");
         totalPrice = conv;
      }
   }
       return "$" + getPayments(totalPrice);
}

function getMonth(postfix){
   if( (DAYS_INTEREST_FREE/30)==3){
      if(postfix) return "third";
      return "three";
   }
   else if( (DAYS_INTEREST_FREE/30)==6){
      if(postfix) return "sixth";
      return "six";
   } else {
      if(postfix) return "sixth";
      return "six";
   }
}
