// these can be overridden in custom.js or homehtml or templates
var co_name = 'Dev Site';
var showPagerArrows = true;
var backmode="normal";
var thisUrl = "";
var delim404 = "/"
var focusTo = '';
var pageIsLoaded = false;
var animate = true;
//
function isIE6() {
  var av = navigator.appVersion.toLowerCase();
  var i = av.indexOf('msie 6');
  return (i < 50 && i > -1);
}
function isIE() {
  var av = navigator.appVersion.toLowerCase();
  var i = av.indexOf('msie');
  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(ele) {
  if (isIE6()) {
    var eles = document.all.tags("SELECT");
    for(var m = 0; m < eles.length; ++m) {
      if (eles[m] != ele) {  eles[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 (window.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; }
  if (ele && w > sw) { ele.style.width = sw-10+'px'; }
		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; }
//alert(hmin+'|'+sh);
  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; }
//alert(ele.offsetHeight+' '+h+' '+sh);
  if (ele && h > sh) { ele.style.height = sh-6+'px'; }
//alert(y);
 	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' || (popupInDiv(e,pd,inpd))))) {
      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, testbool) {
  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 testbool;
			}
		}
		else if (e && e.srcElement) {
			var t = e.srcElement;
			while (t && t.parentElement != null) {
//alert(t.ID+' '+divID+' '+testbool);
				if (t.id==divID) {	return testbool; }
				t = t.parentElement;
			}
		}
		else if (e && e.originalTarget) {
			var t = e.originalTarget;

   try { if (t.id) {} } // will get error here if firefox and input box is clicked on mar 2010
   catch(errr) { /*alert('err: '+errr);*/ return false;}

   try {
   		while (t && (t.parentNode != null) && (t.parentNode != undefined) && (t.attributes)) {
   				if (t.id==divID) { return testbool; }
 	  			t = t.parentNode;
 	  	}
  	}
   catch(err)
   { alert('error: '+err.description);}
		}
		return !testbool;
}
// 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 : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
  document.cookie = s;
}
//--------------------------------------
function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
     ( ( path ) ? ";path=" + path : "") +
     ( ( domain ) ? ";domain=" + domain : "" ) +
     ";expires=Thu, 01-Jan-1990 00:00:01 GMT";
}
//----
function cssStyle(el, property) {
  var elo = el;
  if (typeof(el) == 'string') { el = document.getElementById(el); }
  if (!el) { alert('cssStyle error: element '+elo+' property '+property+' does not exist'); return null; }
  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); }
      }
      try {
      res = getComputedStyle(el,'').getPropertyValue(prop);
      } catch(err) {}
    }
  }
  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, mode ) {
  var offs = { 't':shadowOffset, 'l':shadowOffset, 'w':0, 'h':0 }
  if (mode == 'center') { offs = { 't':-3, 'l':-3, 'w':6, 'h':6 } }

  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) + ''; }
    var fixed = cssStyle(el,'position');
    if (fixed = 'fixed') {
      hmin = 0; wmin = 0;
    } else {
      var hmin = (document.documentElement.scrollTop ? document.documentElement.scrollTop : (window.pageYOffset ? window.pageYOffset : 0));
      if (typeof(hmin) != 'number' || hmin < 0) { hmin = 0; }
      var wmin = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : (window.pageXOffset ? window.pageXOffset : 0));
      if (typeof(wmin) != 'number' || wmin < 0) { wmin = 0; }
    }
    div.style.top = (el.offsetTop+offs.t+hmin) + 'px';
    div.style.left = (el.offsetLeft+offs.l+wmin) + 'px';
    div.style.height = (el.offsetHeight + offs.h) + 'px';
    div.style.width = (el.offsetWidth + offs.w) + 'px';
    div.style.display = 'block';
    shadowBox = div;      // keep a global reference 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 autoSetFrameSize(el) {  // el should be 'this' in the onload of the iframe
  var c=(el.contentWindow || el.contentDocument);
  if (c.document)c=c.document;
  var h = c.body.scrollHeight || c.documentElement.scrollHeight;
  el.style.height = h + 'px';
}

var coverCount = 0;
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';
    coverCount++;
  }
}

function hideModalCover( ) {
  var div = document.getElementById('modalCover');
  if (div) {
    coverCount--;
    if (coverCount == 0) { div.style.display = 'none'; }
  }
}
var globZindex = 7000;
function createDynamicPopup(id, modal, style, parent ) {
  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; }
    if (!parent || parent == undefined) { parent = document.body }
    parent.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 fullPath(path) {
  return (path.match('://') ? path : thisUrl+path);
}
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 createImg(id, owner) {
  var img = document.createElement('img');
  img.setAttribute('id', id);
  img.setAttribute('name', id);
  img.style.display = 'none';
  img.style.zIndex = 1;
  owner.appendChild(img);
  return img;
}
function c_imageTrans(div_id,imgclass,path,imagedefs,options) {

  c_imageTrans.prototype.transTimer = function() {
    try {
      var done = false;
      if (this.images[this.image].width > 0) { //ie the image has loaded
        this.imgs[1].setAttribute('imgno',this.image);
        this.imgs[1].alt = this.imagealts[this.image];
        this.imgs[1].title = this.imagealts[this.image];

        if (this.effect == 'swap') {
          this.imgs[0].style.display = 'none';
          this.imgs[0].src = fullPath(this.path)+this.imagenames[this.image];
          this.imgs[0].style.display = 'block';
          done = true;
        }
        else if (this.effect == 'fadein') {
          if (this.step == 0) {
            this.imgs[1].src = fullPath(this.path)+this.imagenames[this.image];
            this.speed = 40;
            this.pos = 0;
            this.imgs[1].style.marginTop = '-'+this.imgs[0].offsetHeight+'px';
            this.imgs[1].style.marginLeft = '0px';
            this.imgs[1].style.opacity = this.pos / 100;
            this.imgs[1].style.filter = "alpha(opacity=" + Math.round(this.pos) + ")";
            this.imgs[1].style.display = 'block';
          }
          this.step++;
          this.pos = this.pos + 2;
          this.imgs[1].style.opacity = this.pos / 100;
          this.imgs[1].style.filter = "alpha(opacity=" + Math.round(this.pos) + ")";
          if (this.pos >= 100) {
            done = true;
          }
        }
        else if (this.effect == 'slideleft') {
          if (this.step == 0) {
            this.imgs[1].src = fullPath(this.path)+this.imagenames[this.image];
            this.speed = 40;
            this.limit = 0;
            this.pos = this.imgs[0].offsetWidth;
            this.imgs[1].style.marginTop = '-'+this.imgs[0].offsetHeight+'px';
            this.imgs[1].style.marginLeft = this.pos+'px';
            this.imgs[1].style.display = 'block';
          }
          this.step++;
          this.pos = this.pos - 1;
          this.imgs[1].style.marginLeft = this.pos+'px';
          if (this.pos <= this.limit) {
            done = true;
          }
        }
        else if (this.effect == 'slideright') {
          if (this.step == 0) {
            this.imgs[1].src = fullPath(this.path)+this.imagenames[this.image];
            this.speed = 40;
            this.limit = 0;
            this.pos = -this.imgs[0].offsetWidth;
            this.imgs[1].style.marginTop = '-'+this.imgs[0].offsetHeight+'px';
            this.imgs[1].style.marginLeft = this.pos+'px';
            this.imgs[1].style.display = 'block';
          }
          this.step++;
          this.pos = this.pos + 1;
          this.imgs[1].style.marginLeft = this.pos+'px';
          if (this.pos >= this.limit) {
            done = true;
          }
        }
        else if (this.effect == 'stretchright') {
          if (this.step == 0) {
            this.imgs[1].src = fullPath(this.path)+this.imagenames[this.image];
            this.speed = 40;
            this.limit = this.imgs[0].offsetWidth;;
            this.pos = 0;
            this.imgs[1].style.marginTop = '-'+this.imgs[0].offsetHeight+'px';
            this.imgs[1].style.marginLeft = '0px';
            this.imgs[1].style.width = this.pos+'px';
            this.imgs[1].style.display = 'block';
          }
          this.step++;
          this.pos = this.pos + 1;
          this.imgs[1].style.width = this.pos+'px';

          if (this.imgs[1].offsetWidth >= this.limit) {
            done = true;
          }
        }
        if (done) {
            this.imgs[0].src = fullPath(this.path)+this.imagenames[this.image];
            this.imgs[0].style.display = 'block';
            this.imgs[1].style.display = 'none';
            this.imgs[1].style.width = cssStyle(this.imgs[0],'width')+'px';
            this.imgs[0].setAttribute('imgno',this.image);
            this.imgs[0].alt = this.imagealts[this.image];
            this.imgs[0].title = this.imagealts[this.image];
        }
      }
      else
      {
        done = true;  // image not ready so start timer for next transition
      }
    }
    catch(err)
    { alert(err.description); return;}

    if (this.aborted) { return; }

    if (done)
     { this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), this.interval ); }
    else
     { this.timer = setTimeout( ( function ( obj ) { return function () { obj.transTimer( ); }; } )( this ), this.speed ); }
  }

  c_imageTrans.prototype.trans = function() {
    this.timer = setTimeout( ( function ( obj ) { return function () { obj.transTimer( ); }; } )( this ), 10 );

  }

  c_imageTrans.prototype.onTimer = function() {
    try {
      if (this.aborted) { return; }

      if (pageIsLoaded) {
        if (!this.loaded) { // time to load all the images
          for (var i=0; i < this.imagenames.length; i++ ) {
            this.images[i] = new Image();
            this.images[i].src = fullPath(this.path)+this.imagenames[i];
          }
          this.loaded = true;
          this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), this.interval );
        }
        else
        {
          this.image++; if (this.image >= this.images.length) { this.image = 0; }
          this.effectno++; if (this.effectno >= this.effects.length) { this.effectno = 0; }
          this.effect = this.effects[this.effectno];
          this.step = 0;
          if (this.aborted) { return; }
          this.trans();
        }
      }
      else
      {
        this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), this.initinterval );
      }
    }
    catch(err)
    { alert(err.description); return;}
  }

  c_imageTrans.prototype.abort0 = function() {
    var i = this.imgs[0].getAttribute('imgno');
    if (this.imagelinks[i]) {
      this.aborted = true;
      this.imgs[1].style.display = 'none';
      window.location = this.imagelinks[i];
    }
//    alert(this.imagelinks[i]+'xxx0');
  }

  c_imageTrans.prototype.abort1 = function() {
    var i = this.imgs[1].getAttribute('imgno');
    if (this.imagelinks[i]) {
      this.aborted = true;
      this.imgs[1].style.display = 'none';
      window.location = this.imagelinks[i];
    }
//    alert(this.imagelinks[i]+'xxx1');
  }

  c_imageTrans.prototype.stop = function() {
    this.aborted = true;
    clearTimeout(this.timer);
    this.step = 0;
    this.imgs[1].style.display = 'none';
  }

  c_imageTrans.prototype.restart = function() {
    clearTimeout(this.timer);
    this.step = 0;
    this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), this.interval );
    this.aborted = false;
  }

  c_imageTrans.prototype.init = function() {
    var div = document.getElementById(div_id);
    if (div) {
      div.style.overflow = 'hidden';
      this.imgs[0] = createImg(div_id+'img1',div);
      this.imgs[1] = createImg(div_id+'img2',div);
      this.imgs[0].className = this.imgclass;
      this.imgs[1].className = this.imgclass;
      this.imgs[0].src = fullPath(this.path)+this.imagenames[0];
      this.imgs[0].style.display = 'block';
      this.imgs[0].onclick = ( function ( obj ) { return function () { obj.abort0( ); }; } )( this )
      this.imgs[1].onclick = ( function ( obj ) { return function () { obj.abort1( ); }; } )( this )
      this.imgs[0].oncontextmenu = ( function ( obj ) { return function () { obj.stop( ); }; } )( this )
      this.imgs[1].oncontextmenu = ( function ( obj ) { return function () { obj.stop( ); }; } )( this )
      this.imgs[0].alt = this.imagealts[0];
      this.imgs[0].title = this.imagealts[0];
      this.imgs[0].setAttribute('imgno','0');
    }
  }

  checkAnimate();
  var def_effects = new Array ( 'fadein', 'swap', 'slideleft', 'slideright', 'stretchright' );
  this.aborted = false;
  this.imgs = new Array;  // two html img elements for the switch
  this.div_id = div_id;
  this.images = new Array;  // actual images
  this.imagenames = new Array;
  this.imagealts = new Array;
  this.imagelinks = new Array;
  if (typeof(imagedefs) == 'string') {
    var defs = imagedefs.split(',');  // image name|link|alt comma sep list
    for (var i =0; i < defs.length; i++) {
      var defsa = defs[i].split('|');
      this.imagenames[this.imagenames.length] = defsa[0];
      this.imagelinks[this.imagelinks.length] = defsa[1];
      this.imagealts[this.imagealts.length] = defsa[2];
    }
  } else { // its an array of json arrays
    for (var i =0; i < imagedefs.length; i++) {
      this.imagenames[this.imagenames.length] = imagedefs[i].img;
      this.imagelinks[this.imagelinks.length] = imagedefs[i].link;
      this.imagealts[this.imagealts.length] = imagedefs[i].alt;
    }
  }
  this.imgclass = imgclass;
  this.path = path;
  this.effectno = -1;
  this.init();
  this.loaded = false;
  this.img = 0;
  this.image = 0;
  this.initinterval = 100; // timer interval for loaded check

  this.speed = 100;  // timer interval for transition
  this.interval = 1000; // timer interval between transitions
  this.effects = def_effects;

  if (typeof(options) == 'string') {
    if (options != 'random') { this.effects = options.split(','); }
  } else {
    if (options.effect) { if (options.effect != 'random') { this.effects = options.effect.split(','); } }
    if (options.speed) { this.speed = options.speed-0; }
    if (options.interval) { this.interval = options.interval-0; }
  }
  if (!animate) { return; }
  this.timer = setTimeout( ( function ( obj ) { return function () { obj.onTimer( ); }; } )( this ), this.initinterval );
}
function imageTrans(div_id,path,imagenames,imgclass,alt,effect) {
// imagenames can be a string with 'jpg|link|alt,jpg|link|alt' or a json array [ { 'img':'', 'link':'', 'alt':'' },... ]
  var it = new c_imageTrans(div_id,path,imagenames,imgclass,alt,effect);
  return it;
}
//
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
 try {
  	var res = str.replace(new RegExp("^[" + chars + "]+", "g"), "");
 } catch(err) {};
	return res;
}

function rtrim(str, chars) {
	chars = chars || "\\s";
 try {
  	var res = str.replace(new RegExp("[" + chars + "]+$", "g"), "");
 } catch(err) {};
	return res;
}
//
function preLoad(imgs) {
// image path must be relative to root. Comma seperate multiple values
  if (document.images) {
    var imga = imgs.split(',');
    for (var i=0; i < imga.length; i++) {
      var rslt = new Image();
      rslt.src = fullPath(imga[i]);
    }
  }
}
// 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','');
      Coll[m].oncontextmenu= function() { return false; }
    }
    // data-currency-src means there are currency dependent versions of this image
    else if (Coll[m].getAttribute('data-currency-src')) {
      var s = Coll[m].getAttribute('data-currency-src');
      s = s.replace('.jpg',currency_code+'.jpg');
      s = s.replace('.gif',currency_code+'.gif');
      s = s.replace('.png',currency_code+'.png');
      Coll[m].src = s;
      Coll[m].setAttribute('data-currency-src','');
    }
    else if (Coll[m].getAttribute('data-gbponly-src')) {
      var s = Coll[m].getAttribute('data-gbponly-src');
      if (window.currency_code && currency_code != 'GBP') {
        Coll[m].style.display = 'none'; // not gbp = hide it
      } else {
        s = s.replace('.jpg',currency_code+'.jpg');
        s = s.replace('.gif',currency_code+'.gif');
        s = s.replace('.png',currency_code+'.png');
        Coll[m].src = s;
        Coll[m].setAttribute('data-gbponly-src','');
      }
    }
  }
  if (window.resetMenuHeight) { resetMenuHeight(); }
}
/*function addLoadEvent(func, first) {  // set first to true to add this event at the front of the queue
  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 pageLoaded() { pageIsLoaded = true; }
addLoadEvent(pageLoaded);
*/
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 backController() {
//alert(backmode);
  var el = document.getElementById('backctrl');
  if (el) {
    if (el.value=='LOADED') {
      if (backmode == 'normal') {
        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) {
    if (el.value=='OK') { el.value = 'LOADED'; }
    else {
      if (backmode == 'normal') {
        refreshMiniBasket();
      }
      if ((backmode == 'basket') || (backmode == 'lock')) {
        document.body.innerHTML = '';
        location.reload(true);
      }
    }
  }
}
function doLoad() {
  pageIsLoaded = true;
  backController();
  checkAnimate();

  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() {
// just here so ff onload fires when back button is clicked
}
//
function checkAnimate() {
// add ani=false to the querystring to stop animations
  var s = window.location.href.toLowerCase();
  if (s.indexOf('ani=') > -1) {
    var ani = (s.indexOf('ani=false') > -1 ? 'F' : 'T');
    setCookie('animate',ani);
    animate = (ani != 'F');
  } else {
    var ani = getCookie('anmimate');
    if (ani == 'F') { animate = false; }
  }
}
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', 'id1;id2;over|id1;out|id1');" >
// id can be 'large','medium' etc of a full img file path
// hideel is a ; delim list of ids to hide eg. the id of a box with a zoom prompt in it
// stopclick is a ; delim list of ids to remove the onclcik handler from.
// stopclick can be used to switch off mouseover and mouseout by adding 'over|' of out| before the id
// restart = true will re-install the onerror handler - use this if the image src may be changed again
  var safe = el.onerror;
  el.onerror = null;  // stop stack overflow if err image doesnt exist
  if (id == 'large' || id == 'zoom' || id == 'medium' || id == 'thumb' || id == 'small' || id == 'smallhero') {
    id = thisUrl+'products/images/coming_soon_'+id+'.gif';
  }
  if (id == 'swatch' ) { id = thisUrl+'products/images/no-swatch.jpg'; }
  el.src=id;
//hideel = '';
  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]) {
        var typ = '';
        var nam = ar[i].replace(' ','');
        if (nam.match(/over\|/i)) { typ = 'min'; nam = nam.substr(5); }
        if (nam.match(/out\|/i)) { typ = 'mout'; nam = nam.substr(4); }
        ely = document.getElementById(nam);
        if (ely) {
          if (typ == '') { ely.onclick = null; ely.style.cursor = 'default'; }
          if (typ == 'min') { ely.onmouseover = null; }
          if (typ == 'mout') { ely.onmouseout = null; }
        }
      }
    }
  }
  if (restart) {
    el.onerror = safe;
  }
}
// next/prev pager for prodpage
//var pager_Page = '<elucid_head_page_no>';
//var pager_Max  = '<elucid_head_page_max>';
//var pager_Fmt  = '<elucid_head_page_goto>';

function pageTo(p) {
  var s = pager_Fmt;
  s = s.replace('####',p);
  document.location = s;
}
function pagerHeadExample() {
//  var s = '<span class="ptext">Page '+pager_Page+' of '+pager_Max+' </span>';
  var s = '<span class="ptext">Page </span>';
  showPagerArrows = true;
  return s;
}
function pagerText(r1,r2) {
  // create the visible html
  // custom.js should contain a function called pagerHead() which returns the text to show infront of the < 1,2,3,4 > section
  var s = '';
  if (window.pagerHead) { s += pagerHead(); }
  if (pager_Page > 1 && showPagerArrows) {
    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) {
        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 < pager_Max && showPagerArrows) {
    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.innerHTML = s;
  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) {
      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 noNull(s) {
  if (s == null) { s = ''; }
  return s;
}

function printbigpic() {
  printDiv(bigpicName+'Img');c
}

function searchFocus(el,val) {
  var div = document.getElementById(el.id);
  if (div) {
    if (div.value == val) { div.value = ''; }
  }
}

var videoCount = 0;
function showVideo(name, title, wid, ht) {
  name = (name.indexOf(':') > -1 ? name : thisUrl+'products/video/'+name+'.wmv');
  wid = (wid ? wid : 320);
  ht = (ht ? ht : 290);
  var s = '';
  videoCount++;
  s+= '<object id="MediaPlayer'+videoCount+'" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading..." width='+wid+' height='+ht+' type="application/x-oleobject" >';
  s+= '<param name="FileName" value="'+name+'">';
  s+= '<param name="AnimationatStart" value="true">';
  s+= '<param name="TransparentatStart" value="true">';
  s+= '<param name="AutoStart" value="true">';
  s+= '<param name="AutoSize" value="false">';
//  s+= '<param name="ShowTracker" value="true">';
//  s+= '<param name="ShowGotoBar" value="false">';
//  s+= '<param name="ShowDisplay" value="false">';
//  s+= '<param name="ShowStatusBar" value="false">';
  s+= '<param name="UIMode" value="mini">';
//  s+= '<param name="ShowControls" value="true">';
  s+= '<param name="Volume" value="-450">';
  s+= '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+name+'" name="MediaPlayer'+videoCount+'"  width='+wid+' height='+ht+'  autostart=1 showcontrols=1 volume=-450>';
  s+= '</object>';
  showX(s,'',wid+80,title);
}

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.focus();
    w.moveTo(50, 50)
  }
  catch(err)
  {}
}

function stopRightClick() {
  function clickIE() {if (document.all) {return false;}}
  function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}}
  if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
  else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
  document.oncontextmenu=new Function("return false")
}

function setMessage(s) {
// use for top of the page messages
  var el = document.getElementById('headMessage');
  if (el) { el.innerHTML = s; }
}

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+='<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>'; }
  return s;
}
function initAlertX(header, 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">'+header+'</div>';
    s+='</div>';
    s+='<div id="alertXClose"><img onclick="closeAlertX(\''+id+'\');" id="alertXCloseBtn" src="assets/images/headerbtn.jpg"  alt="close" title="close" /></div>';
    if (header.match(/alert/i)) { s+='<div id="alertXIconI"></div>'; }
    if (header.match(/confirm/i)) { s+='<div id="alertXIconQ"></div>'; }
  }
  if (alertPrettyHead) {
    s+='<div class="alertXPrettyMessage" id="alertXMessage'+alertCount+'" class="alertXMessage" style="text-align:'+justify+'"></div>';
  } else {
    s+='<div class="alertXMessage" id="alertXMessage'+alertCount+'" class="alertXMessage" style="text-align:'+justify+'"></div>';
  }
  s+='';
  var c = 0; for (var key in buttons) { c++; }
  if (alertPrettyHead && c > 0) {
    s+='<div class="alertXPrettyPrompt" id="'+id+'Prompt"><div id="'+id+'PromptContainer">';
  } else if (c > 0) {
    s+='<div class="alertXPrompt" id="'+id+'Prompt"><div id="'+id+'PromptContainer">';
  }
  s+= doAlertXButtons(id, buttons);
  s+='</div></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 closeThisAlertX(thisel, val) {
  // will find the AlertX holding the thisel element and close it with 'val' as the closeresult
  var el = thisel;
  while((el=el.offsetParent) != null) {
    if (el.id.substr(0,6) == 'alertX' && el.id.substr(0,13) != 'alertXMessage') {
      closeAlertX(el.id,val);
      return true;
    }
  }
  return false;
}

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);
    }
  }
}
var alertData = new Array();
function showAlertX(s, header, 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(header, buttons, justify, modal);
  if (el) {
    el.closer = closer;
    var elm = document.getElementById('alertXMessage'+alertCount);

    // was it a div id passed rather than text
    if (s.length < 30 && s.indexOf(' ') == -1) {
      var eldata = document.getElementById(s);
      if (eldata) {
        // the first call will put contents into alertData array and kill the original
        // all future calls will use the alertData data
        // this makes sure that if the passed div id contains an input form, there arent duplicates of all the field ids.
        if (alertData[s]) {
          s = alertData[s];
        } else {
          alertData[s] = eldata.innerHTML;
          s = alertData[s];
          eldata.innerHTML = '';
        }
      }
    }

    showModalCover();
    var twid = 0;
    if (!width) {
      temp = createDynamicPopup('alertXT');
      if (temp) {
        s = s.replace(/#39/g,'\'');  // restore #39's to quotes before browser sees it
        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 undefined 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, align) {
  if (!s || s == undefined) { s = ''; }
  s = s + '';
//  s = s.replace(/\n/g,'<br>');
//  s = s.replace(/#39/g,'\'');
  if (!header) { header = co_name+' Alert'; }
  if (!align) { align = 'center'; }
  return showAlertX(s,header,{ 'OK':'ok' }, width, align, closeFunc, isModal);
}
function alertX_BR(s,closeFunc, width, header) {
  if (!s || s == undefined) { s = ''; }
  s = s.replace(/\n/g,'<br>');
  if (!header) { header = 'Alert'; }
  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 = ''; }
  return showAlertX(s,header,buttons, width, 'left', closeFunc, isModal);
}

function makeTable(fmt, s, tclass) {
// fmt is an array of columns defined as ['width','th justify','td justify','head text']
// justify is C, L or R
  var justy = new Array; justy['L']='Left'; justy['C'] = 'center'; justy['R'] = 'right';
//  if (tclass) { tclass = ' class="'+tclass+'"'; } else { tclass='';}
  if (tclass) {} else {tclass='';}

  var dohead = false;  // set to true if text supplied in the fmt array
  var totw = 0;
  var cols = fmt.length;
  for (var i=0; i<cols; i++) {
    var col = fmt[i];
    if (col[3]) { dohead = true; }
    totw += col[0]-0;
  }

  res = '<table cellspacing="0" cellpadding="4" border="0" width="'+totw+'" '+tclass+'>';
  if (dohead) {
    res += '<tr>';
    for (var i=0; i<fmt.length; i++) {
      var col = fmt[i];
      var val = (col[3] ? col[3] : '&nbsp;');
      res += '<th width="'+col[0]+'" align="'+justy[col[1]]+'">'+val+'</th>';
    }
    res += '</tr>';
  }

  var a = s.split('|');
  var col = 0;
  for (var i=0; i<a.length-1; i++) {
    col++;
    if (col == 1) { res += '<tr>'; }
    var val = (a[i] ? a[i] : '&nbsp;');
    res += '<td width="'+fmt[col-1][0]+'" align="'+justy[fmt[col-1][2]]+'">'+val+'</td>';
    if (col == cols) { res += '</tr>'; col = 0; }
  }

  res += '</table>';
  return res;
}

//--------------------------------------
function initBasketPopup(modal) {
  var id = 'basketPopup';
  var div = createDynamicPopup(id,modal);

  var s = '';
  if (window.vouc_data && vouc_data.length > 0) {

    var el = document.getElementById('basketPopupLine_tmp');
    if (el) {
      var tmp = el.innerHTML;
      // remove <!-- and --> from around the template
      tmp = tmp.replace('<!--',''); //substring(4,tmp.length-3);
      tmp = tmp.replace('-->','');
      for (var i=0; i<vouc_data.length; i++) {
        var tmp1 = '';
        tmp1+=tmp;
        tmp1 = tmp1.replace(/<xx_part>/g, vouc_data[i].part);
        tmp1 = tmp1.replace(/<xx_major>/g, vouc_data[i].major);
        tmp1 = tmp1.replace(/<xx_descr>/g, vouc_data[i].descr);
        tmp1 = tmp1.replace(/<xx_qty>/g, vouc_data[i].qty);
        tmp1 = tmp1.replace(/<xx_price>/g, vouc_data_curr+vouc_data[i].total);
//alert(tmp1);
        s+= tmp1;
      }
    }
  }
  var t = div.innerHTML;
  t = t.replace(/<!--rows_go_here-->/i,s);
  div.innerHTML = t;
//alert(div.innerHTML);
  return div;
}
var c = 0;
//--------------------------------------
function onOpenBasketPopupTimer() {
  showBasketPopupReal(null, openBasketEle)
}
function showBasketPopup(event, ele) {
  clearTimeout(openBasketPopupTimer);
  clearTimeout(closeBasketPopupTimer);
  openBasketEle = ele;
  openBasketPopupTimer = setTimeout( 'onOpenBasketPopupTimer()', 300 );
}
function showBasketPopupReal(event, ele) {
  clearTimeout(openBasketPopupTimer);
  clearTimeout(closeBasketPopupTimer);
  if (basketPopupAborted) { return }

  var div = document.getElementById('basketPopup');
  if (div && div.style.display == 'block') { return } // stop repeated firing of mouseover being a problem

  var div = initBasketPopup();
  if (div) {
    c++;
    popupInit(hideBasketPopupReal,'poo');

    var els = document.getElementById('basketPopupScroll');
    els.style.height = 'auto';
    els.style.overflow = 'visible';

    div.style.display='block';
    var xy = getBounds(ele);
    y = yOnPage(xy.y+xy.h,0);
    x = xOnPage(xy.x+xy.w-div.offsetWidth,div.offsetWidth)+10;

    var exy = getBounds(div);
    var sxy = screenSize();
    if (y > sxy.y + sxy.h - exy.h) {
      els.style.overflow = 'auto';
      var h = sxy.y + sxy.h - y - 35;
      if (h < 20) { h = 20; }
      els.style.height = h + 'px';
    }

    div.style.top = y + 'px';
    div.style.left = x + 'px';
    hideSelects();

    div.onmouseover = new Function("keepBasketPopup();");
    div.onmouseout = new Function("hideBasketPopup();");
  }
}
//--------------------------------------
var openBasketPopupTimer = null;
var openBasketEle = null;
var closeBasketPopupTimer = null;
var basketPopupAborted = false;
function hideBasketPopupReal(ss) {
  var id = document.getElementById('basketPopup');
  if (id) { id.style.display='none'; showSelects(); }

}
function onCloseBasketPopupTimer() {
  clearTimeout(closeBasketPopupTimer);
  closeBasketPopupTimer = null;
  popupClose('','');
}
function hideBasketPopup(e) {
//  if (e == undefined) var e = window.event; // make sure IE has the event in e
//alert(popupInDiv(e,'miniBasketMain',true)+'xx'+popupInDiv(e,'basketPopup',true)+'yy'+(!popupInDiv(e,'miniBasketMain',true) && !popupInDiv(e,'basketPopup',true)));
//  if (!popupInDiv(e,'miniBasketMain',true) && !popupInDiv(e,'basketPopup',true)) {
    clearTimeout(openBasketPopupTimer);
    closeBasketPopupTimer = setTimeout( 'onCloseBasketPopupTimer()', 500 );
//  }
}
function keepBasketPopup() {
  clearTimeout(closeBasketPopupTimer);
}
function hideBasketPopup_CO(event,miniBasketEle) {
  // called when mini basket is clicked to go to checkout
  basketPopupAborted = true;
  popupClose('','');
  if (miniBasketEle) {
    miniBasketEle.className = miniBasketEle.className + ' clicked';
  }
}

// call stopTypeAhead() / starttypeAhead() to switch this function off and on

// local vars
var searchBox = null;  // pointer to the searchbox element
var searchhttp=null;
var searchedValue = '';
var badValue = '';
var typeAheadLive=true;

function stopTypeAhead() {
  typeAheadLive = false;
  if (typeAheadPopup) { typeAheadPopup.style.display = 'none'; }
}

function startTypeAhead() {
  typeAheadLive = true;
}

//--------------------------------------
function showSuggestions(a) {
//alert(a);
  var id = 'suggestionBox';
  var div = document.getElementById(id);
  if (!div) {
    div = createDynamicPopup(id,false);
 			div.innerHTML+='<div id="sresults" class="ta" name="suggestionresults"></div>';
  }
  popupInit(hideSuggestionsCore,'!suggestionBox');

  // put the shadow png around the box
  a = '<div id="suggestionT"><!--xx--></div><div id="suggestionM">' + a + '</div><div id="suggestionB"><!--xx--></div>';

  el = document.getElementById('sresults');
  el.innerHTML = a;

  div.style.display='block';
  var xy = getBounds(searchBoxId);
  y = yOnPage(xy.y+xy.h+4,0);
  x = xOnPage(xy.x-10);

  div.style.top = y + 'px';
  div.style.left = x + 'px';
  hideSelects();
//  showShadowBox(div);
}
//--------------------------------------
function hideSuggestions() {
  popupClose('','');
}
function hideSuggestionsCore() {
  var id = document.getElementById('suggestionBox');
  if (id) { id.style.display='none'; showSelects(); }
//  hideShadowBox();
}

function getSearchRes() {
  if (!typeAheadLive) { return; }

 	if(searchhttp.readyState==4 && searchhttp.status==200) {
				res = searchhttp.responseText;
//alert(res);
    if (res) {
      var aa ='';
      var pts = res.split('|');
      for (var i=0; i<pts.length; i++) {
        if (trim(pts[i])) {
          var pt = pts[i].split('\\');
          f=searchedValue;
          var s1 = (pt[2] ? pt[2] : 'products');
          var L_descr = pt[1].toLowerCase();
          var L_f = f.toLowerCase(f);
          var p = L_descr.indexOf(L_f);
          var s = pt[1].substr(p,searchedValue.length);
          var d='<span class="match">'+s+'</span>';
          pt[1]=pt[1].replace(new RegExp(searchedValue,"ig"),d)
          aa = aa+'<li><a id=item'+i+' href="'+thisUrl+'sp'+delim404+s1+delim404+pt[0]+'" onclick="popupClose(\'\',\'\');">'+pt[1]+'</a></li>';
        }
      }
    }
 			if (!aa) {
      a='no suggestions - try again.';
      badValue = searchedValue;
    } else {
      a = '<ul>'+aa+'</ul>';
      badValue = '';
    }

    showSuggestions(a);
		}
}

function getSuggestions() {

  try {   // The following "try" blocks get the XMLHTTP object for various browsers…
        searchhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      searchhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
      // This block handles Mozilla/Firefox browsers...
      try {
        searchhttp = new XMLHttpRequest();
      } catch (e3) {
        searchhttp = false;
      }
    }
  }

		if(searchhttp!=null) {
    var fixer = new Date();
 			searchhttp.open("GET","typeAhead.asp?searchwhat="+searchedValue+'&when='+fixer.getTime(),true);
 			searchhttp.onreadystatechange=function(){ getSearchRes(); };
    searchhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");
 			searchhttp.send(null)
		}
}

function doSearch(c) {
  if (!typeAheadLive) { return }

  var a = trim(searchBox.value);
  if (!a) { hideSuggestions(); searchedValue = ''; return }

  if (searchedValue != a) {
    searchedValue = a;

//    if (badValue == '' || searchedValue.indexOf(badValue) != 0) {
      badValue = '';
      getSuggestions();
//    }
  }
  return
}

function searchSuggKeyDown(c) {
  c = c || window.event;
  var a = (c.keyCode ? c.keyCode : c.which);
 	if (a==191) { if (window.event) { event.returnValue = false; } return false; } // ? mark
	 return true
}

function initSearchBox() {
		searchBox = document.getElementById(searchBoxId);
  if (searchBox) {
//		searchBox.onkeypress = function(c) { return editKeyPress(c)};
  		searchBox.onkeyup = function(c) { return doSearch(c) };
		  searchBox.onkeydown = function(c) { return searchSuggKeyDown(c) };
		}
}

// *********** pre-post form data checking stuff
// to use this all you do is add ' onsubmit="return checkData(this);" ' to the form definition
// and add data-man="" to each input, select or textarea you want to be mandatory.
// data-man can have other values to add extra control to the pre-post checks
// data-man can have values of:
// "email", "minl=xx", "maxl=xx", "minv=xx", "maxv=xx" "pwd", "cc", "confirm=id", "novalue=xx",
// "blankok"
// multiple controls are separated by | eg "minl=5|maxl=20|blankok"
// "email" does a check for a valid email address
// "minl" and "maxl" control the min and max length
// "minv" and "maxv" control the min and max values
// "pwd" sets the min and max length to 6 and 20 - this just means the lengths are set in one place
// "cc" does a basic credit card modulus check with min and max lengths of 13 and 19
// "confirm=xxx" will check that the value is the same as the value in the element with id="xxx"
// "novalue=nowt,none" will check that the value is not '' and not 'nowt' and not 'none' (comma delimited)
//     -- use this if the default or blank value of a drop down is somthing other than ''
// "blankok" allows restrictions to be set but only checked if the value is not '' eg password change

function isEmail(s) {
  return s.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) != null;
}
function ccCheck(number) {
  var number=number.replace(/ /g, '');  // Strip any spaces
  var number_length=number.length;
  var parity=number_length % 2;
  var total=0;
  for (i=0; i < number_length; i++) {
    var digit=number.charAt(i);
    if (i % 2 == parity) { digit=digit * 2;  if (digit > 9) { digit=digit - 9; } }
    total = total + parseInt(digit);
  }
  return ((total % 10 == 0) && (number_length >= 13) ? true : false);
}
var checkEleError = null;
var checkErrTimer = null;
var checkErrVal = '';
var checkErrEle = null;
function showErr(el) {
  if (!checkEleError) {
    checkEleError = createDynamicPopup('errorPopup','','errorPopup');
    var s = '<table cellspacing="0" cellpadding="0" border="0"><tr>';
    s += '<td id="ceeMain" style="padding:14px 0 0 20px; font-weight:bold; background-position: 0 0;"></td>';
    s += '<td style="width:20px; height:20px; background-position: right 0;"><!--x--></td>';
    s += '</tr><tr>';
    s += '<td class="bot" style=" background-position: 0 bottom;"><!--x--></td>';
    s += '<td class="bot" style=" background-position: right bottom;"><!--x--></td>';
    s += '</tr></table>';
    checkEleError.innerHTML = s;
  } else {
    globZindex++;
    checkEleError.style.zIndex = globZindex;
  }

  var tmp = document.getElementById('ceeMain');
  tmp.innerHTML = el.stat;
  checkEleError.style.display = 'block';
  var exy = getBounds(el);
  var exe = getBounds(checkEleError);

  checkEleError.style.top = exy.y -exe.h+1 + 'px';
  checkEleError.style.left = exy.x + 15 + 'px';
  hideSelects(el);
}
function hideErr(el) {
  if (checkErrTimer) { clearTimeout(checkErrTimer); }
  if (checkEleError) { checkEleError.style.display = 'none'; }
  showSelects();
}
function checkErrOnTimer(tim) {
  var ele = checkErrEle;
//alert(ele);
  if (ele.value != checkErrVal) {
    checkEle(ele, 1);
  } else {
    checkErrTimer = setTimeout( "checkErrOnTimer(this)", 1000 );
    checkErrTimer.ele = ele;
  }
}
function hasNoValue(val, novalue) {
  val = val.toLowerCase();
  if (val == '') { return true; }
  if (novalue) {
    for (var i=0; i<novalue.length; i++) {
      if (novalue[i].toLowerCase() == val.toLowerCase()) { return true; }
    }
  }
  return false;
}
function checkEle(ele, from, form) {
  if (checkErrTimer) { clearTimeout(checkErrTimer); }
  var ok = true;
  var man = ele.getAttribute('data-man');
  var val = trim(ele.value);
  if (man != undefined) {
    var minl = 0; var maxl = 9999; var minv = -999999999; var maxv = 999999999;
    var noquote = false;
    var confirm = '';  var novalue = ''; var isval = false; var blankok = false;
    var mana = man.split('|');
    for (var j=0; j<mana.length; j++) {
      var manj = mana[j].split('=');
      if (manj[0] == 'cc') { minl = 13; maxl = 19; }
      if (manj[0] == 'pwd') { minl = 6; maxl = 20; noquote = true; }
      if (manj[0] == 'minl') { minl = manj[1]-0; }
      if (manj[0] == 'maxl') { maxl = manj[1]-0; }
      if (manj[0] == 'minv') { isval = true; minv = manj[1]-0; }
      if (manj[0] == 'maxv') { isval = true; maxv = manj[1]-0; }
      if (manj[0] == 'confirm') { confirm = document.getElementById(manj[1]); }
      if (manj[0] == 'novalue') { novalue = manj[1].split(','); }
      if (manj[0] == 'blankok') { blankok = true; }
    }
    var errstr = '';

    if (blankok && hasNoValue(val,novalue)) {
    }
    else if (confirm == undefined || (confirm && (confirm.value == undefined))) {
      // if the confirm element doesnt exist show a message to programmer
      ok = false; errstr = 'confirm id does not exist (programmer)';
    }
    else if (confirm) {
      if (confirm.value != val) { ok = false; errstr = 'Confirmation value does not match'; }
    }
    else {
      var eng = (ele.tagName == 'SELECT' ? 'selected' : 'entered');
      if (man == 'cc' && !ccCheck(val)) { ok = false; errstr += 'Credit Card number is invalid<br>'; }
      if (man == 'email' && !isEmail(val)) { ok = false; errstr += 'Email address is not a valid address<br>'; }
      if (val.length < minl) { ok = false; errstr += 'Minimum length is '+minl+' characters<br>'; }
      if (val.length > maxl) { ok = false; errstr += 'Maximum length is '+maxl+' characters<br>'; }
      if (noquote && (val.indexOf("'") > -1)) { ok = false; errstr += "The single quote character (') is not allowed<br>"; }
      if (isval && (val-0 < minv || val-0 > maxv)) { ok = false; errstr += 'Please enter a number between '+minv+' and '+maxv+'<br>'; }
      if (hasNoValue(val, novalue)) { ok = false; errstr = 'A value needs to be '+eng+'<br>'; }
    }

    // IE wont do select border so set the parents border instead
    var bel = (ele.tagName == 'SELECT' ? ele.parentNode : ele);

    if (!ok) {
      if (ele.done != true) {
        ele.done = true;
        ele.oldbwid = cssStyle(bel,'borderTopWidth');
        ele.oldbstyle = cssStyle(bel,'borderTopStyle');
        ele.oldbcolor = cssStyle(bel,'borderTopColor');
//alert(bel.tagName+' '+bel.className+' '+ele.oldbcolor);
        ele.oldbgcolor = cssStyle(ele,'backgroundColor');
        ele.oldbgimage = cssStyle(ele,'backgroundImage');
        ele.oldcolor = cssStyle(ele,'color');
        var pos = getBounds(ele);
        ele.onkeyup = new Function("checkEle(this,1)");
        ele.onchange = new Function("checkEle(this,1)");
        ele.onblur = new Function("hideErr(this); checkEle(this,0)");
        ele.onfocus = new Function("checkEle(this,1)");
      }
      ele.stat = errstr;
      bel.style.border = '1px ridge #f00';
      ele.style.background = 'url(assets/images/redcross2.gif) right 2px no-repeat #fff';
      if (from == 1) {
        showErr(ele);
        checkErrVal = val;
        checkErrTimer = setTimeout( "checkErrOnTimer(this)", 1000 );
        checkErrEle = ele;
      }
    }
    else if (ele.done == true) {
      bel.style.border = ele.oldbwid + 'px ' + ele.oldbstyle + ' ' + ele.oldbcolor;
//alert(bel.tagName+' '+bel.style.border);
      ele.style.backgroundImage = ele.oldbgimage;
      ele.style.backgroundColor = ele.oldbgcolor;
      hideErr(ele);
    }
  }
  return ok;
}
function checkData(form) {
  var ok = true;
  var goto = false;
  if (form) {
    var eles = form.elements;
    for (var i=0; i<eles.length; i++) {
      var ele = eles[i];
      var res = checkEle(ele, 0, form);
      if (!res) { ok = false; if (!goto) { goto = ele; } }
    }
  }
  if (!ok) { goto.focus(); }  // error here suggests two inputs with the same id on the page
  return ok;
}

function checkChars(ele) {
   var str = ele.value;
   var max = ele.getAttribute('maxlength');
   var len = max -str.length;
   if (len>=0) {
      document.getElementById('noChars').innerHTML = len;
   } else {
      ele.value = str.substr(0, max)
   }
}

addLoadEvent(setFocusTo);
addLoadEvent(postLoadImages);