var current_onglet = "info";
var goto_review_form = false;

$(document).ready
( function()
  { init_onglets();
    init_overs();
    set_current_onglet();
    check_goto();
  }
);

function pre_load_imgs()
{ (new Image()).src = "/images/simtic/fiche_produit/onglets/add_to_cart_over.png";
}

function check_goto()
{ if(goto_review_form)
  { window.location.href = "#review_form";
  }
}

function set_current_onglet()
{ if(current_onglet == "info") info_on();
  if(current_onglet == "composition") composition_on();
  if(current_onglet == "temoignages") temoignages_on();
}

function init_onglets()
{ $("#fp_onglet_info").click(function() { info_on(); });
  $("#fp_onglet_composition").click(function() { composition_on(); });
  $("#fp_onglet_temoignages").click(function() { temoignages_on(); });
}

function info_on()
{ $("#fp_onglet_info").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_info_v.png)";
  $("#fp_onglet_sep1").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/v_m_1.png)";
  $("#fp_onglet_composition").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_composition_m.png)";
  $("#fp_onglet_sep2").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/m_m_2.png)";
  $("#fp_onglet_temoignages").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_temoignages_m.png)";
  $("#fp_onglet_info").get(0).blur();
  $("#fpoc_info").get(0).style.display = "block";
  $("#fpoc_composition").get(0).style.display = "none";
  $("#fpoc_temoignages").get(0).style.display = "none";
}

function composition_on()
{ $("#fp_onglet_info").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_info_m.png)";
  $("#fp_onglet_sep1").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/m_v_1.png)";
  $("#fp_onglet_composition").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_composition_v.png)";
  $("#fp_onglet_sep2").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/v_m_2.png)";
  $("#fp_onglet_temoignages").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_temoignages_m.png)";
  $("#fp_onglet_composition").get(0).blur();
  $("#fpoc_info").get(0).style.display = "none";
  $("#fpoc_composition").get(0).style.display = "block";
  $("#fpoc_temoignages").get(0).style.display = "none";
}

function temoignages_on()
{ $("#fp_onglet_info").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_info_m.png)";
  $("#fp_onglet_sep1").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/m_m_1.png)";
  $("#fp_onglet_composition").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_composition_m.png)";
  $("#fp_onglet_sep2").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/m_v_2.png)";
  $("#fp_onglet_temoignages").get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/onglet_temoignages_v.png)";
  $("#fp_onglet_temoignages").get(0).blur();
  $("#fpoc_info").get(0).style.display = "none";
  $("#fpoc_composition").get(0).style.display = "none";
  $("#fpoc_temoignages").get(0).style.display = "block";
}

function init_overs()
{ $("#fpoc_a_add").each
  ( function ()
    { $(this).hover
      ( function() { $(this).get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/add_to_cart_over.png)"; },
        function() { $(this).get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/add_to_cart.png)"; }
      );
    }
  );
  $("#fp_add").each
  ( function ()
    { $(this).hover
      ( function() { $(this).get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/add_to_cart_over.png)"; },
        function() { $(this).get(0).style.backgroundImage = "url(images/simtic/fiche_produit/onglets/add_to_cart.png)"; }
      );
    }
  );
}

function set_qty(i)
{ var n = parseInt(document.forms["cart_quantity"].qty.value);
  if(n + i > 0) document.forms["cart_quantity"].qty.value = n + i;
}

function check_review(js_error, min_length, review_text)
{ var error = false;
  var error_message = js_error;
  var review = document.product_reviews_write.review.value;
  if(review.length < min_length)
  { error_message += review_text;
    error = true;
  }
  if(error) alert(error_message);
  return !error;
}
