// Link variables;
var hom = "/index.php";
var men = "/sec/men/index.php";
var cat = "/sec/cat/index.php";
var loc = "/sec/loc/index.php";
var abt = "/sec/abt/index.php";
var con = "/sec/con/index.php";

var cid;
var jid;

var mt01;
var mt02;
var mt03;
var mt04;
var mt05;
var mt06;

var tb01;
var tb02;
var tb03;
var tb04;
var tb05;
var tb06;
var tb07;
var tb08;

var prv;
var nxt;

function goHome(e){document.location.href = hom;}		// Go to Home page;
function goMenu(e){document.location.href = men;}		// Go to top level Menu;
function goCate(e){document.location.href = cat;}		// Go to top level Catering;
function goLoca(e){document.location.href = loc;}		// Go to top level Location;
function goAbou(e){document.location.href = abt;}		// Go to top level About;
function goCont(e){document.location.href = con;}		// Go to top level Contact;


// **************************************************************************
//
// Initialize our tab elements based upon page ID;
//
// **************************************************************************

cid = document.getElementById('mec');
jid = document.getElementById('mej');

if (cid)
	{
	// CHICAGO
	// Tabs
	mt01 = document.getElementById('cbr');
	mt02 = document.getElementById('cbd');
	mt03 = document.getElementById('clu');
	mt04 = document.getElementById('cps');
	mt05 = document.getElementById('csi');
	mt06 = document.getElementById('cdr');
	}
else
	{
	if (jid)
		{

		// JACKSON HOLE
		// Tabs
		mt01 = document.getElementById('jbr');
		mt02 = document.getElementById('jbd');
		mt03 = document.getElementById('jlu');
		mt04 = document.getElementById('jps');
		mt05 = document.getElementById('jsi');
		mt06 = document.getElementById('jdr');

		}
	}

if (cid || jid)
	{
	// Tabcards
	tb01 = document.getElementById('mbe');
	tb02 = document.getElementById('mbd');
	tb03 = document.getElementById('ml1');
	tb04 = document.getElementById('mpa');
	tb05 = document.getElementById('msi');
	tb06 = document.getElementById('mdr');
	tb07 = document.getElementById('ml2');

	if (jid)
		{
		tb08 = document.getElementById('ml3');
		}

	// Next / Previous Buttons for Lunch;
	prv  = document.getElementById('prv');
	nxt  = document.getElementById('nxt');
	}


function tabPrv()
	{
	var tID;

	if (cid)
		{

		// The Chicago lunch menu has only two pages;

		prv.style.display = 'none';
		nxt.style.display = 'block';

		tb03.style.display = 'block';
		tb07.style.display = 'none';
		}
	else
		{
		if (jid)
			{

			// The Jackson Hole menu has three pages;

			tID = document.getElementById('ml3');

			if (tID.style.display === 'block')
				{

				// On last tab, so show the middle tab;
				prv.className 	  += ' pr1';  // Shift over the previous tab;
				prv.style.display  = 'block';
				tb03.style.display = 'none';
				tb07.style.display = 'block';
				tb08.style.display = 'none';

				}
			else
				{

				// On middle tab, so show first tab;
				prv.className 	   = '';  	 // Show in normal position;

				prv.style.display  = 'none';
				tb03.style.display = 'block';
				tb07.style.display = 'none';
				tb08.style.display = 'none';
				}

			// Show "Next" button in both cases;
			nxt.style.display = 'block';
			}
		}
	}

function tabNxt()
	{
	if (cid)
		{
		prv.style.display = 'block';
		nxt.style.display = 'none';

		tb03.style.display = 'none';
		tb07.style.display = 'block';
		}
	else
		{
		if (jid)
			{

			// The Jackson Hole menu has three pages;

			tID = document.getElementById('ml2');

			if (tID.style.display === 'block')
				{

				// On last tab, so show first tab;
				nxt.style.display  = 'none';
				prv.className			 = '';		// Show in normal position;
				tb03.style.display = 'none';
				tb07.style.display = 'none';
				tb08.style.display = 'block';

				}
			else
				{

				// On first tab, so show the middle tab;
				nxt.style.display  = 'block';
				prv.className 	  += ' pr1';  // Shift over the previous tab;

				tb03.style.display = 'none';
				tb07.style.display = 'block';
				tb08.style.display = 'none';

				}

			// Show "Previous" button in both cases;
			prv.style.display = 'block';
			}
		}
	}

function clrTabs()
	{
	// Strip selection class;
	mt01.className = "";
	mt02.className = "";
	mt03.className = "";
	mt04.className = "";
	mt05.className = "";
	mt06.className = "";

	// Hide all tabcards;
	tb01.style.display = 'none';
	tb02.style.display = 'none';
	tb03.style.display = 'none';
	tb04.style.display = 'none';
	tb05.style.display = 'none';
	tb06.style.display = 'none';
	tb07.style.display = 'none';

	if (jid)
		{
		tb08.style.display = 'none';
		}

	// Hide Next / Prev buttons;
	nxt.style.display  = 'none';
	prv.style.display  = 'none';
	}

function tabCh1(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt01.className += "sel";

	// Show tab card;
	tb01.style.display = 'block';
	}

function tabCh2(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt02.className += "sel";

	// Show tab card;
	tb02.style.display = 'block';
	}

function tabCh3(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt03.className += "sel";

	// Show tab card;
	tb03.style.display = 'block';

	// Show Next button;
	nxt.style.display = 'block';
	}

function tabCh4(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt04.className += "sel";

	// Show tab card;
	tb04.style.display = 'block';
	}

function tabCh5(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt05.className += "sel";

	// Show tab card;
	tb05.style.display = 'block';
	}

function tabCh6(e)
	{
	// Clear current tabs;
	clrTabs();

	// Add selection class to currently focused tab;
	mt06.className += "sel";

	// Show tab card;
	tb06.style.display = 'block';
	}

function clrEml(e)
	{
	// Clear all default text from the Join Email list;
	var dv00 = document.getElementById('eml');		// Top; Join Email input field;

	dv00.value = '';
	}

function resEml(e)
	{

	// Reset default text from the Join Email list;
	var dv00 = document.getElementById('eml');		// Top; Join Email input field;

	if (dv00.value == '')
		{
		dv00.value = 'enter your email here';
		}
	}

function hidEml(e)
	{

	// Hide focus outline on the Join Email list;
	var dv00 = document.getElementById('esb');		// Top; Join Email input field;

	dv00.hidefocus = 'true';
	}

function externalLinks()
	{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
		{
   	var anchor = anchors[i];
   	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
    	{
     	anchor.target = "_blank";
     	}
 		}
	}

function addTabIndexes()
	{

	// Add tab indexes to our elements;

	// Basic menu item;
	var dv00 = document.getElementById('skip');		// Skip nav;

//	var dv01 = document.getElementById('hdr');		// Header image; return to home on click;
	var dv02 = document.getElementById('eml');		// Top, Newsletter email field;
	var dv03 = document.getElementById('esb');		// Top, Newsletter email submit;
	var dv04 = document.getElementById('men');		// Top nav; Menu;
	var dv05 = document.getElementById('cat');		// Top nav; Catering;
	var dv06 = document.getElementById('loc');		// Top nav; Locations;
	var dv07 = document.getElementById('abt');		// Top nav; About Us;
	var dv08 = document.getElementById('con');		// Top nav; Contact Us;

	dv00.setAttribute("tabindex","1");
//	dv01.setAttribute("tabindex","2");

	if (dv02) {dv02.setAttribute("tabindex","3");}
	if (dv03) {dv03.setAttribute("tabindex","4");}
	if (dv04) {dv04.setAttribute("tabindex","5");}
	if (dv05) {dv05.setAttribute("tabindex","6");}
  if (dv06) {dv06.setAttribute("tabindex","7");}
	if (dv07) {dv07.setAttribute("tabindex","8");}
	if (dv08) {dv08.setAttribute("tabindex","9");}

	}

function addListeners(e)
	{

	// Assign events to various elements on the page;

	// Get our element list;
	if (document.getElementById('eml')) {var dv00 = document.getElementById('eml');}		// Top; Join Email input field;
	if (document.getElementById('lgo')) {var dv01 = document.getElementById('lgo');}		// Header image; return to home on click;
	if (document.getElementById('men')) {var dv02 = document.getElementById('men');}		// Top nav; Menu;
	if (document.getElementById('cat')) {var dv03 = document.getElementById('cat');}		// Top nav; Catering;
	if (document.getElementById('loc')) {var dv04 = document.getElementById('loc');}		// Top nav; Locations;
	if (document.getElementById('abt')) {var dv05 = document.getElementById('abt');}		// Top nav; About Us;
	if (document.getElementById('con')) {var dv06 = document.getElementById('con');}		// Top nav; Contact Us;
	if (document.getElementById('esb')) {var dv07 = document.getElementById('esb');}

	// Mouse click events;
	if (dv00)
		{
		addEvent(dv00, 'focus',   clrEml, false);
		addEvent(dv00, 'blur',  	resEml, false);
		addEvent(dv07, 'focus',		hidEml, false);
		}


	if (!document.getElementById('wel'))
		{
		// Only make the header clickable if we are on an interior page;
		addEvent(dv01, 'mouseup', goHome, false);
		}

	addEvent(dv02, 'mouseup', goMenu, false);
	addEvent(dv03, 'mouseup', goCate, false);
	addEvent(dv04, 'mouseup', goLoca, false);
	addEvent(dv05, 'mouseup', goAbou, false);
	addEvent(dv06, 'mouseup', goCont, false);

	if (jid || cid)
		{
		addEvent(mt01, 'mouseup', tabCh1, false);
		addEvent(mt02, 'mouseup', tabCh2, false);
		addEvent(mt03, 'mouseup', tabCh3, false);
		addEvent(mt04, 'mouseup', tabCh4, false);
		addEvent(mt05, 'mouseup', tabCh5, false);
		addEvent(mt06, 'mouseup', tabCh6, false);

		addEvent(prv,  'mouseup', tabPrv, false);
		addEvent(nxt,  'mouseup', tabNxt, false);
		}
	}

function addEvent(elm, evType, fn, useCapture)
	{

	// **************************************************************************
	//
	// Add events to the document for specific elements;
	//
	// **************************************************************************

	if (elm.addEventListener)
		{
		elm.addEventListener(evType, fn, useCapture);
		return true;
		}
	else
		if (elm.attachEvent)
			{
			var r = elm.attachEvent('on' + evType, fn);
			return r;
			}
		else
			{
			elm['on' + evType] = fn;
			}

		return false;

		}

// ****************************************************************************
//
// Add our individual events;
//
// ****************************************************************************

addEvent(window, 'load', addListeners,  false);
addEvent(window, 'load', externalLinks, false);
addEvent(window, 'load', addTabIndexes, false);


// ****************************************************************************
// BEGIN PHP LIST PROCESSING;
// ****************************************************************************

var fieldstocheck = new Array();
var fieldnames 		= new Array();
var groupstocheck = new Array();
var groupnames 		= new Array();

function checkform()
	{
  for (i=0;i<fieldstocheck.length;i++)
  	{
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].type") == "checkbox") {
      if (document.subscribeform.elements[fieldstocheck[i]].checked) {
      } else {
        alert("Please enter your "+fieldnames[i]);
        eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
        return false;
      }
    }
    else {
      if ((eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") || (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "enter your email here"))
      	{
        alert("Please enter your "+fieldnames[i]);
        eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
        return false;
      	}

    }
  }
  for (i=0;i<groupstocheck.length;i++) {
    if (!checkGroup(groupstocheck[i],groupnames[i])) {
      return false;
    }
  }

  return true;
}


function addFieldToCheck(value,name)
	{
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
	}

function addGroupToCheck(value,name)
	{
  groupstocheck[groupstocheck.length] = value;
  groupnames[groupnames.length] = name;
	}

function compareEmail()
	{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
	}

function checkGroup(name,value)
	{
  option = -1;
  for (i=0;i<document.subscribeform.elements[name].length;i++)
  	{
    if (document.subscribeform.elements[name][i].checked)
    	{
      option = i;
    	}
  	}
  	if (option == -1)
  		{
    	alert ("Please enter your "+value);
    	return false;
  	}
  	return true;
	}


addFieldToCheck("email","Email");

// ****************************************************************************
// END PHP LIST PROCESSING;
// ****************************************************************************


// ****************************************************************************
// BEGIN IE-ONLY SCRIPTING;
// ****************************************************************************

/*@cc_on

var sfHover = function()
	{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");

	for (var i=0; i<sfEls.length; i++)
		{

		sfEls[i].onmouseover=function()
			{
			this.className += " sfhover";
			}

		sfEls[i].onfocus=function()
			{
			this.className += " sfhover";
			}

		sfEls[i].onblur=function()
			{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}

		sfEls[i].onmouseout=function()
			{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}

		}

	// Handle button events for email list join;
	var esb = document.getElementById("esb");
	esb.onmouseover = function() {this.className.replace(new RegExp(" sfactive\\b"), "");this.className += " sfhover"};
	esb.onfocus 		= function() {this.className.replace(new RegExp(" sfactive\\b"), "");this.className += " sfhover"};
	esb.onmousedown = function() {this.className.replace(new RegExp(" sfhover\\b"), "");this.className += " sfactive"};
	esb.onkeydown 	= function() {this.className.replace(new RegExp(" sfhover\\b"), "");this.className += " sfactive"};
	esb.onmouseout  = function() {this.className = "";};
	esb.onblur  		= function() {this.className = "";};

	}

// Add event to window;
addEvent(window, 'load', sfHover, false);

@*/

// ****************************************************************************
// END IE-ONLY SCRIPTING;
// ****************************************************************************

