/**
 * Copyright © 2001-2003 AZ Software & Jacob Goldin (jake@fotoalbumz.com). All rights reserved.
 * To the best of my knowledge, the code below is the first and the only data-driven
 * image display tool and rotator where the client (browser) does all the work. This makes the
 * image rotator completely server-independent, and facilitates maintainance.
 * I call it Read-Only Clent Side database (ROCS DB)
 *
 */

// how many picutes in a single row
var count = 1;


/**
 * Popup a new browser window
 * @param url URL to navigate to
 */
function popup(url) 
{
//  return window.open(url, 'popup','toolbar=no,location=no,resizable=yes, directories=no,status=yrd,menubar=no,scrollbars=yes,width=800,height=640,x=0,y=0');
  var newWindow = window.open(url, 'popup','toolbar=no,location=no,resizable=yes, directories=no,status=yrd,menubar=no,scrollbars=yes,width=800,height=640,x=0,y=0');
  newWindow.focus();
  return newWindow;
}


// debug
//function popup(url) {return window.open(url);
//}


/**
 * Popup a new small browser window
 * @param url URL to navigate to
 */
function popupSmall(url)
{
/*
//  return window.open(url, 'popupSmall','toolbar=no,location=no,resizable=yes, directories=no,status=yrd,menubar=no,scrollbars=yes,width=640,height=480,x=0,y=0');
  var newWindow = window.open(url, 'popupSmall','toolbar=no,location=no,resizable=yes, directories=no,status=yrd,menubar=no,scrollbars=yes,width=640,height=480,x=0,y=0');
  newWindow.focus();
  return newWindow;
*/
}


/**
 * DEBUG 
 * Popup a new small browser window
 * @param url URL to navigate to
 */
//function popupSmall(url) {return window.open(url);
//}


/**
 * Popup a new browser window
 * @param url URL to navigate to
 */
function popupAll(url) {return window.open(url);}




function orderArray(array)
{
  var i=0;
  var j = 0;
  var orderedArray = new Array();

  for(i=0; i<array.length; i++)
  {
    if(array[i] == null || array[i] == 0) continue;
    orderedArray[j] = array[i];
    j++;
  }

//  for(i=0; i<orderedArray.length; i++)
//  {
//    alert("orderedArray[" + i + "] = " + orderedArray[i]);
//  }
  return orderedArray;
}


/**
 * Create an array with consecutive indices
 */
function orderCategories()
{
  var i=0;
  var j = 0;
  for(i=0; i<categories.length; i++)
  {
    if(categories[i] == null || categories[i] == 0) continue;
    orderedCategories[j] = categories[i];
//    alert("cat[" + i + "] = " 
//      + categories[i] 
//      + "; orderedCat[" + j + "] = "
//      + orderedCategories[j]);
    j++;
  }
}



/**
 * Create an array of items with consecutive indices
 */
function orderItems()
{
  var i=0;
  var j = 0;
  for(i=0; i<items.length; i++)
  {
    if(items[i] == null || items[i] == 0) continue;
//    alert("item = " + items[i]);
    orderedItems[j] = items[i];
    j++;
  }
}


/**
 * Dynamically generate HTML page displaying all categories and thumbnail images.
 */
function display()
{
  var i=0;

  for(i=0; i<orderedCategories.length; i++)
  {
    if(orderedCategories[i] == null || orderedCategories[i] == 0) continue;
    displaySingleCategory(orderedCategories[i]);
  }
}


/**
 * Dynamically generate HTML page displaying a single category with thumbnail images.
 */
function displaySingleCategory(catId)
{
  var i=0;
  var j=0;
  var str;
  var picCount = 0;
  var startTag = false;
  var rowCount = 0;

    if(catId == null)
    {
      catId = queryField("category");
    }

    var cInfo = orderedCategories[catId].split("|");
    var cName = cInfo[0];
    var cDesc = cInfo[1];
    var cPic = cInfo[2];

    if(cName == null || cName == 0) return;
    if(cDesc == null || cDesc == 0) cDesc = "&nbsp;";

    document.write("<table width=\"80%\" align=\"center\">");
    document.write("<tr><td align=\"center\"><span class=header>" + cName + "</span></td></tr>");
    document.write("<tr><td align=\"left\"><span class=header2>" + cDesc + "</span></td></tr>");
    document.write("</table>");
    document.write("<table width=\"80%\" align=\"center\" border=\"0\" CELLSPACING=\"10\" CELLPADING=\"10\">");
    for(j=0; j<orderedItems.length; j++)
    {
      if(orderedItems[j] == null || orderedItems[j] == 0)
      {
        continue;
      }

      str = orderedItems[j];
      var info = str.split("|");
      if(info[1].toLowerCase() != cName.toLowerCase()) continue;

      // description
//      if(info[5] == null || info[5] == 0) info[5] = "&nbsp;";

      if(picCount == 0)
      {
        document.write("<tr>");
        startTag = true;
      }
      picCount++;


      displayThumbnail(j, rowCount);

      if(picCount == count || j >= orderedItems.length-1)
      {
        startTag = false;
        document.write("</tr>");
        picCount = 0;
        rowCount++;
      }  
    } // images

    if(startTag)
    {
      document.write("</tr>");
      rowCount++;
    }
    document.write("</table>");
    document.write("<br>");
}



/**
 * Dynamically generate HTML page displaying all categories represented by a random thumbnail image.
 */
function displayCategories()
{
  var i=0;
  var j=0;
  var str;
  var picsCount = 0;
  var startTag = false;

  document.write("<table width=\"80%\" align=\"center\" border=\"0\" CELLSPACING=\"10\" CELLPADING=\"10\">");
  
  var rowCount = 0;
  for(i=0; i<orderedCategories.length; i++)
  {
    if(orderedCategories[i] == null || orderedCategories[i] == 0)
    {
      continue;
    }
    var cInfo = orderedCategories[i].split("|");
    var cName = cInfo[0];
    var cDesc = cInfo[1];
    var cPic = cInfo[2];

    if(cDesc == null || cDesc == 0)
    {
      cDesc = "&nbsp;";
    }

    if(cName == null || cName == 0)
    {
      continue;
    }
    var num = 0;
    var pics = new Array();

    for(j=0; j<orderedItems.length; j++)
    {
      if(orderedItems[j] == null || orderedItems[j] == 0)
      {
        continue;
      }
      str = orderedItems[j];
      var info = str.split("|");

      if(info[1].toLowerCase() != cName.toLowerCase()) continue;
      pics[num++] = str;
    } // images
    
    if(num <= 0)
    {
      continue;
    }

    var randomInfo = rand(num);

//    alert("random = " + randomInfo);
    var info = pics[randomInfo].split("|");
//    alert("random = " + randomInfo + "; info = " + info);

    if(picsCount == 0)
    {
      document.write("<tr>");
      startTag = true;
    }
    picsCount++;

    var url = "<a href=\"singlecategory.html?category=" + i + "\">";

    var descCell = "<td width=\"30%\" align=\"center\">"
      + "<span class=header3><center>" 
      + url
      + cName + "</a></center></span>"
      + cDesc
      + "</td>";

    var picCell = "<td>"
      + url
      + "<img src=\"" + getUrl(commonHost, info[3]) + "\" width=\"164\" border=\"4\""
      + " alt="
      + getUrl(commonHost, info[2])
      + "></a></td>";


//    alert(rowCount);

    document.write("<tr><td colspan=3><hr></td></tr>");
    if(rowCount%2 == 0)
    {
      document.write(descCell);
      document.write(picCell);
   }
   else
   {
      document.write(picCell);
      document.write(descCell);
   }

//    alert(url);

    if(picsCount == count || i >= orderedCategories.length-1)
    {
      startTag = false;
      document.write("</tr>");
      picsCount = 0;
      rowCount++;
    }  
  } // categories

  if(startTag)
  {
    document.write("</tr>");
    rowCount++;
  }
  document.write("</table>");
}




/* price calculation routines*/

var quant1 = new Array (0, 15, 30, 50, 85);
var quant2 = new Array (0, 10, 20, 30, 55);
var quant3 = new Array (0, 7, 14, 25, 45);
var quant4 = new Array (0, 5, 10, 15, 20);

var quantMatrix = new Array();
quantMatrix[0] = quant1;
quantMatrix[1] = quant2;
quantMatrix[2] = quant3;
quantMatrix[3] = quant4;


var disc = new Array (0, 5, 10, 15, 20);

var priceCat = new Array (0.00, 10.00, 18.00, 22.70);


function round2(number)
{
  var tmp = new Number(Math.round(number*100)/100).toString();

  if(tmp.indexOf(".") == -1)
  {
    tmp += ".00";
  }
  else if(tmp.length - tmp.indexOf(".") == 2)
  {
//alert("tmp = " + tmp + "; index = " + tmp.indexOf(".") + "; len = " + tmp.length);
    tmp += "0";
  }
  return tmp;
}



function getDiscountSchedule(price)
{
  var i=0;
  // what price category?
  var catNum = 0;
  for(i = 0; i<priceCat.length-1; i++)
  {
    if(price > priceCat[i] && price <= priceCat[i+1])
    {
      catNum = i;
      break;
    }  
  }
  return quantMatrix[catNum];
}



function getAddToCart(id, name, price)
{
  var str = "";
  var strMax = "";
  var quant = getDiscountSchedule(price);
  
  str += "<table border=1 cellspacing=2 cellpadding=4>";
  var newPrice;
  for(i = 0; i<disc.length; i++)
  {
    if(i == disc.length - 1)
    {
      strMax = " and more";
    }
    else
    {
      strMax = " - " + quant[i+1];
    }
    newPrice = round2((100 - disc[i])*price/100);

//alert(quant[i]);

    str += "<tr><td valign=\"bottom\">";
    str += getSingleAddToCart(id, name, newPrice, eval(quant[i] + 1));
    str += "</td>";
    str += ("<td nowrap><span class=\"error\" valign=\"top\">$"
      + newPrice
      + "</td><td nowrap valign=\"center\"></span><span class=\"content\"> when you buy "
      + (quant[i] + 1)
      + strMax
      + "</span></td>");

    str += "</tr>";
  }
  str += "</table></form>";
  return str;
}


function getSingleAddToCart(id, name, price, quantity)
{
  var addToCart = "<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">"
    + "<input type=\"hidden\" name=\"cmd\" value=\"_cart\">"
    + "<input type=\"hidden\" name=\"business\" value=\"saysnj@comcast.net\">"
    + "<input type=\"hidden\" name=\"item_name\" value=\""
    
    + name

    + "\">"
    + "<input type=\"hidden\" name=\"item_number\" value=\""
    
    + id

    + "\">"
    + "<input type=\"hidden\" name=\"amount\" value=\""

    + price

    + "\">"
//    + "<input type=\"hidden\" name=\"image_url\" value=\"http://look4gift.com/images/logo.gif\">"

//    + "<input type=\"hidden\" name=\"return\" value=\"http://68.36.179.124/says/thankyou.html\">"
//    + "<input type=\"hidden\" name=\"cancel_return\" value=\"http://68.36.179.124/says/cancel.html\">"
//    + "<input type=\"hidden\" name=\"image_url\" value=\"http://localhost/images/logo.gif\">"

    + "<input type=\"hidden\" name=\"return\" value=\"http://look4gift.com/thankyou.html\">"
    + "<input type=\"hidden\" name=\"cancel_return\" value=\"http://look4gift.com/cancel.html\">"

    + "<input type=\"hidden\" name=\"quantity\" value=\""
    
    + quantity

    + "\">"
    + "<input type=\"hidden\" name=\"currency_code\" value=\"USD\">"
    + "<input type=\"image\" src=\"https://www.paypal.com/images/x-click-but22.gif\" border=\"0\" name=\"submit\""
    + " alt=\"Make payments with PayPal - it's fast, free and secure!\">"
    + "<input type=\"hidden\" name=\"add\" value=\"1\"></form>"
    ;

  return addToCart;
}





function displayThumbnail(item, row)
{
  var info = orderedItems[item].split("|");
  //category name
  var id = info[0];
  var cName = info[1];
  var name = info[2];
  var desc = info[5];
  var price = info[6];
  var shipping = info[7];


    var viewCart = "<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">"
      + "<input type=\"hidden\" name=\"cmd\" value=\"_cart\">"
      + "<input type=\"hidden\" name=\"business\" value=\"saysnj@comcast.net\">"
      + "<input type=\"image\" src=\"https://www.paypal.com/images/view_cart_02.gif\" border=\"0\" name=\"submit\""
      + " alt=\"Make payments with PayPal - it's fast, free and secure!\">"
      + "<input type=\"hidden\" name=\"display\" value=\"1\"></form>";


    var cart = "<td nowrap>" + getAddToCart(id, name, price) + "</td>";


    var urlName = replaceStandard(cName);

    var url = "<a href=\"picture.html?&category="
          + urlName
          + "&number="
          + item
          + "\">";

    var picCell = "<td align=\"center\" nowrap>"
          + url
          + "<img src=\"" + getUrl(commonHost, info[3]) + "\" width=\"164\" border=\"4\""
          + " alt=\"" 
          + name
          + " "
          + info[3]
          + "\"></a></td>";

    var descCell = "<td nowrap align=\"center\">"
      + "<span class=header3><center>" 
      + url
      + "#"
      + info[0]
      + "&nbsp;&nbsp;"
      + name + "</a></center></span>"
      + desc
      + "</td>";

    document.write("<tr><td colspan=3><hr></td></tr>");

    if(row%2 == 0)
    {
      document.write(cart);
      document.write(descCell);
      document.write(picCell);
   }
   else
   {
      document.write(picCell);
      document.write(descCell);
      document.write(cart);
   }

}











/**
 * Select a random picture
 */
function getRandomPicture(category)
{
  if(category == null || category == 0) category = queryField("category");
  if(category == null || category == 0) return;

  var imageNum = 0;
  while(true)
  {
    imageNum = rand(orderedItems.length);
    if(orderedItems[imageNum] == null || orderedItems[imageNum] == 0)
    {
      continue;
    }

    var str = orderedItems[imageNum];
    var info = str.split("|");

    var url = replaceStandard(category.toLowerCase());
    var nameFromInfo = replaceStandard(info[0].toLowerCase());
    if(url.toLowerCase() != nameFromInfo.toLowerCase()) continue;
    return getUrl(commonHost, info[2]);
  }
}


/**
 * Select a random picture number
 */
function getRandomPictureNumber()
{
  var imageNum = 0;
  while(true)
  {
    imageNum = rand(orderedItems.length);
    if(orderedItems[imageNum] == null || orderedItems[imageNum] == 0)
    {
      continue;
    }
    return imageNum;    
  }
}


/**
 * Select next picture number
 */
function getNextNumber(number)
{
  var imageNum = number;
  while(true)
  {
    imageNum++;
    if(imageNum >= orderedItems.length)
    {
      imageNum = 0;
    }

    if(orderedItems[imageNum] == null || orderedItems[imageNum] == 0)
    {
      continue;
    }
    return imageNum;
  }
}


/**
 * Select previous picture number
 */
function getPrevNumber(number)
{
  var imageNum = number;
  while(true)
  {
    imageNum--;
    if(imageNum < 0)
    {
      imageNum = orderedItems.length - 1;
    }

    if(orderedItems[imageNum] == null || orderedItems[imageNum] == 0)
    {
      continue;
    }
    return imageNum;    
  }
}


/**
 * Get picture index by URL
 */
function getPictureInfoByUrl(pictureUrl)
{
  var i;
  for(i=0; i<orderedItems.length; i++)
  {
    var str = orderedItems[i];
    var info = str.split("|");
    if(pictureUrl.toLowerCase() == info[2].toLowerCase())
    {
      return i;
    }
  }
  return -1;
}


/**
 * Get picture index by thumbnail URL
 */
function getPictureInfoByUrl(thumbnailUrl)
{
  var i;
  for(i=0; i<orderedItems.length; i++)
  {
    var str = orderedItems[i];
    var info = str.split("|");
    if(thumbnailUrl.toLowerCase() == info[1].toLowerCase())
    {
      return i;
    }
  }
  return -1;
}


/**
 * Select a particular picture from the
 */
function getNextPicture(imageNum)
{
  if(orderedItems[imageNum] == null || orderedItems[imageNum] == 0)
  {
    return "";
  }

  var str = orderedItems[imageNum];
  var info = str.split("|");

  return getUrl(commonHost, info[2]);
}





/**
 * Display logo
 */
function displayLogo()
{
  orderCategories();
  orderItems();
//  document.write("<center><img src=\"images/logo.gif\" width=\"400\" height=\"30\"></center>");
  document.write("<center><span class=\"huge\">look4gift</span></center>");
  document.write("<center><span class=\"header\">Importer of Crystals - Sterling Silver Jewelry - Crafts - Gifts Since 1998</span></center><br>");
}


/**
 * Display words logo
 */
function displayWordsLogo()
{
  orderCategoties();
  orderItems();
  document.write("<center><span class=\"header\">look4gift: Importer of crystals, sterling silver jewelry, crafts, gifts since 1998</span></center>");
}


/**
 * Display copyright information
 */
function displayCopyright()
{
  document.write("<center><span class=\"copyright\">Copyright © 2003 <A HREF=\"mailto:saysnj@comcast.net\">look4gift</A>.All rights reserved.</span></center>");
  document.write("<center><span class=\"copyright\">This site was designed by <A HREF=\"mailto:jake@az.nu\">AZ Software</a></span></center>");
  document.write("<center><span class=\"copyright\">Read-Only Clent Side DataBase (ROCS DB) concept is a property of <A HREF=\"mailto:jake@az.nu\">Jacob Goldin</a></span></center>");
}




/**
 * Construct URL from host name and absolute file name
 * @param host host name, like http://localhost/photos or http://localhost/photos/
 * @param name absolute file name, like C:\photos\1.jpg
 * @return valid URL, like http://localhost/photos/1.jpg
 */
function getFileUrl(host, name)
{
  return getValidHost(host) + getFileName(name);
}


/**
 * Construct URL from host name and relative file name
 * @param host host name, like http://localhost/photos or http://localhost/photos/
 * @param name relative file name, like photos\1.jpg
 * @return valid URL, like http://localhost/photos/1.jpg
 */
function getUrl(host, name)
{
  name = replace(name, "\\", "/");
  if(name.charAt(0) == "/")
  {
    name = name.substring(1, name.length);
  }
  return getValidHost(host) + name;
}


/**
 * Get valid host name, append forward slash if needed
 * @param host host name
 * @return valid host name
 */
function getValidHost(host)
{
  if(host != null && host.length > 0)
  {
    if(host.charAt(host.length - 1) != "/")
    {
      host += "/";
    }
  }
  return host;
}


/**
 * Get file name only, strip path
 * @param name full file name, may contain path
 * @return file name without path
 */
function getFileName(name)
{
  var fileName = "";
  name = replace(name, "\\", "/");
  if (name.lastIndexOf("/") !=-1)
  {
    var firstpos = name.lastIndexOf("/") + 1;
    var lastpos = name.length;
    fileName = name.substring(firstpos,lastpos);
  }
  else
  {
    fileName = name;
  }
  return fileName;
}



function search()
{
  var i = 0;
  var id;
  var cName;
  var name;
  var desc;
  var price;
  var info;
  var rowCount = 0;
  var resCount = 0;

  var searchBy = queryField("searchBy");
  var sId = queryField("id");
  var sDesc = queryField("desc");
  var sMinPrice = queryField("minPrice");
  var sMaxPrice = queryField("maxPrice");

  if(sMinPrice <= 0) sMinPrice = 0;
  if(sMaxPrice <= 0) sMaxPrice = 1000000;

  document.write("<table width=\"80%\">");
  for(i=0; i<orderedItems.length; i++)
  {
    info = orderedItems[i].split("|");
    id = info[0];
    cName = info[1];
    name = info[2];
    desc = info[5];
    price = info[6];

    if(searchBy == "id")
    {
      if(id == sId)
      {
        document.write("<tr>");
        displayThumbnail(i, rowCount++);
        document.write("</tr>");
      }
    }
    else if(searchBy == "desc")
    {
      if(
        cName.toLowerCase().indexOf(sDesc.toLowerCase()) != -1 ||
        name.toLowerCase().indexOf(sDesc.toLowerCase()) != -1 ||
        desc.toLowerCase().indexOf(sDesc.toLowerCase()) != -1
        )
      {
        document.write("<tr>");
        displayThumbnail(i, rowCount++);
        document.write("</tr>");
      }
    }
    else if(searchBy == "price")
    {
      if(price - sMinPrice >= 0 && price - sMaxPrice <= 0)
      {
        document.write("<tr>");
        displayThumbnail(i, rowCount++);
        document.write("</tr>");
      }
    }
  }
  document.write("</table>");

  if(rowCount <= 0 && searchBy != "")
  {
    document.write("<span class=header3><center>No data found matching your criteria</center></span>");
  }
}



function displayCategoryMenu()
{
  var urls = new Array;
  var pageNames = new Array;
  var descs = new Array;
  var indicators = new Array;

  document.write("<hr>");

  for(i=0; i<orderedCategories.length; i++)
  {
    urls[i] = "singlecategory.html?category=" + i;
    pageNames[i] = orderedCategories[i].split("|")[0];
    descs[i] = orderedCategories[i].split("|")[1];
    indicators[i] = orderedCategories[i].split("|")[2];
  }
  displayGenericMenu(pageNames, urls, descs, indicators, "", 0, 80);
}



var bnames=new Array
(
  "Home",
  "Order",
  "Shipping",
  "Return",
  "Search",
  "About"
);
  

var bimages=new Array
(
  "images/home.gif",
  "images/order.gif",
  "images/shipping.gif",
  "images/areturn.gif",
  "images/search.gif",
  "images/aboutus.gif"
);

var bimages_over=new Array
(
  "images/home1.gif",
  "images/order1.gif",
  "images/shipping1.gif",
  "images/areturn1.gif",
  "images/search1.gif",
  "images/aboutus1.gif"
);

var bimages_inactive=new Array
(
  "images/home2.gif",
  "images/order2.gif",
  "images/shipping2.gif",
  "images/areturn2.gif",
  "images/search2.gif",
  "images/aboutus2.gif"
);


var burls=new Array
(
  "index.html",
  "order.html",
  "shipping.html",
  "return.html",
  "search.html",
  "about.html"
);



function displayButtonMenu(pageName, names, images, images_over, images_inactive, urls)
{
  document.write("<center><form name=\"menu\" method=\"GET\">");
  var str = "";
  for(i=0; i<urls.length; i++)
  {
    if(pageName == names[i])
    {
      str = "<img name=\""
        + names[i]
        + "\" src=\""
        + images_inactive[i]
        + "\">&nbsp;";
    }
    else
    {
      str = "<img name=\""
        + names[i]
        + "\" src=\""
        + images[i]
        + "\" onmouseover=\"document.images['"
        + names[i]
        + "'].src='"
        + images_over[i]
        + "';return true;\""
        + " onmouseout=\"document.images['"
        + names[i]
        + "'].src='"
        + images[i]
        + "';return true;\" onclick=\"action='"
        + urls[i]
        + "';submit();\">&nbsp;";
    }

//alert(str);

    document.write(str);
  }
  document.write("</form></center>");
}



///////////////////////////////////////////////////////////////////////
// Dynamic menu support -- start
///////////////////////////////////////////////////////////////////////


pageNames = new Array
(
  "Home",
  "Order",
  "Shipping",
  "Return",
  "Search",
  "About Us"
);



pageUrls = new Array
(
  "index.html?dummy=dummy",
  "order.html?dummy=dummy",
  "shipping.html?dummy=dummy",
  "return.html?dummy=dummy",
  "search.html?dummy=dummy",
  "about.html?dummy=dummy"
);


/*
function showDescription(descr)
{
  document.MENUFORM.AAA.value = descr;
}
*/

function displayGenericMenu(pageNames, pageUrls, descs, indicators, pageName, userId, width)
{
//  document.write("<form name=\"MENUFORM\" method=\"GET\"><span class=\"header\"><input type=\"text\" name=\"AAA\"></span>");


  document.write("<span class=error><center>Crystal Giftware</center></span>\r\n");

  var tableDesc = "<table border=\"0\" align=\"center\" bgcolor=\"#eeeeff\" cellspacing=\"1\" cellpadding=\"1\">";

  if(userId == null || userId == "")
  {
    userId = queryField("USER_ID");
  }

  document.write("<span class=header>\r\n");

  var i=0;
  var strLen = 0;
  var str = "";

  for(i=0; i<pageNames.length; i++)
  {
    if(indicators[i].toLowerCase() == "separate")
    {
      strLen = 0;
      str += tableDesc;
      str += "<tr><td align=center><span class=error>";
      str += "<a href=\"" 
          + pageUrls[i]
//          + "\" onMouseOver=\"showDescription('"
//          + descs[i]
//          + "');"
          + "\">"
          + pageNames[i]
          + "</a>\r\n";
      str += "</span></td></tr></table>";
      document.write(str);
      str = "";    
      continue;
    }


    if(strLen == 0)
    {
      str += tableDesc;
      str += "<tr>";
    }
    else
    {
      str += "<td>&nbsp;|&nbsp;</td>\r\n";
      strLen += 3;
    }
    
    str += "<td nowrap>\r\n";
    if(pageName == pageNames[i])
    {
      str += ("<font size=3 color=red>" + pageNames[i] + "</font>");
    }
    else
    {
      if( pageUrls[i].indexOf("javascript") == -1 &&
          pageUrls[i].indexOf("mailto") == -1 &&
          pageUrls[i].indexOf("http") == -1)
      {
        str += "<a href=\"" + pageUrls[i]
          + "&USER_ID="
          + userId
//          + "\" onMouseOver=\"showDescription('" 
//          + descs[i]
//          + "');"
          + "\">"
          + pageNames[i]
          + "</a>\r\n";
      }
      else
      {
        // special cases
        if( pageUrls[i].indexOf("javascript") != -1 ||
          pageUrls[i].indexOf("mailto") != -1)
        {
          str += "<a href=\"" + pageUrls[i]
            + "\">"
            + pageNames[i]
            + "</a>\r\n";
        }
        else
        {
          // http
          str += "<a href=\"" + pageUrls[i]
            + "\" target=_blank"
            + ">"
            + pageNames[i]
            + "</a>\r\n";
        }
      }
    }

    strLen += pageNames[i].length;
    if(strLen > width)
    {
      str += "</td></tr></table>";
      strLen = 0;
    }
    else
    {
      str += "</td>\r\n";
    }
    document.write(str);
//    alert(str);
    str = "";
  }
  if(strLen == 0)
  {
    document.write("</table>\r\n");
  }
  else
  {
    document.write("</tr></table>\r\n");
  }
  document.write("</span>\r\n");
//  document.write("</form>");
}

///////////////////////////////////////////////////////////////////////
// Dynamic menu support -- end
///////////////////////////////////////////////////////////////////////

