<!--

function shoppingList(page, sm, prod_data)
{
	this.page = page;
	this.sm = sm;
	this.action = '';
	this.products_data = new Array();
	this.products = new Array();
	this.row_count = 0;
	this.row_num = 0;
	this.output = '';
	this.loaded = false;
	
	this.setProductsDataArray = slSetProductsDataArray;
	this.importProductsData = slImportProductsData;
	this.includeFile = slIncludeFile;
	this.getProductData = slGetProductData;
	this.putData = slPutData;
	this.debug = slDebug;
	
	this.print = slPrint;
	this.printHeader = slPrintHeader;
	this.printFooter = slPrintFooter;
	this.printRow = slPrintRow;
	this.printRowEmpty = printRowEmpty
	this.printSpacer = slPrintSpacer;
	this.doAction = slDoAction;
	this.getProductCount = slGetProductCount;

	this.onAdd = slOnAdd;

	this.onDelete = slOnDelete;

	this.add = slAdd;

	this.del = slDel;

	this.syncSession = slSyncSession;
	
	this.syncSession(false);
	this.action = page.urlArray['params'].get('action');
	this.doAction();
	this.setProductsDataArray(prod_data);
	this.syncSession(true);
}

function slDebug()
{
	var output = 'Eingefügte Produkte:\n';
	var arr = new hashArray();
	arr.setArray(this.products);
	output += arr.dump()+'\n\nProduktdaten:\n';
	
	for(var key in this.products_data)
	{
		output += '[\''+key+'\'][\'ID\']\t= \''+this.products_data[key]['ID']+'\'\n';
		output += '[\''+key+'\'][\'name\']\t= \''+this.products_data[key]['name']+'\'\n';
		output += '[\''+key+'\'][\'desc\']\t= \''+this.products_data[key]['desc']+'\'\n';
		output += '[\''+key+'\'][\'price\']\t= \''+this.products_data[key]['price']+'\'\n';
		output += '[\''+key+'\'][\'img\']\t= \''+this.products_data[key]['img']+'\'\n\n';
		output += '[\''+key+'\'][\'date\']\t= \''+this.products_data[key]['date']+'\'\n\n';		
	}
	alert(output);
}

function slImportProductsData()
{
	for(var key in this.products)
	{
		this.includeFile(this.products[key]);
	}
}

function slGetProductCount()
{
	var count = 0;
	for(var i=0; i<this.products.length; i++)
	{
		if(this.getProductData(this.products[i]))
		{
			count++
		}
	}
	return count;
}

function slIncludeFile(productID)
{
	document.write('<script language="JavaScript" type="text/javascript" src="../files/JS/$file/prod_data_'+productID+'.js" id="inc"></script>');
}

function slPutData(dat)
{
	this.products_data[dat['ID']] = dat;
}

function slSyncSession(into)
{
		 var ha = new hashArray();
		 if(into) // IN SESSION SCHREIBEN
		 {
		 		 var now = new Date();
		 		 var dump = '';
		 		 ha.setArray(this.products);
		 		 dump = ha.dump(';');
		 		 this.sm.set('shopping_list_products', dump);
		 		 this.sm.set('shopping_list_date', parseInt(now.getTime()/1000));
		 }
		 else // AUS SESSION LESEN
		 {
		 		 
		 		 var cookie_time = this.sm.get('shopping_list_date');
		 		 var now = new Date();
		 		 var time = parseInt(now.getTime()/1000);
		 		 if((parseInt(cookie_time)+3600)>=time)
		 		 {
		 		 		 ha.setDump(this.sm.get('shopping_list_products'), ';');
		 		 		 this.products = ha.getArray();
		 		 }		 
		 }
}


function slSetProductsDataArray(products_data)
{
	this.products_data = products_data;
}

function slOnAdd()
{
	var productID = this.page.urlArray['params'].get('produktID');
	this.add(productID);
}

function slAdd(productID)
{
	if(productID)
	{
		var exists = false;
		for(var i=0; i<this.products.length; i++)
		{
			if(this.products[i]==productID)
			{
				exists = true;
			}
		}
		if(!exists)
		{
			this.products[this.products.length] = productID;
		}
	}
}

function slPrintHeader()
{
	this.output += ''
	+'<tr>'
	+'	<td><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="15" height="1" border="0"></td>';
}

function slPrintFooter()
{
	this.output += ''
	+'</tr>';
}

function slPrintRow(product)
{
	this.row_num++;
	var pricep=0;
	var p = product['price'];
	var x = p.indexOf(","); 
	var y = p.indexOf("."); 
	if((x>0)||(y>0))
	{
	pricep=product['price'];
	}
	else
	{
	pricep=product['desc'];
	};
	
	this.output += ''
	+'<td valign="top" width="224">'
	+'<table border="0" cellpadding="0" cellspacing="0" width="224" height="88">'
	+'<tr> <td colspan="4"><img src="' + LinkToSystemImages + 'ekz_hl.gif" alt="" width="224" height="1" border="0"></td> </tr>'
	+'<tr height="25">'
	+' <td colspan="3" class="linkbold" align="left" valign="top">'+product['name']+'</td>'
	+' <td align="left" valign="top">'+product['date']+'</td>'
	+' </tr>'
	+' <tr>'
	+'<td valign="top" rowspan="2"><img src="'+product['img']+'" alt="" width="69" height="54" border="0"></td>'
	+' <td valign="top"  background="' + LinkToSystemImages + 'but_delete_ekz.gif"><a href="../pages/c.o.ekz.index?OpenDocument&action=delete&produktID='+product['ID']+'"><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="18" height="16" border="0"></a></td>'
	+'<td rowspan="2"><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="19" height="1" border="0"></td>'
	+'<td rowspan="2">'
	+' <table border="0" cellpadding="0" cellspacing="0" width="98">'
	+'<tr>'
	+'<td align="center" width="98" height="42" background="' + LinkToSystemImages + 'bg_detail_prize2.gif" class="detailprize">'+pricep+' *</td>' +' </tr>'
	+' </table>' +' </td> ' +' </tr> <tr><td valign="top" height="100%">&nbsp;</td></tr>'
	+' <tr><td colspan="4"><img src="' + LinkToSystemImages + 'ekz_hl.gif" alt="" width="224" height="1" border="0"></td></tr>' 
	+'</table>'
+'</td>';

	if(this.row_num%2==0 && this.row_num!=1 && this.row_num!=this.getProductCount())
	{
		this.output += ''
		+'</tr>'
		+'<tr>'
		+'	<td colspan="4"><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="1" height="12" border="0"></td>'
		+'</tr>'
		+'<tr>'
		+'	<td><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="1" height="1" border="0"></td>';
	}
}

function printRowEmpty()
{
	this.output += ''
	+'<td valign="top" width="" align="center">' + TextEmptyRow + '</td>';
}

function slPrintSpacer()
{
	this.output += ''
	+'<td valign="top" width="224"><img src="' + LinkToSystemImages + 'm_dot.gif" alt="" width="224" height="1" border="0"></td>';
}

function slGetProductData(productID)
{
	return this.products_data[productID];
}

function slPrint()
{
	var productID = 0;
	var product = new Array();
	
	this.printHeader();
	if(this.products.length>0)
	{
		for(var i=0; i<this.products.length; i++)
		{
			productID = this.products[i];
			product = this.getProductData(productID);
			if(product)
			{
				this.printRow(product);
			}
		}
		if(this.row_num%2!=0)
		{
			this.printSpacer();
		}
	}
	else
	{
		this.printRowEmpty();
	}
	
	this.printFooter();
	
	document.write(this.output);
}

function slDoAction()
{
	switch(this.action)
	{
		case 'add' : this.onAdd(); break;
		case 'delete' : this.onDelete(); break;
		default : '';
	}
}

function slOnDelete()
{
	var productID = this.page.urlArray['params'].get('produktID');
	this.del(productID);
}

function slDel(productID)
{
	if(productID)
	{
		if(this.products.length>0)
		{
			var newProducts = new Array();
			for(var i=0; i<this.products.length; i++)
			{
				if(this.products[i]!=productID)
				{
					newProducts[newProducts.length] = this.products[i];
				}
			}
			this.products = newProducts;
		}
	}
}

//-->
