/*#############################################################

Name: Men

Version: 0.9

Author: Stefan Benerowski

Beschreibung: Funktionen fr die Mendarstellung



#############################################################*/



/**

* ffnet ein Browserfenster

*

*

*/

function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}





/**

* Erzeugt die Eintrge fr das Selectfeld model

*

* @param selectId

*

*/

function set_model(selectId)

{

	//alert(document.Eingabe.model.selectedIndex);

	voreinstellung = setzeUebergabe ();

	voreinstellung = voreinstellung["model"];

	//alert(voreinstellung);

	

	selectElement = document.getElementById('model');

	selectElement.options.length = 0;

	

	selectElement.options[0] = new Option('Просьба выбрать модель', '');

	

	

	var tempindex=1;

	var tempueb=0;

	for (i = 0; i < categoryDB.length; i++)

	{

		

		

		if (categoryDB[i][1]=="-1") {

		  

		   if (voreinstellung==categoryDB[i][0]) {

		      //selectElement.options[tempindex].selected=true;

			  //alert (tempindex);

			  tempueb=tempindex;

		   }

		   selectElement.options[tempindex] = new Option(categoryDB[i][2], categoryDB[i][0]);

		   tempindex++;

		}

	}

	selectElement.options[tempueb].selected=true;

	

	if (voreinstellung!=0) {

	   changeTopmenue(voreinstellung);

	}

}



/**

* ndert die Eintrge des Selectfeldes category in Abhngigkeit der Auswahl des Selectfeld model

* param aufnull erzwingt, dass der erste Eintrag (option[0]) ausgewhlt wird

*

* @param selectId

* @param aufnull

*

*/

function changeTopmenue(selectId,aufnull) {

   //alert("drin"+selectId);

   

   selectElement = document.getElementById('productgroup');

   selectElement.options.length = 0;

  

    voreinstellung = setzeUebergabe ();

	voreinstellung = voreinstellung["productgroup"];

	

	//alert (voreinstellung);

	

	// Produkt zurcksetzen

	

	selectElement.options[0] = new Option('---', '');

	selectElement2 = document.getElementById('productgroup');

	selectElement2.options.length = 0;

	selectElement2.options[0] = new Option('---', '');

	

	selectElement3 = document.getElementById('category');

	selectElement3.options.length = 0;

	selectElement3.options[0] = new Option('---', '');

	

	if (selectId=="") {

	   

	} else {

	   selectElement.options[0] = new Option('Просьба выбрать группу продукта', '');

	   var tempindex=1;

	   var tempueb=0;

	   for (i = 0; i < categoryDB.length; i++)

	   {

		

		   //alert (categoryDB[i][1]);

		   if (voreinstellung==categoryDB[i][0]) {

			  tempueb=tempindex;

		   }

		   

		   if (categoryDB[i][1]==selectId) {

		      selectElement.options[tempindex] = new Option(categoryDB[i][2], categoryDB[i][0]);

		      tempindex++;

		   }

	   }

	   

	   

	   if (aufnull) {

		  selectElement.options[0].selected=true;

	   } else {

	      selectElement.options[tempueb].selected=true;

		  

		  if (voreinstellung!=0) {

	         changeCategory(voreinstellung);

	      }

	   }

	   

	   

	}

}



/**

* ndert die Eintrge des Selectfeldes product in Abhngigkeit der Auswahl des Selectfeld category 

* param aufnull erzwingt, dass der erste Eintrag (option[0]) ausgewhlt wird

*

* @param selectId

* @param aufnull

*

*/

function changeCategory(selectId,aufnull) {

   //alert("drin"+selectId);

   

   selectElement = document.getElementById('category');

   selectElement.options.length = 0;

	

	//alert("drin"+selectId);

	voreinstellung = setzeUebergabe ();

	voreinstellung = voreinstellung["category"];

	

	

	if (selectId=="") {

	   selectElement.options[0] = new Option('---', '');

	} else {

	   selectElement.options[0] = new Option('Просьба выбрать категорию', '');

	   

	   var tempindex=1;

	   var tempueb=0;

	   for (i = 0; i < categoryDB.length; i++)

	   {



		   //alert (categoryDB[i][1]);

		   if (voreinstellung==categoryDB[i][0]) {

			  tempueb=tempindex;

		   }



		   

		   if (categoryDB[i][1]==selectId) {

		      selectElement.options[tempindex] = new Option(categoryDB[i][2], categoryDB[i][0]);

		      tempindex++;

		   }

	   }

	   if (aufnull) {

		  selectElement.options[0].selected=true;

	   } else {

	      selectElement.options[tempueb].selected=true;

	   }

	   

	}

}



function changeProduktgr(selectId,aufnull) {



   //alert("drin"+selectId);



   selectElement = document.getElementById('category');

   selectElement.options.length = 0;



	//alert("drin"+selectId);

	voreinstellung = setzeUebergabe ();

	voreinstellung = voreinstellung["category"];



	if (selectId=="") {

	   selectElement.options[0] = new Option('---', '');

	} else {

	   selectElement.options[0] = new Option('Просьба выбрать категорию', '');



	   

	   var tempindex=1;

	   var tempueb=0;

	   for (i = 0; i < categoryDB.length; i++)

	   {



		   //alert (categoryDB[i][1]);

		   if (voreinstellung==categoryDB[i][0]) {

			  tempueb=tempindex;

		   }



		   

		   if (categoryDB[i][1]==selectId) {

		      selectElement.options[tempindex] = new Option(categoryDB[i][2], categoryDB[i][0]);

		      tempindex++;

		   }

	   }



	   if (aufnull) {

		  selectElement.options[0].selected=true;

	   } else {

	      selectElement.options[tempueb].selected=true;

	   }

	}

}



/**

* Versendet das Formularfeld Eingabe 

* Baut den Query (mit Parametern) anhand der Ausgewhlten Optionen (model,category,[product])

*

*/

function Eingabesubmit() {

   //alert("drin");

   a = document.Eingabe.model.options[document.Eingabe.model.selectedIndex].value;

   //alert (a);

   if (a=="") {

      alert("Выберите, пожалуйста, модель!");

	  document.Eingabe.model.focus();

	  return;

   }

   

   b = document.Eingabe.productgroup.options[document.Eingabe.productgroup.selectedIndex].value;



   if (b=="") {

      alert("Выберите, пожалуйста, группу продукта!");

	  document.Eingabe.productgroup.focus();

	  return;

   }

   

   c = document.Eingabe.category.options[document.Eingabe.category.selectedIndex].value;



   if (c=="") {

      alert("Выберите, пожалуйста, категорию!");

	  document.Eingabe.category.focus();

	  return;

   }

   

   

   URL = 'produktliste.html?model='+a+'&productgroup='+b+'&category='+c;

   

   //alert (URL);

   window.location.href = URL;

   //document.Eingabe.action = (URL);

   //document.Eingabe.submit();

}



/**

* Liest aus dem Query die Parameter und berfhrt diese in ein Array

* 

* @return sammlung

*/

function setzeUebergabe () {

   query = self.location.search;

   sammlung = new Array();

   

   sammlung["model"]=0;

   sammlung["category"]=0;

   sammlung["product"]=0;

   sammlung["sort"]=0;



   if (query != '')

   {

     query = query.substr(1, query.length - 1);

     query = query.replace(/%26/,'&');

     teile = query.split('&');



     for (i = 0; i < teile.length; i++) {

       teile[i] = teile[i].split('=');

       sammlung[teile[i][0]] = teile[i][1];

     }

     

	 

     //alert(sammlung["sort"] );

   }

   //alert (query);

   return sammlung;

}



/**

* ffnet ein Browserfenster

* 

*/

function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}




