/**
 * Stores the AJAX infrastructure configuration,
 * @author josala
 * @date 16-apr-2010
 */


/**
 * Stores the AJAX global config
 */
var GlobalConfig = {
    /**
     * Indicates the backend service dispatcher
     */
	AJAX_DISPATCHER_URL:    getURL()+"ajax/dispatcher",
	/**
	 * Indicates the AJAX method to send the information
	 */
    AJAX_DISPATCHER_METHOD: "POST",
    /**
     * Number of results per page on the lists pages
     */
    LIST_RESULT_PER_PAGE:   25,
    /**
     * Show favicon per bookmark on the bookmark pages
     */
    SHOW_FAVICON: false, //Experimental
    /**
     * List of the bookmark category
     */
    BOOKMARKS_CATEGORIES: [{value: "", text: "- Select Category -"},
                           {value: "Blog", text: "Blog"},
                           {value: "Business", text: "Business"},
                           {value: "Entertainment", text: "Entertainment"},
                           {value: "Food", text: "Food"},
                           {value: "Gadget", text: "Gadget"},
                           {value: "Game", text: "Game"},
                           {value: "Lifestyle", text: "Lifestyle"},
                           {value: "Messaging", text: "Messaging"},
                           {value: "News", text: "News"},
                           {value: "Premium content", text: "Premium content"},
                           {value: "Shopping", text: "Shopping"},
                           {value: "Sport", text: "Sport"},
                           {value: "Technology", text: "Technology"},
                           {value: "Travel", text: "Travel"},
                           {value: "N/A", text: "Uncategorized"}],
    /**
     * Stores the Image upload URL
     */
    IMAGE_UPLOAD_URL: getURL()+"image/asynchronousuploader.action"
};


$.ajaxSetup({ 
    scriptCharset: "utf-8" , 
    contentType: "application/json; charset=utf-8"
});


var addthis_config = {
   ui_click: true
}

/**
 * Utilities
 */

/**
 * Method for sorting object list based on an object attribute
 * A bubble sorting method implementation
 * @param 
 */
function qsort(a,attr) {
    if (a.length == 0) return new Array();
 
    var left = new Array();
    var right = new Array();
    var pivot = a[0];
    for (var i = 1; i < a.length; i++) {
        if (a[i][attr] < pivot[attr])
            left.push(a[i]);
        else
            right.push(a[i]);
    }
 
    return qsort(left,attr).concat(pivot, qsort(right,attr));
}

/**
 * Merges a list into a strig separating each item with the "separator" string
 * @param list The list to merge
 * @param separator The list item separator
 */
String.merge = function(list,separator) {
	var _string = new String();
	for(i in list) { 
		if(list[i] && list[i] != "")
			_string += list[i] + (i != list.length-1 ? separator : "");
	}
	return _string;
};

/**
 * Removes the whitespaces at the beginnign and at the end of a string
 * @param _string The string to remove the whitespaces
 * @return The string without the whitespaces
 */
function whitespaces(_string)
{
     return _string.replace(/^\s*|\s*$/g,'');
}


function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

function getURL() {
	var url = window.location;
	return "http://"+url.host+"/";
}

