// baldrick.js - funciones comunes, v. 2009-03-05

function go2(url,msg)
{
	if(msg==undefined || msg=='')
	{
		window.location.href=url;
	}
	else
	{
		if(confirm(msg))
		{
			window.location.href=url;
		}
	}
}

function ajaxGet(target,url)
{
	new Ajax.Updater(
			target,
			url,
			{
				method: 'get'
				// onSuccess: function(t) { Element.show(target); }
			}
		)
}

function ajaxCarga(target,url)
{
	new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: { iesux: new Date().getTime() },
				/* onCreate: function() { Element.update(target,'<img src="images/loading.gif" alt="Cargando..." />'); }, */
				onCreate: function() { new Effect.Shake(target) },
				onSuccess: function(t) { Element.setOpacity(target,0.01); Element.update(target,t.responseText); new Effect.Appear(target); },
				onFailure: function() { Element.update(target,''); }
			}
		)
}

function ver(e)
{
	if(!Element.visible(e)) new Effect.Appear(e,{duration:0.5, queue: {position: 'front', scope: 'qfade'} });
}

function verS(e)
{
	if(!Element.visible(e)) new Effect.BlindDown(e,{duration:0.5, queue: {position: 'front', scope: 'qslide'} });
}

function ocul(e)
{
	if(Element.visible(e)) new Effect.Fade(e,{duration:0.25, queue: {position: 'front', scope: 'qfade'} });
}

function oculS(e)
{
	if(Element.visible(e)) new Effect.BlindUp(e,{duration: 0.5, queue: {position: 'end', scope: 'qslide', limit: 1} });
}

function verTog(e,ef)
{
	if(ef == undefined) ef = 'appear';
	new Effect.toggle(e,ef);
}

function dAlert(msg)
{
	// Dialog.alert(msg);
	return alert(msg);
}

function dConfirm(msg,ops)
{
	// Dialog.confirm(msg,ops);
	return confirm(msg,ops);
}

function elemRotar(cl,t)
// rota todo dentro de una clase
{
	if(t == undefined) t = 5;
	var ea = $$('.' + cl);
	ea.invoke('hide');
	ea.first().show();

	new PeriodicalExecuter(function(per) { elemRota(ea); }, t);
}

function elemRota(ea)
{
	var e = ea.shift();
	new Effect.Fade(e, {duration: 0.5, afterFinish: function(){
		new Effect.Appear(ea.first(), {duration: 0.5}); } });
	ea.push(e);
}

// ejecutar ahora

Ajax.Responders.register({
  onCreate: function() {
	$('loading').show();
  },
  onComplete: function() {
	$('loading').hide();
  }
});
