var vGo = true;
// ----------------------------------------------------------------------------------------------------------
function startSearch(fld) {
	var txt = fld.value;
	if (txt == 'enter keyword/style') {
		fld.value = '';
		fld.style.color='#444';
	}
}

// ----------------------------------------------------------------------------------------------------------
function retcBoot() {

	var url;

	// create menu tracking array, five menu levels
	if (!document.navTrack) document.navTrack = new Array(5);
	document.navTrack[0] = '';
	document.navTrack[1] = '';
	document.navTrack[2] = '';
	document.navTrack[3] = '';
	document.navTrack[4] = '';

	// init RSH system
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(handleHistoryChange);
	var initialLocation = dhtmlHistory.getCurrentLocation();

	// go
	pageLoad(initialLocation);
}

// ----------------------------------------------------------------------------------------------------------
function pageLoad(url) {
	if (url.length == 0) url = 'home.html'; // default page
if (navigator.userAgent.indexOf("Mac") != -1)
{
  if (vGo)
  {
    updateUI(url, null);
    vGo=false; 
    /* vGo=setTimeout("true",3500); */
  }  
}
else
	updateUI(url, null);
}

// ----------------------------------------------------------------------------------------------------------
function handleHistoryChange(newLocation, historyData) {
 if (navigator.userAgent.indexOf("Mac") == -1)
	  updateUI(newLocation, historyData);
}

// ----------------------------------------------------------------------------------------------------------
function updateUI(newLocation, historyData) {

	// if we're handling a history request, restore the menu state
	if (historyData != null) {
		menuCloseToLevel(0);
		for(i = 0; i < 5; i++) {
			if (historyData.message[i]) menuOpenItem(historyData.message[i], i);
			document.navTrack[i] = historyData.message[i];
		}
	} else {

		// trap the current menu state, update history
		var menuState = new Array();
		for(i = 0; i < 5; i++) {
			menuState[i] = document.navTrack[i];
		}

		dhtmlHistory.add(unescape(newLocation), { message: menuState });
//alert('added: '+newLocation+' to history ('+menuState+') ');
	}

	// load content
	ajaxGet(unescape(newLocation), 'column2', null, 0);
}

// ----------------------------------------------------------------------------------------------------------

function menuCloseToLevel(level) {
	if (level==null) level = 0;

	for(i = 4; i >= level; i--) {
		if (document.getElementById(document.navTrack[i])) {

			// change to the "closed" (right-facing) bullet on level 0 items
			if (i==0) {
				document.getElementById(document.navTrack[i]).style.backgroundImage="url('images/navBullet1.gif')";

			// change the class of the first A tag to its inactive version
			} else {
				var kids = document.getElementById(document.navTrack[i]).getElementsByTagName("A");
				if (kids.length > 0) {
					var className = kids[0].className;
					if (className && className.indexOf('ACTIVE') != -1) {
						className = className.replace('ACTIVE','');
						kids[0].className = className;
					}
				}
			}

			// close first UL we find
			var kids = document.getElementById(document.navTrack[i]).getElementsByTagName("UL");
			if(kids.length > 0) kids[0].style.display = 'none';
			document.navTrack[i] = ''; // stop tracking this item (it's closed)
		}
	}
}

// ----------------------------------------------------------------------------------------------------------
function menuOpenItem(obj, level) {

	if (!document.getElementById(obj)) return;
	var main = document.getElementById(obj);

	// change to the "open" (down-facing) bullet on level 0 items
	if (level==0) {
		main.style.backgroundImage="url('images/navBullet2.gif')";

	// change the class of the first A tag to its "active" version
	} else {
		var kids = main.getElementsByTagName("A");
		if (kids.length > 0) {
			var className = kids[0].className;
			if (className && className.indexOf('ACTIVE') == -1) {
				kids[0].className = className+'ACTIVE';
			}
		}
	}

	// open a sub-menu if we find one
	var kids = main.getElementsByTagName("UL");
	if(kids.length > 0) kids[0].style.display = 'block'; // open first UL we find

	// track this item by its ID (it's open)
	document.navTrack[level] = obj;

	// turn on/off the "scroll" graphic (it's on only if all menus are closed)
	if (document.navTrack[0]) {
		document.getElementById('scroll').style.display = 'none';
	} else {
		document.getElementById('scroll').style.display = 'block';
	}
}

// ----------------------------------------------------------------------------------------------------------
function menuClick(obj, level, url) {
	if (document.getElementById(obj)) {
		menuCloseToLevel(level); // close everything down to this item's level
		menuOpenItem(obj, level); // open the requested item
		if (url) updateUI(url, null); // open a page if we got a url
	}
}

// ----------------------------------------------------------------------------------------------------------
// this function defines the following output types:
// type 0: output replaces content of finalDiv, then finalFunc is run if defined
// type 1: output is inserted after existing content of finalDiv, then finalFunc is run if defined
// type 2: output is inserted before existing content of finalDiv, then finalFunc is run if defined
// type 3: finalFunc is called, using output as its only parameter; finalDiv is ignored if defined

/* JD2 01/24/08 */

var vFinalFunc = "";

// ajaxGet(hostURL+appURL+'/olc/get-cart-qty.w?'+vParams, 'cart', null, 0);

function ajaxGet(url, finalDiv, finalFunc, type) {

  vFinalFunc = finalFunc;

  var parms = "";
  var vOptions = null;

  /* Ajax.Updater */
  if (type == 0 || type == 1 || type == 2) {
     if (finalFunc) {  /* run function when complete */

        switch (type) {
           case 0:  /* overwrite div */
              vOptions = {method: 'get',evalScripts: true,onComplete: eval(finalFunc)};
              break;          
           case 1:  /* after div */
              vOptions = {method: 'get',evalScripts: true,insertion: Insertion.Bottom,onComplete: eval(finalFunc)};
              break;
           case 2:  /* before div */
              vOptions = {method: 'get',evalScripts: true,insertion: Insertion.Top,onComplete: eval(finalFunc)};
              break;
        }
     }
     else {
        switch (type) {
           case 0:  /* overwrite div */
              vOptions = {method: 'get',evalScripts: true};
              break;
           case 1:  /* after div */
              vOptions = {method: 'get',evalScripts: true,insertion: Insertion.Bottom};
              break;
           case 2:  /* before div */
              vOptions = {method: 'get',evalScripts: true,insertion: Insertion.Top};
              break;
        }
     }

     var myAjax = new Ajax.Updater(finalDiv,url,vOptions);
  }
  /* Ajax.Request */
  else if (type == 3) {
     vOptions = {method: 'get',onSuccess: evalFunction };
     var myAjax = new Ajax.Request(finalDiv,url,vOptions);
  }
}

function evalFunction(origRequest) {
  eval( vFinalFunc + "('" + origRequest.responseText + "');");
}

/* END JD2 01/24/08 */

// ----------------------------------------------------------------------------------------------------------
function ajaxReturn(http_request, finalDiv, finalFunc, type) {
	if (http_request.readyState == 4) {
		if (navigator.userAgent.indexOf("Mac") != -1)
   { vGo=true; }
  try {
			if (http_request.status == 200) {
				switch(type) {
					case 0:
						try {
							$(finalDiv).innerHTML = http_request.responseText;
       if(document.getElementById("buildArray")) {
        buildArray();
								} 
						} catch(e) {
							alert('ajaxReturn() -- ' + e.message);
						}
						if (finalFunc) eval(finalFunc);
						break;
					case 1:
						try {
							var c = document.getElementById(finalDiv).innerHTML;
							$(finalDiv).innerHTML = c + http_request.responseText;
						} catch(e) {
							alert('ajaxReturn() -- ' + e.message);
						}
						if (finalFunc) eval(finalFunc);
						break;
					case 2:
						try {
							var c = document.getElementById(finalDiv).innerHTML;
							$(finalDiv).innerHTML = http_request.responseText + c;
						} catch(e) {
							alert('ajaxReturn() -- ' + e.message);
						}
						if (finalFunc) eval(finalFunc);
						break;
					case 3:
						try {
							var f = finalFunc+"('"+http_request.responseText+"');";
							eval(f);
						} catch(e) {
							alert('ajaxReturn() -- ' + e.message);
						}
						break;
					default:
						alert('ajaxReturn() -- unknown output type');
				}
			} else {
				alert('ajaxReturn() -- there was a problem with the request: '+http_request.status);
			}
		} catch(e) {
			alert('ajaxReturn() -- ' + e.message);
		}
	}
}


function buildArray()
{
var oScript = document.createElement("script");
    oScript.src = webURL+"/js/loadArray.js";
    document.body.appendChild(oScript); 
}

function getNodeValue(tagName) {
   if (xmlResponse.getElementsByTagName(tagName))
      return xmlResponse.getElementsByTagName(tagName)[0].firstChild.data;
}

function showCart() 
{	
	var d = new Date();
	vParams += d.getMilliseconds(); /*HB working on Q10609: This work around forces IE to get a new version of the page since the URL changes by the millisecond.*/
	ajaxGet(hostURL+appURL+'/olc/get-cart-qty.w?'+vParams, 'cart', null, 0);
}

