var thisPage = location.href; 
var sPath = window.location.pathname;
var re_product = new RegExp('prods/[0-9]+.html');
var re_productcat = new RegExp('prods/pc[0-9]+.html');
var re_shoppingcart = new RegExp('/basket.zi/');

window.onload=initAll;

function initAll(){   
  var currentNavCatBlock = getNavCatBlock(); 

   setNavCat(currentNavCatBlock);
   //Display the promos & news link
   setDisplayOn('navCatBlock8');
   setDisplayOn('navCatBlock10');
   CurrentNavLink();
}

function setNavCat(currentNavCatBlock) {
  var thisTitle = document.title;
  if (thisTitle=="Shopping Cart"){ pageheader.innerText="Shopping Basket";} 
  setDisplayOn(currentNavCatBlock);
}

function getNavCatBlock() {
  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) && (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 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) && (anchor[i].className == 'nav')){ 
       //this is the left nav
       anchor[i].className = "current";
       break;
    }
  }
} 

function setDisplayOn(e){
  element = document.getElementById(e);
  if (element){
   //if IE
   if (element.currentStyle){
       element.style.display='block';
       element.style.visible='visible';
   } else {
    //if FF
    element.setAttribute( 'style', 'display:block');
   }
  }
}

  function field( id ) {
    var obj = document.getElementById( id );
    if ( !obj ) {
      alert( 'Document element not found.  id=' + id );
    }
    return obj;
  }
 
  function show( id ) {
    hideall();
    var ele = field( id )
    if ( ele ) {
      ele.style.display = 'block';
    }
  }
 
  function hide( id ) {
    var ele = field( id )
    if ( ele ) {
      ele.style.display = 'none';
    }
  }

 function hideall() {
    hide('breastlist');
    hide('bodylist');
    hide('facehairlist');
    hide('skinlist');
  }

function validateform(frm) 
{
    // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }

    // Check the Telephone Number field is not blank
    if (frm.txttelephone.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.txttelephone.focus();
        return false;
    }
    // Check the Email field is not blank
    if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Now check the Email field for the "@" symbol
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Check they have checked one of the tickboxes
    if ((frm.chkbrochure.checked != 1) && (frm.chknewsletter.checked != 1) && (frm.chkcall.checked != 1) && (frm.chkconsult.checked != 1))
    {
        alert("Please select if you would like a brochure, arrange a consultation, add you to our newsletter or arrange a call back.");
        return false;
    }

}



