cManufacturerTab = new Array();
cModelTab = new Array();
cSpecTab = new Array();

function cClearSelect(theSelect)
{
	var theSelectSize = theSelect.length;
  for (var i = 0; i < theSelectSize; i++)
  {
    theSelect.options[0] = null;
  }
}

function cManufacturerLoad(theSelect,selectedOption,defaultOption)
{
  cClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"0");
  theSelect.options[0].selected = true;
  for (var i = 0; i < cManufacturerTab.length; i++)
  {
    theSelect.options[i+1] = new Option(cManufacturerTab[i],cManufacturerTab[i]);
  	if (cManufacturerTab[i] == selectedOption)
  	{
      theSelect.options[0].selected = false;
  		theSelect.options[i+1].selected = true;
  	}
  }
}

function cModelLoad(theSelect,manufacturer,selectedOption,defaultOption)
{
  cClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"0");
  theSelect.options[0].selected = true;
  var j = 1;
  for (var i = 0; i < cModelTab.length; i++)
  {
    if (cModelTab[i][0] == manufacturer)
    {
      theSelect.options[j] = new Option(cModelTab[i][1],cModelTab[i][1]);
    	if (cModelTab[i][1] == selectedOption)
    	{
        theSelect.options[0].selected = false;
    		theSelect.options[j].selected = true;
    	}
      j++;
    }
  }
}

function cSpecLoad(theSelect,manufacturer,model,selectedOption,defaultOption)
{
  cClearSelect(theSelect);
  theSelect.options[0] = new Option(defaultOption,"0");
  theSelect.options[0].selected = true;
  var j = 1;
  for (var i = 0; i < cSpecTab.length; i++)
  {
    if (cSpecTab[i][1] == manufacturer)
    {
    	if (model != "0")
    	{
    		if (cSpecTab[i][2] == model)
    		{
          theSelect.options[j] = new Option(cSpecTab[i][3]+' ('+cSpecTab[i][4]+')',cSpecTab[i][0]);
  	      j++;
    		}
    	}
    	else
    	{
        theSelect.options[j] = new Option(cSpecTab[i][3]+' ('+cSpecTab[i][4]+')',cSpecTab[i][0]);
  	    j++;
      }
     	if (cSpecTab[i][3] == selectedOption)
    	{
        theSelect.options[0].selected = false;
    		theSelect.options[j-1].selected = true;
  	  }
    }
  }
}

// cManufacturerAdd
function c1(manufacturer)
{
  cManufacturerTab[cManufacturerTab.length] = manufacturer;
}

// cModelAdd
function c2(manufacturer,model)
{
  cModelTab[cModelTab.length] = new Array(manufacturer,model);
}

// cSpecAdd
function c3(c_spec_id,manufacturer,model,special,year,energy,engine,capacity,fiscale_power,din_power,max_speed,acceleration,acceleration2,consumption,transmission,gearbox,speed,length,width,trunk,weight,price)
{
  cSpecTab[cSpecTab.length] = new Array(c_spec_id,manufacturer,model,special,year,energy,engine,capacity,fiscale_power,din_power,max_speed,acceleration,acceleration2,consumption,transmission,gearbox,speed,length,width,trunk,weight,price);
}

