// JavaScript Document

function sifirla(form_name, deger)
{
	document.forms[form_name].kategori1.style.display = "none"; 
	document.forms[form_name].kategori2.style.display = "inline"; 
	document.forms[form_name].kategori3.style.display = "inline"; 
	document.forms[form_name].kategori4.style.display = "inline"; 
    if (deger < 3) {
	document.forms[form_name].kategori2.options.length = 0;
	document.forms[form_name].kategori2.style.display = "none"; 
	} if (deger < 4) {
	document.forms[form_name].kategori3.options.length = 0;
	document.forms[form_name].kategori3.style.display = "none";
	} if (deger < 5) {
	document.forms[form_name].kategori4.options.length = 0;
	document.forms[form_name].kategori4.style.display = "none";
	}
}

function urun_list(form_name) {
	var j = 0;
	var selected;
	var selectBox;
	
	document.forms[form_name].urunler.options.length = 0;
	document.forms[form_name].urunler.options[0] = new Option("..."); 
	document.forms[form_name].urunler.options[0].value = "0";
	selectBox = document.forms[form_name].kategori2;
	if ( selectBox.style.display != 'none') 
	if ( selectBox.options[selectBox.selectedIndex].value != '0' && selectBox.options[selectBox.selectedIndex].value != '-1')
		selected = selectBox.options[selectBox.selectedIndex].value;
			
	selectBox = document.forms[form_name].kategori3;
	if ( selectBox.style.display != 'none') 
	if ( selectBox.options[selectBox.selectedIndex].value != '0' )
		selected = selectBox.options[selectBox.selectedIndex].value;
			
	selectBox = document.forms[form_name].kategori4;
	if ( selectBox.style.display != 'none') 
	if ( selectBox.options[selectBox.selectedIndex].value != '0' && selectBox.options[selectBox.selectedIndex].value != '-1')
		selected = selectBox.options[selectBox.selectedIndex].value;
			
	
	for (i=0; i<document.URUN.elements.length; i++) 
	if ( document.URUN.elements[i].title == selected ) 
		{ 
		document.forms[form_name].urunler.options[j] = new Option(document.URUN.elements[i].value); 
		document.forms[form_name].urunler.options[j].value = document.URUN.elements[i].name;
		j++;
		}
}


function listele1(form_name,kat_id) {
	var secili;
	sifirla(form_name,'2');
	//document.forms[form_name].kategori1.options[0] = new Option("Kategori Seçin"); 
	//document.forms[form_name].kategori1.options[0].value = "0";
	for (i=0; i<document.KAT1.elements.length; i++) {
		document.forms[form_name].kategori1.options[i+1] = new Option(document.KAT1.elements[i].value); 
		document.forms[form_name].kategori1.options[i+1].value = document.KAT1.elements[i].name;
		if (kat_id == document.KAT1.elements[i].name)
			secili = i+1; 
	}
	document.forms[form_name].kategori1.selectedIndex = secili;
}

function listele2(form_name,kat_id) {
	var secili=-1;
	var selectBox = document.forms[form_name].kategori1;
	var j = 1;
	if (selectBox.selectedIndex == 0){sifirla(form_name,'2'); secili=-1;}	 else {sifirla(form_name,'3'); secili= 0;	}
	document.forms[form_name].kategori2.options.length = 0;
	user_input = selectBox.options[selectBox.selectedIndex].value;
	document.forms[form_name].kategori2.options[0] = new Option("..."); 
	document.forms[form_name].kategori2.options[0].value = "0";
	for (i=0; i<document.KAT2.elements.length; i++) 
	if ( document.KAT2.elements[i].title == user_input ) 
		{ 
		document.forms[form_name].kategori2.options[j] = new Option(document.KAT2.elements[i].value); 
		document.forms[form_name].kategori2.options[j].value = document.KAT2.elements[i].name;
		if (kat_id == document.KAT2.elements[i].name)
			secili = j; 
		j++;
		}
	document.forms[form_name].kategori2.selectedIndex = secili;
	urun_list(form_name);
}

function listele3(form_name,kat_id) {
	var secili;
	var selectBox = document.forms[form_name].kategori2;
	var j = 1;
	if (selectBox.selectedIndex == 0){sifirla(form_name,'3'); secili=-1;}	 else {sifirla(form_name,'4'); secili= 0;	}
	document.forms[form_name].kategori3.options.length = 0;
	user_input = selectBox.options[selectBox.selectedIndex].value;
	document.forms[form_name].kategori3.options[0] = new Option("..."); 
	document.forms[form_name].kategori3.options[0].value = "0";
	for (i=0; i<document.KAT3.elements.length; i++) 
	if ( document.KAT3.elements[i].title == user_input ) 
		{ 
		document.forms[form_name].kategori3.options[j] = new Option(document.KAT3.elements[i].value); 
		document.forms[form_name].kategori3.options[j].value = document.KAT3.elements[i].name;
		if (kat_id == document.KAT3.elements[i].name)
			secili = j; 
		j++;
		}
	if ( j == 1 ) 	document.forms[form_name].kategori3.style.display = "none"; 
	document.forms[form_name].kategori3.selectedIndex = secili;
	urun_list(form_name);
}

function listele4(form_name,kat_id) {
	var secili=-1;
	var selectBox = document.forms[form_name].kategori3;
	var j = 1;
	if (selectBox.selectedIndex == 0){sifirla(form_name,'4'); secili=-1;}	 else {sifirla(form_name,'5'); secili= 0;	}
	document.forms[form_name].kategori4.options.length = 0;
	user_input = selectBox.options[selectBox.selectedIndex].value;
	document.forms[form_name].kategori4.options[0] = new Option("..."); 
	document.forms[form_name].kategori4.options[0].value = "0";
	for (i=0; i<document.KAT4.elements.length; i++) 
	if ( document.KAT4.elements[i].title == user_input ) 
		{ 
		document.forms[form_name].kategori4.options[j] = new Option(document.KAT4.elements[i].value); 
		document.forms[form_name].kategori4.options[j].value = document.KAT4.elements[i].name;
		if (kat_id == document.KAT4.elements[i].name)
			secili = j; 
		j++;
		}
	if ( j == 1 ) 	document.forms[form_name].kategori4.style.display = "none"; 
	document.forms[form_name].kategori4.selectedIndex = secili;
	urun_list(form_name);
}

//  End -->


