
function ActivarDireccionEnvio ()
{
	var Desactivado = ! document.DatosDeEnvio.DireccionDeEnvio.checked;

	document.DatosDeEnvio.NombreEnvio.disabled       = Desactivado;
	document.DatosDeEnvio.DomicilioEnvio.disabled    = Desactivado;
	document.DatosDeEnvio.LocalidadEnvio.disabled    = Desactivado;
	document.DatosDeEnvio.CodigoPostalEnvio.disabled = Desactivado;
	document.DatosDeEnvio.ProvinciaEnvio.disabled    = Desactivado;
	document.DatosDeEnvio.PaisEnvio.disabled         = Desactivado;
	document.DatosDeEnvio.TelefonoEnvio.disabled     = Desactivado;
	
//	if (document.DatosDeEnvio.DireccionDeEnvio.checked)
//		document.DatosDeEnvio.chkDocumentacion.checked = true;
}


function AmpliarImagen (URL)
{
	var Ventana = new TVentana ();

	Ventana.Ancho  = 810;
	Ventana.Alto   = 550;
	Ventana.Nombre = 'AmpliarImagen';
	Ventana.URL    = URL;
	Ventana.ScrollBars  = false;
	Ventana.Open (true);
}


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

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


function BuscarProductos ()
{   
	var Buscar = Trim (document.frmBuscar.Buscar.value);

	if (Buscar == '') 
	{	alert ('Tiene que indicar un texto a buscar.');
		document.frmBuscar.focus ();
	} else
	{	LimpiarParametros;
		Par4 = escape (Buscar);
		Opc = OPC_BUSCADOR;
		CargarPagina ();
	}
}   


function CambiarClave ()
{
	if (Trim (document.Clave.clvActual.value) == '')
	{	alert ('Tiene que indicar la clave actual.');
		document.Clave.clvActual.focus ();
	} else if (Trim (document.Clave.clvNueva.value) == '')
	{	alert ('Tiene que indicar la clave nueva.');
		document.Clave.clvNueva.focus ();
	} else if (Trim (document.Clave.clvConfirmar.value) == '')
	{	alert ('Tiene que confirmar la clave.');
		document.Clave.clvConfirmar.focus ();
	} else if (Trim (document.Clave.clvNueva.value).length < 6)
	{	alert ('La clave nueva tiene que conterner 6 caracteres como mínimo.');
		document.Clave.clvNueva.focus ();
	} else if (document.Clave.clvNueva.value != document.Clave.clvConfirmar.value)
	{	alert ('La clave nueva y su confirmación son distintas.');
		document.Clave.clvNueva.focus ();
	} else DoCambiarClave ();
}


function CambiarIdioma (Idioma)
{
	if (Lng != Idioma)
	{	Lng = Idioma;
		CargarPagina ();
	}
}


function CantidadCesta (Item, Cantidad)
{
	var	Ajax     = new TAjax ();

	Ajax.OnCompletar (onComprar);	
	Ajax.AddParametro ('Item',     Item);
	Ajax.AddParametro ('Cantidad', Cantidad);
	Ajax.Open ('/fuentes/actualizarpedido.php', 'Cargando');
}


function CargarPagina ()
{
	var Pars = '?Opc=' + Opc;
	
	if (Lng)  Pars += '&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 Comprar (Articulo)
{
	var	Ajax = new TAjax ();
	
	Ajax.OnCompletar (onComprar);	
	Ajax.AddParametro ('Id', Articulo);
	Ajax.AddParametro ('Cantidad', 1);
	Ajax.Open ('/fuentes/comprar.php');
}


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

	Ajax.OnCompletar (CargarPagina);	
	Ajax.Open ('/fuentes/desconectar.php');
}


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

	Ajax.OnCompletar (OnCambiarClave);
	Ajax.AddParametro ('clvActual', Trim (document.Clave.clvActual.value));
	Ajax.AddParametro ('clvNueva', Trim (document.Clave.clvNueva.value));
	Ajax.AddParametro ('clvConfirmar', Trim (document.Clave.clvConfirmar.value));
	Ajax.Open ('/fuentes/cambiarclave.php', 'Cargando');
}


function GuardarAnotaciones (Pedido, Repuestos)
{
	var Ajax = new TAjax ();

	Ajax.OnCompletar (onGuardarAnotaciones);
	Ajax.AddParametro ('Id',        Pedido);
	Ajax.AddParametro ('Repuestos', Repuestos);
	Ajax.AddParametro ('Notas',     Trim (document.Anotaciones.Notas.value));
	Ajax.Open ('/fuentes/guardarnotas.php', 'Cargando');
}


function IdentificarCliente ()
{
	var Codigo = Trim (document.Login.Codigo.value);
	var Clave  = Trim (document.Login.Clave.value);

	if (Codigo == '')
	{	alert ("Tiene que indicar un código de usuario.");
		document.Login.Codigo.focus ();
	} else if (Clave == '')
	{	alert ("Tiene que indicar una clave de usuario.");
		document.Login.Clave.focus ();
	} else ValidarCliente ();
}


function Idioma (Esp, Ing, Fra, Ale)
{
	if (LNG == LNG_ALEMAN && Ale) return (Ale);
	if (LNG == LNG_FRANCES && Fra) return (Fra);
	if (Lng == LNG_INGLES && Ing) return (Ing);
	return (Esp);
}


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


function Main (Opcion)
{
	Opc = Opcion;
	LimpiarParametros ();
	CargarPagina ();
}


function NotasPedido (Pedido, Repuestos)
{
	var Ventana = new TVentana ();

	Anotaciones        = Ventana;
	Ventana.Nombre     = 'Anotaciones';
	Ventana.Ancho      = 520;
	Ventana.Alto       = 550;
	Ventana.ScrollBars = false;
	Ventana.URL        = '/fuentes/notaspedido.php?Id=' + Pedido + '&Repuestos=' + Repuestos;
	Ventana.Open (true);
}


function OnCambiarClave (Peticion)
{
	if (Peticion.AsText () == 'OK')
	{	document.Clave.clvActual.value    = '';
		document.Clave.clvNueva.value     = '';
		document.Clave.clvConfirmar.value = '';
		alert ('La clave ha sido cambiada.');
	}	else if (Peticion.AsText () == 'ERROR') alert ('La clave actual no es correcta.');
	else alert ('No se ha podido cambiar la clave.');
}


function onComprar (Peticion)
{
	var Stock = new TDataSet (Peticion.AsXML (), 'STOCK');

	if (Stock.NumRegistros ())
	{	if (Stock.FieldAsInteger ('Unidades') > 0)
			alert ('Solo quedan disponibles ' + Stock.FieldByName ('Unidades') + ' unidades.');
		else alert ('No quedan unidades disponibles de este producto.');
	}
	
	VerTicket (Peticion);
}


function onGuardarAnotaciones (Peticion)
{
	if (Peticion.AsText () == 'OK') document.Anotaciones.Cerrar.click ();
	else alert ('No se ha podido salvar las anotaciones\nPor favor vuelva a intentarlo.');
}


function onValidarCliente (Peticion)
{
	var Resultado = Peticion.AsText ();
	
	if (Resultado == 'OK') CargarPagina ();
	else alert ("Código de cliente o clave incorrectos.\nRecuerde que la clave es sensible\na mayúsculas y minúsculas");
}


function TerminarPedido ()
{
	var Submit = false;
	
	if (document.DatosDeEnvio.DireccionDeEnvio.checked)
	{	if (Trim (document.DatosDeEnvio.NombreEnvio.value) == '')
		{	alert ("Tiene que indicar un nombre\nen la dirección de envío.");
			document.DatosDeEnvio.NombreEnvio.focus ();
		} else if (Trim (document.DatosDeEnvio.DomicilioEnvio.value) == '')
		{	alert ("Tiene que indicar un domicilio \nen la dirección de envío.");
			document.DatosDeEnvio.DomicilioEnvio.focus ();
		} else if (Trim (document.DatosDeEnvio.LocalidadEnvio.value) == '')
		{	alert ("Tiene que indicar una localidad \nen la dirección de envío.");
			document.DatosDeEnvio.LocalidadEnvio.focus ();
		} else if (Trim (document.DatosDeEnvio.ProvinciaEnvio.value) == '')
		{	alert ("Tiene que indicar una provincia \nen la dirección de envío.");
			document.DatosDeEnvio.ProvinciaEnvio.focus ();
		} else if (Trim (document.DatosDeEnvio.PaisEnvio.value) == '')
		{	alert ("Tiene que indicar un país \nen la dirección de envío.");
			document.DatosDeEnvio.PaisEnvio.focus ();
		} else if (Trim (document.DatosDeEnvio.TelefonoEnvio.value) == '')
		{	alert ("Tiene que indicar un teléfono \nen la dirección de envío.");
			document.DatosDeEnvio.TelefonoEnvio.focus ();
		} else Submit = true;
	} else Submit = true;

	if (Submit)
	{	if (Trim (document.DatosDeEnvio.SuPedido.value) == '')
		{	alert ('Tiene que indicar el número de su pedido.');
			document.DatosDeEnvio.SuPedido.focus ();
		}else document.DatosDeEnvio.submit ();
	}
}


function TicketPedido ()
{
	var	Ajax = new TAjax ();
	
	Ajax.OnCompletar (VerTicket);	
	Ajax.Open ('/fuentes/ticketpedido.php');
}


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

	Ajax.OnCompletar (onValidarCliente);	
	Ajax.AddParametro ('Codigo', Trim (document.Login.Codigo.value));
	Ajax.AddParametro ('Clave', Trim (document.Login.Clave.value));
	Ajax.Open ('/fuentes/identificarcliente.php', 'Cargando');
}


function VerDocumentacion (Ident)
{
	Par1 = Ident;
	Par2 = 0;
	CargarPagina ();
}


function VerNoticia (Ident)
{
	var Ventana = new TVentana ();

	Ventana.Ancho  = 610;
	Ventana.Alto   = 550;
	Ventana.Nombre = 'Noticia';
	Ventana.URL    = '/fuentes/vernoticia.php?Id=' + Ident + '&Lng=' + Lng;
	Ventana.Open (true);
}


function VerPlano (Path)
{
	var Ventana = new TVentana ();

	Ventana.Ancho  = 805;
	Ventana.Alto   = 505;
	Ventana.Nombre = 'Plano';
	Ventana.URL    = '/' + Path + '/plantillas/plano.html';
	Ventana.ScrollBars  = false;
	Ventana.Open (true);

}


function VerTicket (Peticion)
{
	var Lineas   = new TDataSet (Peticion.AsXML (), 'LINEAS');
	var Result   = Array ();
	var i        = 0;
	var Total    = 0;
	var Cantidad = 0;
	
	if (Lineas.NumRegistros ())
	{	while (! Lineas.Eof ())
		{	Cantidad = Lineas.FieldAsInteger ('Cantidad');
			Total += Cantidad;
			Result [i++] = '<div class="Linea">' +
			    	         '<div class="Referencia">' + Lineas.FieldByName ('Codigo') + '</div>' +
			  		         '<div class="Cantidad">' + Cantidad + '&nbsp;&nbsp;' +
			  		         '<a href="javascript:CantidadCesta (\'' + Lineas.FieldByName ('Item') + '\',' +
			  		          (Cantidad - 1) + ')">-</a>&nbsp;' + 
			  		         '<a href="javascript:CantidadCesta (\'' + Lineas.FieldByName ('Item') + '\',' +
			  		         (Cantidad + 1) + ')">+</a></div></div>';
			Lineas.Next ();
		}
		InHTML ('idLineasTicket', Result.join (''));
		InHTML ('idTotal', Total);
		Display ('idTicket', 'block');		
	} else Display ('idTicket', 'none');
}


function VerVideo (Opcion)
{
	var Ventana = new TVentana ();

	Ventana.Ancho  = 510;
	Ventana.Alto   = 405;
	Ventana.Nombre = 'Video';
	Ventana.URL    = '/videos/video' + Opcion + '.html';
	Ventana.ScrollBars  = false;
	Ventana.Open (true);
}

function PlanoFlashEs ()
{
	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="800" height="500" id="Plano" align="middle">');
	document.write ('<param name="allowScriptAccess" value="sameDomain" />');
	document.write ('<param name="movie" value="/es/swf/plano.swf" />');
	document.write ('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write ('<embed src="/es/swf/plano.swf" quality="high" bgcolor="#ffffff" width="800" height="500" name="Plano" align="middle"');	
	document.write ('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  />');
	document.write ('</object>');	
}

function PlanoFlashFr ()
{
	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="800" height="500" id="Plano" align="middle">');
	document.write ('<param name="allowScriptAccess" value="sameDomain" />');
	document.write ('<param name="movie" value="/fr/swf/plano.swf" />');
	document.write ('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write ('<embed src="/fr/swf/plano.swf" quality="high" bgcolor="#ffffff" width="800" height="500" name="Plano" align="middle"');	
	document.write ('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  />');
	document.write ('</object>');	
}

function PlanoFlashDe ()
{
	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="800" height="500" id="Plano" align="middle">');
	document.write ('<param name="allowScriptAccess" value="sameDomain" />');
	document.write ('<param name="movie" value="/de/swf/plano.swf" />');
	document.write ('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write ('<embed src="/de/swf/plano.swf" quality="high" bgcolor="#ffffff" width="800" height="500" name="Plano" align="middle"');	
	document.write ('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  />');
	document.write ('</object>');	
}


function PlanoFlashIn ()
{
	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="800" height="500" id="Plano" align="middle">');
	document.write ('<param name="allowScriptAccess" value="sameDomain" />');
	document.write ('<param name="movie" value="/in/swf/plano.swf" />');
	document.write ('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write ('<embed src="/in/swf/plano.swf" quality="high" bgcolor="#ffffff" width="800" height="500" name="Plano" align="middle"');	
	document.write ('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  />');
	document.write ('</object>');	
}


//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================



