﻿function AddOnload(myfunc) {
  if (window.addEventListener)
    window.addEventListener('load', myfunc, false);
  else if (window.attachEvent)
    window.attachEvent('onload', myfunc);
}
function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return "";
}
function KeyPressSearch(e, form) {
  if (e) {
    var key = (e.which || e.which > -1 ? e.which : (window.event ? window.event.keyCode : 13));
    if (key != 13) return true;
  }
  return form.s.submit();
}
function BindAutoSuggest(id, url) {
  var e = document.getElementById(id);
  if (e) {

    url = "http://" + url + (url.indexOf('local') < 0 ? "/wholesaleresources/ExpressOrder" : "") + "/Catalog/";
    
    e.submit = function() {
      var elem = (this.s || this);
      var form = (this.s ? this : this.form);
      if (elem && elem.value && elem.value.length > 0) {
        window.location = url + 'Search.aspx?s=' + elem.value
        + (form.r && form.r.value != '-1' ? '&r=' + form.r.value : '')
        + (form.g && form.g.value != '-1' ? '&g=' + form.g.value : '')
        + (form.a && form.a.value != '0' ? '&a=' + form.a.value : '')
        ;
      }
      return false;
    }
    var args = [];
    args['elem'] = e;
    args['url'] = url + 'autosuggest.aspx';
    new AutoSuggest(args);
  }
  return e;
}