    // *************************************************************
	// Common Javascript for FXMath Modules
    // Included using PERL rather than the Javascript include method
    // *************************************************************
	var arrPairs = new Array("USD/MXN","GBP/AUD","XAU/JPY","USD/HUF","USD/NOK","GBP/DKK","EUR/NOK","CHF/MXN","CHF/CAD","AUD/JPY","XAU/EUR","XAG/AUD","USD/PLN","EUR/THB","GBP/CZK","EUR/CAD","AUD/THB","AUD/CZK","SAR/JPY","XAG/CAD","CHF/SGD","AUD/NZD","USD/CHF","CHF/THB","AUD/MXN","USD/ZAR","XAU/CHF","NZD/JPY","EUR/HUF","CHF/SEK","XAG/CHF","SEK/JPY","CHF/AUD","JPY/HUF","CHF/NZD","AUD/SGD","PLN/JPY","THB/JPY","CAD/ZAR","CHF/NOK","CHF/HKD","CAD/PLN","CHF/JPY","AUD/HUF","AUD/HKD","XAG/USD","GBP/SGD","EUR/USD","GBP/JPY","NZD/USD","USD/DKK","SGD/JPY","GBP/CHF","CZK/JPY","DKK/JPY","MXN/JPY","AUD/SEK","XAU/CAD","CAD/MXN","GBP/ZAR","AUD/SAR","GBP/NZD","XAU/GBP","EUR/NZD","AUD/USD","USD/JPY","EUR/SEK","XAG/EUR","GBP/SEK","CAD/HUF","CAD/SAR","GBP/NOK","EUR/CHF","CHF/HUF","XAG/JPY","GBP/THB","CAD/CZK","CAD/THB","USD/SGD","AUD/ZAR","XAG/GBP","CAD/AUD","CAD/NOK","HKD/JPY","GBP/CAD","CHF/SAR","EUR/ZAR","CAD/NZD","CHF/CZK","ZAR/JPY","GBP/MXN","EUR/JPY","EUR/SGD","EUR/HKD","AUD/PLN","CHF/ZAR","USD/SEK","AUD/NOK","EUR/SAR","CAD/SGD","GBP/PLN","GBP/HKD","XAU/AUD","AUD/DKK","USD/CAD","NOK/JPY","XAU/USD","USD/THB","CAD/DKK","GBP/HUF","CAD/JPY","EUR/MXN","EUR/PLN","EUR/AUD","CHF/DKK","CAD/SEK","GBP/SAR","CAD/HKD","EUR/GBP","EUR/DKK","CHF/PLN","USD/CZK","USD/HKD","USD/SAR","EUR/CZK","GBP/USD");
    var arrRates = new Array(11.2780,2.4785,73004.75,204.40,6.0705,10.8768,7.7978,9.2839,0.9025,84.87,506.0507,16.8558,3.0636,48.98,41.1420,1.4082,28.69,16.6043,29.94,13.9696,1.2980,1.1883,1.2145,31.39,8.5281,6.6718,789.5220,71.38,262.58,5.9381,15.4741,15.07,1.0891,1.8185,1.2946,1.1914,36.63,2.9412,6.0841,4.9978,6.3867,2.7939,92.45,154.55,5.8629,12.705,2.9540,1.28438,210.375,0.6355,5.8048,71.21,2.27527,5.08,18.84,9.94,5.4523,712.7571,10.2844,12.5018,2.8340,2.9463,346.9567,2.0199,0.7557,112.305,9.2648,9.9181,13.5135,186.41,3.4198,11.3738,1.5600,168.26,1430.89,71.45,20.0200,34.76,1.5767,5.0443,6.7999,1.2064,5.5359,13.48,2.0540,3.0874,8.5705,1.4341,18.0711,16.82,21.1340,144.254,2.0253,9.9644,2.3165,5.4922,7.2127,4.5890,4.8169,1.4378,5.7411,14.5335,860.0154,4.3882,1.0963,18.00,649.7,38.13,5.2940,383.04,102.40,14.4879,3.9358,1.6992,4.7800,6.5781,7.0257,7.0744,0.68555,7.4574,2.5222,21.9529,7.7576,3.7501,28.2025,1.87329);
    var arrInterestCode = new Array("AUD","CAD","CHF","CZK","DKK","EUR","GBP","HKD","HUF","JPY","MXN","NOK","NZD","PLN","SAR","SEK","SGD","THB","USD","XAG","XAU","ZAR"
);
    var arrInterestBorrow = new Array(5.2000000000,4.0000000000,1.0000000000,1.5000000000,2.4000000000,2.3500000000,4.2500000000,3.5000000000,5.0000000000,-0.1500000000,6.8000000000,2.5000000000,7.0000000000,4.0000000000,4.5000000000,1.6500000000,2.5000000000,3.5000000000,4.7000000000,0.0000000000,-0.5000000000,6.3000000000
);
    var arrInterestLend = new Array(5.5750000000,4.4000000000,1.3500000000,2.0000000000,3.0000000000,2.7500000000,4.5000000000,3.9000000000,6.0000000000,0.2200000000,7.8000000000,3.0000000000,7.5000000000,4.7500000000,5.0000000000,2.1500000000,3.5000000000,5.2500000000,5.2500000000,1.5000000000,0.5000000000,7.5500000000
);

    // *************************************************************
    // Takes in two currency codes ('base' and 'quote') and returns the value of
    // 1 unit of 'quote' as expressed in 'base'.
    // *************************************************************
	function convert(base, quote) 
    {
        if(base == quote) { return 1; }
        
        // Look for pair in arrPairs
        for(i=0; i<arrPairs.length; i++) {

            // break apart the pair and obtain currency code
     	    pair_base = arrPairs[i].substring(0,3);
     	    pair_quote = arrPairs[i].substring(4,7);

            // check to see if code matches the pair we're interested in
     	    if((pair_base == base) && (pair_quote == quote)) { 
             	return arrRates[i]; 
     	    }            
           	else if((pair_quote == base) && (pair_base == quote)) {
     	    	return (1 / arrRates[i]); 
           	}
           	else {               
                // check to see if the currencies that we're trying to convert
                // exist in some form in our conversion array
        		if((pair_base == base) || (pair_quote == base)) { base_ok = 1; }
        		if((pair_base == quote) || (pair_quote == quote)) { quote_ok = 1; } 
            }
         } // end for
   
     // We haven't found a direct coversion rate, we need to do more work

     // If the currency codes exist in our list of currencies (but we don't
     // have a direct conversion between them) then...
     if((base_ok == 1) && (quote_ok == 1)) {
     
     // NOTE: The below assumes that we are able to convert both base and
     // quote to USD
        
        // calculate what one USD is in the base
        base_us = convert(base, "USD"); 
        
        // calculate what quote is in USD
        us_quote = convert("USD", quote);

        // return the product of the two
        return (base_us * us_quote);
     }

     // We weren't able to convert between the two currencies. Is it possible
     // that we don't have a conversion between 'base' or 'quote' and USD?
     return -1;  

  	} // end convert function

    // *************************************************************
   	// Trims a rate to a certain number of decimal places
    // *************************************************************
	function trimRate(txtRate, intNumberOfDecimals) 
    {
        var numerator;
  		var denominator;
        var decimal_index;
        
        decimal_index = txtRate.indexOf(".");
        
        if(decimal_index < 0) { return txtRate; }
		if(intNumberOfDecimals < 1) { return txtRate.substr(0, decimal_index); }         numerator = txtRate.substr(0,decimal_index);
        denominator = txtRate.substr(decimal_index+1, txtRate.length - (decimal_index+1));
        denominator = denominator.substr(0, intNumberOfDecimals);
        return numerator + "." + denominator;
  	} 

    // *************************************************************
	function popUpWindow(wPage, wName) 
    {
   	    wParam = "status=yes,resizable=yes,scrollbars=yes,width=500,height=300";
        window.open(wPage, wName, wParam);
    }	

    // *************************************************************
    // Finds the value of one PIP in this pair
    // eg. USD/EUR is 0.0001 where USD/JPY is 0.01
    // *************************************************************
	function findPipValue(fltRate) 
    {
        var intDecimalIndex = fltRate.toString().indexOf('.')	
		var intLengthDecimalDifference = fltRate.toString().length - intDecimalIndex;
		alert(intLengthDecimalDifference);
		return (1 / (intLengthDecimalDifference * 10));
    }   



	 
	 // ******************************************
     // Routine when the user changes the value of the currency pair
	 // ******************************************
     function changePair(txtCurrencyPair) {
		var form = document.frmFXMath;	
		var intSlashIndex = txtCurrencyPair.indexOf('/');
		var txtBase = txtCurrencyPair.substr(0, intSlashIndex);
		var txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);
		var fltPipValue = 0.0001;
		var fltClosingRate;
		var fltConversion = convert(txtBase, txtQuote);
        var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;

		// Populate the open rate with convert(base, quote)
		form.txtOpeningRate.value = trimRate(fltConversion.toString(), 4);

		// Special PIP values
		if((txtBase == "JPY") || (txtQuote == "JPY")) { fltPipValue = 0.01; }
		
		// Populate The Closing Rate
		fltClosingRate = (fltPipValue * 10) + fltConversion;
		form.txtClosingRate.value = trimRate(fltClosingRate.toString(), 4);

		// See if it is a different Quote than before, if so clear the closing rate
        if(form.txtBaseCode.value != txtQuote) { 
          calculateProfit();
		}

       // Calculate the closing rate of Quote in the primary account currency
	   form.txtQuotePrimary.value = trimRate(convert(txtQuote, txtPrimaryCode).toString(), 4);

	   // Now change {Base}/{primary currency} combo box
	   form.txtBaseCode.value = txtQuote;
       form.txtPrimaryCode.value = txtPrimaryCode;
       form.txtProfitCode.value = txtPrimaryCode;
     
       // Calculate Profit
	   calculateProfit();

     }
	 // ******************************************
		function calculateProfit() {

            var form = document.frmFXMath;
            var txtCurrencyPair = form.cboCurrencyPair.options[form.cboCurrencyPair.selectedIndex].value;
            var intSlashIndex = txtCurrencyPair.indexOf('/');
            var txtBase = txtCurrencyPair.substr(0, intSlashIndex);
            var txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);

            // check if the units value has been specified by the user yet.
            if(form.txtUnits.value == "") { return; }

            var intUnits = parseInt(form.txtUnits.value);	
            var fltOpeningRate = parseFloat(form.txtOpeningRate.value);
            var fltClosingRate = parseFloat(form.txtClosingRate.value);
            var fltQuotePrimaryRate = parseFloat(form.txtQuotePrimary.value);
        
            var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;
            var fltResult;

            if(txtBase == txtPrimaryCode)
            {
                fltResult = (fltClosingRate - fltOpeningRate) * (1/fltClosingRate) * intUnits;
            } else {
                fltResult = (fltClosingRate - fltOpeningRate) *
                fltQuotePrimaryRate * intUnits;
            }
           
          
            // Calculate by action
            if(form.cboAction.options[form.cboAction.selectedIndex].value == "SELL")
            {
                fltResult = 0 - fltResult;
            }
            form.txtProfit.value = trimRate(fltResult.toString(), 2);
		}	
        // ******************************************
        function changeAction() 
        {
          var form = document.frmFXMath;
          if ((form.txtUnits.value != "") &&
             (form.txtOpeningRate.value != "") &&
             (form.txtClosingRate.value != "") &&
             (form.txtQuotePrimary.value != "")) {

               calculateProfit();
          }
		}
        // ******************************************
		function changeQuotePrimary() 
        {
            var form = document.frmFXMath;
            if((form.txtUnits.value != "") &&
              (form.txtOpeningRate.value != "") &&
              (form.txtClosingRate.value != "") &&
              (form.txtQuotePrimary.value != "")) {
              
                calculateProfit();
		    }
		}

        // ******************************************
        function changePrimaryCurrency()
        {
            var form = document.frmFXMath;
            var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;
            
            form.txtPrimaryCode.value = txtPrimaryCode;
            form.txtProfitCode.value = txtPrimaryCode;
            changePair(document.frmFXMath.cboCurrencyPair.options[document.frmFXMath.cboCurrencyPair.selectedIndex].value);

            if ((form.txtUnits.value != "") &&
               (form.txtOpeningRate.value != "") &&
               (form.txtClosingRate.value != "") &&
               (form.txtQuotePrimary.value != "")) {
               calculateProfit();
            }
        }
<!--

var Volume;

var Ask;

function Recalculate(){

  with (document.PIPCalc){

    var v=Volume.value;

    var a=Ask.value;

    var f=Formula.options[Formula.selectedIndex].value

    if((v>0)&(a>0)){

      var i=Math.round(eval(f)*100);

      if(i<10){

        PIP.value="$.0" + i;

      }else{

        var x="$" + i;

        PIP.value=x.substring(0,(x.length-2))+"."+x.substring((x.length-2),x.length);

      }

    }

  }

  return(false);

}

//-->

    // *********************************************
    // Routine when the user changes the value of the currency pair
	function changePair(txtCurrencyPair) 
    {
        var form = document.frmFXMath;	
        var intSlashIndex = txtCurrencyPair.indexOf('/');
        var txtBase = txtCurrencyPair.substr(0, intSlashIndex);
        var txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);
        var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;

		// Now change {Base}/{Primary currency} combo box
        form.txtBaseCode.value = txtBase;
        form.txtPrimaryCode.value = txtPrimaryCode;
        form.txtMarginCode.value = txtPrimaryCode;
        
        form.txtQuotePrimary.value = convert(txtBase, txtPrimaryCode);

		if(form.txtUnits.value != "") 
        {
            calculateMargin();
		}
    }

    // ******************************************
    function changePrimaryCurrency()
    {
        var form = document.frmFXMath;
        var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;
        form.txtPrimaryCode.value = txtPrimaryCode;
        form.txtMarginCode.value = txtPrimaryCode;

        changePair(document.frmFXMath.cboCurrencyPair.options[document.frmFXMath.cboCurrencyPair.selectedIndex].value);
        
        if ((form.txtUnits.value != "") &&
           (form.txtQuotePrimary.value != ""))
           {
              calculateMargin();
           }
     }


	// *********************************************
		function calculateMargin() {
		var form = document.frmFXMath;
	   if(form.txtUnits.value == "") { return; }

		var intUnits = parseInt(form.txtUnits.value);
		var fltBaseUSDRate = parseFloat(form.txtQuotePrimary.value);
		var fltMarginRatio = parseFloat(form.cboMarginRatio.options[form.cboMarginRatio.selectedIndex].value);
		var fltResult = (fltBaseUSDRate * intUnits) / fltMarginRatio;
		form.txtMargin.value = trimRate(fltResult.toString(), 2);
		}

    // *************************************************************
	// Common Javascript for FXMath Modules
    // Included using PERL rather than the Javascript include method
    // *************************************************************
	var arrPairs = new Array("USD/MXN","GBP/AUD","XAU/JPY","USD/HUF","USD/NOK","GBP/DKK","EUR/NOK","CHF/MXN","CHF/CAD","AUD/JPY","XAU/EUR","XAG/AUD","USD/PLN","EUR/THB","GBP/CZK","EUR/CAD","AUD/THB","AUD/CZK","SAR/JPY","XAG/CAD","CHF/SGD","AUD/NZD","USD/CHF","CHF/THB","AUD/MXN","USD/ZAR","XAU/CHF","NZD/JPY","EUR/HUF","CHF/SEK","XAG/CHF","SEK/JPY","CHF/AUD","JPY/HUF","CHF/NZD","AUD/SGD","PLN/JPY","THB/JPY","CAD/ZAR","CHF/NOK","CHF/HKD","CAD/PLN","CHF/JPY","AUD/HUF","AUD/HKD","XAG/USD","GBP/SGD","EUR/USD","GBP/JPY","NZD/USD","USD/DKK","SGD/JPY","GBP/CHF","CZK/JPY","DKK/JPY","MXN/JPY","AUD/SEK","XAU/CAD","CAD/MXN","GBP/ZAR","AUD/SAR","GBP/NZD","XAU/GBP","EUR/NZD","AUD/USD","USD/JPY","EUR/SEK","XAG/EUR","GBP/SEK","CAD/HUF","CAD/SAR","GBP/NOK","EUR/CHF","CHF/HUF","XAG/JPY","GBP/THB","CAD/CZK","CAD/THB","USD/SGD","AUD/ZAR","XAG/GBP","CAD/AUD","CAD/NOK","HKD/JPY","GBP/CAD","CHF/SAR","EUR/ZAR","CAD/NZD","CHF/CZK","ZAR/JPY","GBP/MXN","EUR/JPY","EUR/SGD","EUR/HKD","AUD/PLN","CHF/ZAR","USD/SEK","AUD/NOK","EUR/SAR","CAD/SGD","GBP/PLN","GBP/HKD","XAU/AUD","AUD/DKK","USD/CAD","NOK/JPY","XAU/USD","USD/THB","CAD/DKK","GBP/HUF","CAD/JPY","EUR/MXN","EUR/PLN","EUR/AUD","CHF/DKK","CAD/SEK","GBP/SAR","CAD/HKD","EUR/GBP","EUR/DKK","CHF/PLN","USD/CZK","USD/HKD","USD/SAR","EUR/CZK","GBP/USD");
    var arrRates = new Array(11.2633,2.4752,73876.50,204.07,6.0643,10.8678,7.7980,9.2808,0.9030,84.88,512.2736,17.2914,3.0566,49.00,41.0970,1.4092,28.71,16.6113,29.90,14.3481,1.2989,1.1874,1.2134,31.39,8.5281,6.6405,799.3649,71.47,262.43,5.9419,15.8849,15.05,1.0884,1.8181,1.2924,1.1929,36.66,2.9393,6.0578,4.9973,6.3924,2.7883,92.41,154.52,5.8722,13.055,2.9539,1.28576,210.119,0.6372,5.7986,71.12,2.27374,5.08,18.84,9.94,5.4588,722.0336,10.2751,12.4461,2.8385,2.9391,351.5180,2.0167,0.7569,112.145,9.2718,10.1797,13.5123,186.15,3.4210,11.3645,1.5602,168.15,1468.11,71.41,19.9991,34.75,1.5763,5.0286,6.9850,1.2049,5.5321,13.46,2.0537,3.0902,8.5394,1.4308,18.0643,16.87,21.1086,144.204,2.0269,9.9751,2.3147,5.4714,7.2104,4.5911,4.8221,1.4379,5.7293,14.5369,870.1449,4.3900,1.0959,17.99,658.4,38.10,5.2899,382.49,102.29,14.4836,3.9310,1.6985,4.7795,6.5778,7.0273,7.0770,0.68613,7.4575,2.5188,21.9239,7.7576,3.7501,28.1955,1.87373);
    var arrInterestCode = new Array("AUD","CAD","CHF","CZK","DKK","EUR","GBP","HKD","HUF","JPY","MXN","NOK","NZD","PLN","SAR","SEK","SGD","THB","USD","XAG","XAU","ZAR"
);
    var arrInterestBorrow = new Array(5.2000000000,4.0000000000,1.0000000000,1.5000000000,2.4000000000,2.3500000000,4.2500000000,3.5000000000,5.0000000000,-0.1500000000,6.8000000000,2.5000000000,7.0000000000,4.0000000000,4.5000000000,1.6500000000,2.5000000000,3.5000000000,4.7000000000,0.0000000000,-0.5000000000,6.3000000000
);
    var arrInterestLend = new Array(5.5750000000,4.4000000000,1.3500000000,2.0000000000,3.0000000000,2.7500000000,4.5000000000,3.9000000000,6.0000000000,0.2200000000,7.8000000000,3.0000000000,7.5000000000,4.7500000000,5.0000000000,2.1500000000,3.5000000000,5.2500000000,5.2500000000,1.5000000000,0.5000000000,7.5500000000
);

    // *************************************************************
    // Takes in two currency codes ('base' and 'quote') and returns the value of
    // 1 unit of 'quote' as expressed in 'base'.
    // *************************************************************
	function convert(base, quote) 
    {
        if(base == quote) { return 1; }
        
        // Look for pair in arrPairs
        for(i=0; i<arrPairs.length; i++) {

            // break apart the pair and obtain currency code
     	    pair_base = arrPairs[i].substring(0,3);
     	    pair_quote = arrPairs[i].substring(4,7);

            // check to see if code matches the pair we're interested in
     	    if((pair_base == base) && (pair_quote == quote)) { 
             	return arrRates[i]; 
     	    }            
           	else if((pair_quote == base) && (pair_base == quote)) {
     	    	return (1 / arrRates[i]); 
           	}
           	else {               
                // check to see if the currencies that we're trying to convert
                // exist in some form in our conversion array
        		if((pair_base == base) || (pair_quote == base)) { base_ok = 1; }
        		if((pair_base == quote) || (pair_quote == quote)) { quote_ok = 1; } 
            }
         } // end for
   
     // We haven't found a direct coversion rate, we need to do more work

     // If the currency codes exist in our list of currencies (but we don't
     // have a direct conversion between them) then...
     if((base_ok == 1) && (quote_ok == 1)) {
     
     // NOTE: The below assumes that we are able to convert both base and
     // quote to USD
        
        // calculate what one USD is in the base
        base_us = convert(base, "USD"); 
        
        // calculate what quote is in USD
        us_quote = convert("USD", quote);

        // return the product of the two
        return (base_us * us_quote);
     }

     // We weren't able to convert between the two currencies. Is it possible
     // that we don't have a conversion between 'base' or 'quote' and USD?
     return -1;  

  	} // end convert function

    // *************************************************************
   	// Trims a rate to a certain number of decimal places
    // *************************************************************
	function trimRate(txtRate, intNumberOfDecimals) 
    {
        var numerator;
  		var denominator;
        var decimal_index;
        
        decimal_index = txtRate.indexOf(".");
        
        if(decimal_index < 0) { return txtRate; }
		if(intNumberOfDecimals < 1) { return txtRate.substr(0, decimal_index); }         numerator = txtRate.substr(0,decimal_index);
        denominator = txtRate.substr(decimal_index+1, txtRate.length - (decimal_index+1));
        denominator = denominator.substr(0, intNumberOfDecimals);
        return numerator + "." + denominator;
  	} 

    // *************************************************************
	function popUpWindow(wPage, wName) 
    {
   	    wParam = "status=yes,resizable=yes,scrollbars=yes,width=500,height=300";
        window.open(wPage, wName, wParam);
    }	

    // *************************************************************
    // Finds the value of one PIP in this pair
    // eg. USD/EUR is 0.0001 where USD/JPY is 0.01
    // *************************************************************
	function findPipValue(fltRate) 
    {
        var intDecimalIndex = fltRate.toString().indexOf('.')	
		var intLengthDecimalDifference = fltRate.toString().length - intDecimalIndex;
		alert(intLengthDecimalDifference);
		return (1 / (intLengthDecimalDifference * 10));
    }   

function addBookmark(title,url) {
	if (window.sidebar) {
	window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
	window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
	return true;
	}
}
function calc()
{
low=document.forms["form1"].lowValue.value
high=document.forms["form1"].highValue.value

if(high=="") 
{alert("Please enter your High Value"); document.forms["form1"].highValue.focus();return;}

if(low=="") 
{alert("Please enter your Low Value"); document.forms["form1"].lowValue.focus();return;}

if( (parseFloat(low)) > (parseFloat(high)) ) 
{alert("Please make sure your Low Value is smaller than your High Value"); document.forms["form1"].lowValue.focus();return;}

r61=parseFloat(low)+0.618*(high-low)
r50=parseFloat(low)+0.5*(high-low)
r38=parseFloat(low)+0.382*(high-low)

rf61=(Math.round(r61*10000)/10000)
rf50=(Math.round(r50*10000)/10000)
rf38=(Math.round(r38*10000)/10000)

document.form1.retracement61.value=rf61
document.form1.retracement50.value=rf50
document.form1.retracement38.value=rf38

}


    // ***************************************************
    function changePair(txtCurrencyPair)
    {
        // Routine when the user changes the value of the currency pair
        var form = document.frmFXMath;
        var txtBase;
        var txtQuote;
        var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;

        if (txtCurrencyPair == "ACCOUNT BALANCE")
        {
            txtBase = txtPrimaryCode;
            txtQuote = txtPrimaryCode;
        }
        else
        {
            var intSlashIndex = txtCurrencyPair.indexOf('/');
            txtBase = txtCurrencyPair.substr(0, intSlashIndex);
            txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);
        }
        var txtAction = form.cboAction.options[form.cboAction.selectedIndex].value;

        var intBaseUSDIndex;
        var intQuoteUSDIndex;

        
        // Now change {Base}/{Primary currency} combo box
        form.txtBasePrimary.value = convert(txtBase, txtPrimaryCode);
        form.txtBasePrimaryCode.value = txtBase;
        form.txtPrimaryCode1.value = txtPrimaryCode;


        // Change {Quote}/{Primary currency} Combo box
        form.txtQuotePrimaryCode.value = txtQuote;
        form.txtQuotePrimary.value = convert(txtQuote, txtPrimaryCode);
        form.txtPrimaryCode2.value = txtPrimaryCode;
                
        form.txtInterestCode.value = txtPrimaryCode;             
        changeInterestSelection();
    }

        // ***************************************************
		// Handles the event of when an interest selection is changed
		// This should happen as a result of change currency pairs as well
    function changeInterestSelection() 
    {
        // Routine when the user changes the value of the currency pair
        var form = document.frmFXMath;
		var txtCurrencyPair = form.cboCurrencyPair.options[form.cboCurrencyPair.selectedIndex].value;
        var txtBase;
        var txtQuote;
        var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;

        if (txtCurrencyPair == "ACCOUNT BALANCE")
        {
            txtBase = txtPrimaryCode;
            txtQuote = txtPrimaryCode;
        }
        else
        {
            var intSlashIndex = txtCurrencyPair.indexOf('/');
            txtBase = txtCurrencyPair.substr(0, intSlashIndex);
            txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);
        }

		var fltLendRate;
		var fltBorrowRate;
		var intInterestIndex;
		var txtAction = form.cboAction.options[form.cboAction.selectedIndex].value;

		// Change the Lend Interest
		if(txtAction == "BUY") {
		// Quote Lend
		intInterestIndex = findArrayInterestIndex(txtQuote);
		fltLendRate = arrInterestLend[intInterestIndex];
		// Base Borrow
		intInterestIndex = findArrayInterestIndex(txtBase);
		fltBorrowRate = arrInterestBorrow[intInterestIndex];


		form.txtLendInterestCode.value = txtQuote;
		form.txtBorrowInterestCode.value = txtBase;

		}
		else {
		// Quote Borrow
		intInterestIndex = findArrayInterestIndex(txtQuote);
		fltBorrowRate = arrInterestBorrow[intInterestIndex];
		// Base Lend
		intInterestIndex = findArrayInterestIndex(txtBase);
		fltLendRate = arrInterestLend[intInterestIndex];

		form.txtLendInterestCode.value = txtBase;
		form.txtBorrowInterestCode.value = txtQuote;


		}
		form.txtLendInterest.value = fltLendRate.toString();
		form.txtBorrowInterest.value = fltBorrowRate.toString();

		calculateInterest();
		}

        // ******************************************
        // This function checks the editable fields of the form to see if
        // they have values specified. Returns 1 (true) iff the fields have a 
        // value specified.
        // ******************************************
        function checkForPopulatedFields()
        {
            var form = document.frmFXMath;

            if ((form.txtBasePrimary.value != "") &&
               (form.txtQuotePrimary.value != "") &&
               (form.txtUnits.value != "") &&                
               (form.txtHoursHeld.value != "") &&                
               (form.txtLendInterest.value != "") &&                
               (form.txtBorrowInterest.value != "")) {
               return 1;
            }

            return 0;

        }

        // ******************************************
        function changePrimaryCurrency()
        {
            var form = document.frmFXMath;
            var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;
            
            form.txtPrimaryCode1.value = txtPrimaryCode;
            form.txtPrimaryCode2.value = txtPrimaryCode;
            form.txtInterestCode.value = txtPrimaryCode;             

            changePair(document.frmFXMath.cboCurrencyPair.options[document.frmFXMath.cboCurrencyPair.selectedIndex].value);

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }

        // ********************************************************************
        // * The following methods handle the case where the user has manually*
        // * edited a field and we need/should do re-calculations. Though the *
        // * routines for each of these are the same, we have separated them  *
        // * into separate methods to improve modularity and future extension *
        // ********************************************************************

		// *******************************************************
		// The user has manually edited the Base/Primary quote field and so we
        // should re-calculate any necessary values
        function changeBasePrimary()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }



        }

		// *******************************************************
		// The user has manually edited the Base/Primary quote field and so we
        // should re-calculate any necessary values
        function changeQuotePrimary()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }
        
		// *******************************************************
		// The user has updated the number of units they're querying about
        //  we should re-calculate any necessary values
        function changeNumberOfUnits()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }
		// *******************************************************
        function changeHoursHeld()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }
		// *******************************************************
        function changeLendInterestCode()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }
		// *******************************************************
        function changeBorrowInterestCode()
        {
            var form = document.frmFXMath;

            if (1 == checkForPopulatedFields()) 
            {
                calculateInterest();
            }
        }

		// ***************************************************
		// Finds the index of the code in the interest code array
		function findArrayInterestIndex(txtCode) {
		if(txtCode == "") { return -1; }
		for(i=0;i<arrInterestCode.length;i++){
		  if(arrInterestCode[i] == txtCode) { return i; }
		  }
		  return -1;
		  }

		  // ***************************************************
		      function seconds_in_this_year() {
		          // get length of this year by subtracting
			  // "Jan 1st, /This Year/" from  "Jan 1st, /Next Year/"
			  var now = new Date();
			  var current_year = now.getFullYear();
			  var jan_first = new Date(current_year, 0, 1, 0, 0, 0, 0);
			  var jan_next = new Date(current_year + 1, 0, 1, 0, 0, 0, 0);
			  return (jan_next.getTime() - jan_first.getTime()) / 1000;
			  } 
				      
	// ***************************************************
    function calculateInterest() 
    {
        var form = document.frmFXMath;
			 
		if( (form.txtQuotePrimary.value != "") &&
		(form.txtBasePrimary.value != "") &&
		(form.txtLendInterest.value != "") &&
		(form.txtBorrowInterest.value != "") &&
		(form.txtHoursHeld.value != "") &&
		(form.txtUnits.value != "")) 
        {
            var txtCurrencyPair = form.cboCurrencyPair.options[form.cboCurrencyPair.selectedIndex].value;
            var txtPrimaryCode = form.cboPrimaryCurrency.options[form.cboPrimaryCurrency.selectedIndex].value;
            var txtBase;
            var txtQuote;

            if (txtCurrencyPair == "ACCOUNT BALANCE")
            {
                txtBase = txtPrimaryCode;
                txtQuote = txtPrimaryCode;
            }
            else
            {
                var intSlashIndex = txtCurrencyPair.indexOf('/');
                txtBase = txtCurrencyPair.substr(0, intSlashIndex);
                txtQuote = txtCurrencyPair.substr(intSlashIndex+1, 3);
            }
            var fltQuoteUSD = parseFloat(form.txtQuotePrimary.value);
            var fltBaseUSD = parseFloat(form.txtBasePrimary.value);
	
            var fltLendInterestRate = parseFloat(form.txtLendInterest.value);
            var fltBorrowInterestRate = parseFloat(form.txtBorrowInterest.value);


            var intUnits = parseInt(form.txtUnits.value);
            var fltHours = parseFloat(form.txtHoursHeld.value);
            var txtAction = form.cboAction.options[form.cboAction.selectedIndex].value;
            var fltYears = (fltHours * 3600) / seconds_in_this_year();
            var intConvertedUnits = convert(txtBase, txtQuote) * intUnits;
            var fltBorrowInterestResult;
            var fltLendInterestResult;
            var fltTotalResult;

            fltBorrowInterestResult = (fltBorrowInterestRate/100) * fltYears * fltBaseUSD * intUnits;
            fltLendInterestResult = (fltLendInterestRate/100) * fltYears * fltQuoteUSD * intConvertedUnits;
            if(txtBase == txtQuote) 
            {
                fltBorrowInterestResult = (fltBorrowInterestRate/100) * fltYears * fltBaseUSD * intUnits;
                fltLendInterestResult = 0;
            }
            fltTotalResult = fltBorrowInterestResult - fltLendInterestResult;
            form.txtInterest.value = trimRate(fltTotalResult.toString(), 5);
		}
    }	

		// ***************************************************
        function changeAction() {
            changeInterestSelection();
        }
    // *************************************************************
	// Common Javascript for FXMath Modules
    // Included using PERL rather than the Javascript include method
    // *************************************************************
	var arrPairs = new Array("USD/MXN","GBP/AUD","XAU/JPY","USD/HUF","USD/NOK","GBP/DKK","EUR/NOK","CHF/MXN","CHF/CAD","AUD/JPY","XAU/EUR","XAG/AUD","USD/PLN","EUR/THB","GBP/CZK","EUR/CAD","AUD/THB","AUD/CZK","SAR/JPY","XAG/CAD","CHF/SGD","AUD/NZD","USD/CHF","CHF/THB","AUD/MXN","USD/ZAR","XAU/CHF","NZD/JPY","EUR/HUF","CHF/SEK","XAG/CHF","SEK/JPY","CHF/AUD","JPY/HUF","CHF/NZD","AUD/SGD","PLN/JPY","THB/JPY","CAD/ZAR","CHF/NOK","CHF/HKD","CAD/PLN","CHF/JPY","AUD/HUF","AUD/HKD","XAG/USD","GBP/SGD","EUR/USD","GBP/JPY","NZD/USD","USD/DKK","SGD/JPY","GBP/CHF","CZK/JPY","DKK/JPY","MXN/JPY","AUD/SEK","XAU/CAD","CAD/MXN","GBP/ZAR","AUD/SAR","GBP/NZD","XAU/GBP","EUR/NZD","AUD/USD","USD/JPY","EUR/SEK","XAG/EUR","GBP/SEK","CAD/HUF","CAD/SAR","GBP/NOK","EUR/CHF","CHF/HUF","XAG/JPY","GBP/THB","CAD/CZK","CAD/THB","USD/SGD","AUD/ZAR","XAG/GBP","CAD/AUD","CAD/NOK","HKD/JPY","GBP/CAD","CHF/SAR","EUR/ZAR","CAD/NZD","CHF/CZK","ZAR/JPY","GBP/MXN","EUR/JPY","EUR/SGD","EUR/HKD","AUD/PLN","CHF/ZAR","USD/SEK","AUD/NOK","EUR/SAR","CAD/SGD","GBP/PLN","GBP/HKD","XAU/AUD","AUD/DKK","USD/CAD","NOK/JPY","XAU/USD","USD/THB","CAD/DKK","GBP/HUF","CAD/JPY","EUR/MXN","EUR/PLN","EUR/AUD","CHF/DKK","CAD/SEK","GBP/SAR","CAD/HKD","EUR/GBP","EUR/DKK","CHF/PLN","USD/CZK","USD/HKD","USD/SAR","EUR/CZK","GBP/USD");
    var arrRates = new Array(11.2983,2.4826,72704.48,204.34,6.0709,10.8673,7.8013,9.2998,0.9042,84.58,504.4801,16.8385,3.0623,49.00,41.1570,1.4114,28.63,16.5820,29.90,13.9524,1.2964,1.1851,1.2146,31.38,8.5254,6.6770,787.4612,71.32,262.61,5.9351,15.4268,15.05,1.0914,1.8206,1.2937,1.1875,36.59,2.9370,6.0772,4.9975,6.3860,2.7876,92.32,154.14,5.8503,12.665,2.9492,1.28491,209.986,0.6359,5.8024,71.19,2.27446,5.07,18.82,9.91,5.4373,712.1994,10.2832,12.5055,2.8280,2.9430,346.1889,2.0194,0.7541,112.145,9.2648,9.8829,13.5017,186.00,3.4133,11.3690,1.5608,168.20,1424.37,71.42,19.9998,34.70,1.5749,5.0376,6.7818,1.2066,5.5260,13.46,2.0570,3.0871,8.5807,1.4305,18.0842,16.78,21.1619,144.105,2.0238,9.9682,2.3102,5.4961,7.2098,4.5787,4.8189,1.4334,5.7360,14.5261,859.5196,4.3763,1.0984,17.97,647.9,38.13,5.2821,382.75,102.06,14.5199,3.9357,1.7033,4.7776,6.5629,7.0223,7.0608,0.68615,7.4574,2.5209,21.9711,7.7574,3.7501,28.2375,1.87239);
    var arrInterestCode = new Array("AUD","CAD","CHF","CZK","DKK","EUR","GBP","HKD","HUF","JPY","MXN","NOK","NZD","PLN","SAR","SEK","SGD","THB","USD","XAG","XAU","ZAR"
);
    var arrInterestBorrow = new Array(5.2000000000,4.0000000000,1.0000000000,1.5000000000,2.4000000000,2.3500000000,4.2500000000,3.5000000000,5.0000000000,-0.1500000000,6.8000000000,2.5000000000,7.0000000000,4.0000000000,4.5000000000,1.6500000000,2.5000000000,3.5000000000,4.7000000000,0.0000000000,-0.5000000000,6.3000000000
);
    var arrInterestLend = new Array(5.5750000000,4.4000000000,1.3500000000,2.0000000000,3.0000000000,2.7500000000,4.5000000000,3.9000000000,6.0000000000,0.2200000000,7.8000000000,3.0000000000,7.5000000000,4.7500000000,5.0000000000,2.1500000000,3.5000000000,5.2500000000,5.2500000000,1.5000000000,0.5000000000,7.5500000000
);

    // *************************************************************
    // Takes in two currency codes ('base' and 'quote') and returns the value of
    // 1 unit of 'quote' as expressed in 'base'.
    // *************************************************************
	function convert(base, quote) 
    {
        if(base == quote) { return 1; }
        
        // Look for pair in arrPairs
        for(i=0; i<arrPairs.length; i++) {

            // break apart the pair and obtain currency code
     	    pair_base = arrPairs[i].substring(0,3);
     	    pair_quote = arrPairs[i].substring(4,7);

            // check to see if code matches the pair we're interested in
     	    if((pair_base == base) && (pair_quote == quote)) { 
             	return arrRates[i]; 
     	    }            
           	else if((pair_quote == base) && (pair_base == quote)) {
     	    	return (1 / arrRates[i]); 
           	}
           	else {               
                // check to see if the currencies that we're trying to convert
                // exist in some form in our conversion array
        		if((pair_base == base) || (pair_quote == base)) { base_ok = 1; }
        		if((pair_base == quote) || (pair_quote == quote)) { quote_ok = 1; } 
            }
         } // end for
   
     // We haven't found a direct coversion rate, we need to do more work

     // If the currency codes exist in our list of currencies (but we don't
     // have a direct conversion between them) then...
     if((base_ok == 1) && (quote_ok == 1)) {
     
     // NOTE: The below assumes that we are able to convert both base and
     // quote to USD
        
        // calculate what one USD is in the base
        base_us = convert(base, "USD"); 
        
        // calculate what quote is in USD
        us_quote = convert("USD", quote);

        // return the product of the two
        return (base_us * us_quote);
     }

     // We weren't able to convert between the two currencies. Is it possible
     // that we don't have a conversion between 'base' or 'quote' and USD?
     return -1;  

  	} // end convert function

    // *************************************************************
   	// Trims a rate to a certain number of decimal places
    // *************************************************************
	function trimRate(txtRate, intNumberOfDecimals) 
    {
        var numerator;
  		var denominator;
        var decimal_index;
        
        decimal_index = txtRate.indexOf(".");
        
        if(decimal_index < 0) { return txtRate; }
		if(intNumberOfDecimals < 1) { return txtRate.substr(0, decimal_index); }         numerator = txtRate.substr(0,decimal_index);
        denominator = txtRate.substr(decimal_index+1, txtRate.length - (decimal_index+1));
        denominator = denominator.substr(0, intNumberOfDecimals);
        return numerator + "." + denominator;
  	} 

    // *************************************************************
	function popUpWindow(wPage, wName) 
    {
   	    wParam = "status=yes,resizable=yes,scrollbars=yes,width=500,height=300";
        window.open(wPage, wName, wParam);
    }	

    // *************************************************************
    // Finds the value of one PIP in this pair
    // eg. USD/EUR is 0.0001 where USD/JPY is 0.01
    // *************************************************************
	function findPipValue(fltRate) 
    {
        var intDecimalIndex = fltRate.toString().indexOf('.')	
		var intLengthDecimalDifference = fltRate.toString().length - intDecimalIndex;
		alert(intLengthDecimalDifference);
		return (1 / (intLengthDecimalDifference * 10));
    }