/*FILTERS*/
/*includes/boxes/filters.php*/

function categoryFilterByManufacturer(category_id){
  //update subcategories select
	//alert('c:'+category_id+'sc:'+$('#subcategory_id').val()+'m:'+$('#manufacturer_id').val()+'lp:'+$('#lowest_price').val()+'hp:'+$('#highest_price').val());
  $.ajax({
    type: "POST",
    url: "ajax_call.php",
	data: "file_name=filter_category.php&category_id="+category_id+"&subcategory_id="+$('#subcategory_id').val()+"&manufacturer_id="+$('#manufacturer_id').val(),
	success: function(datos){ $('#subcategory_id').children().remove().end().append(datos); }
  });
  
  //update prices select
  $.ajax({
	type: "POST",
	url: "ajax_call.php",
	data: "file_name=filter_price.php&category_id="+category_id+"&manufacturer_id="+$('#manufacturer_id').val()+"&lowest_price="+$('#lowest_price').val()+"&highest_price="+$('#highest_price').val()+"&ajax=1",
	success: function(datos){ $('#filter_price').children().remove().end().append(datos); }
  });
}


function manufacturerFilterByCategory(subcategory_ids,category_id,languages_id){
  //update manufacturers select
  $.ajax({
    type: "POST",
    url: "ajax_call.php",
	data: "file_name=filter_manufacturer.php&category_id="+$('#subcategory_id').val()+"&subcategory_ids="+subcategory_ids+"&manufacturer_id="+$('#manufacturer_id').val(),
	success: function(datos){ $('#manufacturer_id').children().remove().end().append(datos); }
  });
  
  //update prices select
  $.ajax({
	type: "POST",
	url: "ajax_call.php",
	data: "file_name=filter_price.php&category_id="+category_id+"&subcategory_id="+$('#subcategory_id').val()+"&lowest_price="+$('#lowest_price').val()+"&highest_price="+$('#highest_price').val()+"&ajax=1",
	success: function(datos){ $('#filter_price').children().remove().end().append(datos); }
  });
  
  //update attributes selecter
  /*$.ajax({
	type: "POST",
	url: "ajax_call.php",
	data: "file_name=filter_attribute.php&languages_id="+languages_id+"&category_id="+category_id+"&subcategory_id="+$('#subcategory_id').val()+"&manufacturer_id="+$('#manufacturer_id').val()+"&lowest_price="+$('#lowest_price').val()+"&highest_price="+$('#highest_price').val()+"&attribute_id="+$('#attribute_id').val()+"&ajax=1",
	success: function(datos){ $('#attribute_id').children().remove().end().append(datos); }
  });*/
}

function optionFilterByAttribute(category_id){
  //update options
  /*$.ajax({
    type: "POST",
    url: "ajax_call.php",
    data: "file_name=filter_attribute.php&category_id="+category_id+"&subcategory_id="+$('#subcategory_id').val()+"&manufacturer_id="+$('#manufacturer_id').val(),
    success: function(datos){
      $('#subcategory_id').children().remove().end().append(datos);
    }
  });*/  
}

/*checkout_shipping.php*/
function changeTransRadioButton(type){
  if(type=='default'){
    document.getElementById('product_trans').value='0';
    document.getElementById('tipo_recogida').checked='checked';
  }
  if(type=='p_transport'){
    document.getElementById('tipo_recogida_p').checked='checked';
    document.getElementById('product_trans').value='1';
  }
  changeTranspotPrice(type);
}

//checkout_shipping.php
function changeTranspotPrice(type){
  var price_d_i=document.getElementById('price_default_i').value;
  var price_d_d=document.getElementById('price_default_d').value;
  var price_t_i=document.getElementById('price_transport_i').value;
  var price_t_d=document.getElementById('price_transport_d').value;
  if(type=='default'){
    document.getElementById('price_integer').innerHTML=price_d_i;
	document.getElementById('price_decimal').innerHTML=price_d_d;
	document.getElementById('shipping').value='table_'+price_d_i+'.'+price_d_d;
  }
  if(type=='p_transport'){
    document.getElementById('price_integer').innerHTML=price_t_i;
	document.getElementById('price_decimal').innerHTML=price_t_d;
	document.getElementById('shipping').value='table_'+price_t_i+'.'+price_t_d;
  }
}

function showPricesSlider(minValue,maxValue,minSelected,maxSelected){
	if(!minSelected || minSelected<0){ minSelected=minValue; }
	if(!maxSelected || maxSelected<0){ maxSelected=maxValue; }
	
	$(function() {
        $slider = $("#slider");//Caching slider object
        $amount = $("#amount");//Caching amount object
        $products = $('#products');//Caching product object
        $ajaxMessage =  $('#ajaxMessage');//Caching ajaxMessage object
        
        $slider.slider({
            range: true, // necessary for creating a range slider
            min: minValue, // minimum range of slider
            max: maxValue, //maximimum range of slider
            values: [minSelected, maxSelected], //initial range of slider
            slide: function(event, ui) { // This event is triggered on every mouse move during slide.
                $amount.html('&euro;' + ui.values[0] + ' - &euro;' + ui.values[1]);//set value of  amount span to current slider values
            },
            stop: function(event, ui){//This event is triggered when the user stops sliding.
                $ajaxMessage.css({display:'block'});
                /*$products.find('ul').css({opacity:.2});                
                $products.load('ajaxSlider.php?minValue='+ui.values[0]+'&maxValue='+ui.values[1],'',function(){
                    $ajaxMessage.css({display:'none'});
                });*/
                //keep changed prices in inputs
                $('#lowest_price').val(ui.values[0]);
                $('#highest_price').val(ui.values[1]);
            }
        });

        $amount.html('&euro;' + $slider.slider("values", 0) + ' - &euro;' + $slider.slider("values", 1));
    });
}

//contact_us.php
function infoTecnChange(check){
  if(check || $('.destino_tecn_check').attr('checked')){
	document.getElementById('numPedido').style.visibility='hidden';
	document.getElementById('info_tecn_check').value='1';	
  }else{
	document.getElementById('numPedido').style.visibility='visible';
	document.getElementById('info_tecn_check').value='0';
  }
}
var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.contact_us.destino_email[0]) {
    document.contact_us.destino_email[buttonSelect].checked=true;
  } else {
    document.contact_us.destino_email.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}
