
//this function is called on the product options select boxes' OnChange event.  It takes the name and value of the select box and uses the base_price hidden field to calculate the adjusted price of the item based on the options' values

function change_price ()
{
	
	//variables to be used to get element position of the current select variable's name in the loop 	
	var tmpstartpos = 0;
	var tmpendpos = 0;

	
	var id = '';

	//get the base price from the hidden variable with id = base_price_id
	var base_price = parseFloat(document.getElementById('base_price_id').value);
	var tmpObject;

	//loop through each 
	for (i = 0; i < id_array.length; i ++)
	{
		//get the next select element and store the reference in a variable
		tmpObject = document.getElementById('id['+ id_array[i] +']');
		
//		alert('The value of name is: ' + tmpObject.name+ ', the value is: ' + tmpObject.value);	

		//get the element position of the current select variable's name (get the value between the brackets):
		tmpstartpos = tmpObject.name.indexOf('[');
		tmpendpos = tmpObject.name.indexOf(']');		
		id = tmpObject.name.substring((tmpstartpos + 1), (tmpendpos));
		
		base_price = base_price + parseFloat(product_attributes[id][tmpObject.value])
	}
	
	document.getElementById('dynamic_price').innerHTML = "$"+format_number(base_price);
}


//This function takes a float number and formats it with commas and two decimal places
function format_number(val)
{
	//take the number and find out how many commas should be inserted.
	
	nStr = val.toFixed(2);

	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}