
function listCars( marke, typ )
{
  if( marke == "" )
  {
    alert( "Bitte wählen Sie eine Marke" );
    return;
  }
  
  if( typ != "" )
  {
    window.location.href = "/de/fahrzeuge/" + marke + "/" + typ;
  }
  else
  {
    window.location.href = "/de/fahrzeuge/" + marke;
  }
}

function listCarsByArt( art )
{
  if( art == "" )
  {
    /* alert( "Bitte wählen Sie einen Fahrzeugtyp" ); */
    window.location.href = "/de/fahrzeuge/all";
    return;
  }
  
    window.location.href = "/de/fahrzeuge/typ/" + art;
}

function loadJson( url )
{
var req = loadFile( url );
//DEBUG 
return JSON.parse( req.responseText );
}

function loadFile( url )
{
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.open("GET", url, false);
		req.send("");
		//DEBUG alert( req.responseText );
		return req;
	}
return null;
}

function updateMarke()
{
  var json = loadJson( "/de/hersteller.json" );
  var smarke = document.getElementById( "s-marke" );

  for( x in json )
  {
    o = document.createElement("option");
    o_text = document.createTextNode( x + " (" + json[x] + ")" );
    o.appendChild( o_text );
    o.setAttribute( "value", x );
    smarke.appendChild( o );
  }

  smarke.onchange = updateTyp;
}

function updateMarke()
{
  var json = loadJson( "/de/fahrzeugtypen.json" );
  var sart = document.getElementById( "s-art" );

  for( x in json )
  {
    o = document.createElement("option");
    o_text = document.createTextNode( x + " (" + json[x] + ")" );
    o.appendChild( o_text );
    o.setAttribute( "value", x );
    sart.appendChild( o );
  }
}

function updateTyp()
{
  clearTypeList();
  var smarke = document.getElementById( "s-marke" );
  modelle = loadJson( "/de/modelle/" + smarke.value + ".json" );
  var styp = document.getElementById( "s-typ" );

  for( x in modelle )
  {
    o = document.createElement("option");
    o_text = document.createTextNode( x + " (" + modelle[x] + ")" );
    o.appendChild( o_text );
    o.setAttribute( "value", x );
    styp.appendChild( o );
  }
}

function clearTypeList()
{
  var styp = document.getElementById( "s-typ" );
  for( i=0; i < styp.childNodes.length; i++ )
  {
    child = styp.childNodes[i];
    if( child.value != "" )
    {
     styp.removeChild( child );
     i--;
    }
  }
}


window.onload = updateMarke;

