function hide(element)
{
  this.className = 'hide';
}

function changeMainImage(prevId)
{
  var prevIdSrc = document.getElementById(prevId).src;
  var mainImage = document.getElementById("mainImage");
  mainImage.setAttribute("src", prevIdSrc);
}

var currentSize = "";

function changeSize(productId, size, outOfStock)
{
  if(outOfStock == "false")
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "";

  }
  else
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "hide";

    var id = document.getElementById("id");
    id.value = productId;

    if(size == "Small")
    {
      if (currentSize == "")
      {
        document.getElementById("s").src = "http://i.3sixteen.com/img/btn/btn_sizing_s_b.gif";
        currentSize = "s";
      }
      else if(currentSize != "s")
      {
        document.getElementById(currentSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentSize +".gif";
        document.getElementById("s").src = "http://i.3sixteen.com/img/btn/btn_sizing_s_b.gif";
        currentSize = "s";
      }  
      else
      {
        document.getElementById("s").src = "http://i.3sixteen.com/img/btn/btn_sizing_s.gif";
        currentSize = "";
      }
    }
    else if(size == "Medium")
    {
      if (currentSize == "")
      {
        document.getElementById("m").src = "http://i.3sixteen.com/img/btn/btn_sizing_m_b.gif";
        currentSize = "m";
      }
      else if(currentSize !="m") 
      {  
        document.getElementById(currentSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentSize +".gif";
        document.getElementById("m").src = "http://i.3sixteen.com/img/btn/btn_sizing_m_b.gif";
        currentSize = "m";
      }
      else
      {
        document.getElementById("m").src = "http://i.3sixteen.com/img/btn/btn_sizing_m.gif";
        currentSize = "";
      }
    }
    else if(size == "Large")
    {
      if (currentSize == "")
      {
        document.getElementById("l").src = "http://i.3sixteen.com/img/btn/btn_sizing_l_b.gif";
        currentSize = "l";
      }
      else if(currentSize != "l")
      {
        document.getElementById(currentSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentSize +".gif";
        document.getElementById("l").src = "http://i.3sixteen.com/img/btn/btn_sizing_l_b.gif";
        currentSize = "l";
      }
      else
      {
        document.getElementById("l").src = "http://i.3sixteen.com/img/btn/btn_sizing_l.gif";
        currentSize = "";
      }
    }
    else if(size == "X-Large")
  {
      if (currentSize == "")
      {
        document.getElementById("xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_xl_b.gif";
        currentSize = "xl";
      }
      else if(currentSize != "xl")
      {
        document.getElementById(currentSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentSize +".gif";
        document.getElementById("xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_xl_b.gif";
        currentSize = "xl";
      }
      else
      {
        document.getElementById("xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_xl.gif";
        currentSize = "";
      }
    }
    else if(size == "XX-Large")
    {
      if (currentSize == "")
      {
        document.getElementById("2xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_2xl_b.gif";
        currentSize = "2xl";
      }
      else if( currentSize != "2xl")
      {
        document.getElementById(currentSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentSize +".gif";
        document.getElementById("2xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_2xl_b.gif";
        currentSize = "2xl";
      }
      else
      {
        document.getElementById("2xl").src = "http://i.3sixteen.com/img/btn/btn_sizing_2xl.gif";
        currentSize = "";
      }
    }
    else
    {

    }
  }
}

var currentBottomSize = "";

function changeBottomSize(productId, size, outOfStock)
{
  if(outOfStock == "false")
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "";
  }
  else
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "hide";

    var id = document.getElementById("id");
    id.value = productId;

    if (currentBottomSize == "")
    {
      document.getElementById(size).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + size + "_b.gif";
      currentBottomSize = size;
    }
    else if(currentBottomSize != size)
    {
      document.getElementById(currentBottomSize).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentBottomSize +".gif";
      document.getElementById(size).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + size + "_b.gif";
      currentBottomSize = size;
    }  
    else
    {
      document.getElementById(size).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + size + ".gif";
      currentBottomSize = "";
    }
  }
}

var currentFootwearSize = "";

function changeFootwearSize(productId, size, outOfStock)
{
  var footwearId = size.replace(".","_");


  if(outOfStock == "false")
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "";
  }
  else
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "hide";

    var id = document.getElementById("id");
    id.value = productId;

    if (currentFootwearSize == "")
    {
      document.getElementById(footwearId).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + footwearId + "_b.gif";
      currentFootwearSize = size;
    }
    else if(currentBottomSize != size)
    {
      document.getElementById(currentFootwearSize.replace(".","_")).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + currentFootwearSize.replace(".","_") +".gif";
      document.getElementById(footwearId).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + footwearId + "_b.gif";
      currentFootwearSize = size;
    }  
    else
    {
      document.getElementById(footwearId).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + footwearId + ".gif";
      currentFootwearSize = "";
    }
  }
}



var os= ""

function changeOS(productId, size, outOfStock)
{
  if(outOfStock == "false")
  {
    var outOfStock = document.getElementById("outOfStock");
    outOfStock.className = "";
  }
  else
  {
    var id = document.getElementById("id");
    id.value = productId;

    if (os == "")
    {
      document.getElementById(size).src = "http://i.3sixteen.com/img/btn/btn_sizing_" + size +  "_b.gif";
      os = size;
    }
    else
    {
      document.getElementById(size).src = "http://i.3sixteen.com/img/btn/btn_sizing_" +size + ".gif";
      os = "";
    }
  }
}

function cartAddSubmit()
{
  if(currentSize != "" || currentBottomSize != "" || os != "" || currentFootwearSize != "")
    document.forms.cartadd.submit();
}

function checkoutSubmit()
{
  var checkout = document.createElement('input');
  checkout.setAttribute('type', 'hidden'); 
  checkout.setAttribute('name', 'checkout');
  checkout.setAttribute('value', 'PROCEED TO CHECKOUT');

  document.getElementById('cart-bottomDesc').appendChild(checkout);
  document.forms.cartform.submit();
}


function loadPreviewPics(imageUrl, numPrevImages)
{
  var stringIndex = imageUrl.lastIndexOf('products/');
  var sub = imageUrl.substr(stringIndex);
  var url = 'http://i.3sixteen.com/img/';
  var product = sub.substring(sub.indexOf('/') + 1,sub.indexOf('_1_small'));
  var collection = product.substring(0,product.indexOf('_'));

  for(var i = 2; i <= numPrevImages; i ++)
  {
    alert("here");
    var preview = 'preview' + i;
    var previewImage = document.getElementById(preview);
 alert("here1");
    previewImage.src = url + collection + '/' + product + '_' + i + '.jpg';
    alert("here2");
   }
}

function addBorder(element, rightImage)
{
  
  if(element.src != "" && element.width != 0)
  {
    element.className = "";
    if(rightImage == false)
    {
      element.parentNode.className="previewPic";
      
    }
    else
    {
      element.parentNode.className="previewPicRight";
    } 
  } 
}