// JavaScript Document

/********************************************************
* makes a popup of determinate picture
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function PopUp(img, toWidth, toHeight){
	foto1= new Image();
	foto1.src=(img);
	Control(img, toWidth, toHeight);
}

/********************************************************
* resize popup creation of determinate picture
*
* @param ancho (required width)
* @param alto (required height)
*
********************************************************/
function redimensionar(ancho, alto){
ventana.resizeTo(ancho+5,alto+30)
ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2) //centra la ventana. Eliminar si no se quiere centrar el popup
}

/********************************************************
* control popup creation of determinate picture
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function Control(img, toWidth, toHeight){
	if((foto1.width!=0)&&(foto1.height!=0)){  
		verFoto(img, toWidth, toHeight);
	} else {funcion="Control('"+img+"')";  
		intervalo=setTimeout(funcion,20);
	}
}

/********************************************************
* open a popup of determinate picture on new window
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function verFoto(img, toWidth, toHeight){  
	ancho=foto1.width; 
	alto=foto1.height;
	ratio = ancho/alto;
	if (ratio > 1 ){ 
		reducc = ancho/toWidth;
		ancho = toWidth;
		alto = alto * 1/reducc;
	} else {
		reducc = alto/toHeight;
		alto = toHeight;
		ancho = ancho * 1/reducc;
	}
	height = alto+20;
	width = ancho+20;
	cadena="width="+width+",height="+height+",resizable=no, centered=yes";
	ventana=window.open(img,"",cadena);
	ventana.document.write('<html><head><title>Show Image</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" ><div align="center"><a href="javascript:this.close()"><img src="' + img + '" onLoad="opener.redimensionar(this.width, this.height)" style="border:none"></a></div>')
}

/********************************************************
* resize an IMG object
*
* @param slider (IMG object)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function preload(slider, toWidth, toHeight){
	image1 = new Image();
	image1.src = slider.src;
	width = image1.width;
	height = image1.height;
	ratio = width/height;
	if (width != 0 && height != 0){
		if (ratio >= 1){
			reducc = width/toWidth;
			width = toWidth;
			height = height * 1/reducc;
		} else {
			reducc = height/toHeight;
			height = toHeight;
			width = width * 1/reducc;
		}
	} else {
		height = toHeight;
		width = toHeight;
	}
	slider.setAttribute("width",width);
	slider.setAttribute("height",height);
}

/********************************************************
* confirm delete
*
* @param act (delete url action)
*
********************************************************/
function confdel(act){
	if(confirm("Are you sure to delete this item?")){
		document.forms[0].action = act;
		return true;
	} else {
		return false;
	}
}

/********************************************************
* send resort list values
*
* @param field (send field to sort list)
*
********************************************************/
function reSort(field){
	if (document.forms[0].orderDir.value == "DESC"){
		document.forms[0].orderDir.value = "ASC";
	} else {
		document.forms[0].orderDir.value = "DESC";
	}
	document.forms[0].orderField.value = field;
	document.forms[0].submit();
}


