function envokeSuggestions(event) {
	suggestedCategory(event);
	
	if ($('tags').value == null || $('tags').value == '') {
		suggestTags(event);
	}
}

function suggestedCategory(event) {
	var element = $('question'); //Event.element(event);
	new Ajax.Request('http://www.questionbin.com/ajaxCategory.php?q=' + element.value,
	{
	 method:'get',
	 onSuccess: handlerFunc,
	 onFailure: function(){}
	});
}


function suggestTags(event) {
	var element = $('question'); //Event.element(event);
	new Ajax.Request('http://www.questionbin.com/ajaxTags.php?q=' + element.value,
	{
	 method:'get',
	 onSuccess: handlerFuncTags,
	 onFailure: function(){}
	});
}


var handlerFunc = function(t) {
  try {
    var xmlDoc = t.responseXML.documentElement;
    // returns HTML Object or HTML Collection
    // and attempts to loop through return UNDEFINED or NULL
	var parent = xmlDoc.getElementsByTagName("parent")[0].childNodes[0].nodeValue;
	var child = xmlDoc.getElementsByTagName("child")[0].childNodes[0].nodeValue;

	// Set the values on the dropdowns
	
	if (parent != 0) {
		$('category').value = parent;
		if (child != 0) { 
			call_ajax_populate_sub_categories('http://www.questionbin.com/questions_ajax.php', 'new=1&t=1040&child=' + child,'subCatDiv'); 
		} else {
			call_ajax_populate_sub_categories('http://www.questionbin.com/questions_ajax.php', 'new=1&amp;t=1040','subCatDiv');
		}
	}
	
  } catch(e) {
  }  
    //Handle data.
}

var handlerFuncTags = function(t) {
  try {
    var xmlDoc = t.responseXML.documentElement;
    // returns HTML Object or HTML Collection
    // and attempts to loop through return UNDEFINED or NULL
	var tags = xmlDoc.getElementsByTagName("tags")[0].childNodes[0].nodeValue;
	
	// Add the value
	if (tags != null && tags != 'undefined' && tags != '') {
		$('tags').value = tags;
	}
	
  } catch(e) {

  }  
    //Handle data.
}