var selected = 1;
function blah(e) {
  var keynum, key;
  var ev=window.event? event : e
  keynum=ev.charCode? ev.charCode : ev.keyCode
  //alert(keynum);
  if(keynum == 40) { //The Down Arrow
    highlightResult(selected,selected+1);
    return(false);
  } else if(keynum == 38) { //The Up Arrow
    highlightResult(selected,selected-1);
    return(false);
  } else if(keynum == 13) { //The Enter Key
    var obj = document.getElementById("popDiv");
    if(obj.style.display != '') {document.searchForm.submit();return(false);}
    if($get('result'+selected))
      $get('searchWord').value = $get('result'+selected).innerHTML;
    hidePopDiv();
    selected = 1;
    document.searchForm.submit();
    return(false);
  }
  else if(keynum == 8) {return(true);}
  else if(keynum < 48 || keynum > 122) {return(false);}
  return(true);
}
function $get(id) {
  return document.getElementById(id);
}
function $find(name) {
  return (document.getElementsByName(name))? document.getElementsByName(name)[0]:document.createElement('select');
}
function sortBy(field) {
  window.location = 'productSheet.asp?orderby='+field;
}
function toggleDisplay(theId) {
  var elem = $get(theId);
  elem.style.display = (elem.style.display == 'none')? '':'none';
  return(false);
}
function highlightResult(oldSelected,newSelected) {
  if($get('result'+newSelected)) {
    selected = newSelected;
    $get('result'+selected).className = 'searchLinkSelected';
    $get('result'+oldSelected).className = 'searchLink';
  }
}
function searchKeywords(searchText,ev) {
  if(searchText.length <= 0) {hidePopDiv();return(false);}
  if(!blah(ev)) {return(false);}
  if(searchText.length > 0) {
    args = 'callback=searchKeywords&searchText='+searchText;
    ajaxCallback('admin/ajaxFunctions.asp',args, onKeywordsSearched ,'');
  } else {
    hidePopDiv();
  }
  return(true);
}
function onKeywordsSearched(result) {
  if(result.length > 0) {
    $get("popDiv").innerHTML = result;
    var elem = document.getElementById('searchWord');
    showPopDiv(elem);
  } else {hidePopDiv();}
}
function showPopDiv(elem){
  var obj = document.getElementById("popDiv");
  if(obj.style.display == '') {return(true);}
    obj.style.top = (moveYbySlicePos (30, elem)) + 'px';
    obj.style.left = (moveXbySlicePos (0, elem)) + 'px';
    obj.style.display = '';
    //alert(obj.style.top+'--'+obj.style.left+'--'+obj.style.display);
}
function hidePopDiv() {
  var obj = document.getElementById("popDiv");
  setTimeout('document.getElementById("popDiv").style.display = \'none\'',200);
}
function saveOption(optid) {
  var optName = encodeMyHtml($find('Name'+optid).value);
  var optType = $find('Type'+optid);
  var optTypeValue = optType.options[optType.selectedIndex].value;
  var optValue = encodeMyHtml($find('Value'+optid).value);
  //alert(optName+' '+optTypeValue+' '+optValue);
  args = 'callback=saveOption&optname='+optName+'&opttype='+optTypeValue+'&optvalue='+optValue+'&optid='+optid;
  ajaxCallback('ajaxFunctions.asp',args, onOptionSaved ,'');
}
function onOptionSaved(result) {
  //alert(result);
  if(!result) {
    alert('there was a problem saving');
  }
}
function deleteOption(optid) {
  if(!confirm('Are you sure you want to permenantly delete this option?')) {return;}
  args = 'callback=deleteOption&optid='+optid;
  var theRow = $get('row'+optid);
  if(theRow) {theRow.parentNode.removeChild(theRow);}
  ajaxCallback('ajaxFunctions.asp',args, onOptionSaved ,'');
}
function showHide(id,show_hide) {
  var elem = $get(id);
  if(show_hide) {
    elem.style.display = '';
    return(true);
  }
  elem.style.display = (elem.style.display=='none')? '':'none';
}
function changeTextBox(elem) {
  var oldVal = elem.value;
  var oldTab = elem.tabIndex;
  var parentElem = elem.parentNode;
  var newElem = document.createElement('textarea');
  newElem.value = oldVal;
  newElem.setAttribute('onblur','changeTextArea(this);')
  newElem.setAttribute('tabindex',oldTab);
  newElem.setAttribute('rows','4');
  newElem.setAttribute('cols','30');
  parentElem.removeChild(elem);
  parentElem.appendChild(newElem);
  newElem.select();

}
function showOptions(prodId) {
  popDiv('options');
  var theI = $get('iframe');
	var currentTime = new Date();
  theI.src = 'options.asp?productid='+prodId+'&time='+currentTime.getTime();
}
function showCategories(prodId) {
  popDiv('options');
  var theI = $get('iframe');
  theI.src = 'categories.asp?productid='+prodId;
}
function duplicateProduct(prodId) {
  if(confirm('Click \'OK\' to duplicate this product, otherwise, click \'Cancel\'.')) {
    var hiddenAction = document.getElementById('hiddenAction');
    var hiddenValue = document.getElementById('hiddenValue');
    hiddenAction.name = 'action';
    hiddenAction.value = 'duplicate'
    hiddenValue.value = prodId
    document.myForm.submit();
  }
}
function catCheckChanged(elem,prodId) {
  //alert(elem.value);
  var catId = elem.value;
  var rank = document.getElementById('RANKID'+catId).value;
  var checked = elem.checked;
  args = 'callback=updateCategory&catid='+catId+'&prodid='+prodId+'&rank='+rank+'&checked='+checked;
  ajaxCallback('ajaxFunctions.asp',args, onOptionSaved ,'');
  return(false);
}
function changeTextArea(elem) {
  var oldVal = elem.value;
  var oldTab = elem.tabIndex;
  var parentElem = elem.parentNode;
  var newElem = document.createElement('input');
  newElem.setAttribute('type','text');
  newElem.setAttribute('tabindex',oldTab);
  newElem.value = oldVal;
  newElem.setAttribute('onfocus','changeTextBox(this);');
  parentElem.removeChild(elem);
  parentElem.appendChild(newElem);
  newElem.form.elements[newElem.tabIndex+1].focus();
  focusTab(newElem.tabIndex+1);
}
function focusTab(index) {
  var elems = document.getElementsByTagName('input');
  for(i=0;i<elems.length;i++) {
    if(elems[i].tabIndex==index) {
      elems[i].focus();
      return;
    }
  }
}
function moveXbySlicePos (x, img) {
  if (!document.layers) {
    var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
    var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
    var par = img;
    var lastOffset = 0;
    while(par){
      if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
      if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
      if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
      par = macIE45 ? par.parentElement : par.offsetParent;
    }
  } else if (img.x) x += img.x;
  return x;
}
function moveYbySlicePos (y, img) {
  if(!document.layers) {
    var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
    var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
    var par = img;
    var lastOffset = 0;
    while(par){
      if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
      if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
      if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
      par = macIE45 ? par.parentElement : par.offsetParent;
    }
  } else if (img.y >= 0) y += img.y;
  return y;
}
function popDiv(elemId) {
  var theDiv = document.getElementById(elemId);
  var theBackground = document.getElementById('backgroundDiv');
  theDiv.style.display = '';
  theBackground.style.display = '';
  theDiv.className = 'center';
  if(document.all) {
    theBackground.style.top = document.documentElement.scrollTop;
    window.onscroll = function () {
      theBackground.style.top = document.documentElement.scrollTop;
    };
    theDiv.style.left = (document.body.clientWidth - theDiv.style.width.replace('px',''))/2 + "px";
    theDiv.style.top = ((document.documentElement.clientHeight - theDiv.style.height.replace('px',''))/2 + document.documentElement.scrollTop) + "px";
    theBackground.style.position = 'absolute';
  }else {
    theDiv.style.left = (window.innerWidth - theDiv.style.width.replace('px',''))/2 + "px";
    theDiv.style.top = ((window.innerHeight - theDiv.style.height.replace('px',''))/2 + document.documentElement.scrollTop) + "px";
  }
}
function closeDiv(elemId) {
  var theDiv = document.getElementById(elemId);
  var theBackground = document.getElementById('backgroundDiv');
  theDiv.style.display = 'none';
  theBackground.style.display = 'none';
}
function ajaxCallback(request,args,oncomplete,onerror) {
	var req = null;
  var responseDiv = document.getElementById('responseout');
	responseDiv.innerHTML="Started...";
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
  }
	req.onreadystatechange = function() {
		responseDiv.innerHTML="Wait, Loading...";
		if(req.readyState == 4) {
			if(req.status == 200) {
				responseDiv.innerHTML = "Done";
				oncomplete(req.responseText);
			}
			else {
				responseDiv.innerHTML="Error: returned status code " + req.status + " " + req.statusText;
				onError(req.status);
			}
		}
	};
	var currentTime = new Date();
	req.open("POST", request + "?time="+currentTime.getTime(), true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  req.send(args);
	return(false)
}
function onError(result) {
  alert(result);
}
function encodeMyHtml(encodedHtml) {
 encodedHtml = escape(encodedHtml);
 encodedHtml = encodedHtml.replace(/\//g,"%2F");
 encodedHtml = encodedHtml.replace(/\?/g,"%3F");
 encodedHtml = encodedHtml.replace(/=/g,"%3D");
 encodedHtml = encodedHtml.replace(/&/g,"%26");
 encodedHtml = encodedHtml.replace(/@/g,"%40");
 encodedHtml = encodedHtml.replace(/\s/g,"%20");
 return(encodedHtml);
}




//*****************************************************************************
// Do not remove this notice.
// Copyright 2000-2002 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************
function Browser() {
  var ua, s, i;
this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  // Treat any other Gecko browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}
var browser = new Browser();
var activeButton = null;
var closeMenu = false;
setTimeout('menuClose()',1000);
function menuClose() {
  if(closeMenu) {
    if (browser.isIE) {
      document.onmousemove = pageMousedown;
      setTimeout('document.onmousemove=""',1000);
    } else {
      document.addEventListener("mousemove", pageMousedown, true);
      setTimeout('document.removeEventListener("mousemove", pageMousedown, true)',1000);
    }
  }
  closeMenu = true;
  setTimeout('menuClose()',1000);
}
if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);
function pageMousedown(event) {
  var el;
  if (activeButton == null)
    return;
  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);
  if (el == activeButton)
    return;
  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}
function buttonClick(event, menuId) {
  var button;
  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;
  button.blur();
  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }
  if (activeButton != null)
    resetButton(activeButton);
  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;
  return false;
}
function buttonMouseover(event, menuId) {
  var button;
  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;
  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}
function depressButton(button) {
  var x, y;
  button.className += " menuButtonActive";
  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;
  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop - 3;
  }
  if(button.menu.innerHTML.length > 1) {
    button.menu.style.left = x + 150 + "px";
    button.menu.style.top  = (y - 35) + "px";
    button.menu.style.visibility = "visible";
  }
}
function resetButton(button) {
  removeClassName(button, "menuButtonActive");
  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}
function menuMouseover(event) {
  var menu;
  closeMenu = false;
  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;
  if (menu.activeItem != null)
    closeSubMenu(menu);
}
function menuItemMouseover(event, menuId) {
  var item, menu, x, y;
  closeMenu = false;
  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");
  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;
  item.className += " menuItemHighlight";
  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }
  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);
  var maxX, maxY;
  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE) {
    maxX = (document.documentElement.scrollLeft   != 0 ? document.documentElement.scrollLeft    : document.body.scrollLeft)
         + (document.documentElement.clientWidth  != 0 ? document.documentElement.clientWidth   : document.body.clientWidth);
    maxY = (document.documentElement.scrollTop    != 0 ? document.documentElement.scrollTop    : document.body.scrollTop)
         + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;
  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));
  if(item.subMenu.innerHTML.length > 0) {
    item.subMenu.style.left = x + "px";
    item.subMenu.style.top  = y + 5 + "px";
    item.subMenu.style.zIndex ++;
    item.subMenu.style.visibility = "visible";
  }
  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}
function closeSubMenu(menu) {
  if (menu == null || menu.activeItem == null)
    return;
  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.zIndex --;
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}
function menuInit(menu) {
  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;
  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }
  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;
  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }
  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }
  menu.isInitialized = true;
}
function getContainerWith(node, tagName, className) {
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }
  return node;
}
function hasClassName(el, name) {
  var i, list;
  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;
  return false;
}
function removeClassName(el, name) {
  var i, curList, newList;
  if (el.className == null)
    return;
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}
function getPageOffsetLeft(el) {
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);
  return x;
}
function getPageOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}
function SwitchVis(strObj, blnHide, ev){
  if(blnHide){
    div.style.display = 'none';
    return(true);
  }
  var tempx, tempy = -1;
  if(document.all) {
    tempx = event.clientX
    tempy = event.clientY
  } else {
    tempx = ev.pageX
    tempy = ev.pageY
  }
  div = document.getElementById(strObj);
  div.style.display = '';
  if(tempx != -1 && tempy != -1) {
    div.style.top = tempy-25 + 'px';
    div.style.left = tempx+25 + 'px';
  }
}

function OpenWindow(url) {
   remote=window.open(url,'project','width=600,height=500,resizable=yes,status=1');
   if (remote != null){
      if (remote.opener == null)
      remote.opener = self;
   }
}
function buildOptions(strField) {
   for(i=0;i<document.editForm.elements.length;i++){
      if (document.editForm.elements[i].name==strField) {
         strvalue=document.editForm.elements[i].value;
         break;
      }
   }
   document.HiddenForm.field.value=strField;
   document.HiddenForm.strvalue.value=strvalue;
   popupWin = window.open('', 'BuildOptions', 'width=600,height=370,resizable=yes,scrollbars=yes,status=yes');
   document.HiddenForm.submit();
}

function UpdateForm(strFormField){
   if (document.forms['editForm'].elements[strFormField].style.visibility == "hidden"){
      document.forms['editForm'].elements[strFormField].style.visibility = "visible";
      document.forms['editForm'].elements[strFormField].focus();
   }else{
      document.forms['editForm'].elements[strFormField].style.visibility = "hidden";
   }
   return true;
}

function switchVis(ClickedCat){
   var i, nextDiv, level, id, nextid;
   div = document.getElementById(ClickedCat);
   id = parseInt(ClickedCat.substring(0,(ClickedCat.length-1)));
   level = ClickedCat.substring((ClickedCat.length-1),ClickedCat.length);
   nextid = (id+1)+String.fromCharCode(parseInt(level.charCodeAt())+1);
   nextDiv = document.getElementById(nextid);

   if(nextDiv){
      if (nextDiv.style.visibility == "hidden"){
         ExpandTree(ClickedCat,nextid);
      }else{
 	 CollapseTree(ClickedCat,nextid);
      }
   }
}

function ExpandTree(ClickedCat,nextid){
   var div,curId,top,i,foundA,prevId;
   i=0;
   foundPrev = false;

   prevId = getPrevId(ClickedCat);
   prevDiv = document.getElementById(prevId);
   curDiv = document.getElementById(ClickedCat);

   if(prevDiv && prevId != "a0"){
      if(curDiv.style.visibility == "hidden"){
         switchVis(prevId);
      }
   }

   clickedLevel = ClickedCat.substring((ClickedCat.length-1),ClickedCat.length);
   div = document.getElementById(ClickedCat);
   top = div.style.top;
   top = parseInt(top.substring(0,(top.length-2)));
   div = document.getElementById(nextid);

   while (div) {
      curId = div.id;
      id = parseInt(curId.substring(0,((curId.length)-1)));
      level = curId.substring((curId.length-1),curId.length);

      if (level <= clickedLevel){
         break;
      }

      i=i+1;
      div.style.visibility = "visible";
      top = top+25;
      div.style.top = top+"px";

      nextid = (id+1)+String.fromCharCode(parseInt(level.charCodeAt()));
      div = document.getElementById(nextid);

      id=id+1
      while(!div){
  	 foundPrev = false;
	 curLevel = nextid.substring((nextid.length-1),nextid.length);
 	 if(curLevel =="a"){
	    id=id+1;
	    curLevel = String.fromCharCode(parseInt(level.charCodeAt())+1)
	 }
	 nextid = (id)+String.fromCharCode(parseInt(curLevel.charCodeAt())-1);
 	 div = document.getElementById(nextid);

 	 if(document.editForm.NumCategories.value < id) {
 	    foundPrev = true;
	    break;
	 }
      }

      if(foundPrev) break;
   }

   curId = nextid;
   id = parseInt(curId.substring(0,((curId.length)-1)));
   level = curId.substring((curId.length-1),curId.length);
   nextid = (id)+String.fromCharCode(parseInt(level.charCodeAt()));
   div = document.getElementById(nextid);

   while(div){
      tmpTop = div.style.top;
      len = tmpTop.length;
      tmpTop = parseInt(tmpTop.substring(0,(len-2)))+(i*25);
      div.style.top = tmpTop;
      curId = div.id;
      id = parseInt(curId.substring(0,((curId.length)-1)));
      level = curId.substring((curId.length-1),curId.length);
      nextid = (id+1)+String.fromCharCode(parseInt(level.charCodeAt())+1);
      div = document.getElementById(nextid);

      while(!div){
  	 curId = nextid;
	 id = parseInt(curId.substring(0,((curId.length)-1)));
	 level = curId.substring((curId.length-1),curId.length);
	 if(level=="a"){
	    break;
	 }else{
	    nextid = (id)+String.fromCharCode(parseInt(level.charCodeAt())-1);
	    div = document.getElementById(nextid);
	 }
      }
   }
}
function getPrevId(ClickedCat){
   id = parseInt(ClickedCat.substring(0,((ClickedCat.length)-1)));
   level = ClickedCat.substring((ClickedCat.length-1),ClickedCat.length);

   while (id > 0){
      id = id-1;
      prevId = (id)+String.fromCharCode(parseInt(level.charCodeAt())-1);
      prevDiv = document.getElementById(prevId);
      if(prevDiv){
 	 return prevId;
      }
   }
   return null;
}
function CollapseTree(ClickedCat,nextid) {
   var top,div,foundPrev,curLevel, clickedLevel;
   top = 0;
   foundPrev = false;
   div = document.getElementById(nextid);
   clickedLevel = ClickedCat.substring((ClickedCat.length-1),ClickedCat.length);

   while (div){
      if (div.style.visibility == "visible"){
         top = top-25;
	 div.style.visibility = "hidden";
      }
      curId = div.id;
      id = parseInt(curId.substring(0,((curId.length)-1)));
      level = curId.substring((curId.length-1),curId.length);
      nextid = (id+1)+String.fromCharCode(parseInt(level.charCodeAt())+1);

      div = document.getElementById(nextid);

      while(!div){
         foundPrev = false;
	 curLevel = nextid.substring((nextid.length-1),nextid.length);
	 nextid = (id+1)+clickedLevel;
	 div = document.getElementById(nextid);
	 if (div) {
	    foundPrev = true;
	    break;
	 }else{
	    nextid = (id+1)+String.fromCharCode(parseInt(curLevel.charCodeAt())-1);
	    div = document.getElementById(nextid);
	    if (curLevel == clickedLevel){
	       foundPrev = true;
	       break;
	    }
         }
      }
      if(foundPrev) break;
   }

   curId = nextid;
   id = parseInt(curId.substring(0,((curId.length)-1)));
   level = curId.substring((curId.length-1),curId.length);
   nextid = (id)+String.fromCharCode(parseInt(level.charCodeAt()));
   div = document.getElementById(nextid);

   while(div){
      tmpTop = div.style.top;
      len = tmpTop.length;
      tmpTop = parseInt(tmpTop.substring(0,(len-2)))+(top);
      div.style.top = tmpTop;
      curId = div.id;
      id = parseInt(curId.substring(0,((curId.length)-1)));
      level = curId.substring((curId.length-1),curId.length);
      nextid = (id+1)+String.fromCharCode(parseInt(level.charCodeAt())+1);
      div = document.getElementById(nextid);

      while(!div){
	 curId = nextid;
	 id = parseInt(curId.substring(0,((curId.length)-1)));
	 level = curId.substring((curId.length-1),curId.length);
	 if(level=="a"){
	    break;
	 }
	 nextid = (id)+String.fromCharCode(parseInt(level.charCodeAt())-1);
	 div = document.getElementById(nextid);
      }
   }
}
