/*
	cwconf v0.1
	(c) 2010 Write.cz, s.r.o. <http://www.write.cz>
	
	mootools core required
	mootools more IframeShim, Assets, HTMLtable required
*/


var cwconf = {
  // user defined
  url : '/konfigurator/getdata.php',
  elForSelMan : 'selManu',
  elForSelModel : 'selModel',
  elForSelEngine : 'selEngine',
  elForImg : 'imgBox',
  elForWheels : 'wheelsBox', 
  elForSizes : 'sizeBox',
  elForVariants : 'variantsBox', 
  elForInfo : 'infoContBox',
  elForWhName : 'whNameBox',
  
  notice : {
    defSelHTML : '-----vyberte si prosím-----'
  },

   
  // predefined
  afterInit : "makeSelNice.delay(10);",
  afterSelUpdate : "makeSelNice.delay(10);",  
  onWheelsShow : "$('content').setStyle('backgroundImage','none')",
  onWheelsUnShow : "$('content').setStyle('backgroundImage','')",
  loaderImageURL : "/img/loader.gif",
  whereToBuyURL : "http://www.pneu-kvalitne.cz/",
  whereToBuyPneuURL : "http://www.pneu-kvalitne.cz/pneumatiky",
  
  
  // for app only - don't change  
  selectManufacturer : false, 
  selectModel : false, 
  selectEngine : false,
  loaderBox: false, 
  loaderImage: false,
  ifraShim: false,
  wheels: false,
  wheelsSizes : false,
  carImage: false,
  wheelsOnlySize: false,
  wheelsSizesSel: Array(),
  
	init: function(){	  
	      // alert('init');
	      cwconf.prepareElms();
        cwconf.clearSels();    
        eval(cwconf.afterInit);
       // cwconf.getDataWheels('?model=210605');                                         
	},	
	
	prepareElms : function() {
	     cwconf.selectManufacturer = new Element('select', {
    		  'id' : 'selectManufacturer',
    		  'name' : 'selectManufacturer',
    		  'class' : 'styled',
    		  'events' : {
            'change' : function(e) {
                cwconf.clearCont();
                if(this.get('value') == '') {
                  cwconf.clearSels() ;                   
                } else {
                  cwconf.getModels();
                }
                            
            }
          }
        }).adopt( new Element('option', { 'value': '', 'html' : cwconf.notice.defSelHTML }) );
        
        cwconf.selectModel = new Element('select', {
    		  'id' : 'selectModel',
    		  'name' : 'selectModel',
    		  'class' : 'styled',
          'events' : {
            'change' : function(e) {
                cwconf.clearCont();
                if(this.get('value') == '') {
                  cwconf.selectEngine.empty();
                } else {
                  cwconf.getEngines(this.value);
                }
            }
          }
        }).adopt( new Element('option', { 'value': '', 'html': cwconf.notice.defSelHTML }) );
        
        cwconf.selectEngine = new Element('select', {
    		  'id' : 'selectEngine',
    		  'name' : 'selectEngine',
    		  'class' : 'styled',
    		  'events' : {
            'change' : function(e) {
                if(this.get('value') == '') {
                  cwconf.clearCont();
                } else {
                  cwconf.getWheels(this.value);
                }
            }
          }
        }).adopt( new Element('option', { 'value': '', 'html': cwconf.notice.defSelHTML }) );
              
        
        if(cwconf.elForSelMan == '' || $chk($(cwconf.elForSelMan)) == false ) {
          cwconf.elForSelMan = new Element('div', {id:'elForSelMan'});
           $(document.body).adopt(cwconf.elForSelMan);        
        } else {
          cwconf.elForSelMan = $(cwconf.elForSelMan);
        }        
        cwconf.elForSelMan.adopt(cwconf.selectManufacturer);
        
        if(cwconf.elForSelModel == '' || $chk($(cwconf.elForSelModel)) == false ) {
          cwconf.elForSelModel = new Element('div', {id:'elForSelModel'});
           $(document.body).adopt(cwconf.elForSelModel);        
        } else {
          cwconf.elForSelModel = $(cwconf.elForSelModel);
        }        
        cwconf.elForSelModel.adopt(cwconf.selectModel);
        
        if(cwconf.elForSelEngine == '' || $chk($(cwconf.elForSelEngine)) == false ) {
          cwconf.elForSelEngine = new Element('div', {id:'elForSelEngine'});
           $(document.body).adopt(cwconf.elForSelEngine);        
        } else {
          cwconf.elForSelEngine = $(cwconf.elForSelEngine);
        }        
        cwconf.elForSelEngine.adopt(cwconf.selectEngine);
        
        
        if(cwconf.elForImg == '' || $chk($(cwconf.elForImg)) == false ) {
          cwconf.elForImg = new Element('div', {id:'elForImg'});
           $(document.body).adopt(cwconf.elForImg);        
        } else {
          cwconf.elForImg = $(cwconf.elForImg);
        }
        
        if(cwconf.elForSizes == '' || $chk($(cwconf.elForSizes)) == false ) {
          cwconf.elForSizes = new Element('div', {id:'elForSizes'});
           $(document.body).adopt(cwconf.elForSizes);        
        } else {
          cwconf.elForSizes = $(cwconf.elForSizes);
        }
        
        if(cwconf.elForInfo == '' || $chk($(cwconf.elForInfo)) == false ) {
          cwconf.elForInfo = new Element('div', {id:'elForInfo'});
           $(document.body).adopt(cwconf.elForInfo);        
        } else {
          cwconf.elForInfo = $(cwconf.elForInfo);
        }
        
        if(cwconf.elForVariants == '' || $chk($(cwconf.elForVariants)) == false ) {
          cwconf.elForVariants = new Element('div', {id:'elForVariants'});
           $(document.body).adopt(cwconf.elForVariants);        
        } else {
          cwconf.elForVariants = $(cwconf.elForVariants);
        }
        
        if(cwconf.elForWhName == '' || $chk($(cwconf.elForWhName)) == false ) {
          cwconf.elForWhName = new Element('div', {id:'elForWhName'});
           $(document.body).adopt(cwconf.elForWhName);        
        } else {
          cwconf.elForWhName = $(cwconf.elForWhName);
        }
        
        
        
        
        
        if(cwconf.elForWheels == '' || $chk($(cwconf.elForWheels)) == false ) {
          cwconf.elForWheels = new Element('div', {id:'elForWheels'});
           $(document.body).adopt(cwconf.elForWheels);        
        } else {
          cwconf.elForWheels = $(cwconf.elForWheels);
        }
                        
        
        cwconf.loaderBox = new Element('div', {
          'id': 'loaderBox',
          'styles' : {
            'position' : 'absolute',
            'top' : 0,
            'left' : 0,
            'width' : document.getScrollSize().x,
            'height' : document.getScrollSize().y, 
            'background-color' : '#000000',
            'opacity' : 0.7,
            'z-index' : '998',
            'display' : 'none'  
          }                 
        });
        
        cwconf.loaderImage = new Asset.image(cwconf.loaderImageURL, {
          'id': 'loaderImage',
          'alt': 'loader',
          'styles' : {
            'position' : 'absolute',
            'border' : 0,
            'top' : ($(document).getSize().y / 2) + $(document).getScroll().y - 10,
            'left' : ($(document).getSize().x / 2) + $(document).getScroll().x - 110,
            'z-index' : '999'             
          }                         
        });
        cwconf.loaderBox.adopt(cwconf.loaderImage);
        
        $(document.body).adopt(cwconf.loaderBox);
        
        cwconf.ifraShim = new IframeShim(cwconf.loaderBox, { show: true } );          
  },
  
  clearSels : function() {
          cwconf.clearOpt(cwconf.selectManufacturer); 
          cwconf.clearOpt(cwconf.selectModel); 
          cwconf.clearOpt(cwconf.selectEngine);  
          cwconf.getDataOpt(cwconf.selectManufacturer, '');  
  },
  
  
  makeOptions : function(elem, odata) {          
          cwconf.clearOpt(elem);  
          // console.log(odata);     
          if(odata != false) {           
              if(!$chk(odata.BrandCode)) {
                $each(odata, function(retval){                
                    if(retval.ModelCode) {
                      elem.adopt( new Element('option', { 'value': '?model='+retval.ModelCode, 'html': retval.ModelText+' rv.'+retval.ModelYear+' - '+retval.Power+'kW - '+retval.BoltPattern+'/'+retval.BoltCircle }) );
                    } else if(retval.TypeCode) {                      
                      elem.adopt( new Element('option', { 'value': '?brand='+retval.BrandCode+'&type='+retval.TypeCode, 'html': retval.TypeText }) );
                    } else {
                      elem.adopt( new Element('option', { 'value': '?brand='+retval.BrandCode, 'html':  retval.BrandText  }) );
                    }
                                    
                });
              } else {
                retval = odata;
                if(retval.ModelCode) {
                  elem.adopt( new Element('option', { 'value': '?model='+retval.ModelCode, 'html': retval.ModelText+' rv.'+retval.ModelYear+' - '+retval.Power+'kW - '+retval.BoltPattern+'/'+retval.BoltCircle }) );
                } else if(retval.TypeCode) {                 
                  elem.adopt( new Element('option', { 'value': '?brand='+retval.BrandCode+'&type='+retval.TypeCode, 'html': retval.TypeText }) );
                } else {
                  elem.adopt( new Element('option', { 'value': '?brand='+retval.BrandCode, 'html': retval.BrandText }) );
                }
              }                                              
          }
          
          // eval(cwconf.afterSelUpdate);
          cwconf.loaderSwitch('hide');          
  }, 
	
	getModels : function() {
	    cwconf.loaderSwitch('show');	    
	    cwconf.clearOpt(cwconf.selectModel); 
      cwconf.clearOpt(cwconf.selectEngine);
      cwconf.getDataOpt(cwconf.selectModel, cwconf.selectManufacturer.get('value'));                	    
  }, 
  
  getEngines : function() { 
      cwconf.loaderSwitch('show');
      cwconf.clearOpt(cwconf.selectEngine);
      cwconf.getDataOpt(cwconf.selectEngine, cwconf.selectModel.get('value')); 
  },
  
  getWheels : function() {
    cwconf.loaderSwitch('show');
    // cwconf.elForImg.empty();
    // cwconf.elForWheels.empty();
    cwconf.clearCont();
    cwconf.getDataWheels(cwconf.selectEngine.get('value'));            
  },
  
  
  getDataWheels : function(getsend) {                                                     
	   var jsonRequest = new Request.JSON({
                          url: cwconf.url,
                          onSuccess: function(answ){
                              if(answ.ErrorHead.ErrorCode == 0) {
                                
                                if($chk(answ.DataLine)){
                                  cwconf.wheels = new Hash(answ.DataLine);
                                  cwconf.wheelsSizes = answ.Sizes.sort();
                                } else {
                                  cwconf.wheels = false;
                                }
                                  
                                  
                                cwconf.showWheels(answ.DataLine);
                              } else {
                                
                              }                                                                                                               
                          }                           
                        }).get(cwconf.url+getsend);                                           
  },
  
  
  showWheels : function(odata) {
                
      if($chk(odata)) {
      
      var icount = 0;
                        
        odata = new Hash(odata);                                        
        $each(odata.getValues(), function(eachval, pos){
        
          
          
          if($chk(new Hash(eachval).getKeys()[0])) {
          
          
        
            var prenosVal = new Hash(eachval);
            
            
            var lowPrice = 9999999;
            prenosVal.map( function(val){
              $each(val, function(val2) {
                if (val2.Price < lowPrice) {
                  lowPrice = val2.Price; 
                }
              });
            });
            
            
            var odrdv = prenosVal.getKeys().sort();              
            eachval = new Hash(prenosVal.get(odrdv[0])); 
            retval = eachval[0];
            
                                      
            var koloElm = new Element('div', {
              'class' : 'kolo',
              'events' : {
                'click' : function() {
                    cwconf.switchWheel(this);
                 } 
              }
            }).adopt( 
              new Element('h2', {
                'html' : retval.Size + '" - ' + retval.BoltPattern + '/' + retval.BoltCircle   
              }),
              new Asset.image(retval.Image, {
                'alt' :  retval.Size + '" - ' + retval.BoltPattern + '/' + retval.BoltCircle + ' - '+ retval.Article,
                'styles' : {
                  'width' : '100px',
                  'height' : '100px'
                }
                
              }),
              new Element('div', {
                'class' : 'priceFrom',
                'html' : 'Cena od:'   
              }).adopt(
                new Element('span', {
                  'html' : (lowPrice).toFloat().numberFormat(2,',','.')+' Kč'
                })
              )               
            );
            
            koloElm.store('retval', prenosVal);
            koloElm.store('sizes', prenosVal.getKeys().sort());
            
            if(pos == 0) {
              koloElm.addClass('active');
              cwconf.carImage = new Asset.image(retval.Image, {
                'alt' :   retval.Size + '" - ' + retval.BoltPattern + '/' + retval.BoltCircle + ' - '+ retval.Article ,
                'styles' : {
                  'width' : '200px',
                  'height' : '200px'
                }
              });
              
              cwconf.elForWhName.adopt( new Element('h2', {'html': retval.Size+'" '+retval.BoltPattern+'/'+retval.BoltCircle + ' - ' + retval.Article  } ));
              
              cwconf.elForImg.empty();
              cwconf.elForImg.adopt(cwconf.carImage);
              cwconf.buildVariants(prenosVal);
            }
            
            if( ((pos+1) % 8) == 0 && pos != 0) {
              koloElm.addClass('last');
            }
            
            cwconf.elForWheels.adopt(koloElm);
            if( ((pos+1) % 8) == 0 && pos != 0) {
                cwconf.elForWheels.adopt(new Element('div', {
                  'class' : 'rowDiv',
                  'html' : '&#160;'
                }));
            
            }
            
            icount ++;
            
          }                             
        });
        
      
        if(icount != 0) {
        
          cwconf.elForWheels.adopt(new Element('div', {
            'class' : 'cleaner',
            'html' : '&#160;'
          }));
        
        
          cwconf.elForSizes.adopt(
              new Element('span', {
                 'html' : 'Filtr rozměrů:'
              })
          );
          
          var whs = cwconf.wheelsSizes.clean();
                 
          whs.each( function(val, keysd) {                                      
              var actLabel = new Element('label', {
                    'for' : 'size'+val,
                    'html' : val+'"'
              });
                        
              var actInp = new Element('input', {
                      'type' : 'checkbox',
                      'id' : 'size'+val,
                      'name' : 'size'+val,
                      'value' : val
              });          
              actLabel.adopt(actInp);
              cwconf.elForSizes.adopt(actLabel); 
          });
          
          
          cwconf.elForSizes.adopt(
              new Element('a', {
                 'html' : 'nastav',
                 'href' : '#',
                 'class' : 'filtrSet',
                 'events' : {
                    'click' : function() {
                        cwconf.onlySize();
                        return false;
                    }
                 }
              })
          );
          
          
          if(cwconf.wheelsSizesSel.length == 0 || cwconf.wheelsSizesSel == false) {
            cwconf.wheelsSizesSel = whs.clean();
          }
          
          $each(cwconf.elForSizes.getElements('input'), function(elm){ 
              if(cwconf.wheelsSizesSel.contains(elm.get('value').toInt())) {
                elm.set('checked','true');
              }                   
          });
          
                      
          eval(cwconf.onWheelsShow);
              
        } else {
           cwconf.elForImg.set('html', '<h2>Pro Vámi zadaná kriteria bohužel nemáme vhodný disk</h2>');
           eval(cwconf.onWheelsUnShow);   
        }
      } else {
           cwconf.elForImg.set('html', '<h2>Pro Vámi zadaná kriteria bohužel nemáme vhodný disk</h2>');
           eval(cwconf.onWheelsUnShow);
      }
      
      cwconf.loaderSwitch('hide');
                       
      
  }, 
  
  onlySize : function() {   
      
     var whs = cwconf.wheelsSizes.clean();  
    
     cwconf.loaderSwitch('show');
     cwconf.wheelsOnlySize = false;         
     cwconf.wheelsSizesSel.empty();
        
     $each(cwconf.elForSizes.getElements('input'), function(elm){
        if(elm.get('checked')) {
          cwconf.wheelsSizesSel.include(elm.get('value').toInt());     
        }
     })
       
     if(cwconf.wheelsSizesSel.length > 0) {
        cwconf.wheelsOnlySize = new Hash();  
        $each(cwconf.wheels, function(val, keyname) {
          
          var tempH = new Hash(val).filter(function(val2, key2){
            return(cwconf.wheelsSizesSel.contains(key2.toInt()));
          });
          
          if(tempH.getLength() != 0) {
            cwconf.wheelsOnlySize.set(keyname, tempH);       
          }
          
          
          
        });
     } else {
        cwconf.wheelsSizesSel = whs;
        cwconf.wheelsOnlySize = cwconf.wheels;   
     }                     
    
      
    
     cwconf.clearContEls();
     
     // console.log(cwconf.wheelsOnlySize);   
     
     
                
     cwconf.showWheels(cwconf.wheelsOnlySize);
     
  }, 
  
  buildVariants : function(odata) {
    
    cwconf.elForVariants.empty();
    
    var sels = new Element('select', {
        'class' : 'styled',
        'name' : 'variants',
        'events' : {
          'change' : function(e) {
            cwconf.showVariant(this.getSelected().retrieve('data')[0]);          
          }
        }
    });
    
    var keys = odata.getKeys().sort();
    
    $each(keys, function(val1, key1) {     
      odata.get(val1).each(function(val2, key2) {
        var opt = new Element('option', {
          'value' : val2.Article,
          'html' : val2.Dimension + ' ET:'+ val2.Offset
        });
        opt.store('data', val2);
        sels.adopt(opt);        
        if(key1 == 0 && key2 == 0) {
          cwconf.buildInfo(val2);
        }  
      });
    });    
    cwconf.elForVariants.adopt(sels);
  },
  
  showVariant : function(odata) {     
    cwconf.carImage.set('src', odata.ImageOnCar);    
    cwconf.buildInfo(odata);             
  },
    
  buildInfo : function(odata) {
    cwconf.elForInfo.empty();
        
    cwconf.elForInfo.adopt( new Element('h3', {'html':'Technické informace'}));        
    
    var mytable = new HtmlTable({
          properties: {
              'border': 0,
              'cellspacing': 0,
              'cellpadding' : 0, 
              'class' : 'pneuSpec'
          },
          headers: [{content: odata.Size+'" '+odata.BoltPattern+'/'+odata.BoltCircle + ' - ' + odata.Article , properties: {colspan: 2}}],
          rows: [
              ['Kód:', odata.Article],
              ['Rozměr:', odata.Dimension],
              ['Rozteč:', odata.BoltPattern+'/'+odata.BoltCircle],
              ['ET:', odata.Offset]
          ]
    });
    cwconf.elForInfo.adopt(mytable);
    
    var mytable2 = new HtmlTable({
          properties: {
              'border': 0,
              'cellspacing': 0,
              'cellpadding' : 0, 
              'class' : 'recPneu'
          },
          headers: ['PNEU']
    });
    
    if($chk(odata.TyreLine.Tyre)) {
        var helparr = odata.TyreLine.Tyre.split('/');
        var pneusirka = '';
        var pneuvyska = '';
        var pneuprumer = '';
        var pneuzbytek = '';
        
        if($chk(helparr[1])) {
          pneusirka = helparr[0];
          helparr = helparr[1].split('R');
          if($chk(helparr[1])) {
            pneuvyska = helparr[0];
            helparr = helparr[1].split(' ');
            pneuprumer = helparr[0];            
            if($chk(helparr[1])) {
              pneuzbytek = helparr[1];
            }   
          }    
        }
        
        if($chk(pkAttID.sirka.get(pneusirka)) && $chk(pkAttID.vyska.get(pneuvyska)) && $chk(pkAttID.prumer.get(pneuprumer)) ) {
          mytable2.push([ new Element('a', { 
                              'href': cwconf.whereToBuyPneuURL+'?profil='+pkAttID.vyska.get(pneuvyska)+'&rafek='+pkAttID.prumer.get(pneuprumer)+'&sirka='+pkAttID.sirka.get(pneusirka), 
                              'html' : pneusirka+'/'+pneuvyska+'R'+pneuprumer,
                              'target' : '_blank'  
                              }), 
                          new Element('span', {
                              'html' : ' '+pneuzbytek
                          })   
                        ]);
                  
        } else {
          mytable2.push([odata.TyreLine.Tyre , ' ']);
        }
    } else {
      $each(odata.TyreLine, function(val){
          var helparr = val.Tyre.split('/');
          var pneusirka = '';
          var pneuvyska = '';
          var pneuprumer = '';
          var pneuzbytek = '';
          
          if($chk(helparr[1])) {
            pneusirka = helparr[0];
            helparr = helparr[1].split('R');
            if($chk(helparr[1])) {
              pneuvyska = helparr[0];
              helparr = helparr[1].split(' ');
              pneuprumer = helparr[0];
              pneuzbytek = '';
              if($chk(helparr[1])) {
                pneuzbytek = helparr[1];
              }   
            }    
          }
          
          if($chk(pkAttID.sirka.get(pneusirka)) && $chk(pkAttID.vyska.get(pneuvyska)) && $chk(pkAttID.prumer.get(pneuprumer)) ) {
            mytable2.push([ new Element('a', { 
                                'href': cwconf.whereToBuyPneuURL+'?profil='+pkAttID.vyska.get(pneuvyska)+'&rafek='+pkAttID.prumer.get(pneuprumer)+'&sirka='+pkAttID.sirka.get(pneusirka), 
                                'html' : pneusirka+'/'+pneuvyska+'R'+pneuprumer,
                                'target' : '_blank'  
                                }), 
                            new Element('span', {
                                'html' : ' '+pneuzbytek
                            })   
                          ]);
                    
          } else {
            mytable2.push([val.Tyre , ' ']);
          } 
      });
    }
    
    
    
    cwconf.elForInfo.adopt(mytable2);
                                                                    
    cwconf.elForInfo.adopt( 
            new Element('div', {'class' : 'addInfo'}).adopt(
                new Element('h3', {'html' : 'Ke stažení'}), 
                new Element('a', {'href' : odata.Certificate, 'html' : 'Certifikát - '+ odata.Article, 'title' : 'Certifikát - '+ odata.Article, 'target' : '_blank' })  
            ) 
    );
    
    cwconf.elForInfo.adopt( 
            new Element('div', {'class' : 'buyInfo'}).adopt(
                new Element('h3', {'html' : 'Koupit'}),
                new Element('span', {'html' : 'Cena za kus'}).grab(
                  new Element ('span', {'html' : (odata.Price).toFloat().numberFormat(2,',','.')+' Kč' }), 'top'
                ),
                new Element('a', {'href' : cwconf.whereToBuyURL + odata.URL, 'html' : 'KOUPIT', 'class': 'buyButt', 'target' : '_blank' })  
            ) 
    );
    
    

   // console.log(odata);
    
        
  },
  
  switchWheel : function(ref) {
    sizes = ref.retrieve('sizes');  
    
    $each(cwconf.elForWheels.getElements('div.active'), function(el){
        el.removeClass('active');
    });
    
    retval = ref.retrieve('retval');     
    cwconf.buildVariants(retval);    
    var first = retval.get(sizes[0])[0];    
    cwconf.carImage.set('src', first.Image);
    cwconf.carImage.set('alt', first.Size + '" - ' + first.BoltPattern + '/' + first.BoltCircle + ' - '+ first.Article);
    ref.addClass('active'); 
    
    cwconf.elForWhName.empty();
    cwconf.elForWhName.adopt( new Element('h2', {'html': first.Size+'" '+first.BoltPattern+'/'+first.BoltCircle + ' - ' + first.Article} ));
       
    cwconf.buildInfo(first);          
  }, 

	getDataOpt : function(refto, getsend) {                                                     
	   var jsonRequest = new Request.JSON({
                          url: cwconf.url,
                          // async: false,
                          onSuccess: function(answ){
                              if(answ.ErrorHead.ErrorCode == 0) {
                                  cwconf.makeOptions(refto, answ.DataLine);
                              } else {
                                  cwconf.makeOptions(refto, false);
                              }                                                                                                               
                          }                           
                        }).get(cwconf.url+getsend);                                           
  },
  
  loaderUpdate : function() {
      cwconf.loaderBox.setStyles({
            'position' : 'absolute',
            'top' : 0,
            'left' : 0,
            'width' : document.getScrollSize().x,
            'height' : document.getScrollSize().y, 
            'background-color' : '#000000',
            'opacity' : 0.6,
            'z-index' : '999',
            'display' : 'block'                           
        });
        
        cwconf.loaderImage.setStyles({
            'top' : ($(document).getSize().y / 2) + $(document).getScroll().y - 10,
            'left' : ($(document).getSize().x / 2) + $(document).getScroll().x - 110                                      
        });    
  }, 
  
  loaderSwitch : function(sh) {    
    if(sh == 'show') {
      cwconf.loaderUpdate();
      cwconf.ifraShim.show();
      cwconf.loaderBox.setStyle('display', 'block');  
       
    } else {
      cwconf.loaderBox.setStyle('display', 'none');
      cwconf.ifraShim.hide();
      eval(cwconf.afterSelUpdate);
    }
    
  }, 
  
  clearOpt : function(elm) {
    elm.empty().adopt( new Element('option', { 'value': '', 'html': cwconf.notice.defSelHTML }) ); 
  },
  
  clearCont : function() {
    cwconf.wheels = false;
    cwconf.wheelsSizes = false;
    cwconf.wheelsSizesSel = false;
    cwconf.elForImg.empty();
    cwconf.elForWheels.empty();
    cwconf.elForSizes.empty(); 
    cwconf.elForInfo.empty();
    cwconf.elForVariants.empty();
    cwconf.elForWhName.empty();
    
    eval(cwconf.onWheelsUnShow);
  },
  
  clearContEls : function() {    
    cwconf.elForImg.empty();
    cwconf.elForWheels.empty();
    cwconf.elForSizes.empty(); 
    cwconf.elForInfo.empty();
    cwconf.elForVariants.empty();
    cwconf.elForWhName.empty();    
  } 
  
  	
};


window.addEvent('load', function(){
  cwconf.init();
  
});



