function updateForm()
{
	var form = document.prices;

	var total=0;
	var features=0;
	var options=0;
	var oi_package=0;

	var iList = form.getElementsByTagName('INPUT');

	for( var i=0; i<iList.length; i++)
	{
		var input = iList[i];
		if(input.checked==false)
			continue;
		var td = input.parentNode.nextSibling;
		if(td==null)
			continue;
		if(td.className=='col2')
		{
			if(td.firstChild!=null)
			{
				var price = td.firstChild.nodeValue;
				price = price.replace("$", "");
				price = price.replace("+", "");
				price = price.replace(",", "");
				total = parseFloat(total) + parseFloat(price);
				//alert(td.parentNode.parentNode.parentNode);
				if(input.name.indexOf('oi_package')>-1)
				{
					oi_package = parseFloat(price);
					//2008-02-18 DKU T#5470
					//var tmp = document.getElementById('features_value_price');
					//if(tmp!=null)
					//	tmp.innerHTML='+$' + formatPrice(oi_package*0.4);
					features = parseFloat(features) + parseFloat(price);
				}
				else if(input.name.indexOf('features')>0)
					features = parseFloat(features) + parseFloat(price);
				else if(td.parentNode.parentNode.parentNode.id=='options')
					options = parseFloat(options) + parseFloat(price);
			}
		}
	}

	var select = document.getElementById('form_prices_oi_extra_sets');

	if(select!=null)
	{
		var price = parseFloat(select.value) * parseFloat(document.getElementById('extra_sets_cost').innerHTML)

		var td = select.parentNode.nextSibling;
		if(td.className=='col2')
		{
			if(td.firstChild!=null)
				td.firstChild.nodeValue ='+$'+formatPrice(price);
		}
		total = parseFloat(total) + parseFloat(price);
		options = parseFloat(options) + parseFloat(price);
	}

	var tmp = document.getElementById('total_price');
	tmp.innerHTML = formatPrice(total);

	tmp = document.getElementById('features_subtotal');
	if(tmp!=null)
		tmp.innerHTML = formatPrice(features);

	//tmp = document.getElementById('options_subtotal');
	//tmp.innerHTML = formatPrice(options);
}

function setCheckFunction()
{
	var iList = document.prices.getElementsByTagName('INPUT');
	for(var i=0; i<iList.length; i++)
	{
		if((iList[i].type.toLowerCase() == 'checkbox' || iList[i].type.toLowerCase() == 'radio') && iList[i].name!='oi_customization')
			iList[i].onclick=updateForm;
	}
}

function checkPricesForm()
{
	var pList = document.getElementsByName('oi_package');
	for(var i=0; i<pList.length; i++)
	{
		if(pList[i].checked==true)
		{
			var fList = document.getElementsByName('oi_foundation_options');
			if(fList.length==0)
				return true;
			for(var j=0; j<fList.length; j++)
			{
				if(fList[j].checked==true)
					return true;
			}
			fList[0].focus();
			alert('You must choose Foundation Option.');
			return false;
		}
	}
	pList[0].focus();
	alert('You must choose Package.');
	return false;
}

function customization()
{
	var select = document.getElementById('form_prices_customization');
	var element = select.parentNode

	var tmpList = element.getElementsByTagName('INPUT');
	setDisabled(tmpList, select);
	tmpList = element.getElementsByTagName('TEXTAREA');
	setDisabled(tmpList, select);
	tmpList = element.getElementsByTagName('SELECT');
	setDisabled(tmpList, select);
}

function setDisabled(list, element)
{
	for(var i=0; i<list.length; i++)
	{
		if(list[i].type!='checkbox')
			list[i].disabled=!element.checked
	}
}

function formatPrice(d,decimal)
{
	var d2 = Math.floor(d);
	var s = "" + ((d*100-d2*100));
	if (s.length>2) s=s.substr(0,2);
	else while (s.length<2) s="0"+s;

	var s1=""+d2;
	if (s1.length>3) s1=s1.substr(0,s1.length-3) + "," + s1.substr(s1.length-3,s1.length)
	return s1+"."+s;
}
