alanis.core.module.provide('bmodel');
alanis.core.module.require('alanis.gui.Window');
alanis.core.module.require('alanis.core.type');
alanis.core.module.require('alanis.application.Application');
alanis.core.module.require('alanis.application.Receiver');
alanis.core.module.require('alanis.application.ResultHandler');
alanis.core.module.require('alanis.model.ParameterSet');

alanis.debug = false;

bmodel = {};

bmodel.declareTinyMCEEditors = function(i_names) {
	var ids = i_names.split(',');
	
	for (var i = 0; i < ids.length; i++) {
		$('#' + ids[i]).css('width', '100%').css('height', '200px');
	}
	
	tinyMCE.init({
		language : "fr",
		mode : "exact",
		elements: i_names,
		entity_encoding : "numeric",
		theme : "advanced",
		theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,link,unlink",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "none",
		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		setup : function(ed) {
			// Display an alert onclick
			ed.onChange.add(function(ed) {
				var id = '#' + ed.id;
				if ($(id).get(0).onchange) {
					$(id).get(0).onchange();
				}
			});
		}
	});
}

alanis.onReady(function(){
	alanis.core.module.map('bmodel', 'js');

	alanis.core.module.require('bmodel.lib.util');	// Load definitions, handlers, etc...
	alanis.core.module.require('bmodel.navigator');
	alanis.core.module.require('bmodel.lib.rules');

	// Defines navigation handler
	$_app.history.onEvtNavigate = bmodel.navigator.onEvtNavigate;
	
	$_app.history.registerServerControl("navigator.proxy");
	$_app.history.receiver.setContentLoader(bmodel.navigator.fill);

	bmodel.w_appcontrol = new alanis.gui.Window('appcontrol', 'appcontrol.proxy');
	bmodel.w_login = new alanis.gui.Window('login', 'login.proxy');
	bmodel.w_forgotpassword = new alanis.gui.Window('forgotpassword', 'forgotpassword.proxy');
	bmodel.w_subscribe = new alanis.gui.Window('subscribe', 'subscribe.proxy');
	
	bmodel.w_home = new alanis.gui.Window('home', 'home.proxy');

	bmodel.w_nbnotebook = new alanis.gui.Window('nbnotebook', 'nbnotebook.proxy');
	bmodel.w_nbnewspaper = new alanis.gui.Window('nbnewspaper', 'nbnewspaper.proxy');
	bmodel.w_nbnews = new alanis.gui.Window('nbnews', 'nbnews.proxy');
	bmodel.w_nbdiary = new alanis.gui.Window('nbdiary', 'nbdiary.proxy');
	bmodel.w_nbdiaryall = new alanis.gui.Window('nbdiaryall', 'nbdiaryall.proxy');
	bmodel.w_nbevent = new alanis.gui.Window('nbevent', 'nbevent.proxy');
	bmodel.w_nbkits = new alanis.gui.Window('nbkits', 'nbkits.proxy');
	bmodel.w_nbkit = new alanis.gui.Window('nbkit', 'nbkit.proxy');
	bmodel.w_nbarticle = new alanis.gui.Window('nbarticle', 'nbarticle.proxy');
	bmodel.w_nbkitssearch = new alanis.gui.Window('nbkitssearch', 'nbkitssearch.proxy');

	bmodel.w_clubclub = new alanis.gui.Window('clubclub', 'clubclub.proxy');
	bmodel.w_clubmessages = new alanis.gui.Window('clubmessages', 'clubmessages.proxy');
	bmodel.w_clubmessage = new alanis.gui.Window('clubmessage', 'clubmessage.proxy');
	bmodel.w_clubnewmessage = new alanis.gui.Window('clubnewmessage', 'clubnewmessage.proxy');
	bmodel.w_clubprofile = new alanis.gui.Window('clubprofile', 'clubprofile.proxy');
	bmodel.w_clubprofilerealizations = new alanis.gui.Window('clubprofilerealizations', 'clubprofilerealizations.proxy');
	bmodel.w_clubprofileprojects = new alanis.gui.Window('clubprofileprojects', 'clubprofileprojects.proxy');
	bmodel.w_clubcontacts = new alanis.gui.Window('clubcontacts', 'clubcontacts.proxy');
	bmodel.w_clubcontact = new alanis.gui.Window('clubcontact', 'clubcontact.proxy');
	bmodel.w_clubnetwork = new alanis.gui.Window('clubnetwork', 'clubnetwork.proxy');
	bmodel.w_clubnetworkprofiles = new alanis.gui.Window('clubnetworkprofiles', 'clubnetworkprofiles.proxy');
	bmodel.w_clubnetworkrealizations = new alanis.gui.Window('clubnetworkrealizations', 'clubnetworkrealizations.proxy');
	bmodel.w_clubnetworkprojects = new alanis.gui.Window('clubnetworkprojects', 'clubnetworkprojects.proxy');
	bmodel.w_clubnetworkalerts = new alanis.gui.Window('clubnetworkalerts', 'clubnetworkalerts.proxy');
	
	bmodel.w_profileprofile = new alanis.gui.Window('profileprofile', 'profileprofile.proxy');
	bmodel.w_profilerealizations = new alanis.gui.Window('profilerealizations', 'profilerealizations.proxy');
	bmodel.w_profileprojects = new alanis.gui.Window('profileprojects', 'profileprojects.proxy');
	bmodel.w_profilecontacts = new alanis.gui.Window('profilecontacts', 'profilecontacts.proxy');

	bmodel.w_tbtools = new alanis.gui.Window('tbtools', 'tbtools.proxy');
	bmodel.w_tbbusinessmodels = new alanis.gui.Window('tbbusinessmodels', 'tbbusinessmodels.proxy');
	
	bmodel.w_bmbusinessmodel = new alanis.gui.Window('bmbusinessmodel', 'bmbusinessmodel.proxy');
	bmodel.w_bmproducts = new alanis.gui.Window('bmproducts', 'bmproducts.proxy');
	bmodel.w_bmproduct = new alanis.gui.Window('bmproduct', 'bmproduct.proxy');
	bmodel.w_bmdirectsales = new alanis.gui.Window('bmdirectsales', 'bmdirectsales.proxy');
	bmodel.w_bmdirectsale = new alanis.gui.Window('bmdirectsale', 'bmdirectsale.proxy');
	bmodel.w_bmcommissions = new alanis.gui.Window('bmcommissions', 'bmcommissions.proxy');
	bmodel.w_bmobjectives = new alanis.gui.Window('bmobjectives', 'bmobjectives.proxy');
	bmodel.w_bmprofiles = new alanis.gui.Window('bmprofiles', 'bmprofiles.proxy');
	bmodel.w_bmprofile = new alanis.gui.Window('bmprofile', 'bmprofile.proxy');
	bmodel.w_bmresources = new alanis.gui.Window('bmresources', 'bmresources.proxy');
	bmodel.w_bmresource = new alanis.gui.Window('bmresource', 'bmresource.proxy');
	bmodel.w_bmforecast = new alanis.gui.Window('bmforecast', 'bmforecast.proxy');

	bmodel.w_account = new alanis.gui.Window('account', 'account.proxy');
	bmodel.w_confirmemailaddress = new alanis.gui.Window('confirmemailaddress', 'confirmemailaddress.proxy');

	bmodel.w_aboutcompany = new alanis.gui.Window('aboutcompany', 'aboutcompany.proxy');
	bmodel.w_aboutpartners = new alanis.gui.Window('aboutpartners', 'aboutpartners.proxy');
	bmodel.w_aboutpartner = new alanis.gui.Window('aboutpartner', 'aboutpartner.proxy');
	
	bmodel.lib.rules.apply();
});

