function product_recalculate_price(id_product) {
    
  var id_product = parseInt(id_product);
  var qty = parseInt($('#qty_'+id_product).val());
  
  if((id_product>0) && (qty>0)) 
  {
    
    $.ajax({
            type : 'POST',
            url : './forms/product_ajax.php',
            dataType : 'JSON',
            data: {
                op: 'recalculate_item_price',
                id: id_product,
                i_qty: qty
            },
            success : function(data){
                data = eval(data);
                //window.alert(data);
                for ( key in data[0] )//get key => value
                    {    
                        $('#item_count').text(data[0][key]);    
                    }
                for ( key in data[1] )//get key => value
                    {    
                        $('#item_price_'+id_product).text(data[1][key]);    
                    }
                for ( key in data[2] )//get key => value
                    {    
                        $('#subtotal').text(data[2][key]);    
                        $('#top_subtotal').text(data[2][key]);    
                    }              
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $('#item_price').text("-1");
            }
          });    
  }
  else 
    {   
        if(qty==0)
            {
                $('#item_price_'+id_product).text("$0");    
            }
            else
                {
                    window.alert("Entered quantity is not a valid number");
                }
    }
  
}
  
function calculate_freight(action) {
  var ok = true;
  
  for(i=0;i<$('#postcode').val().length;i++)
    {   
        if(($('#postcode').val().charAt(i)<'0')||($('#postcode').val().charAt(i)>'9'))
            {                   
                ok=false;
            }
    }
  if(($('#postcode').val().length>0)&&($('#postcode').val()!='Delivery Postcode') && ok==true)
    {
        $.ajax({
            type : 'POST',
            url : './forms/product_ajax.php',
            dataType : 'JSON',
            data: {
                op: 'calculate_freight',
                post_code: $('#postcode').val()
            },
            success : function(data){
                
                if((data!='NOT VALID'))
                    {
                      if(!isNaN(data)){
                        $('#freight').text(data);  
                        if(action=='manual')
                            {
                                $('.chck_btn img').css('display','block');                
                                $('#checkout_row').css('background-color','black');                
                            }
                      }else{
                        $('#freight_error').html(data);
                        $('#freight_error').parent().parent().show();
                      }
                    }
                    else
                        {
                            window.alert("Entered postcode is not valid");
                        }                   
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $('#freight').text("Error");
                //alert("Some error occured during the freight calculation! Please try again.");
                $('#freight_error').html("Some error occured during the freight calculation! Please try again.");
                $('#freight_error').parent().parent().show();
            }
          });    
    }
    else
        {
            window.alert("Postcode is a required field!");
        }   
}

function display_related_product_detail(id_prod_main, id_product, id_cat, id_dept) {
  $('#ajax_background').show();
  $.ajax({
      type : 'POST',
      url : './forms/product_ajax.php',
      dataType : 'JSON',
      data: {
          op: 'display_related_product',
          id_product: parseInt(id_product),
          id_cat: parseInt(id_cat),
          id_dept: parseInt(id_dept),
          id_product_main: parseInt(id_prod_main)
      },
      success : function(data){        
        $('#ajax_container').show();
        $('#ajax_container').html(data);
        easytabs('1', '1');
      },
      error : function(XMLHttpRequest, textStatus, errorThrown) {
          $('#ajax_container').html("Some error occured!");
      }
    });
}

function hide_related_product_detail(){
  $("#ajax_container").hide();
  $("#ajax_background").hide();
}
