     /*Ajax.Responders.register({
  onCreate: function() {
    Ajax.activeRequestCount++;
    
    //Element.spinBeside(Element,'Een ogenblik geduld aub'); 
  },
  onComplete: function(req) {

    //document.fire("foo:inithelp");
    Ajax.activeRequestCount--;
    if(Ajax.activeRequestCount == 0){
       // Element.hide('systemWorking');  
       //Element.stopBeside(Element);
    }
  }
});   */


Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;
Prototype.Browser.Firefox = (Prototype.Browser.Gecko) && navigator.userAgent.indexOf('Firefox/') > -1; 
Prototype.Browser.FirefoxVersion = (Prototype.Browser.Gecko) ? parseFloat(navigator.userAgent.split("Firefox/")[1]) || 0 : 0;

var valid;

var Cart = Class.create({

    initialize: function() {     
        this.url = SHOP_BASE_REL+'front/server_cart.php';  
    }
    ,addRelated: function(div_id){
        var params=$H(
            {
                action: 'addRelated',
                cart_mode: 'simple',
                sid:Math.random()
            }
        ).toQueryString();

        params = params + "&" + $('form_related').serialize();

        $(div_id).ajaxUpdate(
            this.url,
            {
                method: 'post',
                parameters: params,
                onComplete: this.showCompleteCart()
            }    
        );    
    }
    ,addToCart: function(div_id,product_id,quantity){
        
        cart_mode = 'simple';
        if(div_id == 'winkelmand_container')
            cart_mode = 'extended';
    
    
        var params=$H(
            {
                action: 'addToCart',
                product_id:product_id,
                cart_mode: cart_mode,
                quantity:quantity,
                sid:Math.random()
            }
        ).toQueryString();

        if(div_id == 'winkelmand_container'){
            $(div_id).ajaxUpdate(
                this.url,
                {
                    method: 'get',
                    parameters: params,
                    onComplete: this.showCompleteCart()
                }    
            );
        }
        else{
            $(div_id).ajaxUpdate(
                this.url,
                {
                    method: 'get',
                    parameters: params,
                    onComplete: this.showCompleteCart()
                }    
            );    
        }
    }
    ,removeFromCart: function(id,product_id,cart_id){
        
        var params=$H(
            {
                action: 'remove',
                product_id: product_id,
                cart_id: cart_id,
                sid:Math.random()
            }
        ).toQueryString();

    
        $(id).ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete: function(){
                    resize();                   
                }          
            }    
        );
    }
    ,updateToCart: function(id,product_id,quantity,cart_id){

        var params=$H(
            {
                action: 'update',
                product_id: product_id,  
                cart_id: cart_id,
                quantity:quantity,
                sid:Math.random()
            }
        ).toQueryString();

    
        $(id).ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete: function(){
                    resize();             
                }            
            }    
        );
    }
    ,refreshCart: function(id){

        var params=$H(
            {
                action: 'refresh',
                sid:Math.random()
            }
        ).toQueryString();

    
        $(id).ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params
            }    
        );
    }
    ,clearCart: function(){
        
        var params=$H(
            {
                action: 'clearCart',
                sid:Math.random()
            }
        ).toQueryString();

    
        $('winkelmand_container').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete: function(){

                    resize(); 
                }
            }    
        );
    }
    ,saveCart: function(id,name){

        var params=$H(
            {
                action: 'save_cart',
                cart_id: id,
                cart_name: name,
                sid:Math.random()
            }
        ).toQueryString();

    
        $('winkelmandje-storebox').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete: function(){
                    alert('Bestellijst is opgeslagen');
                }

            }    
        );
    }
    ,loadSavedCart: function(id){
        
        var params=$H(
            {
                action: 'load_saved_cart',
                cart_id: id,
                sid:Math.random()
            }
        ).toQueryString();

    
        $('header_cart').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete: function(){
                    showCompleteCart();
                }

            }    
        );
    }
    ,deleteSavedCart: function(id){
        
        var params=$H(
            {
                action: 'delete_saved_cart',
                cart_id: id,
                sid:Math.random()
            }
        ).toQueryString();

    
        $('order_list_overview').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params
            }    
        );
    }
    ,goto_checkout: function(step,substep,action){

            var params=$H(
                {
                    action: action,
                    step: step,
                    substep: substep,
                    sid:Math.random()
                }
            ).toQueryString();

            
            $('popup_module-resultaat').ajaxUpdate(
                this.url,
                {
                  method: 'get',
                  parameters: params,
                  onComplete: function(){

                        if($('form_checkout')){
                            valid = new Validation('form_checkout', {immediate : true, onFormValidate : formCallback,useTitles:true});          
                        }
                        else{ 
                            if($('form_user') && $('user_choice_subscribe').visible()){
                                valid = new Validation('form_user', {immediate : true, onFormValidate : formCallback,useTitles:true});          
                                Validation.addAllThese([
                                        ['validate-url', 'Een correcte adres invullen a.u.b.', function (v) {
                                            return Validation.get('IsEmpty').test(v) || v == "http://" || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
                                        }],            
                                        ['validate-postcode', 'Postcode is niet correct', function (v,elm) {

                                            return Validation.get('IsEmpty').test(v) ||  /^[\d]{4,4}\s{0,1}[a-zA-Z]{2,2}$/.test(v) 
                                        }]
                                    ]);                     
                            }
                            else if($('form_login') && $('user_choice_login').visible()){
                                valid = new Validation('form_login', {immediate : true, onFormValidate : formCallback,useTitles:true});          
                            }
                        }
                        resize();  
                  }
                }    
            );  
    }    
    ,checkout_goto: function(step){
        this.goto_checkout(step,'','show');
    }
    ,checkout_confirm_form: function(form,nextstep){

        $(form).request({
            onComplete: function(req){ 
                    //if(dialogCounter == 1) 
                        //hideProcessing();  
                    
                    
                    $('popup_module-resultaat').innerHTML = req.responseText; 
                    
                    if($('form_checkout')){  
                        valid = new Validation('form_checkout', {immediate : true, onFormValidate : formCallback,useTitles:true});
                    }
                    else{
                        if($('form_user') && $('user_choice_subscribe').visible()){ 
                            valid = new Validation('form_user', {immediate : true, onFormValidate : formCallback,useTitles:true});   
                            Validation.addAllThese([
                                    ['validate-url', 'Een correcte adres invullen a.u.b.', function (v) {
                                        return Validation.get('IsEmpty').test(v) || v == "http://" || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
                                    }],            
                                    ['validate-postcode', 'Postcode is niet correct', function (v,elm) {

                                        return Validation.get('IsEmpty').test(v) ||  /^[\d]{4,4}\s{0,1}[a-zA-Z]{2,2}$/.test(v) 
                                    }]
                                ]);                                
                        }
                        else if($('form_login') && $('user_choice_login').visible()){ 
                            valid = new Validation('form_login', {immediate : true, onFormValidate : formCallback,useTitles:true});          
                        }                    
                    }

                    
                    resize();                         
                    
            }
        }); 
        return false;
    }
    ,showCompleteCart: function(action){

        if(action && action=='payment'){
            action = action;
        }
        else
            action = 'show';  

        var params=$H(
        {
            action:action,
            sid:Math.random()
        }
        ).toQueryString();

        this.req_parameters = params;

        Lightview.show({
          href: this.url,
          rel: 'ajax',
          options: {
            menubar: false,
            innerPreviousNext:false,
            overflow:'auto',  
            topclose: true,
            autosize: false,     
            ajax: {
              method: 'get',
              parameters: this.req_parameters, 
              onComplete: function(){ 

              }
            }
          }
        });
    }    
    
});

var Payment = Class.create({   
    initialize: function() {   
    
    }
    ,checkAgree: function(){
        return $('agree2').checked;
        //return true;
    }    
    ,showPaymentDescription: function(){
        pchoice = $RF('pchoice');  
        if (pchoice != null){ 
           switch(pchoice){
                
                case 'Buckaroo_ideal': 
                    $('payment_method_description').innerHTML = $('form_description_buckaroo_ideal').innerHTML;
                    break;
                case 'Buckaroo_incasso':       
                    $('payment_method_description').innerHTML = $('form_description_buckaroo_incasso').innerHTML;                   
                    break;                    
                case 'Vooruitbetalen': 
                    $('payment_method_description').innerHTML = $('form_description_vooruitbetalen').innerHTML;   
                    break;
                case 'OpRekening': 
                    $('payment_method_description').innerHTML = $('form_description_oprekening').innerHTML;       
                    break;                    
                case 'PayPal': 
                    $('payment_method_description').innerHTML = $('form_description_paypal').innerHTML;       
                    break;    
           }          
        }
    }
    ,pay: function(){
        //if(this.checkAgree()){
        if(true){
            checkout_only = false;
            if($('form_payment_checkout_only')){
                checkout_only = true;
            }
                
                

            if(checkout_only){
                var pform = $('form_payment_checkout_only');    
                pform.submit();
            }
            else{
                pchoice = $RF('pchoice');
                
                if (pchoice == null){
                    alert("Kies eerst de gewenste betaalmethode");
                    return;
                }

                switch(pchoice){
                    
                    case 'Buckaroo_ideal': 
                                   
                        var pform = $('form_payment_buckaroo_ideal');
                        
                        $('payment_method_description').innerHTML = $('form_description_buckaroo_ideal').innerHTML;
                        
                        /*if($F('BPE_Issuer') == "" ){
                            alert("Kies eerst de gewenste betaalmethode");
                            return;
                        }                             
                        
                        if($F('BPE_Issuer') == "X" ){
                            alert("U kunt uitsluitend met iDeal betalen\nals u bankiert bij één van de genoemde banken.\nSelecteer andere betaalmethode!");
                            //setRadio('pform','pchoice','incasso');
                            return;
                        } */
                        //self.name = "payopener"; 
                        //prevWin = open('','_pay','toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=800, height=600, top=100, left=150');
                        //if (prevWin && !prevWin.closed)
                            //prevWin.focus();

                        pform.submit();                                
                        //submitFormAfterValidate_project(pform.id,0); 
                    
                        return true;
                        break;

                    case 'Buckaroo_incasso': 
                        
                        var pform = $('form_payment_buckaroo_incasso');           
                        $('payment_method_description').innerHTML = $('form_description_buckaroo_incasso').innerHTML;
                        
                        //self.name = "payopener"; 
                        //prevWin = open('','_pay','toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=800, height=600, top=100, left=150');
                        //if (prevWin && !prevWin.closed)
                           // prevWin.focus();
                        
                        
                        pform.submit();                                
                        //submitFormAfterValidate_project(pform.id,0);
                        return true;                       
                        break;                    
                        
                    case 'Vooruitbetalen': 
                        var pform = $('form_payment_vooruitbetalen'); 
                        $('payment_method_description').innerHTML = $('form_description_vooruitbetalen').innerHTML;   
                        
                        pform.submit();

                        break;
                        
                    case 'OpRekening': 
                        var pform = $('form_payment_oprekening'); 
                        $('payment_method_description').innerHTML = $('form_description_oprekening').innerHTML;       
                        pform.submit();
                        
                        break;                    
                        
                    case 'PayPal': 
                        var pform = $('form_payment_paypal'); 
                        $('payment_method_description').innerHTML = $('form_description_paypal').innerHTML;       
                        pform.submit();
                        
                        // $('paysubscription').submit();
                       //submitFormAfterValidate_project($('paysubscription').id,0);
                        break;   
                    
                    default : 
                        alert("Het is niet mogelijk om te betalen via deze weg. Neem contact op met de eigenaar.");  
            
                }
            }
        }else{
            alert("U dient alvorens de bevestiging akkoord te gaan met de Algemene Voorwaarden");
        }
        
    }
    ,showGeneralConditions: function(buttons){
    
         if($('general_conditions')){
            
            if($(buttons + '_confirm'))
                $(buttons + '_confirm').toggle();
            if($(buttons + '_previous'))
                $(buttons + '_previous').toggle();                
                
            $('payment_container').toggle();
            $('general_conditions').clonePosition($('lightview'));
            $('general_conditions').setStyle({'width':width-20+'px', 'height':height-100+'px'});
            $('general_conditions').toggle();
        }   
    
    }

});

var Login = Class.create({
    
    initialize: function() {   
    
    }
    ,password_forgotten: function(form_id,login_box_id,login_box_forgotten_id,name_id,name_forgotten_id){
      
        if($(login_box_id + '_confirm'))
                $(login_box_id + '_confirm').hide();
                    
        $(name_forgotten_id).value = $F(name_id);
        $(login_box_id).toggle(); 
        $(login_box_forgotten_id).toggle(); 
      }
      ,
      send_password: function(form_id,login_box_id,login_box_forgotten_id,name_id,name_forgotten_id){
            f_value = $F(name_forgotten_id);

            var url = SHOP_BASE_REL+'front/server_user.php';
            var params=$H(
                {
                    action: 'send',
                    id:f_value,
                    sid:Math.random()
                }
            ).toQueryString();

    
            $('passwordforgotten_response').ajaxUpdate(
                url,
                {
                  method: 'get',
                  parameters: params,
                  onComplete: function(){

                         
                         $(form_id).password.value = '';   
                         $(name_id).value = $F(name_forgotten_id);
                         this.password_forgotten(form_id,login_box_id,login_box_forgotten_id,name_id,name_forgotten_id);
                         if($(login_box_id + '_confirm'))
                            $(login_box_id + '_confirm').show();                 
                  }
                }    
            );
    }
    ,loginEnter: function(e){
        
      if(window.event && e.keyCode == 13){ // IE{
            valid.validate();
      }
      else if(e.which && e.which == 13){ // Netscape/Firefox/Opera{
            valid.validate();
      } 
    }  

});



var Shop = Class.create({   
    
    initialize: function() {     
        this.url = SHOP_BASE_REL+'front/server.php';  
        this.cart = new Cart();
        this.payment = new Payment();
        this.login = new Login();
        this.req_parameters = "";
        this.product_detail_fullscreen = false;
    }
    ,setParameters: function(params){
        this.req_parameters = params;
    }
    ,showCompleteCart: function(action){
        this.cart.showCompleteCart(action);
    }
    ,getCart: function(){    
        return this.cart;
    }
    ,getLogin: function(){    
        return this.login;
    }
    ,getPayment: function(){    
        return this.payment;
    }        
    ,showProductDetail: function(){                                         
        if($('filters'))
            $('filters').hide();
         
        if($('module-resultaat.resultaat')){
            $('module-resultaat.resultaat').hide();
        }
        
        if($('module-resultaat.detail')){

            if($('module-resultaat')){

                if(this.product_detail_fullscreen){
                        var detail = $('module-resultaat.detail');
  
                        Element.extend(detail);
                        detail.show();
                        detail.absolutize(); 
                        detail.style.zIndex = "4999";
                        detail.style.background = "#000000 none repeat scroll 0 0";            
                        detail.clonePosition($('document_body'));
                        detail.style.height = document.viewport.getHeight() + "px"; 
                }
                else{            

                    el = $('module-resultaat').up('div');
                    var detail = $('module-resultaat.detail');
                    Element.extend(detail);
                    detail.show();
                    
                    if(!Prototype.Browser.Firefox){
                    
                    }
                    else{
                        detail.absolutize(); 
                    }
                        
                    detail.style.zIndex = "4999";
                    /*detail.style.background = "white";*/
                    detail.style.marginTop = "10px";
                    detail.clonePosition(el);
                }
            }            
            
            scroll(0,0); 
        }
    }
    ,showProductSearch: function(){

        if($('product-details') ){
            if($('product-details') != "undefined" )
                $('product-details').hide();                                                     
        }
    
        if($('filters') ){ 
            $('filters').show();                                                    
        }    
    
        if($('module-resultaat.detail'))
            $('module-resultaat.detail').hide();                                                                                                    
    
        if($('module-resultaat.resultaat'))
            $('module-resultaat.resultaat').show();
    
        scroll(0,0);  
    }
    ,closeProductDetail: function(){
        this.showProductSearch();   
    }    
    ,updateCategory: function(catid){
        if(catid == "")
            catid = 0;
    
        if($('module-resultaat.breadcrumb')){
            $('module-resultaat.breadcrumb').show();  
            this.updateCategoryForElement(catid,'breadcrumb','module-resultaat.breadcrumb');   
        }
        
        if($('module-resultaat.sub_categories')){
            $('module-resultaat.sub_categories').show();  
            this.updateCategoryForElement(catid,'list_sub_categories','module-resultaat.sub_categories');   
        }        
        
        if($('module-resultaat.resultaat')){                                     
            this.updateCategoryForElement(catid,'gallery','module-resultaat.resultaat');   
        }
        
        if($('product_bestsellers')){
            this.updateBestsellers(catid);
        }
        
        //dhtmlHistory.add("shop_cat_"+catid, catid);
            
        this.closeProductDetail();         
    }
    ,updateBestsellers: function(catid){
    
        var params=$H(
            {
                action:'update',
                catid : catid,       
                sid:Math.random()
            }
        ).toQueryString();    
      
        $('product_bestsellers_list').ajaxUpdate(
            SHOP_BASE_REL+'front/server_bestellers.php',
            {
                method: 'get',
                parameters: params,
                onComplete:function(transport){
                     if($('product_bestsellers_list')){   
                     
                        if(transport.responseText.length > 0){
                            $('product_bestsellers').show();
                        }
                        else{
                            $('product_bestsellers').hide();  
                        }
                     }
                }
            }    
        );        
    
    }
    ,changeTab: function(artikelCode,tab,tab_selected){

        var params=$H(
            {
                action:'tabchange',
                artikelCode : artikelCode,       
                tab_selected: tab_selected,
                sid:Math.random()
            }
        ).toQueryString();
        
        this.req_parameters = removeValuePairs(this.req_parameters,'sid','');
        this.req_parameters = removeValuePairs(this.req_parameters,'action','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'artikelCode','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'relatieCode','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'tab_selected','');  
        this.req_parameters = this.req_parameters + "&" + params;             
        
        $(tab).ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params
            }    
        );    
    }
    ,changeViewType: function(){
    
        this.showProductSearch();
    
        
        var params=$H(
            {
                action:'typeSelection',
                type: $F('weergave'),
                sid:Math.random()
            }
        ).toQueryString();
     
        this.req_parameters = removeValuePairs(this.req_parameters,'sid','');
        this.req_parameters = removeValuePairs(this.req_parameters,'action','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'type','');     
        this.req_parameters = removeValuePairs(this.req_parameters,'nav_page','');          
        this.req_parameters = this.req_parameters + "&" + params;
    
        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: this.req_parameters,
                onComplete: function(){
                    Lightview.updateViews();
                }
            }    
        ); 
       
    }
    ,changeSort: function(column,direction){
    
        this.showProductSearch();
    
        if(!column){
            pair = $F('sortering').split("|");
            column = pair[0];
            direction = pair[1];
        }

        var params=$H(
            {
                action:'sort',
                column:column,
                direction:direction,
                sid:Math.random()
            }
        ).toQueryString();
    
        this.req_parameters = removeValuePairs(this.req_parameters,'sid','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'action','');  
        this.req_parameters = removeValuePairs(this.req_parameters,'sort',''); 
        this.req_parameters = removeValuePairs(this.req_parameters,'direction',''); 
        this.req_parameters = removeValuePairs(this.req_parameters,'column',''); 
        this.req_parameters = this.req_parameters + "&" + params;
    
        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: this.req_parameters,
                onComplete: function(){
                    Lightview.updateViews()  
                }
            }    
        );   
    }
    ,subproductDetails: function(artikelCode,parentArtikelCode){

        this.productDetail(artikelCode,parentArtikelCode,1,0);  
    }
    ,returnToParentProductDetails: function(artikelCode){
        this.productDetail(artikelCode,'',0,1);
    }
    ,productDetails: function(artikelCode){
    
        this.productDetail(artikelCode,'',0,0);
    }
    ,productDetail: function(artikelCode,parentArtikelCode,sub,backfromsub){
    
        this.showProductDetail();    
        
        var params=$H(
            {
                action:'details',
                artikelCode : artikelCode,
                parentArtikelCode : parentArtikelCode, 
                sub: sub,
                backfromsub: backfromsub,
                sid:Math.random()                                      
            }
        ).toQueryString();
    
        $('module-resultaat.detail').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: params,
                onComplete:function(req){ 
                    Lightview.updateViews()
                    //getProductPrice(req.request.parameters.artikelCode);
                }
            }    
        );      
    
        return false;
    }   
    ,searchProducts: function(clean){

        this.showProductSearch();
        searchTerms = $F('searchterms');
        if($('exact'))
            exact = $F('exact');  
        else
            exact = 0;
        
        var params=$H(
            {
                action:'search',
                searchTerms : searchTerms,
                exact: exact, 
                sid:Math.random()                                      
            }
        ).toQueryString();
    
        if(clean){
            this.req_parameters = params;
        }
        else{
            this.req_parameters = removeValuePairs(this.req_parameters,'searchTerms',''); 
            this.req_parameters = removeValuePairs(this.req_parameters,'sort','');
            this.req_parameters = removeValuePairs(this.req_parameters,'direction','');
            this.req_parameters = removeValuePairs(this.req_parameters,'exact',''); 
            this.req_parameters = removeValuePairs(this.req_parameters,'sid',''); 
            this.req_parameters = this.req_parameters + '&' + params;
        }
        
        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
                method: 'get',
                parameters: this.req_parameters,
                onComplete:function(){ 
                    Lightview.updateViews();    
                
                    if($('module-resultaat')){
                        $('module-resultaat').removeClassName('module-resultaat');
                        $('module-resultaat').addClassName('module-resultaat-full');
                    }

                    if($('menu_titel')) 
                        $('menu_titel').addClassName('menu_titel_collapse');  
                    
                    
                    if($('module-info'))    
                        $('module-info').style.width =  '22px';
                    
                    if($('module-infoContents'))
                        $('module-infoContents').hide();   
                    
                    if($('module-resultaat.breadcrumb'))
                        $('module-resultaat.breadcrumb').hide();
                    
                    isExtended = 0; 
                    if($('filters')){   
                        this.updateFilterList();
                    }                    
                    
                }
            }    
        );       
    }
    ,updateFilterList: function(){
    
            this.showProductSearch();

            var params=$H(
            {
                action:'filter',
                sid:Math.random()
                
            }
            ).toQueryString();
            
            this.req_parameters = removeValuePairs(this.req_parameters,'sid',''); 
            this.req_parameters = removeValuePairs(this.req_parameters,'action',''); 
            this.req_parameters = this.req_parameters + "&" + params;
            
            $('filters').ajaxUpdate(
                url,
                {
                  method: 'get',
                  parameters: this.req_parameters
                }    
            );  
    
    }
    ,updateProductListPage: function(page){

        this.showProductSearch();

        //var params = $('form.module-resultaat.resultaat').serialize(true);
        var params=$H(
        {
            action:'navigate',
            nav_page:page,
            sid:Math.random()
        }
        ).toQueryString();
        
        this.req_parameters = removeValuePairs(this.req_parameters,'action',''); 
        this.req_parameters = removeValuePairs(this.req_parameters,'nav_page',''); 
        this.req_parameters = removeValuePairs(this.req_parameters,'sid',''); 
        this.req_parameters = this.req_parameters + "&" + params;

        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
              method: 'get',
              parameters: this.req_parameters,
              onComplete: function(){
                Lightview.updateViews();  
              }
            }    
        );      
    }
    ,updateCategoryForElement: function(catid,action,elementId){


        var params=$H(
        {
            catid:catid,
            action:action,
            sid:Math.random()
        }
        ).toQueryString();

        this.req_parameters = params; 
        
        $(elementId).ajaxUpdate(
            this.url,
            {
              method: 'get',
              parameters: params,
              onComplete: function(){
              
                Lightview.updateViews();  
              }
            }    
        );
    }
    ,switchPersonal: function(){


        if($('user_choice_subscribe').visible()){
        
            $('user_choice_login').show();
            $('user_choice_subscribe').hide();
            $('tabs_tab_subscribe').removeClassName('active');
            $('tabs_tab_login').addClassName('active');        
            
            valid = new Validation('form_login', {immediate : true, onFormValidate : formCallback,useTitles:true});          
        }
        else if($('user_choice_login').visible()){
        
            $('user_choice_subscribe').show();
            $('user_choice_login').hide();
            $('tabs_tab_subscribe').addClassName('active');
            $('tabs_tab_login').removeClassName('active');
            
            valid = new Validation('form_user', {immediate : true, onFormValidate : formCallback,useTitles:true});          
                Validation.addAllThese([
                        ['validate-url', 'Een correcte adres invullen a.u.b.', function (v) {
                            return Validation.get('IsEmpty').test(v) || v == "http://" || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
                        }],            
                        ['validate-postcode', 'Postcode is niet correct', function (v,elm) {

                            return Validation.get('IsEmpty').test(v) ||  /^[\d]{4,4}\s{0,1}[a-zA-Z]{2,2}$/.test(v) 
                        }]
                    ]);                             
        }
    }
    ,checkout_login: function(button){
        valid = new Validation('form_login', {immediate : true, onFormValidate : formCallback,useTitles:true});          
        
        button.disabled = true; 
        if(!valid.validate()){
            button.disabled = false;
        }
        return false;        
        
    }
    ,checkout_subscribe: function(button){
        valid = new Validation('form_user', {immediate : true, onFormValidate : formCallback,useTitles:true});          
            Validation.addAllThese([
                    ['validate-url', 'Een correcte adres invullen a.u.b.', function (v) {
                        return Validation.get('IsEmpty').test(v) || v == "http://" || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
                    }],            
                    ['validate-postcode', 'Postcode is niet correct', function (v,elm) {

                        return Validation.get('IsEmpty').test(v) ||  /^[\d]{4,4}\s{0,1}[a-zA-Z]{2,2}$/.test(v) 
                    }]
                ]);                                 
        button.disabled = true; 
        if(!valid.validate()){
            button.disabled = false;
        }
        return false;                        
    }
    ,removeFilter: function(key,value){

        this.showProductSearch();

        var params=$H(
        {
            action:'removefilter',
            nav_page: 1,
            sid:Math.random()
            
        }
        ).toQueryString();
        
        
        this.req_parameters = removeValuePairs(this.req_parameters,'column','');
        this.req_parameters = removeValuePairs(this.req_parameters,'direction','');

        
        this.req_parameters = removeValuePairs(this.req_parameters,key,value) + "&" + params; 
        

            
        //alert(req_parameters);
        
        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
              method: 'get',
              parameters: this.req_parameters,
              onComplete: function(){
                Lightview.updateViews();  
              }
            }    
        );    
        
        this.updateFilterList();   
           
    }    
    ,addFilter: function(key,value){
   
        this.showProductSearch();
        
        this.req_parameters = removeValuePairs(this.req_parameters,'action','');
        this.req_parameters = removeValuePairs(this.req_parameters,'sid','');
        this.req_parameters = removeValuePairs(this.req_parameters,'nav_page','');
        
        var params=$H(
        {
            action:'addfilter',
            nav_page: 1,
            sid:Math.random() 
            
        }
        ).toQueryString();
        
        
        this.req_parameters = removeValuePairs(this.req_parameters,'column','');
        this.req_parameters = removeValuePairs(this.req_parameters,'direction','');    
        
        this.req_parameters = this.req_parameters + '&' + key + '=' + value + "&" + params;
        
        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
              method: 'get',
              parameters: this.req_parameters,
              onComplete: function(){
                Lightview.updateViews();  
              }
            }    
        );    
        
        this.updateFilterList();
   } 
   ,showLargeImage: function(source_el){

       var el = $('img_groot_replace');
       $('img_groot_container').hide();
       
       if(el){
            el.src = (source_el.src.replace(/.thumb.png/, ""));
            $('img_groot_replace_container').show();
            
       }
        
   }
   ,hideLargeImage: function(){
       $('img_groot_container').show();
       if($('img_groot_replace_container')){
            $('img_groot_replace_container').hide();
       }
   }
});

var Dealer = Class.create({  
    initialize: function() {   
    
    }    
    ,openinfowindow:function(id){

        d_info = $$('div.dealer_info');
        
        d_info.each(function(el){
                el.removeClassName('active_dealer');
                el.hide();
        });
        
       // d_open_info = $$('span.open_dealer_info');
       // d_open_info.each(function(el){
         //       el.show();
        //});        

      // $('open_dealer_'+id).hide();
       $('dealer_'+id).show();
       $('dealer_'+id).addClassName('active_dealer');

    }
    ,opensidebar:function(id){

        this.openinfowindow(id);
        click_sidebar(id);
    }
    
});

var PPage = Class.create({
    
    initialize: function() {   
        this.url = SHOP_BASE_REL+'front/server_ppage.php'; 
    }
    ,changeValidation: function(val){
 
        valid.reset();
        switch(val){
            case 'DE':
                    $('company_btwnummer').removeClassName('required');
                    break;        
            case 'NL':
                    $('company_btwnummer').addClassName('required');
                    break;
            case 'BE':
                    $('company_btwnummer').removeClassName('required');
                    break;        
        }
    }
    ,sameCheckValue: function(){

        var boxStatus;
        boxStatus = eval($('place1').checked);
        if(boxStatus == true){
            $('user_delivery_address').value = $F('user_address'); 
            $('user_delivery_housenumber').value = $F('user_housenumber');      
            $('user_delivery_zipcode').value = $F('user_zipcode');    
            $('user_delivery_city').value = $F('user_city');      
        }
    }            
    ,submitResultaat: function(form,action){

        $(form).request({
            onComplete: function(req){ 
                    //if(dialogCounter == 1) 
                        //hideProcessing(); 
                        
                    $('module-resultaat.resultaat').innerHTML = req.responseText; 
                   
                        if($('form_ppage_user')){
                            valid = new Validation('form_ppage_user', {immediate : true, onFormValidate : formCallback,useTitles:true});
                        } 
            }
        });    
    
        return false;
    }     
    ,updateResultaatDeleteId: function(action,id){

        if (confirm('Gebruiker verwijderen?')){      
            var params=$H(
            {
                action:action,
                res_id:id,
                sid:Math.random() 
                
            }
            ).toQueryString();

            $('module-resultaat.resultaat').ajaxUpdate(
                this.url,
                {
                  method: 'get',
                  parameters: params,
                  onComplete: function(){
                        
                        if($('form_ppage_user')){
                            valid = new Validation('form_ppage_user', {immediate : true, onFormValidate : formCallback,useTitles:true});
                        } 
                                               
                  }
                  
                }    
            );  
        }
    }
    ,updateResultaatId: function(action,id){

        var params=$H(
        {
            action:action,
            res_id:id,
            sid:Math.random() 
            
        }
        ).toQueryString();

        $('module-resultaat.resultaat').ajaxUpdate(
            this.url,
            {
              method: 'get',
              parameters: params,
              onComplete: function(){
                    
                        if($('form_ppage_user')){
                            valid = new Validation('form_ppage_user', {immediate : true, onFormValidate : formCallback,useTitles:true});
                        }                      
              }
              
            }    
        );  
    }
    ,updateResultaat: function(action){

        if(typeof $('module-resultaat.resultaat') == "undefined" ){
            return true;
        }
        else{

            if($('locatie-informatie'))
                $('locatie-informatie').innerHTML = '<a href=\'index.php?page=70&id=65\'>Mijn Triepels</a><span id="module-resultaat.breadcrumb" style="margin: 0px; padding: 0px; float: left;"></span>'; 
            
            if($('module-resultaat.breadcrumb'))
                $('module-resultaat.breadcrumb').hide();

            var params=$H(
            {
                action:action,
                sid:Math.random() 
                
            }
            ).toQueryString();

            $('module-resultaat.resultaat').ajaxUpdate(
                this.url,
                {
                  method: 'get',
                  parameters: params,
                  onComplete: function(){
                        if($('form_ppage_user')){
                            valid = new Validation('form_ppage_user', {immediate : true, onFormValidate : formCallback,useTitles:true});
                        }                                    
                        
                        if($('module-resultaat.resultaat')){
                            el = $('module-resultaat').up('div');

                            $('module-resultaat.resultaat').absolutize(); 
                            $('module-resultaat.resultaat').style.zIndex = "4999";
                            $('module-resultaat.resultaat').style.background = "white";
                            $('module-resultaat.resultaat').style.marginTop = "10px";
                            $('module-resultaat.resultaat').clonePosition(el);
                        }                        
                        
                  }
                }    
            );  
            return false;
       }
    }
});


var shop = new Shop(); 
var ppage = new PPage();


function removeAllFilters(params){

   
     if(params[0] == "?")
        params = params.substr(1);
        
     var pairs = params.split("&");  
     var splitPair;  
     
     res = "";
     // Load the key/values of the return collection  
     for (var i = 0; i < pairs.length; i++) {  
         splitPair = pairs[i].split("=");  
         found = splitPair[0].indexOf('f_');
         
         if(found == -1){
 
             if(res.length == 0)
                res = res + "?";
             else
                res = res + "&";
             
             res = res + splitPair[0] + "="  + splitPair[1]   
         }

     }  
   
     return res;   
    

}


function removeValuePairs(params, key,value){
   
     if(params[0] == "?")
        params = params.substr(1);
        
     var pairs = params.split("&");  
     var splitPair;  
     
     res = "";
     // Load the key/values of the return collection  
     for (var i = 0; i < pairs.length; i++) {  
         splitPair = pairs[i].split("=");  

         if(key != splitPair[0]){
 
             if(res.length == 0)
                res = res + "?";
             else
                res = res + "&";
             
             res = res + splitPair[0] + "="  + splitPair[1]   
         }

     }  
   
     return res;        
}

function checkNumber(elId,afname){
    v = $F(elId);
    
    if(isNaN(v) || /^\s+$/.test(v)){
       $(elId).value = afname;
    }
    else{
        if(v == 0){
            $(elId).value = afname;
            v = afname;
        }
            
        if((v % afname) > 0){
           alert('Minimale afname is ' + afname + '. U kunt alleen hier meervouden van kiezen.');
           $(elId).value = afname;
        }
    }
}

function addQuantity(elId,afname){
    $(elId).value = parseInt($F(elId)) + afname;
    
    checkNumber(elId,afname);
}

function removeQuantity(elId,afname){
    
    
    temp = parseInt($F(elId)) - afname;
    if(temp < afname)
        $(elId).value = afname;
    else
        $(elId).value = temp;
    
    checkNumber(elId,afname);
}

function resize(){
    
    if($('lightview')){                     
    
       // $('lightview').style.marginTop = '0px';
        //$('lightview').scrollTop = '0px';
        height = $('lightview').getHeight(); 
        width  = $('lightview').getWidth(); 
        $$('.lv_contentTop')[0].setStyle({'width':width+'px', 'height':height+'px'});
        
        
        //resize winkelmandje
        if($('winkelmandje-overzicht')){
            if(Prototype.Browser.IE)    
                $('winkelmandje-overzicht').setStyle({'width':width-18+'px','height':(height*0.70)-5+'px'});          
            else
                $('winkelmandje-overzicht').setStyle({'width':width-25+'px','height':(height*0.70)-5+'px'});          
        }     
        
        //resize subscription form
        
        if($('checkout-subscribe.content')){   
            subscribe_height = ((height*0.8)-5);
            if(Prototype.Browser.IE)    
                    $('checkout-subscribe.content').setStyle({'overflow':'hidden','width':width-15+'px', 'height':subscribe_height+'px'});  
            else
                    $('checkout-subscribe.content').setStyle({'overflow':'hidden','width':width-15+'px', 'height':subscribe_height+'px'});  
        }
        
        if($('subscription_wrapper')){
           
           if($('checkout-subscribe.content')){
                
                if($('button_checkout_subscribe')){       
                    subscribe_height = ($('checkout-subscribe.content').getHeight() - 20); 
                }
                else{
                    subscribe_height = ($('checkout-subscribe.content').getHeight()); 
                }
                    
                //if($('user_choice_login'))
                    //subscribe_width  = ($('checkout-subscribe.content').getWidth()*0.6);            
                //else    
                    subscribe_width  = ($('checkout-subscribe.content').getWidth()*0.98);      
                          
                if(Prototype.Browser.IE){
                    $('subscription_wrapper').setStyle({'overflow':'hidden','width':subscribe_width+'px','height':(subscribe_height-10)+'px'});          
                    $('subscription_content').setStyle({'overflow':'auto','width':subscribe_width+'px','height':(subscribe_height-30)+'px'});          
                }
                else{
                    $('subscription_wrapper').setStyle({'overflow':'hidden','width':subscribe_width+'px','height':(subscribe_height-10)+'px'});                    
                    $('subscription_content').setStyle({'overflow':'auto','width':subscribe_width+'px','height':(subscribe_height-30)+'px'});          
                } 
                scroll(0,0);             
           }
           else{
            if(Prototype.Browser.IE){
                $('subscription_wrapper').setStyle({'overflow':'auto','width':width-18+'px','height':(height*0.80)-5+'px'});          
                $('subscription_content').setStyle({'overflow':'auto','width':$('subscription_wrapper').style.width+'px','height':$('subscription_wrapper').style.height+'px'});          
            }
            else{
                $('subscription_wrapper').setStyle({'overflow':'auto','width':width-25+'px','height':(height*0.80)-5+'px'});                  
                $('subscription_content').setStyle({'overflow':'auto','width':$('subscription_wrapper').style.width+'px','height':($('subscription_wrapper').style.height-20)+'px'});          
            }
            
           }
        }   
    }

}


function trigger(name){

    var element=$('subcat_'+name);
    var hrefElement = $('href_'+name);

    if(trim(hrefElement.innerHTML) == "+"){
        hrefElement.innerHTML = "-";
        element.style.display='block';
    }
    else{
        hrefElement.innerHTML = "+";
        element.style.display='none';
    }
}


function submitForm(form,action){


    //dialogCounter = 0;
    //showProcessing();

        
    if(form ==  'form_checkout' || form ==  'form_login' || form ==  'form_user')
        shop.getCart().checkout_confirm_form(form,action);
    else 
        ppage.submitResultaat(form,action);
}

function formCallback(result, form) 
{   form_status =  result;
   /* include the ajax httprequest here */
   
  
   
    if (form_status){
        //submitFormAfterValidate_project(form.id,0);
        if(form.id ==  'form_checkout' || form.id ==  'form_login' || form.id ==  'form_user') {
            if (confirm(SHOP_CONFIRM)){  
                submitForm(form.id,$F('step'));
            }
        }        
        

    }
}   

document.observe('lightview:opened', function(event) {

    if(!event.target.href){  
        resize();
        Event.observe(window, "resize", function() {   
            resize(); 
        });  
    }
    else{

        if(Prototype.Browser.Firefox && Prototype.Browser.FirefoxVersion < 3){
            
            $('lightview').style.top = 25 + 'px';
    
            Event.observe(window, "scroll", function() { 
                
                $('lightview').style.top = 25 + 'px';    
            });     
            
            Event.observe(window, "resize", function() {  
                 $('lightview').style.top = 25 + 'px';
            });      
                    //height = $('lightview').getHeight(); 
                    //width  = $('lightview').getWidth();     
                    
                    //alert(height +  ' : ' + width);
        }   
        else{
            $('lightview').style.position = 'absolute';
            $('lightview').style.marginTop = 25 + 'px'; 
            $('lightview').style.top = 0 + 'px';
        
            Event.observe(window, "scroll", function() { 
                $('lightview').style.top = 0 + 'px';    
                $('lightview').style.marginTop = 25 + 'px';    
            });     
            
            Event.observe(window, "resize", function() {  
                $('lightview').style.top = 0 + 'px';
                $('lightview').style.marginTop = 25 + 'px';
            });
        }            
    }
});

document.observe('lightview:hidden', function(event) {
  if(!event.target.href){
  
    if($('header_cart'))
        shop.getCart().refreshCart('header_cart');   
                                
    if($('order_list_overview') != null ){ 
       ppage.updateResultaat('order_list_overview'); 
    }  
  }
});


/*window.dhtmlHistory.create({
    toJSON: function(o) { return Object.toJSON(o); },
    fromJSON: function(s) { return s.evalJSON(); } 
});

var  = function(newLocation, historyData) {
    
    var historyMsg = (typeof historyData == "object" && historyData != null ? historyStorage.toJSON(historyData) : historyData);

    var msg = "A history change has occured:\n oldLocation=" + oldLocation + "\n historyData=" + historyMsg ;

    // myRestorePage(oldLocation, historyData)

    alert(msg); 
} */



/*var load = function(newLocation, historyData) {
    alert(newLocation);
    var historyMsg = (typeof historyData == "object" && historyData != null ? historyStorage.toJSON(historyData) : historyData);

    var msg = "A history change has occured:\n oldLocation=" + oldLocation + "\n historyData=" + historyMsg ;

    // myRestorePage(oldLocation, historyData)

    alert(msg)
     
  new Ajax.Updater('main', newLocation, { method: 'get', evalScripts: true }); 
  dhtmlHistory.add(newLocation); 
  return false; 
 };*/

//load = function(page) {
  //new Ajax.Updater('main', page, { method: 'get', evalScripts: true }); 
  //dhtmlHistory.add(page); return false; 
 //};

  