function LJs(){
	this.modalNotification = new ModalNotification();
}



LJs.prototype.ajax = function(attr){
	//TODO: Check all parameters and only use those that exists

	jQuery.ajax({
		url:attr.url,
		success:attr.success,
		data:attr.data,
		dataType:"json",
		type:"POST"
	});
}

LJs.prototype.ajaxForm = function(attr){
	//TODO: Check all parameters and only use those that exists
	
	jQuery(attr.selector).ajaxForm({
		beforeSubmit:attr.beforeSubmit,
		data:attr.data,
		success:attr.success,
		dataType:  'json',
		url:attr.url,
		type:"POST"
	});
}

function ModalNotification(){
	this.notificationDiv = document.createElement("div");
	this.notificationDiv.setAttribute("id", "notificationDiv");
	jQuery("body").append(this.notificationDiv);
}


ModalNotification.prototype.infoBox = function(title, message){
	jQuery.ui.dialog.defaults.bgiframe = false;
	this.notificationDiv.setAttribute("title", title);
	this.notificationDiv.innerHTML = message;
	if(this.modal != null){
		this.modal.remove();
	}
	this.modal = jQuery(this.notificationDiv).dialog({
		modal:true, 
		resizeable: false, 
		draggable:false,
		close: function(event, ui) { 
		
		}
	});
	this.modal.dialog('option', 'title', title);
}

ModalNotification.prototype.okBox = function(title, message){
	this.notificationDiv.setAttribute("title", title);
	this.notificationDiv.innerHTML = message;
	if(this.modal != null){
		this.modal.remove();
	}
	this.modal = jQuery(this.notificationDiv).dialog({
		modal:true, 
		resizeable: false, 
		draggable:false,
		buttons: { "Ok": function() { jQuery(this).dialog("close"); }}
	});
	this.modal.dialog('option', 'title', title);
}


ModalNotification.prototype.remove = function(finalMessage){
	if(finalMessage != null){
		this.notificationDiv.innerHTML = finalMessage;
		var tmp = this.modal;
		setTimeout(function(){tmp.remove()}, 700);
	}
	else{
		this.modal.remove();
	}
}

jQuery(document).ready(function(){LJs = new LJs();})
