/*
AUTOR: Eduardo Alemany Vicens
FECHA: 07/06/2004

Funciones javascript de utilidad.
*/

var fotoGaleria = '';
var nombreFotoGaleria = '';
//--------------------------------------------------------------------------------------------------
function ampliaFoto(url){
	abrirVentana(url+"?foto="+fotoGaleria,'ampliaFoto','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',550,413,'center','ignoreLink','',0,'');
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function galeria(img,img_med,img_small,iconos){
	fotoGaleria = img;
	//definimos imagenes
	image_med = new Image();
	image_small = new Image();
	//definimos las rutas
	image_med.src = img_med;
	image_small.src = img_small;
	loader(img_med, img_small,iconos);
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function loader(img, img_small,iconos){
	flagx=false;
	var tiempo = "";
	var imagen_aux = "";

	if (image_med.complete){flagx=true;}
	if (flagx) {
		clearTimeout(tiempo);
		//redimensionamos
		var altura,anchura;
		altura = image_med.height; anchura = image_med.width;
		while (altura > 200) {
			altura = Math.ceil(altura / 1.1);
			anchura = Math.ceil(anchura / 1.1);
		}
		while (anchura > 200) {
			anchura = Math.ceil(anchura / 1.1);
			altura = Math.ceil(altura / 1.1);
		}
		document.images['large'].height=altura;
		document.images['large'].width=anchura;
		document.images['large'].src=image_med.src;
	} else {
	imagen_aux = new Image();
	imagen_aux.src = iconos+"/loading.gif";
	document.images['large'].height=imagen_aux.height;
	document.images['large'].width=imagen_aux.width;
	document.images['large'].src = imagen_aux.src;
	tiempo=setTimeout("loader('"+img+"', '"+img_small+"')",1000);
	}
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function checkSizeImage (obj,ruta,cond_ancho,cond_alto) {
	source = new Image();
	source.src = ruta;
	
	ancho = source.width; alto = source.height; 
	while (ancho > cond_ancho) {
		ancho = Math.ceil(ancho / 1.1);
		alto = Math.ceil(alto / 1.1);
	}
	while (alto > cond_alto) {
		ancho = Math.ceil(ancho / 1.1);
		alto = Math.ceil(alto / 1.1);
	}
	obj.width = ancho;
	obj.height = alto;
	obj.src = source.src;
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function resizeImage (obj,source,ancho,alto) {
	var unidad_h = 1;
	var unidad_w = 1;
	source = new Image();
	source.src = source;
	
	if (alto > 100) {alto=00; unidad_h=2;} if (alto < 0) alto=0;
	if (ancho > 100) {ancho=00; unidad_w=2; } if (ancho < 0) ancho=0;
	obj.height = Math.ceil(source.height / unidad_h.alto);
	obj.width = Math.ceil(source.width / unidad_w.ancho);
	obj.src = source.src;
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function clearText(thefield){
	if (thefield.defaultValue==thefield.value) {
		thefield.value = "";
	}
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function resetText(thefield){
	if(thefield.value==""){
		thefield.value=thefield.defaultValue;
	}
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function redimensiona () {
	var h=document.foto.height+50; 
	var w=document.foto.width+30; 
	self.resizeTo(w,h); 
}
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function abrirVentana(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}//FIN funcion
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function abrirDialogo(url)  {
	abrirVentana(url,'DIALOGO','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no',417,250,'center','ignoreLink','',0,''); 
}//FIN funcion abrirDialogo
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
function lanzarPaginaPost(formulario,pagina) {
	document.datos.page.value=pagina;
        document.datos.submit();
}//FIN funcion lanzarPaginaPost 
//--------------------------------------------------------------------------------------------------