if (typeof Browser == "undefined" || !Browser) {
	var Browser = {};
}
Browser.getClientWidth = function () {
	return (window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || (document.body && document.body.clientWidth) || 0);
};
Browser.getClientHeight = function () {
	return (window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || (document.body && document.body.clientHeight) || 0);
};
Browser.getPageScrollTop = function () {
	return (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop) || 0;
};
Browser.getPageScrollLeft = function () {
	return (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft) || 0;
};
Browser.getPageSize = function () {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else {
		if (document.body.scrollHeight > document.body.offsetHeight) {
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
		}
	}
	var pageHeight, pageWidth;
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
};

var App = Class.create();
App.prototype = {baseInitialize:function () {

}, initialize:function () {
	this.listenKey();
}, getKey:function (e) {
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	if (key == 'x') { 
		janela.prototype.hide();
	}
}, addLoadEvent:function (func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}	
}, listenKey:function () {
	document.onkeypress = this.getKey; 
}, stoplistenKey:function () {
	document.onkeypress = ''; 	
}};

var AppAjuda  = Class.create();
AppAjuda.prototype = {initialize:function (event,element,texto) {
	this.create(event,element,texto);
},create:function (event,element,texto) {
		//<div id="divteste" style="position:absolute;width:300px;height:100px;z-index:1;background-color:#CCCCCC;border:solid #000000 1px;visibility:hidden;"></div>
		container = document.createElement("div");
		container.setAttribute("id","ajuda");
		container.style.top=Event.pointerY(event)+'px';
		container.style.left=Event.pointerX(event)+10+'px';
		var div = $('salacontainer');
		div.appendChild(container);
		var ajax = new AppAjax('EAD_script&sala='+sala, 'ajuda', 'passo=ajuda&texto='+texto, 'post');
		//Event.observe(element, "mousemove", this.eventMouseMove.bindAsEventListener(this,element,event), false);		
		Event.observe(element, "mouseout", this.eventMouseOut.bindAsEventListener(this,element,event),false);
		//$('divteste').style.visibility='';$('divteste').style.left=Event.pointerX(event);$('divteste').style.top=Event.pointerY(event);
		//$('divteste').style.visibility='hidden';
		//alert('oi');
},eventMouseMove:function (obj,element,event) {
	AppAjax.prototype.msg(Event.pointerY(event));
	var container = $('ajuda');
	container.style.top=Event.pointerY(event)+10+'px';
	container.style.left=Event.pointerX(event)+10+'px';
},eventMouseOut:function (obj,element,event) {
	var node = $('ajuda').parentNode;
	node.removeChild($('ajuda'));
	//Event.stopObserving(element, "mousemove", this.eventMouseMove.bindAsEventListener(this,element,event), false);		
	Event.stopObserving(element, "mouseout", this.eventMouseOut.bindAsEventListener(this),false);
}};

var intervalID = new Array();

var AppChat  = Class.create();
AppChat.prototype = {initialize:function (event) {
	this.create(event);
},create:function (event) {
	var el = getElementsByClass(document,'dialog','*');
	for (i=0;i<el.length;i++) {
		var existe=true;
	}
	if (existe) {
		AppAjax.prototype.msg('Chat j&aacute; est&aacute; ativo');
	}else{
		var win = new Window({className: "dialog", top:Browser.getClientHeight()-350,left:Browser.getClientWidth()-450,width:400, height:300, zIndex: 999, resizable: false, title: "Chat Sala Virtual UNIDAVI", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true});
		win.getContent().innerHTML= '<div id="chat"></div>';
		win.setStatusBar("www.virtual.unidavi.edu.br");
		var ajax = new AppAjax('EAD_script&sala='+sala, 'chat', 'passo=chat', 'post');
		win.show();
		this.show();
		
		var el = getElementsByClass(document,'dialog','*');
		for (i=0;i<el.length;i++) {
			var id=el[i].id;
		}
		Event.observe($(id+'_close'), "click", this.close.bindAsEventListener(this,id),false);
		

	}
},close:function(obj,div){
	var node = $(div).parentNode;
	node.removeChild($(div));
	
	clearInterval(intervalID[0]);
	clearInterval(intervalID[1]);
},show:function () {
	var ajax = new AppAjax('EAD_script&sala='+sala, 'chat', 'passo=chat', 'post');
	intervalID[0]=setInterval("var ajax = new AppAjax('EAD_script&sala='+sala, 'chat_users', 'passo=chat&pass=chat_users', 'post');", 5000)
	intervalID[1]=setInterval("var ajax = new AppAjax('EAD_script&sala='+sala, 'chat_msg', 'passo=chat&pass=chat_msg', 'post');", 2000)
}};

var AppAjax  = Class.create();
AppAjax.prototype = {initialize:function (pagina, destino, parametros, metodo, call, retornopadrao, pgretorno, menu) {
	//this.create();
	if (call != null && call != '') {
		this.call = call;
	}
	if (metodo == null) {
		this.metodo = 'post'
	}else{
		this.metodo = metodo;	
	};
	if (parametros == null) {
		this.parametros = 'nulo=null';
	}else{
		this.parametros = parametros;		
	};
	if (destino == '' ) {
		this.destino = msg;
	}else{
		if (destino == 'sala') {
			this.destino = 'salacontainer';
		}else{
			this.destino = destino;
		}
	};
	if (this.destino!='sysmsg') {
		$(this.destino).innerHTML='<img src="EAD/imagens/ajax-loader-1.gif" border="0">';
	}
	if (retornopadrao == true) {
		this.retornopadrao = true;
	};	
	if (pgretorno != null) {
		this.pgretorno = pgretorno;
	}
	if (menu != null) {
		this.menu = true;
	}
	//StartRequest = setTimeout("window.location.href = 'http://www.unidavi.edu.br/?pagina=meu_espaco';alert('Probelmas com o JavaScript de Seu Computador. Precione Ctrl + F5 para atualizar efetivamente.');",50000);
	this.load(pagina, this.destino, this.parametros, this.metodo);
}, gifload:function () {
	return gifload;	
}, load:function (pagina, destino, parametros, metodo) {
	this.contentNode = $(destino);
	var request = new Ajax.Request(URL_PAGINA + pagina, {method:metodo , postBody:parametros, onSuccess:this.attachEvents.bind(this)});
	return this.contentNode;
}, attachEvents:function (response) {
	this.contentNode.innerHTML = response.responseText;
	this.response(response.responseText);
	if (this.call != null){
		this.call(response.responseText);
	}
	if (this.destino == 'sysmsg') {
		this.msg (response.responseText)
	}
	if (response.responseText == 'area restrita') {
		window.location.href = url;
	};
	if (this.retornopadrao == true) {
		var ajax = new AppAjax('EAD_script&sala=' + sala, 'sala','passo=recados','post');
	};	
	if (this.pgretorno != null) {
		var ajax = new AppAjax('EAD_script&sala=' + sala, 'sala', this.pgretorno,'post');
	};
	if (this.menu == true) {
		var ajax = new AppAjax('EAD_script&sala=' + sala, 'menu', 'atualizar=menu','post');	
	}
	
	if (StartRequest) {
  	  //clearTimeout(StartRequest);  
	}	
	//this.hideLoad();
}, response:function (response) {
	return response;	
}, reset:function () {

}, create:function () {
	this.showLoad();
}, msg:function (msg) {
	if ($('sysmsg').style.display != 'none') {
		$('sysmsg').style.display = '';
		$('sysmsg').innerHTML = ''
    }
	$('sysmsg').innerHTML = msg;	
	$('sysmsg').style.display = 'block';
	if (cont) {
  	  clearTimeout(cont)	;
	}
	cont = setTimeout("document.getElementById('sysmsg').style.display = \"none\";",10000); 
}, showLoad:function () {
	div = document.createElement('div');
	div.id = 'loading';
	gif = document.createElement("img");
	gif.src = this.gifload();
	div.appendChild(gif);
	divtexto = document.createElement('div');
	divtexto.appendChild(document.createTextNode('  Aguarde... '));
	div.appendChild(divtexto);
	document.body.appendChild(div);
}, hideLoad: function () {
	document.body.removeChild($('loading'));
}, createRequester:function () {

}, finaly: function () {
	this.hideLoad();	
}};

var AppAjaxYUI = Class.create();
AppAjaxYUI.prototype = {initialize:function (pagina, destino, parametros, metodo) {
	YAHOO.namespace("SalaVirtual.index");
	if (destino!='sysmsg') {
		document.getElementById('salacontainer').innerHTML='<img src="EAD/imagens/ajax-loader-1.gif" border="0">';
	}
	var callbacks = {	
		success : function (o) {
			document.getElementById('salacontainer').innerHTML = o.responseText;
		}
	};
	YAHOO.util.Connect.asyncRequest(metodo,URL_PAGINA + pagina, callbacks, parametros);	
	//YAHOO.util.Connect.asyncRequest('POST',"http://www.unidavi.edu.br/?pagina=EAD_script&sala="+sala, callbacks, '');	
}};

var AppAjaxLog  = Class.create();
AppAjaxLog.prototype = {initialize:function (tipo) {
	this.metodo = 'post'
	this.parametros = 'passo=acesso&pass=' + tipo;
	this.load(this.parametros, this.metodo);
}, load:function (parametros, metodo) {
	//alert(sala);
	var request = new Ajax.Request(URL_PAGINA + 'EAD_script&sala='+sala, {method:metodo , postBody:parametros, onSuccess:this.attachEvents.bind(this)});
}, attachEvents:function (response) {
	//alert(response.responseText);
	if (response.responseText == 'area restrita') {
		window.location.href = host;
	};
}};

var fundomodal = Class.create();
fundomodal.prototype = {baseInitialize:function () {

}, initialize:function () {
	this.show();
}, getfundo:function () {
	return 'fundo';
}, setPlacement:function (width, height) {
	if (top < 0) {
		top = 0;
	}
	if (left < 0) {
		left = 0;
	}
	Element.setStyle($('fundo'), {top:top + "px", left:left + "px", width:width + "px"});
	
}, resize:function () {
	var fundo = $('fundo');
	var height = Browser.getClientHeight() + Browser.getPageScrollTop();
	if (height <= 632) {
		height = 650;
	}
	fundo.style.height = height + 'px';
} , show:function () {
	var divfundo = document.createElement('div');
	divfundo.id = this.getfundo();
	var scrollTop = Browser.getPageScrollTop();
	divfundo.style.height = Browser.getClientHeight() + Browser.getPageScrollTop() + scrollTop +  'px';
	document.body.appendChild(divfundo);	
}, hide:function () {
	document.body.removeChild($('fundo'));	
}};

var janela = Class.create();
janela.prototype = {baseInitialize:function (options) {

}, initialize:function (pagina, destino, parametros, metodo) {
	this.iniJanela(pagina, destino, parametros, metodo);
	this.container = $(destino);
} , container:function () {
	return $('janela');	
}, janelatexto: function (destino) {
	return 'janelatexto';
} , janela: function () {
	return 'janela';
} , hide:function () {
	$(this.janela()).style.display = 'none';
	$(this.janelatexto()).innerHTML = '';
	fundomodal.prototype.hide();
	App.prototype.stoplistenKey();
	
	//eliminando o listner de eventos
	Event.stopObserving($('fechajanela'), "click", this.hide.bindAsEventListener(this));
	Event.stopObserving($('linkfechajanela'), "click", this.hide.bindAsEventListener(this));	
	Event.stopObserving(window, "resize", this._centerDialog.bindAsEventListener(this));
	Event.unloadCache();

}, iniJanela:function (pagina, destino, parametros, metodo) {
	this.fundo = new fundomodal();
	var divjanela = document.createElement('div');
	divjanela.id = this.janela();
	var janelalink = document.createElement('div');
	janelalink.id = 'janelalink';
	divjanela.appendChild(janelalink);
	var divjanelatexto = document.createElement('div');
	divjanelatexto.id = this.janelatexto();
	divjanela.appendChild(divjanelatexto);
	document.body.appendChild(divjanela);
	$('janelalink').innerHTML = 'Pressione <a href="#" id="fechajanela" title="Fechar">x</a> para fechar. <a href="#" id="linkfechajanela" title="Fechar"><img src="' + closeButton + '" border="0" alt="Bot&atilde;o para fechar a Janela" /></a>';
	this.show();
	Event.observe($('fechajanela'), "click", this.hide.bindAsEventListener(this));
	Event.observe($('linkfechajanela'), "click", this.hide.bindAsEventListener(this));
	App.prototype.listenKey();
	var ajax = new AppAjax(pagina, this.janelatexto(), parametros, metodo);	
	this._centerDialog();	
	Event.observe(window, "resize", this._centerDialog.bindAsEventListener(this));
	
}, organizafundo:function () {
	fundomodal.prototype.resize();
}, setPlacement:function (top, left, width, height) {
	if (top < 0) {
		top = 0;
	}
	if (left < 0) {
		left = 0;
	}
	Element.setStyle($('janela'), {top:top + "px", left:left + "px", width:width + "px"});
}, _centerDialog:function (e) {
	var width = 792;
	var height = 632;
	var scrollTop = Browser.getPageScrollTop();
	var top = (Browser.getClientHeight() - height) / 2 + Browser.getPageScrollTop() + scrollTop;
	var left = (Browser.getClientWidth() - width) / 2 + Browser.getPageScrollLeft();
	this.setPlacement(top / 2, left, width, height);
	this.organizafundo();	
}, show:function () {
	$('janela').style.display = '';
}};

//Ijanela
var ijanela = Class.create();
ijanela.prototype = {baseInitialize:function (options) {

}, initialize:function (pagina, destino, parametros, metodo) {
	this.iniJanela(pagina, destino, parametros, metodo);
	this.container = $(destino);
} , container:function () {
	return $('janela');	
}, janelatexto: function (destino) {
	return 'ijanelatexto';
} , janela: function () {
	return 'janela';
} , hide:function () { 
	$(this.janela()).style.display = 'none';
	//$(this.janelatexto()).innerHTML = '';
	fundomodal.prototype.hide();
	App.prototype.stoplistenKey();
	
	//eliminando o listner de eventos
	Event.stopObserving($('fechajanela'), "click", this.hide.bindAsEventListener(this));
	Event.stopObserving($('linkfechajanela'), "click", this.hide.bindAsEventListener(this));	
	Event.stopObserving(window, "resize", this._centerDialog.bindAsEventListener(this));
	Event.unloadCache();

}, iniJanela:function (pg, destino, parametros, metodo) {
	this.fundo = new fundomodal();
	var divjanela = document.createElement('div');
	divjanela.id = this.janela();
	var janelalink = document.createElement('div');
	janelalink.id = 'janelalink';
	divjanela.appendChild(janelalink);

//	var linkdown = document.createElement('div');
//	linkdown.id = 'linkdown';
//	divjanela.appendChild(linkdown);
	
	var divjanelatexto = document.createElement('iframe');
	divjanelatexto.id = this.janelatexto();
	divjanelatexto.src = url + pagina + pg;
	
	divjanela.appendChild(divjanelatexto);
	
	document.body.appendChild(divjanela);
	$('janelalink').innerHTML = 'Pressione <a href="" id="fechajanela" onclick="return false;" title="Fechar">aqui</a> para fechar. <a href="" id="linkfechajanela" onclick="return false;" title="Fechar"><img src="' + closeButton + '" border="0" alt="Bot&atilde;o para fechar a Janela" /></a>';
//	$('linkdown').innerHTML = 'teste';	
	this.show();
	Event.observe($('fechajanela'), "click", this.hide.bindAsEventListener(this));
	Event.observe($('linkfechajanela'), "click", this.hide.bindAsEventListener(this));
	App.prototype.listenKey();
//	var ajax = new AppAjax(pagina, this.janelatexto(), parametros, metodo);	
	this._centerDialog();	
	Event.observe(window, "resize", this._centerDialog.bindAsEventListener(this));
	
}, organizafundo:function () {
	fundomodal.prototype.resize();
}, setPlacement:function (top, left, width, height) {
	if (top < 0) {
		top = 0;
	}
	if (left < 0) {
		left = 0;
	}
	Element.setStyle($('janela'), {top:top + "px", left:left + "px", width:width + "px"});
}, _centerDialog:function (e) {
	var width = 792;
	var height = 632;
	var scrollTop = Browser.getPageScrollTop();
	var top = (Browser.getClientHeight() - height) / 2 + Browser.getPageScrollTop() + scrollTop;
	var left = (Browser.getClientWidth() - width) / 2 + Browser.getPageScrollLeft();
	this.setPlacement(top / 2, left, width, height);
	this.organizafundo();	
}, show:function () {
	$('janela').style.display = '';
}};
