function TabPageClick(oBtn){
		 aNameParts = oBtn.id.split('_');
	 iBtnClickedIndex = parseInt( aNameParts[2] );         // the index of the clicked button
	 if( oBtn.className == "navUnselected" ){ return true; // already selected 
	 }

	 oBtn.className = "navUnselected";
	 
	 for(i=1;  i <= 10; i++ ){
		 if(i == iBtnClickedIndex ){  
			document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ iBtnClickedIndex).style.display="block"; // show the clicked layer
			continue;
		 }
		 
		 oBtn = document.getElementById("uiTabControl_"+ aNameParts[1] +"_"+ i);
		 if(oBtn){
			document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ i).style.display="none";
			oBtn.className = "navSelected";
		 //}else{
		//	break;
		 }
	 }
}

function RememberSelection(key, oBtn) {

	sName = key + '-selectedTab';

	aNameParts = oBtn.id.split('_');
	iBtnClickedIndex = parseInt( aNameParts[2] );         // the index of the clicked button

	tabSetCookie(sName, iBtnClickedIndex);
	
}

function RecallSelection(key) {

	sName = key + '-selectedTab';

	iBtnClickedIndex = tabGetCookie(sName);
	
	if (iBtnClickedIndex != null) {
		oBtn = document.getElementById('uiTabControl_Main_' + iBtnClickedIndex);
		if (oBtn != null) {
			TabPageClick(oBtn);
		}
	}
}

function tabSetCookie(sName, sValue)
{
  date = new Date();
  date.setDate(date.getDate() + 1);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}

function tabGetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}


