/* customize */

function setOptionTitle(value)
{
  window.status = value;
  return true;
}

function setOption(option_id)
{
  if(!document.getElementById)
    return true;
  else
  {
    oOption_link_side = document.getElementById('option_tr_side_' + current_option);
    if(oOption_link_side)
      oOption_link_side.className = '';
    oOption = document.getElementById('option_' + current_option);
    if(oOption)
      oOption.style.display = 'none';

    oOption_link_side = document.getElementById('option_tr_side_' + option_id);
    if(oOption_link_side)
      oOption_link_side.className = 'selectedLinkSide';
    oOption = document.getElementById('option_' + option_id);
    if(oOption)
      oOption.style.display = 'block';

    current_option = option_id;

    return false;
  }
}

function setOptionValue(option_id, value_id, description, animate)
{
  var returnValue = false;
  var animate = true;
  var IsRestricted = false;
  var i = 0;
  if(arguments.length == 4)
    animate = arguments[3];
  if(!overlayLoaded || !oForm)
    setTimeout('setOptionValue(\'' + option_id + '\', \'' + value_id + '\', \'' + description + '\', ' + animate + ')', 500);
  else
  {
    if(value_id)
    {
      for(i = 0; i < options[option_id].restrictions.length; i++)
      {
        if(isChecked(oForm.elements['option_' + options[option_id].restrictions[i]]))
        {
          IsRestricted = true;
          alert(options[option_id].restriction_message);
          options[option_id].checked = false;
          break;
        }
      }
    }
    if(!IsRestricted)
    {
      options[option_id].checked = (!oForm.elements['option_' + option_id].length) ? oForm.elements['option_' + option_id].checked : true;
      oImage = (window.frames['overlay']) ? window.frames['overlay'].document.getElementById('option_image_' + option_id) : document.getElementById('option_image_' + option_id);
      oImage.src = (value_id) ? options[option_id].values[value_id].overlay.src : blank.src;
      if(!value_id && oImage.runtimeStyle && oImage.runtimeStyle.filter && oImage.runtimeStyle.filter != '')
        oImage.runtimeStyle.filter = '';
      oImage.onerror = function()
      {
        oImage.src = '/images/t.gif';
      }
      oOptionDD = document.getElementById('product-option-' + option_id);
      oOptionsPriceTotal = document.getElementById('options-price-total');
      oProductPriceTotal = document.getElementById('product_price_total');
      if(oOptionDD)
      {
        if(options[option_id].checked)
        {
          if(oOptionDD.style.display != 'block') oOptionDD.style.display = 'block';
          document.getElementById('option_value_' + option_id).innerHTML = (description && description.length > 0) ? '(' + description + ')' : '';
          if(animate)
            new Effect.Highlight(oOptionDD, { startcolor: '#cccc01', endcolor: '#e6e6e6', duration: 0.5 });
        }
         else
          oOptionDD.style.display = 'none';
//          new Effect.BlindUp(oOptionDD);
      }
      if(oOptionsPriceTotal)
      {
        oOptionsPriceTotal.innerHTML = dollarFormat('' + getOptionsPrice());
        if(animate)
          new Effect.Highlight(oOptionsPriceTotal, { startcolor: '#cccc01', endcolor: '#e6e6e6', duration: 0.5 });
      }
      if(oProductPriceTotal)
      {
        oProductPriceTotal.innerHTML = dollarFormat(regular_price + getOptionsPrice());
        if(animate)
          new Effect.Highlight(oProductPriceTotal.parentElement, { startcolor: '#cccc01', endcolor: '#e6e6e6', duration: 0.5 });
      }
      returnValue = true;
    }
    return returnValue;
  }
}

function getCheckedValue(oElement)
{
  var returnValue = null;
  if(oElement)
  {
    if(!oElement.length)
    {
      if(oElement.checked)
        returnValue = oElement.value;
    }
    else
    {
      for(var i = 0; i < oElement.length; i++)
      {
        if(oElement[i].checked)
        {
          returnValue = oElement[i].value;
          break; 
        }
      }
    }
  }
  return returnValue;
}

function isChecked(oElement)
{
  var returnValue = false;
  if(oElement)
  {
    if(!oElement.length)
      if(oElement.checked)
        returnValue = true;
    else
    {
      for(var i = 0; i < oElement.length; i++)
      {
        if(oElement[i].checked)
        {
          returnValue = true;
          break; 
        }
      }
    }
  }
  return returnValue;
}

function getOptionsPrice()
{
  var returnValue = 0;
  for(option in options)
  {
    if(options[option].checked)
      returnValue += options[option].price_added;
  }
  return returnValue;
}

function dollarFormat(valuein)
{ 
  var returnValue = '$0.00';
  valuein = '' + valuein;
//  return '$' + valuein;
  if(valuein)
  {
    var Outdollars = '';
    var decipos = valuein.indexOf('.');
    if (decipos == -1)
      decipos = valuein.length;
    var dollars = valuein.substring(0, decipos);
    var dollen = dollars.length;
    if(dollen > 3)
    {
      while(dollen > 0)
      {
        tDollars = dollars.substring(dollen -3, dollen)
        if(tDollars.length == 3)
        {
          Outdollars = ',' + tDollars + Outdollars;
          dollen = dollen - 3;
        }
        else
        {
          Outdollars = tDollars + Outdollars;
          dollen = 0;
        }
      }
      if(Outdollars.substring(0, 1) == ',')
        dollars = Outdollars.substring(1, Outdollars.length);
      else
        dollars = Outdollars;
    }
    
    var cents = valuein.substring(decipos + 1, decipos + 3);
    if(cents == '')
      cents = '00';
    if (cents.length == 1)
      cents = cents + '0';
  }
  else
  {
    dollars = '0';
    cents = '00';
  }
  returnValue = '$' + dollars + '.' + cents;
  return returnValue;
} 

function newWindow(href, target, width, height)
{
  var returnValue = false;
  var features = (arguments.length == 4) ? 'scrollbars,status,width=' + width + ',height=' + height : ((arguments[5]) ? arguments[5] + ',width=' + width + ',height=' + height : 'width=' + width + ',height=' + height);
  if(window.screen)
  {
    var pxLeft = ((screen.availWidth - width - 10) * .5);
    var pxTop = ((screen.availHeight - height - 30) * .5);
    features += ',left=' + pxLeft + ',top=' + pxTop + ',x=' + pxLeft + ',y=' + pxTop;
  }
  if(!window.open)
    returnValue = true;
  else
  {
    if(self[target + 'Win'] && !self[target + 'Win'].closed)
      self[target + 'Win'].close();
    self[target + 'Win'] = window.open(href, target, features);
    if(self[target + 'Win'].focus)
      self[target + 'Win'].focus();
  }
  return returnValue;
}

function toggleStep(step)
{
  var oHeader = null;
  var oStep = null;
  if(current_step)
  {
    oHeader = $(current_step + '-header');
    if(oHeader)
    {
      if(oHeader.className.indexOf('error') == -1)
      {
        Element.removeClassName(oHeader, 'selected');
        oStep = $(current_step);
        new Effect.BlindUp(oStep);
      }
      else
        oHeader.className = 'step error';
    }
  }
  if(current_step == step)
  {
    current_step = null;
    return;
  }
  oHeader = $(step + '-header');
  if(oHeader)
  {
    Element.addClassName(oHeader, 'selected');
    if(oHeader.className.indexOf('error') == -1)
    {
      oStep = $(step);
      new Effect.BlindDown(oStep);
    }
    current_step = step;
  }
}

var current_description_timer = null;

function toggleDescription(prefix, descriptionID)
{
  if(current_description_timer != null)
  {
    clearTimeout(current_description_timer);
    current_description_timer = null;
  }
  if(!document.getElementById)
    return;
  if(current_description == prefix + '-notes-' + descriptionID)
    return;
  if(current_description)
  {
    oDescription = $(current_description);
    if(oDescription)
      new Effect.BlindUp(oDescription);
  }
  oDescription = document.getElementById(prefix + '-notes-' + descriptionID);
  if(oDescription)
    new Effect.BlindDown(oDescription);
  current_description = prefix + '-notes-' + descriptionID;
  return true;
}

function toggleSynopsis(synopsisID, bDisplay)
{
  oSynopsis = document.getElementById('synopsis_option_' + synopsisID);
  oSynopsisMoreLink = document.getElementById('more_synopsis_link_' + synopsisID);
  oSynopsisMoreLink.style.display = (bDisplay) ? 'none' : '';
  oSynopsis.style.display = (bDisplay) ? 'block' : 'none';
}

function toggleCatalogDetails(oHeader, oElement)
{
  if(oElement.checked)
  {
    Element.addClassName(oHeader, 'required');
    new Effect.BlindDown($('customize-catalog-info'));
  }
  else
  {
    Element.removeClassName(oHeader, 'required');
    new Effect.BlindUp($('customize-catalog-info'));
  }
}