var backmode="normal";
var thisUrl = "";
var delim404 = "/"
var focusTo = '';
// -------------------- library functions
function isIE6() {
  var av = navigator.appVersion;
  var i = av.indexOf('MSIE 6');
  return (i < 50 && i > -1);
}
function hide(el,swapto) {
  if (typeof(el) == 'string') { el = document.getElementById(el); }
  if (el && el.style) { el.style.display = 'none'; }
  if (swapto) {
    if (typeof(swapto) == 'string') { var elto = document.getElementById(swapto); } else { var elto = swapto; }
    if (elto) {elto.style.display = 'block'; }
  }
}
//
function hideSelects() {
  if (isIE6()) {
    for(var m = 0; m < document.all.tags("SELECT").length; ++m) {
        document.all.tags("SELECT")[m].style.visibility='hidden';
    }
  }
}
//
function showSelects() {
  if (isIE6()) {
    for(var s = 0; s < document.all.tags("SELECT").length; ++s) {
        document.all.tags("SELECT")[s].style.visibility='visible';
    }
  }
}
//
function setFocusTo() {
  if (focusTo) {
    var el = document.getElementById(focusTo);
    if (el) { el.focus(); try { el.select(); } catch(err) {}; }
  }
}
//
function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
//
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}
//--------------------------------------
function getBounds(ele) {
  var res = { x:0, y:0, w:0, h:0 }
  if (typeof(ele) == 'string') { var el = document.getElementById(ele); } else { var el = ele; }
  if (el) {
    res.x = el.offsetLeft; res.y = el.offsetTop;  res.h = el.offsetHeight;  res.w = el.offsetWidth;
    while((el=el.offsetParent) != null) {
      res.x += el.offsetLeft+(el.clientLeft ? el.clientLeft : 0);
      res.y += el.offsetTop+(el.clientTop ? el.clientTop : 0);
    }
  }
  return res;
}
//--------------------------------------
function xOnPage(x,w,centerIt,ele,fixed) {
  var sw = -1;
  if (self.innerWidth){sw = self.innerWidth;}
  else if (document.documentElement && document.documentElement.clientWidth){sw = document.documentElement.clientWidth;}
  else if (document.body){sw = document.body.clientWidth;}
  var wmin = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : (window.pageXOffset ? window.pageXOffset : 0));
  if (typeof(wmin) != 'number' || wmin < 0) { wmin = 0; }

  if (isIE6()) { fixed = false; }
  if (fixed) { wmin = 0; }

  var sw = sw + wmin;
  if (centerIt) { x = (Math.round((sw - wmin - w) / 2)) + wmin; }
  if ((sw > -1)) {	if (x<0) { x=0; }		if ((x + w) > sw - 10) {	x = sw - w - 10;	} }
		if (x < wmin) { x = wmin; }
		return x;
}
function yOnPage(y,h,centerIt,ele,fixed) { // pass ele to make sure max height is not exceeded
  var sh = -1;
  if (self.innerHeight){sh = self.innerHeight;}
  else if (document.documentElement && document.documentElement.clientHeight){sh = document.documentElement.clientHeight;}
  else if (document.body){sh = document.body.clientHeight;}
  var hmin = (document.documentElement.scrollTop ? document.documentElement.scrollTop : (window.pageYOffset ? window.pageYOffset : 0));
  if (typeof(hmin) != 'number' || hmin < 0) { hmin = 0; }

  if (isIE6()) { fixed = false; }
  if (fixed) { hmin = 0; }

  var sh = sh + hmin;
  if (centerIt) { y = (Math.round((sh - hmin - h) / 2)) + hmin; }
  if ((sh > -1)) {	if (y<0) { y=0; }		if ((y + h) > sh - 10) {	y = sh - h - 10 ; } }
		if (y < hmin) { y = hmin; }
  if (ele && h > sh) { ele.height = sh; }
		return y;
}
//--------------------------------------
// popup.... are routines to use if you want a mouse listener and optional hotspot.
// use: call popupInit(closefunc, hotid) at the start of your popup show function and pass it your hide/close function.
// hotId is the id of the click-to-close area - pass '' for anywhere on the page or !divid to close anywhere EXCEPT divid.
// If you want to manually close the popup, call popupClose('','myresult') NOT your hide/close function
// 'myresult' will be put in global var popupResult so you can control what to do in the hide/close function
var popupSafeToClose = false;
var popupOMD = null;
var popupDiv = '';
var popupCloseFunc = null;
var popupResult = '';
var popupClosing = false;
var popupPending = null;
var popupClosedTime = 0;
//
function popupInit(closeFunc, hotId) {
  if (popupClosing) { return false;  }
  popupPending = null;
  // tidy up any open popup
  if (popupSafeToClose) { popupRemoveListener(); if (popupCloseFunc) { popupCloseFunc();} popupCloseFunc = null;  popupSafeToClose = false; }
  // prep the listener for the new popup
  popupCloseFunc = closeFunc;  popupDiv = hotId;  popupAttachListener();  hideSelects();  popupSafeToClose = true;
  return true;
}
//
function popupClose(e,closeResult) {
  if (popupSafeToClose) {
    if (e == undefined) var e = window.event; // make sure IE has the event in e
    if (e && e.button && e.button == 2) return;
    if (popupDiv.match('!')) { var pd = popupDiv.substring(1,100); var inpd = false; } else { var pd = popupDiv; var inpd = true; }
    if (pd == '' || (pd != '' && (e == '' || e == 'timer' || (inpd && popupInDiv(e,pd)) || (!inpd && !popupInDiv(e,pd))))) {
      popupClosing = true;
      popupResult = (closeResult==undefined ? null : closeResult);
//      popupResult = ((closeResult == '') || (closeResult==null) || (closeResult==undefined) ? '' : closeResult);
      popupRemoveListener();
      popupSafeToClose = false;
      if (popupCloseFunc) { popupCloseFunc();}
      popupCloseFunc = null;
      showSelects();
      popupClosing = false;
      popupClosedTime = Date.parse(new Date());

      if (popupPending) { popupPending(); popupPending = null; }
    }
  }
}
function popupJustClosed() {
  var now = Date.parse(new Date());
//  alert(now+' '+popupClosedTime);
  var i = Math.abs(now - popupClosedTime);
//  alert(i);
  popupClosedTime = 0;
  return (i < 300);
}
//
function popupAttachListener() {
   	if (document.layers) {	document.captureEvents(Event.MOUSEDOWN);	}
   	popupOMD = document.onmousedown;
   	if (popupOMD != null) {	document.onmousedown = function(event) { popupOMD(event); popupClose(event); } }
    else { document.onmousedown = function(event) { popupClose(event); } }
}
//
function popupRemoveListener() {
   	if (popupOMD != null) {	document.onmousedown = popupOMD; } else { document.onmousedown = null; }
}
//
function popupInDiv(e, divID) {
  if (!e) var e = window.event; // make sure IE has the event in e
  if (!divID) { divID = popupDiv; }
  if (document.layers) {
			var clickX = e.pageX;
			var clickY = e.pageY;
			var t = document.layers[divID];
			if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
				return true;
			}
		}
		else if (e && e.srcElement) {
			var t = e.srcElement;
			while (t && t.parentElement != null) {
				if (t.id==divID) {	return true; }
				t = t.parentElement;
			}
		}
		else if (e && e.originalTarget) {
			var t = e.originalTarget;
   try {
   		while (t && t.parentNode != null) {
  				if (t.id==divID) { return true; }
  				t = t.parentNode;
  			}
  	}
   catch(err)
   {}
		}
		return false;
}
// end popup listener
//--------------------------------------
function getCookie( check_name ) {
   var a_all_cookies = document.cookie.split( ';' );
   var a_temp_cookie = '';
   var cookie_name = '';
   var cookie_value = '';
   var b_cookie_found = false; // set boolean t/f default f

   for ( i = 0; i < a_all_cookies.length; i++ )
   {
      a_temp_cookie = a_all_cookies[i].split( '=' );
      cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');  // trim
      if ( cookie_name == check_name )
      {
         b_cookie_found = true;
         if ( a_temp_cookie.length > 1 ) { cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') ); }
//alert(document.cookie);
         return cookie_value;
         break;
      }
      a_temp_cookie = null;
      cookie_name = '';
   }
   if ( !b_cookie_found ) { return ''; }
}
//--------------------------------------
// expires is in days
function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; }
  var expires_date = new Date( today.getTime() + (expires) );

  var s = name + "=" +escape( value ) +
    ( ( expires ) ? "; expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
    ( ( path ) ? "; path=" + path : "; path=/" ) +
    ( ( domain ) ? "; domain=" + domain : "" ) +
    ( ( secure ) ? "; secure" : "" );
  document.cookie = s;
}
//--------------------------------------
function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
     ( ( path ) ? "; path=" + path : "; path=/") +
     ( ( domain ) ? "; domain=" + domain : "" ) +
     "; expires=Thu, 01-Jan-1990 00:00:01 GMT";
}
//----
function cssStyle(el, property) {
  var res = el.style[property];
  if (!res) {
    if (el.currentStyle && el.currentStyle[property]) {
      res = el.currentStyle[property];
    } else {
      // this method uses 'background-image' not the passed format of 'backgroundImage'
      prop = "";
      for (var i=0; i < property.length; i++) {
        if (property.charAt(i) == property.charAt(i).toUpperCase()) {
          prop += '-' + property.charAt(i).toLowerCase(); }
        else {
          prop += property.charAt(i); }
      }
      res = getComputedStyle(el,'').getPropertyValue(prop);
    }
  }
  if (!res) { res = ''; }
  if (typeof(res) == 'string') { res = res.replace('px',''); }
  return res;
}
//------------
var isModal = true;
var shadowOffset = 8;
var shadowBox = null;

function showShadowBox( id ) {
  var div = createDynamicPopup('shadowBox');  div.style.zIndex = '2000';
  if (div) {
    if (typeof(id) == 'string') { var el = document.getElementById(id); } else {var el = id; }

    var i = cssStyle(el,'zIndex');
    if (i-0 > 0) { div.style.zIndex = (i-1) + ''; }
    div.style.top = (el.offsetTop+shadowOffset) + 'px';
    div.style.left = (el.offsetLeft+shadowOffset) + 'px';
    div.style.height = el.offsetHeight + 'px';
    div.style.width = el.offsetWidth + 'px';
    div.style.display = 'block';
    shadowBox = div;      // keep a gloabl refeerence to it
    el.shadow = shadowBox;  // so drag can find the div
  }
}
function hideShadowBox( ) {
  var div = document.getElementById('shadowBox');
  if (div) {
    div.style.display = 'none';
  }
}

function documentSize() {
  if (window.innerHeight != undefined && window.scrollMaxY != undefined) {// Firefox
    var y = window.innerHeight + window.scrollMaxY;
    var x = window.innerWidth + window.scrollMaxX;
//  } else if (document.documentElement.clientHeight) {  // dumb opera return the window size not the document
//    var x = document.documentElement.clientHeight;
//    var y = document.documentElement.clientHeight;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    var y = document.body.scrollHeight;
    var x = document.body.scrollWidth;
  } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    var y = document.body.offsetHeight;
    var x = document.body.offsetWidth;
  }
  if (y == 0)  y = 5000;
  return { 'width':x, 'height':y };
}

function showModalCover( ) {
  var div = document.getElementById('modalCover');
  if (div) {
    div.style.left = '0px';
    div.style.width = '100%';
    div.style.top = '0px';

    var sh = -1;
    if (self.innerHeight){sh = self.innerHeight;}
    else if (document.documentElement && document.documentElement.clientHeight){sh = document.documentElement.clientHeight;}
    else if (document.body){sh = document.body.clientHeight;}

    var size = documentSize();
    var h = size.height;
    if (h < sh) { h = sh; }
    div.style.height = h+'px';
    div.style.display = 'block';
  }
}
function hideModalCover( ) {
  var div = document.getElementById('modalCover');
  if (div) {
    div.style.display = 'none';
  }
}

function createDynamicPopup(id, modal ) {
  if (modal) { var cover = createDynamicPopup('modalCover');  cover.style.zIndex = ''; }

//  var div = document.getElementById(id);
// 	if (div) { div.parentNode.removeChild(div);

  var div = document.getElementById(id);
  if (!div) {
    var div = document.createElement('div');
    div.setAttribute('id', id);
    div.setAttribute('name', id);
    div.style.display = 'none';
    div.style.zIndex = 10000;
    document.body.appendChild(div);
  }
  return div;
}
function integerOnly(event) {
  event = event || window.event;
  var key = (event.keyCode ? event.keyCode : event.which);
// 0..9, return, tab, del, backspace, left, rig7ht, home, end
  if (((key > 47) && (key < 58)) || (key == 13) || (key == 8) || (key == 9) || (key == 46) || (key == 39) || (key == 37) || (key == 35) || (key == 36))
    { return true; }
  else
    { event.returnValue = false; return false; }
}
/*function myunload() {
  document.getElementById('unloading').style.display = 'block';
//  document.body.className = 'unloading';
  window.scrollTo(0,1);
  window.scrollTo(0,0);
}*/
function wborder(el) {
// returns the padding and border width for el's style
  return (cssStyle(el,'borderLeftWidth')-0) + (cssStyle(el,'borderRightWidth')-0) +
         (cssStyle(el,'paddingLeft')-0) + (cssStyle(el,'paddingRight')-0);
}
function hborder(el) {
// returns the padding and border width for el's style
  return (cssStyle(el,'borderTopWidth')-0) + (cssStyle(el,'borderBottomWidth')-0) +
         (cssStyle(el,'paddingTop')-0) + (cssStyle(el,'paddingBottom')-0);
}
function transitionStop(el) {
  if (el && el.trans) { el.trans.die(); }
}
function transition(from, tooo, param) {
  var i_trans = new c_trans(from, tooo, param);
}
function c_trans(from, tooo, param) {
//from:  { id:id, el:element, x:left, y:top, w:width, h:height }
//tooo:  { id:id, el:element, x:left, y:top, w:width, h:height }
//param  { classname:'abc', speed:##, movediv:'Y', grow:'Y', vanish:'Y', hide:'Y', onend:funcname } NOTE ALL FIELD NAMES ARE LOWERCASE
// speed is approx time the transition should take in millisecs, note IE is a bit slow
// vanish:'Y' overrides the tooo size/position so it ends up as 10x10 box in the center of tooo.id
// grow='Y' auto calculates the from position to be a 10x10 box in the center of tooo.id
//     - specify x,y,w,h in from to override the 10x10 centred start position
// movediv:'Y' will move the actual div passed as 'from'
// hide:'Y' will hide the div at the end and move it back to its original position and size Only works if movediv is used
// onend : pass it a function to call when the transition is complete - format: function(div) where div will be the 'from' div
// focus : will set focus to the passed id after the onend has been called
// note, pass a div or el as from if you need to access the div in the onend function

   c_trans.prototype.die = function() {
     clearTimeout(this.timer);
     if (this.from.el && this.from.el.trans) { this.from.el.trans = null; }

     if (!this.param.movediv) {
       this.div.style.display = 'none';
       var elp = this.div.parentNode;
       if (elp) { elp.removeChild(this.div); }
     }
     else if (this.param.hide) {
       this.div.style.display = 'none';
       // put it back in its original position
       this.div.style.top = this.div.opos.y + 'px';
       this.div.style.left = this.div.opos.x + 'px';
       this.div.style.width = this.div.opos.w + 'px';
       this.div.style.height = this.div.opos.h + 'px';
     }
   }
   
   c_trans.prototype.onTimer = function() {
     try {
       this.count++;
       if (this.count <= this.maxCount) {
         if (this.loops[this.loop] == 'wh' || this.loops[this.loop] == 'w') {
           this.div.pos.x = this.div.pos.x + this.xstep;
           this.div.pos.w = this.div.pos.w - this.wstep;
         }

         if (this.loops[this.loop] == 'wh' || this.loops[this.loop] == 'h') {
           this.div.pos.y = this.div.pos.y + this.ystep;
           this.div.pos.h = this.div.pos.h - this.hstep;
         }

         if (this.loops[this.loop] == 'fi') {
           this.opacity += this.ostep;
           this.div.style.opacity = this.opacity / 100;
           this.div.style.filter = "alpha(opacity=" + Math.round(this.opacity) + ")";
         }

         this.div.style.top = Math.round(this.div.pos.y) + 'px';
         this.div.style.left= Math.round(this.div.pos.x) + 'px';
         this.div.style.width = Math.round(this.div.pos.w) + 'px';
         this.div.style.height = Math.round(this.div.pos.h) + 'px';
       }
       if (this.count <= this.maxCount+1) {
         if (this.count > this.maxCount && this.loop < this.loops.length-1)
         {
           this.loop++;  this.count = 0;
         }
         this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), tinc );
       } else {
  //     this.div.style.zIndex = 100;
  //alert('trans width='+this.div.offsetWidth+' '+this.div.pos.w+' '+this.div.opos.w+' '+this.wstep);
         if (this.from.el && this.from.el.offsetLeft < -1500) { this.from.el.style.left = this.div.post.x + 'px'; }
         this.die();
         if (this.param.onend) { this.param.onend(this.from.el); }
         if (this.param.focus) { var el = document.getElementById(this.param.focus); if (el) { el.focus(); } }
         this.destroy;
       }
     }
     catch(err)
     {}
   }

   var copyof = function(x) { var ret = {}; for (var i in x) { ret[i] = x[i]; } return ret; }
   var exists = function(val) { return val != undefined; }

   c_trans.prototype.init = function() {
     var posf = { x:0, y:0, w:10, h:10 }
     var post = { x:100, y:100, w:10, h:10 }

     if (exists(this.from.el)) { var elf = this.from.el; var posf = getBounds(elf); }
     if (exists(this.from.id)) { var elf = document.getElementById(this.from.id); var posf = getBounds(elf); this.from.el = elf; }
     if (exists(this.from.x)) { posf.x = this.from.x; }
     if (exists(this.from.y)) { posf.y = this.from.y; }
     if (exists(this.from.w)) { posf.w = this.from.w; }
     if (exists(this.from.h)) { posf.h = this.from.h; }
     if (this.from.el) { this.from.el.trans = this; }
//for (var xxx in posf) { alert(xxx + ' = ' + posf[xxx]) }

     if (exists(this.to.el)) { var elt = this.to.el; var post = getBounds(elt); }
     if (exists(this.to.id)) { var elt = document.getElementById(this.to.id); var post = getBounds(elt); this.to.el = elt; }
     if (exists(this.to.x)) { post.x = this.to.x; }
     if (exists(this.to.y)) { post.y = this.to.y; }
     if (exists(this.to.w)) { post.w = this.to.w; }
     if (exists(this.to.h)) { post.h = this.to.h; }
     if (this.to.el) { this.to.el.trans = this; }

     var hmin = (document.documentElement.scrollTop ? document.documentElement.scrollTop : (window.pageYOffset ? window.pageYOffset : 0));
     if (typeof(hmin) != 'number' || hmin < 0) { hmin = 0; }
     var fixed = (cssStyle(this.from.el,'position') == 'fixed' && !isIE6());
//alert(fixed);
     if (fixed) { post.y += hmin;  posf.y += hmin; }

     if (posf && post) {
       if (this.param.movediv) {
         this.div = elf;
       } else {
         this.div = createDynamicPopup('trans_div'+c_trans.divno);
         c_trans.divno++;
         if (this.from.el) { this.from.el.style.left = '-2000px'; }
       }
       this.div.style.position = 'absolute';
       if (!this.param.movediv) {
         if (this.param.classname)
           { this.div.className = this.param.classname; }
         else
           { this.div.style.background = 'white'; this.div.style.border = '1px solid red'; }
       }

       if (this.loops[0] == 'fi') {
         this.div.style.opacity = this.opacity / 100;
         this.div.style.filter = "alpha(opacity=" + this.opacity + ")";
       }

       var wfix = wborder(this.div);
       posf.w -= (wfix);
       post.w -= (wfix);

       var hfix = hborder(this.div);
       posf.h -= (hfix);
       post.h -= (hfix);

       if (posf.w < 0) { posf.w = 0; }
       if (posf.h < 0) { posf.h = 0; }

       if (this.param.grow) {
         // default is grow from 10x10 centered on 'to' but can be overridden by setting the 'from' x,y,w,h
         if (this.from.w == undefined) { posf.w = 10; }
         if (this.from.x == undefined) { posf.x = Math.round(post.x + (post.w/2)-(posf.w/2)); }
         if (this.from.h == undefined) { posf.h = 10; }
         if (this.from.y == undefined) { posf.y = Math.round(post.y + (post.h/2)-(posf.h/2)); }
       }
//for (var xxx in posf) { alert(xxx + ' = ' + posf[xxx]) }

       if (this.param.vanish) {  // shrink to 10x10 centered on 'to'
         post.x = Math.round(post.x + (post.w/2)-5); post.w = 10;
         post.y = Math.round(post.y + (post.h/2)-5); post.h = 10;
       }

       this.div.style.top = posf.y + 'px';
       this.div.style.left = posf.x + 'px';
       this.div.style.width = posf.w + 'px';
       this.div.style.height = posf.h + 'px';
       this.div.pos = copyof(posf);
       this.div.opos = copyof(posf);
       this.div.post = copyof(post);
       this.div.style.display = 'block';

       var xdiff = (posf.x - post.x);
       var ydiff = (posf.y - post.y);
       var wdiff = (posf.w - post.w);
       var hdiff = (posf.h - post.h);

       this.maxCount = Math.round(this.param.speed / ((tinc + 100) * this.loops.length)) + 1;
       this.xstep = -xdiff / this.maxCount;
       this.ystep = -ydiff / this.maxCount;
       this.wstep = wdiff / this.maxCount;
       this.hstep = hdiff / this.maxCount;

       if (this.loops[0] == 'fi') {
         tinc = 50;
         this.maxCount = this.param.speed / (tinc + 20);
         this.ostep = 80 / this.maxCount;
       }
//alert('posf '+posf.x+' '+posf.y+' '+posf.w+' '+posf.h+' post '+post.x+' '+post.y+' '+post.w+' '+post.h+' '+this.div.style.display);

       this.count = 0;
       this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), 1 );
     }
   }

  var tinc = 33;
  this.from = from;
  this.to = tooo;
  this.param = param;
//for (var xxx in param) { alert(xxx + ' = ' + param[xxx]) }

  this.loops = new Array;
  this.loop = 0;
  if (this.param.action == undefined)
    { this.loops[0] = 'wh'; }
  else
    { this.loops = this.param.action.split(',');
  }
  this.opacity = 20;
  if (this.param.speed == undefined) { this.param.speed = 20; }
  if (this.param.movediv == undefined) { this.param.movediv = ''; }
  if (this.param.classname == undefined) { this.param.classname = ''; }
  if (this.param.onend == undefined) { this.param.onend = ''; }
  if (this.param.hide == undefined) { this.param.hide = ''; }
  if (this.param.focus == undefined) { this.param.focus = ''; }

  this.init();
}
c_trans.divno = 0;
// ---------
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
//
// load most of the images after the main body has loaded.
// to use just change img src="??" to img data-src="??"
function postLoadImages() {
  var Coll = document.getElementsByTagName("IMG");
  for (var m = 0; m < Coll.length; ++m) {
    if (Coll[m].getAttribute('data-src')) {
      Coll[m].src = Coll[m].getAttribute('data-src');
      Coll[m].setAttribute('data-src','');
    }
  }
}
/*function addLoadEvent(func, first) {  // set first to true to add this event at the front of the queue
return
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
  window.onload = function() {
      if (first) { func(); }
      if (oldonload) { oldonload(); }
      if (!first) { func(); } // an error here usually means you have passed the func with ()
    }
  }
}
function addUnloadEvent(func, first) {  // set first to true to add this event at the front of the queue
  var oldunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  }
  else {
  window.onunload = function() {
      if (first) { func(); }
      if (oldunload) { oldunload(); }
      if (!first) { func(); } // an error here usually means you have passed the func with ()
    }
  }
}*/
var loadEvents = new Array;
function addLoadEvent(func, first) {  // set first to true to add this event at the front of the queue
  loadEvents[loadEvents.length] = { 'func':func, 'first':(first==true ? true : false) }
}
function resetBackController() {
  var el = document.getElementById('backctrl');
  if (el) { el.value='OK'; }
}
function backController() {
//alert(backmode);
  var el = document.getElementById('backctrl');
  if (el) {
    if (el.value=='LOADED') {
      if (backmode == 'normal') {  // normal = do a forced reload of the page
//        document.body.innerHTML = '<html><head></head><body><center>Loading Page. Please wait...</center></body><html>';
location.reload(true);
//        location = window.location.href;
      }
      if ((backmode == 'basket') || (backmode == 'lock')){
        document.body.innerHTML = '';
location.reload(true);
/*        var s = window.location.href;
        var fixer = new Date();
        var i = s.indexOf('when=');
        if (i > -1) {
          var j = s.indexOf('&',i+1);  if (j == -1) { j = s.length+1; }
          s = s.replace(s.substring(i,j),"when="+fixer.getTime());
        }
        else
        { s += (s.indexOf('?') > -1 ? '&' : '?') + "when="+fixer.getTime(); }
        location = s;
*/
      }
    }
    else { var xx = window.setTimeout('backController2()',1); }
  }
}
function backController2() {
  var el = document.getElementById('backctrl');
  if (el) {
    if (el.value=='OK') { el.value = 'LOADED'; }
    else {
      if (backmode == 'normal') {
        location.reload(true);
      }
      if ((backmode == 'basket') || (backmode == 'lock')) {
        document.body.innerHTML = '';
        location.reload(true);
      }
    }
  }
}
function doLoad() {
   backController();

   for (var i=loadEvents.length-1; i >= 0; i--) {
     if (loadEvents[i].first) { loadEvents[i].func(); }
   }
   for (var i=0; i<loadEvents.length; i++) {
     if (!loadEvents[i].first) { loadEvents[i].func(); }
   }
}
//
function setHeight() {
var y = -1;
if (self.innerHeight){y = self.innerHeight;}
else if (document.documentElement && document.documentElement.clientHeight){y = document.documentElement.clientHeight;}
else if (document.body){y = document.body.clientHeight;}
if ((y > 100) && (document.body.offsetHeight) && (y > document.body.offsetHeight))
  { document.body.style.height = y + 'px'; }
}
//--------------------------------------
function noBack(path) {
// call this rather than loction= to stop the current page being added to the browser history
// not tested but the logic needs to be replace the url rather than locate to another
  window.URL.replace(path);
}
//
function imageErr(el, id, hideel, stopclick, restart) {
// usage = <img onerror="imageErr(this, 'imagesize', 'hide1;hide2', 'noclick1;noclick2');" >
  var safe = el.onerror;
  el.onerror = null;  // stop stack overflow if err image doesnt exist
  if (id == 'large' || id == 'zoom' || id == 'thumb') { id = thisUrl+'products/images/coming_soon_'+id+'.gif'; }
  el.src=id;
  if (hideel) {
    var ar = hideel.split(';');
    for (var i=0; i<ar.length; i++) {
      if (ar[i]) {
        ely = document.getElementById(ar[i].replace(' ',''));
        if (ely) {ely.style.display='none'; }
      }
    }
  }
  if (stopclick) {
    var ar = stopclick.split(';');
    for (var i=0; i<ar.length; i++) {
      if (ar[i]) {
        ely = document.getElementById(ar[i].replace(' ',''));
        if (ely) {ely.onclick = null; ely.style.cursor = 'normal'; }
      }
    }
  }
  if (restart) {
    el.onerror = safe;
  }
}
//--
// -------------------- web site functions
//--
function noNull(s) {
  if (s == null) { s = ''; }
  return s;
}
function imageErr2(s,s1) {
alert('error '+s.src+' '+bigpicImage.src);
}
function initBigImage(modal) {
  // this replaces the hidden code in the HTML script to prevent the IE6 hidden stuff problem
  var id = 'bigImage';
  var div = createDynamicPopup(id,modal);
  var s = '';
  s+='<div id="bigImageHead"></div>';
  s+='<img id="bigImageCloseBtn" src="'+thisUrl+'assets/images/headerbtn.jpg" alt="close" title="close" />';
  s+='<div id="bigImageImg"><img id="bigImageImgImage" onerror="imageErr(this,\'zoom\')" /></div>';
  div.innerHTML = s;
//  var el = document.getElementById('bigImageHead');
//  if (el) { dhBig = DragHandler.attach(el,div); } // make it draggable on the header
}
function bigpicClose()
{
  el = document.getElementById('bigImage');
//  hideShadowBox();
  transitionStop(el);
  hideModalCover();
  el.style.display='none';
}
var explodeStage = 0;
var bigpicInitSize = { w:0, h:0 }
var bigpicImage = null;
function bigpicAdjust()
{
  var div = document.getElementById('bigImage');
  var im = document.getElementById('bigImageImgImage');
  var el = bigpicImage;
//alert(el.width+' '+el.height+' '+bigpicInitSize.wi+' '+bigpicInitSize.hi+' '+div.origleft+' '+x+' '+bigpicInitSize.w)
  if (el.width > bigpicInitSize.wi && (el.width != bigpicInitSize.wi || el.height != bigpicInitSize.hi)) {
    var x = xOnPage(0,el.width+bigpicInitSize.wx,true);
    var y = yOnPage(0,el.height+bigpicInitSize.hx,true,null,true);

    bigpicInitSize.innerDiv.style.width = el.width+'px';
    bigpicInitSize.innerDiv.style.height = el.height+'px';
    div.style.width = el.width+bigpicInitSize.wx+'px';
    div.style.height = el.height+bigpicInitSize.hx+'px';
    div.style.left = x + 'px';
    div.style.top = y + 'px';
  //  showShadowBox('bigImage');
  }
  im.src = el.src;
}
function bigpicLoaded()
{
  if (explodeStage < 2)
    { explodeStage = 3; } // save the image element for the explode finish
  else if (explodeStage == 2)
    { bigpicAdjust(); } // explode has finished so redraw it
}
function exploded(div) {
  if (explodeStage == 1) {  // image hasnt loaded yet so just show the div
    explodeStage = 2; // finished explode
    if (window.opera || bigpicImage.width > 0) { bigpicAdjust(); } // cos wont call the onload handler and ie doesnt if its already loaded
//    showShadowBox(div);
  } else {
    bigpicAdjust();
  }
}
function explode(div, classs, endfunc, fromcust, focus_to) {
  showModalCover();
  div.style.left = '-2000px';
  explodeStage = 1; // exploding
  var too = { x:div.origleft, y:div.offsetTop, w:div.offsetWidth, h:div.offsetHeight };
  if (fromcust) { var from = fromcust; } else { var from = { el:div }; }
  transition( from, too, { speed:1000, classname:classs, grow:'Y', onend:endfunc, action:'h,w', focus:focus_to } );
//  transition( from, too, { speed:700, classname:'bigImage', movediv:'Y', onend:exploded, action:'fi' } );
}
function bigpic(what,sub) {
// sub >=0 = bikebuilder feature index
// sub = -1  bikebuilder frame
// sub = -2  prodpage
// sub = -3  showpart
// sub = -4  bb
// sub = -5  basket
   explodeStage = 0; // start new load
   initBigImage(isModal);
   popupInit(bigpicClose,'!bigImageImg');//'bigImageCloseBtn');
   var el = document.getElementById('bigImage');
   var eli = document.getElementById('bigImageImg');
   if (el && eli) {
     el.style.display = 'none';
     if (sub == -5) { var im = '('+document.getElementById("bsktImg"+what).src+')'; }
     else
     if (sub == -3) { var im = '('+noNull(document.getElementById("pdImage").src)+noNull(document.getElementById("pdImage").getAttribute('data-src'))+')'; }
     else
     if (sub == -2) { var im = '('+document.getElementById("pimage"+what).src+')'; }
     else
     if (sub == -1) { var im = '('+document.getElementById("bbImage"+what).src+')'; } //style.backgroundImage; }
     else
     if (sub == -4) { var im = document.getElementById("bbImage"+what).style.backgroundImage; }
     else
     { var im = '('+document.getElementById("bbImage"+what+'Sub'+sub).src+')'; } //style.backgroundImage; }
     im = im.replace(/"/g,'');  // stupid opera puts quotes on the path from backgroundImage
     var a = im.split('(');
     im = a[1];
     a = im.split(')');
     im = a[0];
     if (im.match('coming_soon') || im.match('blank.gif')) { return false; }  // dont show if its a coming soon image
     c = im.replace('_1_large','_1_zoom');
     c = c.replace('_1_thumb','_1_zoom');

//     var ii = c.indexOf('products');  // opera fix
//     if (ii > -1) { c = c.substring(ii,100); }
//     eli.innerHTML = '';
     el.style.left = '-2000px';
// save all the original dimensions so that proper sizes are set when the image loads
     if (bigpicInitSize.w == 0) {
       bigpicInitSize.w = cssStyle(el,'width');
       bigpicInitSize.h = cssStyle(el,'height');
       bigpicInitSize.wi = cssStyle(eli,'width');
       bigpicInitSize.hi = cssStyle(eli,'height');
       bigpicInitSize.wx = bigpicInitSize.w - bigpicInitSize.wi;
       bigpicInitSize.hx = bigpicInitSize.h - bigpicInitSize.hi;
     }
     bigpicInitSize.innerDiv = eli;
     el.style.width = bigpicInitSize.w + 'px';
     el.style.height = bigpicInitSize.h + 'px';
     eli.style.width = bigpicInitSize.wi + 'px';
     eli.style.height = bigpicInitSize.hi + 'px';
     el.style.display = 'block';
// at this point the image is 400 x 399 in theory so save the widthdiff and heightdiff in the div for later
     var x = xOnPage(x,el.offsetWidth,true);
     var y = yOnPage(y,el.offsetHeight,true,null,true);

     el.origleft = x;
//     el.style.left = x + 'px';
     el.style.top = y + 'px';
//alert(c);
//     eli.innerHTML = '<img id="bigImageImgImage" onerror="imageErr(this,\'zoom\')" onload="bigpicLoaded(this)" onchange="alert(\'changed\')">';
// new way to try and get opera to actually call the onload handler - doesnt work
     bigpicImage = new Image();
     bigpicImage.onload = bigpicLoaded;
     bigpicImage.src = c;

     if (sub == -5) {
       document.getElementById('bigImageHead').innerHTML = document.getElementById('bsktTitle'+what).innerHTML;
     }
     else
     if (sub == -3) {
       document.getElementById('bigImageHead').innerHTML = what;
     }
     else
     if (sub == -2) {
       document.getElementById('bigImageHead').innerHTML = document.getElementById('listItemTitle'+what).innerHTML;
     }
     else
     if (sub == -1 || sub == -4) {
       var elt = document.getElementById('bbItemTitle'+what);
       if (elt) { document.getElementById('bigImageHead').innerHTML = elt.innerHTML; }
     }
     else {
       document.getElementById('bigImageHead').innerHTML = document.getElementById('bbItemTitle'+what+'Sub'+sub).innerHTML; }
//     document.getElementById('bigImageText').innerHTML = c;
//     document.getElementById('bigImageText').style.textAlign = 'right';
     explode(el,'bigImage',exploded);
//     showShadowBox(el);
   }
   return false;
}
//--------------------------------------
function initEuFlags(modal) {
  // this replaces the hidden code in the HTML script to prevent the IE6 hidden stuff problem
  var id = 'currencyFlagsEU';
  var div = createDynamicPopup(id,modal);
  var s = '';
  s+='<div id="currencyFlagsHead">Please Choose Your Country</div>';
		s+='<a href="#" onClick="hideEuFlags(); return false;" id="currencyCloseBtn"></a>';
  s+='<div id="currencyFlagsMain">';
  s+='<div class="col">';
		s+='<a onClick="changeCurrency(\'EUR\',\'AT\')" alt="Austria" title="Austria"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Austria.jpg" /><span class="currencyT">Austria</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'BE\')" alt="Belgium" title="Belgium"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Belgium.jpg" /><span class="currencyT">Belgium</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'BG\')" alt="Bulgaria" title="Bulgaria"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Bulgaria.jpg" /><span class="currencyT">Bulgaria</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'CY\')" alt="Cyprus" title="Cyprus"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Cyprus.jpg" /><span class="currencyT">Cyprus</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'CZ\')" alt="Czech Republic" title="Czech Republic"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Czech.jpg" /><span class="currencyT">Czech Republic</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'DK\')" alt="Denmark" title="Denmark"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Denmark.jpg" /><span class="currencyT">Denmark</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'EE\')" alt="Estonia" title="Estonia"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Estonia.jpg" /><span class="currencyT">Estonia</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'FI\')" alt="Finland" title="Finland"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Finland.jpg" /><span class="currencyT">Finland</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'FR\')" alt="France" title="France"><img class="currencyE" src="'+thisUrl+'assets/images/flags/France.jpg" /><span class="currencyT">France</span></a>';
		s+='</div>';
  s+='<div class="col">';
		s+='<a onClick="changeCurrency(\'EUR\',\'DE\')" alt="Germany" title="Germany"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Germany.jpg" /><span class="currencyT">Germany</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'GR\')" alt="Greece" title="Greece"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Greece.jpg" /><span class="currencyT">Greece</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'HU\')" alt="Hungary" title="Hungary"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Hungary.jpg" /><span class="currencyT">Hungary</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'IE\')" alt="Irish Republic" title="Irish Republic"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Ireland.jpg" /><span class="currencyT">Irish Republic</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'IT\')" alt="Italy" title="Italy"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Italy.jpg" /><span class="currencyT">Italy</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'LV\')" alt="Latvia" title="Latvia"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Latvia.jpg" /><span class="currencyT">Latvia</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'LT\')" alt="Lithuania" title="Lithuania"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Lithuania.jpg" /><span class="currencyT">Lithuania</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'LU\')" alt="Luxembourg" title="Luxembourg"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Luxembourg.jpg" /><span class="currencyT">Luxembourg</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'MT\')" alt="Malta" title="Malta"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Malta.jpg" /><span class="currencyT">Malta</span></a>';
		s+='</div>';
  s+='<div class="col">';
		s+='<a onClick="changeCurrency(\'EUR\',\'NL\')" alt="Netherlands" title="Netherlands"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Netherlands.jpg" /><span class="currencyT">Netherlands</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'NO\')" alt="Norway" title="Norway"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Norway.jpg" /><span class="currencyT">Norway</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'PL\')" alt="Poland" title="Poland"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Poland.jpg" /><span class="currencyT">Poland</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'PT\')" alt="Portugal" title="Portugal"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Portugal.jpg" /><span class="currencyT">Portugal</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'RO\')" alt="Romania" title="Romania"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Romania.jpg" /><span class="currencyT">Romania</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'SK\')" alt="Slovakia" title="Slovakia"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Slovakia.jpg" /><span class="currencyT">Slovakia</span></a>';
//		s+='<a onClick="changeCurrency(\'EUR\',\'SI\')" alt="Slovenia" title="Slovenia"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Slovenia.jpg" /><span class="currencyT">Slovenia</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'ES\')" alt="Spain" title="Spain"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Spain.jpg" /><span class="currencyT">Spain</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'SE\')" alt="Sweden" title="Sweden"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Sweden.jpg" /><span class="currencyT">Sweden</span></a>';
		s+='<a onClick="changeCurrency(\'EUR\',\'CH\')" alt="Switzerland" title="Switzerland"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Switzerland.jpg" /><span class="currencyT">Switzerland</span></a>';
  s+='</div>';
  s+='</div>';
  div.innerHTML = s;
  var el = document.getElementById('currencyFlagsHead');
  if (el) { dhCur = DragHandler.attach(el,div); } // make it draggable from the header
  return div;
}
//--------------------------------------
function showEuFlags(ele) {
  var id = initEuFlags(isModal);
  if (id) {
    var xy = getBounds(ele);
    var x = xOnPage(xy.x+xy.w-500,530);
    var y = yOnPage(xy.y+xy.h,0);

    showModalCover();
    id.style.top = y + 'px';
    id.style.left = x + 'px';
    id.style.display='block';
    hideSelects();

    wx = wborder(id);
    id.origleft = x;
    explode(id, 'currencyFlagsEU', '', { el:id, y:y, x:x+id.offsetWidth-2-wx, w:2+wx });
  }
}
//--------------------------------------
function hideEuFlags(justDiv) {
  var id = document.getElementById('currencyFlagsEU');
  if (id) { id.style.display='none'; showSelects(); }
  if (!justDiv) hideModalCover();
}
function initCIFlags(modal) {
  // this replaces the hidden code in the HTML script to prevent the IE6 hidden stuff problem
  var id = 'currencyFlagsEU';
  var div = createDynamicPopup(id,modal);
  var s = '';
  s+='<div id="currencyFlagsHead">Please Choose Your Island</div>';
		s+='<a href="#" onClick="hideCIFlags(); return false;" id="currencyCloseBtn"></a>';
  s+='<div id="currencyFlagsMain">';
		s+='<a onClick="changeCurrency(\'GBP\',\'JE\')" alt="Jersey" title="Jersey"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Jersey.jpg" /><span class="currencyT">Jersey</span></a>';
		s+='<a onClick="changeCurrency(\'GBP\',\'GU\')" alt="Guernsey" title="Guernsey"><img class="currencyE" src="'+thisUrl+'assets/images/flags/Guernsey.jpg" /><span class="currencyT">Guernsey</span></a>';
  s+='</div>';
  div.innerHTML = s;
  var el = document.getElementById('currencyFlagsHead');
  if (el) { dhCur = DragHandler.attach(el,div); } // make it draggable from the header
  return div;
}
//--------------------------------------
function showCIFlags(ele) {
  var id = initCIFlags(isModal);
  if (id) {
    var xy = getBounds(ele);
    y = yOnPage(xy.y+xy.h,0);
    x = xOnPage(xy.x+xy.w-500,530);

    showModalCover();
    id.style.display='block';
    id.style.top = y + 'px';
    id.style.left = x + 'px';
    hideSelects();

    wx = wborder(id);
    id.origleft = x;
    explode(id, 'currencyFlagsEU', '', { el:id, y:y, x:x+id.offsetWidth-2-wx, w:2+wx });
  }
}
//--------------------------------------
function hideCIFlags(justDiv) {
  var id = document.getElementById('currencyFlagsEU');
  if (id) { id.style.display='none'; showSelects(); }
  if (!justDiv) hideModalCover();
}
//--------------------------------------
function changeCurrency(c,cc) {
  hideEuFlags(true);
  hideCIFlags(true);
  var from = parent.window.location.href;
  from = from.replace('?','qq_que');
  from = from.replace(/\&/g,'qq_amp');
  var param = '?C='+c+'&CC='+cc+'&from='+from;
  location=thisUrl+'ChangeCurrency.asp'+param;
}
//--------------------------------------
function showLiveFlag() {
// also controls display of currency flags
  if (country_code == '<elucid_country_code>' || country_code == 'GB' || country_code == '') { country_code = 'UK'; }
  if (currency_code == '<elucid_currency_code>' || currency_code == '') { currency_code = 'GBP'; }

  var sub = false;
  var el = document.getElementById('cur'+country_code);
  if (!el) { el = document.getElementById('cur'+currency_code); sub = true; } // for EUR and CI
  if (el) {
    var elb = document.getElementById('currencyChosen');
    if (elb) {
      var im = el.src;
      im = im.replace('_faint','_large');
      elb.src = im;
      elb.alt = el.alt;
      elb.title = el.title;
      if (sub) { elb.onclick = el.onclick; elb.style.cursor = 'pointer'; }
      el.style.display = 'none';
    }
  }
}
//--------------------------------------
function showHomeTab(id) {
  var s = new Array ('RIBMO','RIBTR','RIBMT');
  // default to road and track
  if (!id || id == '<elucid_homeid>') { id = s[0]; }
 	homeid = id; // set the global variable in case it was blank

  for (var i=0; i<s.length; i++) {
    var nid = s[i];
    if (document.getElementById('htab_'+nid)) {
      document.getElementById('htab_'+nid).className = 'm';
      document.getElementById('htabl_'+nid).className = 'l';
      document.getElementById('htabr_'+nid).className = 'r';
    }
  }

  if (document.getElementById('htab_'+id)) {
    document.getElementById('htab_'+id).className = 'm_on';
    document.getElementById('htabl_'+id).className = 'l_on';
    document.getElementById('htabr_'+id).className = 'r_on';
  }

 return false;
}
//--------------------------------------
function showBGSTab(id) {
// bikebuilder, groupset, specials tabs
  var s = new Array ('b','g','s');
  if (!id || id == '<elucid_homeid>') { id = ''; }

  for (var i=0; i<s.length; i++) {
    var nid = s[i];
    if (document.getElementById('htab_'+nid)) {
      document.getElementById('htab_'+nid).className = 'm';
      document.getElementById('htabl_'+nid).className = 'l';
      document.getElementById('htabr_'+nid).className = 'r';
    }
  }

  if (document.getElementById('htab_'+id)) {
    document.getElementById('htab_'+id).className = 'm_on';
    document.getElementById('htabl_'+id).className = 'l_on';
    document.getElementById('htabr_'+id).className = 'r_on';
  }
 return false;
}
//----------
function killTheMenuBecauseIE6IsRubbish(loaded) {
  if (isIE6()) {
    if (loaded != 'loaded') {
      addLoadEvent(function() {killTheMenuBecauseIE6IsRubbish('loaded'); });
      return;
    }
    el = document.getElementById('leftContainer');
    if (el) {
      var elp = el.parentNode;
      if (elp) { elp.removeChild(el); }
    }
    el = document.getElementById('search');
    if (el) {
      var elp = el.parentNode;
      if (elp) { elp.removeChild(el); }
    }
  }
}
//--------------------------------------
function showMenu(id, href) {
  // jiggles the top level menu items content so that the open menu is always at the bottom of the list.
  var m = 'mca';  // = menuid values -> left menu content and order - this must match the html code order
  var mid = '';

  var oid = getCookie('menuId');
  if (!id || id == '<elucid_menuid>') { mid = oid; }
  else if (m.indexOf(id) > -1) { mid = id; }
  if (!mid) { mid = 'a';  } // default to last entry in 'm'

  setCookie('menuId',mid);
  if (oid != mid) {
   hideAllSubMenus(); openMenus = ''; setCookie('openMenus',openMenus); }
  else {
   openMenus = getCookie('openMenus');
  }
//alert(oid+'--'+mid+'--'+id+'--'+getCookie('menuId')+'--'+document.cookie);

  if (!id || !href) {
    var mi = new Array;
    // save the element contents in to the correct array slot
    for (var i=0; i<m.length; i++) {
      var nid = m.charAt(i);
      if (document.getElementById('menu_'+nid)) { document.getElementById('menu_'+nid).style.display = 'none'; }
      if (document.getElementById('menu_top_'+nid)) {
        var t = document.getElementById('menu_top_'+nid).innerHTML;
        document.getElementById('menu_top_'+nid).innerHTML = '';
        var j = t.indexOf('menuid_');
        var c = t.charAt(j+7);
        mi[c] = t;
      }
    }

    // set the new menu order with id at the end
    var m1 = m.replace(mid,'') + mid;
    // add the saved contents into the correct element
    for (var i=0; i<m1.length; i++) {
      var nid = m.charAt(i);
      var nid1 = m1.charAt(i);
      if (document.getElementById('menu_top_'+nid)) {
        document.getElementById('menu_top_'+nid).innerHTML = mi[nid1]; }
    }
    if (document.getElementById('menu_'+mid)) { document.getElementById('menu_'+mid).style.display = 'block'; }

    if (!href) {
      var ar = openMenus.split(';');
      openMenus = '';  // they will be added back in by the calls to showsubmenu
      for (var i=0; i<ar.length; i++) {
        if (ar[i]) {
          var el = document.getElementById(ar[i]);
          if (el) { showSubMenu(null,el.parentNode,ar[i]); }
        }
      }
    }
  }
  // a bug in ie means that clicking on the span inside the <a> does not call the href so do it in here
//  if (href) { location=href; return false;}
//  else { return true; }
//  if (href) { loadTemplateAjax(href); }
  return (href != '')
//  return false;
}
//--------------------------------------
function showSubMenu(e, el, id) {
  if (popupInDiv(e,id)) { return false; };  // if its over the sub menu get out of here
  var div = document.getElementById(id);
//  hideAllSubMenus()
  if (div) {
    if (div.style.display == 'block') {
      div.style.display = 'none';
      el.className = 'la';
      openMenus = openMenus.replace(id+';','');
    }
    else {
      div.style.display = 'block';
      el.className = 'la_open';
      openMenus+=id+';';
    }
  }
  setCookie('openMenus',openMenus);
}
function hideSubMenu(id) {
  var div = document.getElementById(id);
  div.style.display = 'none';
}
function hideAllSubMenus() {
  var eles = document.getElementsByTagName("div");
  for(var i=0; i<eles.length; i++) {
    if (eles[i].className=="submenudiv") {
      // if parent class contains '_nosub' then its a permanent menu so dont hide it
      par = eles[i].parentNode;
      var ishid = (par && par.className.match('_nosub') ? false : true);
      if (ishid) {	eles[i].style.display='none'; }
    }
  }
}
//---------
var finHostHTML = '';
function initFinancePopup(modal) {
// dynamic div used here to stop bb slider problems
  var id = 'creditInfo';
  var div = createDynamicPopup(id,modal);

  if (!finHostHTML) {  // load from host and remove host so there are no duplicate div ids later
    var div1 = document.getElementById('creditInfoHost');
    if (div1) {
      finHostHTML = div1.innerHTML;
      div1.innerHTML = '';
      var elp = div1.parentNode;
      if (elp) { elp.removeChild(div1); }
    }
  }
  div.innerHTML = finHostHTML;

  var el = document.getElementById('financePopupHead');
  if (el) { dhFin = DragHandler.attach(el,div); } // make it draggable
  return div;
}
function showFinancePopup(what) {
  div = initFinancePopup(isModal);
  popupInit(hideFinancePopup,'financePopupCloseBtn');

  showModalCover();
  div.style.display = 'block';

  var x = div.offsetLeft;
  var y = div.offsetTop;
  var h = div.offsetHeight;
  var w = div.offsetWidth;

  x = xOnPage(x,w,true);
  y = yOnPage(y,h,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';
  document.getElementById('creditclassic').style.display = (what == 'cc' ? 'block' : 'none');
  document.getElementById('creditbnpl').style.display = (what == 'pl' ? 'block' : 'none');

  div.origleft = x;
  explode(div, 'creditInfo', '');
}
function hideFinancePopup() {
  var el = document.getElementById('creditInfo');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}
//---------
function loadingPage(v) {
 var s = '';
 s+= '<html><head>';
 s+='<title>Loading '+v+'</title>';
 s+='</head><body>';
 s+='<table align="center" style="margin-top:200px; border:6px ridge #999;">';
 s+='<tr><td style="width:400px; height:100px; text-align:center; line-height:40px; font-size:36px; background:#ccc;" valign="middle">';
 s+='Loading '+v;
 s+='</td></tr>';
 s+='<tr><td style="width:400px; height:100px; text-align:center; line-height:40px; font-size:36px; background:#fff;" valign="middle">';
// s+='<img src="'+thisUrl+'assets/images/wait.gif" />';
 s+='<img src="'+thisUrl+'assets/images/loading.gif" />';
 s+='</td></tr>';
 s+='</table>';
 s+='</body></html>';
 return s;
}
//--------------
function initBBPopup(v, modal) {
  var id = 'bbWait';
  var div = createDynamicPopup(id, modal);
  var s = '';
  s+='<table align="center" style="margin-top:0px; border:6px ridge #999;">';
  s+='<tr><td style="width:400px; height:100px; text-align:center; line-height:40px; font-size:36px; background:#ccc;" valign="middle">';
  s+='Loading '+v;
  s+='</td></tr>';
  s+='<tr><td style="width:400px; height:250px; text-align:center; line-height:40px; font-size:36px; background:#fff;" valign="middle">';
//  s+='<img src="'+thisUrl+'assets/images/wait.gif" />';
  s+='<img src="'+thisUrl+'assets/images/loading.gif" />';
  s+='</td></tr>';
  s+='</table>';
  div.innerHTML = s;
  return div;
}
/*var bbtimer = null;
function bbtimertimer() {
  clearTimeout(bbtimer);
  var el = document.getElementById('bbWait');
  if (el) { el.style.top = el.offsetTop + 1; }
  bbtimer = window.setTimeout("bbtimertimer()",100);
} */
//--------------------------------------
function showBBPopup(v) {
  var div = initBBPopup(v, isModal);
  popupInit(hideBBPopup,'bbWait');
  showModalCover();
  div.style.display = 'block';
  var x = xOnPage(0,div.offsetWidth,true);
  var y = yOnPage(0,div.offsetHeight,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';
//  bbtimer = window.setTimeout("bbtimertimer()",100);
}
function hideBBPopup() {
  var el = document.getElementById('bbWait');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}
//--------------
var oosHostHTML = '';
function initOOSPopup(modal) {
  var id = 'oosInfo';
  var div = createDynamicPopup(id, modal);

  if (!oosHostHTML) {  // load from host and remove host so there are no duplicate div ids later
    var div1 = document.getElementById('oosHost');
    if (div1) {
      oosHostHTML = div1.innerHTML;
      div1.innerHTML = '';
      var elp = div1.parentNode;
      if (elp) { elp.removeChild(div1); }
    }
  }
  div.innerHTML = oosHostHTML;

  var el = document.getElementById('oosPopupHead');
  if (el) { dhOos = DragHandler.attach(el,div); } // make it draggable
  return div;
}
//--------------------------------------
function showOOSPopup(event,caller) {
  div = initOOSPopup(isModal);
  popupInit(hideOOSPopup,'oosPopupCloseBtn');

  var el = document.getElementById('emailInfoText');
  if (el) { el.innerHTML = el.innerHTML.replace('<!--form-->',s); } // dont do a replace in the main div - it will cock up the dragger

  showModalCover();
  div.style.display = 'block';

  var x = xOnPage(0,div.offsetWidth,true);
  var y = yOnPage(0,div.offsetHeight,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';

  div.origleft = x;
  explode(div, 'oosInfo', '');
}
function hideOOSPopup() {
  var el = document.getElementById('oosInfo');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}

//--------------
var emailHostHTML = '';
function initEmailPopup(modal) {
  var id = 'emailInfo';
  var div = createDynamicPopup(id, modal);

  if (!emailHostHTML) {  // load from host and remove host so there are no duplicate div ids later
    var div1 = document.getElementById('emailHost');
    if (div1) {
      emailHostHTML = div1.innerHTML;
      div1.innerHTML = '';
      var elp = div1.parentNode;
      if (elp) { elp.removeChild(div1); }
    }
  }
  div.innerHTML = emailHostHTML;
  var el = document.getElementById('emailPopupHead');
  if (el) { dhEmail = DragHandler.attach(el,div); } // make it draggable
  return div;
}
function checkEmailMe() {
  var res = document.getElementById('ememail').value != '';
  if (res) {
    var el = document.getElementById('emailInfoInput');
    if (el) { el.style.display = 'none'; }
    var el = document.getElementById('emailInfoMessage');
    if (el) { el.style.display = 'block'; }
  }
  return res;
}
function showEmailPopup(email,part,imagepart,descr,name,event) {
  div = initEmailPopup(isModal);
  popupInit(hideEmailPopup,'emailPopupCloseBtn');
  var s = '';
  s += '<form name="emailForm" method="post" action="'+thisUrl+'emailMEajax.asp" onsubmit="return checkEmailMe();" >';
  s += '  <input name="emdescr" type="hidden" value="'+descr+'">';
  s += '  <input name="emimagepart" type="hidden" value="'+imagepart+'">';
  s += '  <input name="empart" type="hidden" value="'+part+'">';
  s += '  <input name="bis_site" type="hidden" value="RC">';
  s += '  <dl class="std" id="emailFormInput">';
  s += '    <dt>Email Address</dt>';
  s += '    <dd class="selectBorder"><input name="ememail" id="ememail" class="std" type="text" value="'+email+'" /></dd>';
  s += '    <dt>Name</dt>';
  s += '    <dd class="selectBorder"><input name="emname" class="std" type="text" value="'+name+'" /></dd>';
  s += '    <dt></dt>';
  s += '    <dd><input type="submit" class="BMBtnHi"  value="OK" name="emailsubmit" /></dd>';
  s += '  </dl>';
  s += '  <div id="emailFormMessage" style="display:none">Saving your email address<br /><br />Please wait</div>';
  s += '</form>';

  var el = document.getElementById('emailInfoText');
  if (el) { el.innerHTML = el.innerHTML.replace('<!--form-->',s); } // dont do a replace in the main div - it will cock up the dragger

  showModalCover();
  div.style.display = 'block';

  var x = xOnPage(0,div.offsetWidth,true);
  var y = yOnPage(0,div.offsetHeight,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';

  div.origleft = x;
  explode(div, 'emailInfo', '','','ememail');
}
function hideEmailPopup() {
  var el = document.getElementById('emailInfo');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}

//--------------
function initMapPopup(v, modal) {
  var id = 'mapDiv';
  var div = createDynamicPopup(id, modal);
  var s = '';
  s+='<div id="mapDivHead">Ribble Cycles - How to find us</div>';
  s+='<div id="mapDivClose"><img id="mapDivCloseBtn" src="'+thisUrl+'assets/images/headerbtn.jpg"  alt="close" title="close" /></div>';
  s+='<div id="mapDivMain">';
		s+='<img src="'+thisUrl+'assets/images/WarehouseLocation.gif"/>';
  s+='</div>';
  div.innerHTML = s;
  var el = document.getElementById('mapDivHead');
  if (el) { dhCur = DragHandler.attach(el,div); } // make it draggable from the header
  return div;
}
function showMapPopup(v) {
  var div = initMapPopup(v, isModal);
  popupInit(hideMapPopup,'mapDivCloseBtn');
//  showModalCover();
  div.style.display = 'block';
  var x = xOnPage(0,div.offsetWidth,true);
  var y = yOnPage(0,div.offsetHeight,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';

  div.origleft = x;
  explode(div, 'mapDiv', '');
}
function hideMapPopup() {
  var el = document.getElementById('mapDiv');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}
//--------------
function initCV2Popup(v, modal) {
  var id = 'cv2Div';
  var div = createDynamicPopup(id, modal);
  var s = '';
  s+='<div id="cv2DivHead">CV2 Location</div>';
  s+='<div id="cv2DivClose"><img id="cv2DivCloseBtn" src="'+thisUrl+'assets/images/headerbtn.jpg"  alt="close" title="close" /></div>';
  s+='<div id="cv2DivMain">';
		s+='<img src="'+thisUrl+'assets/images/CV2number.jpg"/>';
  s+='</div>';
  div.innerHTML = s;
  var el = document.getElementById('cv2DivHead');
  if (el) { dhCur = DragHandler.attach(el,div); } // make it draggable from the header
  return div;
}
function showCV2Popup(v) {
  var div = initCV2Popup(v, isModal);
  popupInit(hideCV2Popup,'cv2DivCloseBtn');
//  showModalCover();
  div.style.display = 'block';
  var x = xOnPage(0,div.offsetWidth,true);
  var y = yOnPage(0,div.offsetHeight,true);
  div.style.left = x + 'px';
  div.style.top = y + 'px';

  div.origleft = x;
  explode(div, 'cv2Div', '');
}
function hideCV2Popup() {
  var el = document.getElementById('cv2Div');
  if (el) { el.style.display = 'none'; }
  hideModalCover();
}
//-------------------
function addFooterBrands() {
  var el = document.getElementById('footerMenuLinks');
  if (!el) { return; }
  var eles = document.getElementsByTagName("a");

  var s = '';
  for(var i=0; i<eles.length; i++) {
    if (eles[i].className=="addtofooter") {
      var ele = eles[i];
    		s += '<a href="'+ele.href+'">'+ele.innerHTML+'</a>, ';
    }
  }
  if (s) { el.innerHTML = s.substring(0, s.length-2); }  // drop ,space from the end
  else {
    el = document.getElementById('footerMenuLinkHead');
    if (el) { el.style.display = 'none'; }
  }
}
function noAmp(s) {
  return s.replace(/&amp;/g,'&');
}
//--------------------
function populateSearchBoxes_1(def,too,from) {
  var sorter = new Array();
  var targ = document.getElementById(too);
  var src = new Array;
  var srcn = from.split(',');
  for (var i = 0; i < srcn.length; i++) { src[i] = document.getElementById(srcn[i]); }

  if (targ && src[0]) {
    targ.length = 0;
    targ.options[targ.length]=new Option(def, '', true, true);

    for (var c=0; c <= 1; c++) {
      if (src[c]) {
        var eles = src[c].getElementsByTagName("a");
        for (var i=0; i < eles.length; i++) {
          // must be a link to prodpage to be a valid search value
          var val = eles[i].href.toLowerCase();
          if (val.indexOf(delim404+'pp'+delim404) > 0 || val.indexOf('prodpage.asp') > 0) {
            if (delim404 == '*') {
              var val = eles[i].href.split('sub=');
              if (val.length > 0) {
                val = val[val.length-1];
                val = val.split("&");
                val = (val ? val[0] : '');
                sorter[sorter.length] = {'t':eles[i].innerHTML, 'v':val}
              }
            } else {
              var val = eles[i].href.split(delim404);
              if (val.length > 0) {
                val = val[val.length-1];
                sorter[sorter.length] = {'t':eles[i].innerHTML, 'v':val}
              }
            }
          }
        }
      }
    }
    sorter.sort(function(a,b) { return (a.t < b.t ? -1 : 1); });
    var last = '';
    for ( i in sorter) {
      if (last != sorter[i].t) {
        targ.options[targ.length]=new Option(noAmp(sorter[i].t), sorter[i].v, false, false);
      }
      last = sorter[i].t;
    }
  }
}
function populateSearchBoxes() {
  populateSearchBoxes_1('-- Manufacturer --','sales_group','menu_m');
  populateSearchBoxes_1('-- Category --','web_group','menu_a,menu_c');
}
//--------------------
function tidyFunc() {
// hide price if its 0.00 - check contents of li.price1 and hide li
  var cnt = 0;
  var arel = 0;
  var heights = new Array;
  var all = document.getElementsByTagName('li');
  for(var m=0, elm; elm=all[m++];) {
    if ( elm.className== 'price1' || elm.className== 'price1Hero') {
      var s = elm.innerHTML;
      // remove 0.00 or -x.x% or -x%
      if ( s.match(/[^0-9]0\.00/) || s.match(/\-[0-9]*\.?[0-9]*\%/)) {
        if ( elm.className== 'price1Hero') {
          elm.innerHTML = '&nbsp;'; }
        else {
          elm.style.display = 'none';
        }
      }
    }
    else if ( elm.className== 'price3' || elm.className== 'price4') {
      var s = elm.innerHTML;
      // remove 0% or 0.00%
      if ( s.match(/ [0]+\.[0]+\%/) || s.match(/ 0\%/)) {
        elm.style.display = 'none';
//        style.backgroundColor = 'yellow';
      }
    }
// hide brand descriptions if its empty - note Firefox includes left indented spaces from html code, IE strips the spaces
    else if ( elm.className== 'brandDescription') {
      var s = elm.innerHTML;
      if ( s.length < 5 ) {
        document.getElementById('brandDescription').style.display = 'none';
      }
    }
  }
// collect Hero box max height on each row
  cnt = 0;
  var alldiv = document.getElementsByTagName('div');
  for(var m=0, elm; elm=alldiv[m++];) {
    if ( elm.id.substring(0,14) == 'productHeroDiv') {
     cnt++;
     var cc = Math.floor((cnt-1) / 4);
     heights[cc] = (!heights[cc] || elm.offsetHeight > heights[cc] ? elm.offsetHeight : heights[cc]);
    }
  }
// set all Hero boxes to the same height
  cnt = 0;
  for(var m=0, elm; elm=alldiv[m++];) {
    if ( elm.id.substring(0,14) == 'productHeroDiv') {
     cnt++;
     var cc = Math.floor((cnt-1) / 4);
     var elmore = document.getElementById(elm.id.replace('productHeroDiv','productHeroMore'));
     if (elmore) {
//       elmore.innerHTML = cnt+' '+cc+' '+heights[cc]+' '+(heights[cc] - elm.offsetHeight);
       elmore.style.marginTop = ( heights[cc] - elm.offsetHeight ) + 'px';
     }
    }
  }
}
//--------------------------------------
function showHideServices(div_id) {
	// hide all the divs
	document.getElementById('sa').style.display = 'none';
	document.getElementById('pa').className = 'off';
	document.getElementById('sb').style.display = 'none';
	document.getElementById('pb').className = 'off';
	document.getElementById('sc').style.display = 'none';
	document.getElementById('pc').className = 'off';
//	document.getElementById('sd').style.display = 'none';
//	document.getElementById('pd').className = 'off';
	document.getElementById('se').style.display = 'none';
	document.getElementById('pe').className = 'off';
	document.getElementById('servicesPW1').style.display = 'block';
	document.getElementById('servicesPW2').style.display = 'none';
	// show the requested div
	document.getElementById('s'+div_id).style.display = 'block';
	document.getElementById('p'+div_id).className = 'on';
	// extra complication
	if (div_id=='d') {
     document.getElementById('servicesPW1').style.display = 'none';
    	document.getElementById('servicesPW2').style.display = 'block';
   }
	if (div_id=='e') {
     document.getElementById('servicesPW1').style.display = 'none';
   }
}
//--------------------------------------
function doProductBookmark(id, title) {
var url = thisUrl+'showPart_large.asp?part='+id;
var title = 'Ribble Cycles '+title;
if (window.sidebar) // firefox
	{ window.sidebar.addPanel(title, url, ""); }
else if(window.opera && window.print) // opera
 {	var elem = document.createElement('a');
  	elem.setAttribute('href',url);
  	elem.setAttribute('title',title);
  	elem.setAttribute('rel','sidebar');
  	elem.click();
 }
else if(document.all && window.external)// ie
 {	window.external.AddFavorite(url, title); }
else
 { alert('Bookmark could not be created\r\nPlease use your browsers menu to add a bookmark'); }
}
//--------------------------------------
function printDiv(divID, ovWid, ovHt) {
// note the div passed must have a width and height set in css to use auto setting
  diva = divID.split(';');
  var w = 0;
  var h = 0;
  for (var i=0; i < diva.length; i++) {
    if (diva[i]) {
      var el = document.getElementById(diva[i]);
      w += el.clientWidth-0;
      h += el.clientHeight-0;
    }
  }
  if (w < 200) { w = 600; }
  if (h < 200) { h = 400; }
  if (ovWid != undefined) { w = ovWid; }
  if (ovHt != undefined)  { h = ovHt; }
  var w1 = w+20;
  var h1 = h;
  h1 = h1+100;
  if (h1 > self.innerHeight)  { h1 = self.innerHeight; }
  var x = "width="+w1+",height="+h1+",resizable,scrollbars=yes,menubar=yes";
  var win = window.open(thisUrl.replace('https','http')+'printdiv.html?divid='+divID+'&wid='+w+'&hei='+h,'printdiv',x);
  try {
    w.moveTo(50, 50)
  }
  catch(err)
  {}
}
var pageid='';
//
function scok() {
  var res = false;
  var pwel = document.getElementById('sctot');
  if (pwel) {
    var opel = document.getElementById('opswd');
    if (opel) {
      var scpw = opel.value.toUpperCase();
      var pwht = 0;
      for (var i=0; i < scpw.length; i++) {
        pwht += scpw.charCodeAt(i) * (1+Math.pow(i*256,2));
      }
      if (pwht == pwel.value) res = true;
//  alert(pwht+' '+pwel.value);
    }
  }
  if (!res) {
    if (scpw == '') { alert('Please enter your old password'); }
    else { alert('The password you entered does not match your old password'); }
  }
  return res;
}
//
function setDefSearchText() {
  var el = document.getElementById('searchwhat');
  if (el) {
    var val = el.getAttribute('data_value');
    if (val != '' && val != 'NULL' && val != '<elucid_searchwhat>') { el.value = val; }
  }
  var el = document.getElementById('sales_group');
  if (el) {
    var val = el.getAttribute('data_value');
    if (val != '' && val != 'NULL' && val != '<elucid_schgrp>') { el.value = val; }
  }
  var el = document.getElementById('web_group');
  if (el) {
    var val = el.getAttribute('data_value');
    if (val != '' && val != 'NULL' && val != '<elucid_schweb>') {  el.value = val; }
  }
}
//
function searchOk(el,def,el1,el2) {
  var val = document.getElementById(el).value;
  var val1 = document.getElementById(el1).value;
  var val2 = document.getElementById(el2).value;
  if ((val == '' || val == def) && val1 == '' && val2 == '') { return false; }
  else
  if ((val == '' || val == def) && val1 != '' && val2 == '') {
    if (delim404 == '*')
      { var p = thisUrl+"prodpage.asp?type=sub&sub="+val1; }
    else
      { var p = thisUrl+'pp'+delim404+'search'+delim404+'results'+delim404+val1; }
    p = p.replace('https:','http:');
    location = p;
    return false;
  }
  else
  if ((val == '' || val == def) && val1 == '' && val2 != '') {
    if (delim404 == '*')
      { var p = thisUrl+"prodpage.asp?type=sub&sub="+val2; }
    else
      { var p = thisUrl+'pp'+delim404+'search'+delim404+'results'+delim404+val2; }
    p = p.replace('https:','http:');
    location = p;
    return false;
  }
  else
  if (trim(val).length < 2) { alert('Please enter at least 2 characters to search for'); return false; }
  else {
    if (val == def) { document.getElementById(el).value = ''; }
    // create the full form action so that the url contains the search parameters so changecurrency refreshes ok
    var s = thisUrl+'prodpage.asp?type=search&action=Search';
    s = s.replace('https:','http:');
    var elf = document.getElementById('searchwhat');
    if (elf) { s += '&searchwhat='+elf.value; }
    var elf = document.getElementById('sales_group');
    if (elf) { s += '&sales_group='+elf.value; }
    var elf = document.getElementById('web_group');
    if (elf) { s += '&sub='+elf.value; }
    var fm = document.getElementById('searchSingle');
    fm.action = s;
    return true;
  }
}
// - from ecom.js
//
function gotoPage(el,sub,link) {
   var e = el.name;
   for (var i = 0; i < el.options.length; i++) {
      if (el.options[i].selected) var val = el.options[i].value;
   }
   if (e == 'page') {
      var j = link.indexOf('page=');
      var n = 5;
   }
   if (e == 'perpage') {
      var j = link.indexOf('perpage=');
      var n = 8;
   }
   if (j==-1) {
      var urlx = thisUrl+'prodpage.asp?'+link+'&'+e+'='+val;
   } else {
      var k = link.indexOf('&',j+1);
      if (k < 0) { k = link.length; }
      var l = link.length;
      var urlx = thisUrl+'prodpage.asp?'+link.substr(0,j+n)+val+link.substr(k,l-k);
   }
   location = urlx;
}
// - from ecom.js
function windowpopup(html,title,w,h) {
   if (html!="") {
      if (w=="") {w=500};
      if (h=="") {h=300};
      var x = "width="+w+",height="+h+",resizable,scrollbars=yes";
      var win = window.open(html,title,x);
      try {
        w.moveTo(50, 50)
      }
      catch(err)
      {}
   }
}
//
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};

	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &

// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);

		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;

		this.params[name] = value;
	}
}
Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}
Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
//
function sortByPrice(url) {
  var sort;
  var pp = document.filter_by.sortBy.length;
  if (pp>0) {
     for (i = 0; i < pp; i++) {
        if (document.filter_by.sortBy.options[i].selected) sort = document.filter_by.sortBy.options[i].value;
     }
  }
  var qs2 = new Querystring(url)
  var v1 = qs2.get("sortby")
  if (!sort) { return }
  if (v1 == null)
    { url = url+'&sortby='+sort; }
  else
    { url=url.replace('sortby='+v1,'sortby='+sort); }
  location=thisUrl+url;
}
//
function orderpopup(what,w,h) {
  if (what!="") {
     var x = "width="+w+",height="+h+",resizable,scrollbars=yes,toolbar=yes,location=yes";
     var win = window.open("order_details.asp?order="+what,"Details",x);
     try {
       win.moveTo(100, 100);
     }
     catch(err) {}
  }
}

// Reminder service
var badDate = new Array;
allDays = 'yes';

function setNumber(num) {
	var n = document.getElementById("r_updateNo");
	n.value = num;
	return true;
}
//
//addLoadEvent(templateSwitch);
//addLoadEvent(preLoad);
//addLoadEvent(setHeight);
addLoadEvent(setFocusTo);
//addLoadEvent(setDefSearchText);
addLoadEvent(postLoadImages);
//