var ArrNavBar = new Array();
var intspeed=1; //number of ms for setTimeout to animate open/close navbar
var intnudge=25; //increment of size we increase/decrease by
prevId = "";	//id of the previous button clicked by a user

function WM_toggle(id,shref) 
{
var i = 0;
var Tempid, toSwap;
var prevImg = new String();	// name of the previous button's image

	navToHref(shref);

}


function WM_toggle_On(id,src1,src2,href) {
//alert(navigator.platform.indexOf('Mac'));
 WM_imageToggle(id+"_IMG",src1,src2);   
if ((document.all) && (navigator.platform.indexOf('Mac')==-1))
 {
	var obj = document.getElementById(id);
	if(document.all[id].style.display == 'none')
		{	obj.style.overflow="hidden";
			obj.style.posHeight=0; 
			obj.style.display="";
			animate(id,1,0,obj.scrollHeight);
		} 
	else {obj.style.overflow="hidden";animate(id,-1,obj.offsetHeight,0);}
 } else if (document.getElementById)
  {
   if(document.getElementById(id).style.display == 'none')
    {
	 document.getElementById(id).style.display = 'block';
    } 
   else { document.getElementById(id).style.display = 'none'; }
   }
 else  { navToHref(href); };
}


function WM_imageToggle(daImage, src1, src2){
   var objStr,obj;
   // alert(daImage+","+src1+","+src2);
   // Check to make sure that images are supported in the DOM.
   if (document.images[daImage])
   {
      myImage = document.images[daImage];
      if(document.images){
        // Check to see whether you are using a name, number, or object
          if(myImage.src.indexOf(src1)>0){
        	myImage.src = src2;
          } else {myImage.src = src1; }
      }
   }
}


// this function will change section images when a menu option is selected
function WM_imageChange(id){
   var fromImage, toImage, posStart, posEnd;
   var strSrcImg = String(document.getElementById("a"+id).innerHTML);

	//retrieving the current image name
	posStart = strSrcImg.lastIndexOf("/");
	posEnd = strSrcImg.lastIndexOf(".gif");
	fromImage = strSrcImg.substring(posStart+1,posEnd-2);
	
	if (strSrcImg.substring(posStart+1,posEnd-2).lastIndexOf("_sl") == -1)
	{// current image is not in selected state
		toImage = fromImage+"_sl"+strSrcImg.substr(posEnd-2,2)+".gif";
	}
	else
	{// current image is in selected state
		toImage = strSrcImg.substring(posStart+1,strSrcImg.lastIndexOf("_"))+strSrcImg.substring(strSrcImg.lastIndexOf("_")+3,posEnd)+".gif";
	}
	if (document.images)
	{
		document.getElementById("a"+id).innerHTML = "<img src='/hbcrewards/images/"+toImage+"' border=0>";
	}
}


// This function is used to open the menu when clicked from the homepage
function OpenParent(el)
{
	var objParent = (intBrowser==0) ? el.parentElement : el.parentNode;
	var currentImg = new String();

	// check browser before swapping image
	if (intBrowser == 2) {}
	else
	{
		if (document.getElementById("Aitem_id").getAttribute("value") != "")
		{currentImg = String(document.getElementById("a"+document.getElementById("Aitem_id").getAttribute("value")).innerHTML);}
	
		if (currentImg.lastIndexOf("_sl") == -1)
		{	// swap the current button image
			WM_imageChange(document.getElementById("Aitem_id").getAttribute("value")); 
			// set the prevId to the current one
			prevId = document.getElementById("Aitem_id").getAttribute("value");
		}
	}
	
	if (el.id!="")
	{   
		if (objParent!=null){
		   
			if (objParent.id!=""){
			   var shref=GetObject("a"+objParent.id,'').href;
			   eval(shref.substr(11))
			   }
			OpenParent(objParent);
			}
		}
	}


// This function will open and close menu
function animate(sid,factor,intstep,intheight)
{	var intinc = intstep + (intnudge * factor);	var obj = document.getElementById(sid);	blndone= factor<0 ? "intinc>intheight" : "intinc<intheight";
	if (eval(blndone))
		{obj.style.posHeight = intinc;
		window.setTimeout("animate('"+sid+"',"+factor+","+intinc+","+intheight+")",intspeed);
		
		//sid = item id from the xml file
		document.getElementById("nav_display").className = "mh"+sid
		}
	else
		{if (factor>0) { 	obj.style.posHeight = intheight;obj.style.overflow=""; }
		else { obj.style.display = "none";}
		}
}


// This function is called when a user clicks Redeem Points button 
// from the homepage
function setoption(obj,newvalue,rb)
{var i;
 var currentImg = new String();

	// check browser before swapping image
	if (intBrowser == 2) {}
	else
	{
		// checking if any menu item was selected
		if (document.getElementById("Aitem_id").getAttribute("value") != "")
		{ 
			currentImg = String(document.getElementById("a"+document.getElementById("Aitem_id").getAttribute("value")).innerHTML);
			// check if the current menu image is not active to swap it
			if (currentImg.lastIndexOf("_sl") == -1)
			{
				// swap the current button image
				WM_imageChange(document.getElementById("Aitem_id").getAttribute("value")); 
				// set the prevId to the current one
				prevId = document.getElementById("Aitem_id").getAttribute("value");
			}
		}
	}
	
if (obj)
   {
   for(i=0;i < obj.length;i++)
	{
	if (obj[i].value==newvalue)
		{
		eval(rb);
		//obj.selectedIndex = i;
		
		}
	}
   return true;
   }
}


// This function is used to link from the sub-nav bar to specific page
function navToHref(strhref, strNewWindow, width, height, WinOptions)
{var strcat="",obj
 var strDefaultCat= "0";

	if (document.getElementById)
	{obj=document.getElementById('cattouse');
		if (obj){strcat=obj.value;}
	}
	else
	{if (document.catalogue)
	   {
	      obj = eval("document.catalogue.cattouse");
	      if (obj){strcat=obj.options[obj.selectedIndex].value+"";}	
	   }
	}

	// need to check if it's 'Select a Catalogue'	
	if ((strhref.toUpperCase().indexOf('NAV=HBCREWARDS') > 0) && (strcat == "") && (strhref.toUpperCase().indexOf('CATTOUSE') > 0)) {}
	else
	{
		strcat = (strcat=="") ? strDefaultCat : strcat;
		var ipos = strhref.toUpperCase().indexOf('MSCSPROFILE')
		if (ipos>0){strhref = strhref.substr(0,ipos);}

		var tt = strhref.replace("CATTOUSE","1")+"CATTOUSE="+ strcat +"&"+mscsprofile;

		//check if the parameter was passed
		if (strNewWindow == null)
			window.location.href = tt;
		else
			{
				if (strNewWindow == "1")
					OpenWindow(tt,width,height,WinOptions);
				else
					window.location.href = tt;
			}
	}

//return true;
}