
/// <reference path="jquery-1.2.6-vsdoc.js"/>

function clearInput(obj, samplevalue) {
    if ($(obj).val() == samplevalue) {
        $(obj).val('');
    }
    $(obj).removeClass("default");
}

function fillInput(obj, samplevalue) {
    if ($(obj).val() == "") {
        $(obj).val(samplevalue);
        $(obj).addClass("default");
    }
}

function FormMailToUserView() 
{
    this.email = null;
}

function FormMailToStageView()
{
    this.companyName = null;
    this.prefixName = null;
    this.firstName = null;
    this.middleName = null;
    this.lastName = null;
    this.email = null;
    this.phoneNumber = null;
    this.specialRemarks = null;
}

Number.prototype.toCurrency = function() {
    var intPart = this.toString();
    var decPart = "0";
    if (intPart.indexOf('.') != -1) {
        var parts = intPart.split('.');
        intPart = parts[0];
        decPart = parts[1];
    }
	if (decPart.length == 0) {
	    decPart = '00';
	}
	else if (decPart.length == 1) {
		decPart += '0';
	} 
	else if (decPart.length > 2) {
	    decPart = decPart.substr(0,2);
	}
	return intPart.toString() + ',' + decPart.toString();
}

//var articles = [];

$(document).ready(function() {

    $('#boxOpenSlider').click(function() {
        $('#ajaxLoader').show();
        cp.fillDetailedPriceReport(cp.getConfigurator().getDetailedPriceReport());
        $('#ajaxLoader').hide();
        $('#boxCloseSlider').show();
        $('#boxOpenSlider').hide();
        $("#expandedBlock").show('slide', { direction: 'right' }, 1000);
    });

    $('#boxCloseSlider').click(function() {
        $("#expandedBlock").hide('slide', { direction: 'right', distance: 480 }, 1000, function() {
            $('#boxCloseSlider').hide();
            $('#boxOpenSlider').show();
        });
    });

    $('.popupForm :text').add('.popupForm textarea').addClass('default');

    // here starts golden's code
    var IsFormLocked = false;

    var ConfiguratorProcessor = function() {

        var formIsLocked = false;
        var prodDrop = $('#productionsList');
        var dateDrop = $('#datesList');
        var locDrop = $('#locationsList');
        var amountTxt = $('#amountOfPersons');
        var resetBtn = $('#resetBtn');
        var startBtn = $('#startBtn');
        var ajaxLoader = $('#ajaxLoader');
        var calendarProductId = null;
        var articles = [];
        var currentShowedTip = null;
        var currentShowedPopup = null;
        var basisServicesTitle = 'Basis';
        var extraServicesTitle = 'Extra services';

        var fillForm = function() {
            ajaxLoader.show();
            fillDropDown(prodDrop, conf.getProductionsList(null, null));
            prodDrop.attr('disabled', false);
            fillDropDown(dateDrop, conf.getDatesList(null, null));
            dateDrop.attr('disabled', false);
            fillDropDown(locDrop, conf.getLocationsList(null, null));
            locDrop.attr('disabled', false);
            amountTxt.attr('disabled', false);
            ajaxLoader.hide();
        }

        var showPopup = function(name) {
            if (currentShowedPopup && currentShowedPopup == name) {
                $('#' + name).hide();
                currentShowedPopup = null;
                return;
            }
            ie6fixApply();
            $('#' + name).show();
            currentShowedPopup = name;
        }

        var showProductionThumbnail = function(urlPicture) {
            if ($('#productImage', parent.document).size() > 0) {
                html = '<img src="' + urlPicture + '" />';
                $('#productImage', parent.document).html(html);
            }
        }

        var bindHandlers = function() {
            prodDrop.change(function() {
                if ($(this).val() == '') return;
                showProductionThumbnail(conf.getProductionThumbnail($(this).val()));
                if (checkFormFilling()) return lockForm(this);
                ajaxLoader.show();
                fillDropDown(dateDrop, conf.getDatesList(prodDrop.val(), nullize(locDrop.val())));
                fillDropDown(locDrop, conf.getLocationsList(prodDrop.val(), nullize(dateDrop.val())));
                ajaxLoader.hide();
            });
            dateDrop.change(function() {
                if ($(this).val() == '') return;
                if (checkFormFilling()) return lockForm(this);
                ajaxLoader.show();
                fillDropDown(prodDrop, conf.getProductionsList(nullize(locDrop.val()), dateDrop.val()));
                fillDropDown(locDrop, conf.getLocationsList(nullize(prodDrop.val()), dateDrop.val()));
                ajaxLoader.hide();
            });
            locDrop.change(function() {
                if ($(this).val() == '') return;
                if (checkFormFilling()) return lockForm(this);
                ajaxLoader.show();
                fillDropDown(prodDrop, conf.getProductionsList(locDrop.val(), nullize(dateDrop.val())));
                fillDropDown(dateDrop, conf.getDatesList(nullize(prodDrop.val()), locDrop.val()));
                ajaxLoader.hide();
            });
            amountTxt.keypress(function(e) {
                if ($.inArray(e.which, [null, 0, 8, 9, 13, 27]) != -1) return true;
                var keyChar = String.fromCharCode(e.which);
                if (("0123456789").indexOf(keyChar) != -1) return true;
                e.preventDefault();
                return false;
            });
            resetBtn.click(function() { resetForm() });
            startBtn.click(function() { startForm() });
            //$('#mailToStageBtn').click(function(){showPopup('mailToStageForm');});
            $('.popupBtn').click(function() {
                showPopup($(this).attr('id').replace('Btn', 'Popup'));
            });
            //$('.closePopupBtn').click()
            $('.closeBtn').click(function() {
                showPopup($(this).attr('id').replace('Close', ''));
            });

            var requiredValidator = function(field, prop, data, defaultData, form) {
                data[prop] = $.trim($('[name=' + field + ']', form).val());

                if (data[prop] == null || data[prop] == '' || data[prop] == defaultData[prop]) {
                    $('[name=' + field + ']', form).css('color', 'red');
                    return false;
                }
                else {
                    $('[name=' + field + ']', form).css('color', 'black');
                    return true;
                }
            }

            var readAndCleanIfDefault = function(field, prop, data, defaultData, form) {
                data[prop] = $.trim($('[name=' + field + ']', form).val());
                if (data[prop] == defaultData[prop]) {
                    data[prop] = '';
                }
            }

            $('#mailToStageSubmit').click(function() {
                var data = new FormMailToStageView();
                var defaultData = { companyName: 'bedrijfsnaam', prefixName: 'Dhr.', firstName: 'voornaam', middleName: 'tussenvoegsel', lastName: 'achternaam', email: 'emailadres', phoneNumber: 'telefoonnummer', specialRemarks: 'Is uw evenement geheim voor uw collega’s of heeft u nu al specifieke opmerkingen?' };
                var form = $('#mailToStagePopup form');
                var formIsValid = true;
                formIsValid &= requiredValidator('bedrijfsnaam', 'companyName', data, defaultData, form);
                //formIsValid &= requiredValidator('dhr','prefixName',data,defaultData,form);
                readAndCleanIfDefault('dhr', 'prefixName', data, defaultData, form);
                formIsValid &= requiredValidator('voornaam', 'firstName', data, defaultData, form);
                //formIsValid = requiredValidator('tussenvoegsel','middleName',data,defaultData,form);
                readAndCleanIfDefault('tussenvoegsel', 'middleName', data, defaultData, form);
                formIsValid &= requiredValidator('achternaam', 'lastName', data, defaultData, form);
                formIsValid &= requiredValidator('email', 'email', data, defaultData, form);
                formIsValid &= requiredValidator('telephone2', 'phoneNumber', data, defaultData, form);
                readAndCleanIfDefault('remarks', 'specialRemarks', data, defaultData, form);
                if (formIsValid) {
                    $('#inProgressPopup').show();
                    $('#mailToStagePopup').hide();
                    conf.mailToStage(data,
                        function() {
                            $('#inProgressPopup').hide();
                            showPopup('mailToStagePopupThx');
                            $.get('bedankt_mail_stage.html');
                        }
                    );
                }
            });
            $('#mailToUserSubmit').click(function() {
                var data = new FormMailToUserView();
                var defaultData = { email: 'emailadres' };
                var form = $('#mailToUserPopup form');
                var formIsValid = true;
                formIsValid &= requiredValidator('email', 'email', data, defaultData, form);
                if (formIsValid) {
                    $('#inProgressPopup').show();
                    $('#mailToUserPopup').hide();
                    conf.mailToUser(data,
                        function() {
                            $('#inProgressPopup').hide();
                            showPopup('mailToUserPopupThx');
                            $.get('bedankt_mail_user.html');
                        }
                    );
                }
            });
            $('#printBtn').click(function() {
                var pdfUrl = conf.pdfCurrent();
                var w = window.open(pdfUrl, '_print');
                /*w.document.open();
                w.document.write(html);
                w.document.close();
                w.print();*/
            });
            $('#showLink a').click(function() {
                if ($('#moreInfoBox').is(':hidden')) {
                    $('#moreInfoBox').show();
                }
                else {
                    $('#moreInfoBox').hide();
                }
            })
            $(document).bind('click', function(e) {
                var clicked = $(e.target)
                if ($.browser.msie) {
                    if (clicked.is('.info_button')) {
                        if (!currentShowedTip) return;
                        $('a.info_button:not([href$=' + currentShowedTip + ']) div.tooltip:visible').hide();
                    }
                    else {
                        if (currentShowedTip) {
                            $('div.tooltip').hide();
                            currentShowedTip = null;
                            ie6fixUndo();
                        }
                    }
                }
                if (clicked.closest('.popupForm').size() != 0) return;
                if (clicked.is('.popupBtn')) {
                    if (!currentShowedPopup) return;
                    $('.configuratorPopup:not(#' + currentShowedPopup + ')').hide();
                }
                else {
                    if (currentShowedPopup) {
                        $('div.configuratorPopup').hide();
                        currentShowedPopup = null;
                        ie6fixUndo();
                    }
                }
            });
        }

        var bindTooltipsHandlers = function() {

            var r_hrefId = /(#tooltip[0-9]+)$/i;
            var match = r_hrefId.exec($(this).attr('href'));
            $(this).simpletip(
                {
                    persistent: true,
                    content: $(match[1]).html(),
                    fixed: true,
                    position: 'bottom',
                    onShow: function() {
                        ie6fixApply();
                        if ($.browser.msie) {
                            currentShowedTip = match[1];
                        }
                    },
                    onHide: function() {
                        ie6fixUndo();
                    }
                }
            )
        };

        var bindTooltipsHandlersForProceReport = function() {

            var r_hrefId = /(#tooltip[0-9]+)$/i;
            var match = r_hrefId.exec($(this).attr('href'));
            $(this).simpletip(
                {
                    persistent: true,
                    content: $(match[1]).html(),
                    fixed: true,
                    position: [-190, 0],
                    onShow: function() {
                        ie6fixApply();
                        if ($.browser.msie) {
                            currentShowedTip = match[1];
                        }
                    },
                    onHide: function() {
                        ie6fixUndo();
                    }
                }
            )
        };

        var ie6fixApply = function() {
            if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
                $('select').hide();
            }
        }

        var ie6fixUndo = function() {
            if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
                $('select').show();
            }
        }

        var fillDropDown = function(dropDown, values) {
            var curVal = dropDown.val();
            $('option', dropDown).remove();
            dropDown[0].options.add(new Option('', ''));
            $.each(values, function(i, val) {
                dropDown[0].options.add(new Option(val, i));

            });
            if (curVal != undefined && curVal != null) dropDown.val(curVal);
        }

        var nullize = function(val) {
            if ($.trim(val) == '') return null;
            return val;
        }

        var checkFormFilling = function() {
            if (prodDrop.val() != '' && dateDrop.val() != '' && locDrop.val() != '') return true;
            return false;
        }

        var calendarProductionId = null;

        var lockForm = function(dropObj) {
            var drop = $(dropObj);
            if (!drop.is('#' + prodDrop.attr('id'))) $('option:not([value=' + prodDrop.val() + '])', prodDrop).remove();
            if (!drop.is('#' + dateDrop.attr('id'))) $('option:not([value=' + dateDrop.val() + '])', dateDrop).remove();
            if (!drop.is('#' + locDrop.attr('id'))) $('option:not([value=' + locDrop.val() + '])', locDrop).remove();
            calendarProductionId = drop.val();
            resetBtn.show();
        }

        var startForm = function() {
            if (IsFormLocked) return;
            if (prodDrop.val() == '') {
                alert('Selecteert u een productie');
                prodDrop.focus();
                return;
            }
            if (dateDrop.val() == '') {
                alert('Selecteert u een datum');
                dateDrop.focus();
                return;
            }
            if (locDrop.val() == '') {
                alert('Selecteert u een locatie');
                locDrop.focus();
                return;
            }
            if (amountTxt.val() == '') {
                alert('Vult u het aantal personen in');
                amountTxt.focus();
                return;
            }
            if (amountTxt.val() < 10) {
                alert('U kunt geen arrangement voor minder dan 10 personen samenstellen');
                amountTxt.focus();
                return;
            }
            prodDrop.attr('disabled', true);
            dateDrop.attr('disabled', true);
            locDrop.attr('disabled', true);
            var amount = amountTxt.val();
            amountTxt.attr('disabled', true);
            IsFormLocked = true;
            //$('#startPanel').hide();
            ajaxLoader.show();
            fillArticles(conf.createNew(calendarProductionId, amount));
            fillPriceReport(conf.getPriceReport());
            ajaxLoader.hide();
        }

        var resetForm = function resetForm() {
            //if (!IsFormLocked) return;
            fillForm();
            prodDrop.val('');
            dateDrop.val('');
            locDrop.val('');
            prodDrop.attr('disabled', false);
            dateDrop.attr('disabled', false);
            locDrop.attr('disabled', false);
            amountTxt.attr('disabled', false);
            IsFormLocked = false;
            resetBtn.hide();
            $('#contentOnzeSuggestie').hide();
            $('#priceReport').empty();
            $('#tooltipsCollection').empty();
            $('#expandedBoxContent').empty();
            $('#stickedBox').hide();
            $('#reportTitle').text('Onze suggestie:');
            calendarProductionId = null;
            //$('#startPanel').show();
            $('#stickedBoxStab').show();
            //$('#disclaimerContent').show();
        }

        var sanitizeCatName = function(name) {
            return name.toLowerCase().replace(/[^a-z]+/g, '');
        }

        var randomString = function(len) {
            var letters = 'qwertyuiopasdfghjklzxcvbnm1234567890';
            var res = '';
            while (res.length < len) {
                var i = parseInt(Math.random() * letters.length);
                res += letters[i];
            }
            return res;
        }

        var fillArticles = function(articlesList) {

            $('#stickedBoxStab').hide();
            //$('#disclaimerContent').hide();

            var idArtDiv = randomString(10);

            var artHtml = '<div id="' + idArtDiv + '">';
            var tipsHtml = '';
            $.each(articlesList, function(iCat, vCat) {
                if (vCat.title == basisServicesTitle) return;
                artHtml += '<div id="level_1_' + (iCat + 1) + '"> <a class="linkList arrow_open" href="#" onclick="return false"><span class="form_title '
                    + sanitizeCatName(vCat.title) + '">'
                    + vCat.title + '</span></a>';
                artHtml += '<div class="level2" id="level_2_'
                    + (iCat + 1)
                    + '"><div class="content_form">'
                    + '<form id="formCat' + vCat.articleCategoryId + '"><table>'
                if (vCat.title == extraServicesTitle) {
                    artHtml += '<tr><td colspan="5"></td>'
                        + '<td>Aantal personen:</td>'
                        + '</tr>';
                }
                $.each(vCat.articles, function(iArt, vArt) {
                    articles = $.merge(articles, $.makeArray(vArt));
                    artHtml += '<tr id="rowArt_' + vArt.articleId + '"'
                        + (vArt.isDisabled ? ' style="display:none"' : '')
                        + '>';
                    if (vCat.title != extraServicesTitle) {
                        artHtml += '<td class="colWithRadio"><input type="radio" name="cat'
                            + vCat.articleCategoryId
                            + '" value="'
                            + vArt.articleId
                            + '"'
                            + (vArt.isChecked ? ' checked' : '')
                            + '/></td>';
                    }
                    else {
                        artHtml += '<td><input type="checkbox" name="cat'
                            + vCat.articleCategoryId + '_art'
                            + vArt.articleId
                            + '" id="cat'
                            + vCat.articleCategoryId + '_art'
                            + vArt.articleId
                            + '" /></td>';
                    }
                    artHtml += '<td>' + vArt.title + '</td><td>'
                            + '<a href="#tooltip'
                            + (iCat + 1) + '' + (iArt + 1)
                            + '" onclick="return false;" class="info_button png" alt="Info"></a>'
                            + '</td>';

                    if (vCat.title != extraServicesTitle || !vArt.isPriceHidden) {
                        artHtml += '<td>&euro;</td><td class="colWithPrice">'
                            + vArt.pricePerPerson.toCurrency() + '</td>';
                    }
                    else {
                        artHtml += '<td>&nbsp;</td><td>&nbsp;</td>';
                    }

                    if (vCat.title == extraServicesTitle) {
                        if (!vArt.isAmountOfPersonsHidden) {
                            artHtml += '<td class="colWithAmountEnter"><input type="text" id="amount_cat'
                                + vCat.articleCategoryId + '_art'
                                + vArt.articleId + '" name="amount_cat'
                                + vCat.articleCategoryId + '_art'
                                + vArt.articleId
                                + '" value="'
                                + vArt.amountOfPersons
                                + '" size="2" maxlength="4" min="'
                                + vArt.minAmountOfPersons + '" max="'
                                + vArt.maxAmountOfPersons
                                + '" /></td>';
                        }
                        else {
                            artHtml += '<td>&nbsp;</td>';
                        }
                    }
                    artHtml += '</tr>';
                    tipsHtml += '<div id="tooltip'
                        + (iCat + 1) + '' + (iArt + 1)
                        + '" class="tooltip_block"><div class="tooltip_content">'
                        + (vArt.urlPicture != '' ? '<p><img src="' + vArt.urlPicture + '" /></p>' : '')
                        + '<p>' + vArt.textBalloon
                        + '</p><a href="javascript:void(0)" class="bottom">Sluit venster</a></div></div>';
                });
                artHtml += '</table>';
                if (vCat.title == extraServicesTitle) {
                    artHtml += '<div id="instructionsBox" class="instructionsBoxCollapsed">'
                        + $('#instructionsBoxPrototype').html()
                        + '</div>';
                }
                artHtml += '</form></div></div>';
                artHtml += '</div>';
            });
            artHtml += '</div>';
            $('#contentOnzeSuggestie').html(artHtml).show();
            $('#' + idArtDiv).accordion({ header: 'a.linkList', autoHeight: false });
            $('#tooltipsCollection').html(tipsHtml);
            $('#contentOnzeSuggestie .info_button').each(bindTooltipsHandlers);
            $('#contentOnzeSuggestie :radio')
                .click(function(e) { radioChecked(e) });
            $('#contentOnzeSuggestie :checkbox').mousedown(function(e) {
                var el = $(this);
                var r_artId = /^cat[0-9]+_art([0-9]+)$/i;
                var match = r_artId.exec(el.attr('id'));
                var artId = parseInt(match[1]);
                if (el.is(':checked')) {
                    fillPriceReport(conf.articleIsUnchecked(artId));
                }
                else {
                    var txtEl = $('#amount_' + el.attr('id'));
                    if (txtEl.size() == 0) {
                        fillPriceReport(conf.articleIsChecked(artId, -1));
                    }
                    else {
                        if (!checkEnteredAmount(txtEl)) {
                            el.one('click', function(e) {
                                $(this).attr('checked', false);
                            });
                            return;
                        }
                        fillPriceReport(conf.articleIsChecked(artId, txtEl.val()));
                    }
                }
            });
            var timers = {};
            $('#contentOnzeSuggestie :text')
		        .keypress(function(e) {
		            if ($.inArray(e.which, [null, 0, 8, 9, 13, 27]) != -1) return true;
		            var keyChar = String.fromCharCode(e.which);
		            if (("0123456789").indexOf(keyChar) != -1) return true;
		            e.preventDefault();
		            return false;
		        })
		        .keyup(function() {
		            var el = $(this);
		            var r_artId = /^amount_cat[0-9]+_art([0-9]+)$/i;
		            var match = r_artId.exec(el.attr('id'));
		            var artId = parseInt(match[1]);
		            var chEl = $('#' + el.attr('id').replace('amount_', ''));

		            if (checkEnteredAmount(el)) {
		                if (timers[artId] != undefined && timers[artId] != null) { clearTimeout(timers[artId]); }
		                var curVal = el.val();
		                timers[artId] = setTimeout(function() { fillPriceReport(conf.articleIsChecked(artId, curVal)); chEl.attr('checked', true) }, 1000);
		            }
		            else {
		                if (!chEl.is(':checked')) return;
		                if (timers[artId] != undefined && timers[artId] != null) { clearTimeout(timers[artId]); }
		                timers[artId] = setTimeout(function() { fillPriceReport(conf.articleIsUnchecked(artId)); chEl.attr('checked', false) }, 1000);
		            }
		        })
		        .blur(function() {
		            var el = $(this);
		            var chEl = $(':checkbox', el.parent().parent());
		            if (el.is('.wrongFilled') && chEl.is(':checked')) {
		                chEl.attr('checked', false).triggerHandler('click');
		            }
		        });
            $('#instructionsBox .instructionsTitle').click(function() {
                $(this).parent().toggleClass('instructionsBoxCollapsed').toggleClass('instructionsBoxExpanded');
            });
            $('#instructionsBox .popupInstructBtn').click(function() {
                $('#' + $(this).attr('id').replace('InstructBtn', 'Btn')).click();
            });
        }

        function checkEnteredAmount(el) {
            var curVal = el.val();
            if (curVal == '') return false;
            var min = parseInt(el.attr('min'));
            if (curVal < min) { el.addClass('wrongFilled').attr('title', 'TE WEINIG!!!'); return false; }
            var max = parseInt(el.attr('max'));
            if (curVal > max) { el.addClass('wrongFilled').attr('title', 'TE VEEL!!!'); return false; }
            el.removeClass('wrongFilled').attr('title', '');
            return true;
        }

        var radioChecked = function(e) {
            var artId = $(e.target).val();
            if ($(e.target).is(':checked')) {
                fillPriceReport(conf.articleIsChecked(artId, -1));
            }
            else {
                fillPriceReport(conf.articleIsUnchecked(artId));
            }
            $('#reportTitle').text('Uw arrangement:');
        }

        var getArticleById = function(artId) {
            for (var i = 0; articles.length; i++) {
                if (articles[i].articleId == artId) return articles[i];
            }
            return null;
        }

        var fillPriceReport = function(report) {
            if (report['enabledArticles'] != undefined && report.enabledArticles.length > 0) {
                for (var i = 0; i < report.enabledArticles.length; i++) {
                    $('#rowArt_' + report.enabledArticles[i]).show();
                }
            }
            if (report['disabledArticles'] != undefined && report.disabledArticles.length > 0) {
                for (var i = 0; i < report.disabledArticles.length; i++) {
                    $('#rowArt_' + report.disabledArticles[i]).hide();
                }
            }
            var html = '<p><b>'
                + report.productionTitle + '</b><br/>'
	            + report.locationTitle + '<br/>'
	            + report.dateEvent + '<br/>'
	            + report.amountOfPersons + ' personen<br/>'
	            + 'Aanvangstijd: ' + report.timeBeginning + ' uur<br/>'
	            + 'Einde: ' + report.timeEnd + ' uur</p>';

            html += '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tablePrices">';
            var tipsHtml = '';
            $.each(report.categories, function(i, vCat) {
                html += '<tr>'
	                + '<td width="100%"><p style="float:left;padding-right:5px;">' + vCat.categoryTitle + '</p>';
                if (vCat.isInfoIconVisible) {
                    html += '<a href="#tooltip' + (i + 1)
                        + '" onclick="return false;" class="info_button png" alt="Info"></a>'
                        + '</td>';
                    tipsHtml += '<div id="tooltip' + (i + 1)
                        + '" class="tooltip_block"><div class="tooltip_content">'
                        + (vCat.urlPicture != '' ? '<p><img src="' + vCat.urlPicture + '" /></p>' : '')
                        + '<p>' + vCat.textBalloon
                        + '</p><a href="javascript:void(0)" class="bottom">Sluit venster</a></div></div>';
                }
                html += '</p></td>'
	                + '<td><p>&euro;</p></td>'
	                + '<td align="right"><p>' + vCat.totalPricePerPerson.toCurrency() + '</p></td><td>';
                if (vCat.isInfoIconVisible) {
                    html += '&nbsp;<a href="#tooltip' + (i + 1) + '" onclick="return false;" class="info_button info_link">info</a>';
                }
                else {
                    html += '&nbsp;<a href="javascript:void(0)" class="tabLink lnk_level_1_' + (i + 1) + '">wijzig</a>';
                }
                html += '</tr>';
            });
            html += '<tr class="totalFirst">'
                + '<td><p class="total">Totale prijs p.p.</p></td>'
	            + '<td><p class="total">&euro;</p></td>'
	            + '<td align="right"><p class="total">' + report.totalPricePerPerson.toCurrency() + '</p></td>'
	            + '</tr><tr class="totalLast">'
	            + '<td><p class="total">Totale indicatie prijs</p></td>'
	            + '<td><p class="total">&euro;</p></td>'
	            + '<td align="right"><p class="total">' + report.totalPrice.toCurrency() + '</p></td>'
	            + '</tr>';

            html += '</table>';
            $('#priceReport').html(html);
            $('#priceReport a.tabLink').click(function() {
                var rLevel = /lnk_(level_1_[0-9]+)/i;
                if (matches = rLevel.exec($(this).attr('class'))) {
                    $('#' + matches[1] + ' a.linkList').click();
                }
            })
            $('#stickedBox').show();
            $('#moreInfoWrapper').show();

            $('#tooltipsCollection').append(tipsHtml);
            $('#priceReport .info_button').each(bindTooltipsHandlersForProceReport);
        }

        this.fillDetailedPriceReport = function(report) {
            var html = '<dl>';
            $.each(report, function(i, vCat) {
                html += '<dt>'
                    + vCat.categoryTitle
                    + '</dt>'
                $.each(vCat.articles, function(i, vArt) {
                    html += '<dd>'
                        + vArt.articleTitle + '</dd>';
                });
                html += '';
            });
            html += '<dl>';
            $('#expandedBoxContent').html(html);
        }

        var conf = new ConfiguratorGetway();
        $('#introText').html(conf.getText(1));
        this.getConfigurator = function() { return conf; }
        fillForm();
        bindHandlers();

        ajaxLoader.show();

        var tmpDate = conf.getDateState();
        if (tmpDate != "") {
            var tmpDateName = conf.getNameDate();
            $('option', dateDrop).remove();
            dateDrop[0].options.add(new Option(tmpDateName, tmpDate));
            var tmpLocation = conf.getLocationState();
            if (tmpLocation > -1) {
                var tmpLocationName = conf.getNameLocation();
                $('option', locDrop).remove();
                locDrop[0].options.add(new Option(tmpLocationName, tmpLocation));

            }
            var tmpProd = conf.getProductState();
            if (tmpProd > -1) {
                var tmpProdName = conf.getNamePart();
                $('option', prodDrop).remove();
                prodDrop[0].options.add(new Option(tmpProdName, tmpProd));
            }
            var tmpCntPers = conf.getCountPersonState();
            if (tmpCntPers > -1) {
                amountTxt.val(tmpCntPers);
            }
            var tmpMainInt = conf.getMainInt();
            if (tmpMainInt > -1) {
                calendarProductionId = tmpMainInt;
                startForm();
            }
        }
        ajaxLoader.hide();

    }

    var cp = new ConfiguratorProcessor();



});
