function nwindow(mypage,myname,w,h,scroll,pos)
{
  if (pos=="random")
  {
    LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
    TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
  }
  else if (pos=="center")
  {
    LeftPosition=(screen.width)?(screen.width-w)/2:100;
    TopPosition=(screen.height)?(screen.height-h)/2:100;
  }
  else
  {
    LeftPosition=0;
    TopPosition=20;
  }

  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);

  if(win.focus)
  {
    win.focus();
  }
}

function redimensionar (ancho, alto)
{
  LeftPosition=(screen.width)?(screen.width-ancho)/2:100;
  TopPosition=(screen.height)?(screen.height-alto)/2:100;

  window.moveTo(LeftPosition,TopPosition);
  window.resizeTo(ancho,alto);
  window.focus();
}


function redondear(value, precision)
{
  value = "" + value //convert value to string
  precision = parseInt(precision);

  var whole = "" + Math.round(value * Math.pow(10, precision));
  var decPoint = whole.length - precision;

  if(decPoint != 0)
  {
    result = whole.substring(0, decPoint);
    result += ".";
    result += whole.substring(decPoint, whole.length);
  }
  else
  {
    result = 0;
    result += ".";
    result += whole.substring(decPoint, whole.length);
  }
  return (result);
}


function adjuntar_fichero()
{
  nwindow('adjuntar_fichero.php', 'Fichero', '500', '240', 'no', 'center');
}


function isNumeric (valor)
{
	var valor1 = parseFloat(valor);
	
	if (isNaN(valor1))
	{
        return (false);
    }
	else
	{
		return (true);
	}
}


function adjuntar_imagen()
{
  nwindow('adjuntar_imagen.php', 'Imagen', '500', '380', 'no', 'center');
}


/*function ampliar_foto(url,caption,rel)
{
	var obj = document.createElement('a');
	obj.setAttribute('href',url);
	obj.setAttribute('rel','lightbox');
	obj.setAttribute('title',caption);
	Lightbox.prototype.start(obj);
}*/


function ampliar_imagen(posicion,parametro1,parametro2,pagina,imagen)
{
	if(document.getElementById("amp_img"))
	{
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;
		document.getElementById("amp_img").style.display = "block";
	}
	else
	{
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','amp_img');
		objOverlay.style.display = 'block';
		objOverlay.onclick = function() { cerrar_galeria(); }
		document.getElementsByTagName("body").item(0).appendChild(objOverlay);
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;
	}
	
	if(document.getElementById("amp_img_Container"))
	{
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;
		document.getElementById("amp_img_Container").style.display = "block";
	}
	else
	{
		var objlay = document.createElement("div");
		objlay.setAttribute('id','amp_img_Container');
		objlay.style.display = 'block';
		document.getElementsByTagName("body").item(0).appendChild(objlay);
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;		
	}		
	
	cargar_pagina('ampliacion_galeria.php?j=' + posicion +"&p="+pagina+"&"+ parametro1+"="+parametro2+"&i="+imagen, 'amp_img_Container', imagen);
}

function ampliar_foto(titulo,imagen,tipo)
{
	if(document.getElementById("amp_img"))
	{
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;
		document.getElementById("amp_img").style.display = "block";
	}
	else
	{
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','amp_img');
		objOverlay.style.display = 'block';
		objOverlay.onclick = function() { cerrar_galeria(); }
		document.getElementsByTagName("body").item(0).appendChild(objOverlay);
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;
	}
	
	if(document.getElementById("amp_img_Container"))
	{
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;		
		document.getElementById("amp_img_Container").style.display = "block";
	}
	else
	{
		var objlay = document.createElement("div");
		objlay.setAttribute('id','amp_img_Container');
		objlay.style.display = 'block';
		document.getElementsByTagName("body").item(0).appendChild(objlay);
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;		
	}		
	
	if(tipo == 'noticia') cargar_pagina('ampliacion_foto.php?t='+titulo+"&tipo="+tipo+"&i="+imagen, 'img_noticias', imagen);
	else cargar_pagina('ampliacion_foto.php?t='+titulo+"&tipo="+tipo+"&i="+imagen, 'imgs_txt', imagen);
}


function ampliar_imagen_establecimientos(tipo, id_establecimiento, id_imagen, imagen)
{	
	if(document.getElementById("amp_img"))
	{
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;					
		document.getElementById("amp_img").style.display = "block";
	}
	else
	{
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','amp_img');
		objOverlay.style.display = 'block';
		objOverlay.onclick = function() { cerrar_galeria(); }
		document.getElementsByTagName("body").item(0).appendChild(objOverlay);
		document.getElementById('amp_img').style.position = 'fixed';
		document.getElementById('amp_img').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img').offsetHeight/2;					
	}
	
	if(document.getElementById("amp_img_Container"))
	{
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;					
		document.getElementById("amp_img_Container").style.display = "block";
	}
	else
	{
		var objlay = document.createElement("div");
		objlay.setAttribute('id','amp_img_Container');
		objlay.style.display = 'block';
		document.getElementsByTagName("body").item(0).appendChild(objlay);
		document.getElementById('amp_img_Container').style.position = 'fixed';
		document.getElementById('amp_img_Container').style.top = document.documentElement.clientHeight/2 - document.getElementById('amp_img_Container').offsetHeight/2;							
	}
	
	cargar_pagina_establecimientos('ampliacion_galeria_establecimientos.php?tipo='+tipo+'&id='+id_establecimiento+'&img='+id_imagen, 'amp_img_Container', imagen, tipo);
}


function mover_foto(posicion,parametro1,parametro2,pagina,imagen)
{
	//alert('ampliacion_galeria.php?j=' + posicion +"&p="+pagina+"&"+ parametro1+"="+parametro2 + ' --- amp_img_Container --- ' + imagen);
	cargar_pagina('ampliacion_galeria.php?j=' + posicion +"&p="+pagina+"&"+ parametro1+"="+parametro2+"&i="+imagen, 'amp_img_Container', imagen);
}


function mover_foto_establecimientos(tipo, id_establecimiento, id_imagen, imagen)
{
	cargar_pagina_establecimientos('ampliacion_galeria_establecimientos.php?tipo='+tipo+'&id='+id_establecimiento+'&img='+id_imagen, 'amp_img_Container', imagen, tipo);
}


function cerrar_galeria()
{
	if (document.getElementById("img_Container"))
		document.getElementById("img_Container").src = "";
	document.getElementById("amp_img").innerHTML = "";
	document.getElementById("amp_img").style.display = "none";
	document.getElementById("amp_img_Container").innerHTML = "";
	document.getElementById("amp_img_Container").style.display = "none";
}
