/*Copyright 2005-2099 FitLink LLC*/

window.is_top=true; if (typeof $ != "undefined") $j = $;
var $ = function (e) { return typeof e == 'string' ? document.getElementById(e) : e; }
function E(e) { return document.createElement(e); }

function show(id,s) {
  var l = $(id);
  if (l) l.style.display = s ? s : 'block';
}

function hide(id) {
  var l = $(id);
  if (l) l.style.display = 'none';
}

function get_value(f) {
  var e = $(f); if (!e) return null;
  if (e.options==undefined && e.length) for (var i=0; i<e.length; i++) { if (e[i].checked) return e[i].value; }
  else if (e.checked==undefined || e.checked || (e.type && e.type.toLowerCase()!='checkbox')) return e.value;
  return null;
}

function has_value(f) {
  return !is_empty(get_value(f));
}

function get_option(f) {
  var e = $(f);
  return e && e.selectedIndex > -1 ? e.options[e.selectedIndex].text : null;
}

function has_option(f) {
  return !is_empty(get_option(f));
}

function set_value(f,v) {
  var e = $(f); if (!e) return v;
  if (e.options==undefined && e.length) for (var i=0; i<e.length; i++) { if (e[i].value=='v') e.checked = true; }
  else if (e.checked==undefined || (e.type && e.type.toLowerCase()!='checkbox')) e.value = v;
  else e.checked = !!v;
  return v;
}

function set_option(f,v) {
  var e = $(f); if (!e) return;
  var o = e.options; var n = o.length;
  for (var i=0; i<n; i++) if (o[i].text==v) {
    o[i].selected = true;
    break;
  }
}

function get_text(e) {
  var e = $(e); if (!e) return '';
  if (e.innerText) return e.innerText;
  if (e.textContent) return e.textContent;
  var t = '';  if (e.childNodes) for (var i=0; i<e.childNodes.length; i++) {
    if (e.childNodes[i].nodeType==Node.TEXT_NODE) t += e.childNodes[i].nodeValue; 
  }
  return t;
}

function set_text(e,t) {
  var e = $(e); if (!e) return;
  if (e.innerText) e.innerText = t;
  else if (e.textContent) e.textContent = t;
  else {
    while (e.firstChild) e.removeChild(e.firstChild);
    e.appendChild(document.createTextNode(t));
  }
}

function set_html(f,t) {
  var f = $(f);
  if (f) f.innerHTML = t;
}

function set_cookie(f,v,e) {
  if (is_empty(v)) { e = new Date(); e.setTime(e.getTime()-100000); }
  var d = e ? 'expires=' + e.toGMTString() + '; ' : '';
  document.cookie = f+"="+v+"; "+d+"path=/";
}

function get_cookie(f) {
  var cs = document.cookie.split(';'); for (var i in cs) { var nv = cs[i].split('=');
    if (string_trim(nv[0])==f) return nv.length>1 ? unescape(string_trim(nv[1])) : null; 
  }
  return null;
}

function copy_value(from,to) {
  set_value(to,get_value(from));
}

function array_find(a, e) {
  for (var i=0; i<a.length; i++) if (a[i]==e) return i;
  return -1;
}

function array_contains(a, e) {
  return array_find(a,e)>=0;
}

function array_implode(a,d,e) {
  var s = '';
  for (var i=0; i<a.length; i++) {
    if (i!=0) s += d;
    if (!is_empty(a[i])) s += e ? string_escape(a[i]) : a[i];
  }
  return s;
}

function array_concat(a,d) {
  var s = '';
  for (var i=0; i<a.length; i++) {
    if (s.length>d.length && s.substring(s.length-d.length)!=d && !is_empty(a[i])) s += d;
    if (!is_empty(a[i])) s += a[i];
  }
  return s;
}

function has_class(e,c) {
  e = $(e); if (!e) return false;
  var p = e.className.split(" "); var l = p.length;
  for (var i=0; i<l; i++) if (p[i]==c) return true;
  return false;
}

function add_class(e,c) {
  e = $(e); if (!e || has_class(e,c)) return;
  e.className = e.className + (is_empty(e.className) ? '' : ' ') + c;
  if (e.tagName.toLowerCase()=='td' && is_gecko()) e.parentNode.parentNode.innerHTML = e.parentNode.parentNode.innerHTML;
}

function remove_class(e,c) {
  e = $(e); if (!e) return;
  var p = e.className.split(" "); var l = p.length;
  for (var i=0; i<l; i++) if (p[i]==c) {
    if (p.splice) p.splice(i,1); else p[i] = null;
    e.className = p.join(" ");
    return;
  }
}

function blank_class(e,c) {
  e = $(e); if (!e) return;
  if (e.value=='') add_class(e,c);
  else remove_class(e,c);
}

function toggle_div(e,c) {
  if (has_class(e,'headerOpen')) {
    remove_class(e,'headerOpen'); add_class(e,'headerClosed'); hide(c);
  } else {
    remove_class(e,'headerClosed'); add_class(e,'headerOpen'); show(c);
  }
}

function smooth_hide(e) {
  new YAHOO.util.Anim(e,{height:{to:0}}).animate();
}

function get_param(p) {
  var params = window.location.search.substring(1).split("&");
  for (var i=0;i<params.length;i++) {
    var pair = params[i].split("=");
    if (pair[0]==p) return decodeURIComponent(pair[1]);
  }
  return null;
} 

function set_param(p,v,t) {
  var params = window.location.search.substring(1).split("&"); var f = false;
  for (var i=0;i<params.length;i++) {
    var pair = params[i].split("=");
    if (pair[0]==p) { if (v) params[i] = p + "=" + encodeURIComponent(v); else params.splice(i,1); f = true; break; }
  }
  if (!f) params[params.length] = p + "=" + encodeURIComponent(v); var s = params.length>0 ? "?" + params.join("&") : "";
  if (t && window.history.replaceState) window.history.replaceState(t,t,window.location.pathname + s);
  else window.location.search = s;
}

function add_param(u,p) {
  return u + (u.indexOf('?')>=0 ? '&' : '?') + p;
}

function do_click(o) {
  o = $(o); var f = o.getAttribute('onclick');
  if (f instanceof Function) f();
  else if (f) eval(f);
  else if (o.click) o.click();
}

function do_submit(f) {
  var url = f.action;
  for (var i=0; i<f.elements.length; i++) {
    var e = f.elements[i];
    if (e.name && has_value(e)) url = add_param(url, e.name + '=' + encodeURIComponent(get_value(e)));
  }
  window.location = url;
  return false;
}

function trigger_event(f, t) {
  if (f.fireEvent) f.fireEvent('on' + t);
  else if (document.createEvent) {
    var e = document.createEvent('HTMLEvents');
    e.initEvent(t, true, true);
    f.dispatchEvent(e);
  }
}

function trigger_key(f, t, k) {
  if (f.fireEvent) {
    e = document.createEventObject();
    e.keyCode=k;
    f.fireEvent('on' + t, e);
  } else {
    var e = document.createEvent('KeyEvents');
    e.initKeyEvent(t, true, true, window, false, false, false, false, k, k);
    f.dispatchEvent(e);
  }
}

function check_enter(event,handler) {
  if (event.keyCode==13) {
    handler();
    return false;
  }
  return true;
}

function is_gecko() {
  var a = window.navigator.userAgent.toLowerCase();
  return a.indexOf('gecko')>=0 && a.indexOf('safari')<0;
}

function is_opera() {
  return window.opera != null;
}

function is_empty(v) {
  return !v || v=='';
}

function is_integer(event) {
  var key = event.keyCode ? event.keyCode : event.which;
  return is_digit(key) || is_control(key) || (is_nav(key) && !event.shiftKey);
}

function is_decimal(field, event) {
  var key;
  if (event.keyCode) key = event.keyCode;
  else key = event.which;
  return is_digit(key) || is_control(key) || (is_nav(key) && !event.shiftKey);
}

function is_digit(key) {
  return key > 47 && key < 58;
}

function is_control(key) {
  return key == 8 || key == 9 || key == 10 || key == 13 || key == 46 || key == 127;
}

function is_nav(key) {
  return key > 34 && key < 41;
}

function limit_area(f, limit) {
  var c = f.value.length - limit; if (c<=0) return;
  if (document.selection) { // ie
    var sel = document.selection.createRange();
    sel.moveStart('character', -c);
    sel.text = '';
  } else if (f.selectionStart || f.selectionStart=='0') { // gecko
    var s = Number(f.selectionStart);
    f.value = f.value.substring(0,s-c) + f.value.substring(s);
  } else {
    f.value = f.value.substring(0, limit);
  }
}

function set_days(month, day) {
  if (month==0) return;
  var daysInMonth = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[month-1];
  var selectedDay = day.selectedIndex == null ? 1 : day.selectedIndex;
  var oldDays = day.options.length;
  day.options.length = daysInMonth + 1;
  for (var i=oldDays; i <= daysInMonth; i++) day.options[i] = new Option(i,i);
  day.selectedIndex = Math.min( selectedDay, daysInMonth );
}

function tool_bar(f) {
  var e = document.createElement('p');
  e.innerHTML = tag_link(f,'heading') + tag_link(f,'subheading') + tag_link(f,'paragraph') + tag_link(f,'list') + tag_link(f,'item') +
                tag_link(f,'quote') + tag_link(f,'bold') + tag_link(f,'italics') + tag_link(f,'link') + tag_link(f,'user');
  f = $(f);
  f.parentNode.insertBefore(e,f);
}
function tag_link(f,t) {
  return "<a class='toolbar " + t + "' href='javascript:;' onclick=\"insert_tag('" + f + "','" + t + "');\"  title='" + t.substring(0,1).toUpperCase() + t.substring(1) + "'>&nbsp;</a>";
}

function insert_tag(f, tag) {
  f = $(f);
  var st = '[' + tag;
  if (tag=='link' || tag=='user') {
    var p = tag=='link' ? prompt('Enter the URL:','http://') : prompt('Enter the username:','');
    if (p==null || p==false) return;
    st = st + '=' + p;
  }
  st = st + ']';
  var et = '[/' + tag + ']';
  if (document.selection) { // ie
    f.focus();
    var sel = document.selection.createRange();
    sel.text = st + sel.text + et;
    sel.moveEnd('character', -et.length);
    sel.select();
    f.focus();
  } else if (f.selectionStart || f.selectionStart=='0') { // gecko
    var s = Number(f.selectionStart); var e = Number(f.selectionEnd); var c = e; var t = f.scrollTop;
    f.value = f.value.substring(0,s) + st + f.value.substring(s,e) + et + f.value.substring(e);
    c = e + st.length;
    f.focus();
    f.selectionStart = f.selectionEnd = c;
    f.scrollTop = t;
  } else {
    f.value += st + et;
    f.focus();
  }
  trigger_key(f,'keyup',55);
}

function go_nav() {
  $('nav').click(); return false;
}

function stay(n,i) {
  var e = document.createElement('input');
  e.setAttribute('type','submit');
  e.setAttribute('name',n);
  e.setAttribute('value',n);
  e.className='hidden';
  document.main_form.appendChild(e);
  e.click();
}

function flag(v) {
  document.cookie = 'flag=' + (v ? v : 1);
}

function set_rating(v) {
  v = v || parseFloat(get_value('rating')); var lis = $('ratingStars').getElementsByTagName('li');
  for (var i=0; i<5; i++) lis.item(i).className = v>=(i+0.75) ? 'on' : (v>=(i+0.25) ? 'half' : 'off');
}

function set_votes(d) {
  var v = get_value('votes'); var t = v+" vote"+(v==1?'':'s');
  setTimeout("set_html('ratingText','("+t+")')",d);
}

function rate(o,id,r) {
  set_html('ratingText','Thanks for rating!'); show('ratingDetail');
  ajax_call('/parts/rate?object='+o+'&id='+id+'&rating='+r,function(v) {
    v = unserialize(v); if (!v) return; set_value('rating',v[0]); set_value('votes',v[1]); set_rating(); set_votes(2000);
  });
}

function toggle_stars(id,v) {
  set_value(id,v);
  for (var i=1; i<=5; i++) $(id+'_'+i).className = v>=(i-0.25) ? 'on' : (v>=(i-0.75) ? 'half' : 'off');
}

function pop_up(n,l,w,h) {
  l = l + (l.indexOf('?')>0 ? '&' : '?') + 'popup=1';
  eval("window." + n + "=window.open('" + l + "','" + n + "','location=0,status=0,resizable=1,scrollbars=1,width=" + w + ",height=" + h + "')");
  eval("window." + n + ".focus()");
}

function feed_back() {
  pop_up('feedback','/feedback?referrer=' + encodeURIComponent(window.location.pathname + window.location.search),800,475);
}

function unpop(p) {
  if (p) p.destroy();
  return null;
}

function process(r,f) {
  var s = /<script(.|\s)*?\/script>/img; var scripts = [];
  r = r.replace(s,function(v) { scripts.push(v.replace(/<\/?script(.|\s)*?>/img,'')); return ''; });
  f(r);
  for (var is=0; is<scripts.length; is++) { eval(scripts[is]); }
}

function render(p,r) {
  process(r,function(t) {
    p.setBody(t);
    p.render(document.body);
    p.center();
    p.show();
  });
}

function loading() {
  if (window.loading_panel) done_loading();
  page_clear();
  var p = new YAHOO.widget.Panel('wait',{modal:true,close:false,fixedcenter:true,draggable:false,visible:false,zIndex:100});
  p.setBody("<div id='loading'/>");
  p.render(document.body);
  p.show();
  window.loading_panel = p;
  if (!window.onunload) window.onunload = handleUnload;
}

function done_loading() {
  window.loading_panel = unpop(window.loading_panel);
}

function done_floating() {
  window.floater = unpop(window.floater);
}

var onOpen = function(o) {
  done_loading();
  render(window.floater,o.responseText);
}
var onSuccess = function(o) {
  done_loading();
  var r = o.responseText;
  if (r.substring(0,7)=="SUCCESS") {
    process(r.substring(7), function(t) {
      if (typeof o.argument=="function") o.argument(t);
      else { set_html(o.argument,t); done_floating(); }
    });
  } else render(window.floater,r);
}
var onFailure = function(o) {
  done_loading();
  done_floating();
  page_warning("There was an error processing your request.  Please try again");
}

var handleSubmit = function() { this.submit(); };
var handleCancel = function() { this.cancel(); };
var handleHide = function(k,v) { if (v[0][0]=='visible' && !v[0][1]) done_floating(); };
var handleUnload = function() { done_loading(); done_floating(); window.onunload = null; };

function dialog(u,t,e) {
  if (window.floater) { setTimeout(function(){dialog(u,t,e);},10); return; }
  loading();
  var p = new YAHOO.widget.Dialog('floater',{width:'600px',height:'525px',modal:true,close:true,draggable:false,visible:false,
    buttons:e?[{text:"Save",handler:handleSubmit,isDefault:true},{text:"Cancel",handler:handleCancel}]:[],hideaftersubmit:false,zIndex:5});
  p.beforeSubmitEvent.subscribe(loading);
  p.cfg.configChangedEvent.subscribe(handleHide);
  p.callback = {success:onSuccess,failure:onFailure,upload:onSuccess,argument:e};
  p.setHeader(t);
  window.floater = p;
  YAHOO.util.Connect.asyncRequest('GET',u,{success:onOpen,failure:onFailure});
}

function load_states() {
  var c = parseInt(get_value('country'));
  if (c==1 || c==17) ajax_call("/parts/states?country="+c,handle_states);
  else { hide('code_li'); show('state_li'); set_value('state',''); set_value('state_code',''); }
}

function handle_states(d) {
  var d = string_trim(d).split("\n"); var so = $('state_code').options; so.length = d.length + 1; so[0] = new Option("","");
  for (var i=0;i<d.length;i++) { var p = d[i].indexOf('|'); so[i+1] = new Option(d[i].substring(p+1),d[i].substring(0,p)); }
  show('code_li'); hide('state_li'); set_value('state','');
}

function ajax_init() {
  if (window.XMLHttpRequest) { return new XMLHttpRequest(); }
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) {}
  return null;
}

function ajax_call(uri, target) {
  var x = ajax_init();
  if (!x) return true;
  x.open("GET", uri, true);
  x.onreadystatechange = function() { ajax_response(x,target); }
  x.send('');
}

function ajax_post(uri, params, target) {
  var x = ajax_init();
  if (!x) return true;
  show('loading');
  x.open("POST", uri, true);
  x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  x.setRequestHeader("Content-length", params.length);
  x.setRequestHeader("Connection", "close");
  x.onreadystatechange = function() {
    ajax_response(x,target);
    hide('loading');
  }
  x.send(params);
}

function ajax_response(r,target) {
  if (r.readyState!=4) return;
  var d = r.responseText;
  process(d,function(t) {
    if (typeof target=="function") target(d);
    else set_html(target,t);
  });
  delete r;
}

function unserialize(s) {
  s = string_trim(s);
  if (is_empty(s)) return null;
  return un_serialize(s)[0];
}

function un_serialize(s) {
  switch (s.charAt(0)) {
    case 'N':
      return [null, s.substr(2)];
    case 's':
      var l = s.substring(2, s.indexOf(':',2));
      var n = Number(l), p = 0, j = l.length+4;
      while (p<n) {
        var c = s.charCodeAt(j++);
        p += c < 128 ? 1 : (c < 2048 ? 2 : (c < 65536 ? 3 : 4));
      }
      return [s.substring(l.length + 4, j), s.substr(j + 2)];
    case 'i':
    case 'd':
      var n = s.substring(2, s.indexOf(';',2));
      return [Number(n), s.substr(n.length + 3)];
    case 'b':
      var b = s.substr(2, 1) == 1;
      return [b, s.substr(4)];
    case 'a':
      var l = s.substring(2, s.indexOf(':',2));
      s = s.substr(l.length + 4);
      l = Number(l);
      var a = new Array();
      for (var i=0; i<l; i++) {
        var k = un_serialize(s);
        var v = un_serialize(k[1]);
        s = v[1];
        a[k[0]] = v[0];
      }
      return [a, s.substr(1)];
    case 'O':
      var l = s.substring(2, s.indexOf(':',2));
      var c = s.substr(l.length + 4,Number(l));
      s = s.substr(l.length + 6 + Number(l));
      var n = s.substr(0, s.indexOf(':'));
      s = s.substr(n.length + 2);
      n = Number(n);
      var o = new Object();
      for (var i=0; i<n; i++) {
        var property = null;
        var value    = null;
        var k = un_serialize(s);
        var v = un_serialize(k[1]);
        // strip access mods
        key[0] = key[0].replace(new RegExp('^\x00' + c + '\x00'), '').replace(new RegExp('^\x00\\*\x00'), '');
        s = v[1];
        o[k[0]] = v[0];
      }
      return [a, s.substr(1)];
    default:
      return [null, null];
  }
}

function page_info(m) {
  var e = ($('messages_part')) ? 'messages_part' : 'messages';
  set_html(e,m+'.');
  remove_class(e,'error');
  add_class(e,'info');
  show(e);
  scrollTo(0,0);
}

function page_warning(m) {
  var e = ($('messages_part')) ? 'messages_part' : 'messages';
  set_html(e,m+'.');
  remove_class(e,'info');
  add_class(e,'error');
  show(e);
  scrollTo(0,0);
}

function page_clear() {
  var e = ($('messages_part')) ? 'messages_part' : 'messages';
  hide(e);
}

function string_trim(s,c) {
  c = c ? c.replace(/\s/,"\\s") : "\\s";
  return s ? s.replace(new RegExp("^["+c+"]+|["+c+"]+$","g"),'') : s;
}

function string_append(s,n,d) {
  d = is_empty(d) ? ', ' : d; s = is_empty(s) ? '' : s;
  if (!is_empty(s) && !is_empty(n)) s += d;
  if (!is_empty(n)) s += n;
  return s;
}

function string_pad_left(s,c,n) {
  s = String(s);
  while (s.length<n) s = c + s;
  return s;
}

function string_pad_right(s,c,n) {
  s = String(s);
  while (s.length<n) s = s + c;
  return s;
}

function string_escape(s) {
  if (!s) return null;
  var re = /['"&\\]/g;
  return String(s).replace(re,"\\$&");
}
