$(document).ready(function(){
	 $("#first_ebay_level2").hide();
	 $("#first_ebay_level3").hide();
	 $("#first_ebay_level4").hide();
	 $("#first_ebay_level5").hide();
	 $("#second_ebay_level2").hide();
	 $("#second_ebay_level3").hide();
	 $("#second_ebay_level4").hide();
	 $("#second_ebay_level5").hide();
	 $('#first_category_status').css({'background-color' : 'red'});
	 $('#second_category_status').css({'background-color' : 'red'});

	 $("#first_ebay_level1").change(function(){
		
		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;
			
			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#first_ebay_level2"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
						if(data[i].level != 1){
						options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";
						}
					}
					
				select.append(options);
				//LEAF CONTROL
				$('#first_category_status').css({'background-color' : 'red'});	
				$("#first_ebay_level2").show();
				$("#first_ebay_level3").hide();
				 $("#first_ebay_level4").hide();
				 $("#first_ebay_level5").hide();
				}
			});
				$('#first_ebay_level3')
				.find('option')
				.remove()
			
				$('#first_ebay_level4')
				.find('option')
				.remove()
				
				$('#first_ebay_level5')
				.find('option')
				.remove()
				return false;				
	});
});
$(document).ready(function(){
	$("#first_ebay_level2").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#first_ebay_level3"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#first_ebay_level2 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
				if(leaf_content == 0){
					$('#first_category_status').css({'background-color' : 'red'});	
					$("#first_ebay_level3").show();
					$("#first_ebay_level4").hide();
					$("#first_ebay_level5").hide();
					}else{
					$('#first_category_status').css({'background-color' : 'green'});	
					$("#first_ebay_level3").hide();
					$("#first_ebay_level4").hide();
					$("#first_ebay_level5").hide();
					}
				}
			});
				$('#first_ebay_level4')
				.find('option')
				.remove()
				
				$('#first_ebay_level5')
				.find('option')
				.remove()
	});
});
$(document).ready(function(){
	$("#first_ebay_level3").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#first_ebay_level4"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
					
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#first_ebay_level3 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
					if(leaf_content == 0){
					$('#first_category_status').css({'background-color' : 'red'});	
					$("#first_ebay_level4").show();
					$("#first_ebay_level5").hide();
					}else{
					$('#first_category_status').css({'background-color' : 'green'});	
					$("#first_ebay_level4").hide();
					$("#first_ebay_level5").hide();
					}
				}
			});
				$('#first_ebay_level5')
				.find('option')
				.remove()
	});
});
$(document).ready(function(){
	$("#first_ebay_level4").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#first_ebay_level5"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
					
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#first_ebay_level4 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
					if(leaf_content == 0){
					$('#first_category_status').css({'background-color' : 'red'});	
					$("#first_ebay_level5").show();
					}else{
					$('#first_category_status').css({'background-color' : 'green'});	
					$("#first_ebay_level5").hide();
					}
				}
			});
			
			
	});
});

// LAST first_ebay_level 5
$(document).ready(function(){
	$("#first_ebay_level5").change(function(){
				//LEAF CONTROL
				var selected_element = $("#first_ebay_level5 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
				if(leaf_content == 0){
				$('#first_category_status').css({'background-color' : 'red'});	
				}else{
				$('#first_category_status').css({'background-color' : 'green'});	
				}
			});
	});
	
//SECOND CATEGORY TREE

$(document).ready(function(){
	 $("#second_ebay_level5").hide();
	$("#second_ebay_level1").change(function(){
		
		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;
			
			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#second_ebay_level2"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
						if(data[i].level != 1){
						options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";
						}
					}
					
				select.append(options);
				//LEAF CONTROL
				$('#second_category_status').css({'background-color' : 'red'});	
				$("#second_ebay_level2").show();
				$("#second_ebay_level3").hide();
				 $("#second_ebay_level4").hide();
				 $("#second_ebay_level5").hide();
				}
			});
				$('#second_ebay_level3')
				.find('option')
				.remove()
			
				$('#second_ebay_level4')
				.find('option')
				.remove()
				
				$('#second_ebay_level5')
				.find('option')
				.remove()
				return false;				
	});
});
$(document).ready(function(){
	$("#second_ebay_level2").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#second_ebay_level3"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#second_ebay_level2 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
				if(leaf_content == 0){
					$('#second_category_status').css({'background-color' : 'red'});	
					$("#second_ebay_level3").show();
					$("#second_ebay_level4").hide();
					$("#second_ebay_level5").hide();
					}else{
					$('#second_category_status').css({'background-color' : 'green'});	
					$("#second_ebay_level3").hide();
					$("#second_ebay_level4").hide();
					$("#second_ebay_level5").hide();
					}
				}
			});
				$('#second_ebay_level4')
				.find('option')
				.remove()
				
				$('#second_ebay_level5')
				.find('option')
				.remove()
	});
});
$(document).ready(function(){
	$("#second_ebay_level3").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#second_ebay_level4"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
					
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#second_ebay_level3 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
					if(leaf_content == 0){
					$('#second_category_status').css({'background-color' : 'red'});	
					$("#second_ebay_level4").show();
					$("#second_ebay_level5").hide();
					}else{
					$('#second_category_status').css({'background-color' : 'green'});	
					$("#second_ebay_level4").hide();
					$("#second_ebay_level5").hide();
					}
				}
			});
				$('#second_ebay_level5')
				.find('option')
				.remove()
	});
});
$(document).ready(function(){
	$("#second_ebay_level4").change(function(){

		var data = {
		'cid': $(this).val() // LEX_ID FROM DETAILBUTTON
	}
		var dataString = data;

			$.ajax({
				url: "php/ebay_api/php/ebay_cathandler.php",
				type: "POST",
				data: dataString,
				dataType: 'json',
				success: function (data) {
				
				var select = $("#second_ebay_level5"), options = '';
				select.empty();      

					for(var i=0;i<data.length; i++){
					options += "<option value='"+data[i].cid+'|'+data[i].leaf+"'>"+ data[i].name +"</option>";              
					}
					
				select.append(options);		
				//LEAF CONTROL
				var selected_element = $("#second_ebay_level4 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
					if(leaf_content == 0){
					$('#second_category_status').css({'background-color' : 'red'});	
					$("#second_ebay_level5").show();
					}else{
					$('#second_category_status').css({'background-color' : 'green'});	
					$("#second_ebay_level5").hide();
					}
				}
			});
			
			
	});
});

// LAST second_ebay_level 5
$(document).ready(function(){
	$("#second_ebay_level5").change(function(){
				//LEAF CONTROL
				var selected_element = $("#second_ebay_level5 option:selected").val();
				var leaf_content = (selected_element.split('|')[1]);
				if(leaf_content == 0){
				$('#second_category_status').css({'background-color' : 'red'});	
				}else{
				$('#second_category_status').css({'background-color' : 'green'});
				}
			});
	});
