

Extranet.SeleccionarMenu = function  (aURL)
{
	if (aURL.length == 1) Main.$ ('idMen-extranet', 'className', 'Activo');
	else Main.$ ('idMen-'+aURL[1] , 'className', 'Activo');
}



Extranet.AnyadirAFavoritos = function (Ident, sPath)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion) { window.location = '/' + sPath + 'extranet/c1/dp-reductores-pendulares-de-dos-trenes-de-engranajes'; }
	Ajax.Vars.Id  = Ident;
	Ajax.Cargar ('/fuentes/anyadirafavoritos.php');
}


Extranet.CantidadFavorito = function (Ident, Linea, Aumentar, iLng)
{
	var Ajax     = new TAjax ();
	var Cantidad = document.PlantillaLineas ['Cantidad' + Linea].value.asInteger ();

	if (Aumentar) Cantidad++; else Cantidad--;
	if (Cantidad < 0) Cantidad = 0;
	Ajax.onCargar = function (oPeticion)
	                {	if (oPeticion.asText () == 'OK') window.location = Extranet.Path (iLng) + '/extranet/misproyectos/' + Ident;
		                else alert ("Error");
	                }
	Ajax.Vars.Lng 	   = iLng;
	Ajax.Vars.Id 		   = Ident;
	Ajax.Vars.Linea    = Linea;
	Ajax.Vars.Cantidad = Cantidad;
	Ajax.Cargar ('/fuentes/cantidadfavorito.php');
}


Extranet.ConvertirAPedido = function (Ident, iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{	var Result = oPeticion.asText ();

										if (Result == 'NOALMACEN')
											alert (Main.Idioma (iLng, 'No se pueden convertir solicitudes de almacenes distintos.',
											               'Il n´est pas permis de faire des commandes d´une autre succursale.',
											               'Requests from different warehouses can not be turned into orders.'));
										else if (Result == 'CONVIRTIENDOSE')
											alert (Main.Idioma (iLng, 'Esa solicitud ya se está convirtiendo a pedido.',
											               'Votre commande est en train de se réaliser.',
											               'That request is turning into order.'));
										else if (Result == 'OK') window.location = Extranet.Path (iLng) + '/extranet/missolicitudes';
									}

	Ajax.Vars.Id  = Ident;
	Ajax.Cargando = 'idConvirtiendo';
	Ajax.Cargar ('/fuentes/convertirapedido.php');
}


Extranet.DescargarArchivoPedidos = function (Ident, Fichero, Tipo, Existe, iLng)
{
	if (! Existe) Extranet.PedirDocumentacion (Ident, Tipo, iLng);
	else window.location = '/fuentes/descargararchivo.php?Fichero=' + Fichero + '&Tipo=' + Tipo;
}


Extranet.EditarFavorito = function (Ident, iLng)
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Plantilla';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 300;
	Ventana.URL    = '/fuentes/generarplantilla.php?Id=' + Ident + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.EliminarOferta = function (Ident, iLng)
{
	var Ajax = new TAjax ();

	if (confirm (Main.Idioma (iLng, '¿Está seguro que quiere eliminar la oferta?',
	                     			      'Are you sure you want to eliminate the offer?',
	                     			      'Vous êtes sûr de vouloir annuler el offres?')))
	{	Ajax.onCargar = function (oPeticion)
	  	              {	if (oPeticion.asText () == 'OK') window.location = Extranet.Path (iLng) + '/extranet/misofertas';
		                  else alert ("No se ha podido eliminar el proyecto.");
	      	          }
		Ajax.Vars.Id   = Ident;
		Ajax.Cargar ('/fuentes/eliminaroferta.php');
	}
}


Extranet.EliminarProyecto = function (Ident, iLng)
{
	var Ajax = new TAjax ();

	if (confirm (Main.Idioma (iLng, '¿Está seguro que quiere eliminar el favorito?',
	                     			      'Are you sure you want to delete the bookmark?',
	                     			      'Etes-vous sûr de vouloir supprimer le signet?')))
	{	Ajax.onCargar = function (oPeticion)
	  	              {	 if (oPeticion.asText () == 'OK') window.location = Extranet.Path (iLng) + '/extranet/misproyectos';
		                   else alert ("No se ha podido eliminar el proyecto.");

	      	          }
		Ajax.Vars.Id   = Ident;
		Ajax.Cargar ('/fuentes/eliminarplantilla.php');
	}
}


Extranet.EliminarSolicitud = function (Ident, iLng)
{
	var Ajax = new TAjax ();

	if (confirm (Main.Idioma (iLng, '¿Está seguro que quiere eliminar la solicitud?',
	                                 'Are you sure you want to eliminate your order?', 'Vous êtes sûr de vouloir annuler la commande?')))
	{	Ajax.onCargar = function (oPeticion)
	  	              {	 if (oPeticion.asText () == 'OK') window.location = Extranet.Path (iLng) + '/extranet/missolicitudes';
		                   else alert ("No se ha podido eliminar la solicitud.");
	      	          }
		Ajax.Vars.Id 	 = Ident;
		Ajax.Vars.Lng  = iLng;
		Ajax.Cargando  = 'Cargando';
		Ajax.Cargar ('/fuentes/eliminarsolicitud.php');
	}
}


Extranet.GuardarAnotaciones = function (Pedido, iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{	if (oPeticion.asText () == 'OK') document.Anotaciones.Cerrar.click ();
										else alert (Main.Idioma (iLng, 'No se ha podido salvar las anotaciones\nPor favor vuelva a intentarlo.',
																				'On n´a pas peut sauver les annotations.\nVeuillez réessayer, s´il vous plait.',
																				'It has not been possible to save any notes.\nPlease, try it again.'));
									}

	Ajax.Vars.Id 	  = Pedido;
	Ajax.Vars.Notas = document.Anotaciones.Notas.value.Trim ();
	Ajax.Cargando   = 'Cargando';
	Ajax.Cargar ('/fuentes/guardarnotas.php');
}


Extranet.GuardarAnotacionesSolicitud = function (Ident, iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{	if (oPeticion.asText () == 'OK') document.Anotaciones.Cerrar.click ();
										else alert (Main.Idioma (iLng, 'No se ha podido salvar las anotaciones\nPor favor vuelva a intentarlo.',
																				'On n´a pas peut sauver les annotations.\nVeuillez réessayer, s´il vous plait.',
																				'It has not been possible to save any notes.\nPlease, try it again.'));
									}
	Ajax.Vars.Id 		= Ident;
	Ajax.Vars.Notas = document.Anotaciones.Notas.value.Trim ();
	Ajax.Cargando 	= 'Cargando';
	Ajax.Cargar ('/fuentes/guardarnotassolicitud.php');
}


Extranet.GuardarObservacionesOferta = function (Oferta)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{	
										window.opener.location = window.opener.location;
										if (oPeticion.asText () == 'OK') document.Observaciones.Cerrar.click ();
										else alert (Main.Idioma (iLng, 'No se ha podido salvar las observaciones\nPor favor vuelva a intentarlo.',
																				'On n´a pas peut sauver les observations.\nVeuillez réessayer, s´il vous plait.',
																				'It has not been possible to save any observations.\nPlease, try it again.'));
									}
	Ajax.Vars.Id 				  	= Oferta;
	Ajax.Vars.Observaciones = document.Observaciones.Observaciones.value.Trim ();
	Ajax.Vars.Estado			  = document.Observaciones.selEstado.value;
	Ajax.Cargando = 'Cargando';
	Ajax.Cargar ('/fuentes/guardarobservaciones.php');
}


Extranet.GuardarPlantilla = function (iLng)
{
	var Ajax = new TAjax ();
  var Descripcion = document.Plantilla.Descripcion.value.Trim ();
  if (! Descripcion) alert ('Debe ingresar una descripción que identifique su favorito.');
	else
	{	Ajax.onCargar 			  = function (oPeticion)
														{ if (oPeticion.asText () == 'OK')
															{	document.Plantilla.Cerrar.click ();
																window.opener.location.reload();

															}	else alert (Main.Idioma (iLng, 'No se ha podido salvar el favorito.\nPor favor vuelva a intentarlo.',
		   																						'No se ha podido salvar el favorito.\nVeuillez réessayer, s´il vous plait.',
				  																				'No se ha podido salvar el favorito.\nPlease, try it again.'));
														};
		Ajax.Vars.IdPlantilla = document.Plantilla.IdPlantilla.value;
		Ajax.Vars.Descripcion = Descripcion;
		Ajax.Cargando = 'Cargando';
		Ajax.Cargar ('/fuentes/guardarplantilla.php');
	}
}


Extranet.InfoArticulo = function (Articulo, Lng)
{
	var Ventana = new TVentana ()
	Ventana.Ancho  = 550;
	Ventana.Alto   = 530;
	Ventana.Nombre = 'InfoArticulo';
	Ventana.URL    = '/fuentes/infoarticulo.php?Id=' + Articulo + '&Lng=' + Lng;
	Ventana.Open (true);
}


Extranet.Login = function (oFormulario, sPath, aURL)
{
	var	Ajax = new TAjax ();

	if (Formulario.Validar (oFormulario))
	{	Ajax.onCargar    = function (oPeticion)
		                   {	if (oPeticion.asText () == 'OK') 
		                   		{	if (aURL [0] == 'extranet') window.location = '/' + sPath + 'extranet/' + aURL [1] + '/' + aURL [2];
		                   			else window.location = '/' + sPath + 'extranet';
		                   	 	}	else
		                   	 		alert (Main.Idioma (Formulario.Lng, "código o clave incorrectos.\nRecuerde que la clave es sensible\na mayúsculas y minúsculas",
		                   	 		                   "Code or password incorrect.\nRemember that the key is sensitive\nto uppercase and lowercase",
		                   	 		                   "Le code ou mot de passe incorrect.\nRappelez-vous que la clé est sensible\nen majuscules et en minuscules"));
		                   } 
		Ajax.Vars.Codigo = oFormulario.Codigo.value.Trim ();
		Ajax.Vars.Clave  = oFormulario.Clave.value.Trim ();
		Ajax.Cargando    = 'idCargando|block';
		Ajax.Cargar ('/fuentes/login.php');
	}
}


Extranet.MisOfertasFiltro = function (iLng)
{
	 if (document.Ofertas.selEstado.value > 0)
	 	window.location = Extranet.Path (iLng) + '/extranet/misofertas/' + document.Ofertas.selEstado.value;
	 else window.location = Extranet.Path (iLng) + '/extranet/misofertas';
}


Extranet.NotasPedido = function (Pedido, iLng)
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Anotaciones';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 500;
	Ventana.URL    = '/fuentes/notaspedido.php?Id=' + Pedido + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.NotasSolicitud = function (Ident, iLng)
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Anotaciones';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 500;
	Ventana.URL    = '/fuentes/notassolicitud.php?Id=' + Ident + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.ObservacionesOferta = function (Ident, iLng)
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Observaciones';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 550;
	Ventana.URL    = '/fuentes/observacionesoferta.php?Id=' + Ident + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.OcultarFotoCategoria = function ()
{
	Main.$ ('idFotoCategoria', 'style.visibility', 'hidden');
}


Extranet.PedirDocumentacion = function (Articulo, Tipo, iLng)
{
	var Ventana  = new TVentana ();
	Ventana.Nombre = 'Oferta';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 500;
	Ventana.URL    = '/fuentes/pedirdocumentacion.php?Articulo=' + Articulo + '&Tipo=' + Tipo + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.PosicionAbsoluta = function (Etiqueta)
{
	var oAux  = Main.$(Etiqueta);
	var iLeft = 0;
	var iTop  = 0;

	if (oAux && oAux.offsetParent)
	{	iLeft = oAux.offsetLeft;
		iTop  = oAux.offsetTop;
		while (oAux = oAux.offsetParent)
		{	iLeft += oAux.offsetLeft;
			iTop  += oAux.offsetTop;
		}
	}
	return [iLeft, iTop];
}


Extranet.ProveedoresOfertaTarifa = function (iFila, iOferta, iArticulo)
{
	oDatos.Fila     = iFila;
	oDatos.Oferta   = iOferta;
	oDatos.Articulo = iArticulo;

	var TD     = Main.$ ('idCodigo-' + iFila);
	var Aux    = document.createElement ('input');
	var Icono  = Main.$ ('idEditar-1');
	var Codigo = Main.$ ('idCodigo-' + iFila).innerHTML;
	var Precio = Main.$ ('idPrecio-' + iFila).innerHTML;
	
	for (var i = 1; Icono; i++)
	{	if (i == iFila)
		{	Main.$ ('idAceptar-' + i, 'style.display', '');
			Icono.style.display = 'none';
		} else Icono.style.visibility = 'hidden';
		Icono = Main.$ ('idEditar-' + (i + 1));
	}
		
	Aux.id        = 'idCodigo';
	Aux.type      = 'text';
	Aux.value     = Codigo.replace ('&nbsp;', '');
	Aux.className = 'InputCodigo';
	Aux.setAttribute ('maxlength', '15');
	if (Aux.addEventListener) Aux.addEventListener ('keydown', function (event) { Extranet.ProvOfertaTarifaCantKeyDown (event); }, false);
	else if (Aux.attachEvent) Aux.attachEvent ('onkeydown',  function () { Extranet.ProvOfertaTarifaCantKeyDown (event); });
	TD.innerHTML  = '';
	TD.appendChild (Aux);

	TD  = Main.$ ('idPrecio-' + iFila);
	Aux = document.createElement ('input');
	Aux.id        = 'idPrecio';
	Aux.type      = 'text';
	Aux.value     = Precio.replace ('&nbsp;', '');
	Aux.className = 'InputPrecio';
	Aux.setAttribute ('maxlength', '10');
	if (Aux.addEventListener) Aux.addEventListener ('keydown', function (event) { Extranet.ProvOfertaTarifaPreKeyDown (event); }, false);
	else if (Aux.attachEvent) Aux.attachEvent ('onkeydown',  function () { Extranet.ProvOfertaTarifaPreKeyDown (event); });
	TD.innerHTML  = '';
	TD.appendChild (Aux);
}


Extranet.ProvOfertasObservaciones = function (iOferta, iLng)
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Observaciones';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 500;
	Ventana.URL    = '/fuentes/proveedoresofertasobservaciones.php?Id=' + iOferta + '&Lng=' + iLng;
	Ventana.Open (true);
}


Extranet.ProvOfertasObservacionesOK = function (iOferta, iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{
										if (oPeticion.asText () == 'OK') document.Oferta.Cerrar.click ();
										else alert (Main.Idioma (iLng, 'No se ha podido salvar las observaciones\nPor favor vuelva a intentarlo.',
																			      	     'Aucun commentaire n\'a été enregistré.\nS\'il vous plaît essayez de nouveau.',
																							     'No comments have been saved.\nPlease, try it again.'));
									}
	Ajax.Vars.Id          = iOferta;
	Ajax.Vars.Observacion = document.Oferta.Observacion.value.Trim ();
	Ajax.Cargando         = 'Cargando';
	Ajax.Cargar ('/fuentes/proveedoresofertasobservacionesok.php');
}


Extranet.ProvOfertaTarifaCantKeyDown = function (oEvent)
{
	if (! oEvent) oEvent = window.event;
	if (oEvent.keyCode == 13) Main.$ ('idPrecio').focus ();
}


Extranet.ProvOfertaTarifaOK = function ()
{
	if (Formulario.MascaraFloat (Main.$ ('idPrecio'), 'precio'))
	{	var Codigo   = Main.$ ('idCodigo').value.Trim ();
		var Precio   = Main.$ ('idPrecio').value.asFloat ();
		var Ajax     = new TAjax ();
	
		Main.$ ('idAceptar-' + oDatos.Fila, 'style.display', 'none');
		Ajax.Vars.Oferta   = oDatos.Oferta;
		Ajax.Vars.Articulo = oDatos.Articulo;
		Ajax.Vars.Codigo   = Codigo;
		Ajax.Vars.Precio   = Precio;
		Ajax.Cargando      = 'idCargando-' + oDatos.Fila;
		Ajax.onCargar      = Extranet.ProvOfertaTarifaOKOn;
		Ajax.Cargar ('/fuentes/ofertatarifaok.php');
	}
}


Extranet.ProvOfertaTarifaOKOn = function (oPeticion)
{
	if (oPeticion.asText () == 'OK')
	{	Main.$ ('idCodigo-' + oDatos.Fila, 'innerHTML', oPeticion.Vars.Codigo);
		Main.$ ('idPrecio-' + oDatos.Fila, 'innerHTML', FlotanteACadena (oPeticion.Vars.Precio, 4));

		Main.$ ('idEditar-' + oDatos.Fila, 'style.display', '');
		var Icono = Main.$ ('idEditar-1');
		for (var i = 2; Icono; i++)
		{	Icono.style.visibility = '';
			Icono = Main.$ ('idEditar-' + i);
		}
	} else alert ('No se ha podido actualizar la tarifa. Por favor vuelva a intentarlo');
}


Extranet.ProvOfertaTarifaPreKeyDown = function (oEvent)
{
	if (! oEvent) oEvent = window.event;
	if (oEvent.keyCode == 13) Extranet.ProvOfertaTarifaOK ();
}


Extranet.TipoBusqueda = function (bDirecta)
{
	if (bDirecta)
	{	Main.$ ('idTecnica', 'style.display', 'none');
		Main.$ ('idDirecta', 'style.display', '');
	} else
	{	Main.$ ('idDirecta', 'style.display', 'none');
		Main.$ ('idTecnica', 'style.display', '');
	}

	Extranet.VaciarFiltros (1, 1);
	Extranet.VaciarFiltros (1, 2);
	Extranet.LimpiarArticulos ();
	Main.$ ('idBusquedaTecnica', 'className', bDirecta ? '' : 'Activo');
	Main.$ ('idBusquedaDirecta', 'className', bDirecta ? 'Activo' : '');
}


Extranet.VerFotoCategoria = function (oEvent, Ident)
{
	var oEvent = TEvento (oEvent);

	var oDiv = Main.$ ('idFotoCategoria');
	if (oDiv && Ident != 13)
	{	if (iXImg < 0)
		{	iXImg = Extranet.PosicionAbsoluta ('idMenuCategoria')[0];
			oDiv.style.left = (iXImg + 150) + 'px';
		}
		oDiv.style.visibility = 'visible';
		oDiv.style.top = oEvent.PosY () + 'px';//document.body.scrollTop + TEvento ()._Evento.clientY - 34;
		Main.$ ('imgFotoCategoria', 'src', '/contenidos/categorias/indice/' + Ident + '.gif');
	}
}


function Extranet ()
{
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


Extranet.DetalleOferta = function (iId, iLng)
{
	window.location = Extranet.Path (iLng) + '/extranet/proveedores-ofertas/' + iId;
}


Extranet.VaciarFiltros = function (Filtro, Tipo)
{
	var oSelect   = Main.$ ('slcFiltro' + Tipo + '-' + Filtro);
	var txtSelect = Main.$ ('txtFiltro' + Tipo + '-' + Filtro);

	while (oSelect)
	{	if (Filtro > 1)
		{	EliminarHijos (oSelect);
			OptionSelect (oSelect, 'null', '-----------------------------------------------------------------');
			oSelect.disabled = true;
			if (txtSelect) txtSelect.style.color = '#ACA899';
		} else oSelect.value = 'null';
		oSelect = document.getElementById ('slcFiltro' + Tipo + '-' + (++Filtro));
		txtSelect = document.getElementById ('txtFiltro' + Tipo + '-' + Filtro);
	}
	Extranet.LimpiarArticulos ();
}


Extranet.CambiarFiltro = function (Component, Tipo, Lng, Cliente, Categoria)
{
	var Filtro  = Component.name.substr (11).asInteger ();
	var oSelect = Main.$ ('slcFiltro' + Tipo + '-' + Filtro);

 	if (oSelect.value != 'null')
	{	Extranet.ActivarFiltro (oSelect.value == 'null' ? Filtro -1 : Filtro, Tipo, Lng, Cliente, Categoria);
		if (oSelect.value != 'null') Filtro++;
	}
	Extranet.VaciarFiltros (Filtro + 1, Tipo);
}


Extranet.ActivarFiltro = function (Filtro, Tipo, Lng, Cliente, Categoria)
{ var	Ajax      = new TAjax ();
	var i         = 0;
	var UltFiltro = document.getElementById ('slcFiltro' + Tipo + '-' +(Filtro + 1)) ? false : true;

	Ajax.onCargar        = Extranet.ActivarFiltroOn;
	Ajax.Filtro          = Filtro + 1;
	Ajax.Categoria       = Categoria;
	Ajax.Tipo            = Tipo;
	Ajax.Lng             = Lng;
	Ajax.Cliente         = Cliente;
	Ajax.Vars.Categoria  = Categoria;
	Ajax.Vars.Pedidos    = true;
	Ajax.Vars.UltFiltro  = UltFiltro;
	Ajax.Vars.Filtros    = Filtro;
	Ajax.Vars.Lng        = Lng;
	Ajax.Vars.Tipo       = Tipo;

	for (i = 1; i <= Filtro; i++)
	{	Ajax.Vars ['cFiltro' + i] = document.Filtros ['Filtro' + Tipo + '-' + i].value;
		Ajax.Vars ['vFiltro' + i] = document.Filtros ['slcFiltro' + Tipo + '-' + i].value;
	}
	if (! UltFiltro) Ajax.Vars ['cFiltro'] = document.Filtros ['Filtro' + Tipo + '-' + (Filtro + 1)].value;
	Ajax.Cargando = 'idCargando' + Tipo + '-' + (Filtro + 1) + '|visible';
	Ajax.Cargar ('/fuentes/filtrocategoria.php');
}

Extranet.ActivarFiltroOn = function (Peticion)
{
	var Datos     = DataSet (Peticion.asText (), 'FILTRO');
	var oSelect   = document.getElementById ('slcFiltro' + Peticion.Tipo + '-' + Peticion.Filtro);
	var txtSelect = document.getElementById ('txtFiltro' + Peticion.Tipo + '-' + Peticion.Filtro);
	var SoloUno   = 0;

	if (oSelect)
	{	EliminarHijos (oSelect);
		Categorias.OpcionSelect (oSelect, 'null');
		if (Datos.RecordCount () == 1) SoloUno = Datos.ByName ('Id');

		while (! Datos.Eof ())
		{	OptionSelect (oSelect, Datos.ByName ('Id'), Datos.ByName ('Valor'));
			Datos.Next ();
		}
		oSelect.disabled = false;
		if (txtSelect) txtSelect.style.color = '#333A42';
	}
	Extranet.CargarArticulosPedidos (Peticion);
	if (SoloUno)
	{	oSelect.focus ();
		oSelect.value = SoloUno;
		Extranet.CambiarFiltro (oSelect, Peticion.Tipo, Peticion.Lng, Peticion.Cliente, Peticion.Categoria);
	}
}


Extranet.CargarArticulosPedidos = function (Peticion)
{
	var Datos      = DataSet (Peticion.asText (), 'ARTICULOS', 'ACCESORIOS');
	var Articulos  = Datos [0];
	var Acc        = Peticion.Categoria == 13;
	var Result     = '';
	var Estilo     = 1;
	var Ident      = 0;
  var txtPedir   		 = Main.Idioma (Lng, 'Pedir', 'Demander', 'Order');
  var txtInformacion = Main.Idioma (Lng, 'Información', '', 'Information');
  var Comprar		     = Peticion.Cliente > 0;

	if (Articulos.RecordCount () > 0)
	{	Result = '<table width="100%" border="0" cellpadding="0"  cellspacing="0" class="TablaNormal" style="text-align:left;">';
		while (! Articulos.Eof ())
		{	Ident = Articulos.ByName ('Id');
			if (Estilo < 0) Result += '<tr>';
			else Result += '<tr style="background:#efefef">';
			if (Acc)
				Result += '<td style="vertical-align:middle; padding-left:10px;" ' + (Articulos.ByName ('Titulo') ? 'title="' + Articulos.ByName ('Titulo') + '"' : '') + '><strong>&nbsp; ' + Articulos.ByName ('Referencia') + '</strong></td>' +
				          '<td style="vertical-align:middle; text-align:right;">' + Articulos.ByName ('Descripcion') + '</td>' +
				          '<td style="vertical-align:middle; text-align:right; padding-right:10px;">' + Articulos.ByName ('Precio2') + '</td>' +
		  		        '<td style="vertical-align:middle; text-align:right;" width="80">' +
		  		        (Articulos.ByName ('ExistePDF') ?
                     '<a href="javascript:Extranet.InfoAccesorio (' + Ident + ');">' +
		  	             '<img src="/imagenes/iconoinfo.gif" title="' + txtInformacion + '" border="0" style="vertical-align:middle"></a>&nbsp;' : '') +
		  	          (Comprar ?
		  	  	         '<input type="text" name="Cantidad' + Ident +  '" id="Cantidad' + Ident + '" maxlength="2" size="2" ' +
  	  	             'style="width: 30px;">&nbsp;' +
          			  	 '<a href="javascript:Pedidos.Pedir (' + Ident + ',' + Lng +');">' +
          			     	'<img src="/imagenes/cestamas.gif" title="' + txtPedir + '" border="0"></a>' : '') + '&nbsp;</td></tr>';
			else
				Result += '<td style="vertical-align:middle; padding-left:10px;" ' + (Articulos.ByName ('Titulo') ? 'title="' + Articulos.ByName ('Titulo') + '"' : '') + '><strong>&nbsp;' + Articulos.ByName ('Ref') + '</strong></td>' +
				          '<td style="vertical-align:middle; text-align:right; padding-right:10px;">' + Articulos.ByName ('Precio2') + '</td>' +
		  		        '<td style="vertical-align:middle; text-align:right;" width="80">' +
		  	  	        '<a href="javascript:Extranet.InfoArticulo (' + Ident + ',' + Lng + ');">' +
		  	    	        '<img src="/imagenes/iconoinfo.gif" title="' + txtInformacion + '" border="0" style="vertical-align:middle"></a>&nbsp;' +
		  	    	    (Comprar ?
		  	      	    '<input type="text" name="Cantidad' + Ident +  '" id="Cantidad' + Ident + '" maxlength="2" size="2" ' +
		  	      	      'style="width: 30px;">&nbsp;' +
          			  	'<a href="javascript:Pedidos.Pedir (' + Ident + ',' + Lng +');">' +
          			     	'<img src="/imagenes/cestamas.gif" title="' + txtPedir + '" border="0"></a>' : '') + '&nbsp;</td></tr>';
			Estilo *= -1;
			Articulos.Next ();
		}
		Result += '</table>';
		Result += Extranet.CargarAccesorios (Datos [1], Comprar);
		Main.$ ('ListaArticulos', 'innerHTML', Result);
	} else if (Peticion.Vars.UltFiltro)
		Main.$ ('ListaArticulos', 'innerHTML', '<div align="center"><br><br><br>' +
		                                Main.Idioma (Lng, 'No se han encontrado referencias.',
		                                                  'No references found.',
		                                                  'Pas de références trouvées') + '</div>');
	else Extranet.LimpiarArticulos ();
}

Extranet.LimpiarArticulos = function ()
{
	Main.$ ('ListaArticulos', 'innerHTML', '<div align="center"><br><br><br>' +
		                                Main.Idioma (Lng, 'Indique las caracter&iacute;sticas de lo que est&aacute; buscando.',
		                                        'Indicate the characteristics of wich you are looking for.',
		                                        'Indiquez les caract&eacute;ristiques de ce que vous cherchez.') + '</div>');
}


Extranet.CargarAccesorios = function (Accesorios, Comprar)
{
	var Estilo   = 1;
	var Ident    = 0;
	var Result   = '';
	var txtPedir 			 = Main.Idioma (Lng, 'Pedir', 'Order', 'Demander');
	var txtAccesorios  = Main.Idioma (Lng, 'Accesorios', 'Accessories', 'Accessoires');
	var txtInformacion = Main.Idioma (Lng, 'Información', '', 'Information');

	if (Accesorios.RecordCount () > 0)
	{	Result += '<div class="lblAccesorios">' + txtAccesorios + '</div>' +
		          '<table width="100%" border="0" cellpadding="0"  cellspacing="0" class="TablaNormal">';
		while (! Accesorios.Eof ())
		{	Ident = Accesorios.ByName ('Id');
			if (Estilo < 0) Result += '<tr>';
			else Result += '<tr style="background:#efefef">';
			Result += '<td style="vertical-align:middle; padding-left:10px; text-align:left;">' + Accesorios.ByName ('Descripcion') + '</td>' +
			          '<td style="text-align:right; vertical-align: middle; padding-right:10px;">' + Accesorios.ByName ('Precio2') + '</td>' +
			  		    '<td style="vertical-align:middle; text-align:right;" width="80">' +
			  		      (Accesorios.ByName ('ExistePDF') ?
                  '<a href="javascript:Extranet.InfoAccesorio (' + Ident + ');">' +
			  	        '<img src="/imagenes/iconoinfo.gif" title="' + txtInformacion + '" border="0" style="vertical-align:middle"></a>&nbsp;' : '') +
			  	        (Comprar ?
			  	  	    '<input type="text" name="Cantidad' + Ident +  '" id="Cantidad' + Ident + '" maxlength="2" size="2" ' +
			  	  	    'style="width: 30px">&nbsp;' +
      			  	  '<a href="javascript:Pedidos.Pedir (' + Ident + ',' + Lng +');">' +
       			       	'<img src="/imagenes/cestamas.gif" title="' + txtPedir + '" border="0"></a>' : '') + '&nbsp;</td></tr>';
			Estilo *= -1;
			Accesorios.Next ();
		}
		Result += '</table>';
	}
	return (Result);
}



Extranet.BuscarTarifa = function (iLng)
{
	alert (iLng);
	var Buscar = Main.$ ('idBuscar').value.Trim ();
	if (Buscar) window.location = Extranet.Path (iLng) + '/extranet/proveedores-buscar/' + Buscar;
}


Extranet.BuscarTarifaKeyDown = function (oEvent)
{
	if (! oEvent) oEvent = window.event;
	if (oEvent.keyCode == 13) Extranet.BuscarTarifa ();
}


Extranet.TarifaProveedor = function (iFila, sCodigo, sUnidades, sPrecio)
{
	var TD  = Main.$ ('idCodigo-' + iFila);
	var Aux = document.createElement ('input');
	var Icono = Main.$ ('idEditar-1');

	for (var i = 1; Icono; i++)
	{	Icono.style.display = 'none';
		if (i == iFila) Main.$ ('idAceptar-' + i, 'style.display', '');
		Icono = Main.$ ('idEditar-' + (i + 1));
	}

	Aux.id           = 'idCodigo';
	Aux.type         = 'text';
	Aux.value        = sCodigo;
	Aux.className    = 'InputCodigo';
	TD.innerHTML = '';
	TD.appendChild (Aux);

	TD  = Main.$ ('idUnidades-' + iFila);
	Aux = document.createElement ('input');
	Aux.id        = 'idUnidades';
	Aux.type      = 'text';
	Aux.value     = sUnidades;
	Aux.className = 'InputUnidades';
	TD.innerHTML  = '';
	TD.appendChild (Aux);

	TD  = Main.$ ('idPrecio-' + iFila);
	Aux = document.createElement ('input');
	Aux.id        = 'idPrecio';
	Aux.type      = 'text';
	Aux.value     = sPrecio;
	Aux.className = 'InputPrecio';
	TD.innerHTML  = '';
	TD.appendChild (Aux);
}



Extranet.AceptarTarifaProveedor = function (iArticulo, iFila)
{
	var Codigo   = Main.$ ('idCodigo').value.Trim ();
	var Unidades = Main.$ ('idUnidades').value.asInteger ();
	var Precio   = Main.$ ('idPrecio').value.asFloat ();
	var Ajax     = new TAjax ();
	var miFecha  = new Date ();

	Ajax.Fila           = iFila;
	Ajax.Vars.Articulo  = iArticulo;
	Ajax.Vars.Codigo    = Codigo;
	Ajax.Vars.Unidades  = Unidades;
	Ajax.Vars.Precio    = Precio;

	Ajax.onCargar 			= Extranet.AceptarTarifaProveedorOn;
	Ajax.Cargar ('/fuentes/actualizartarifa.php');
}


Extranet.AceptarTarifaProveedorOn = function (oPeticion)
{
	if (oPeticion.asText () == 'OK')
	{	Main.$ ('idCodigo-' + oPeticion.Fila,   'innerHTML', oPeticion.Vars.Codigo);
		Main.$ ('idUnidades-' + oPeticion.Fila, 'innerHTML', oPeticion.Vars.Unidades);
		Main.$ ('idPrecio-' + oPeticion.Fila,   'innerHTML', oPeticion.Vars.Precio);

		Main.$ ('idAceptar-' + oPeticion.Fila, 'style.display', 'none');
		var Icono = Main.$ ('idEditar-1');
		for (var i = 1; Icono; i++)
		{	Icono.style.display = '';
			Icono = Main.$ ('idEditar-' + (i + 1));
		}
		location.reload();
	} else alert ('No se ha podido actualizar la tarifa. Por favor vuelva a intentarlo');
}


Extranet.DescargarDocumento = function (Documento, Tipo, Cliente)
{
	window.location = '/fuentes/descargardocumento.php?Fichero=' + Documento + '&Tipo=' + Tipo + '&Cliente=' + Cliente;
}


Extranet.GenerarPlantilla = function ()
{
	var Ventana = new TVentana ();

	Anotaciones    = Ventana;
	Ventana.Nombre = 'Plantilla';
	Ventana.Ancho  = 520;
	Ventana.Alto   = 300;
	Ventana.URL    = '/fuentes/generarplantilla.php?Lng=' + Lng;
	Ventana.Open (true);
}


Extranet.GenerarPedido = function (Plantilla, iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar = function (oPeticion)
									{ var Resultado = oPeticion.asText ();
										if (Resultado == 'OK') window.location = Extranet.Path (iLng) + '/extranet/c1/dp-reductores-pendulares-de-dos-trenes-de-engranajes';
										else alert (Main.Idioma (iLng, "El pedido no ha podido ser actualizado.", 'The request could not be updated',
																						 "La requête n'a pas pu être mis à jour"));
									}
	Ajax.Vars.Lng 			=	iLng;
	Ajax.Vars.Plantilla = Plantilla;
	Ajax.Formulario (document.PlantillaLineas);
	Ajax.Cargando = 'MsgPedido';
	Ajax.Cargar ('/fuentes/generarpedido.php');
}


Extranet.MiClave = function (iLng)
{
	var Ventana = new TVentana ();

	Ventana.Ancho      = 500;
	Ventana.Alto       = 340;
	Ventana.scrollbars = false;
	Ventana.URL        = '/fuentes/miclave.php?Lng=' + iLng;
	Ventana.Open (true);
}



Extranet.CambiarClave = function (iLng)
{
	if (document.Clave.clvActual.value.Trim () == '')
	{	alert (Main.Idioma (iLng, 'Tiene que indicar la clave actual.',
									 'Please, enter your password.', 'Vous devez indiquer la clef actuelle.'));
		document.Clave.clvActual.focus ();
	} else if (document.Clave.clvNueva.value.Trim () == '')
	{	alert (Main.Idioma (ilng, 'Tiene que indicar la clave nueva.',
									 'Please, enter your new password', 'Vous devez indiquer la clef nouvelle.'));
		document.Clave.clvNueva.focus ();
	} else if (document.Clave.clvConfirmar.value.Trim () == '')
	{	alert (Main.Idioma (iLng, 'Tiene que confirmar la clave.',
									 'Password must be confirmed.', 'Il faut confirmer le code d´accés.'));
		document.Clave.clvConfirmar.focus ();
	} else if (document.Clave.clvNueva.value.Trim ().length < 6)
	{	alert (Main.Idioma (iLng, 'La clave nueva tiene que conterner 6 caracteres como mínimo.',
									 			 'The new password must contain 6 characters like minimum.', 'La nouvelle clef d´accés doit avoir 6 caractères comme minimum.'));
		document.Clave.clvNueva.focus ();
	} else if (document.Clave.clvNueva.value != document.Clave.clvConfirmar.value)
	{	alert (Main.Idioma (iLng, 'La clave nueva y su confirmación son distintas.',
									 			 'The new password and its confirmation are different.', 'Le nouveau code et sa confirmation sont différentes.'));
		document.Clave.clvNueva.focus ();
	} else Extranet.DoCambiarClave (iLng);
}


Extranet.DoCambiarClave = function (iLng)
{
	var Ajax = new TAjax ();

	Ajax.onCargar          = Extranet.DoCambiarClaveOn;
	Ajax.Lng							 = iLng;
	Ajax.Vars.clvActual    = document.Clave.clvActual.value.Trim ();
	Ajax.Vars.clvNueva     = document.Clave.clvNueva.value.Trim ();
	Ajax.Vars.clvConfirmar = document.Clave.clvConfirmar.value.Trim ();
	Ajax.Cargando = 'Cargando';
	Ajax.Cargar ('/fuentes/cambiarclave.php');
}


Extranet.DoCambiarClaveOn = function (Peticion)
{
	if (Peticion.asText () == 'OK')
	{ Main.$ ('idFormulario', 'style.display', 'none');
		Main.$ ('idNota', 'style.display', 'none');
		Main.$ ('idOK', 'style.display', 'block');
	}	else if (Peticion.asText () == 'ERROR') alert (Main.Idioma(Peticion.Lng, 'La clave actual no es correcta.',
																																				'The present password is not correct.', 'La clef actuelle n´est pas correcte'));
	else alert (Main.Idioma (Peticion.Lng, 'No se ha podido cambiar la clave.',
											'It has not been possible to change the password', 'On n´a pas peut changer le code d´accés.'));
}



Extranet.InfoArticuloEmail = function (oFormulario, iLng)
{
	if (Formulario.Validar (oFormulario))
	{	var Ajax = new TAjax ();
		Ajax.onCargar = function (oPeticion) { alert ('Información enviada.'); }
		Ajax.Formulario (oFormulario)
		Ajax.Lng  = iLng;
		Ajax.Cargar ('/fuentes/infoarticuloemail.php');

	}
}


Extranet.InfoAccesorio  = function (Accesorio)
{
	window.location = '/fuentes/descargaraccesorio.php?Id=' + Accesorio;
}


Extranet.Portes = function ()
{
	var Desactivar = document.DatosDeEnvio.Portes1.value != 99;
	document.DatosDeEnvio.Portes2.disabled = Desactivar;
	if (Desactivar) document.DatosDeEnvio.Portes2.value = '';

}


Extranet.Path = function (iLng)
{
	switch (iLng)
	{	case 1: return '/es';
		case 2: return '/en';
		case 3: return '/fr';
		default: return '/es';
	}
}


Extranet.SinFamilia = function (iLng)
{	
	alert (Main.Idioma (iLng, 
	'Usted no tiene asignada esta familia de productos.\nSi desea presupuestarla, póngase en contacto con nuestro departamento de compras.',
	'You do not have assigned this family of products.\nIf you want to budget, please contact our purchasing department.',
	"Vous n'avez pas attribué cette famille de produits.\nSi vous souhaitez pour le budget, s'il vous plaît communiquer avec notre service des achats."));
}


