﻿var Lang='en';
try
{
  if (window.opener)
  {
    openerUrl = window.opener.top.location.href;
  }
}
catch(e)
{
}

function AddToCart(sId)
{
  var oSelect = document.getElementById("sel"+sId);
  var oQty    = document.getElementById("txt"+sId);
  
  if (oSelect.value.length == 0)
  {
    if (Lang=='fr')
    {
      alert("SVP choisissez une option.");
    }
    else
    {
      alert("Please select one option.");
    }
    return;
  }
  
  var varId = oSelect.value;
  var maxqty = "200000000";
  
  if (varId.indexOf('-') > -1)
  {
    maxqty = varId.substring(varId.indexOf('-')+1, varId.length);
    varId = varId.substring(0, varId.indexOf('-'));
  }
  
  if (oQty.value.length == 0)
  {
    if (Lang=='fr')
    {
      alert("Vous n'avez pas entré de quantité pour cet item. Avant de l'ajouter à votre panier, SVP choisissez le produit spécifique que vous désirez dans la liste de sélection puis indiquez une quantité dans le champ QTÉ à droite du bouton 'Ajouter au panier'.");
    }
    else
    {
      alert("You have not entered a quantity for this item. Before adding an item to your shopping cart, please select the specific product you desire from the drop-down list and indicate a quantity in the QTY box just right of the 'Add to cart' button.");
    }
    return;
  }
  
  if (isNaN(oQty.value))
  {
    if (Lang=='fr')
    {
      alert("Vous avez entré des caractères non-numériques dans le champ QTÉ. SVP entrez uniquement des chiffres dans ce champ.");
    }
    else
    {
      alert("You have entered non-numeric characters in the QTY field. Please use digits only.");
    }
    return;
  }
  
  if (parseInt(maxqty,10) < oQty.value)
  {
    if (Lang=='fr')
    {
      alert("Vous ne pouvez pas commander une quantité supérieure à la quantité disponible (" + maxqty + ").");
    }
    else
    {
      alert("You cannot order a quantity greater than the available quantity (" + maxqty + ").");
    }
    return;
  }
  
  window.open("AddToCart.aspx?V="+varId+"&N="+oQty.value+"&Lang="+Lang, "_self");
  oQty.value = '';
}


function OpenImages(url)
{
  window.open(url,'images','height=600,width=520,resizable=1,scrollbars=1,menubar=0,location=0,titlebar=0,status=0');
}

function OnOff(div, status)
{
  image = document.getElementById("img" + div);
  layerframe = document.getElementById(div + "_iframe");
  leftAnchor = document.getElementById(div + "_leftAnchor");
  topAnchor = document.getElementById(div + "_topAnchor");
  
  var oDiv = document.getElementById(div);
  
  if (!oDiv)
  {
    alert(div + ' is not defined.');
    return;
  }
  
  if (status == null)
  {
    if (oDiv.style.display=='none')
    {
      if (leftAnchor) oDiv.style.left = GetLeftPos(leftAnchor);
      if (topAnchor) oDiv.style.top = GetTopPos(offsetTop);
      
      oDiv.style.display='block';
      if (layerframe)
      {
        layerframe.style.display = 'block';
        layerframe.style.width = oDiv.offsetWidth;
        layerframe.style.height = oDiv.offsetHeight;
        layerframe.style.left = oDiv.offsetLeft;
        layerframe.style.top = oDiv.offsetTop;
      }

      if (image) image.src = '../img20/off.gif';
    }
    else
    {
      oDiv.style.display='none';
      if (layerframe) layerframe.style.display = 'none';
      if (image) image.src = '../img20/on.gif';
    }
  }
  else if (status == 'On')
  {
    oDiv.style.display='block';
    if (layerframe)
    {
      layerframe.style.display = 'block';
      layerframe.style.width = oDiv.offsetWidth;
      layerframe.style.height = oDiv.offsetHeight;
      layerframe.style.left = oDiv.offsetLeft;
      layerframe.style.top = oDiv.offsetTop;
    }      
    if (image) image.src = '../img20/off.gif';
  }
  else
  {
    oDiv.style.display='none';
    if (layerframe) layerframe.style.display = 'none';
    if (image) image.src = '../img20/on.gif';
  }
}
