activo = 0;

function IWcambiar_fecha(mes,ano,e,valor){
	new Ajax.Updater('IWcalendar','IWcalendar/_calendar.php?id='+e+'&value='+valor+'&mes='+mes+'&ano='+ano);	
	
}

function IWcalendar_show(e){
	el = $(e);
	var positions = IWposition(el);
	
	capa = $('IWcalendar');
	
	valor = el.value;
	
	positions[1] = positions[1]+23;
	
	capa.style.left = positions[0]+"px";
	capa.style.top = positions[1]+"px";
	
	new Ajax.Updater('IWcalendar','IWcalendar/_calendar.php?id='+e+'&value='+valor, {
					 
					 onComplete: function(){
						 
						 capa.style.display = "block";
						 						 
					 }
					 
					 });	
}

function IWcalendar_hide(){
	
	if(activo==0){
		capa = $('IWcalendar');
		capa.style.display = "none";
	}
}

function active(){

	activo = 1;
	
}

function desactive(){

	activo = 0;
	
}

function IWselect(e,valor){
	
	$(e).value = valor;
	desactive()
	IWcalendar_hide();
	
}

function IWchange(e){
	
	el = $(e);
	var positions = IWposition(el);
	
	capa = $('IWcalendar');
	
	positions[1] = positions[1]+23;
	
	capa.style.left = positions[0]+"px";
	capa.style.top = positions[1]+"px";
}

function IWposition(el)
{
	var curLeft = 0;
	var curTop = 0;
	var corrections = IWcorrection(el);

	if (el.offsetParent)
	{
		do {
			curLeft += el.offsetLeft;
			curTop += el.offsetTop;
		} while (el = el.offsetParent);
		
			desplazamiento_y=document.body.scrollTop;
			desplazamiento_x=document.body.scrollLeft;
			curLeft = curLeft+desplazamiento_x;
			curTop = curTop + desplazamiento_y;
		
		return [ (curLeft - corrections[0]), (curTop - corrections[1]) ];
	}
}


function IWcorrection(el)
{
	var curX = 0;
	var curY = 0;
	do {
		curX += el.scrollLeft;
		curY += el.scrollTop;
		if (el.nodeName == 'BODY')
			break;
	} while (el = el.parentNode);
	return [curX, curY];
}
