/* 
 * Creates the BonzoBox logging objects - both for client-side logging and
 * asynchronous server-side logging.
 * 
 */


/**
 * An abstraction for console.log so that we don't have to check every time to see if console.log exists
 */
BBX.log = function(msg) {
	if('undefined' !== typeof console && console.log) {
		console.log(msg);
	}
};


/**
 * Server-side logging
 */

(function() {



    //  record($type,$doer,$doee,$site=NULL,$url=NULL,$email=NULL,$info=NULL)

    /**
     * @param domobj DOM object, (optional, but really good to have) A DOM object
     * to attach the XHR request to.  When provided this makes it more likely to
     * have multiple logging requests work together.
     * @param type string, Required. The string telling what happened, (one of the strings
     * used as an event type)
     * @param site integer Optional. The site ID of the site that is involved in
     * this event.
     * @param url string optional. An external URL related to this event.
     * @param doee int optional. The user ID of the person that this event was
     * done to
     * @param email string optional. An E-mail address related to this event
     * @param info string optional. Any extra data that we want to record about
     * this event.
     *
     * @name BBX.elog
     *
     * Used to asynchronously record a client-side action in the event log.
     *
     *
     */
    function elog(domobj, type, site, url, doee, email, info) {

	var data = '', opts;

	if(type !== null) {
	    data += 'type=' + encodeURIComponent(type);
	}

	if(site !== null) {
	    data += '&site=' + encodeURIComponent(site);
	}

	if(url !== null) {
	    data += '&url=' + encodeURIComponent(url);
	}

	if(doee !== null) {
	    data += '&doee=' + encodeURIComponent(doee);
	}

	if(email !== null) {
	    data += '&email=' + encodeURIComponent(email);
	}

	if(info !== null) {
	    data += '&info=' + encodeURIComponent(info);
	}

	if(domobj !== null) {
	    domobj = $(domobj);
	} else {
	    domobj = DOMAssistant;
	}


	opts = {

	  url: '/apps/elog.php',
	  method: 'POST',
	  params: data

	};
	
	domobj.ajax(opts);

	
	
    };






    BBX.namespace('elog');
    BBX.elog = elog;

})();



