$(function()
{
	// now its messy yes. ask the boss.
	
	// handle category select, populate sub categories
	$('#category_id').change(function()
	{
		var selectWidth = $(this).css('width');
		populateSubCategories(this.options[this.options.selectedIndex].value, selectWidth);
	});
	
	// handle category 2 select, populate sub categories 2
	$('#category_id2').change(function()
	{
		var selectWidth = $(this).css('width');
		populateSubCategories2(this.options[this.options.selectedIndex].value, selectWidth);
	});
	
	// handle category 3 select, populate sub categories 3
	$('#category_id3').change(function()
	{
		var selectWidth = $(this).css('width');
		populateSubCategories3(this.options[this.options.selectedIndex].value, selectWidth);
	});
	
});


function populateSubCategories(category_id, selectWidth)
{
	var x = new Hijax(); x.setContainer( document.getElementById('category_id'));
	x.setUrl("/p/populateSubCategories.php?category_id=" + category_id + "&width=" + selectWidth);
	x.setCanvas(document.getElementById('subCategorySelectWrapper')); x.captureData();
}
function populateSubCategories2(category_id, selectWidth)
{
	var x = new Hijax(); x.setContainer( document.getElementById('category_id2'));
	x.setUrl("/p/populateSubCategories.php?category_id=" + category_id + "&width=" + selectWidth + "&n=2");
	x.setCanvas(document.getElementById('subCategorySelectWrapper2')); x.captureData();
}
function populateSubCategories3(category_id, selectWidth)
{
	var x = new Hijax(); x.setContainer( document.getElementById('category_id3'));
	x.setUrl("/p/populateSubCategories.php?category_id=" + category_id + "&width=" + selectWidth + "&n=3");
	x.setCanvas(document.getElementById('subCategorySelectWrapper3')); x.captureData();
}




function countCharacters(obj, display)
{
	var c = obj.value.split(' ');
	var dis = document.getElementById(display);
	var l = c.length - 1;
	$(dis).html('Word Count: ' + l);
	
	if ( c.length >= 120 )
	{
		alert('Warning: Any text over 120 words will be truncated.');
	}

}
