﻿function launchCartWizard2() {
    ShopWebService.CartWizard2_GetSteps(sid, CartWizard2_GetSteps_callback, generic_callbackerror);
}

function CartWizard2_GetSteps_callback(result) {
    _stepArray=result;
    _currentWizardStep='';
    activateWizardStep(null,null,_queryStringWizardStep, true);
    refreshCartContents();
}

function getStepArrayObject(internalname) {
    for (i=0;i<_stepArray.size();i++) {
        if (_stepArray[i].InternalName.toLowerCase()==internalname) {
            return _stepArray[i];
        }
    }
    return null;
}

function reloadWizardStep() {
    activateWizardStep(null,null,_currentWizardStep, true);
    refreshCartContents();
}

function nextWizardStep(obj, evt) {
    var x = getStepArrayObject(_currentWizardStep);
    activateWizardStep(null,evt,x.NextStep.toLowerCase(),false);
}

function prevWizardStep(obj, evt) {
    var x = getStepArrayObject(_currentWizardStep);
    activateWizardStep(null,evt,x.PrevStep.toLowerCase(),false);
}

function confirmWizardStep(obj, evt) {
    if (!$get('chkLeveringsvoorwaardenAccepteren').checked) {
        alert(_ML('Afronden.Afronden.Leveringsvoorwaarden.Melding'));
        return false;
    }
    if (!validateAndSaveBevestigen('finalize')) {
        return false;   // confirmorder vindt plaats in de callback van validateAndSaveBevestigen
    }
}

function CartWizard2_ConfirmOrder_callback(result) {
    //if (al=='C'||al=='A') {
    if (getStepArrayObject(_currentWizardStep).NextStep=='Betaalmethode') {
        window.location.href='Cart.aspx?cartwizardstep=betaalmethode';
    } else {
        window.location.href='Cart.aspx?cartwizardstep=voltooid';
    }
}

function activateWizardStep(obj, evt, stepid, skipvalidation) {
//    while (_synchronousWait) {
//        //wacht
//    }

    // Handle tab switch validation
    if (!skipvalidation) {
        switch (_currentWizardStep) {
            case 'uwgegevens':
                if (_WizardStepState=='edituserdetails') {
                    if (!validateAndSaveUwGegevens(stepid)) {
                        return false;
                    }
                }
                break;
            case 'bevestigen':
                if (!validateAndSaveBevestigen(stepid)) {
                    return false;
                }
            default:
                break;
        }
    }

    // Initial tab when page refreshes
    if (stepid=='') {
        if ($get('divStepNoOrderLines') != null) {
            stepid='noorderlines';
        } else {
            stepid='uwbestelling';
        }
    }
    _currentWizardStep=stepid;

    // Set tab appearance
    if ($get('divStepNoOrderLines') != null) {
        $get('divStepNoOrderLines').className   = (_currentWizardStep=='noorderlines') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepNoOrderLinesCaption').className   = (_currentWizardStep=='noorderlines') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepUwBestelling') != null) {
        $get('divStepUwBestelling').className   = (_currentWizardStep=='uwbestelling') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepUwBestellingCaption').className   = (_currentWizardStep=='uwbestelling') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepUwGegevens') != null) {
        $get('divStepUwGegevens').className     = (_currentWizardStep=='uwgegevens') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepUwGegevensCaption').className     = (_currentWizardStep=='uwgegevens') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepBestelwijze') != null) {
        $get('divStepBestelwijze').className    = (_currentWizardStep=='bestelwijze') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepBestelwijzeCaption').className    = (_currentWizardStep=='bestelwijze') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepBevestigen') != null) {
        $get('divStepBevestigen').className     = (_currentWizardStep=='bevestigen') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepBevestigenCaption').className     = (_currentWizardStep=='bevestigen') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepBetaalmethode') != null) {
        $get('divStepBetaalmethode').className  = (_currentWizardStep=='betaalmethode') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepBetaalmethodeCaption').className  = (_currentWizardStep=='betaalmethode') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    if ($get('divStepVoltooid') != null) {
        $get('divStepVoltooid').className       = (_currentWizardStep=='voltooid') ? "divWizardStep divWizardStepSelected":"divWizardStep";
        $get('divStepVoltooidCaption').className       = (_currentWizardStep=='voltooid') ? "divWizardStepCaption divWizardStepCaptionSelected":"divWizardStepCaption";
    }
    
    $get('divWizardContent').style.width='1024px';
    if (_currentWizardStep=='uwbestelling' || _currentWizardStep=='bevestigen') {
//        $get('divWizardContent').style.width='1024px';
//        $get('divWizardContent').style.height='';
    } else {
        //$get('divWizardContent').style.height='600px';
    }

    // Dispatch rendering of the tab content
    _WizardStepState=null;
    switch (_currentWizardStep) {
        case 'noorderlines':
            setCartStepButtonState('');
            renderNoOrderLines();
            break;
        case 'uwbestelling':
            if (_isShowroomMode) {
                setCartStepButtonState('');
            } else {
                setCartStepButtonState('next');
            }
            renderUwBestelling();
            break;
        case 'uwgegevens':
            if (al=='A' && _WizardStepState!='edituserdetails') {
                setCartStepButtonState('back');
            } else {
                setCartStepButtonState('back next');
            }
            renderUwGegevens();
            break;
        case 'bestelwijze':
            setCartStepButtonState('back');
            renderVerzendwijze();
            break;
        case 'bevestigen':
            setCartStepButtonState('print back order');
            renderOverzicht();
            break;
        case 'betaalmethode':
            setCartStepButtonState('');
            renderBetaalmethode();
            break;
        case 'voltooid':
            setCartStepButtonState('');
            renderVoltooid();
            break;
    }
}

function setCartStepButtonState(stepstring) {
    if (_blnAllowOCPrint) {
        $get('rbtnPrintOCTop').style.display=(stepstring.indexOf('print') == -1) ? 'none':'';
    }
    $get('rbtnNextTop').style.display=(stepstring.indexOf('next') == -1) ? 'none':'';
    $get('rbtnPrevTop').style.display=(stepstring.indexOf('back') == -1) ? 'none':'';
    $get('rbtnOrderTop').style.display=(stepstring.indexOf('order') == -1) ? 'none':'';

    if (_blnAllowOCPrint) {
        $get('rbtnPrintOCBottom').style.display=(stepstring.indexOf('print') == -1) ? 'none':'';
    }
    $get('rbtnNextBottom').style.display=(stepstring.indexOf('next') == -1) ? 'none':'';
    $get('rbtnPrevBottom').style.display=(stepstring.indexOf('back') == -1) ? 'none':'';
    $get('rbtnOrderBottom').style.display=(stepstring.indexOf('order') == -1) ? 'none':'';
}

function renderNYI() {
    $get('divWizardContent').innerHTML='Not yet implemented.';
}

function renderNoOrderLines() {
    $get('divWizardContent').innerHTML=_ML('Afronden.Bestelling.Nog niets besteld');
}

function renderLoading() {
    //$get('divWizardContent').innerHTML='<div><div style="text-align:center;vertical-align:center;height:500px;"><img style="margin-top:230px;" src="images/main/ajax-loader.gif" /></div></div>';
}

function renderUwBestelling() {
    ShopWebService.CartWizard2_UwBestelling(sid, CartWizard2_UwBestelling_callback, generic_callbackerror);
}

function CartWizard2_UwBestelling_callback(result) {
    if (result.NrOfRows==0) {
        window.location.href='assortiment.aspx?action=home';
    } else {
        $get('divWizardContent').innerHTML=result.HTML;
        if (_blnUseCartGrouping) {
            $get('divWizardContent').style.height='';
        } else {
            if ($get('tblCartContents').clientHeight<580) {
                var intCalculatedHeight=600;
                $get('divWizardContent').style.height=intCalculatedHeight.toString() + 'px';
            } else {
                $get('divWizardContent').style.height='';
            }
        }        
    }
}

function renderUwGegevens() {
    ShopWebService.CartWizard2_UwGegevens(sid, false, CartWizard2_UwGegevens_callback, generic_callbackerror);
}

function CartWizard2_UwGegevens_callback(result) {
    $get('divWizardContent').innerHTML=result.HTML;
    _WizardStepState=result.state;
    
    if (_WizardStepState=='edituserdetails') {

        userDetailsFactCountryChanged();
        userDetailsAfleverCountryChanged();
    
        if ($get('chkSameAsInvoice')!=null) {
            $get('chkSameAsInvoice').onclick = function() {
                $get('txtAfleverAdres').disabled = !this.checked;
                $get('txtAfleverAdresExtra').disabled = !this.checked;
                $get('txtAfleverPostcode').disabled = !this.checked;
                $get('txtAfleverPlaats').disabled = !this.checked;
                $get('cboAfleverState').disabled = !this.checked;
                $get('cboAfleverLandcode').disabled = !this.checked;

                if ($get('txtAfleverAdresContactpersoon')!=null) {$get('txtAfleverAdresContactpersoon').disabled = !this.checked;};
                if ($get('txtAfleverEmail')!=null) {$get('txtAfleverEmail').disabled = !this.checked;};
                if ($get('txtAfleverTelefoonnummer')!=null) {$get('txtAfleverTelefoonnummer').disabled = !this.checked;};
                
                if (!this.checked) {
                    userDetailsChanged();
                }
            }
        }

        $get('txtFactAdres').onblur=userDetailsChanged;
        $get('txtFactAdresExtra').onblur=userDetailsChanged;
        $get('txtFactPostcode').onblur=userDetailsChanged;
        $get('txtFactPlaats').onblur=userDetailsChanged;
        $get('cboFactState').onchange=userDetailsChanged;
        $get('cboFactLandcode').onchange=userDetailsFactCountryChanged;
        $get('cboAfleverLandcode').onchange=userDetailsAfleverCountryChanged;

    }
    
    if (_WizardStepState=='edituserdetails' || _WizardStepState=='login_or_new') {
        $get('divValidatorMessage').innerHTML='* ' + _ML('Afronden.Uw gegevens.Verplicht veld');
        $get('divValidatorMessage').style.color='#808080';
    }

    if (al=='A' && _WizardStepState=='edituserdetails') {
        setCartStepButtonState('back next');
    }
}

function userDetailsFactCountryChanged() {
    if ($get('chkSameAsInvoice')!=null) {
        if (!$get('chkSameAsInvoice').checked) {
            $get('cboAfleverLandcode').value=$get('cboFactLandcode').value;
            userDetailsAfleverCountryChanged();
        }
    } else {
        $get('cboAfleverLandcode').value=$get('cboFactLandcode').value;
        userDetailsAfleverCountryChanged();
    }
    ShopWebService.GetStates(sid, $get('cboFactLandcode').value, GetStatesFactCountry_callback, generic_callbackerror);
}

function GetStatesFactCountry_callback(result) {
    $get('cboFactState').options.length=0;

    var oOption = document.createElement("OPTION");
    $get('cboFactState').options.add(oOption);
    oOption.text = '';
    oOption.value = 'XX';

    for (i=0;i<result.length;i++) {

        var oOption = document.createElement("OPTION");
        $get('cboFactState').options.add(oOption);
        oOption.text = result[i].Text;
        oOption.value = result[i].Value;
    }
    userDetailsChanged();
}

function userDetailsAfleverCountryChanged() {
    ShopWebService.GetStates(sid, $get('cboAfleverLandcode').value, GetStatesAfleverCountry_callback, generic_callbackerror);
}

function GetStatesAfleverCountry_callback(result) {
    $get('cboAfleverState').options.length=0;

    var oOption = document.createElement("OPTION");
    $get('cboAfleverState').options.add(oOption);
    oOption.text = '';
    oOption.value = 'XX';

    for (i=0;i<result.length;i++) {

        var oOption = document.createElement("OPTION");
        $get('cboAfleverState').options.add(oOption);
        oOption.text = result[i].Text;
        oOption.value = result[i].Value;
    }
    userDetailsChanged();
}

function userDetailsChanged() {
    syncAfleverAdres();
}

function syncAfleverAdres() {
    if (al=='B' || al=='E') return;
    if ($get('chkSameAsInvoice')!=null) {
        if (!$get('chkSameAsInvoice').checked) {
            $get('txtAfleverAdres').value=$get('txtFactAdres').value;
            $get('txtAfleverAdresExtra').value=$get('txtFactAdresExtra').value;
            $get('txtAfleverPostcode').value=$get('txtFactPostcode').value;
            $get('txtAfleverPlaats').value=$get('txtFactPlaats').value;
            $get('cboAfleverState').value=$get('cboFactState').value;
            $get('cboAfleverLandcode').value=$get('cboFactLandcode').value;
        }
    } else {
        $get('txtAfleverAdres').value=$get('txtFactAdres').value;
        $get('txtAfleverAdresExtra').value=$get('txtFactAdresExtra').value;
        $get('txtAfleverPostcode').value=$get('txtFactPostcode').value;
        $get('txtAfleverPlaats').value=$get('txtFactPlaats').value;
        $get('cboAfleverState').value=$get('cboFactState').value;
        $get('cboAfleverLandcode').value=$get('cboFactLandcode').value;
    }
}

function registerAccount() {
    ShopWebService.CartWizard2_UwGegevens(sid, true, CartWizard2_UwGegevens_callback, generic_callbackerror);
}

function renderVerzendwijze() {
    ShopWebService.CartWizard2_Verzendwijze(sid, CartWizard2_Verzendwijze_callback, generic_callbackerror);
}

function CartWizard2_Verzendwijze_callback(result) {
    $get('divWizardContent').innerHTML=result.HTML;
}

function selectDeliveryMethod (obj,evt,ratepk) {
    ShopWebService.CartWizard2_SelectVerzendwijze(sid, ratepk, CartWizard2_SelectVerzendwijze_callback, generic_callbackerror);
}

function CartWizard2_SelectVerzendwijze_callback(result) {
    setCartStepButtonState('back next');
    ShopWebService.CartWizard2_GetStepsHTML(sid, _currentWizardStep, CartWizard2_GetStepsHTMLVerzendwijze_callback, generic_callbackerror);
}

function CartWizard2_GetStepsHTMLVerzendwijze_callback(result) {
    $get('divWizardStepContainer').innerHTML = result;
    renderVerzendwijze();
}

function renderOverzicht() {
    ShopWebService.CartWizard2_Overzicht(sid, CartWizard2_Overzicht_callback, generic_callbackerror);
}

function CartWizard2_Overzicht_callback(result) {
    if (result.NrOfRows==0) {
        window.location.href=window.location.href;
    } else {
        $get('divWizardContent').style.height='';
        $get('divWizardContent').innerHTML=result.HTML;
    }
}

function renderBetaalmethode() {
    ShopWebService.CartWizard2_Betaalmethode(sid, _strPaymentResult, CartWizard2_Betaalmethode_callback, generic_callbackerror);
}

function CartWizard2_Betaalmethode_callback(result) {
    $get('divWizardContent').innerHTML=result.HTML;
}

function renderVoltooid() {
    ShopWebService.CartWizard2_Voltooid(sid, CartWizard2_Voltooid_callback, generic_callbackerror);
}

function CartWizard2_Voltooid_callback(result) {
    $get('divWizardContent').innerHTML=result.HTML;
}

function loginQuick(obj, evt) {
    if (validateLoginGegevens()) {
        ShopWebService.CartWizard2_Login(sid, $get('txtUsername').value, $get('txtPassword').value, CartWizard2_Login_callback, generic_callbackerror);
    }
}

function CartWizard2_Login_callback(result) {
    switch (result) {
        case 'noaccess':
            $get('divValidatorMessage').innerHTML=_ML('Afronden.Uw gegevens.Onbekende gebruiker');
            $get('divValidatorMessage').style.color='red';
            break;
        default:
            window.location.href='Cart.aspx?cartwizardstep=uwgegevens';
            break;
    }
}

function validateLoginGegevens() {
    var intNrOfValidationErrors=0;

    intNrOfValidationErrors += validateTextbox('txtUsername', true);
    intNrOfValidationErrors += validateTextbox('txtPassword', true);

    if (intNrOfValidationErrors >= 1) {
        $get('divValidatorMessage').innerHTML=_ML('Afronden.Uw gegevens.Svp gegevens corrigeren');
        $get('divValidatorMessage').style.color='red';
        return false;
    } else {
        $get('divValidatorMessage').innerHTML='* ' + _ML('Afronden.Uw gegevens.Verplicht veld');
        $get('divValidatorMessage').style.color='#808080';
        return true;
    }
}

function removeCartRow(td, artcode, regeltype, OrderRegel_PK) {
    ShopWebService.RemoveOrderRegel(sid,artcode,'',regeltype,OrderRegel_PK,RemoveOrderRegel_callback, generic_callbackerror,td.parentNode.rowIndex);
    return false;
}

function RemoveOrderRegel_callback(result, rowindex) {
    renderUwBestelling();
}

function wizard_UpdateAantal(ibox,evt,OrderRegel_PK,minbesteleenheid) {
    var Aantal;

    Aantal = ibox.value;
    
    _currentCartAdd_method='wizardupdateaantal';
    _currentCartAddInputbox=ibox;
    _currentCartAdd_minbesteleenheid=minbesteleenheid;
    _currentCartAdd_OrderRegel_PK=OrderRegel_PK;
    if (checkCartAantal(Aantal,minbesteleenheid)) {
        $find('ModalBehaviourInvalidOrderUnit').hide();
        ShopWebService.UpdateAantal(sid,OrderRegel_PK,Aantal,wizard_UpdateAantal_callback, generic_callbackerror);
    }
    return false;
}

function wizard_UpdateAantal_callback(result, rowindex) {
    renderUwBestelling();
}

function wizard_UpdatePrijs(ibox,evt,OrderRegel_PK) {
    var Prijs;
    Prijs = ibox.value;
    ShopWebService.UpdatePrijs(sid,OrderRegel_PK,Prijs,wizard_UpdatePrijs_callback, generic_callbackerror);
    return false;
}

function wizard_ResetPrijs(ibox,evt,OrderRegel_PK) {
    var Prijs;

    Prijs = "0%";
    ShopWebService.UpdatePrijs(sid,OrderRegel_PK,Prijs,wizard_UpdatePrijs_callback, generic_callbackerror);
    return false;
}

function wizard_UpdatePrijs_callback(result, rowindex) {
    renderUwBestelling();
}

function validateAndSaveUwGegevens(intended_stepid) {
    var intNrOfValidationErrors=0;
    var blnAbort=false;

    if (al=='?') {
        //skip validation
    } else {
        //contactpersoon
        intNrOfValidationErrors += validateTextbox('txtVoornaam', false);
        intNrOfValidationErrors += validateTextbox('txtAchternaam', true);
        intNrOfValidationErrors += validateTextbox('txtEmail', true);
        intNrOfValidationErrors += validateTextbox('txtTelefoon', true);
        
        if (!validateEmail($get('txtEmail').value.trim())) {
            $get('txtEmail_validator').style.visibility='visible';
            $get('txtEmail_validator').title='This field requires a valid e-mail address';
            intNrOfValidationErrors++;
        }

        //faktuuradres
        intNrOfValidationErrors += validateTextbox('txtFactAdres', true);
        intNrOfValidationErrors += validateTextbox('txtFactPostcode', true);
        intNrOfValidationErrors += validateTextbox('txtFactPlaats', true);
        //intNrOfValidationErrors += validateCombobox('cboFactState', true);
        intNrOfValidationErrors += validateCombobox('cboFactLandcode', true);

        //afleveradres
        intNrOfValidationErrors += validateTextbox('txtAfleverAdres', true);
        intNrOfValidationErrors += validateTextbox('txtAfleverPostcode', true);
        intNrOfValidationErrors += validateTextbox('txtAfleverPlaats', true);
        //intNrOfValidationErrors += validateCombobox('cboAfleverState', true);
        intNrOfValidationErrors += validateCombobox('cboAfleverLandcode', true);
        if ($get('txtAfleverTelefoonnummer')!=null) {
            intNrOfValidationErrors += validateTextbox('txtAfleverTelefoonnummer', false);
        }
        if ($get('txtAfleverEmail')!=null) {
            if ($get('txtAfleverEmail').value.trim()!='') {
                if (!validateEmail($get('txtAfleverEmail').value.trim())) {
                    $get('txtAfleverEmail_validator').style.visibility='visible';
                    $get('txtAfleverEmail_validator').title='This field requires a valid e-mail address';
                    intNrOfValidationErrors++;
                }
            }
        }
        if ($get('txtAfleverAdresContactpersoon')!=null) {
            intNrOfValidationErrors += validateTextbox('txtAfleverAdresContactpersoon', true);
        }

        if (intNrOfValidationErrors >= 1) {
            $get('divValidatorMessage').innerHTML=_ML('Afronden.Uw gegevens.Svp gegevens corrigeren');
            $get('divValidatorMessage').style.color='red';
            return false;
        } else {
            $get('divValidatorMessage').innerHTML='* ' + _ML('Afronden.Uw gegevens.Verplicht veld');
            $get('divValidatorMessage').style.color='#808080';
        }
        
    }
    var arrUpdate=['txtVoornaam', 'txtTussenvoegsel', 'txtAchternaam', 'txtBedrijfsnaam', 'txtTelefoon', 'txtEmail',
                   'txtFactAdres', 'txtFactAdresExtra', 'txtFactPostcode', 'txtFactPlaats', 'cboFactState', 'cboFactLandcode',
                   'txtAfleverAdresContactpersoon', 'txtAfleverAdres', 'txtAfleverAdresExtra', 'txtAfleverPostcode', 'txtAfleverPlaats', 'cboAfleverState', 'cboAfleverLandcode', 'txtAfleverTelefoonnummer', 'txtAfleverEmail'];
    var strControlName='';
    var arrParameters=[];

    for (a=0;a<arrUpdate.length;a++) {
        // Check if the control exists. If not, skip it
        if ($get(arrUpdate[a])!=null) {
            // Determine the type of control based on its prefix
            strControlName=arrUpdate[a];
            switch (strControlName.substr(0,3)) {
                case 'txt':
                    arrParameters.push(strControlName);
                    arrParameters.push($get(strControlName).value);
                    break;
                case 'cbo':
                    arrParameters.push(strControlName);
                    if ($get(strControlName).selectedIndex==-1) {
                        arrParameters.push('XX');
                    } else {
                        arrParameters.push($get(strControlName).options[$get(strControlName).selectedIndex].value);
                    }
                    break;
                default:
                    blnAbort=true;
                    alert('Unknown control type ' + strControlName);
                    break;
            }
        }
    }

    if (!blnAbort) {
        ShopWebService.CartWizard2_UpdateAccountInfo(sid, arrParameters, CartWizard2_UpdateAccountInfo_callback, generic_callbackerror, intended_stepid);
    }
    return false;
}

function CartWizard2_UpdateAccountInfo_callback(result, intended_stepid) {
    switch (result.toLowerCase()) {
        case 'ok':
            window.location.href='Cart.aspx?cartwizardstep=' + intended_stepid;
            break;
        case 'nochanges':
            activateWizardStep(null, null, intended_stepid, true);
            break;
        default:
            alert("We're sorry, your account could not be created. Please try again later.");
            break;
    }
}

function validateAndSaveBevestigen(intended_stepid) {
    var intNrOfValidationErrors=0;
    var strUwReferentie;
    var strOpmerkingen;

    // Validate klantreferentie
    strUwReferentie='';
    if ($get('txtUwReferentie')!=null) {
        if ($get('txtUwReferentie').value.trim()=='') {
            // Klantreferentie is niet verplicht
        } else {
            strUwReferentie=$get('txtUwReferentie').value;
        }
    }
    
    // Validate opmerkingen
    strOpmerkingen='';
    if ($get('taOpmerkingen')!=null) {
        strOpmerkingen = $get('taOpmerkingen').value;
    }
    
    // Evalueer de uitkomst van alle validaties en geef een melding of update de back-end
    if (intNrOfValidationErrors >= 1) {
        $get('divValidatorMessage').innerHTML=_ML('Afronden.Uw gegevens.Svp gegevens corrigeren');
        $get('divValidatorMessage').style.color='red';
        return false;
    } else {
        $get('divValidatorMessage').innerHTML='* ' + _ML('Afronden.Uw gegevens.Verplicht veld');
        $get('divValidatorMessage').style.color='#808080';

        ShopWebService.CartWizard2_UpdateOrderInfo(sid,
                        encodeURIComponent(strOpmerkingen), strUwReferentie,
                        CartWizard2_UpdateOrderInfo_callback, generic_callbackerror, intended_stepid);
        return true;
    }
}

function CartWizard2_UpdateOrderInfo_callback(result, intended_stepid) {
    if(intended_stepid=='finalize') {
        ShopWebService.CartWizard2_ConfirmOrder(sid, CartWizard2_ConfirmOrder_callback, generic_callbackerror);
    }
    return true;
}

function validateTextbox(id, isrequired) {
    var intNrOfValidationErrors=0;
    
    $get(id + '_validator').style.visibility='hidden';

    if (isrequired && $get(id).value.trim()=='') {
        $get(id + '_validator').style.visibility='visible';
        $get(id + '_validator').title='This field requires a value';
        intNrOfValidationErrors++;
    }
   
    return intNrOfValidationErrors;
}

function validateCombobox(id, isrequired) {
    var intNrOfValidationErrors=0;
    var strValue='';
    
    $get(id + '_validator').style.visibility='hidden';
    strValue=$get(id).value;
    strValue=strValue.trim();

    if (isrequired && strValue=='') {
        $get(id + '_validator').style.visibility='visible';
        $get(id + '_validator').title='This field requires a value';
        intNrOfValidationErrors++;
    }
   
    return intNrOfValidationErrors;
}

function printOCFromCart(obj, evt) {
    if (validateAndSaveBevestigen(_currentWizardStep)) {
        window.open('Print.aspx?d=oc','windowPrintOC','resizable=1');
    }
}

function addShowroomCartToB2BOrder(obj, evt) {
    if ($get('txtB2BOrderPassword').value=='') {
        alert("Voer a.u.b. uw wachtwoord in.");
    } else {
        ShopWebService.AddShowroomCartToB2BOrder(sid, AddShowroomCartToB2BOrder_callback, generic_callbackerror);
    }
}

function AddShowroomCartToB2BOrder_callback(result) {
    window.location.href='assortiment.aspx?action=home';
}

function expandCartGroup(obj, evt, cartgroup) {
    var tbl = $get('tblAfronden');
    var tr;
    var blnExpand;
    
    if (obj.attributes['isexpanded'].value=='false') {
        blnExpand=true;
        obj.attributes['isexpanded'].value = 'true';
        obj.cells[0].childNodes[0].src='skins/' + _shopid + '/cartdock/expanded_cart.png';
    } else {
        blnExpand=false;
        obj.attributes['isexpanded'].value = 'false';
        obj.cells[0].childNodes[0].src='skins/' + _shopid + '/cartdock/collapsed_cart.png';
    }


    for (i=0;i<tbl.rows.length;i++) {
        tr = tbl.rows[i];
        if (tr.attributes['cartgrouping']) {
            if (tr.attributes['cartgrouping'].value==cartgroup) {
                if (blnExpand) {
			        if (navigator.appName == 'Microsoft Internet Explorer') {
	                            tr.style.display='block';
			        } else {
			            tr.style.display='table-row';
			        }
                } else {
                    tr.style.display='none';
                }
            }
        }
    }
}

