// Define a System Type Object.
  function SystemTypeObj()
  {
  	this.id = 0;
  	this.description = "";
  	this.contentCode = "";
  } 
  
  // Define a Product Type Object
  function ProductTypeObj()
  {
  	this.id = 0;
  	this.description = "";
  	this.systemTypeId = 0;
  	this.contentCode = "";
  }
  
  // Define an object containing an Id
  function IdObj() 
  {
  	this.id = "";
  }
	
// Initialise the objects state
function initialise() 
{		
	updateSystemType();
	updateProductType();
	updateUI();
}

// Update the system type combo box
function updateSystemType()
{
	var st = document.getElementById("systemType");
	
	st.length = 0;
	for (var i = 0; i < aSystemType.length(); i++)
	{
		if (true)
		{
			var option = new Option(aSystemType.get(i).description, aSystemType.get(i).id);
			st.options[st.length] = option;
		}
	}
}
	
// update the product type combo box
function updateProductType()
{
	var productType = document.getElementById("productType");
	var securityCategory = document.getElementById("systemType");
	productType.length = 0;
	for (var i = 0; i < aProductType.length(); i++)
	{
		if (aProductType.get(i).systemTypeId == 0 || securityCategory.value == aProductType.get(i).systemTypeId)
		{
				var option = new Option(aProductType.get(i).description, aProductType.get(i).id);
				productType.options[productType.length] = option;
		}
	}
	if (productType.length == 1 && securityCategory.value != 0)
	{
		productType.length = 0;
		var option = new Option("No Products Available", "");
		productType.options[productType.length] = option;
	}
}
		
// submit the main form, TQA (category search)
function submitForm() 
{
	if (document.getElementById("productType").value == 0)
		alert("Please Select a Category and Product Type");
	else
		document.getElementById("tqa").submit();
}

// submit the certificate search form
function certSearch() 
{
	if (document.getElementById("securitySystem").value == "0")
		alert("Please Select a Certificate Number.");
	else
		document.getElementById("certSearch").submit();
}

// submit the manufacturer search form
function manufacturerSearch() 
{
	if (document.getElementById("productManufacturer").value == "0")
		alert("Please Select a Product Manufacturer.");
	else
		document.getElementById("manufacturerSearch").submit();
}

// submit the vehicle manufacturer search form
function vehicleManufacturerSearch() 
{
	if (document.getElementById("vehicleManufacturer").value == "0")
		alert("Please Select a Vehicle Manufacturer.");
	else
		document.getElementById("vehicleManufacturerSearch").submit();
}

 // submit the vehicle type search
function vehicleTypeSearch() 
{
	if (document.getElementById("vehicleType").value == "0")
		alert("Please Select a Vehicle Type e.g. Cars");
	else
		document.getElementById("vehicleTypeSearch").submit();
}	

// Update the text on div "qualityVariableText) on the left-hand side of the website using just text.
function updateTextOnTheLeftFromText(text)
{
	var e = document.getElementById("qualityVariableText");
	e.innerHTML = text;		
}

// Update the text on div "qualityVariableText) on the left-hand side of the website using AJAX
function updateTextOnTheLeftFromUrl(url)
{
	var ajax = new AjaxRequest();
	
	// Ajax Function to update div.
	var returnFunction = function()
	{
		if (ajax.isReady())
		{			
			updateTextOnTheLeftFromText(ajax.getResponse());				
		}
	};	
	ajax.send(url, "GET", returnFunction);			
}
	
// when the combo box changes, react to change the text on the page on the left, on div called qualityVariableText
// Page 951
function changeTextOnTheLeft()	
{		
	if (e)
	{
		var selectedSystemTypeId = document.getElementById("systemType").value;
		var selectedProductTypeId = document.getElementById("productType").value;
		
		var code ="";
		
		systemType = aSystemType.getById(parseInt(selectedSystemTypeId));
		productType = aProductType.getById(parseInt(selectedProductTypeId));
		
		// Start by product type.
		code = productType.contentCode;
		
		// No product selected having specific associated web page. Try category.
		if (code == "")			
			if (systemType.contentCode != "")
			{						
				code = systemType.contentCode;
			}
		
		// none? then keep default page.
		if (code == "")
			code = "TQA_DEFAULT";
				
		updateTextOnTheLeftFromUrl("/includes/getPageContent.jsp?title=" + code);
	}				
}
	
// Update the User Interface
function updateUI()
{
	changeTextOnTheLeft();
}

// Submit the Vehicle Type form according to the type of vehicle specified.
function submitVehicleTypeForm(type)
{
	document.getElementById("vehicleType").value = type;
	document.getElementById("vehicleTypePosted").value = 7;
	vehicleTypeSearch();
}