<!-- Begin
// directory.js - provides functions to display information in a variety of formats
// Copyright 2005 SimpleWebDesign.co.uk romiley.co.uk

// Define some constants...
sections = new Array() ;

//---------------------------------------------------------------------------------------------
// displayDirectory - displays the directory based on the input parameters
function displayDirectory( catcode, idx )
{
  // Make sure idx is considered to be a number
  idx *= 1 ;

  // Decide what to display based on the input params
  if( ( catcode == "" ) && ( idx < 0 ) )
  {
    // No input parameters - display the category selection
    replyString = "Please select a category:<BR><BR>" ;

    // Display a link for each category in the database
    currCode = "" ;

    for( i = 0 ; i < categoryList.length ; i++ )
    {
      if( categoryCodeList[i] != currCode )
      {
        currCode = categoryCodeList[i] ;
        replyString += "<A HREF='?catcode=" + categoryCodeList[i] + "'>" + categoryList[i] + "</A><BR>" ;
      }
    }

		// Add a link to display the A-Z Index
		replyString += "<BR><A HREF='?catcode=all'>A-Z Index</A><BR>" ;

    return( replyString ) ;
  }

  // Build a standard params string for use in links
  params = "catcode=" + catcode ;

  // If there's no index, display the category...
  if( idx < 0 )
  {
    // Display the category name
    if( catcode == "all" )
    {
      replyString = "<span class='BodyHeading'>A-Z Index</span><br>" ;
    }
    else
    {
      // Get the proper category title from the catgegory code
      for( catIdx = 0 ; catIdx < categoryList.length ; catIdx++ )
      {
        if( categoryCodeList[catIdx] == catcode )
          break ;
      }

      replyString = "<span class='BodyHeading'>" + categoryList[catIdx] + "</span><br>";
    }

    replyString += "<span class='date'>Click on a business name for more information and contact details:</span><BR><BR>" ;
    replyString += "<TABLE WIDTH='95%' ALIGN='CENTER'>" ;
    replyString += "<TR><TD>Business Name</TD><TD>Type</TD><TD>Description</TD></TR>" ;

    for( i = 0 ; i < directoryName.length ; i++ )
    {
      if( ( catcode != "all" ) && ( directoryCategoryCode[i] != catcode ) )
        continue ;

      replyString += "<TR>" ;
      replyString += "<TD><A HREF='?idx=" + i + "&" + params + "'>" + directoryName[i] + "</A></TD>" ;
      replyString += "<TD>" + directoryClass[i] + "</TD>" ;
      replyString += "<TD>" + directoryStrapline[i] + "</TD>" ;
      replyString += "</TR>" ;
    }

    // Close off the table...
    replyString += "</TABLE><BR><BR>" ;

    // ...add a footer...
    replyString += "<A HREF='./shop.html'>Back to category index</A> " ;

    // ...and return it to the calling page
    return( replyString ) ;
  }

  // If we've got this far, idx must be 0 or greater, so we must want to display an entry

  if( directoryListType[idx] == "Enhanced" )
  {
    // Need to handle this oustide this code, really!
    if( directoryName[idx] == "Gainsborough Interiors" )
      window.location = "gainsborough.html" ;
  }

  replyString = "<span class='heading'>" + directoryName[idx] + "</span><br>";

  // Only display the rest if the business has paid for a full listing
  if( directoryListType[idx] == "Full" )
  {
    if( directoryStrapline[idx] != "" )
      replyString += "<span class='italic'>" + directoryStrapline[idx] + "</span><br><br>" ;

    if( directoryDescription[idx] != "" )
      replyString += directoryDescription[idx] + "<br><br>" ;

    replyString += "<span class='bold'>Contact details:</span><br>";

    if( directoryContactName[idx] != "" )
      replyString += directoryContactName[idx] + "<br>" ;
    replyString += directoryName[idx] + "<br>" ;
    if( directoryBldgName[idx] != "" )
      replyString += directoryBldgName[idx] + "<br>" ;
    if( directoryNo[idx] != "" )
      replyString += directoryNo[idx] + ", " ;
    if( directoryRoad[idx] != "" )
      replyString += directoryRoad[idx] + "<br>" ;
    if( directoryArea[idx] != "" )
      replyString += directoryArea[idx] + "<br>" ;
    if( directoryTown[idx] != "" )
      replyString += directoryTown[idx] + "<br>" ;
    if( directoryPostcode[idx] != "" )
      replyString += directoryPostcode[idx] + "<br>" ;

    replyString += "<TABLE>" ;
    if( directoryPhone1[idx] != "" )
      replyString += "<TR><TD>Phone</TD><TD>" + directoryPhone1[idx] + "</TD></TR><br>" ;
    if( directoryPhone2[idx] != "" )
      replyString += "<TR><TD>Alt. Phone</TD><TD>" + directoryPhone2[idx] + "</TD></TR><br>" ;
    if( directoryFax[idx] != "" )
      replyString += "<TR><TD>Fax</TD><TD>" + directoryFax[idx] + "</TD></TR><br>" ;
    if( directoryEmail[idx] != "" )
      replyString += "<TR><TD>Email</TD><TD>" + directoryEmail[idx] + "</TD></TR><br>" ;
    if( directoryURL[idx] != "" )
    {
      replyString += "<TR VALIGN='top'><TD>Web</TD><TD><A HREF='http://" + directoryURL[idx] ;
      replyString += "' TARGET='_blank'>" + directoryURL[idx] + "</A>" ;
      replyString += "  <SPAN CLASS='italic'>(Link will open in a new window)</SPAN></TD></TR><br>" ;
    }
    replyString += "</TABLE>" ;
  }
  else
    replyString += "<span class='italic'>No further details available</span><br><br>" ;

  // ...add a footer...
  replyString += "<BR><A HREF='./shop.html?catcode=" + catcode + "'>Back to list</A> " ;

  // ...and return it to the calling page
  return( replyString ) ;

}

//---------------------------------------------------------------------------------------------
// URLParse - removes URL encoded parameters (e.g. '+') from the string
function URLParse(str)
{
  str = "" + str;
  while (true)
  {
    var i = str.indexOf ('+') ;
    if (i < 0)
      break;
    str = str.substring(0,i) + ' ' + str.substring(i+1,str.length) ;
  }
  return unescape(str);
}

//---------------------------------------------------------------------------------------------
// getParams - gets parameters from the URL and stuffs them into the args[] array
function getParams()
{
  args = new Array() ;
  var argstring = window.location.search ;
  if( argstring.charAt (0) != '?' )
    return;
  argstring = argstring.substring(1, argstring.length) ;
  var argarray = argstring.split('&') ;
  var i ;
  var singlearg ;

  for( i = 0; i < argarray.length; ++i )
  {
    singlearg = argarray[i].split('=') ;
    if( singlearg.length != 2 )
      continue ;
    var key = URLParse(singlearg[0] ) ;
    var value = URLParse(singlearg[1] ) ;
    args[key] = value;
  }
}
//---------------------------------------------------------------------------------------------

// End -->


