
function ActivarDireccionEnvio ()
{
	var Desactivado = ! document.DatosDeEnvio.DireccionDeEnvio.checked;
	
	document.DatosDeEnvio.EnvioNombre.disabled       = Desactivado;
	document.DatosDeEnvio.EnvioDireccion.disabled    = Desactivado;
	document.DatosDeEnvio.EnvioDireccion2.disabled   = Desactivado;
	document.DatosDeEnvio.EnvioPais.disabled         = Desactivado;
	document.DatosDeEnvio.EnvioCodigoPostal.disabled = Desactivado;
	document.DatosDeEnvio.EnvioMunicipio.disabled    = Desactivado;
	document.DatosDeEnvio.EnvioProvincia.disabled    = Desactivado;
	document.DatosDeEnvio.EnvioTelefono.disabled     = Desactivado;
}


function AvisoLegal ()
{
	var Ventana = new TVentana ();

	Ventana.Ancho       = 550;
	Ventana.Alto        = 400;
	Ventana.Nombre      = 'AvisoLegal';
	Ventana.URL         = '/fuentes/avisolegal.php';
	Ventana.Open (true);
}


function Buscar (iOpc)
{
	var Buscar = document.Buscar.Buscar.value.Trim ();
	
	if (Buscar)
	{	LimpiarParametros ();
		Par4 = Buscar;
		Main (iOpc);
	}
}


function CambiarIdioma (iLng)
{
	Lng = iLng;

	CargarPagina ();
}


function CantidadCesta (sItem, iCantidad)
{
	var	Ajax = new TAjax ();

	Ajax.onCargar = CantidadCestaOn;
	Ajax.Vars ('Item',     sItem);
	Ajax.Vars ('Cantidad', iCantidad);
	Ajax.Cargar ('/fuentes/actualizarpedido.php', 'Cargando');
}


function CantidadCestaOn (Peticion)
{
	var Datos = DataSet (Peticion.asText (), 'STOCK', 'CESTA');

	if (Datos [0].RecordCount ())
	{	if (Datos [0].asInteger ('Items') == 0) Main (0);
		else if (Datos [0].asInteger ('Unidades') > 0)
			alert (Idioma (2) + ' ' + Stock.ByName ('Unidades') + ' ' + Idioma (3));
		else alert (Idioma (4));
	} else
	{ InHTML ('idCesta', Datos [1].ByName ('HTML'));
		InHTML ('idTotalCesta', Datos [1].ByName ('TotalCesta'));
	}
}


function CargarFormasDeEnvio ()
{
	var Ajax  = new TAjax ();

	Ajax.onCargar = CargarFormasDeEnvioOn;
	Ajax.Vars ('Lng', + Lng);
	Ajax.Cargar ('/fuentes/formasdeenvio.php', 'idCargando');
}


function CargarFormasDeEnvioOn (Peticion)
{
	var Formas = $('idFormasDeEnvio');
	var Nodo;
	
	FormasDeEnvio = DataSet (Peticion.asText (), 'FORMASDEENVIO');
	OptionSelect (Formas, 0, '');
	while (! FormasDeEnvio.Eof ())
	{	OptionSelect (Formas, FormasDeEnvio.asInteger ('Id'), FormasDeEnvio.ByName ('Descripcion'));
		FormasDeEnvio.Next ();
	}
}


function CargarFormasDePago ()
{
	var Ajax         = new TAjax ();
	var FormaDeEnvio = document.FormasDePago.FormaDeEnvio.value.asInteger ();
	var Pagos        = document.getElementById ('idFormasDePago');

	EliminarHijos (Pagos);
	InHTML ('idAnotacion', '&nbsp;');
	GastosDeEnvio (TotalCesta, 0, 0);
	
	if (FormaDeEnvio)
	{	FormasDeEnvio.Locate ('Id', FormaDeEnvio);
		if (FormasDeEnvio.asBoolean ('Limite'))
		{	alert (Idioma (23));
			document.FormasDePago.FormaDeEnvio.value = 0;
		} else
		{	GastosDeEnvio (FormasDeEnvio.asFloat ('Total'), FormasDeEnvio.asFloat ('Gastos'), 
			               FormasDeEnvio.asFloat ('Descuento'));
			Ajax.onCargar = CargarFormasDePagoOn;
			Ajax.Vars ('FormaDeEnvio', FormaDeEnvio);
			Ajax.Vars ('Lng', Lng);
			Ajax.Cargar ('/fuentes/formasdepago.php');
		}
	}
}


function CargarFormasDePagoOn (Peticion)
{
	var Pagos    = document.getElementById ('idFormasDePago');
	FormasDePago = DataSet (Peticion.asText (), 'FORMASDEPAGO');

	OptionSelect (Pagos, 0, '');
	while (! FormasDePago.Eof ())
	{	OptionSelect (Pagos, FormasDePago.asInteger ('Id'), FormasDePago.ByName ('Descripcion'));
		FormasDePago.Next ();
	}
}


function CargarPagina ()
{
	var Pars = '?Opc=' + Opc + '&Lng=' + Lng;

	if (Par1) Pars += '&Par1=' + Par1;
	if (Par2) Pars += '&Par2=' + Par2;
	if (Par3) Pars += '&Par3=' + Par3;
	if (Par4) Pars += '&Par4=' + Par4;
	window.location = '/index.php' + Pars;
}


function ColorDetalle (iIdColor, bDesdeColores)
{
	var Ventana = new TWindow ();
	
	Ventana.Titulo = Idioma (21);
	
	Ventana.Vars ('Lng', Lng);
	Ventana.Vars ('Id', iIdColor);
	Ventana.Vars ('DesdeColores', bDesdeColores);
	Ventana.Cargar ('/fuentes/color.php');
}


function Colores (iId)
{
	var Ventana = new TWindow ();
	
	Ventana.Titulo = ' ';

	Ventana.Vars ('Lng', Lng);
	Ventana.Vars ('Id', iId);
	Ventana.Cargar ('/fuentes/colores.php');
}


function ColorSeleccionar (iColor)
{
	document.imgColor.src        = "/contenidos/colores/" + iColor + '-2.jpg';
	document.Comprar.Color.value = iColor;
	TWindow.Cerrar ();
}


function Comprar (iArticulo, iOpcion)
{

	var	Ajax     = new TAjax ();
	var Cantidad = 1;
	var Color    = '-1';
	var Talla    = '-1';

	if (document.Comprar)
	{	Cantidad = document.Comprar.Cantidad.value.asInteger ();
		Color    = document.Comprar.Color.value.asInteger ();
		Talla    = document.Comprar.Talla.value.split ('|')[0];
	}

	if (! Color) alert (Idioma (23));
	else if (! Talla) alert (Idioma (22));
	else if (Cantidad <= 0) alert (Idioma (1));
	else
	{	Ajax.onCargar = ComprarOn;
		Ajax.Opcion   = iOpcion;
		Ajax.Vars ('Id', iArticulo);
		Ajax.Vars ('Cantidad', Cantidad);
		Ajax.Vars ('Color', Color);
		Ajax.Vars ('Talla', Talla);
		Ajax.Cargar ('/fuentes/comprar.php');
	}
}


function ComprarOn (Peticion)
{
	var Stock = DataSet (Peticion.asText (), 'STOCK');

	if (Stock.RecordCount ())
	{	if (Stock.asInteger ('Unidades') > 0)
			alert (Idioma (2) + ' ' + Stock.ByName ('Unidades') + ' ' + Idioma (3));
		else alert (Idioma (4));
	} else Main (Peticion.Opcion);
}


function ConfirmarClave (oFormulario)
{
	var Clave   = oFormulario.Clave.value.Trim ();
	var Repetir = oFormulario.Repetir.value.Trim ();

	if (Clave != Repetir)
	{	alert (Idioma (9));
		oFormulario.Clave.focus ();
		return false;
	}
	return true;
}


function DesconectarCliente ()
{
	var	Ajax = new TAjax ();

	Ajax.onCargar = CargarPagina;	
	Ajax.Cargar ('/fuentes/desconectar.php');
}

function EnviarFormMayoristas (Formulario)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (Formulario))
	{	Ajax.onCargar = EnviarFormOn;
		Ajax.Formulario (Formulario);
		Ajax.Cargar ('/fuentes/enviarmayoristas.php');
	}
}

function EnviarFormOn (Peticion)
{
	Display ('idFormulario', 'none');
	Display ('idEnvioOK', 'block');
}


function FinalizarPedido (iFin, iPago)
{
	var	Ajax         = new TAjax ();
	var FormaDeEnvio = document.FormasDePago.FormaDeEnvio.value.asInteger ();
	var FormaDePago  = document.FormasDePago.FormaDePago.value.asInteger ();

	if (FormaDeEnvio)
	{	if (FormaDePago)
		{	Ajax.Fin  = iFin;
			Ajax.Pago = iPago;
			Ajax.Vars ('FormaDeEnvio', FormaDeEnvio);
			Ajax.Vars ('FormaDePago',  FormaDePago);
			Ajax.Vars ('Gastos',       document.FormasDePago.Gastos.value.asFloat ());
			Ajax.Vars ('Descuento',    document.FormasDePago.Descuento.value.asFloat ());
			Ajax.Vars ('Total',        document.FormasDePago.Total.value.asFloat ());
			Ajax.onCargar = FinalizarPedidoOn;
			Ajax.Cargar ('/fuentes/finalizarpedido.php', 'Cargando');
		} else alert (Idioma (18));
	} else alert (Idioma (19));
}


function FinalizarPedidoOn (Peticion)
{
	var Result = Peticion.asText ();
	
	if (Result == 'OK') Opc = Peticion.Fin;
	else if (Result == 'PAGOELECTRONICO') Opc = Peticion.Pago;
	else alert (Idioma (20));
	CargarPagina ();
}


function FormasDePago (oFormulario, iOpcion)
{
	var	Ajax = new TAjax ();

	if (! oFormulario.DireccionDeEnvio.checked || ValidarFormulario (oFormulario))
	{	Ajax.onCargar = FormasDePagoOn;
		Ajax.Formulario (oFormulario);
		Ajax.Opcion = iOpcion;
		Ajax.Cargar ('/fuentes/hayformasdepago.php', 'idCargando');
	}
}


function FormasDePagoOn (Peticion)
{
	var Result = Peticion.asText ();

	if (Result == 'NOPAGO') alert (Idioma (17));
	else if (Result == 'OK') Main (Peticion.Opcion);
}


function FlashPlano ()
{
	document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
	document.write ('codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"');
	document.write ('width="390" height="200" id="plano" align="middle">');
	document.write ('<param name="allowScriptAccess" value="sameDomain" />');
	document.write ('<param name="movie" value="/swf/plano.swf" />');
	document.write ('<param name="quality" value="high" />');
	document.write ('<param name="bgcolor" value="#ffffff" />');
	document.write ('<embed src="/swf/plano.swf" quality="high" bgcolor="#ffffff" width="390" height="200"');
	document.write ('name="plano" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"');
	document.write ('pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write ('</object>');
}


function GastosDeEnvio (fTotal, fGastos, fDescuento)
{
	InHTML ('idTotalAPagar', FlotanteACadena (fTotal, 2));
	InHTML ('idGastosDeEnvio', FlotanteACadena (fGastos, 2));
	InHTML ('idDtoGastos', '-' + FlotanteACadena (fDescuento, 2));
	Display ('idDivDtoGastos', fDescuento > 0.01 ? 'block' : 'none');
	document.FormasDePago.Total.value     = fTotal;
	document.FormasDePago.Gastos.value    = fGastos;
	document.FormasDePago.Descuento.value = fDescuento;
}


function GastosFormaDePago ()
{
	InHTML ('idAnotacion', '&nbsp;');
	GastosDeEnvio (TotalCesta, 0, 0);

	if (FormasDePago.Locate ('Id', document.FormasDePago.FormaDePago.value))
	{	InHTML ('idAnotacion', FormasDePago.ByName ('Texto') + '&nbsp;');
		GastosDeEnvio (FormasDePago.asFloat ('Total'), FormasDePago.asFloat ('Gastos'),
		               FormasDePago.asFloat ('Descuento'));
	}	else if (FormasDeEnvio.Locate ('Id', document.FormasDePago.FormaDeEnvio.value))
		GastosDeEnvio (FormasDeEnvio.asFloat ('Total'), FormasDeEnvio.asFloat ('Gastos'),
		               FormasDePago.asFloat ('Descuento'));
}


function GuiaDeTallas (iId)
{
	var Ventana = new TWindow ();
	Ventana.Titulo = Idioma (24);
	Ventana.Vars ('Lng', Lng);
	Ventana.Vars ('Id', iId);
	Ventana.Cargar ('/fuentes/tallas.php');
}


function IdentificarCliente (Formulario)
{
	var	Ajax = new TAjax ();

	if (ValidarFormulario (Formulario))
	{	Ajax.onCargar = IdentificarClienteOn;
		Ajax.Vars ('Codigo', Formulario.Codigo.value.Trim ());
		Ajax.Vars ('Clave', Formulario.Clave.value.Trim ());
		Ajax.Cargar ('/fuentes/identificarcliente.php', 'idCargando');
	}
}

function IdentificarClienteOn (Peticion)
{
	var Resultado = Peticion.asText ();

	if (Resultado == 'OK') CargarPagina ();
	else alert (Idioma (5));
}


function ImgArticuloOut (iArticulo, iId)
{
	ImageSrc ('imgArticulo', '/contenidos/articulos/' + iArticulo + '-1.jpg');
}


function ImgArticuloOver (iArticulo, iId)
{
	ImageSrc ('imgArticulo', '/contenidos/articulosgaleria/' + iArticulo + '-' + iId + '-1.jpg');
}


function InicializarPais (Control, Pais)
{
	var i = Control.length - 1;

	while (i >= 0 && Control.options [i].value != Pais) i--;
	if (i >= 0) Control.selectedIndex = i;
}


function InitMenCategorias (iCategoria, iSubcategoria)
{
	Clase ('idCat-' + iCategoria,    'Seleccionado');
	Clase ('idCat-' + iSubcategoria, 'Seleccionado');
}


function InitMenus ()
{
	Clase ('idOpc-' + Opc, 'Seleccionado');
}


function LimpiarParametros ()
{
	Par1 = 0;
	Par2 = 0;
	Par3 = 0;
	Par4 = '';
}


function Lopd ()
{
	var Ventana = new TVentana ();

	Ventana.Ancho       = 550;
	Ventana.Alto        = 300;
	Ventana.Nombre      = 'AvisoLegal';
	Ventana.URL         = '/fuentes/avisolegal.php?Lopd=1';
	Ventana.Open (true);
}


function Main (iOpc, iPar1, iPar2)
{
	if (typeof (iPar1) == 'undefined') iPar1 = 0;
	if (typeof (iPar2) == 'undefined') iPar2 = 0;

	Opc  = iOpc;
	Par1 = iPar1;
	Par2 = iPar2;
	Par3 = 0;
	
	CargarPagina ();
}


function onRollOutCesta (Fila)
{
	Fila.style.backgroundColor = '';
}


function onRollOverCesta (Fila)
{
	Fila.style.backgroundColor = '#F6DFED';
}


function PedirClave (Formulario)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (Formulario))
	{	Ajax.onCargar = PedirClaveOn;
		Ajax.Vars ('Email',   Formulario.Email.value.Trim ());
		Ajax.Cargar ('/fuentes/recordarclave.php', 'idRecordar');
	}
}


function PedirClaveOn (Peticion)
{
	if (Peticion.asText () == 'OK')
	{	Display ('idRecordarClave', 'none');
		Display ('idEnvioOK', 'block');
	} else alert (Idioma (8));
}


function PrecargaGaleria (iArticulo)
{
	var Imagenes = new Array ();
	var i = arguments.length;

	for (i; i > 0; i--)
	{	Imagenes [i] = new Image ();
		Imagenes [i].src = '/contenidos/articulosgaleria/' + iArticulo + '-' + arguments [i] + '-1.jpg';
	}
}


function PrecioTalla ()
{
	$('idPrecioArt').innerHTML = document.Comprar.Talla.value.split ('|')[1];
}


function RecordarClave ()
{
	var Ventana = new TWindow ()

  	Ventana.Vars ('Lng', Lng);
	Ventana.Cargar ('/fuentes/recordarclave.php');
}


function RegistrarCliente (oFormulario, iOpcion)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (oFormulario) && ConfirmarClave (oFormulario))
	{	if (oFormulario.Aceptar.checked)
		{	Ajax.Opcion = iOpcion;
			Ajax.onCargar = RegistrarClienteOn;
			Ajax.Vars ('Lng', Lng);
			Ajax.Formulario (oFormulario);
			Ajax.Cargar ('/fuentes/datoscliente.php', 'idCargando');
		} else alert (Idioma (16));
	}
}


function RegistrarClienteOn (Peticion)
{
	var Result = Peticion.asText ();

	if (Result == 'OK') Main (Peticion.Opcion);
	else if (Result == 'NOLOGIN') alert (Idioma (10));
	else if (Result == 'NOCLAVE') alert (Idioma (11));
	else if (Result == 'NOEMAIL') alert (Idioma (12));
	else if (Result == 'LOGINDUPLICADO') alert (Idioma (14));
	else if (Result == 'EMAILDUPLICADO') alert (Idioma (15));
	else alert (Idioma (13));
}


function Ticket ()
{
	var Ajax = new TAjax ();

	Ajax.onCargar = TicketOn;
	Ajax.Vars ('Lng', Lng);
	Ajax.Cargar ('/fuentes/ticket.php');
}


function TicketAvanzar (Avanzar)
{
	if (Avanzar)
	{	if (LineaTicket < LineasTicket.RecordCount () - 3)
		{	LineaTicket++;
			TicketLineas ();
		}
	} else
	{	if (LineaTicket > 1)
		{	LineaTicket--;
			TicketLineas ();
		}
	}

	if ((LineaTicket < LineasTicket.RecordCount () - 3))
		ImageSrc ('RtTicket', '/imagenes/pedido_bajar.gif');
	else ImageSrc ('RtTicket', '/imagenes/pedido_bajar_off.gif');
	if (LineaTicket > 1) ImageSrc ('AvTicket', '/imagenes/pedido_subir.gif');
	else ImageSrc ('AvTicket', '/imagenes/pedido_subir_off.gif');
}


function TicketLineas ()
{
	var f         = 0;
	var Div       = null;
	var Aux       = null;
	var Etiqueta  = document.getElementById ('idLineasTicket');

	if (Etiqueta)
	{	Etiqueta.innerHTML = '';
		LineasTicket.RecNo (LineaTicket);
		while (! LineasTicket.Eof () && f++ < 4)
		{	Div = document.createElement ('div');
			Div.className = 'Fila';
			Aux = document.createElement ('div');
			Aux.className = 'Descripcion';
			Aux.innerHTML = LineasTicket.ByName ('Cantidad') + ', ' + LineasTicket.ByName ('Descripcion');
			Div.appendChild (Aux);
			Aux = document.createElement ('div');
			Aux.className = 'Importe';
			Aux.innerHTML = LineasTicket.ByName ('Importe') + ' &euro;';
			Div.appendChild (Aux);
			Etiqueta.appendChild (Div);
			LineasTicket.Next ();
		}
	}
}


function TicketOn (Peticion)
{
	var MAXLINEAS = 4;

	LineasTicket = DataSet (Peticion.asText (), 'TICKET');
	var Etiqueta = document.getElementById ('idLineasTicket');
	var Lineas   = LineasTicket.RecordCount ();

	if (Etiqueta && Lineas)
	{	LineaTicket = 0;
		if (Lineas > 4) LineaTicket = Lineas - 3;
		TicketLineas ();
	}
}


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



function EnviarFormContacto (Formulario)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (Formulario))
	{	
		Ajax.onCargar = onEnviar;
		Ajax.Formulario (Formulario);
		Ajax.Cargar ('/fuentes/enviarcontacto.php');
	}
}

function onEnviar (Peticion)
{
	Display ('idFormulario', 'none');
	Display ('idEnvioOK', 'block');
}




  

