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

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

IndexValues = Array();
// The following arrays contain the Code of the products //
IndexValues[0] = Array('L'); 
IndexValues[1] = Array('1', '2', '3', '4');
IndexValues[2] = Array('0', '1');
IndexValues[3] = Array('0', '1', '2','3','4');
IndexValues[4] = Array('0', '1');
IndexValues[5] = Array('0', '1', '2', '4', '5', '6','7','8');
IndexValues[6] = Array('P', 'P1', 'SG', 'SG1');
IndexValues[7] = Array('BL', ' ');
IndexValues[8] = Array('CBL01', ' ');
IndexValues[9] = Array('CBL02', ' ');
IndexValues[10] = Array('CBL05', ' ');
IndexValues[11] = Array('IPC', ' ');
IndexValues[12] = Array('BOX1', ' ');
IndexValues[13] = Array('BOX2', ' ');

PricesArray = new Array();
// The following arrays contain the Prices of all the products //
PricesArray[0] = new Array(230);
PricesArray[1] = new Array(0,0,40,40);
PricesArray[2] = new Array(0,30);
PricesArray[3] = new Array(0,80,55,100,75);
PricesArray[4] = new Array(0,90);
PricesArray[5] = new Array(0,60,80,90,60,100,120,150);
PricesArray[6] = new Array(0,10,0,10);
PricesArray[7] = new Array(0, 0);
PricesArray[8] = new Array(19, 0);
PricesArray[9] = new Array(39, 0);
PricesArray[10] = new Array(15, 0);
PricesArray[11] = new Array(40, 0);
PricesArray[12] = new Array(140, 0);
PricesArray[13] = new Array(180, 0);

function CreateModelNumber(RadioIndex, SelectedIndex)
{
	if (RadioIndex > 6) // 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 = 'L'; // The value that is always selected //
	for (i=1;i<7;i++) // This loop generates the code according to the selected Radios //
	{
		Code = Code + '' + IndexValues[i][SelectedIndexes[i]];
	}

	for (i=7;i<14;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 = 'L';
	for (i=1;i<7;i++)
	{
		Code = Code + '' + IndexValues[i][SelectedIndexes[i]];
	}

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

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