var Sum = 235; // The Initial amount  //
var Amt = 0;
var Index = 0;

SumArray = new Array(235,0,0,0,0); // The prices of products that are selected by default when the page opens //
SelectedIndexes = Array(0,0,0,0,0,1,1); // The selected Indexes of all Radio Buttons Starting From 0 //

IndexValues = Array();
// The following arrays contain the Code of the products //
IndexValues[0] = Array(''); 
IndexValues[1] = Array('2');
IndexValues[2] = Array('0', '1');
IndexValues[3] = Array('0', '2');
IndexValues[4] = Array('P385C','P385F','P392C','P392F','N672C','N672F','C427C','C427F');
IndexValues[5] = Array('CBL04', ' ');
IndexValues[6] = Array('CBL02', ' ');

PricesArray = new Array();
// The following arrays contain the Prices of all the products //
PricesArray[0] = new Array(235);
PricesArray[1] = new Array(0);
PricesArray[2] = new Array(0,30);
PricesArray[3] = new Array(0,0);
PricesArray[4] = new Array(0,0,0,0,0,0,0,0);
PricesArray[5] = new Array(19,0);
PricesArray[6] = new Array(39,0);

function CreateModelNumber(RadioIndex, SelectedIndex)
{
	if (RadioIndex > 4) // if the function is called on clicking a checkbox //
	{
		if (document.getElementById('checkbox'+RadioIndex).checked)
		{
			Amt = PricesArray[RadioIndex][SelectedIndex];

			SumArray[RadioIndex] = Amt;
			Sum += Amt;
		
			Q = document.form1.qty.selectedIndex+1;
			Amt = Sum*Q;
		}
		else
		{
			Sum = Sum - SumArray[RadioIndex];
			Amt = 0;
			Q = document.form1.qty.selectedIndex+1;
			Amt = Sum*Q;
		}
	}
	else
	{
		Sum = Sum - SumArray[RadioIndex];
	
		Amt = PricesArray[RadioIndex][SelectedIndex];
	
		SumArray[RadioIndex] = Amt;
		Sum += Amt;
	
		Q = document.form1.qty.selectedIndex+1;
		Amt = Sum*Q;
	}

	SelectedIndexes[RadioIndex] = SelectedIndex;

	Code = 'LTA'; // The value that is always selected //
	for (i=0;i<5;i++) // This loop generates the code according to the selected Radios //
	{
		Code = Code + '' + IndexValues[i][SelectedIndexes[i]];
	}

	for (i=5;i<7;i++) // This loop adds the code of selected 'Add-on Options' to the Model Number //
	{
		if (document.getElementById('checkbox'+i).checked)
		{
			Code = Code + ', ' + IndexValues[i][0];
		}
	}

	document.getElementById('ModelNumber').innerHTML = Code; // Write the generated Code to the Table at the end of the page //
	document.getElementById('BasicPrice').innerHTML = Sum; // Write the Sum to the Table at the end of the page //
	document.getElementById('OrderQuantity').innerHTML = Q; // Write the Quantity to the Table at the end of the page //
	document.getElementById('OrderTotal').innerHTML = Amt; // Write the Entended Price to the Table at the end of the page //

	document.getElementById('ModelConfig').value = Code; // Set the value of hidden field 'ModelConfig' to the generated Code //

	document.forms.form1.PricePerModel.value = Sum; // Set the value of hidden field 'PricePerModel' to Price Per Model //
	document.forms.form1.hdnQuantity.value = Q; // Set the value of hidden field 'hdnQuantity' to the Quantity //
}

function calculateTotal() // This function is called when the Quantity is changed //
{
	Q = document.form1.qty.selectedIndex+1;
	Amt = Sum*Q;
	
	document.getElementById('BasicPrice').innerHTML = Sum;
	document.getElementById('OrderQuantity').innerHTML = Q;
	document.getElementById('OrderTotal').innerHTML = Amt;

	document.forms.form1.PricePerModel.value = Sum;
	document.forms.form1.hdnQuantity.value = Q;
}

window.onload = function()
{
	Code = 'LTA';
	for (i=1;i<5;i++)
	{
		Code = Code + '' + IndexValues[i][SelectedIndexes[i]];
	}

	for (i=5;i<7;i++)
	{
		document.getElementById('checkbox'+i).checked = false;
	}
	document.getElementById('ModelNumber').innerHTML = Code;

	document.getElementById('ModelConfig').value = Code;
	document.forms.form1.PricePerModel.value = 235;
	document.forms.form1.hdnQuantity.value = 1;
}
