/*
 * Variable 'baseUrl' is global variable which is set dynamically in the header
 */

function do_toggleShop (action, idx, params) {

	//alert( 'Webshop actie: '+action+' : '+idx+' : '+params );

	x_toggleShop(action, idx, params, writeContentDealer);
	//document.getElementById('product'+idx+'-content').innerHTML = '<a href="'+dealerBaseUrl+dealerOrderPage+'">Wijzig aantal</a>';
	//document.getElementById('product'+idx+'-image').source = 'test.jpg';
	
} 

function writeContentDealer ( content ) {

    // fix the content string
	content = new String(content);
	content = trim( content );
	content = escape( content );
	content = content.replace( /%0A/g, "g" );
	content = content.replace( /%26/g, "&" );
	content = content.replace( /%20/g, " " );
	content = content.replace( /%3B/g, ";" );

    if ( content == 'add' ) {
        //alert( 'Uw item is toegevoegd aan de bestellijst' );

    } else if ( content == 'alter' ) {
		//alert( 'Uw item is gewijzigd' );
		window.location = dealerBaseUrl+dealerOrderPage;

	} else if ( content == 'addpay' ) {
		//alert( 'Uw item is toegevoegd' );
		window.location = dealerBaseUrl+dealerOrderPage;

	} else if ( content == 'clear' ) {
		//alert("jump");
		//window.location = baseUrl+'This-151_Besteloverzicht.html';

	} else if ( content == 'remove' ) {
		//alert("jump after remove "+dealerBaseUrl+dealerOrderPage);
		window.location = dealerBaseUrl+dealerOrderPage;

	} else if ( content == 'opbouwkostenclientkeuze' ) {
		//alert( 'Uw opbouwkosten zijn gewijzigd' );
	    //alert('refresh the page');
		window.location = dealerBaseUrl+dealerOrderPage;

	} else if ( content == 'settimerange' ) {
		window.location = dealerBaseUrl+dealerOrderPage;

	} else {
        //alert( "Webshop fout: " + content );
        
    }
}

/**
 * Trim the leading spaces from a String
 */
function trim( str )
{
    // trim leading spaces
    var i;
    for ( i = 0; i < str.length; i++ )
    {
        if (   str.charAt( i ) == "\n"
            || str.charAt( i ) == "\r"
            || str.charAt( i ) == "\t"
            || str.charAt( i ) == " "
            || str.charCodeAt( i ) > 255 )
            continue;
        break;
    }
    return str.substring( i );
}

/**
 * Time Range Picker for the shopping basket
 */
var TimeRangePicker = new Class({

	initialize: function( idx, container, starttime, endtime ) {
		
		this.idx = idx;
		this.container = container;
	
		// setup layout
		container.appendChild( new Element( "div", { "html": "Van: ", "styles": { "float": "left" } } ) );
		container.appendChild( this.starttime = new Element( "div", {"styles": {"float":"left"}} ) );
		container.appendChild( new Element( "div", { "html": "&nbsp;tot:&nbsp;", "styles": { "float": "left" } } ) );
		container.appendChild( this.endtime = new Element( "div", {"styles": {"float":"left"}} ) );
		container.appendChild( new Element( "div", {"styles": {"clear":"both"}} ) );
		
		// create start time picker
		this.startpicker = new TimePicker( this.starttime, false, starttime );		
		this.startpicker.addSetEvent( function( ) {
			this.updatePrices();
		}.bind( this ) );
		
		// create end time picker
		this.endpicker = new TimePicker( this.endtime, false, endtime );
		this.endpicker.addSetEvent( function( ) {
			this.updatePrices();
		}.bind( this ) );	
	},

	updatePrices: function( ) {
		
		var starttime = this.startpicker.getTime();
		var endtime = this.endpicker.getTime();
		
		if ( starttime == null || endtime == null )
			return;
		
		do_toggleShop( "settimerange", this.idx, starttime + "," + endtime ); 
	}
});





















 