	$(function(){
		$('#setQuestion').hide();
		$('span.addComment').click(function() {
			if( $('#setQuestion').is(':visible') ) {
				$('#setQuestion').slideUp('slow');
				$(this).addClass('addComment');
				$(this).removeClass('removeComment');
				$(this).html( 'Add a comment' );
			} else {
				$('#setQuestion').slideDown('slow');
				$(this).removeClass('addComment');
				$(this).addClass('removeComment');
				$(this).html( 'Dont add a comment' );
			}
		});

		$('#useemail').hide();
		$('input.useemail').click(function(){
			if( $('#useemail').is(':visible') ) {
				$('#useemail').slideUp('slow');
			} else {
				$('#useemail').slideDown('slow');
			}
		});
		
		//if( posted ) { $('#faqsEngine').html( 'You were the last person to submit a comment.' ); }
		
		$('li.answer div').children('.delete').click(function(){
			action = "commentID="+$(this)[0].id+"&delete=true";
			$.ajax({
				type: 'GET',
				url: '/comments.php',
				data: action,
				timeout: 10000,
				error: function(error){
					$('#thankyou').html('<div align="center">'+error+'</div>');
				},
				success: function(php){
					$('#thankyou').html( 'Deleted' );
				}
			});
			return false;
		}).css('cursor','pointer');
		
		$('li.answer div').children('.accept').click(function(){
			action = "commentID="+$(this)[0].id+"&accept=true";
			$.ajax({
				type: 'GET',
				url: '/comments.php',
				data: action,
				timeout: 10000,
				error: function(error){
					$('#thankyou').html('<div align="center">'+error+'</div>');
				},
				success: function(php){
					$('#thankyou').html( 'Accepted' );
				}
			});
			return false;
		}).css('cursor','pointer');
		
		$('div.respond').hide();
		$('li.answer div').children('.respond').click(function(){
			if( $(this).parent().parent().children('div.respond').is(':visible') ) {
				$(this).parent().parent().children('div.respond').slideUp('slow');
			} else {
				$(this).parent().parent().children('div.respond').slideDown('slow');
			}
		}).css('cursor','pointer');
	});
	
	function checkLength(obj) {
		if( obj.value.length > 500 ) {
			obj.value = obj.value.substring(0,500);
			return false;
		} else {
			if( obj.value.length ) { $('#chars').html( obj.value.length ); } else { $('#chars').html( '0' ); }
		}
	}
	
	function submitComment(obj) {
		if( obj.comment.value == '' || obj.comment.value == 'Write your comment or question...' ) { return false; }
		var form = obj;
		$('#thankyou').empty();
		$(form).addClass("ajWait").find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea").filter(":enabled").each(	 function() {
			var name = ( this.name || this.id || this.parentNode.name || this.parentNode.id );
			if ( name ) {
				if( typeof(action) != 'undefined' ) { action += '&' + name + '=' + escape( this.value ); }
				else { action = name + '=' + escape( this.value ); }
			}
		});
		$.ajax({
			type: 'POST',
			url: '/comments.php',
			data: action,
			timeout: 10000,
			error: function(error){
				$('#thankyou').html('<div align="center">'+error+'</div>');
			},
			success: function(php){
				$('#thankyou').html( php );
			}
		});
		form.comment.value = '';
		$('#faqsEngine').hide();
		$('span.addComment').hide();
		$('span.removeComment').hide();
		return false;
	}
	
	function sendAnswer(obj) {
		comment = $(obj).parent().children('textarea').val();
		commentID = obj.name;
		$.ajax({
			type: 'POST',
			url: '/comments.php',
			data: "comment="+comment+"&commentID="+commentID+'&sitecode='+sitecode+'&page='+page+'&respond=true',
			timeout: 10000,
			error: function(error){
				$('#thankyou').html('<div align="center">'+error+'</div>');
			},
			success: function(php){
				$('#thankyou').html( php );
			}
		});
		return false;
	}