 /* globals */
String.trim = function(s) {
  if (s==null) {
    return s;
  }
  return s.replace(/^\s+/, "").replace(/\s+$/, "");
}

var EU = {
    locale: ''
};
EU.txtSearch_cleared = false;
EU.txtSearch_checkvalue = function(obj) {
  if (!EU.txtSearch_cleared) {
    obj.value = '';
    EU.txtSearch_cleared = true;
  }
}

EU.Popover = {};
EU.Popover.tagId = 'a_popover';
EU.Popover.close = function() {
  // Are we in the div tag?
  var popoverDivTag = null;
  if (window.parent &&
    window.parent.document &&
    window.parent.document.getElementById(EU.Popover.tagId)) {
    popoverDivTag  = window.parent.document.getElementById(EU.Popover.tagId)
    popoverDivTag.style.visibility='hidden';
    return 0;
  }

  // Not in the popover
  popoverDivTag = $(EU.Popover.tagId);
  if (popoverDivTag!=null) {
    popoverDivTag.style.visibility='hidden';
  }
  return 0;
}


/*
  Popover creator
*/
EU.Popover.open = function(url, width, height, isText) {
  var popoverDivTag = $(EU.Popover.tagId);
  var i_width = (width<=0 || undefined == width)?500:width;
  var i_height = (height<=0 || undefined == height)?400:height;

  if (popoverDivTag==null) {
    popoverDivTag = document.createElement('DIV');
    popoverDivTag.style.position='absolute';
    popoverDivTag.style.margin='0 0 0 0';
    popoverDivTag.style.border = "1px ridge Black";
    popoverDivTag.style.width =  i_width + 'px';
    popoverDivTag.style.height = i_height + 'px';
    popoverDivTag.style.zIndex = 102;
    popoverDivTag.id = EU.Popover.tagId;
    document.body.insertBefore(popoverDivTag, document.body.firstChild);
  }

  if (isText) {
    popoverDivTag.innerHTML = url;
  } else {
    var iHtml = '<iframe sr';
    iHtml = iHtml + "c='" + url;
    iHtml = iHtml + "' style='width:100%; height: 100%' ";
    iHtml = iHtml + "scrolling='yes' id='interstitialFrame' name='interstitialFrame'></iframe>";

    popoverDivTag.innerHTML = iHtml;
  }

  popoverDivTag.style.left=((document.body.clientWidth - i_width)/3 + "px");

  var topOffSet = window.pageYOffset
    || document.documentElement.scrollTop
    || document.body.scrollTop
    || 0;

  popoverDivTag.style.top=(topOffSet + 30) + "px";

  popoverDivTag.style.visibility='visible';
}


EU.Popover.currentPopover=null;
EU.Popover.showPopover=function (elementName, imageName) {

  if (EU.Popover.currentPopover!=null) {
    EU.Popover.hidePopover(elementName);
  }

    var movieWidth = 650;
    var movieHeight = 580;
    var vSizeWidth = 521;
    var vSizeHeight = 400;
    var movieBgc = 'ffffff';
    var requiredVersion = 7;

    var url = S7Config.isViewerRoot + S7Config.isGenericZoomViewer;
    // viewer parameters
    var urlParams = '?serverUrl=' + S7Config.isRoot;
    urlParams += '&contentRoot=' + S7Config.isContentRoot;

    // create image set on the fly

    urlParams += '&image=Armstrong/' + imageName + ';Armstrong/' + imageName;

    urlParams += '&singleImageSwatch=false';
    urlParams += '&backgroundColor=0x' + movieBgc;
    urlParams += '&autoResize=true,true';
    urlParams += '&viewSize=200,200';

    var langId = EU.Popover.languageId;
    if(langId == "uk") langId = "en";
    urlParams += '&config=Armstrong/afp_com_viewer_' + langId;
    urlParams += '&swLayout=vert,0,0';

//    detectFlash();
    var flashText = '';
    flashText = flashText + '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
    flashText = flashText + '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
    flashText = flashText + ' ID="Main" WIDTH="' + movieWidth + '" HEIGHT="' + movieHeight + '" ALIGN="">';
    flashText = flashText + ' <PARAM NAME=movie VALUE="' + url + urlParams + '"> <PARAM NAME=loop VALUE=false> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>  <PARAM NAME=wmode VALUE=transparent> <PARAM NAME="allowScriptAccess" VALUE="sameDomain" />';
    flashText = flashText + ' <EMBED src="' + url + urlParams + '" loop=false menu=false quality=high bgcolor=#FFFFFF allowScriptAccess="sameDomain"  ';
    flashText = flashText + ' swLiveConnect=TRUE WIDTH="' + movieWidth + '" HEIGHT="' + movieHeight + '" WMODE=transparent NAME="Main" ALIGN=""';
    flashText = flashText + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
    flashText = flashText + ' </EMBED>';
    flashText = flashText + ' </OBJECT>';
    $('popoverContent').innerHTML = flashText;

    new Effect.Appear($(elementName), { duration: 1.5 });


  EU.Popover.currentPopover = elementName;
}


EU.Popover.hidePopover = function() {
  if (EU.Popover.currentPopover!=null) {
    new Effect.Fade($(EU.Popover.currentPopover), { duration: 2});
    EU.Popover.currentPopover = null;
  }
}


EU.Popover.togglePopover=function(elementName, imageName) {
  if (EU.Popover.currentPopover==null || EU.Popover.currentPopover!=elementName) {
    EU.Popover.showPopover(elementName, imageName);
  } else {
    EU.Popover.hidePopover(elementName);
  }
}



/*
  Spawn a popup. returns false to cancel the click.
  Usage:
  DEFAULT
    <a href="wacky.html"
       onclick="return a_popup(this)">
      Foo
    </a>
  Set width/height
    <a href="wacky.html"
       onclick="return a_popup(this, 200, 300)">
      Foo
    </a>

  Custom style - not resizeable
    <a href="wacky.html"
       onclick="return a_popup(this, 200, 300, 'titlebar,scrollbars=yes,resizable=no')">
      Foo
    </a>

  Custom style - and text
    <a href="wacky.html"
       onclick="return a_popup(this, 200, 300, 'titlebar,scrollbars=yes,resizable=no', 'doh')">
      Foo
    </a>
*/
function a_popup() {
  var a_element=null;
  var a_width=null;
  var a_height=null;
  var a_windowStyle=null;
  var a_customText=null;

  switch (a_popup.arguments.length) {
    case 5:
      a_customText = a_popup.arguments[4];
    case 4:
      a_windowStyle = a_popup.arguments[3];
    case 3:
      a_height = a_popup.arguments[2];
    case 2:
      a_width = a_popup.arguments[1];
    case 1:
      a_element = a_popup.arguments[0];
    default:
  }

  var aTarget = a_element.target;

  if (aTarget==null || aTarget=="") {
    aTarget = "pop";
  }

  /* Because we can't do real design work - only kludge things up */
  if (a_element.href!=null && a_element.href.match(/\/(fs|dar|floor_selector)\.asp/)) {
    aTarget = "eieio";
  }

  if (a_windowStyle==null) {
    a_windowStyle = "titlebar,scrollbars=yes,resizable=yes";
  }

  if (a_width==null || a_width <=0) {
    a_width=400;
  }
  if (a_height==null || a_height <=0) {
    a_height=400;
  }

  a_windowStyle+= (",left="+((screen.availWidth - a_width) / 2));
  a_windowStyle+= (",width="+a_width);

  a_windowStyle+= (",top="+(((screen.availHeight - a_height) / 2 ) - 30));
  a_windowStyle+= (",height="+a_height);

  var w;
  if (a_customText!=null) {
    w = window.open('', aTarget, a_windowStyle);
    try {
      w.document.close();
      w.document.open();
      w.document.writeln(a_customText);
      try {
        w.document.close();
      } catch(e){}
    } catch(e){}
  } else {
    w = window.open(a_element.href, aTarget, a_windowStyle);
  }

  try {
    w.focus();
  } catch(e){}

  return false;
}



EU.Cookie = {};

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
EU.Cookie.set = function(name, value, path, expires, domain, secure) {
    document.cookie= name + "=" + encodeURIComponent(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 * Returns null if cookie does not exist.
 */
EU.Cookie.get = function(name) {
  try {
    var cookies = document.cookie;
    var index = cookies.indexOf(name + "=");
    if (index == -1) return null;
    index = cookies.indexOf("=", index) + 1;
    var endstr = cookies.indexOf(";", index);
    if (endstr == -1) endstr = cookies.length;
    return decodeURIComponent(cookies.substring(index, endstr));
  } catch(e) {}
  return null;
}

/**
 * Deletes the specified cookie.
 * delete is areserved word in javascript
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 */
EU.Cookie.remove = function (name, path) {
    if (EU.Cookie.get(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


EU.Menu = {};
EU.Menu.startList=function(){
  if (navigator && navigator.appName && navigator.appName.match(/Opera/)) {
    return;
  }
  if (document.all&&document.getElementById&&window.mainMenuBar){
    // Add a shim to hide select items for drop down menus.
    if (navigator.appVersion.substr(22,3)!="5.0") {
      var shhhhhim = document.createElement('IFRAME');
      shhhhhim.id= "menushim";
      shhhhhim.src="about:blank"
      shhhhhim.scrolling="no"
      shhhhhim.frameborder="1"
      shhhhhim.style.position='absolute';
      shhhhhim.style.display='none';
      shhhhhim.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
      shhhhhim.style.margin='5 5 5 5';
      shhhhhim.style.border = "5px ridge Black";
//      shhhhhim.innerHTML = '<iframe id="menushim" src="about:blank" scrolling="no" frameborder="2" style="position:absolute;display:none;filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);background-color:blue"></iframe>';
      document.body.insertBefore(shhhhhim, document.body.firstChild);
    }
    navRoot=document.getElementById("mainMenu");
    for (i=0;i<navRoot.childNodes.length;i++){
      node=navRoot.childNodes[i];
      if (node.nodeName=="LI"&&node.getElementsByTagName("UL").length>0){
        node.onmouseover=function(){
          if(this.className.indexOf("over")==-1){
            this.className+=" over";
            EU.Menu.hideDropdowns(this.getElementsByTagName("UL")[0],true);
          }
        }
        node.onmouseout=function(){
          if(!EU.Menu.isInParent(event.toElement, this)){
            this.className=this.className.replace(" over","");
            EU.Menu.hideDropdowns(this.getElementsByTagName("UL")[0],false);
          }
        }
      }
    }
  }
}
EU.Menu.isInParent = function(el, parent){
  if (!el || ! parent)
    return false;

  var aEls=parent.getElementsByTagName(el.tagName)
  if (!aEls)
      return false;
  if(aEls.length==0)
    return false;
  for(var i=0;i<aEls.length;i++){
    if(el==aEls[i])
      return true;
  }
  return false;
}
EU.Menu.hideDropdowns = function(obj, bool){
  if (navigator.appVersion.substr(22,3)=="5.0"){
    if(bool)
      EU.Menu.hideSelects();
    else
      EU.Menu.showSelects();
    return;
  }
  var mnuShim=document.getElementById("menushim");
  if(bool){
    mnuShim.style.left=(EU.Menu.getPageOffsetLeft(obj)-11)+"px";
    mnuShim.style.top=(EU.Menu.getPageOffsetTop(obj)-5)+"px";
    mnuShim.style.width=obj.offsetWidth+"px";
    mnuShim.style.height=obj.offsetHeight+"px";
    obj.style.zIndex="101";
    mnuShim.style.zIndex="0";
    mnuShim.style.display="block";
  } else
    mnuShim.style.display="none";
}
EU.Menu.getPageOffsetLeft=function (el){
  var x;
  x=el.offsetLeft;
  if (el.offsetParent!=null)
    x+=EU.Menu.getPageOffsetLeft(el.offsetParent);
  return x;
}
EU.Menu.getPageOffsetTop = function(el){
  var y;
  y=el.offsetTop;
  if (el.offsetParent!=null)
    y+=EU.Menu.getPageOffsetTop(el.offsetParent);
  return y;
}
EU.Menu.hideSelects = function(){
  var oSelects=document.getElementsByTagName("select");
  for(var i=0;i<oSelects.length;i++)
    oSelects[i].className+=" hide";
}
EU.Menu.showSelects = function(){
  var oSelects=document.getElementsByTagName("select");
  for(var i=0;i<oSelects.length;i++)
    oSelects[i].className=oSelects[i].className.replace(" hide","");
}
EU.Menu.addEvent = function(obj, evType, fn) {
  // adds an eventListener for browsers which support it
  // Written by Scott Andrew: nice one, Scott
  if (obj.addEventListener){
    obj.addEventListener(evType,fn,true);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType,fn);
    return r;
  } else {
    return false;
  }
}

EU.Menu.addEvent(window,"load",EU.Menu.startList);

EU.updateCartCount = function updateCartCount() {
  var opt = {
    method: 'post',
    onSuccess: function(t) {
      $('cartCount').innerHTML  = String.trim(t.responseText);
      EU.Cookie.set('cartCount', String.trim(t.responseText), '/commflreu');
      EU.Cookie.remove('CART_UPDATE', '/commflreu');
    }
  }


  new Ajax.Request('cart-count.asp', opt);
}

EU.trackCartCountChange = function trackCartCountChange(sel,sampleOrderId,sampleOrderLineItemId,hiddenQuantityVarId) {
  var opt = {
    method: 'post',
    onSuccess: function(t) {
      EU.updateCartCount();
      if(String.trim(t.responseText) == '0'){
          var oRow = $("selectQuantity" + sampleOrderLineItemId + "tr");
          oRow.parentNode.deleteRow(oRow.sectionRowIndex);
          location.reload(true);
      }
  }
}
 var sampleQuantity = sel.options[sel.selectedIndex].value;
 if(document.getElementById(hiddenQuantityVarId)){

 if(document.getElementById(hiddenQuantityVarId).value != "0"){
 document.getElementById(hiddenQuantityVarId).value = sampleQuantity;
 }else{
 alert("The selected item is in the process of deletion.");
 return;
 }
 }
 new Ajax.Request('cart-update-qty.asp?sampleOrderId='+sampleOrderId+'&sampleOrderLineItemId='+sampleOrderLineItemId+'&sampleQuantity='+sampleQuantity, opt);

}


EU.Omniture = {};
EU.Omniture.addLinkTrackEvents = function(myEvent) {
  s.linkTrackVars = 'events';
  if (s.linkTrackEvents != null && s.linkTrackEvents != "") {
    s.linkTrackEvents += "," + myEvent;
  } else {
    if (myEvent.indexOf('event') > 0) {
      s.linkTrackVars = 'events';
      s.linkTrackEvents = myEvent;
    } else
    s.linkTrackEvents = myEvent;
  }
}

/* for focus fun */
EU.hack1 =  function() {
    try {
    var x = function(inputs) {
      for (var i=0; i<inputs.length; i++) {
        if (!inputs[i].type.match(/(button|radio|check|image)/)) {
          inputs[i].onfocus=function() {
            this.className+=" focussy";
          }
          inputs[i].onblur=function() {
            this.className=this.className.replace(new RegExp(" focussy\\b"), "");
          }
        }
      }
    }
    x(document.getElementById("content").getElementsByTagName("INPUT"));
    x(document.getElementById("content").getElementsByTagName("TEXTAREA"));
    x(document.getElementById("content").getElementsByTagName("SELECT"));
  } catch(aintsupported) {
  }
}
/* Set focus on first visible text field */
EU.skipHack2 = false;
EU.hack2 =  function() {
  if(EU.skipHack2) {
    return;
  }
    try {
    var x = function(inputs) {
      for (var i=0; i<inputs.length; i++) {
        if (inputs[i].type.match(/text/i)) {
          inputs[i].focus();
          return;
        }

      }
    }
    x(document.getElementById("content").getElementsByTagName("INPUT"));
  } catch(aintsupported) {
  }
}

if (window.attachEvent) window.attachEvent("onload", EU.hack1);
Event.observe(window, "load", EU.hack2);

EU.setFocusOnLoad = function(fieldName) {
  EU.skipHack2 = true;
  var f = function() {
    var nodes = document.getElementById("content").getElementsByTagName("SELECT");
    for (var i=0; i<nodes.length; i++) {
      if (fieldName == nodes[i].name) {
        nodes[i].focus();
        return;
      }
    }
    nodes = document.getElementById("content").getElementsByTagName("INPUT");
    for (var i=0; i<nodes.length; i++) {
      if (fieldName == nodes[i].name) {
        nodes[i].focus();
        return;
      }
    }
  }
  Event.observe(window, "load", f);
};


EU.loadResults = function(baseQueryString, productLineId) {
  $('popoverContent').innerHTML  = "Loading results ...";
  var qs = baseQueryString + "&productLineId=" + productLineId;
  var opt = {
    method: 'post',
    onSuccess: function(t) {
      $('popoverContent').innerHTML  = String.trim(t.responseText);
    },
    onFailure: function(t) {
      $('popoverContent').innerHTML  = "An error occured";
    }
  }
  new Ajax.Request('ajax-items.asp?' + qs, opt);

  // Don't hide the popover
  if (EU.Popover.currentPopover==null) {
    EU.Popover.togglePopover('allItemsContainer');
  }

  var popover = $('allItemsContainer');
  var offsets = EU.viewport.getScrollOffsets();
  popover.style.top = offsets.top + 60 + 'px';

  return false;
}

EU.printPage = function() {
window.print();
}

 EU.signup = function() {
     var address;
     try {
         address = $F('emailAddress');
     } catch(e) { }
     if (address == null || address == undefined || address.blank()) {
         try {
             address = $F('footerEmailAddress');
         } catch(e) { }
     }
     EU.containerPopup('signupPopup', '/commflreu/' + EU.locale + '/optin.asp?emailAddress=' + address);
     return false;
 }

 EU.closeSignup = function() {
     EU.closeContainerPopup('signupPopup');
 }

 EU.containerPopup = function(id, src) {
     var popup = new Element('iframe', {'id': id, 'name': id, 'src': src, 'allowTransparency': 'true'});
     var container = $('content');
     if (container) {
         container.insert({before: popup});
         popup.setStyle({'width': '400px', 'left': "186px", 'overflow': 'hidden'});

         var top = (Math.abs(container.viewportOffset().top) + (pageHeight() / 2) - 50);
         if (top < 50) top = 50;
         popup.setStyle({'height': '170px', 'top': top + 'px'});
     }
     return popup;
 }

 // Browser Window Size and Position
 // copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
 // you may copy these functions but please keep the copyright notice as well
 function pageHeight() {
     return  window.innerHeight != null ? window.innerHeight :
             document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight :
             document.body != null ? document.body.clientHeight : null;
 }

 EU.closeContainerPopup = function(id) {
     var p = parent.document.getElementById(id);
     p.style.display = 'none';
     p.remove();
 }
