


function Buscar ()
{
    if (Trim (document.Buscar.BuscarPor.value) != '')
        window.location = '/index.php?Lng=' + Lng + '&Opc=' + OPC_CATEGORIA + '&Par1=' + CAT_BUSCAR +
                                     '&Par4=' + document.Buscar.BuscarPor.value;
}


function CambiarCaso (Opcion, P1)
{
    if (typeof P1 == 'undefined') P1 = 0;

    if (Opcion == OPC_CATEGORIA)
    {   if (Opcion != Opc || Par1 != P1)
            window.location = '/index.php?Lng=' + Lng + '&Opc=' + Opcion + '&Par1=' + P1;
    } else if (Opcion != Opc) window.location = '/index.php?Lng=' + Lng + '&Opc=' + Opcion;
}


function CambiarIdioma ()
{
    var Idioma = 1;

    if (Lng == 1) Idioma = 2;
    window.location = '/index.php?Lng=' + Idioma + '&Opc=' + Opc + '&Par1=' + Par1 + '&Par2=' + Par2 +
                                '&Par3=' + Par3 + '&Par4=' + Par4;
}


function Comprar (Articulo, LeerCantidad, CerrarVentana, ControlarStock, Stock)
{
    var ajax     = new TAjax ();
    var Cantidad = 1;

    if (LeerCantidad) Cantidad = CadenaAEntero (document.Formulario.Cantidad.value);
    if (Cantidad > 0)
    { 
    	ajax.OnCompletar (function (peticion)
    											{
    												if (mensaje (peticion.AsText ()))
    													window.location = '/index.php?Opc=' + OPC_CESTA + '&Lng=' + Lng + '&Mon=' + Mon;
    											});
			ajax.AddParametro ('Articulo', Articulo);
			ajax.AddParametro ('Cantidad', Cantidad);
			ajax.AddParametro ('ControlarStock', ControlarStock ? 1 : 0);
			ajax.AddParametro ('Stock', Stock);
			ajax.Open ('/fuentes/comprar.php');    											
    	
/*
        Ventana.URL        =  '/cesta/cesta.php?Lng=' + Lng + '&Mon=' + Mon + '&Caso=2&Articulo=' + Articulo + 
                              '&Cantidad=' + Cantidad +
                              '&ControlarStock=' + (ControlarStock ? '1' : '0') + '&Stock=' + Stock;
*/                              
    } else
    {   if (Lng == 2) alert ('It must indicate a unit');
        else alert ("Tiene que indicar una cantidad");
    }
}


function ActualizarCesta (Lng, Item, ControlarStock, Stock, EsTarjeta)
{
    var Cantidad = CadenaAEntero (document.Cesta ['edtCantidad' + Item].value);

		if (EsTarjeta) window.location.replace ('/cesta/actualizartarjeta.php?Lng=' + Lng + '&Mon=' + Mon + '&Item=' + Item);
		else 
		{	if (Cantidad <= 0)
    	{   if (Lng == 2) alert ('It must indicate an amount.');
      	  else alert ('Tiene que indicar una cantidad.');
        	document.Cesta ['edtCantidad' + Item].focus ();
    	} else 
			{	var ajax = new TAjax ();
				
				ajax.OnCompletar (function (peticion)
    											{
    												if (mensaje (peticion.AsText ()))
    													window.location = '/index.php?Opc=' + OPC_CESTA + '&Lng=' + Lng + '&Mon=' + Mon;
    											});
			ajax.AddParametro ('Item', Item);
			ajax.AddParametro ('Cantidad', Cantidad);
			ajax.AddParametro ('ControlarStock', ControlarStock ? 1 : 0);
			ajax.AddParametro ('Stock', Stock);
			ajax.Open ('/fuentes/actualizar.php');    											
/*
    		window.location.replace ('/cesta/cesta.php?Lng=' + Lng + '&Mon=' + Mon + '&Caso=3&Item=' + Item + '&Cantidad=' + Cantidad +
      	                              '&ControlarStock=' + (ControlarStock ? '1' : '0') + '&Stock=' + Stock);
*/
    	}
    }
}


function EnviarURL (Articulo)
{
    var Ventana = new TVentana ();

    Ventana.Ancho      = 400;
    Ventana.Alto       = 300;
    Ventana.Nombre     = 'EnviarAmiga';
    Ventana.ScrollBars = false;
    Ventana.URL        = '/fuentes/enviaramiga.php?Lng=' + Lng + '&Articulo=' + Articulo;
    Ventana.Open ();
    Ventana.Focus ();
}


function Idioma (Lng, Esp, Ing)
{
    if (Lng == 2) return (Ing);
    else return (Esp);
}


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

    Ventana.Ancho  = 500;
    Ventana.Alto   = 550;
    Ventana.Nombre = 'Oferta';
    Ventana.URL    = '/fuentes/ofertadelmes.php?Lng=' + Lng + '&Mon=' + Mon;
    Ventana.Open (true);
}


function ValidarAmiga (Lng)
{
    if (Trim (document.boletin.frommail.value) == "")
        alert (Idioma (Lng, 'Tiene que indicar su e-mail.', 'It must indicate your e-mail'));
    else if (! EmailCorrecto (document.boletin.frommail.value))
        alert (Idioma (Lng, 'Su e-mail no es correcto.', 'Your e-mail is invalid.'));
    else if (Trim (document.boletin.tomail.value) == "")
        alert (Idioma (Lng, 'Tiene que indicar el e-mail de su amig@.', 'It must indicate your friend e-mail.'));
    else if (! EmailCorrecto (document.boletin.tomail.value))
        alert (Idioma (Lng, 'El e-mail de su amig@ no es correcto.', 'Your friend e-mail is invalid.'));
    else return (true);
    return (false);
}




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

    Ventana.Ancho      = 760;
    Ventana.Alto       = 420;
    Ventana.Nombre     = 'Comprar';
    Ventana.ScrollBars = true;
    Ventana.URL        = '/cesta/cesta.php?Caso=1&Lng=' + Lng + '&Mon=' + Mon;
    Ventana.Open (true);
}


function VerMarcas (Categoria)
{
    var Ventana = new TVentana ();

    Ventana.Ancho      = 350;
    Ventana.Alto       = 450;
    Ventana.Nombre     = 'Marcas';
    Ventana.ScrollBars = true;
    Ventana.URL        = '/fuentes/vermarcas.php?Lng=' + Lng + '&Mon=' + Mon + '&Categoria=' + Par1;
    Ventana.Open (true);
}


function VerRegalo (Regalo)
{
    var Ventana = new TVentana ();

    Ventana.Ancho      = 100;
    Ventana.Alto       = 50;
    Ventana.ScrollBars = false;
    Ventana.Centrar    = true;
    Ventana.Nombre     = 'Regalos';
    Ventana.URL        = '/fuentes/verregalo.php?Regalo=' + Regalo;
    Ventana.Open (true);
}




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

function VerMarcas (Categoria)
{
	var Ventana = new TVentana ();
	var Pars    = '?Lng=' + Lng;

	if (Mon)  Pars += '&Mon=' + Mon;
	if (Ord)  Pars += '&Ord=' + Ord;
	Pars += '&Categoria=' + Par1;

  Ventana.Ancho      = 350;
  Ventana.Alto       = 450;
  Ventana.Nombre     = 'Marcas';
  Ventana.ScrollBars = true;
  Ventana.URL        = '/fuentes/vermarcas.php' + Pars;
  Ventana.Open (true);
}

function VerCategorias ()
{
	var Ventana = new TVentana ();
	var Pars    = '?Lng=' + Lng;

	if (Mon)  Pars += '&Mon=' + Mon;
	if (Ord)  Pars += '&Ord=' + Ord;
	Pars += '&Categoria=' + Par1;

  Ventana.Ancho      = 350;
  Ventana.Alto       = 450;
  Ventana.Nombre     = 'Categorias';
  Ventana.ScrollBars = true;
  Ventana.URL        = '/fuentes/vercategorias.php' + Pars;
  Ventana.Open (true);
}

function CambiarCaso (Opcion, P1)
{
    if (typeof P1 == 'undefined') P1 = 0;

    if (Opcion == OPC_CATEGORIA)
    {   if (Opcion != Opc || Par1 != P1)
    		{	Opc  = Opcion;
    			Par1 = P1;
    			Par2 = 0;
    			Par3 = 0;
    			Par4 = 0;
    			CargarPagina ();
    		}
    } else if (Opcion != Opc)
    {	Opc = Opcion;
    	Par1 = 0;
    	Par2 = 0;
    	Par3 = 0;
    	Par4 = 0;
    	CargarPagina ();
		}
}


function CargarPagina ()
{
	var Pars = '?Lng=' + Lng;
	
	if (Opc)  Pars += '&Opc=' + Opc;
	if (Mon)  Pars += '&Mon=' + Mon;
	if (Ord)  Pars += '&Ord=' + Ord;
	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 CambiarVerPrecios ()
{
	var Moneda = document.Opciones.VerPrecio.value;
	
	if (Moneda != Mon)
	{	Mon = Moneda;
		CargarPagina ();
	}
}

function CambiarOrden ()
{
	var Orden = document.Opciones.Orden.value;
	
	if (Ord != Orden)
	{	Ord = Orden;
		CargarPagina ();
	}
}

function TarjetaRegalo ()
{
	if (Par3 != -1)
	{	Par3 = -1;
		CargarPagina ();
	}
}

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

function ActualizarTarjeta (Item)
{ if (ValidarDatosTarjeta ())
		window.location.replace ('/cesta/cesta.php?Lng=' + Lng + '&Mon=' + Mon + '&Caso=7&Item=' + Item + 
      	                     '&Importe=' + document.Tarjeta.Importe.value + 
                             '&Destinatario=' + document.Tarjeta.Destinatario.value + 
                             '&Mensaje=' + escape (document.Tarjeta.Mensaje.value) + 
                             '&Email=' + document.Tarjeta.Email.value);                     		
}


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

	if (ValidarDatosTarjeta ())
	{		Ventana.Ancho      = 760;
      Ventana.Alto       = 420;
      Ventana.Nombre     = 'Comprar';
      Ventana.ScrollBars = true;
      Ventana.URL        =  '/cesta/cesta.php?Lng=' + Lng + '&Mon=' + Mon + '&Caso=6&Importe=' + document.Tarjeta.Importe.value + 
                            '&Destinatario=' + document.Tarjeta.Destinatario.value + 
                            '&Mensaje=' + escape (document.Tarjeta.Mensaje.value) + 
                            '&Email=' + document.Tarjeta.Email.value;                     
				                            
      Ventana.Open (true);
      document.Tarjeta.reset ();    
	}	
}


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

		Ventana.Ancho      = 760;
    Ventana.Alto       = 420;
    Ventana.Nombre     = 'ConsultaSaldo';
    Ventana.ScrollBars = true;
    Ventana.URL        = '/fuentes/consultasaldo.php?Lng=' + Lng + '&Mon=' + Mon;
    		                            
    Ventana.Open (true);
}


function ImporteValido (Importe)
{
	var Aux = Importe;		
	if (EsNumero (Aux))
  { if (CuentaSubCadenas (Importe, ',') == 0)
  		Aux = String (Importe.replace ('.', ','));
  	Importe = parseFloat (Importe);
  	if (isNaN (Importe)) Aux = 0;
  } else Aux = 0;
  return (Aux);
}



function SaldoTarjeta ()
{	
	var	Ajax  = new TAjax ();
	
	if (! document.frmSaldoTarjeta.NTarjeta.value) 
	{	alert (Idioma(Lng, 'Debe indicar el número de tarjeta a consultar.', 'You must type the number of the giftcard you want to check.'));
		document.frmSaldoTarjeta.NTarjeta.focus();
	} else if (! document.frmSaldoTarjeta.Email.value) 
	{ alert (Idioma(Lng, 'Debe indicar su e-mail.', 'It must indicate your e-mail.'));
		document.frmSaldoTarjeta.Email.focus();
	} else if (! EmailCorrecto (document.frmSaldoTarjeta.Email.value))
	{ alert (Idioma(Lng, 'E-mail ingresado no es correcto.', 'E-mail is invalid.'));
		document.frmSaldoTarjeta.Email.focus();
	} else 
	{	Ajax.OnCompletar (OnSaldoTarjeta)
		Ajax.AddFormulario (document.frmSaldoTarjeta);
		Ajax.Open ('/fuentes/saldotarjeta.php');
	}

}

function OnSaldoTarjeta (Peticion)
{
	//Display ('IdSaldoTarjeta', 'none');
	var Etiqueta = document.getElementById ('Saldo');
	
	if (Etiqueta) 
	{	if (Peticion.AsText () == 'NOOK') 
			Etiqueta.innerHTML = Idioma (Lng, ' La tarjeta no es válida o no existe.', ' This card does not exist or is not a valid tubotica® giftcard number.');
		else Etiqueta.innerHTML = Peticion.AsText ();	
	}
	Display ('idTRSaldoOk', DisplayTR ());
}


function CancelarTarjeta (Item)
{
		window.location.replace ('/cesta/cesta.php?Caso=1&Lng=' + Lng + '&Mon=' + Mon);
}

function ValidarDatosTarjeta ()
{
	var Importe  = 0;
	var Result   = false;
	
  document.Tarjeta.Importe.value = ImporteValido (document.Tarjeta.Importe.value);
  if (! document.Tarjeta.Destinatario.value) 
	{	alert (Idioma(Lng, 'Debe indicar un destinatario.', "It must indicate an recipient's name."));
		document.Tarjeta.Destinatario.focus();
	} else if (! document.Tarjeta.Email.value) 
	{ alert (Idioma(Lng, 'Debe indicar el e-mail del destinatario.', "It must indicate an recipient's email."));
		document.Tarjeta.Email.focus();
	} else if (! EmailCorrecto (document.Tarjeta.Email.value))
	{ alert (Idioma(Lng, 'E-mail no es correcto.', 'E-mail is invalid.'));
		document.Tarjeta.Email.focus();
	} else if (! document.Tarjeta.Email2.value)
	{ alert (Idioma(Lng, 'Debe indicar el e-mail de confirmación.', 'You must type a confirmation email.'));
		document.Tarjeta.Email2.focus();
	} else if (! EmailCorrecto (document.Tarjeta.Email2.value))
	{ alert (Idioma(Lng, 'E-mail de confirmación no es correcto.', 'Confirmation e-mail is invalid.'));
		document.Tarjeta.Email2.focus();
	} else if (document.Tarjeta.Email.value !=  document.Tarjeta.Email2.value)
	{	alert (Idioma(Lng, 'El E-mail y el de confirmación no son iguales.', 'Your email and confirmation email do not match.'));
		document.Tarjeta.Email2.focus();
	} else if (document.Tarjeta.Importe.value == 0)
	{ alert (Idioma(Lng, 'Debe indicar un importe a regalar.', 'It must indicate an amount to gift.'));
		document.Tarjeta.Importe.focus();
	} else Result = true;
		
	return (Result);
}


function Medicamentos ()
{
	var	Ajax  = new TAjax ();
	
	Ajax.OnCompletar (OnMedicamentos)
	Ajax.Open ('/fuentes/medicamentos.php');
}
	

function OnMedicamentos (Peticion)
{
  var Ventana = new TVentana ();

	if (Peticion.asText () == 'LOGIN')
	{	Ventana.Ancho      = 750;
    Ventana.Alto       = 450;
    Ventana.Nombre     = 'MiCuenta';
    Ventana.ScrollBars = true;
    Ventana.URL        = '/micuenta/identificar.php?Lng=' + Lng;
    Ventana.Open (true);
	}
}


function mensaje (msg)
{
	if (msg == 'OK') return true;
	else if (msg.substr (0, 4) == 'MSG:') alert (msg.substr (4));
	else alert ('Se ha producido un error.\nPor favor vuelva a intentarlo.');
	return false;
}

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

    Ventana.Ancho      = 760;
    Ventana.Alto       = 420;
    Ventana.Nombre     = 'Comprar';
    Ventana.ScrollBars = true;
    Ventana.URL        = '/fuentes/recordarclave.php?Lng=' + Lng;
    Ventana.Open (true);
}


function MiCuenta ()
{
	window.location = '/index.php?Opc=54&Lng=' + Lng;
}

