function rf(arg1, arg2){
  var xmlhttp = false;
  if (window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }else if(window.ActiveXObject){
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open('GET', arg1, true);
  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4){
      parent.document.getElementById(arg2).innerHTML = xmlhttp.responseText;
      if(document.getElementById('dealerSearchResults')){
        scrollDiv=document.getElementById('dealerSearchResults');
        if(scrollDiv.scrollUpdate) scrollDiv.scrollUpdate();
      }
    }
  }
  xmlhttp.send(null);
}

function homeRoll(arg){
  var bantopload=document.getElementById('bantopload');
  bantopload.style.background="url(/assets/homepage/banner/"+arg+") no-repeat";
  bantopload.style.display='block';
}
function homeRollO(){
  var bantopload=document.getElementById('bantopload');
  bantopload.style.background='';bantopload.style.display='none';
}

//DISCIPLINE + BANLOAD PRELOAD AND ROLLOVER
if(document.images){
  pic1= new Image(30,30);pic2= new Image(30,30);pic3= new Image(30,30);pic4= new Image(30,30);pic5=new Image(126,22);
  pic1.src="/i/dxco.jpg";pic2.src="/i/damo.jpg";pic3.src="/i/ddho.jpg";pic4.src="/i/dro.jpg";pic5.src="/i/load.gif";
}
function disc(inout,elem){
  if(inout == 'on'){
    elem.className='disco';document.getElementById(elem.id+'i').src="/i/"+elem.id+"o.jpg";
    //elem.style.width='30px';elem.style.height='30px';elem.style.margin='0 2px';
  }else if(inout == 'out'){
    elem.className='disc';document.getElementById(elem.id+'i').src="/i/"+elem.id+".jpg";
    //elem.style.width='24px';elem.style.height='24px';elem.style.margin='0 5px';
  }
}

//SEARCH
function isSearch(arg){
  if(document.getElementById(arg).value=='search >>')document.getElementById(arg).value='';
}
function checkEnter(e){
  var keynum;var keychar;
  if(window.event){ // IE
    keynum = e.keyCode
  }else if(e.which){ // Netscape/Firefox/Opera
    keynum = e.which
  }
  if(keynum==13){
    var q=trim(document.getElementById('search').value);
    if(q != '') document.location.href="/search/"+q.replace(' ','-')+"/";
  }
}
function advanceSearch(e){
  var filt;
  if(document.getElementById('compfilt').checked)filt='components';
  if(document.getElementById('appfilt').checked){if(filt)filt+='-apparel';else filt='apparel';}
  if(document.getElementById('contfilt').checked){if(filt)filt+='-content';else filt='content';}
  if(filt && filt != 'undefined')filt='filter_'+filt+'/';else filt='';
  var q=trim(document.getElementById('searchfld').value);
  if(q != ''){
    if(e){if(window.event)keynum=e.keyCode;else if(e.which)keynum=e.which;if(keynum==13){document.location.href="/search/"+document.getElementById('searchfld').value.replace(' ','-')+"/"+filt;}}
    else{document.location.href="/search/"+document.getElementById('searchfld').value.replace(' ','-')+"/"+filt;}
  }
}
function trim(s){
  if((s==null)||(typeof(s)!='string')||!s.length)return'';
  return s.replace(/^\s+/,'').replace(/\s+$/,'')
}

//LINKS AND NAVIGATION
function go(thelink,dir){
  var curx = getX(); var cury = getY();
  if(curx == 0 && cury == 0){
    if((document.getElementById('bnr').style.height == '0px' && dir == 'u') || (document.getElementById('bnr').style.height == '260px' && dir == 'd')){
      document.location.href=thelink;
    }else{rollNav(thelink,dir);}
  }else{scrollWin(thelink,dir);}
}
function getX(){
  var scrOfX = 0;
  if(typeof(window.pageXOffset) == 'number') scrOfX = window.pageXOffset;
  else if(document.body && document.body.scrollLeft) scrOfX = document.body.scrollLeft;
  else if(document.documentElement && document.documentElement.scrollLeft) scrOfX = document.documentElement.scrollLeft;
  return scrOfX;
}
function getY(){
  var scrOfY = 0;
  if(typeof(window.pageYOffset) == 'number') scrOfY = window.pageYOffset;
  else if(document.body && document.body.scrollTop) scrOfY = document.body.scrollTop;
  else if(document.documentElement && document.documentElement.scrollTop) scrOfY = document.documentElement.scrollTop;
  return scrOfY;
}
function scrollWin(thelink,dir){
  var cury = getY(); var newy = Math.round(cury/1.3);
  var curx = getX(); var newx = Math.round(curx/1.3);
  if(newy < 3) newy = 0; if(newx < 3) newx = 0;
  window.scroll(newx,newy);
  if(newy != 0 || newx != 0) setTimeout("scrollWin('"+thelink+"','"+dir+"')",1);
  else go(thelink,dir);
}
var bopac;
function bodOpac(thelink,dir){
  if(!bopac) bopac=1;
  var bod=document.getElementById('bod').style;
  bopac=bopac/1.3;
  if(bopac < 0.1)bopac='0';
  bod.MozOpacity=bopac;bod.opacity=bopac;document.getElementById('bod').style.filter='alpha(opacity='+Math.round(bopac*100)+')';
  if(bopac > 0) setTimeout("bodOpac('"+thelink+"','"+dir+"')",1);
  else go(thelink,dir);
}
function rollNav(thelink,dir){
  var bnr = document.getElementById('bnr').style;
  if(bnr.height){
    var bnrheight = parseInt(bnr.height);
    if(dir == 'u'){
      newbnrheight = Math.round(bnrheight/1.3);
      if(newbnrheight < 3) newbnrheight = 0;
      bnr.height=newbnrheight+'px';
      if(newbnrheight != 0){ setTimeout("rollNav('"+thelink+"','"+dir+"')",1); }
      else{
        bnr.borderBottom='0px';
        go(thelink,dir);
      }
    }else{
      bnr.borderBottom='2px solid #6f6e70';
      newbnrheight = 260 - Math.round((260-bnrheight)/1.3);
      if(newbnrheight > 257) newbnrheight = 260;
      if(newbnrheight < 2) newbnrheight = 2;
      bnr.height=newbnrheight+'px';
      if(newbnrheight != 260) setTimeout("rollNav('"+thelink+"','"+dir+"')",1);
      else go(thelink,dir);
    }
  }else{
    bnr.height= (dir == 'u' ? '260px' : '0px');
    setTimeout("rollNav('"+thelink+"','"+dir+"')",1);
  }
}

function showSub(navlink,dir){
  clearTimeout(hsub);
  if(!dir) dir = 'd';
  if(document.getElementById('subnav').style.height != '20px'){
    rollSub(navlink);
    return;
  }
  var x = document.getElementsByTagName('div');
  for(var i=0;i<x.length;i++){
    if(x[i].className == 'subnav') x[i].style.display='none';
  }
  document.getElementById(navlink+'-sub').style.display='block';
}
var hsub;
function hideSub(){
  hsub = setTimeout("rollSub()",1000);
}
function rollSub(thelink){
  var subheight = document.getElementById('subnav').style.height;
  var theheight = subheight.split('px'); theheight = parseInt(theheight[0]);
  if(thelink){
    if(theheight < 20){
      document.getElementById('subnav').style.height = (theheight+2)+'px';
      setTimeout("rollSub('"+thelink+"')",10);
    }else{
      showSub(thelink);
    }
  }else{
    var x = document.getElementsByTagName('div');
    for(var i=0;i<x.length;i++){
      if(x[i].className == 'subnav') x[i].style.display='none';
    }
    if(theheight > 0){
      document.getElementById('subnav').style.height = (theheight-2)+'px';
      setTimeout("rollSub()",10);
    }
  }
}

//PRODUCTS
var gtime=new Array();
var stime=new Array();
var pwidth=new Array();

function grow(compid,ext,elem){
  prodthumb=document.getElementById('thumb'+elem);
  if(!pwidth[elem]){pwidth[elem]=prodthumb.style.width;pwidth[elem]=pwidth[elem].split('px');pwidth[elem]=parseFloat(pwidth[elem][0]);}
  if(pwidth[elem] < 129){
    clearTimeout(stime[elem]);
    pwidth[elem]+=5;prodthumb.style.width=pwidth[elem]+'px';    gtime[elem] = setTimeout("grow('"+compid+"','"+ext+"','"+elem+"')",10);
  }else{
    prodthumb.src='/'+lyt+'/'+compid+'/botthumb.'+ext;  }
}
function shrink(compid,ext,elem){
  if(!ext)ext='png';
  prodthumb=document.getElementById('thumb'+elem);
  if(!pwidth[elem]){pwidth[elem]=parseInt(prodthumb.style.width);}
  if(pwidth[elem]>111){
    clearTimeout(gtime[elem]);
    pwidth[elem]-=5;prodthumb.style.width=pwidth[elem]+'px';    stime[elem] = setTimeout("shrink('"+compid+"','"+ext+"','"+elem+"')",10);
  }else{
    prodthumb.src='/'+lyt+'/'+compid+'/thumb.'+ext;  }
}
function prodPrev(prodid){
  document.getElementById('bnr').style.background="url(/i/load.gif) center center no-repeat";
  document.getElementById('bnr').innerHTML="<img src='/"+lyt+"/"+prodid+"/rollban.jpg' alt='' />";
}
/*var scr;
var prodScroll = {
  init: function(){
    if(document.getElementById('prodScroll')){
      //find the container and bod widths //find how much overhang //define curX at 0
      prodScroll.contW = document.getElementById('prodScroll').offsetWidth;
      prodScroll.bodW = document.getElementById('prodScrollBod').offsetWidth;
      prodScroll.diff = prodScroll.contW-prodScroll.bodW;
      prodScroll.curX = 0;
      if(prodScroll.curX == 0) document.getElementById('lscroll').style.visibility='hidden';
      if(prodScroll.diff >= 0) document.getElementById('rscroll').style.visibility='hidden';
    }
  },
  r: function(inc){
    if(prodScroll.contW < prodScroll.bodW){
      if(!inc) inc=1;
      if(prodScroll.curX > prodScroll.diff+inc){ prodScroll.curX -= inc;document.getElementById('lscroll').style.visibility='visible';}
      else{ prodScroll.curX = prodScroll.diff; document.getElementById('rscroll').style.visibility='hidden';}
      document.getElementById('prodScrollBod').style.left=prodScroll.curX+'px';
      if(inc < 5) inc++;
      if(prodScroll.curX > prodScroll.diff) scr = setTimeout("prodScroll.r("+inc+")",100/inc);
    }
  },
  l: function(inc){
    if(prodScroll.contW < prodScroll.bodW){
      if(!inc) inc=1;
      if(prodScroll.curX < -inc){ prodScroll.curX += inc;document.getElementById('rscroll').style.visibility='visible';}
      else{ prodScroll.curX = 0;document.getElementById('lscroll').style.visibility='hidden';}
      document.getElementById('prodScrollBod').style.left=prodScroll.curX+'px';
      if(inc < 5) inc++;
      if(prodScroll.curX < 0) scr = setTimeout("prodScroll.l("+inc+")",20);
    }
  }
}*/
function scRoll(elem,lr,io){
  if(io==1){
    elem.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/"+lr+"arro.png', sizingMethod='scale')";
  }else{
    elem.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/"+lr+"arr.png', sizingMethod='scale')";
  }
}
//onload=prodScroll.init;

//SITEMAP
function pinfo(pc,id,level,it){
  if(id) branch(id,level,it);
  rf('/p/installation-instructions.inc.php?id='+pc,'pbox');
}
function preview(pc,id,level,it){
  if(id) branch(id,level,it);
  rf('/p/reviews.inc.php?id='+pc,'pbox');
}
//product hilite
function phl(id){
  if(document.getElementById('p'+id)) document.getElementById('p'+id).style.border='2px solid #b20404';
  if(document.getElementById('t'+id)) document.getElementById('t'+id).style.textDecoration='underline';
}
function pul(id){
  if(document.getElementById('p'+id)) document.getElementById('p'+id).style.border='2px solid #000';
  if(document.getElementById('t'+id)) document.getElementById('t'+id).style.textDecoration='none';
}
function branch(id,level,it){
  if(!level) level='';
  var theBranch = document.getElementById(id+'-subs');
  if(theBranch.className=='smapsub'+level){
    var aElm=document.body.getElementsByTagName('div');
    for(var i=0; i<aElm.length; i++){
      if(aElm[i].className=='smapsubs'+level){
        aElm[i].className='smapsub'+level;
        pid=aElm[i].id.split('-');
        document.getElementById(pid[0]+'-pm').innerHTML="<img src='/i/+.gif' alt='+' title='Expand' />";
      }
    }
    theBranch.className='smapsubs'+level;
    document.getElementById(id+'-pm').innerHTML="<img src='/i/-.gif' alt='-' title='Close' />";
  }else{
    if(it!='t'){
      theBranch.className='smapsub'+level;
      document.getElementById(id+'-pm').innerHTML="<img src='/i/+.gif' alt='+' title='Expand' />";
    }
  }
}

function review(id){
  rev = window.open('/p/installation-instructions.inc.php?rev='+id,'revwin','left=20,top=20,width=640,height=500,toolbar=0,resizable=0');rev.focus()
}


//RIDERS
function rhl(id){
  if(document.getElementById('rimg'+id))document.getElementById('rimg'+id).style.border='3px solid #b20404';
  if(document.getElementById('rname'+id))document.getElementById('rname'+id).style.color='#b20404';
}
function rul(id){
  if(document.getElementById('rimg'+id))document.getElementById('rimg'+id).style.border='3px solid #000';
  if(document.getElementById('rname'+id)){
    rname=document.getElementById('rname'+id);
    if(rname.className=='rnameO')rname.style.color='#333';
    else rname.style.color='#666';
  }
}
function riderProfile(id){
  prof = window.open('/assets/rider-profiles/'+id+'/main.html','profwin','left=20,top=20,width=770,height=650,toolbar=0,resizable=0');prof.focus();
}
function hideProfile(){
  document.getElementById('riderProfile').style.display='none';
  document.getElementById('riderProfile').innerHTML="";
}

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

//DEALER
function dealerSearchType(arg){
  document.getElementById('dealerSearchType').innerHTML="<div style='text-align:center;'><img src='/i/load-222.gif' /></div>";
  rf('/p/dealer-search.inc.php?type='+arg,'dealerSearchType');
  document.getElementById('dealerSearchResults').innerHTML='';
}
function dealerFilter(arg,arg2,arg3){
  document.getElementById('dealerSearchResults').innerHTML='';
  document.getElementById(arg3).innerHTML="<div style='text-align:center;'><img src='/i/load-222.gif' /></div>";
  rf('/p/dealer-search.inc.php?type='+arg+'&filter='+arg2,arg3);
}
function dealerReFilter(arg,arg2,arg3){
  document.getElementById('dealerSearchResults').innerHTML="<div style='text-align:center;'><img src='/i/load-222.gif' /></div>";
  rf('/p/dealer-search.inc.php?type='+arg+'&filter='+arg2+'&refilter='+arg3,'dealerSearchResults');
}
function distributorSearch(arg,arg1){
  var myclass = new RegExp('\\b'+'intcountries'+'\\b');
  var elem = document.getElementsByTagName('*');
  for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) elem[i].style.color='#b20404';
  }
/*  var intcountries = document.getElementsByClassName('intcountries');
  for(x in intcountries){
    intcountries[x].style.color='#b20404';
    if(x == (intcountries.length-2)) break;
  }*/
  document.getElementById('country'+arg1).style.color='#fff';
  document.getElementById('dealerSearchResults').innerHTML="<div style='text-align:center;'><img src='/i/load-222.gif' /></div>";
  rf('/p/international-distributors.inc.php?filter='+arg,'dealerSearchResults');
}

//NEWS
function newsOpen(newsID){
  theNews=document.getElementById('news'+newsID);
  if(theNews.style.display=='block'){
    theNews.style.display='none';
    document.getElementById('arr'+newsID).src='/i/rarrow.gif';
  }else{
    theNews.style.display='block';
    document.getElementById('arr'+newsID).src='/i/darrow.gif';
  }
}

//COMD
function episodePrev(episode){
  var epPrev=document.getElementById('epPrev');
  if(epPrev.style.display=='block'){
    epPrev.style.display='none';
    epPrev.style.background='none';
  }else{
    epPrev.style.background='url(/assets/crap-on-my-desk/Episode'+episode+'/episode'+episode+'.jpg) center center no-repeat';
    epPrev.style.display='block';
  }
}
function episodeShow(episode){
  rf("/p/crap-on-my-desk.inc.php?ep="+episode,"epShow");
  rf("/p/crap-on-my-desk.inc.php?eptitle="+episode,"epTitle");
  rf("/p/crap-on-my-desk.inc.php?epwinners="+episode,"epWinners");
}

function jobs(job){
  var theJob=document.getElementById('job'+job);
  if(theJob.style.display=='block') theJob.style.display='none';
  else theJob.style.display='block';
}

//LANGUAGE SELECTER
function langSelect(){
  var slctr = document.getElementById('slctr');
  if(slctr.style.display=='block') slctr.style.display='none';
  else slctr.style.display='block';
}