var backmode="normal";
var pageIsLoaded = false;
var thisUrl = "";
var delim404 = "/"
var focusTo = '';
var co_name = 'Ribble';
// -------------------- 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 screenSize() {
  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; }
  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; }
  return { 'x':wmin, 'y':hmin, 'w':sw, 'h':sh };
}

function documentSize() {
//alert(window.innerHeight+'|'+window.scrollMaxY+'|'+document.body.scrollHeight+'|'+document.body.offsetHeight);
  if (window.innerHeight != undefined && window.scrollMaxY != undefined) {// Firefox
    var y = window.innerHeight + window.scrollMaxY;
    var x = window.innerWidth + window.scrollMaxX;
  } 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) {
    var y = document.body.scrollHeight || document.documentElement.scrollHeight;
    var x = document.body.scrollWidth || document.documentElement.scrollWidth;
  }
  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';
  }
}

var globZindex = 10000;
function createDynamicPopup(id, modal, style ) {
  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);
    if (style) { div.className = style; }
    document.body.appendChild(div);
  }
  div.style.display = 'none';
  globZindex++;
  div.style.zIndex = globZindex;
  return div;
}

function integerOnly(event) {  // onkeydown event
  event = event || window.event;
  var key = (event.keyCode ? event.keyCode : event.which);
  var shift = (event.shiftKey ? event.shiftKey : event.shiftKey);
// 0..9 with no shift, 0-9 keypad, return-13, tab-9, del-46, backspace-8, left-37, right-39, home-36, end-35
//document.title = key+'x'+shift;
  if ((((key >= 48) && (key <= 57)) && shift!=1) || ((key >= 96) && (key <= 105)) || (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','');
    }
  }
}
//
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) {
//alert('a'+el.value+' '+backmode);
    if (el.value=='LOADED') {
      if (backmode == 'ppcancel') {
        location = thisUrl+'publish.asp?what=contact&page=1';
      }
      if (backmode == 'normal') {  // normal = do a forced reload of the page
        refreshMiniBasket();
      }
      if ((backmode == 'basket') || (backmode == 'lock')){
        document.body.innerHTML = '';
        location.reload(true);
      }
    }
    else { var xx = window.setTimeout('backController2()',100); }
  }
}
function backController2() {
  var el = document.getElementById('backctrl');
  if (el) {
//alert('x'+el.value+' '+backmode);
    if (el.value=='OK') { el.value = 'LOADED'; }
    else {
      if (backmode == 'ppcancel') {
        location = thisUrl+'publish.asp?what=contact&page=1';
      }
      if (backmode == 'normal') {
        refreshMiniBasket();
      }
      if ((backmode == 'basket') || (backmode == 'lock')) {
        document.body.innerHTML = '';
        location.reload(true);
      }
    }
  }
}
function doLoad() {
  pageIsLoaded = true;
  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 doUnLoad() {
//  alert('unloading '+backmode);
// just here so ff onload fires when back button is clicked
}
//
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\',\'IR\')" 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+'" maxlength="100"/></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 deTag(s) {
  while (s.indexOf('<') > -1) {
    var i = s.indexOf('<');
    var j = s.indexOf('>');
    s = s.slice(0,i) + (j > -1 ? s.slice(j+1) : '');
  }
  return s;
}
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':deTag(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':deTag(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');
//  setDefSearchText();
}
//--------------------
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+'printdiv.html?divid='+divID+'&wid='+w+'&hei='+h,'printdiv',x);
  try {
    w.moveTo(50, 50)
  }
  catch(err)
  {}
}
var pageid='';
//
function pageTo(p) {
  var s = pager_Fmt;
  s = s.replace('####',p);
  document.location = s;
}
function pagerText(r1,r2) {
  // create the visible html
  var s = '<span class="ptext">Page '+pager_Page+' of '+pager_Max+' </span>';
  if (pager_Page-0 > 1)
    { s += '<a class="prev" onclick="pageTo(\''+(pager_Page-1)+'\')" alt="Page '+(pager_Page-1)+'" title="Page '+(pager_Page-1)+'"><!--xx--></a>'; }
  if (r1 < r2) {
    for (var j=r1; j<=r2; j++) {
      if (j == pager_Page-0) {
        s += '<span alt="This Page" class="pthis">'+j+'</span>';
      } else {
        s += '<a class="page" onclick="pageTo(\''+j+'\')" alt="Page '+j+'" title="Page '+j+'">'+j+'</a>';
      }
    }
  }
  if (pager_Page-0 < pager_Max-0)
    { s += '<a class="next" onclick="pageTo(\''+(pager_Page-0+1)+'\')" alt="Page '+(pager_Page-0+1)+'" title="Page '+(pager_Page-0+1)+'"><!--xx--></a>'; }
  return s;
}

function makePager() {
  if (!window.pager_Max) { alert('pager_... vars must be set'); return; }
//  if (!pager_Fmt) return;  // no link so it must be only page

  temp = createDynamicPopup('pagerT');  // off screen div, used to find width of page list
  if (!temp) { return; }
  temp.className = 'pager';
  temp.style.display = 'block';
  var ida = makePagers.split(',');  // = the div ids to be processed
  for (var i=0; i<ida.length; i++) {
    var el = document.getElementById(ida[i]);
    if (el) {
      el.innerHTML = ' W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W';;
      var r1 = 1; var r2 = pager_Max;
      do { // cycle round shrinking the displayed range until it fits in the onscreen div
        var s = pagerText(r1,r2);
        temp.innerHTML = s;
        if (temp.offsetWidth > el.offsetWidth) {
          if (pager_Page - r1 > r2 - pager_Page) { r1++; } else { r2--; }
        }
      } while ( r2 > r1 && temp.offsetWidth > el.offsetWidth);
      try { el.innerHTML = s; } catch(err) {};
    }
    el.style.width = 'auto';
  }
  var el = temp.parentNode;
  if (el) { el.removeChild(temp); }
}
//
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 setNumber(num) {
	var n = document.getElementById("r_updateNo");
	n.value = num;
	return true;
}

function searchNiceName(el, el1) {
  var s = el.options[el.selectedIndex].innerHTML;
  if (el1) { s += ' ' + el1.options[el1.selectedIndex].innerHTML; }
  var s1 = new RegExp(eval('/\\'+delim404+'/g'));
  s = s.replace(s1,'-');
  s = s.replace(/ - /g,'-');
  s = s.replace(/ /g,'-');
  s = s.replace(/--/g,'-');
  return s;
}
function searchOk(ids,def,idb,idc) {
  // dont let the form post. I want all the data in the querystring
  var els = document.getElementById(ids);  // searchstring
  var elb = document.getElementById(idb);  // brand
  var elc = document.getElementById(idc);  // categeory

  if (els.value == def) { els.value = ''; }

  var vals = (els ? escape(trim(els.value.replace(/\:/g,''))) : '');
  var valb = (elb ? trim(elb.value) : '');
  var valc = (elc ? trim(elc.value) : '');

  if (vals == '' && valb == '' && valc == '') { return false; }

  var typ = ''; var styp = '';
  if (vals) {
    typ = 't';
    if (valb != '' && valc != '') { styp = 'a'; }
    else
    if (valb != '') { styp = 'b'; }
    else
    if (valc != '') { styp = 'c'; }
    else
    { styp = 't'; }
  }
  else
  if (valb != '' && valc != '') { typ = 'a'; }
  else
  if (valb != '') { typ = 'b'; }
  else
  if (valc != '') { typ = 'c'; }

  if (typ == 't' && vals.length < 2) {
    alert('Please enter at least 2 characters to search for'); return false;
  }

  var s = '';
  if (delim404 == '*') {
    if (typ == 'b') { s = thisUrl.replace('https:','http:')+"prodpage.asp?type=sub&sub="+valb; }
    else
    if (typ == 'c') { s = thisUrl.replace('https:','http:')+"prodpage.asp?type=sub&sub="+valc; }
    else
    if (typ == 'a') { s = thisUrl.replace('https:','http:')+"prodpage.asp?type=sub&sub="+valb+valc; }
    else {
      s = thisUrl.replace('https:','http:')+'prodpage.asp?type=search&action=Search';
      s += '&searchwhat='+vals;
      s += '&sales_group='+valb;
      s += '&sub='+valc;
    }
  } else {
    var pp = thisUrl.replace('https:','http:') + 'pp'+delim404+hometype+delim404;

    if (typ == 'b') { s = pp + searchNiceName(elb)+delim404+valb; }
    if (typ == 'c') { s = pp + searchNiceName(elc)+delim404+valc; }
    if (typ == 'a') { s = pp + searchNiceName(elb, elc)+delim404+valb+valc; }

    if (typ == 't') {
      s = thisUrl.replace('https:','http:') + 'product' + delim404 + styp + delim404;
      if (styp == 'a' || styp == 'b') { s += searchNiceName(elb) + delim404 + valb + delim404; }
      if (styp == 'a' || styp == 'c') { s += searchNiceName(elc) + delim404 + valc + delim404; }
      s += vals;
    }
  }
  if (s) { document.location = s; }
  return false;
}
// - 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 = link+'&'+e+'='+val;
   } else {
      var k = link.indexOf('&',j+1);
      if (k < 0) { k = link.length; }
      var l = link.length;
      var urlx = link.substr(0,j+n)+val+link.substr(k,l-k);
   }
   el.style.display = 'none';
   document.getElementById('pp').innerHTML = 'Please wait - Working...';
//   el.offsetParent.innerHTML = 'Working...';
   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 makeWorkArea(s) {
  // temp off screen work area. First used as a place to process the ajax matrix html
  // done so that the matrix height is known before passing it to showAlertX
  var div = createDynamicPopup('workArea');
  if (div) {
    div.style.left = '-3000px';
    div.style.display = 'block';
    div.innerHTML = s;
  }
}
function getWorkArea() {
  var div = document.getElementById('workArea');
  var res = 'workArea doesnt exist';
  if (div) {
    res = div.innerHTML;
    div.innerHTML = '';
  }
  return res;
}

var alertCount = 0;
var alertPrettyHead = false;
function doAlertXButtons(id, buttons) {
  var s = '';
  var c = 0;
  for (var key in buttons) {
    var val = buttons[key];
    c++;
    if (c==1) { s+='<div class="alertXPrompt" id="'+id+'Prompt"><table id="'+id+'PromptTable" align="center" cellspacing="0" cellpadding="0" style="width:auto; margin:0 auto; padding:0;" ><tr>'; }
    s+='<td align="center" style="padding:4px 5px 0 5px;"><a class="BMBtn" onclick="closeAlertX(\''+id+'\',\''+val+'\');" style="width:100px; margin:0px 0;" alt="" title="">'+key+'</a></div></td>';
  }
  if (c > 0) { s+='</tr></table></div>'; }
  return s;
}
function initAlertX(mode, buttons, justify, modal) {
  alertCount++;
  var id = 'alertX'+alertCount;
  var alertClass = (alertPrettyHead ? 'alertXPretty' : 'alertX');
  el = createDynamicPopup(id, modal, alertClass);
  var s = '';
  if (alertPrettyHead) {
    s+='<div id="alertXHead'+alertCount+'" class="alertXPrettyHead"></div>';
    s+='<div id="alertXPrettyClose"><img onclick="closeAlertX(\''+id+'\');" id="alertXPrettyCloseBtn" src="assets/images/popupclose.jpg"  alt="close" title="close" /></div>';
  } else {
    s+='<div id="alertXHead'+alertCount+'" class="alertXHead">';
    s+='<div id="alertXHeadText">'+mode+'</div>';
    s+='<div id="alertXClose"><img onclick="closeAlertX(\''+id+'\');" id="alertXCloseBtn" src="assets/images/headerbtn.jpg"  alt="close" title="close" /></div>';
  }
  if (mode == 'alert') {  s+='<div id="alertXIconI"></div>'; } else {  s+='<div id="alertXIconQ"></div>'; }
  s+='</div>';
  s+='<div id="alertXMessage'+alertCount+'" class="alertXMessage" style="text-align:'+justify+'">';
  s+='</div>';
  s+='<div id="'+id+'PromptContainer">';
  s+= doAlertXButtons(id, buttons);
  s+='</div>';
  if (el) {
    el.innerHTML = s;
    var el1 = document.getElementById('alertXHead'+alertCount);
    var AlertX = DragHandler.attach(el1,el); // make it draggable
  }
  alertPrettyHead = false;  // reset for next call
  return el;
}

function closeAlertX(id, val) {
  var el = document.getElementById(id);
  if (el) {
    var res = true;
    if (el.closer && el.closer != undefined) { res = el.closer(val); }
    if (res || res == undefined) {
      el.style.display = 'none';
//      hideShadowBox();
      hideModalCover();
      document.body.removeChild(el);
    }
  }
}
function showAlertX(s,mode, buttons, width, justify, closer, modal ) {
// returns the ID of the Alert box in case it is needed for manual close of button changing
  el = initAlertX(mode, buttons, justify, modal);
  if (el) {
    el.closer = closer;
    var elm = document.getElementById('alertXMessage'+alertCount);

    showModalCover();
    var twid = 0;
    if (!width) {
      temp = createDynamicPopup('alertXT');
      if (temp) {
        temp.innerHTML = s;
        temp.style.display = 'block';
        twid = temp.offsetWidth-0;  // this is the width the text wants to try to be
        temp.innerHTML = '';
      }
    }
    var ss  = screenSize();
    el.style.display = 'block';

    var elp = document.getElementById('alertX'+alertCount+'PromptTable');
    if (elp && elp.offsetWidth > twid) { twid = elp.offsetWidth; }
    if (twid == 0) { twid = 400; }
    if (twid < 200) { twid = 200; }
    if (width) { twid = width; }
    elm.innerHTML = s;

    if (twid > ss.w-wborder(el)-16) { twid = ss.w-wborder(el)-16; }
    elm.style.width = twid + 'px';
    el.style.width = twid + wborder(elm) + 'px';
    if (el.offsetHeight > ss.h-16) {
      var elh = document.getElementById('alertXHead'+alertCount);
      var maxmh = ss.h-(elp ? elp.offsetHeight : 0)-hborder(elm)-hborder(el)-16;
      if (elm.offsetHeight > maxmh) { elm.style.height = maxmh+'px'; }
//      el.style.height = ss.h-hborder(el)-16+'px';
    }

    var x = el.offsetLeft;
    var y = el.offsetTop;
    var w = el.offsetWidth;
    var h = el.offsetHeight;
    x = xOnPage(x,w,true);
    y = yOnPage(y,h,true);

    el.style.left = x + 'px';
    el.style.top  = y + 'px';
    if (!modal) { showShadowBox(el); }
  }
  return 'alertX'+alertCount;
}

// close func must have a single param which will contain the value of the button clicked or null if the X is clicked
// width will force the width of the box if set. '' or 0 will auto set the width
// header will override the default box header
// buttons is a json array like { 'visible text':'return value', 'Cancel':'cancel', 'Ok':'ok' }
// all alert boxes are independent so to close one manually you will need to save alertX_Id() after creating one

// an example alertX closing function
function alertCloseTest(val) {
  if (val == 'ok') { alert('ok clicked - return is false so it wont close'); return false; }
  if (val == 'cancel') { alert('cancel clicked - will close');  }
  if (val == undefined) { alert('you clicked the close icon');  }
}

function alertX_SetButtons(id, buttons) {
// allows the buttons to be changed dynamically  eg { 'Close':'close' }
// save the result of alertX() so it can be passed here as id
  var el = document.getElementById(id+'PromptContainer');
  if (el) {
    var s = doAlertXButtons(id, buttons);
    el.innerHTML = s;
  }
}
function alertX(s,closeFunc, width, header) {
  if (!s || s == undefined) { s = ''; }
  s = s + '';
//  s = s.replace(/\n/g,'<br>');
//  s = s.replace(/#39/g,'');
  if (!header) { header = co_name+' Alert'; }
  return showAlertX(s,header,{ 'OK':'ok' }, width, 'center', closeFunc, isModal);
}
function alertX_BR(s,closeFunc, width, header) {
  if (!s || s == undefined) { s = ''; }
  s = s.replace(/\n/g,'<br>');
  return showAlertX(s,header,{ 'OK':'ok' }, width, 'left', closeFunc, isModal);
}
function showX(s,closeFunc, width, header) {
  if (!s || s == undefined) { s = ''; }
  s = s + '';
  if (!header) { header = co_name+' Alert'; }
  return showAlertX(s,header,{}, width, 'center', closeFunc, isModal);
}
function confirmX(s, closeFunc, width, header) {
//  s = s.replace(/\n/g,'<br>');
//  s = s.replace(/#39/g,'''');
  if (!header) { header = co_name+' Confirm'; }
  return showAlertX(s,header,{ 'OK':'ok', 'Cancel':'cancel' }, width, 'left', closeFunc, isModal);
}
function promptX(s, closeFunc, width, buttons, header) {
//  s = s.replace(/\n/g,'<br>');
  s = s.replace(/#39/g,"'");
  if (!header) { header = co_name+' Confirm'; }
  return showAlertX(s,header,buttons, width, 'left', closeFunc, isModal);
}
//
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); }
  document.filter_by.sortBy.style.display = 'none';
  document.filter_by.innerHTML = 'Sorting...';
  location=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(preLoad);
//addLoadEvent(setHeight);
addLoadEvent(setFocusTo);
addLoadEvent(postLoadImages);
//
