var showClass = "lg_show";
var hideClass = "lg_hide";
$(
	function(){
		$("a.lg_expandable").click(
			function(){
				ref = this.href;
				
				ref = ref.split("#");
				ref = "#" +  ref[1];
				if ( $(ref).hasClass( showClass ) ) {
					$(ref).removeClass( showClass );
					$(ref).addClass( hideClass );
					$(ref).slideUp();
				} else{
					$(ref).addClass( showClass );
					$(ref).removeClass( hideClass );
					$(ref).slideDown();
				}
				
				return false;
			}
		);
		var searchUrl = base + "/ayuda/buscar?q=";
		$('#liveQuerySearch').liveSearch( { ajaxURL: searchUrl , customCSS : true, appendTo: $('#SearchResults'), resultClass: "questionsResults" } );

		$("#expand_form").click( function(){ 
				ref = this.href;
				
				ref = ref.split("#");
				ref = "#" +  ref[1];
				if ( $(ref).hasClass( showClass ) ) {
					$("#conditionExpand").hide();
				} else{
					$("#conditionExpand").show();
					$("#comment-messages").hide();
				}
		} );

		var options = {
        		success:       showResponse,
        		dataType:  'json'
     		}; 
    		// bind form using 'ajaxForm'
    		$('#user_question').ajaxForm(options);
	}

);

function showResponse( data )  {
		if ( data.error ){
			$('#comment-messages').empty();
			$('#comment-messages').html("<p class='error'>"+ data.msg +"</p>");
			$('#comment-messages').removeClass("notice");
			$('#comment-messages').addClass("error-message");
			$('#comment-messages').show();
			return false;
		} else{
			$('#comment-messages').hide();
			$("#expand_form").click();
			setGlobalMessage("Tu pregunta fue enviada correctamente");
			$('#user_question div.input input').val('');
			$('#user_question textarea').val('');

		}
		return false;
} 