var thisPage = location.href;
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
var re_product = new RegExp('prods/[0-9]+.html');
var re_productcat = new RegExp('prods/pc[0-9]+.html');
var re_shoppingcart = new RegExp('/cshopcart.cgi/');

window.onload=initAll;

function initAll(){
  var currentNavCatBlock = getNavCatBlock();
  var currentNavCatContent  = 'navCatContent'+(currentNavCatBlock.substring(currentNavCatBlock.lastIndexOf('k') + 1));
  setNavCat(currentNavCatBlock, currentNavCatContent);
  CurrentNavLink();
}

function setDisplayOn(e){
  element = document.getElementById(e);
  if (element){
    //if IE
    if (element.currentStyle){
       element.style.display='block';
    }else{
     //if FF
     element.setAttribute( 'style', 'display:block');
    }
  }
}


function setNavCat(currentNavCatBlock, currentNavCatContent) {

  if (sPage=='index.html')  {    
   //dont display any right nav & change nav width
   var rightnavelement = document.getElementById('rightnavpanel');
   rightnavelement.style.display = "none";
   var elementDIV = document.getElementById('pageMainBody');
   elementDIV.style.marginLeft= "0px";
   elementDIV.style.marginRight= "0px";
  } else if (thisPage.indexOf("about") > 0) { setDisplayOn('navCatBlock7'); 
  } else if (thisPage.indexOf("charity") > 0) { setDisplayOn('navCatBlock30'); 
  } else if (thisPage.indexOf("qualification") > 0) { setDisplayOn('navCatBlock9'); 
  } else if (thisPage.indexOf("contactus") > 0) { setDisplayOn('navCatBlock13'); 
  } else if (thisPage.indexOf("successstories") > 0) { setDisplayOn('navCatBlock18'); 
  } else if (thisPage.indexOf("meetourdogs") > 0) { setDisplayOn('navCatBlock19'); 
  } else if (thisPage.indexOf("ourservices") > 0) { setDisplayOn('navCatBlock21');
  } else if (thisPage.indexOf("treatment_") > 0) { setDisplayOn('navCatBlock22');
  } else if (thisPage.indexOf("recommended") > 0) { setDisplayOn('navCatBlock23');
  } else if (thisPage.indexOf("insipiration") > 0) { setDisplayOn('navCatBlock24'); 
  } else if (sPath.match(re_productcat)) { 
    //this is a product cat page
    setDisplayOn('navCatBlock27');
  } else if (sPath.match(re_product)) {	
    //this is a product page
    var rightnavelement = document.getElementById('rightnavpanel'); 
    rightnavelement.style.display = "none";
    changeTheHeadline();
  } else if (sPath.match(re_shoppingcart)) {
    //See which page of check out process we are
    var pageheader= document.getElementById('shopcartheadline'); 
    var thisTitle = document.title;

    if (thisTitle=="Shopping Cart"){ pageheader.innerText="Shopping Basket";} 
    if (thisTitle.indexOf("Checkout") > 0) {
      //this is a checkout page
      var theBody = document.getElementsByTagName('body')[0];
      theBody.style.color='#000'; 
      theBody.style.background="url('https://www.britnett-carver2.co.uk/brightpaws/assets/sty_pgbodyback.gif') left top repeat";
      theBody.style.textAlign="center";
      var topTable = document.getElementById('mainbody');
      topTable.width="745";
    }
    pageheader.style.color="#99671c";
    var toplogo= document.getElementById('toplogopanel'); 
    toplogo.style.display='block';
    toplogo.style.visible='visible';
    var shoppingPage = document.getElementById('thePage');
    shoppingPage.style.width="745px"; 
    var shoppingFooter = document.getElementById('footerpanel');
    shoppingFooter.style.backgroundImage="url('https://www.britnett-carver2.co.uk/brightpaws/assets/sty_footback.gif')";
    shoppingFooter.style.textAlign="left"; 
    hideFirstContinueShopping();
    
  }  else {
   //display default
   setDisplayOn('navCatBlock25');
  }
   setDisplayOn(currentNavCatBlock);
   setDisplayOn(currentNavCatContent);
}

function CurrentNavLink() {
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors; 
    thisHREF = anchor[i].getAttribute("href");
    if ((thisHREF == thisPage) || (sPage =='index.html')) {
       //this is the left nav
       //alert(anchor[i].href);
       anchor[i].className = "current";
       break;
    }
  }
} 

function hideFirstContinueShopping(){
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors; 
    thisCLASS = anchor[i].className;
    if (thisCLASS == 'cartlink') {
       //this is the first shopping cart link to hide it
       anchor[i].className = "cartlinkhidden";
       break;
    }
  }
}

  function showImage(){
     document.write('<img src="'+theImages[whichImage]+'">');
   }

function getNavCatBlock() {
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  if ((thisPage.indexOf("index") > 0) || ((thisPage.indexOf(".html") < 0) && !(sPath.match(re_shoppingcart)))) {
    sPage = "index.html";  
    currentNavCatBlock = 'navCatBlock10';
    return currentNavCatBlock;
  }

  if (sPath.match(re_product)) {	
    //this is a product page
    currentNavCatBlock = 'navCatBlock5';
    return currentNavCatBlock;
  } 

  if (sPath.match(re_shoppingcart)) {
    //this is a shopping cart page
    currentNavCatBlock = 'navCatBlock5';
    return currentNavCatBlock;
  } else {
     for (var i=0; i<anchors.length; i++) { 
       var anchor = anchors; 
       thisHREF = anchor[i].getAttribute("href");
       if (((thisHREF == thisPage) && (anchor[i].className == 'nav')) || ((thisHREF == thisPage) && (anchor[i].parentNode.tagName == 'DIV'))){ 
         //this is a navigation link - return the navCatBlock
         return anchor[i].parentNode.parentNode.id;
       } 
     }
  }
} 

function changeTheHeadline() {

  var headline = document.getElementById('headline'); 
  headline.style.display="block";
  headline.style.visible="visible";
  headline.style.fontSize="16pt";
  headline.style.color="#f9ae56";
  headline.innerText = '\r\r' + headline.innerText;
  headline.style.height="100px";
  headline.style.backgroundImage="url('/images/productheader.gif')";
}