var co_name = 'JoJo';
var pageId = 'maternity';
var alertPrettyHead = false; //legacy - dead
alertConfig = { defaultHeaders : false, cssButtons : false, useIcons : false, leftFillHeader : false, printButton : false }

// -------------------- web site functions
function saveWallp(el) {
  var id = el.getAttribute('data-id');
  id = id.replace('-extra','');
  setCookie('wallp',id);
}
function setWallp() {
  var wid = getCookie('wallp');
  if (thisPageId && thisPageId != '<elucid_pageid_placeholder>') { wid = thisPageId; }
  if (!wid) { wid = pageId; }
  if (wid) {
    pageId = wid;
//    document.body.style.backgroundImage = 'url('+thisUrl+'assets/images/lifestyle/'+wid+'-back.jpg)';
//alert(document.body.style.backgroundImage);
  }
}
var menuTimer = null;
var menuTId = '';
var menuCaller = null;
function onMenuTimer() {
  if (menuTId) {
    var el = document.getElementById(menuTId);
    if (el) {
      if (window.imgtrans1) {
//        if (!isIE()) { imgtrans1.stop(); }
      }
      if (menuCaller) { el.style.left = menuCaller.offsetLeft + 'px'; }
      el.style.zIndex = '2000';
      el.style.display = 'block';
    }
  }
}
function delayMenu(id,caller) {
  clearTimeout(menuTimer);
  menuTId = id;
  menuCaller = caller;
  menuTimer = setTimeout( 'onMenuTimer()', 200 );
}

function hideMenu(ev) {
  clearTimeout(menuTimer);
  if (!ev) var ev = window.event;
	 var t = ev.relatedTarget || ev.toElement;

  if (t && menuTId) {
    var gone = true; var checked = false;
    if (t.parentElement) {
      checked = true;
   			while (t && t.parentElement != null) {
   //alert(t.tagName+' '+t.className);
   			 if (t == menuCaller) { gone = false; }
   				t = t.parentElement;
   			}
   	} else if (t.parentNode) {
      checked = true;
   			while (t && t.parentNode != null) {
   			 if (t == menuCaller) { gone = false; }
   				t = t.parentNode;
   			}
   	}

    if (gone && checked && menuTId) {
      var el = document.getElementById(menuTId);
      if (el) { el.style.display = 'none'; menuTId = '';}
      if (window.imgtrans1) {
//        if (!isIE()) { imgtrans1.restart(); }
      }
    }
  }
}
/*
var bigpicInitSize = { w:0, h:0 }
var bigpicImage = null;
var bigpicName = 'bigImage';
//
function printbigpic() {
  printDiv(bigpicName+'Img');
}
function initBigImage(sub) {
  // switch the look of the box for the large map image
  if (sub == -4) { bigpicName = 'mapImage'; } else { bigpicName = 'bigImage'; }
  var div = createDynamicPopup(bigpicName);
  var s = '';
  s+='<div id="'+bigpicName+'Head"></div>';
  s+='<img id="'+bigpicName+'PrintBtn" src="'+thisUrl+'assets/images/popupprint.jpg" alt="print" title="print" onclick="printbigpic();"/>';
  s+='<img id="'+bigpicName+'CloseBtn" src="'+thisUrl+'assets/images/popupclose.jpg" alt="close" title="close" />';
  s+='<div id="'+bigpicName+'Img"><img id="'+bigpicName+'ImgImage" 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() {
  hideShadowBox();
  var el = document.getElementById(bigpicName);
  if (el) { el.style.display='none'; }
}
function bigpicLoaded() {
  var div = document.getElementById(bigpicName);
  var im = document.getElementById(bigpicName+'ImgImage');
  var el = bigpicImage;
//alert(el.width+' '+el.height+' '+bigpicInitSize.wi+' '+bigpicInitSize.hi+' '+bigpicInitSize.w)
  if (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);

    var w = el.width; var h = el.height;
    var ss = screenSize();
    if (w > ss.w-bigpicInitSize.wx-16) { w = ss.w-bigpicInitSize.wx-16; }
    if (h > ss.h-bigpicInitSize.hx-16) { h = ss.h-bigpicInitSize.hx-16; }
    bigpicInitSize.innerDiv.style.width = w+'px';
    bigpicInitSize.innerDiv.style.height = h+'px';
    div.style.width = w+bigpicInitSize.wx+'px';
    div.style.height = h+bigpicInitSize.hx+'px';
    div.style.left = x + 'px';
    div.style.top = y + 'px';
  }
  im.src = el.src;
  showShadowBox(bigpicName);
}
function showbigpic() {
  if (window.opera || bigpicImage.width > 0) { bigpicLoaded(); }
}
function bigpic(what,sub) {
// sub >=0 = bikebuilder feature index
// sub = -1  bikebuilder frame
// sub = -2  prodpage
// sub = -3  showpart
   initBigImage(sub);
   popupInit(bigPicClose,bigpicName+'CloseBtn');
   var el = document.getElementById(bigpicName);
   var eli = document.getElementById(bigpicName+'Img');
   if (el && eli) {
     el.style.display = 'none';
     if (sub == -4) { var im = '('+noNull(what)+')'; }
     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+')'; }
     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('.jpg','_large.jpg');
//     c = c.replace('thumb','zoom');
//     c = c.replace('small','zoom');
//     c = c.replace('medium','zoom');
//     var ii = c.indexOf('products');  // opera fix
//     if (ii > -1) { c = c.substring(ii,100); }
     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';

     var x = el.offsetLeft;
     var y = el.offsetTop;
     x = xOnPage(x,600,true);
     y = yOnPage(y,554,true);

     el.style.left = x + 'px';
     el.style.top = y + 'px';
//     el1.style.width = wd + 'px';
//     el1.style.height = ht + 'px';

     bigpicImage = new Image();
     bigpicImage.onload = bigpicLoaded;
     bigpicImage.src = c;

//     el1.innerHTML = '<img src="'+c+'" onerror="imageErr(this,\'zoom\')" onload="bigpicLoaded(this)">';
     if (sub == -4) {
     }
     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 ) {
       document.getElementById('bigImageHead').innerHTML = document.getElementById('bbItemTitle'+what).innerHTML;
     }
     else {
       document.getElementById('bigImageHead').innerHTML = document.getElementById('bbItemTitle'+what+'Sub'+sub).innerHTML; }
//     document.getElementById('bigImageText').innerHTML = c;
//     document.getElementById('bigImageText').style.textAlign = 'right';
     showbigpic();
   }
   return false;
}
*/
//--------------------------------------
function explode(div, classs, endfunc, fromcust) {
  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' } );
//  transition( from, too, { speed:700, classname:'bigImage', movediv:'Y', onend:exploded, action:'fi' } );
}
//--------------------------------------
function initSizeChart() {
  var id = 'sizeChartDiv';
  var div = createDynamicPopup(id);
  var sct = document.getElementById('sizechartHost');
  if (sct) { sct = sct.innerHTML; } else { sct = 'Size Chart Not Found'; }

  var s = '';
  s+='<div id="sizeChartHead">Size Chart Help</div>';
  s+='<img id="sizeChartCloseBtn" src="assets/images/headerbtn.jpg"  alt="close" title="close" />';
  s+='<div id="sctable">'+sct+'</div>';
  div.innerHTML = s;
  var el = document.getElementById('sizeChartHead');
  if (el) { dhSize = DragHandler.attach(el,div); } // make it draggable on the header
  return div;
}
function showSizeChart() {
  var div = initSizeChart();
  if (div) {
    popupInit(hideSizeChart,'sizeChartCloseBtn');

    div.style.display = 'block';
    var posd = getBounds(div);
    var x = xOnPage(0,posd.w,true);
    var y = yOnPage(0,posd.h,true);
    div.style.left = x + 'px';
    div.style.top = y + 'px';
    showShadowBox(div);
  }
}
function hideSizeChart() {
  var el = document.getElementById('sizeChartDiv');
  hideShadowBox();
  if (el) { el.style.display = 'none'; }
}
//--------------------------------------
function initFlags(modal) {
  var id = 'currencyFlags';
  var div = createDynamicPopup(id,modal);
  var s = '';
  s+='<div id="currencyFlagsHead">Please Choose Your Currency</div>';
  s+='<img id="currencyCloseBtn" src="assets/images/headerbtn.jpg"  alt="close" title="close" onclick="popupClose(\'\',\'\');"/>';
  s+='<div id="currencyFlagsMain">';
		s+='<a onclick="changeCurrency(\'GBP\',\'UK\')" alt="UK Pounds GBP" title="UK Pounds GBP"><img class="currencyE" src="'+thisUrl+'assets/images/flags/GBP.jpg" /><span class="currencyT">UK Pounds GBP</span></a>';
		s+='<a onclick="changeCurrency(\'EUR\',\'FR\')" alt="Euro EUR" title="Euro EUR"><img class="currencyE" src="'+thisUrl+'assets/images/flags/EUR.jpg" /><span class="currencyT">Euro EUR</span></a>';
		s+='<a onclick="changeCurrency(\'USD\',\'US\')" alt="US Dollars" title="US Dollars"><img class="currencyE" src="'+thisUrl+'assets/images/flags/USD.jpg" /><span class="currencyT">US Dollars USD</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 showFlags(ele) {
  var div = initFlags(isModal);
  if (div) {
    popupInit(hideFlags,'!currencyFlags');

    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);

    div.style.top = y + 'px';
    div.style.left = x + 'px';
    hideSelects();
    showShadowBox(div);
  }
}
//--------------------------------------
function hideFlags() {
  var id = document.getElementById('currencyFlags');
  if (id) { id.style.display='none'; showSelects(); }
  hideShadowBox();
}
//--------------------------------------
function changeCurrency(c,cc) {
  popupClose('','');
  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+'&flag=yes';
  location=thisUrl+'ChangeCurrency.asp'+param;
}
//--------------------------------------
function showLiveFlag() {
  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 el = document.getElementById('CC_'+currency_code);
  if (el) {
    var bpos = el.getAttribute('data-on');
    el.style.backgroundPosition = bpos;
  }
}
//--------------------
function tidyFunc() {
// hide price if its 0.00 - check contents of li.price1 and hide li
  var cnt = 0;
  var arel = 0;
  var all = document.getElementsByTagName('div');
  for (var m=0, elm; elm=all[m++];) {
    if ( elm.className== 'rrpsav') {
      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]*\%/)) {
        elm.innerHTML = '&nbsp;';
      }
    }
  }
  all = null;

// collect vs box max height on each row

  var heights = new Array;
  cnt = 0;
  var alldiv = document.getElementsByTagName('div');
  for(var m=0, elm; elm=alldiv[m++];) {
    if ( elm.id.substring(0,12) == 'productVSDiv') {
     cnt++;
     var cc = Math.floor((cnt-1) / 4);
     heights[cc] = (!heights[cc] || elm.offsetHeight > heights[cc] ? elm.offsetHeight : heights[cc]);
    }
  }

// set all prodpage boxes to the same height
  cnt = 0;
  for(var m=0, elm; elm=alldiv[m++];) {
    if ( elm.id.substring(0,12) == 'productVSDiv') {
     cnt++;
     var cc = Math.floor((cnt-1) / 4);
     var h1 = elm.offsetHeight;
     elm.style.height = heights[cc]+'px';
     var h2 = elm.offsetHeight;
//     elm.innerHTML = cnt+' '+cc+' '+heights[cc]+' '+(heights[cc] - elm.offsetHeight);
     var elmore = document.getElementById(elm.id.replace('productVSDiv','productVSPrice'));
     if (elmore) {
//       elmore.innerHTML = h1+' '+h2+' '+cnt+' '+cc+' '+heights[cc]+' '+(heights[cc] - elm.offsetHeight);
       elmore.style.paddingBottom = ( h2 - h1 ) + 'px';
     }
    }
  }

  // manage left menu - its a copy of the main menu
  // - remove the mouseover handlers
  var lm = document.getElementById('leftMenu');
  if (lm) {
    var lia = lm.getElementsByTagName("LI");
    for (var i=0; i < lia.length; i++ ) {
      lia[i].onmouseover=null;
      lia[i].onmouseout=null;
    }
    // make visible all menus with data-id = pageid or data-id = pageid+'extra'
    // pageid can have a _??? section, the _??? allows for different background but same menu
    // remove the _??? to get the correct menu
    var pid = pageId;
    if (pid.indexOf('_') > 0) { pid = pid.substr(0,pid.indexOf('_')); }
    var lia = lm.getElementsByTagName("LI");
    for (var i=0; i < lia.length; i++ ) {
      var id = lia[i].getAttribute('data-id');
      if (id == pid) { lia[i].style.display = 'block'; }
      if (id == pid+'-extra') { lia[i].style.display = 'block'; }
    }
    var el = document.getElementById('innerContainer');
    if (el) {
      // make sure images on the page have a specified height, otherwise this will calc the wrong height
      var ht = el.offsetHeight;
      ht = (ht > 100 ? ht : 100); // -10 to match innerContainer padding
      lm.style.height = ht + 'px';
    }
  }
}

function resetMenuHeight() {  // used in tabbed info pages
  var lm = document.getElementById('leftMenu');
  if (lm) {
    lm.style.height = 'auto';
    var el = document.getElementById('innerContainer');
    if (el) {
      var ht = el.offsetHeight;
      ht = (ht > 100 ? ht - 10 : 100); // -10 to match innerContainer padding
      lm.style.height = ht + 'px';
    }
  }
}
//--------------------------------------
function killTheLeftMenu(loaded) {
return;
  if (isIE6() || 1==1) {
    if (loaded != 'loaded') {
      addLoadEvent(function() {killTheLeftMenu('loaded'); });
      return;
    }
    el = document.getElementById('leftContainer');
    if (el) {
      var elp = el.parentNode;
      if (elp) { elp.removeChild(el); }
    }
  }
}
//--------------------------------------
function doProductBookmark() {
var url = location.href;
var title = document.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
 { alertX('Bookmark could not be created\r\nPlease use your browsers menu to add a bookmark'); }
}
//--------------------------------------
//
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 searchOk(el,def) {
  var val = document.getElementById(el).value;
  if ((val == '' || val == def)) { return false; }
  if (trim(val).length < 2) { alertX('<br>&nbsp;&nbsp;Please enter at least 2 characters to search for&nbsp;&nbsp;<br>'); return false; }
  else {
    // dont let the form post. I want all the data in the querystring
    val = escape(trim(val.replace(/:/g,'')));
    if (delim404 == '*') {
      var s = thisUrl.replace('https:','http:')+'prodpage.asp?type=search&action=Search&searchwhat='+val;
      document.location = s;
    } else {
      var s = thisUrl.replace('https:','http:')+'product'+delim404+'t'+delim404+val;
      document.location = s;
    }
    popupClose('','');  // close any open popups
  }
  return false;
}
function setNumber(num) {
	var n = document.getElementById("r_updateNo");
	n.value = num;
	return true;
}

function pagerHead() {  // gets called from pagerText in common.js
//  var s = '<span class="ptext">Page '+pager_Page+' of '+pager_Max+' </span>';
  var s = '<span class="ptext">Page </span>';
  showPagerArrows = true;
  return s;
}

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;
}

// info page 'more' popup
function infoAlertClose(val) {
  if (val == undefined) { return true; }
}

function doInfoPopup(id, wid) {
  var el = document.getElementById(id);
  if (el) {
    alertPrettyHead = true;
    var buttons = {};
    if (!wid) { wid = 0; }
    promptX(el.innerHTML, infoAlertClose, wid, buttons);
  }
}

function infoPageTo(thisel, id, wid) {
  closeThisAlertX(thisel,'');
  doInfoPopup(id, wid);
}

// switch on intellisense (search drop down) by calling initSearchBox()
var searchBoxId = 'searchwhat';  // the id of the search input box
addLoadEvent(initSearchBox);
//stopRightClick();
//addLoadEvent(templateSwitch);
//addLoadEvent(preLoad);
//addLoadEvent(setHeight);
