// JavaScript Document

function stripNonNumeric(inStr) {
	var numbers = '0123456789';
	inStr = inStr.replace(",","");
	// look for a leading dollar sign; if it exists, strip it
	if (inStr.indexOf("$",0) == 0) {
		inStr = inStr.replace("$","");
	}
	return inStr;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Set_The_Commission_Saving_Example_Fields( The_Field_ID_Prefix )
//
// This function fills the Equity-Saver commission, traditional-broker commission, and commision savings
// fields based on the value of the property price field, the Equity-Saver commission percentage field, and
// the traditional-broker commission field.
//
// PARAMETERS:
//
//    The_Field_ID_Prefix: Prepended to the standard field-id strings to create unique field ids for the
//                         fields used.  This is necessary to allow this script to be used for multiple
//                         field sets on the same page.
//
{
   var The_Property_Price_Field_ID                           = The_Field_ID_Prefix + "propertyPrice";
   var The_Equity_Saver_Commission_Percentage_Field_ID       = The_Field_ID_Prefix + "equityCommissionPercent";
   var The_Traditional_Broker_Commission_Percentage_Field_ID = The_Field_ID_Prefix + "brokerCommissionPercent";
   var The_Equity_Saver_Commission_Field_ID                  = The_Field_ID_Prefix + "equityCommission";
   var The_Traditional_Broker_Commission_Field_ID            = The_Field_ID_Prefix + "brokerCommission";
   var The_Commission_Savings_Field_ID                       = The_Field_ID_Prefix + "savings";

   var The_Property_Price = stripNonNumeric(document.getElementById( The_Property_Price_Field_ID ).value);
   
   var The_Equity_Saver_Commission_Percentage =
	      document.getElementById( The_Equity_Saver_Commission_Percentage_Field_ID ).value / 100.0;

   var The_Traditional_Broker_Commission_Percentage =
          document.getElementById( The_Traditional_Broker_Commission_Percentage_Field_ID ).value / 100.0;
	
   var The_Equity_Saver_Commission;
   var The_Traditional_Broker_Commission;
   var The_Commission_Savings;
   
   The_Equity_Saver_Commission = The_Property_Price * The_Equity_Saver_Commission_Percentage;
   
   The_Traditional_Broker_Commission = The_Property_Price * The_Traditional_Broker_Commission_Percentage;
   
   The_Commission_Savings = The_Traditional_Broker_Commission - The_Equity_Saver_Commission;
   
   
   document.getElementById( The_Equity_Saver_Commission_Field_ID ).childNodes[0].nodeValue =
      formatCurrency(parseInt( The_Equity_Saver_Commission ));

   document.getElementById( The_Traditional_Broker_Commission_Field_ID ).childNodes[0].nodeValue =
      formatCurrency(parseInt( The_Traditional_Broker_Commission ));
   
   document.getElementById( The_Commission_Savings_Field_ID ).childNodes[0].nodeValue =
      formatCurrency(parseInt( The_Commission_Savings ));
   
   document.getElementById( The_Property_Price_Field_ID ).value =
      formatCurrency(parseInt( The_Property_Price ));
	  
} // end Set_The_Commission_Saving_Example_Fields

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function Set_The_Fee_Example_Fields( The_Field_ID_Prefix )
//
// This function fills the Equity-Saver fee, traditional-broker fee, and fee savings fields (four of each)
// based on the value of the property value field, the commission percentage field, and the equity-saver
// contract-delay fee percentage fields (four).
//
// PARAMETERS:
//
//    The_Field_ID_Prefix: Prepended to the standard field-id strings to create unique field ids for the
//                         fields used.  This is necessary to allow this script to be used for multiple
//                         field sets on the same page.
//
{
   var The_Property_Value_Field_ID                             = The_Field_ID_Prefix + "propertyValue";
   var The_Commission_Percentage_Field_ID                      = The_Field_ID_Prefix + "commissionPercent";
   var The_Equity_Saver_Contract_Delay_Fee_Percentage_Field_ID = The_Field_ID_Prefix + "equityFeeValue";
   var The_Equity_Saver_Fee_Field_ID                           = The_Field_ID_Prefix + "equityFee";
   var The_Traditional_Broker_Fee_Field_ID                     = The_Field_ID_Prefix + "brokerFee";
   var The_Fee_Savings_Field_ID                                = The_Field_ID_Prefix + "equitySavings";

   var The_Property_Value = stripNonNumeric(document.getElementById( The_Property_Value_Field_ID ).value);
	
   var The_Commission_Percentage =
	      document.getElementById( The_Commission_Percentage_Field_ID ).value / 100.0;

   var The_Equity_Saver_Commission_Percentage;
   var The_Equity_Saver_Fee;
   var The_Equity_Saver_Savings;
   var The_Traditional_Broker_Fee;
   
   
   The_Traditional_Broker_Fee = The_Property_Value * The_Commission_Percentage;
   
   for( The_Index = 1; The_Index <= 4; The_Index = The_Index + 1 )
   {
      The_Equity_Saver_Commission_Percentage =
	      document.getElementById( The_Equity_Saver_Contract_Delay_Fee_Percentage_Field_ID + The_Index ).value / 100.0;

      The_Equity_Saver_Fee = The_Traditional_Broker_Fee * The_Equity_Saver_Commission_Percentage;
	  
	  The_Equity_Saver_Savings = The_Traditional_Broker_Fee - The_Equity_Saver_Fee;
   
      document.getElementById( The_Equity_Saver_Fee_Field_ID + The_Index ).childNodes[0].nodeValue =
	     formatCurrency(parseInt( The_Equity_Saver_Fee ));
      document.getElementById( The_Traditional_Broker_Fee_Field_ID + The_Index ).childNodes[0].nodeValue =
	     formatCurrency(parseInt( The_Traditional_Broker_Fee ));
      document.getElementById( The_Fee_Savings_Field_ID + The_Index ).childNodes[0].nodeValue =
	     formatCurrency(parseInt( The_Equity_Saver_Savings ));
      document.getElementById( The_Property_Value_Field_ID ).value =
	     formatCurrency(The_Property_Value);
   
   } // end for
   
}// end Set_The_Fee_Example_Fields

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function formatCurrency(num) {
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);
}
//  End -->
