var thisPage = location.href; 
var sPath = window.location.pathname;
var re_product = new RegExp('prods/[0-9]+.html');

window.onload=initAll;

function initAll(){   
  repositionTopNav();
  var currentNavCatBlock = getNavCatBlock();
  if ((sPath.indexOf("searchresults") > 0) || (sPath.indexOf("csa.cgi") > 0) || (sPath.match(re_product))) { 
    //search results page or product page so display opps header 
    currentNavCatBlock = 'navCatBlock10';
  } else if ((thisPage.indexOf("index") > 0) || (thisPage.indexOf("privacy") > 0) || (thisPage.indexOf(".html") < 0) || (thisPage.indexOf("contact.html") > 0) || (thisPage.indexOf("emailcontactussuccess") > 0)) {
    currentNavCatBlock = 'navCatBlock6';
  } else if ((thisPage.indexOf("applyonline") > 0) || (thisPage.indexOf("cvuploadthankyou") > 0) || (thisPage.indexOf("cvnotuploaded") > 0)){
    currentNavCatBlock = 'navCatBlock7';
  } else if (thisPage.indexOf("emailclientenquirysuccess") > 0){
    currentNavCatBlock = 'navCatBlock8';
  }    
  changeSloganPanel(currentNavCatBlock);
  setNavCat(currentNavCatBlock);
  CurrentNavLink();
}

function setNavCat(currentNavCatBlock) {
  if ((sPath.indexOf("searchresults") > 0) || (sPath.indexOf("csa.cgi") > 0) || (sPath.match(re_product))) { 
    //search results or product page so display opps header 
    currentNavCatBlock = 'navCatBlock10';
    //changeSearchAgainLink();
  } else if (thisPage.indexOf("index") > 0) {
   //display left nav for index page
   currentNavCatBlock = 'navCatBlock6';
  }
  else if (thisPage.indexOf("applyonline") > 0) {
   currentNavCatBlock = 'navCatBlock7';
  } else if (thisPage.indexOf("emailclientenquirysuccess") > 0){
    currentNavCatBlock = 'navCatBlock8';
  }  
   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 repositionTopNav() {
  topNav = document.getElementById("topnavpanel");
  topNav.style.display="block";
  topNav.style.visible = "visible";
}

function changeSloganPanel(currentNavCatBlock){
  var sloganimg = document.getElementById('sloganpanel').getElementsByTagName('img')[0];  
  sloganimg.src="http://www.executiveselectionltd.co.uk/images/" + currentNavCatBlock + ".gif";
  sloganimg.style.display="block";
  sloganimg.style.visible = "visible";
}

function changeSearchAgainLink() {
  var getTable = getElementsByClassName('maincontent');
  getTable[0].getElementsByTagName('a')[0].href="http://www.executiveselectionltd.co.uk/opportunities.html";
}

function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp(classname);
    var els = document.all?document.all:document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
      if(re.test(els[i].className))a.push(els[i]);
      return a;
}


function setCookies(positionvalue, locationvalue,sectorvalue,contractvalue)
{
  document.cookie= "cmbposition" + "=" + escape(positionvalue); 
  document.cookie= "cmblocation" + "=" + escape(locationvalue); 
  document.cookie= "cmbsector" + "=" + escape(sectorvalue); 
  document.cookie= "cmbcontract" + "=" + escape(contractvalue); 
}

function validate(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 Email field to see if any characters were entered
    //
    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;
    }

}

function validateapplication(frm) 
{
    // Check the Name field is not blank
    if (frm.strname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.strname.focus();
        return false;
    }
// Check the Email field to see if any characters were entered
    //
    if (frm.stremail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.stremail.focus();
        return false;
    }
    //
    // Now check the Email field for the "@" symbol
    //
    if (frm.stremail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.stremail.focus();
        return false;
    }
    // Check the salary field is not blank
    if (frm.strsalary.value.length == 0)
    {
        alert("Please enter your current salary.");
        frm.strsalary.focus();
        return false;
    }
    // Check the job title field is not blank
    if (frm.strjob.value.length == 0)
    {
        alert("Please enter your current job title.");
        frm.strjob.focus();
        return false;
    }
    // Check the contactfield is not blank
    if (frm.strno.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.strno.focus();
        return false;
    }
    if (frm.strresume.value.length ==0)
    {
        alert("Please attach your CV.");
        return false;    
    } 
}

