
//
// function to recalcaulate Total Price for "Purchase & Sale Summary" form
function RecalculateTotalPrice()
{
	var nPrice1 = 0;
	var nPrice2 = 0;
	var nPrice3 = 0;
	
	// get all input elements on the page
	var pElements = document.getElementsByTagName("INPUT");
	
	// find 3 textboxe for Prices     
	for (i = 0; i < pElements.length; i++)
	{
		var pElement = pElements[i];
		
		// if Price can not be retrieved, ignore this element
		if ( isNaN(parseInt(pElement.value)) )
			continue;
		
		// get Prices
		if (pElement.id.indexOf("txtPrice1") >= 0)
			nPrice1 = parseInt(pElement.value);
		else if (pElement.id.indexOf("txtPrice2") >= 0)
			nPrice2 = parseInt(pElement.value);
		else if (pElement.id.indexOf("txtPrice3") >= 0)
			nPrice3 = parseInt(pElement.value);
	}
	
	// calculate Total price
	var nTotalPrice = nPrice1 + nPrice2 + nPrice3;
			
	// display Total price
	if (nTotalPrice > 0)
		document.getElementById("divTotalPrice").innerHTML = "&pound;" + nTotalPrice;
	else
		document.getElementById("divTotalPrice").innerHTML = "N/A";
}


//
// Add event handlers to Price textboxes on "Purchase & Sale Summary" form
function AddRecalculateTotalPriceEvent()
{
	// get all input elements on the page
	var pElements = document.getElementsByTagName("INPUT");
	
	// find all Price textboxes     
	for (i = 0; i < pElements.length; i++)
	{
		var pElement = pElements[i];
		
		// add events
		if (pElement.id.indexOf("txtPrice") >= 0)
			pElement.onkeyup = RecalculateTotalPrice;
		
	}
}