// SMCrunch2 Version 2.0.1, Copyright (C) Smart Media Ltd 2001-2005. All Rights Reserved.
//
// !!! Note: JScript by default
//
/// (c) Copyright Smart Media Limited, 2008-2009.
///
///This Software is provided under a license and may not be modified, copied or altered in any
///way by Licensee's own personnel or by any third party. This Software or parts of it,
///or its documentation may not be provided, copied, printed out or otherwise made available to
///any other person. Any attempt to copy, modify or reverse engineer the Software is strictly
///prohibited.
///
///This Software may only be used on the equipment it is licensed for.
///
///Title, copyright and all other proprietary rights in the Software and the Documentation and all
///parts and copies thereof shall remain vested with Smart Media Limited.
///
///This Software and information in it is subject to change without notice.
function getBasket()
{
var c = ''+document.cookie;
var btest = c.match(/smbskt=([A-Za-z0-9,:]*)(;|$)/);
var b = null;
if( btest != null )
b = btest[1];
var ba = new Array();
if( b != null )
{
var bs = b.split(',');
for( var i=0; i< bs.length; i++ )
{
var bps = bs[i].split(':');
if( bps != null )
{
var cq = parseInt(bps[1],10);
if( cq != null && !isNaN(cq) && cq > 0 )
{
ba[bps[0]] = cq;
}
}
}
}
return ba;
}
function saveBasket(ba)
{
var bstr = '';
var count = 0;
for( var i in ba )
{
if( ba[i] != null )
{
if( count > 0 )
bstr += ',';
bstr += i+':'+ba[i];
count++;
}
}
document.cookie = 'smbskt='+bstr;
}
function displayBasketCount()
{
var basketfilled = document.getElementById('basketfilled');
var basketfilled2 = document.getElementById('basketfilled2');
var basketempty = document.getElementById('basketempty');
var basketempty2 = document.getElementById('basketempty2');
var basketcount = document.getElementById('basketcount');
var ba = getBasket();
var count = 0;
var vs = 'block';
if( typeof basketdisplay != 'undefined' && basketdisplay != null ) vs = basketdisplay;
for( var i in ba )
{
if( ba[i] > 0 ) count+=ba[i];
}
if( count == 0 )
{
if( basketfilled != null )	basketfilled.style.display = 'none';
if( basketfilled2 != null )	basketfilled2.style.display = 'none';
if( basketempty != null )	basketempty.style.display = vs;
if( basketempty2 != null )	basketempty2.style.display = vs;
}
else
{
if( basketfilled != null )	basketfilled.style.display = vs;
if( basketfilled2 != null )	basketfilled2.style.display = vs;
if( basketempty != null )	basketempty.style.display = 'none';
if( basketempty2 != null )	basketempty2.style.display = 'none';
}
if( basketcount != null )
{
basketcount.innerHTML = ''+count+' item'+(count==1?'':'s');
}
}
function addToBasket(prodcode)
{
if( prodcode == null )
return;
var q = document.getElementById('q_'+prodcode);
var qval = 1;
if( q != null )
{
qval = parseInt(q.value,10);
if( isNaN(qval) )
qval = 0;
}
if( qval <= 0 )
{
alert('You entered an invalid quantity');
return;
}
var ba = getBasket();
if( ba[prodcode] != null )
ba[prodcode] += qval;
else
ba[prodcode] = qval;
if( typeof basketmaxqty == 'number' && ba[prodcode] > basketmaxqty )
ba[prodcode] = basketmaxqty;
saveBasket(ba);
displayBasketCount();
}
function removeFromBasket(prodcode)
{
if( prodcode == null )
return;
var ba = getBasket();
if( ba[prodcode] != null )
ba[prodcode] = null;
saveBasket(ba);
displayBasketCount();
}
function displayBasket()
{
displayBasketCount();
var basket = document.getElementById('basket');
if( basket == null )
{
return;
}
var ba = getBasket();
var count = 0;
var bstr = '';
for( var i in ba )
{
if( ba[i] > 0 )
{
if( count == 0 )
{
bstr = '<table cellpadding="0" cellspacing="0" border="0" class="basket">'+
'<tr><th>Productcode</th><th>Quantity</th></tr>';
}
bstr += '<tr><td>'+i+'</td><td>'+ba[i]+'</td></tr>';
count += ba[i];
}
}
if( count > 0 )
bstr += '</table>';
alert(bstr);
basket.innerHTML = bstr;
}
if( window.addEventListener )
window.addEventListener('load',displayBasket,false);
else if( window.attachEvent)
window.attachEvent('onload',displayBasket);

