
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// ajax product detail technology
function load_technology(category_name){  
  if (category_name == 'rims') category_name = 'wheels';
  jQuery.post(home_url+lang+"/technology.htm?param[name]="+category_name, { 
         layout: 'clean',             
         time: new Date().getTime() },         
         function (data) {                                                                    
            jQuery('.ajax_technology').html(data);                            
            document_height = jQuery(document).height();
            scrollpos = jQuery(window).scrollTop();
            jQuery('.jump_to_category').css("display",'none');
            if( scrollpos != 0){
              pos = scrollpos - 60;
              jQuery('.bm_lightbox.tech.'+category_name).css("top",pos);      
            }else{
              pos = 0;
              jQuery('.bm_lightbox.tech.'+category_name).css("top",pos);                 
            }
            jQuery('.bm_lightbox.tech.'+category_name).fadeIn();
         });  
}

// show jump to category
function show_jump_category(){
  jQuery('.bm_lightbox.tech').fadeOut();
  
  document_height = jQuery(document).height();
  scrollpos = jQuery(window).scrollTop();
  jQuery('.jump_to_category').css("display",'none');
  if( scrollpos != 0){
    pos = scrollpos;
    jQuery('.jump_to_category').css("top",pos);      
  }else{
    pos = 200;
    jQuery('.jump_to_category').css("top",pos);                 
  }           
  jQuery('.jump_to_category').fadeIn();
}


function hide_jump_category(){
  jQuery('.jump_to_category').fadeOut();
} 

// ajax change variation on product detail
function variation_update(var_id,category_name,product_name){
    
  jQuery(".col_left,.col_right").css("opacity","0.3");            
  jQuery(".ajax_loader").show();      
  
  jQuery.post(home_url+lang+"/products.htm?var_id="+var_id+"&p_category="+category_name+"&id="+product_name, { 
       layout: 'clean',       
       time: new Date().getTime() },
       
       function (data) {         
        jQuery(".ajax_loader").hide();
        jQuery('.ajax_replace').html(data);
        jQuery(".col_left,.col_right").css("opacity","1");
        jQuery(window).scrollTo( 114 , 0 );
        sIFR.replace(octin, {
          selector: '.h1.sifr',            
          css: {'.sIFR-root' : { 'font-size': '48px','color': '#000000', 'leading': -10, 'text-transform':'uppercase','font-weight': 'bold','background-color':'transparent'}},   // leading adjusts line-height
          wmode: 'transparent',
        	fitExactly: true,    
          offsetTop: 0,
          tuneWidth: 450,
          tuneHeight: -1
        });
        sIFR.replace(octin, {
          selector: 'h1.sifr_detail',            
          css: {'.sIFR-root' : { 'font-size': '26px','color': '#000000', 'leading': -5, 'text-transform':'uppercase','font-weight': 'bold','background-color':'transparent'}},   // leading adjusts line-height
          wmode: 'transparent',
        	fitExactly: true,    
          offsetTop: 0,
          tuneWidth: 0,
          tuneHeight: 8
        });
        tb_init('a.thickbox');
      }
  );
}
// ajaxu add compare
function add_to_compare(category_id,product_id,var_id){
  
  jQuery.post(home_url+lang+"/add_to_compare.htm?category_id="+category_id+"&id="+product_id+"&var_id="+var_id, { 
         layout: 'clean',       
         time: new Date().getTime() },
         
         function (data) { 
          if(data){          
            jQuery('.ajax_product_compare').html(data);  
            jQuery('.button.compare').hide();
            jQuery('.button.no_compare').fadeIn();          
          }
        }
    );
}

// tooltip in product detail product in category
function show_all_product_in_category(count_product_in_category){
  for( k = 0; k<=count_product_in_category; k++){
      jQuery("#trigger_product_"+k).css("display","block");
  }                          
  jQuery("#button_product_in_cat").css("visibility","hidden");
}

//product detail document ready
function product_detail_ready(product_pictograms_count,product_in_category_count){
 
  for( i = 0; i<=product_pictograms_count; i++){      
    jQuery("#trigger_"+i).tooltip({  
      position: ['top', 'left'], 
      offset: [10, 70]
    });                    
  }
      
  for( k = 0; k<=product_in_category_count; k++){
    jQuery("#trigger_product_"+k).tooltip({  
      position: ['top', 'right'], 
      offset: [10, -445]
    });       
  }
    
}

// ajax send product to mail
function send_product(){    
      
   from_name =  jQuery(".send_friend .from_name").val();
   from_email =  jQuery(".send_friend .from_email").val();
   to_name =  jQuery(".send_friend .to_name").val();
   to_email =  jQuery(".send_friend .to_email").val();
   
   product_id =  jQuery(".product_id").val();
   variation_id =  jQuery(".variation_id").val();
   category_id =  jQuery(".category_id").val();
          
   param = "&param[from_name]="+from_name+"&param[from_email]="+from_email+"&param[to_name]="+to_name+"&param[to_email]="+to_email;              
   ids = "&id="+product_id+"&var_id="+variation_id+"&category_id="+category_id;                                         
   //alert(ids);
  
   action = "&action=send_product_friend";                                            
   
   jQuery.post(home_url+lang+"/products.htm?"+param+ids+action, {                                                
       layout: 'clean',
       time: new Date().getTime() },             
       function (data) {                                                                                            
            jQuery('.ajax_send_compare').html(data);              
      }
     );
}

// ajax product list change page or subcategory
function update_product(page,subcategory,category_id){ 
  
   var cond = '';
                
   
   for(i=0 ; i < (subcategory.length)-1 ; i++){                                    
     name = 'checkbox'+subcategory[i];       
     if (document.getElementById(name).checked == true){       
        cond = cond+"&param[subcategory]["+subcategory[i]+"] = on";          
     }           
   }
   
   if(page || page == 0){
    jQuery(window).scrollTo( 0 , 0 );
   }  
   
   list_navigation = ('list_param[from]='+page+'');                    
          
   jQuery(".col_left .product").css("opacity","0.3");             
   jQuery(".ajax_loader").show();
                             
   jQuery.post(home_url+lang+"/products.htm?"+list_navigation+cond+"&p_category="+category_id, { 
     layout: 'clean',       
     last: 1,              
     time: new Date().getTime() },
     
     function (data) { jQuery('.ajax_replace').html(data); 
                        
                        sIFR.replace(octin, {
                          selector: 'h1',            
                          css: {'.sIFR-root' : { 'font-size': '48px','color': '#000000', 'leading': -10, 'text-transform':'uppercase','font-weight': 'bold','background-color':'transparent'}},   // leading adjusts line-height
                          wmode: 'transparent',
                        	fitExactly: true,    
                          offsetTop: 0,
                          tuneWidth: 120,
                          tuneHeight: 8
                        });
                        
                        sIFR.replace(octin, {
                          selector: 'h2 a',            
                          css: {'.sIFR-root' : { 'font-size': '24px','color': '#000000', 'leading': -10, 'text-transform':'uppercase','font-weight': 'bold','background-color':'transparent'}},   // leading adjusts line-height
                          wmode: 'transparent',
                        	fitExactly: true,    
                          offsetTop: 0,
                          tuneWidth: 120,
                          tuneHeight: 8
                        });
                              
    }
  );
}

// show pictgorams in product list
function load_pictograms_list(pictograms_count){
  for( i = 0; i<=pictograms_count; i++){
      jQuery("#trigger_"+i).tooltip({  
        position: ['top', 'left'], 
        offset: [10, 60] 
      });
  }
}

var active;
// gadgets show resolution
function show_resolution(wallpaper){    
  if(active == wallpaper){
    jQuery('.'+wallpaper).fadeOut();
    active = "";
  }else{
    active = wallpaper;
    jQuery('.resolution').fadeOut();
    jQuery('.'+wallpaper).fadeIn();
  }    
}

// support other language
function show_download_lang(what, filename){
    
  if(active == what){
    jQuery('.lang_'+active+' .download_box').slideToggle(1000);
    active = "";    
    jQuery('.file.'+what).animate({ backgroundPosition: "-291px 0px"}, 1000 );
  }else{  
    if(active){
      jQuery('.file.'+active).css("background","none");
      jQuery('.lang_'+active+' .download_box').slideToggle(1000);
            
      jQuery('.lang_'+active).html();
    }
    active = what;    
    jQuery('.file.'+what).css("background","url(../images/bg_file_active.gif) repeat-y -291px top");
    jQuery('.file.'+what).animate({ backgroundPosition: "0px 0px"}, 1000 );
    load_lang_box = jQuery('.load_lang').html();        
    replased = replaceAll(load_lang_box,'file',filename);            
    jQuery('.lang_'+what).html(replased);    
    jQuery('.lang_'+what+' .download_box').slideToggle(1000);
  }
}

function replaceAll(text, strA, strB){
    while ( text.indexOf(strA) != -1){
        text = text.replace(strA,strB);
    }
    return text;
}

var rider_id = 0; 
var mouse_hover = true; 

function check_hover(){
  jQuery('.rider').hover(function(){ mouse_hover = false; },function(){ mouse_hover = true; });   
}
// change riders wtb-life  
function change_rider(rider_count){                 
  check_hover();      
  if( mouse_hover == true ){                  
    jQuery('.rand_'+rider_id).fadeOut(1000,function () {
      jQuery('.rand_'+rider_id).css("display","none");
      if(rider_id == rider_count ){
        rider_id = 0;
      }else{
        rider_id = rider_id + 1;
      }                  
      jQuery('.rand_'+rider_id).fadeIn(1000);
    });        
  }          
}

//ajax newsletter
function send_newsletter(){          
   var action,email,country,age,param,time,data;
   
   action =  jQuery(".newsletter .action").val();      
   email =  jQuery(".newsletter .email").val();
   country =  jQuery(".newsletter .select_country").val();
   age =  jQuery(".newsletter .age").val();
   
   param = "action="+action+"&param[email]="+email+"&param[country]="+country+"&param[age]="+age;                                                                                              
   jQuery.post(home_url+lang+"/newsletter.htm?"+param,{                                                
       layout: 'clean',
       time: new Date().getTime() 
       },             
       function (data) {                                                                                                              
            jQuery('.ajax_newsletter').html(data);              
      }
   );
}
// search form
function send_search(text_err){
  search = jQuery('.input_search').val();      
  if(search != ""){
    jQuery('.search_form').submit();
  }else{
    jQuery('.search_echo').text(text_err);
  }
}

// select product div
function show_select_product(){ 
  document_height = jQuery(document).height();
  scrollpos = jQuery(window).scrollTop();
  if( scrollpos != 0){
    pos = scrollpos - 30;
    jQuery(".bm_lightbox").css("top",pos);
    jQuery(".home .bm_lightbox").css({'top' : pos-275});
  }else{
    pos = 0;
    jQuery(".bm_lightbox").css("top",pos);            
    jQuery(".home .bm_lightbox").css({'top' : pos-300});
    
  }    
      
  jQuery('.bm_lightbox').fadeIn();       
}

function hide_select_category(){    
  jQuery('.bm_lightbox').fadeOut();       
}

// show top product compate 
function show_block() {
            
  if(jQuery('.compare_list').hasClass('display')) {            
    jQuery('.compare_list').removeClass('display');      
    jQuery('.compare_list').fadeOut();      
    jQuery('#button_compare').css("background-position","0px 0px");
    setTimeout("jQuery('.products_pictograms').css('z-index','20');jQuery('.top_compare').css('z-index','0');",500); 
  }else{
    jQuery('.compare_list').addClass('display');
    jQuery('.products_pictograms').css("z-index","0");
    jQuery('.pictogram_item').css("z-index","0");
    jQuery('.top_compare').css("z-index","10");
    jQuery('.compare_list').fadeIn();
    jQuery('#button_compare').css("background-position","0px -25px");  
  }

}