
function fillComboBox(level, data)
{
	var options = data.split(",");

	if((options.length / 2) >= 1) {
		document.getElementById('categorylist' + level).style.display = 'inline';
		addSelectOption('categorylist' + level, 'Select a category', 0, '');
		for(var i = 0; i < options.length / 2; i++) {
			addSelectOption('categorylist' + level,
				options[i * 2],
				options[i * 2 + 1],
				"updateCategoryCombos(" + level + ", " + options[i * 2 + 1] + ");");
		}
	}
}

function fillClassifiedComboBox(level, data)
{
	var options = data.split(",");

	if((options.length / 2) >= 1) {
		document.getElementById('categorylist' + level).style.display = 'inline';
		addSelectOption('categorylist' + level, 'Select a category', 0, '');
		for(var i = 0; i < options.length / 2; i++) {
			addSelectOption('categorylist' + level,
				options[i * 2],
				options[i * 2 + 1],
				"");
		}
	}
}

function fillComboBoxLocation(level, data)
{
	var options = data.split(",");

	if((options.length / 2) >= 1) {
		document.getElementById('locationlist' + level).style.display = 'inline';
		addSelectOption('locationlist' + level, 'Select a location', 0, '');
		for(var i = 0; i < options.length / 2; i++) {
			addSelectOption('locationlist' + level,
				options[i * 2],
				options[i * 2 + 1],
				"updateLocationCombos(" + level + ", " + options[i * 2 + 1] + ");");
		}
	}
}

function updateCategoryCombos(level, pid)
{
	var oAjax = new clsAjax();
	oAjax.url = '../ajax/ajax_category.php';
	oAjax.method = 'POST';
	oAjax.addPostField('pid', pid);
	oAjax.fetchData();
	var data = oAjax.responseText;

	document.getElementById('categorylist1_err').style.display = 'none';

	for(var i = level + 1; i <= 3; i++) {
		document.getElementById('categorylist' + i).style.display = 'none';
		deleteSelectOptions('categorylist' + i);
	}

	if(level < 3) {
		fillComboBox(level + 1, data);
	}

	// I'm using a for loop, in case we want to add more categories.
	for(var i = level + 2; i <= 3; i++) {
		addSelectOption('categorylist' + i, 'No categories', 0, '');
	}
}

function updateCCategoryCombos(level, pid)
{
	var oAjax = new clsAjax();
	oAjax.url = '../ajax/ajax_ccategory.php';
	oAjax.method = 'POST';
	oAjax.addPostField('pid', pid);
	oAjax.fetchData();
	var data = oAjax.responseText;

	document.getElementById('categorylist1_err').style.display = 'none';

	for(var i = level + 1; i <= 2; i++) {
		document.getElementById('categorylist' + i).style.display = 'none';
		deleteSelectOptions('categorylist' + i);
	}

	if(level < 2) {
		fillClassifiedComboBox(level + 1, data);
	}

	// I'm using a for loop, in case we want to add more categories.
	for(var i = level + 2; i <= 2; i++) {
		addSelectOption('categorylist' + i, 'No categories', 0, '');
	}

	$('category_label').style.display = 'inline';
}


function updateLocationCombos(level, pid)
{
	var oAjax = new clsAjax();
	oAjax.url = '../ajax/ajax_location.php';
	oAjax.method = 'POST';
	oAjax.addPostField('pid', pid);
	oAjax.fetchData();
	var data = oAjax.responseText;

	document.getElementById('locationlist1_err').style.display = 'none';

	for(var i = level + 1; i <= 3; i++) {
		document.getElementById('locationlist' + i).style.display = 'none';
		deleteSelectOptions('locationlist' + i);
	}

	if(level < 3) {
		fillComboBoxLocation(level + 1, data);
	}

	// I'm using a for loop, in case we want to add more categories.
	for(var i = level + 2; i <= 3; i++) {
		addSelectOption('locationlist' + i, 'No Locations', 0, '');
	}
}