var appsite = Class.create({
	
	initialize:function(){
		document.observe('dom:loaded',function(){
			AppAdmin.show_debug();
			
			
		});
		this.debug_texts=Array();
		this.mboxes=Array();
	},
	submit:function(form){
		alert($(form));
		$(form).submit();
	},
	launch:function(funct){
		document.observe('dom:loaded',function(){
			eval(htmlspecialchars_decode(funct,'ENT_QUOTES'));	
		});
	},
	showConsult:function(){
		
		if (this.mboxes.length){
			var objBody = $$('body')[0];
			for(i=0;i<this.mboxes.length;i++){
				this.mboxes[i].render();	
			}
		}
	},
	close_consult:function(){
		$('messagebox').remove();
	},
	consult:function(texto){
		var div = new Element('div',{id: 'consult', className: 'consult'});
		var a = this.consult.arguments;
		var mbox = new messagebox(texto);
		if (a.length>1){
			for (i=1; i< a.length-1;i+=2){
				mbox.addButton(a[i],a[i+1]);	
			}
		}
		this.mboxes.push(mbox);
		document.observe('dom:loaded',function(){
			AppAdmin.showConsult();
		});
		
	},
	login:function(){
		$('loginpass').value=hex_md5($('loginpass').value);
		
		if ($('formulario')){
			$('formulario').submit();
		}
	},
	debug:function(texttodebug){
		this.debug_texts.push(texttodebug);
	},
	show_debug:function(){
		
		if (this.debug_texts.length==0) return false;
		var div = new Element('div',{id: 'debugger', className: 'debugger_container'});
			div.className='debugger_container';
			div.insert('<div style="display:block;">Debugging</div>');
		var closer = new Element('div',{id: 'debuggerx', className: 'debugger_closer'});
			closer.className='debugger_closer';
			closer.insert('X');
			closer.observe('click',function(){
					$('debugger').remove();
			});
			div.insert(closer);	
		var cont_container = new Element('div',{id: 'dbcc', className: 'debugger_content_container'});
			cont_container.className='debugger_content_container';
		for (i=0; i < this.debug_texts.length;i++){
			more = new Element('div',{className:'debugger_content'});
			more.className='debugger_content';
			more.insert(htmlspecialchars_decode(this.debug_texts[i]));
			cont_container.insert(more);
		}
		
		div.insert(cont_container);
		var objBody = $$('body')[0];
		objBody.appendChild(div);
		
	}
	
});
AppSite = new appsite();
