
/**
 * Querycomposer-class
 * @class Querycomposer
 * @property {string} prefixdir Prefix for certain AJAX-loading -calls
 */
function Querycomposer(){

    this.prefixdir = "querycomposer/";
    var that = this;
    
    
    /**
     * Toggle visibility of Querycomposer - choose set -form
     * @function toggleQuerycomposerForm
     */
    this.toggleQuerycomposerForm = function(){
    
        $("#querycomposer_setselect_hideout").show();
        
    };

    /**
     * Composes queries based on a given search string
     * @function loadQueries
     */
    this.loadQueries = function(searchstring, set){

       $("#querycomposer").load(that.prefixdir + "loadcontent.php", {
            action: "createqueries",
			searchstring: escape(search.checkSearchstring(searchstring).replace(/\"/g, '#')),
			standalone: true
        });
        
    };

    /**
     * Create form for selecting which queries to show and which not
     * @function loadQueryForm
     */
    this.loadQueryForm = function(searchstring, set){

       $("#querycomposer").load(that.prefixdir + "loadcontent.php", {
            action: "queryform",
//			searchstring: escape(search.checkSearchstring(searchstring).replace(/\"/g, '#')),
			standalone: true
        });
        
    };

    /**
     * Grabs selected querylinks and saves them to a cookie
     * @function saveQuerySelection
     */
    this.saveQuerySelection = function(){

		var querysource = new Array;
		$("#querychoicesform input[checked]").each(function() {
			querysource.push($(this).attr('value'));
		});

		if (querysource.length > 0) {

			$.post(that.prefixdir + "loadcontent.php", {
				action: "savequeryselection",
				querysources: querysource.join(),
				standalone: true
			}, function(data) {
				//$("#querycomposer").empty();
				//$("#querycomposerinfo").html("Query selection saved").fadeOut(2000);
				that.loadQueries($('#querycomposer_searchstring').attr('value'),0);
			});
			
		}
        
    };
    
}
