
    function formatCurrency( rawValue, showPence, showPenceSymbol)
    {
        if ( typeof(showPence) == "undefined")
        {
            showPence = true; 
        } 
        if ( typeof(showPenceSymbol) == "undefined")
        {
            showPenceSymbol = true;
        } 
      
	    rawValue += '';
	    var cSplit = rawValue.split('.');
	
	    var pence;
	    var pounds = cSplit[0];
        if ( parseInt(pounds) > 0)
        {
	        var rgx = /(\d+)(\d{3})/;
	        while (rgx.test(pounds)) 
	        {
	    	    pounds =  pounds.replace(rgx, '$1' + ',' + '$2');
	        }  
	        pounds = "&#163;" + pounds;
	    }
    	else
	    {
	    
	        pounds = "";
	    }
	
	    if (cSplit.length > 1)
	    {
	        pence = cSplit[1];
	    
	        if ( pence.length == 1)
	        {
	            pence = ((pounds != "") ? "." : "") + pence + "0";
	        }
	        else
	        {
	            pence = ((pounds != "") ? "." : "") + pence ;
	        }
	        var haspence = true;
	    }
	    else
	    {
	        haspence = false;
	        pence = "";
	    }
	  
	    if ( pounds != "")
        {
        	showPenceSymbol = false;
	     
        }

	    
	    return  pounds +  ((showPence && haspence) ? pence : "") + ((showPenceSymbol && showPence && haspence ) ? "p" : "");
    }
    

	function getValueInRange( value, min, max)
	{
		//if ( value < min)
		//{
		//	value = min;
		//}
		//if ( value > max)
		//{
		//	value = max;
		//}
		
		return ((value < min) ? min : ( (value > max ) ? max : value));
		
		//17-8-07: tg created this 1 line version.  test for a while before removing commented code.
		
		//return value;
	}



	function parseImageUrl( obj, oldSuffix, newSuffix)
	{
		if ((!obj) || (!oldSuffix) || (!newSuffix)) return false;
		if (!obj.style.backgroundImage) return false;
	 
		var initalBG = obj.style.backgroundImage; 
		var step1, step2, step3, verify = false;
	 
		if ( initalBG != "")
		{
			step1 = initalBG.split("(");
			step2 = step1[1].split(".");
			step3 = step2[0].split(oldSuffix);
			verify = true;
		}
	 
		return (verify) ? "url(" + step3[0] + newSuffix + ".gif)" : false;
	}
	function navIsSelected( obj)
	{
		if (!obj) return false;	
		if (!obj.style) return false;
		if (!obj.style.backgroundImage) return false;
	
		return ( (obj.style.backgroundImage).indexOf("_selected") != -1) ? true : false;
	
	}
	function setMenuImageOn()
	{
		var newImage;	
	
		if ( !navIsSelected( this))
		{
			if ( newImage = parseImageUrl( this, "_off", "_on"))
			{
				this.style.backgroundImage = newImage;
			}
		}
	}
	function setMenuImageOff()
	{
		var newImage;
	
		if ( !navIsSelected( this))
		{
			if ( newImage = parseImageUrl( this, "_on", "_off"))
			{
				this.style.backgroundImage = newImage;
			}
		}
	}
	function initializeSiteNavigtaionMenu()
	{
		var x,y,siteNavMenu = $TGFUNC_("siteNavigationMenu");
	  	if (!siteNavMenu ) return false;
	 
	  	for (x=0; x<siteNavMenu.childNodes.length;x++)
	  	{
			if (siteNavMenu.childNodes[x].nodeType == 1)
			{
				for (y=0; y<siteNavMenu.childNodes[x].childNodes.length;y++)
				{
					if (siteNavMenu.childNodes[x].childNodes[y].nodeType == 1)
					{
						siteNavMenu.childNodes[x].childNodes[y].onmouseover = setMenuImageOn;
						siteNavMenu.childNodes[x].childNodes[y].onmouseout = setMenuImageOff;
					}
				}
			}
		}
		return true;
	}








/*   Loan calculator */


    function SetLoanCalcValues(monthlyInterestRate, paymentProtectionRate, loanAmount, loanTerm)
    {
        loanCalculator.IR = monthlyInterestRate;
        loanCalculator.PPIWS = paymentProtectionRate;
        loanCalculator.LA = loanAmount;
        loanCalculator.LT = loanTerm;
    }


		var loanCalculator = 
		{
			IR:.00693,
			PPIWS: .1662,
			LA: 5000,
			LT:5,
			getPPIA: function()
			{
				var LA = loanCalculator.LA;
				var PPIWS = loanCalculator.PPIWS;
				
				return LA*PPIWS;
			},
			getPPID: function()
			{
				var PPIA = loanCalculator.getPPIA();
				var LT = loanCalculator.LT;
				
				return Math.round( ( (loanCalculator.getTotalRepaymentWithProtection() - loanCalculator.getTotalRepayment() ) / ( LT * ( 365 /12))) * 100) / 100;
				

			},
			getLAP: function()
			{
				var LA = loanCalculator.LA;
				
				return (LA + loanCalculator.getPPIA());
			},
			getTotalRepaymentWithProtection: function()
			{
			
				var LAP = loanCalculator.getLAP();
				var LT = loanCalculator.LT;
				var IR = loanCalculator.IR;
			
				return (LAP * LT * IR)/(1-(Math.pow((1+IR),-LT)));
			},
			
			getTotalRepayment: function()
			{
				var LA = loanCalculator.LA;
				var LT = loanCalculator.LT;
				var IR = loanCalculator.IR;
				
				return (LA * LT * IR)/(1-(Math.pow((1+IR),-LT)));
			},
			getMonthlyRepaymentWithProtection: function()
			{	
				var LT = loanCalculator.LT;
				var TR = loanCalculator.getTotalRepaymentWithProtection();
				return Math.round( (TR/LT)*100)/100;
			},
			getMonthlyRepayment: function()
			{
				var LT = loanCalculator.LT;
				var TR = loanCalculator.getTotalRepayment();
				return Math.round( (TR/LT)*100)/100;
			},
			getRoundedTotalRepaymentWithProtection: function()
			{
				var MP = loanCalculator.getMonthlyRepaymentWithProtection();
				var LT = loanCalculator.LT;
				
				return Math.round((MP*LT)*100)/100;
			},
			getRoundedTotalRepayment: function()
			{
				var MP = loanCalculator.getMonthlyRepayment();
				var LT = loanCalculator.LT;
				
				return Math.round((MP*LT)*100)/100;
			},
			
			//RO - bonus calc here.
			//11/04/2008
		
		    //PPI calcs
		    getBonusPPID: function()
			{
				var PPIA = loanCalculator.getBonusPPIA();
				var LT = loanCalculator.LT;
				var TotalPPI = PPIA - loanCalculator.getRoundedBonusTotalRepayment();
				return Math.round( ( (TotalPPI) / ( LT * ( 365 /12))) * 100) / 100;
						
			},
			
						
			getBonusMonthlyRepaymentWithProtection: function()
			{	
				var PPIA = loanCalculator.getBonusPPIA();
				var LT = loanCalculator.LT;
				var TotalPPI = PPIA - loanCalculator.getRoundedBonusTotalRepayment();
				return Math.round( (TotalPPI/LT)*100)/100;
			},
					
		    getBonusPPIA: function()
			{
				var LA = loanCalculator.getRoundedBonusTotalRepayment();
				var PPIWS = 1+ loanCalculator.PPIWS;
				return LA*PPIWS;
			},
			
			getBonusLAP: function()
			{
				var LA = loanCalculator.LA;
				
				return (LA + loanCalculator.getBonusPPIA());
			},
				
			//Normal Calcs - no PPI
			getRoundedBonusTotalRepayment: function()
			{
				var MP = loanCalculator.getMonthlyBonusRepayment();
				var LT = loanCalculator.LT;
				return Math.round((MP*LT)*100)/100;
			},
		
		    getMonthlyBonusRepayment: function()
			{
				var LT = loanCalculator.LT;
				var TR = loanCalculator.getTotalBonusRepayment();
				return Math.round( (TR/LT)*100)/100;
			},
			
			getTotalBonusRepayment: function()
			{
				var DiscountPeriod = 3;
				var FollowOnPeriod = loanCalculator.LT-3;
				var InitialPayment = DiscountPeriod * loanCalculator.getInitialMonthlyRepayment();
				var FollowOnPayment = FollowOnPeriod * loanCalculator.getInitialGotoMonthlyRepayment();
 			    var total =InitialPayment + FollowOnPayment;
 			    return total;
			},
			
			getInitialTotalRepayment: function()
			{
				var LA = loanCalculator.LA;
				var LT = loanCalculator.LT;
				var IR = 0.00403;
				return (LA * LT * IR)/(1-(Math.pow((1+IR),-LT)));
			},
						
			getInitialMonthlyRepayment: function()
			{
				var LT = loanCalculator.LT;
				var TR = loanCalculator.getInitialTotalRepayment();
				return Math.round( (TR/LT)*100)/100;
				
			},
			
			getInitialGotoTotalRepayment: function()
			{
				var LA = loanCalculator.LA;
				//reduce Loan Term by 3 months
				var LT = loanCalculator.LT-3;
				var IR = 0.00693;
			    //calc interest for 3 months and add to total amount owing.
			    var IntialMonthlyPayment = loanCalculator.getInitialMonthlyRepayment();
			    var Month1 = LA+(LA*0.00403)-IntialMonthlyPayment;
			    var Month2 = Month1+(Month1*0.00403)-IntialMonthlyPayment;
			    var Month3 = Month2+(Month2*0.00403)-IntialMonthlyPayment;
				LA=Month3;
				return (LA* LT * IR)/(1-(Math.pow((1+IR),-LT)));
				
			},
							
			
			getInitialGotoMonthlyRepayment: function()
			{
				var LT = loanCalculator.LT-3;
				var TR = loanCalculator.getInitialGotoTotalRepayment();
				return Math.round( (TR/LT)*100)/100;
			}
					
			//end of bonus calc
					
		}