/***************************************************************************************** * DESC:    Code to update quantities on the approval tool * DATE:    12/22/2008 * BY:      Consolidated Marketing Services  *          Ed Orsini  ****************************************************************************************/	function fieldChanged (icn) {	  // set changed flag to TRUE		document.getElementById('changed').value = 'true';				// define and initialize variables		tax = 0;		//shipping = 0;		price = document.getElementById( 'price' + icn ).value;		quantity = document.getElementById ( 'quan' + icn ).value;		delcheck = document.getElementById ( 'del' + icn );		tax = document.getElementById ( 'taxtotal' ).value;		shipping = document.getElementById ( 'shippingtotal' ).value;		//alert(shipping);				// if deleted is checked		if ( delcheck.checked ) {			document.getElementById ( 'total' + icn ).value = 0.00;		}		// if the quantity changed		else {			document.getElementById ( 'total' + icn ).value = toUSCurrency(quantity * price);		}				// specifies the form in order to manipulate the elements		elements = document.forms['orderdtl'].elements;				// whole order sum		sum = 0.00;		for ( i = 0; i < elements.length; i++ ) {			field = elements[i];						if ( field.id.substring(0, 5) == 'total' ) {				sum = (parseFloat(field.value) + sum);			}		}				document.getElementById ( 'abstotal' ).value = toUSCurrency( sum ); // Order Cost    //document.getElementById ( 'taxtotal' ).value = sum;  // Tax Total		//document.getElementById ( 'shippingtotal' ).value = sum;  // Shipping Total		document.getElementById ( 'completetotal' ).value = toUSCurrency((sum * 1) + (tax * 1) + (shipping * 1)); // Complete Total			}		function updateTotal () {	 		// define and initialize variables		price = document.getElementById( 'price' + icn ).value;		quantity = document.getElementById ( 'quan' + icn ).value;		delcheck = document.getElementById ( 'del' + icn );		tax = document.getElementById ( 'taxtotal' ).value;		shipping = document.getElementById ( 'shippingtotal' ).value;				// specifies the form in order to manipulate the elements		elements = document.forms['orderdtl'].elements;				// whole order sum		sum = 0.00;		for ( i = 0; i < elements.length; i++ ) {			field = elements[i];						if ( field.id.substring(0, 5) == 'total' ) {				sum = (parseFloat(field.value) + sum);			}		}				document.getElementById ( 'abstotal' ).value = toUSCurrency( sum ); // Order Cost		document.getElementById ( 'completetotal' ).value = toUSCurrency((sum * 1) + (tax * 1) + (shipping * 1)); // Complete Total	}	  function toUSCurrency (input) {	// Make sure input is a string:	input += "";	// Keep original copy of input string:	var original_input = input;	// Strip leading dollar sign if necessary:	if (input . charAt (0) == "$")		input = input . substring (1, input . length);	else if	(		input . substring (0, 2) == "-$"	||	input . substring (0, 2) == "+$"	)		input = input . charAt (0) + input . substring (2, input . length);	// Get float value:	var amount = parseFloat (input);	// Return unmodified input if we weren't able to convert it:	if (isNaN (amount))		return original_input;	// Express amount in pennies, rounded to the nearest penny:	amount = Math . round (100 * amount);	// Prepare to add a US currency prefix:	var prefix = "$";	if (amount < 0)	{		prefix = "-" + prefix;		amount = - amount;	}	// Convert amount to string and pad with leading zeros if necessary:	var string;	if (amount < 10)		string = "00" + amount;	else if (amount < 100)		string = "0" + amount;	else		string = "" + amount;	// Insert prefix:	//string = prefix + string; // taken off so that I can calculate	// Insert decimal point before last two digits:	string =		string . substring (0, string . length - 2) +		"." +		string . substring (string . length - 2, string . length);	// Return formatted currency string:	return string;}
