// JavaScript Document

window.addEvent('domready',function(){
	if($('slide')){
		var handles5 = $$('.mini-slide img');
		var V2 = new viewer($$('#slide img.img-slide'),{
			mode: 'alpha',
			interval: 4500,
			onWalk: function(current_index){
				handles5.removeClass('active');
				handles5[current_index].addClass('active');
			}
		}).play(true);
	}	
	toolTips();
	clickea();
	$$('.menu ul li ul li').each(function(e,i){
		e.addEvent('click',function(ev){
			
			if(e.get('rel')!="" && e.get('rel')!=null) window.location.href=e.get('rel');
		});
	});
	if($('as_dian')){
		myCal = new Calendar({ as_dian: 'Y-m-d' }, { classes: ['alternate'],navigation:2, tweak: {x: 7, y: 0} }); 
	}
	if($('formulario')){
		new FormCheck('formulario', {
		display : {
			showErrors : 0,	
			closeTipsButton : 0,
			flashTips : 1
		}
	})	
	}
});
function calendarioVer(dia,mes){
	c  = $('calendarioVer');
	var req = new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=calendario',
	        	    data: { 'pr' : 'info', 'dia':dia,'mes':mes },
    	        	onRequest: function() { c.set('html','Cargando, un momento por favor'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) { 
						c.set('html',response);
					}
	}).send();
}
 function cargaCalendario(mes){
	 var c = $('calendario_web');
		new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=calendario',
	        	  	data: { 'mes_actual' : mes },
    	        	onRequest: function() { c.set('html','<div align="center" style="padding-top:90px;"><img src="imagenes/loader.gif" /><div>Cargando</div></div>'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) {
						c.set('html',response);
						toolTips();
					}
	    }).send(); 
 }
 function grupos(acc){
	 var c = $('listado_grupos');
	 if(acc=="agregar"){
		if($('titulo_g').get('value')!="" && $('materia_g').get('value')!=0){
			new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=agenda-acciones',
	        	  	data: { 'titulo' : $('titulo_g').get('value'),'acc':acc+'Grupos','materia': $('materia_g').get('value') },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) {
						c.set('html',response);
						toolTips();
					}
	    	}).send(); 
		}else{
			alert("Faltan datos");	
		}
	 }
 }
 function representado(id){
	new Request({
    	method: 'post',
        url: 'llamada.php?id=agenda-acciones',
	    data: { 'acc':'cambiarEstudiante' , 'representado' : id },
 		onComplete: function(response) {
			id_ = response.replace(/^\s*|\s*$/g,"").split("::");
			// dia,mes,anio
			window.location.href='agenda.php';
			//calendarioAgenda(id_[1]);
			//agenda(id_[1],id_[1],id_[2]);
		}
	 }).send(); 
 }
 function cerrarVentana(id){
 	MUI.closeWindow($(id));
 }
 function calendarioAgenda(mes){
	 var c = $('calendario_agenda');
		new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=agenda-calendario',
	        	  	data: { 'mes_actual' : mes },
    	        	onRequest: function() { c.set('html','<div align="center" style="padding-top:90px;"><img src="imagenes/loader.gif" /><div>Cargando</div></div>'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) {
						c.set('html',response);
						toolTips();
					}
	    }).send(); 
 }
 function agenda(dia,mes,anio){
	 var c = $('resutlado_dia');
		new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=agenda-resultado',
	        	  	data: { 'mes_actual' : mes,'dia_actual':dia,'anio_actual':anio, 'acc':'fecha' },
    	        	onRequest: function() { c.set('html','<div align="center">Cargando</div>'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) {
						c.set('html',response);
						$$('.dias li').each(function(i){
							i.removeClass('actual');							
						});
						$('dia'+dia).addClass('actual');
						toolTips();
						clickea();
						Mediabox.scanPage();
					}
	    }).send();
		if($('tareasRecientes')){
			var d = $('tareasRecientes');
		new Request({
    	    	    method: 'post',
        	    	url: 'llamada.php?id=agenda-acciones',
	        	  	data: { 'acc':'trecientes' },
    	        	onRequest: function() { d.set('html','<div align="center">Cargando tareas nuevas</div>'); },
               		update: d.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) {
						d.set('html',response);
						toolTips();
						clickea();
						Mediabox.scanPage();
					}
	    }).send(); 
		}
 }
 function clickea(){
		
		$$('.click').each(function(i,l){
			i.addEvent('click',function(e){
				MUI.iframeVentana(i.get('rel'),'agenda-tareas',i.get('title'),820,400);
			});
		});
		
 }
 function toolTips(){
	$$('a').each(function(el){
			if(el.get('content')!=null){
				el.tooltip (el.get('content'), { width: 200, style: 'alert', sticky: 0, hook: 1 });
			}
	}); 
 }
