﻿
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function cambiar(capa, propiedad, maximo, minimo, sufijo, retardo, constante) {
	var div = document.getElementById(capa);
	var actual = parseInt(div.style[propiedad]);
	if (typeof(div.ascender) == 'undefined')
	{
		div.ascender = {};
	}
	if ((actual == maximo) || div.ascender[propiedad] == false)
	{ 
		div.ascender[propiedad] = true;
		interpolar(capa, propiedad, minimo, sufijo, retardo, constante);
	}
	else if ((actual == minimo) || div.ascender[propiedad] == true)
	{
		div.ascender[propiedad] = false;
		interpolar(capa, propiedad, maximo, sufijo, retardo, constante);
	}
}

function interpolar(capa, propiedad, valor, sufijo, retardo, constante) { 
	var div = document.getElementById(capa);
	var actual = parseFloat(div.style[propiedad]);
	if (typeof(div.actual) == 'undefined')
	{
		div.actual = {};
	}
	if (typeof(div.valor) == 'undefined')
	{
		div.valor = {};
	}
	if (typeof(div.constante) == 'undefined')
	{
		div.constante = {};
	}
	div.actual[propiedad] = actual;
	div.valor[propiedad] = valor;
	div.constante[propiedad] = (constante) ? ((valor - actual) / retardo) : 0;
	if (typeof(div.intervalo) == 'undefined')
	{
		div.intervalo = {};
	}
	if (typeof(div.intervalo[propiedad]) != 'undefined' && div.intervalo[propiedad] != null)
	{
		clearInterval(div.intervalo[propiedad]);
		div.intervalo[propiedad] = null;
	}
	div.intervalo[propiedad] = setInterval('interpolando("'+capa+'", "'+propiedad+'", "'+sufijo+'", '+retardo+')', retardo);
}

function interpolando(capa, propiedad, sufijo, retardo) {
	var div = document.getElementById(capa);
	if(div.actual[propiedad] != div.valor[propiedad]) {  
		var incremento = (div.constante[propiedad] == 0) ? ((div.valor[propiedad] - div.actual[propiedad]) / retardo) : div.constante[propiedad];
		div.style[propiedad] = (div.actual[propiedad] + incremento) + sufijo;
		div.actual[propiedad] += incremento;
		incremento = (div.constante[propiedad] == 0) ? ((div.valor[propiedad] - div.actual[propiedad]) / retardo) : div.constante[propiedad];
		if (Math.abs(div.valor[propiedad] - div.actual[propiedad]) < Math.abs(incremento))
		{
			div.style[propiedad] = div.valor[propiedad] + sufijo;
			div.actual[propiedad] = div.valor[propiedad];
		}
	}
	else
	{
		clearInterval(div.intervalo[propiedad]);
	}
}

function cambios() { 
	if(document.getElementById('accion').value != 'alta' || document.getElementById('accion').value != 'borrar') 
	{
	document.getElementById('cambios_param').value = 1;
	}
}

function confirma_cambios() {
	if(!(document.getElementById('accion').value == 'alta' || document.getElementById('accion').value == 'borrar')) 
	{
		if(document.getElementById('cambios_param').value == 1) { 
			if(confirm('¿Desea guardar los cambios efectuados?')) { 
				document.getElementById('gestion').submit();
				parent.MOOdalBox.close();
			}
			else {
				parent.MOOdalBox.close();
			}
		}
		parent.MOOdalBox.close(); 
	}
	else 
	{ 
		parent.MOOdalBox.close(); 
	}
}

function confirma_borrar(id, nombre_foto) {
	if(confirm('¿Desea borrar '+nombre_foto.substr(33)+'?')) { 
		cambios();  
		if(document.getElementById('cambios_fotos').value=='') {
			document.getElementById('cambios_fotos').value = nombre_foto;
		}
		else {
			document.getElementById('cambios_fotos').value = document.getElementById('cambios_fotos').value+';'+nombre_foto;
		}
		document.getElementById('img_'+id).style.display = 'none';
	} 
}
