// Copyright 2001 - Deferr Fabrice
// All rights reserved
// www.deferr.ch - fabrice@deferr.ch

function Catalog(idcatalog,title,isbn,author,chf,frf,eur,qty)
{
	this.idcatalog	= idcatalog;
	this.title		= title;
	this.isbn		= isbn;
	this.author		= author;
	this.chf		= chf;
	this.frf		= frf;
	this.eur		= eur;
	
	this.qty		= qty;
}

function setQuantity(idcatalog,title,isbn,author,chf,frf,eur,qty)
{
	var nbQty = 0;
	var mode = 0;
	for (var i=0; i < this.nPos; i++)
	{
		if (this.oTable[i] != null && this.oTable[i].idcatalog == idcatalog)
		{
			nbQty = parseInt(this.oTable[i].qty) + parseInt(qty);
			this.oTable[i].qty = nbQty;
			mode = 1;
		}
	}
	
	if (mode == 0)
	{
		this.oTable[this.nPos++] = new Catalog(idcatalog,title,isbn,author,chf,frf,eur,qty);
	}
	
	this.oCaddyFrame.document.location = this.oDocumentName;
}

function deleteQuantity(idcatalog)
{
	var bDone;
	bDone = confirm("êtes-vous sur de vouloir supprimer cet article ?");
	if (bDone == true)
	{
		for (var i=0; i < this.nPos; i++)
		{
			if (this.oTable[i] != null)
			{
				if (this.oTable[i].idcatalog == idcatalog)
				{
					this.oTable[i] = null;
				}
			}
		}
		this.oCaddyFrame.location.reload();
	}
}

function getTotal(currency)
{
	var nTotalchf = 0;
	var nTotalfrf = 0;
	var nTotaleur = 0;
	for (var i=0; i < this.nPos; i++)
	{
		if (this.oTable[i] != null)
		{
			nTotalchf += this.oTable[i].chf * this.oTable[i].qty;
			nTotalfrf += this.oTable[i].frf * this.oTable[i].qty;
			nTotaleur += this.oTable[i].eur * this.oTable[i].qty;
		}
	}
	
	if (currency == 'chf')
	{
		return nTotalchf;
	}
	else if (currency == 'frf')
	{
		return nTotalfrf;
	}
	else if (currency == 'eur')
	{
		return nTotaleur;
	}
}

function setCaddyFrame(obj,doc)
{
	this.oCaddyFrame = obj;
	this.oDocumentName = doc;
}

function getCaddyFrame()
{
	return this.oCaddyFrame;
}

function Caddy()
{
	this.hWND				= null;
	this.oTable				= new Array();
	this.nPos				= 1;

	this.oCaddyFrame		= null;
	this.oDocumentName		= null;
	this.useCaddyFrame		= false;

	this.setQuantity		= setQuantity;
	//this.modifyQuantity		= modifyQuantity;
	this.deleteQuantity 	= deleteQuantity;
	this.getTotal			= getTotal;
	this.getCaddyFrame		= getCaddyFrame;
	this.setCaddyFrame		= setCaddyFrame;
	//this.deleteAllObject 	= deleteAllObject;
}