function recalculateSubtotal (subItem)
{
  totalPrice = 0;

  for ( a = 0; a < document.forms [ 'shopCart' ].elements.length; a ++ )
  {
    if ( document.forms [ 'shopCart' ].elements [ a ].name.indexOf ( 'pieces[' ) != -1)
    {
      id = document.forms [ 'shopCart' ].elements [ a ].name.substring ( 7, document.forms [ 'shopCart' ].elements [ a ].name.length - 1 );
      price = document.forms [ 'shopCart' ].elements [ a ].value * document.getElementById ( 'piecePrice_' + id ).value;

      if ( !isNaN ( document.forms [ 'shopCart' ].elements [ a ].value ) )
        totalPrice += price;

      document.getElementById ( 'totalPrice_' + id ).innerHTML = number_format ( price, 2, ',', '.' );
    }

    if ( document.forms [ 'shopCart' ].elements [ a ].name.indexOf ( 'piecesInsurance[' ) != -1)
    {
      id = document.forms [ 'shopCart' ].elements [ a ].name.substring ( 16, document.forms [ 'shopCart' ].elements [ a ].name.length - 1 );

      if(document.forms['shopCart'].elements['insurance['+id+']'].checked) {

        if(parseInt(document.forms [ 'shopCart' ].elements [ a ].value) > parseInt(document.forms [ 'shopCart' ].elements [ 'pieces['+id+']' ].value)) {
          document.forms [ 'shopCart' ].elements [ a ].value = document.forms [ 'shopCart' ].elements [ 'pieces['+id+']' ].value;
        }

        price = document.forms [ 'shopCart' ].elements [ a ].value * document.getElementById ( 'piecesInsurancePrice_' + id ).value;

        if ( !isNaN ( document.forms [ 'shopCart' ].elements [ a ].value ) )
          totalPrice += price;

        document.getElementById ( 'piecesInsuranceTotal_' + id ).innerHTML = number_format ( price, 2, ',', '.' );
      } else {
        document.getElementById ( 'piecesInsuranceTotal_' + id ).innerHTML = number_format ( 0, 2, ',', '.' );
      }
    }

    if ( document.forms [ 'shopCart' ].elements [ a ].name.indexOf ( 'piecesInsuranceTrans[' ) != -1)
    {
      id = document.forms [ 'shopCart' ].elements [ a ].name.substring ( 21, document.forms [ 'shopCart' ].elements [ a ].name.length - 1 );

      if(document.forms['shopCart'].elements['insuranceTrans['+id+']'].checked) {

        if(parseInt(document.forms [ 'shopCart' ].elements [ a ].value) > parseInt(document.forms [ 'shopCart' ].elements [ 'piecesInsurance['+id+']' ].value)) {
          document.forms [ 'shopCart' ].elements [ a ].value = document.forms [ 'shopCart' ].elements [ 'piecesInsurance['+id+']' ].value;
        }

        price = document.forms [ 'shopCart' ].elements [ a ].value * document.getElementById ( 'piecesInsuranceTransPrice_' + id ).value;

        if ( !isNaN ( document.forms [ 'shopCart' ].elements [ a ].value ) )
          totalPrice += price;

        document.getElementById ( 'piecesInsuranceTransTotal_' + id ).innerHTML = number_format ( price, 2, ',', '.' );
      } else {
        document.getElementById ( 'piecesInsuranceTransTotal_' + id ).innerHTML = number_format ( 0, 2, ',', '.' );
      }
    }

    document.getElementById ( 'subtotalPrice' ).innerHTML = number_format ( totalPrice, 2, ',', '.' );
  }
}

function number_format ( price, i, sep, thousand )
{
  if ( isNaN ( price ) || price < 0 )
    price = 0;

  if ( parseInt ( price ) != price )
  {
    eur = parseInt ( price );
    cent = Math.round ( ( price - eur ) * 100 );

    if ( cent < 10 )
      cent = '0' + cent;

  }
  else
  {
    eur = price;
    cent = '00';
  }

  if ( eur > 0 )
  {
    t = eur + '';

    eur = '';
    while ( t.length > 3 )
    {
      eur = thousand + t.substring ( t.length - 3, t.length ) + eur;
      t = t.substring ( 0, t.length - 3 );
    }
    if ( t > 0 )
      eur = t + eur;
  }
  else
    eur = '0';

  return eur + sep + cent;
}

function viewImage( url, alt, obj )
{
  if( !$( 'viewImage' ) )
  {
    var div = new Element( 'div' );
    div.setProperty( 'id', 'viewImage' );
    div.setOpacity( 0 );
    div.setStyles( {
      'position':'absolute',
      'left': '0px',
      'top': '0px',
      'width': window.getWidth() + 'px', 
      'height': window.getScrollHeight() + 'px',
      'text-align':'center'
    } );
    div.addEvent( 'click', function( ){ viewImageClose( ) } );
    
    var divImg = new Element( 'div' );
    
    var img = new Element( 'img' );
    img.setProperty( 'alt', alt );
    img.setProperty( 'src', url );
    
    var x = new Element( 'span' );
    x.setHTML( 'sluiten X' );
    x.setStyles( {
      'position':'absolute',
      'right':'5px',
      'top':'5px',
      'color':'black',
      'font-weight':'bold',
      'cursor':'pointer'
    } );
    
    x.injectInside( divImg );
    img.injectInside( divImg );
    divImg.injectInside( div );
    div.injectInside( document.body );
  }

  //$$( '#viewImage img' ).setProperty( 'src', url );

  t = window.getScrollTop() + 100 + 'px';
  $$( '#viewImage div' ).setStyle( 'top', t );

  ( function(){
      l = divImg.getCoordinates();
      l = Math.round( ( window.getWidth() - l.width ) / 2 ) + 'px';
      divImg.setStyle('left', l);
    }
  ).delay(10);

  new Fx.Style( 'viewImage', 'opacity', { duration:500 } ).start( 0, 1 );
  
  return false;
}

function viewImageClose( )
{
  if( $( 'viewImage' ) )
  {
    new Fx.Style( 'viewImage', 'opacity', { duration:500, onComplete: function() {
      $( 'viewImage' ).remove( )
    } } ).start( 1, 0 );
  }
}

function detailZoom( image )
{
	if( ( zoom = $('detailZoom') ) )
	{

		if( image == 2 ) {
			setExample(example2);
		} else {
			setExample(example1);
		}

		zoom.setStyles( {
			'display': 'block',
			'opacity':0
		} );

		new Fx.Style( 'detailZoom', 'opacity', { duration:500 } ).start( 1 );

		if( window.ie6 ) {
			$$('select').setStyle('visibility','hidden');
		}

		return false;
	}
}

function detailZoomClose()
{
	if( ( zoom = $('detailZoom') ) )
	{
		new Fx.Style( 'detailZoom', 'opacity', { duration:500, onComplete: function() {
			zoom.setStyle('display', 'none');
		} } ).start( 0 );
		if( window.ie6 ) {
			$$('select').setStyle('visibility','visible');
		}
		return false;
	}
}

function sizeInfo()
{
	if( ( zoom = $('sizeInfo') ) )
	{

		zoom.setStyles( {
			'display': 'block',
			'opacity':0
		} );

		new Fx.Style( 'sizeInfo', 'opacity', { duration:500 } ).start( 1 );

		if( window.ie6 ) {
			$$('select').setStyle('visibility','hidden');
		}

		return false;
	}
}

function sizeInfoSwithTab(id)
{
	$$('.sizeContent').setStyle('display', 'none');
	$('sizeContent-'+id).setStyle('display', '');

	return false;
}

function sizeInfoClose()
{
	if( ( zoom = $('sizeInfo') ) )
	{
		new Fx.Style( 'sizeInfo', 'opacity', { duration:500, onComplete: function() {
			zoom.setStyle('display', 'none');
		} } ).start( 0 );
		if( window.ie6 ) {
			$$('select').setStyle('visibility','visible');
		}
		return false;
	}
}


window.addEvent('domready', function() {
	var tips = new Tips($$('.Tips1'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
});
