var ShSettings={
  "shvDB":"sakworldpaintball",
  "storeURL":"www.sakworldpaintball.com",
  "yahooID":"sakworldpaintballsupply-store",
  "cartURL":"http://order.store.yahoo.net/cgi-bin/wg-order?sakworldpaintballsupply-store",
  "ywa_tid":"10001972058177",
  "allowSpellCorr":true,
  "allowFilters":true,
  "autoShowFilters":true,
  "permFilter":null,
  "filtCount":5,
  "sortBy":[['Popular',-1],['Price',0,1],['Rating',3],['Newest',2],['Alphabetical',11]],
  "pricelbl":"",
  "bottomElt":null,
  "callback":"",
  "maxThumbHeight":120,
  "lbItemHeight":220,
  "lbItemWidth":200,
  "lbItemPadding":15,
  "lbRowCount":6 };
document.write('<link rel="stylesheet" href="http://shoptivate.com/shared/shoptivate-d3.css" />');
document.write('<link rel="stylesheet" href="http://sakworldpaintball.shoptivate.com/override.css" />');
document.write('<div id="shvshade"></div>');
document.write('<div id="shscont" style="display:none"><input id="shstate" style="display:none"/></div>');
document.write('<div id="shcontent">');
document.write('<script src="http://shoptivate.com/shared/shv-d-code11.js" ></script>');
function shvCkCart() {
  if (window.eyGetCookie && window.shopt && shopt.cartUpdate) {
    var c=eyGetCookie("count");
    var st=eyGetCookie("subtotal");
    if (c && st) shopt.cartUpdate(st, c);
  }
  setTimeout(shvCkCart, 1000);
}
setTimeout(shvCkCart, 1000);
function shvFindItFast() {
  var e=document.getElementById('productDD');
  var pval=e ? e.value : '';
  if (pval.substring(0,2)=='--') pval='';

  e=document.getElementById('manufacturerDD');
  var mval=e ? e.value : '';
  if (mval.substring(0,2)=='--') mval='';

  e=document.getElementById('priceDD');
  var prval=e ? e.value : '';

  if (mval || prval) {
    var rsuffix = '';
    var rfilters = [];

    if (mval) {
      var code = 't1='+mval.replace(/'/, '').replace(/[^A-Za-z0-9]+/, ' ');
      rsuffix += '&'+code;
      rfilters.push([mval, code]);
    }
    if (prval.match(/^(\d+)-(\d+)$/)) {
      var lowdollar = (RegExp.$1)-0;
      var highdollar = (RegExp.$2)-0;
      if (highdollar==100000) {
        var code='a0='+lowdollar+'00';
        rsuffix += '&'+code;
        rfilters.push(['$'+lowdollar+'.00 and up', code]);
      } else {
        var code='a0='+lowdollar+'00&b0='+highdollar+'99';
        rsuffix += '&'+code;
        rfilters.push(['$'+lowdollar+'.00-$'+highdollar+'.99', code]);
      }
    }

    searchFor(pval, null, [rsuffix, rfilters]);
  } else {
    searchFor(pval);
  }
}

var shvcatmap={'gun':[6, 'Gun'], 'hopper':[8, 'Hopper'], 'tank':[7, 'Tank'], 'regulator':[10, 'Goggles'],
    'barrel':[4, 'Barrel'], 'macrolinehose':[12, 'Harness/Vest'], 'clampfeed':[5, 'Pods'], 'grips':[9, 'Grips']};

function shvGunFix(prodhtml) {
  return prodhtml.replace(/http:\/\/shoptivate.com\/sakworldpaintball\/cart.gif/,
    'http://lib.store.yahoo.net/lib/sakworldpaintballsupply-store/ey-addtoGunBuilder.jpg');
};
ShSettings.onSchClose = function() {
  ShSettings.processProdDetail = null;
  window.cart_handler = null;
};
function shvGunSubmit(f) {
  var opts=f.getElementsByTagName('select');
  if (opts.length) {
    var otxt='';
    for (var i=0; i<opts.length; ++i) otxt+=opts[i].name+'='+opts[i].value+'|';
    var e=document.getElementById('shvGboptions');
    if (e) {
      e.name='options';
      e.value=otxt;
    }
  }
  var e=document.getElementById('shvGbForm');
  if (e) {
    e.submit();
  }
}

function shvParsePrice(x, label) {
  if (!x.match(/^ *\$? *([\d,]*(\.\d\d)?) *$/)) {
    alert("Please enter "+label+" in standard format: 9.99");
    return null;
  }
  var n = RegExp.$1.replace(/,/, '')-0;
  return [n.toFixed(2), (n*100).toFixed()];
}
function shvGunBuild() {
  var e=document.getElementById("gbCat");
  var cval=e ? e.value : '';
  if (!cval || cval.substring(0,2)=='--') {
    alert("Please select a category.");
    return;
  }

  e=document.getElementById("gbMin");
  var pmin=e ? e.value : '';

  e=document.getElementById("gbMax");
  var pmax=e ? e.value : '';

  e=document.getElementById("gbSch");
  var sval=e ? e.value : '';

  var rsuffix = '';
  var rfilters = [];

  if ((pmin && (pmin = shvParsePrice(pmin, 'minimum price'))===null) ||
      (pmax && (pmax = shvParsePrice(pmax, 'maximum price'))===null)) {
    return;
  }
  if (pmin && pmax) {
    code = 'a0='+pmin[1]+'&b0='+pmax[1];
    rsuffix += '&'+code;
    rfilters.push(['$'+pmin[0]+'-$'+pmax[0], code]);
  } else if (pmin) {
    code = 'a0='+pmin[1];
    rsuffix += '&'+code;
    rfilters.push(['$'+pmin[0]+' and up', code]);
  } else if (pmax) {
    code = 'b0='+pmax[1];
    rsuffix += '&'+code;
    rfilters.push(['$'+pmax[0]+' or less', code]);
  }

  if (shvcatmap[cval]) {
    code = 't'+shvcatmap[cval][0]+'=y';
    rsuffix += '&'+code;
    rfilters.push([shvcatmap[cval][1], code, 1]);
  }

  ShSettings.processProdDetail = shvGunFix;
  window.cart_handler = {process_form:shvGunSubmit};
  searchFor(sval, null, [rsuffix, rfilters]);
}
function shvFixButtons() {
  function launchGBsch(cval) {
    if (shvcatmap[cval]) {
      var cnum = shvcatmap[cval][0], cttl = shvcatmap[cval][1];

      ShSettings.processProdDetail = shvGunFix;
      window.cart_handler = {process_form:shvGunSubmit};
      searchFor('', null, ['&t'+cnum+'=y', [[cttl, 't'+cnum+'=y', 1]]]);
      return false;
    }
  }

  function fixButton(id, cval) {
     var e=document.getElementById(id);
     if (e) {
       var aelts=e.getElementsByTagName('a');
       for (var i=0; i<aelts.length; ++i) {
         if (aelts[i].href.indexOf("&category=")!=-1)
           aelts[i].onclick=function() {return launchGBsch(cval);};
       }
     }
  }

  var e=document.getElementById('LeftColumn');
  if (e) {
    fixButton('currentGunButton', 'gun');
    fixButton('currentHopperButton', 'hopper');
    fixButton('currentTankButton', 'tank');
    fixButton('currentRegulatorButton', 'regulator');
    fixButton('currentBarrelButton', 'barrel');
    fixButton('currentMacrolinehoseButton', 'macrolinehose');
    fixButton('currentClampfeedButton', 'clampfeed');
    fixButton('currentGripsButton', 'grips');
  } else {
    setTimeout(shvFixButtons, 500);
  }
}
setTimeout(shvFixButtons, 500);
