//-----------------------------------------------------------------------------
// FILE: driver_wizard.js
// COMMENT: Admin site = http://webtest.matrox.com/video/en/apps/driver_wizard/main.cfm
//-----------------------------------------------------------------------------

function dw_clearSelections()
{

	document.driver_wizard.products.length = 0;
	document.driver_wizard.download_types.length = 0;
	document.driver_wizard.downloads.length = 0;
	document.driver_wizard.products.selectedIndex  = -1;
	document.driver_wizard.download_types.selectedIndex = -1;
	document.driver_wizard.downloads.selectedIndex = -1;
	document.getElementById('description_box').innerHTML = "";
	document.driver_wizard.btnGo.disabled = 'disabled';
}

function dw_PopulateOperatingSystems()
{
	dw_clearSelections();

	document.driver_wizard.operating_systems.length = driver_wizard_data.length;
	for (i = 0; i < driver_wizard_data.length; i++)
	{
		document.driver_wizard.operating_systems[i].value = driver_wizard_data[i][0][0];
		document.driver_wizard.operating_systems[i].text = driver_wizard_data[i][0][1];
	}
}

function dw_PopulateProducts()
{
	dw_clearSelections();

	selected_os_index = document.driver_wizard.operating_systems.selectedIndex;

	document.driver_wizard.products.length = driver_wizard_data[selected_os_index][1].length;
	for (i = 0; i < document.driver_wizard.products.length; i++)
	{
		document.driver_wizard.products[i].value = driver_wizard_data[selected_os_index][1][i][0][0][0];
		document.driver_wizard.products[i].text = driver_wizard_data[selected_os_index][1][i][0][0][1];
	}
}

function dw_PopulateDownloadsTypes()
{
	// clear download selections
	document.driver_wizard.downloads.length = 0;
	document.driver_wizard.download_types.length = 0;
	document.driver_wizard.downloads.selectedIndex = -1;
	document.driver_wizard.download_types.selectedIndex = -1;
	document.getElementById('description_box').innerHTML = "";
	document.driver_wizard.btnGo.disabled = 'disabled';

	selected_os_index = document.driver_wizard.operating_systems.selectedIndex;
	selected_product_index = document.driver_wizard.products.selectedIndex;

	document.driver_wizard.download_types.length = driver_wizard_data[selected_os_index][1][selected_product_index][0][1].length;
	for (i = 0; i < document.driver_wizard.download_types.length; i++)
	{
		document.driver_wizard.download_types[i].value = driver_wizard_data[selected_os_index][1][selected_product_index][0][1][i][0][0];
		document.driver_wizard.download_types[i].text = unescape( driver_wizard_data[selected_os_index][1][selected_product_index][0][1][i][0][1]);
	}

	// auto-select the download type is there's only one choice
	if ( document.driver_wizard.download_types.length == 1 )
	{
		document.driver_wizard.download_types.selectedIndex = 0;
		dw_PopulateDownloads();
	}
}

function dw_PopulateDownloads()
{
	// clear download selections
	document.driver_wizard.downloads.length = 0;
	document.driver_wizard.downloads.selectedIndex = -1;
	document.getElementById('description_box').innerHTML = "";
	document.driver_wizard.btnGo.disabled = 'disabled';

	selected_os_index = document.driver_wizard.operating_systems.selectedIndex;
	selected_product_index = document.driver_wizard.products.selectedIndex;
	selected_download_type_index = document.driver_wizard.download_types.selectedIndex;

	document.driver_wizard.downloads.length = driver_wizard_data[selected_os_index][1][selected_product_index][0][1][selected_download_type_index][1].length;
	for (i = 0; i < document.driver_wizard.downloads.length; i++)
	{
		document.driver_wizard.downloads[i].value = driver_wizard_data[selected_os_index][1][selected_product_index][0][1][selected_download_type_index][1][i][0];
		document.driver_wizard.downloads[i].text = driver_wizard_data[selected_os_index][1][selected_product_index][0][1][selected_download_type_index][1][i][1];
	}

	// auto-select the download is there's only one choice
	if ( document.driver_wizard.downloads.length == 1 )
	{
		document.driver_wizard.downloads.selectedIndex = 0;
		dw_PopulateDescriptionBox();
	}
}

function dw_PopulateDescriptionBox()
{
	selected_os_index = document.driver_wizard.operating_systems.selectedIndex;
	selected_product_index = document.driver_wizard.products.selectedIndex;
	selected_download_index = document.driver_wizard.downloads.selectedIndex;
	selected_download_type_index = document.driver_wizard.download_types.selectedIndex;

	document.getElementById('description_box').innerHTML = driver_wizard_data[selected_os_index][1][selected_product_index][0][1][selected_download_type_index][1][selected_download_index][2];

	// enable Go button
	document.driver_wizard.btnGo.disabled = '';
}

function dw_Go(language)
{
	selected_os_index = document.driver_wizard.operating_systems.selectedIndex;
	selected_product_index = document.driver_wizard.products.selectedIndex;
	selected_download_index = document.driver_wizard.downloads.selectedIndex;
	selected_download_type_index = document.driver_wizard.download_types.selectedIndex;

	if ( selected_os_index >= 0 && selected_product_index >= 0 && selected_download_index >= 0 )
	{
		link = '/video/' + language + driver_wizard_data[selected_os_index][1][selected_product_index][0][1][selected_download_type_index][1][selected_download_index][3];
		document.driver_wizard.link.value = link;
		document.driver_wizard.selected_product.value = driver_wizard_data[selected_os_index][1][selected_product_index][0][0][0];
	//clear the select index
	
	document.driver_wizard.operating_systems.selectedIndex = -1;
		
		document.driver_wizard.submit(); // handle the download redirection on the server side
	}
}
