function _xenonGetAjax(url, identifier, position) {
	$.get('_get/ajax/json/' + url + '/', 
		function(data) { 
		    appendOthers(data);
			if (position == 'replace') {
				$(identifier).replace(data.content); 
			} else {
				$(identifier).append(data.content); 
			}
		}
	);
}

function _xenonToAjaxJsonURL(url, key) {
    var cu = '';
    cu = url.replace(('_' + key), ('_get/ajax/json/' +  key));
//    cu = url.replace(document.domain, '');
//    cu = cu.replace('http://', '');
//    cu = cu.replace('https://', '');
//    cu = cu.replace(key + '/', key + ',');
//    cu = url.replace('/', '_get/ajax/json/' + url + '/');
//    cu = cu.replace('//', '/');
    return cu;
}

function appendOthers(data) {
    // automatically appends scripts and content sent via AJAX
    // soon needs to check for exists and then process
	if (data.foot != '') { $('body').append(data.foot); }
	if (data.head != '') { $('head').append(data.head); }
}

// function for checking integrity of json return data
function checkReturn(data) {
    if ((typeof(data.status) == 'undefined') || (data.status == false)) {
        alert('An error occured processing your request.' + "\n" + 'The message returned was: ' + "\n\n" + data.error);
        return false;
    } else {
        return true;
    }
}

// function for displaying data to user when errors and notices occur
function showErrorContents(data) {
    alert(data);
    return false;
}


/* _Xenon confirmation dialog object */
/* _Xenon confirmation dialog object */
var _XenonConfirm = {
    id : '_XenonConfirm_' + randomString(8),
    opts : { },
    create : function(opt) {
        this.checkData(opt);
        $('body').prepend('<div class="' + this.id + '"></div>');
        $('div.' + this.id).html(this.opts.text).dialog({
                                    closeOnEscape: true,
                                    width : '400px',
                                    position : 'center',
                                    modal : true,
                                    title : this.opts.title,
                                    movable : true,
                                    resizable : false,
	                                buttons : { 
                                        'Continue' : function() { _XenonConfirm.destroy(); opt.callback(); }, 
                                        'Cancel' : function() { _XenonConfirm.destroy(); }
                                        },
                                    close : function() {
                                        $(this).dialog('destroy');
                                        }
                                    });
        
    },
    destroy : function() {
        $('body div.' + this.id).dialog('close').remove();
    },
    checkData : function(g) {
        this.opts = g;
        if (typeof(this.opts.title) == 'undefined') this.opts.title = 'Please Confirm';
        if (typeof(this.opts.text) == 'undefined') this.opts.text = 'Confirm this action.';
    }
}
/* _Xenon confirmation dialog object */
/* _Xenon confirmation dialog object */

/* _Xenon notice dialog object */
/* _Xenon notice dialog object */
var _XenonNotice = {
    id : '_XenonNotice_' + randomString(8),
    create : function(content, title) {
    	if ((typeof(title) == 'undefined') || (title == '')) { title = 'Notice';}	
        $('body').prepend('<div class="' + this.id + '">' + content + '</div>');
        $('div.' + this.id).dialog({
                                    closeOnEscape: true,
                                    width : '400px',
                                    position : 'center',
                                    modal : true,
                                    title : title,
                                    movable : false,
                                    resizable : false,
                                    buttons : { 
                                        'OK' : function() { _XenonNotice.destroy(); }
                                        },
                                    close : function() {
                                        $(this).dialog('destroy');
                                        }
                                    });
    },
    destroy : function() {
        $('body div.' + this.id).dialog('close').remove();
    }
}
/* _Xenon notice dialog object */
/* _Xenon notice dialog object */

function randomString(len) {
	var x = '';
    var p = 'abcdefghijklmnopqrstuvwxyz0123456789';
    for (var i=0; i < len; i++) x += p.charAt(Math.floor(Math.random() * p.length));
    return x;
}


