function Module(options) {

	this.xmlhttp = new Ajax();
	this.url = options.url || null;
	this.box = new Box(options.col || null, options.id || null);
	this.html = null;
	this.param = options.param || '';
	
	this.type = 'M';
	this.id = options.id || null;

 	this.getModule = function() {
		var self = this;
		this.box.loading();
		this.xmlhttp.onsuccess = function() { self.showModule(); }
		this.xmlhttp.request("/getModule.php?url=" + this.url, {method: 'GET'});
	}

	this.showModule = function () {

		this.html = this.xmlhttp.responseXML;
		var body = this.html.getElementsByTagName('body')[0];

		
		if (!body && window.ActiveXObject) { 
			var xmldoc;
			try { xmldoc = new ActiveXObject("MSXML2.XmlDom"); } catch (e) {}
			if (!xmldoc) try { xmldoc = new ActiveXObject("Microsoft.XmlDom"); } catch (e) {}
			if (!xmldoc) try { xmldoc = new ActiveXObject("MSXML.XmlDom"); } catch (e) {}
			if (!xmldoc) try { xmldoc = new ActiveXObject("MSXML3.XmlDom"); } catch (e) {}
			xmldoc.validateOnParse = false;
			if (xmldoc.loadXML(this.xmlhttp.responseText)) { // recovery seems possible
				this.html = xmldoc.documentElement;
				body = this.html.getElementsByTagName('body')[0];
			} 
		}

		if(!body) {
			this.box.setContent(document.createTextNode('Votre module contiens une erreur.'));
			this.box.setTitle('Module non Valide');
			return false;
		}
		
		// Récupération du Titre du Module
	    var JM_TITLE = this.html.getElementsByTagName('title')[0];
		this.box.setTitle(JM_TITLE.firstChild.nodeValue);

		// Récupération du Contenu du Module
		var JM_CONTENT = document.createElement("div");
		JM_CONTENT.className = 'module';
		JM_CONTENT.innerHTML = (body.innerHTML)?body.innerHTML:body.xml;

		// Récupération des scripts du Module
		var JM_ONLOAD = null;

		var scripts = this.html.getElementsByTagName('script');
		for (var i=0; i<scripts.length; i++) {
			var src = scripts[i].getAttribute('src');
			if(!scripts[i].getAttribute('src')) {
		       eval(scripts[i].firstChild.nodeValue);
			}
		}
		
		// Script de modif 
		var allforms = JM_CONTENT.getElementsByTagName('div');

		for (var i=0; i<allforms.length; i++) {
			if(allforms[i].className=='config') {
				var JM_CONFIG = document.createElement("form");
				JM_CONFIG.appendChild(allforms[i]);
				this.box.setConfig(JM_CONFIG);
				break;
				
			}
		}
		

		// CSS
		var allcss = this.html.getElementsByTagName('style');
		var css_rules = '';
		for (var i=0; i<allcss.length; i++) {
			if(allcss[i].firstChild) css_rules += allcss[i].firstChild.nodeValue;
		}
		
		if(css_rules.length>0) {
			var css = document.createElement('style');
			css.setAttribute('type','text/css');
			var head = document.getElementsByTagName('head')[0];
			if(css.styleSheet) {
				css.styleSheet.cssText = css_rules;
			} else {
				css.innerHTML = css_rules;
			}
			head.appendChild(css);
		}
		
		

		if (JM_ONLOAD) window.setTimeout(JM_ONLOAD, 100);  
		this.box.setContent(JM_CONTENT);
		
	}	

	this.onLoad = function() {
		
		this.getModule();
		boxObjArray[boxObjArray.length] = this;

		if(!this.id) {
			var self = this;

			this.ajaxid = new Ajax();
			this.ajaxid.onsuccess = function() {
				self.id = self.ajaxid.responseText;
				self.box.id = self.ajaxid.responseText;
			}
			this.ajaxid.request("/save.php?action=new&type=M&url=" + escape(this.url), {method: 'GET'});
		} else {
			this.box.id = this.id;
		}
	}

	this.onLoad();
}

