// JavaScript Document

function AddImage(campo)
{
 	fin = window.open('/admin/modulos/imagenes/index.php?action=insertar_imagen&tipo=2&campo='+campo, 'Images', 'width=467, height=450, scrollbars=yes, statusbar=no, resizable=yes');				
	centrarVentana(fin, 467, 450);
	fin.focus();
}

function AddDoc(campo)
{
 	vent = window.open('/admin/modulos/documentos/index.php?action=insertar_documento&tipo=2&campo='+campo, 'Images', 'width=466, height=392, scrollbars=yes, statusbar=no, resizable=yes');				
	centrarVentana(vent, 466, 392);
	vent.focus();
}

function AddEnlace(campo)
{
 	vent = window.open('/admin/modulos/enlaces/index.php?action=insertar_enlace&tipo=2&campo='+campo, 'Images', 'width=466, height=392, scrollbars=yes, statusbar=no, resizable=yes');				
	centrarVentana(vent, 466, 392);
	vent.focus();
}

function openImage(id_foto)
{
	vent = window.open('/admin/modulos/imagenes/index.php?action=getHTMLImagen&id_imagen='+id_foto, 'Images', 'width=466, height=392, scrollbars=yes, statusbar=no, resizable=yes');				
	centrarVentana(vent, 466, 392);
	vent.focus();
}

function centrarVentana(objvent, width, height)
{
	objvent.moveTo((screen.width-width)/2,(screen.height-height)/2);
}

function fieldNumber(objeto, numeroDecimales, e) 
{ 
	var valorCampo; 
	var evento_key = (document.all) ? e.keyCode : e.which; 
	var numPosPunto = 0; 
	var strParteEntera = ""; 
	var strParteDecimal = ""; 
	var NUM_DECIMALES = numeroDecimales; 

	switch (evento_key) 
	{ 
		case 48: 
		case 49: 
		case 50: 
		case 51: 
		case 52: 
		case 53: 
		case 54: 
		case 55: 
		case 56: 
		case 57: 
		break; 
		default: 
			if (((evento_key != 44) || (NUM_DECIMALES == 0)) && (evento_key != 8))
			{
				if (document.all) 
					e.keyCode = 0;
				else 
					e.stopPropagation();
				return false; 
			}
			else if (evento_key == 8) return true;
	} 

	valorCampo = objeto.value; 	
	if (evento_key == 44) 
	{
		if (valorCampo == '')
		{
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		}
		else if (valorCampo.indexOf(",") != -1)
		{ 
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		} 
	}
	/* Sólo puede teclear el número de decimales indicado en NUM_DECIMALES */ 
	if ((numPosPunto = valorCampo.indexOf(",")) != -1) 
	{ 
		strParteEntera = valorCampo.substr(0,(numPosPunto - 1)); 
		strParteDecimal = valorCampo.substr((numPosPunto + 1), valorCampo.length) 
		
		if (strParteDecimal.length > (NUM_DECIMALES - 1)) 
		{ 
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		} 
	} 
	
	return true; 
} 

