var AskAnExpert = {

	blankComment : function() {
		if ($('comment_comment').value == '') {
			alert("Please enter a comment");
			return true;
		} else {
			return false;
		}
	},
	
	setConfirm : function() {
		var a = $('moderate_action').value;
		var text = a + ' selected comments?';
		return (a == '' ? false : confirm(text));
	},

	// Set default value for blank elements. 
	// Used by initSiteSearch()
	toggleFocus: function(element, val){
		var obj = $(element);
		if (obj.hasClassName('focus')) {
			obj.removeClassName('focus');
			if (obj.value.blank()) 
				obj.value = val;
		}
		else {
			obj.addClassName('focus');
			if (obj.value == val) 
				obj.value = '';
		}
	},

	addPrompt : function(id, text)
	{
		Event.observe(id, 'focus', function(){
			AskAnExpert.toggleFocus(this, text);
		});
		Event.observe(id, 'blur', function(){
			AskAnExpert.toggleFocus(this, text);
		});
		if ($F(id).blank()) 
			$(id).value = text;
	},
	
	removePrompt : function(id, text)
	{
		if ($(id).value == text){
			$(id).value = "";
		}
	
	},

	escapeHTMLChars : function(text)
	{
		return text.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
	},
	
	showCommentForm : function(form, link)
	{
		$(form).show();
		$(link).hide();
	},
	
	clickTag : function(tag)
	{
		// the input field
		var tag_list = $('question_tag_list');
    // the tags
		var tags = $A(tag_list.value.split(/\s*,\s*/));
    // tag text
    var tag_text = tag.innerHTML;

		if (tag.hasClassName('selected')) {
			// Remove class and tag.
			tag.removeClassName('selected');
			tags = tags.without(tag_text);
		} else {
			// Set class, add tag.
			tag.addClassName('selected');
      tags.push(tag_text);
		}
  	// Rebuild, removing empty elements and duplicates.
  	tag_list.value = tags.uniq().without('').join(', ');
	},
	
	charCounter : function(id, limit, info){
		//
		var value = id.getValue();
		var length = value.length;
		//
		if (length >= limit) {
			id.setValue(value.substr(0,limit));
			length = limit;
		}
		//
		info.update(length +'/'+limit);
	}

}

