//-----Custom Events Script-----//
var CustomEvent = function() {
	//name of the event
	this.eventName = arguments[0];
	var mEventName = this.eventName;

	//function to call on event fire
	var eventAction = null;

	//subscribe a function to the event
	this.subscribe = function(fn) {
		eventAction = fn;
	};

	//fire the event
	this.fire = function(sender, eventArgs) {
		if(eventAction != null) {
			eventAction(sender, eventArgs);
		}
	};
};

var popup = function(){}

//onClose Event
popup.onClosePopup = new CustomEvent("Close Popup");

popup.show = function(jsonObject) {
	
	new Ajax('/ajax/popup.ajax.php',{method: 'post', data: jsonObject, onComplete: this.displayCallback}).request();
	
}

popup.changePage = function(jsonObject) {
	
	$('popup-main-inner').innerHTML = '<div style="text-align:center;">Please wait...</div>';
	new Ajax('/ajax/popup.ajax.php',{method: 'post', data: jsonObject, onComplete: this.changePageCallback}).request();
	
}

popup.close = function() {

	$('popup-wrapper').style.display = 'none';
	popup.onClosePopup.fire();

}

popup.setTitle = function(title) {
	
	$('popup-title').innerHTML = title;
	
}

popup.setFooterText = function(text) {
	
	$('popup-footer-inner').innerHTML = text;
	
}

popup.displayCallback = function(data) {
	
	$('popup').innerHTML = data;
	$('popup-wrapper').style.display = 'block';

}
