
categories = new Array( );
characters = new Array( );

function category(pid, catid, name, locked) {
	this.pid = pid
	this.catid = catid
	this.name = name
	this.locked = locked
}

function character(charid, catid, charname) { 
	this.charid = charid
	this.catid = catid
	this.charname = charname
}

function setCategories( chosen ) {
	var category = chosen.options[chosen.selectedIndex].value; 

	var count = 0;
	for(x = 0; x < categories.length; x++) 
	{ 
		if(categories[x].pid == category) count++; 
	}
	if(count) {
		chosen.options.length = 0;
		for(x = 0; x < categories.length; x++) {
			if(categories[x].pid == category || categories[x].catid == category) { 
				chosen.options[chosen.options.length] = new Option(categories[x].name, categories[x].catid); 
			}
		}
		if(category != -1) { 
			chosen.options[chosen.options.length] = new Option(lang['Back2Cat'], '-1');
			chosen.options.selectedIndex = 0;
		}
		else { 
			chosen.options[chosen.options.length] = new Option(lang['ChooseCat'], '-1');
			chosen.options.selectedIndex = chosen.options.length - 1;
			
		}
	}
}

function clearSelectedCategory( chosen ) {
	chosen.options.length = 0;
}

function setSelectedCategory( chosen ) {
	newList = new Array(  );
	var category = chosen.options[chosen.selectedIndex].value; 
	var len = document.form.catid.options.length;

	for(x = 0; x < categories.length; x++) {
		if(categories[x].catid != category) continue;
		locked = categories[x].locked;
		break;
	}
	if(locked && document.form.formname.value == "stories") alert(lang['Locked']);
	else {
		document.form.catid[len] = new Option(chosen.options[chosen.selectedIndex].text, chosen.options[chosen.selectedIndex].value, chosen.options[chosen.selectedIndex].defaultSelected, true);

		if(document.form.formname.value != "admins") {
			var charname = document.form.charname;

			for(x = 0; x < characters.length; x++) {
				if(characters[x].catid == category) { 
					charname.options[charname.options.length] = new Option(characters[x].charname, characters[x].charname); 
				}
			}
		}
	}		
}
categories[0] = new category(-1, 1, "K-3", 0);
categories[1] = new category(-1, 2, "4-7", 0);
categories[2] = new category(-1, 3, "8-10", 0);
categories[3] = new category(-1, 5, "11-12", 0);

