cXCoord = 0;
cXWidth = 1;
cYSpace = 2;
cSheetName = 3;
cSheetColour = 4;
cFontColour = 5;
cPickerName = 6;
cPickerLayout = 7;
cPicker1XCoord = 8;
cPicker1YCoord = 9;
cPicker2XCoord = 10;
cPicker2YCoord = 11;
cText = 12;
cDate = 13;
cName = 14;
cEmailUsr = 15;
cEmailHost = 16;
	  
function DrawMessage(EntryNo)
{
  document.writeln('<div id="layer',EntryNo,'" style="width:',DB[EntryNo][cXWidth],'px; position:absolute; left:',DB[EntryNo][cXCoord],'px; top:190px; z-index:2; layer-background-color:',DB[EntryNo][cSheetColour],'; ">');

  document.writeln('<img src="pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_M.gif" width="1" height="40" border="0">')
  document.writeln('<table id="table1" border="0" align="center" width="',DB[EntryNo][cXWidth]-30,'"><tr><td width="',DB[EntryNo][cXWidth]-30,'" colspan="2">');
  document.writeln('<font size=2 color="',DB[EntryNo][cFontColour],'">');
  document.writeln(DB[EntryNo][cText],'<br><br>');
  document.writeln('</font></td></tr><tr><td>');
  document.writeln('<font size=2 color="',DB[EntryNo][cFontColour],'">');
  document.writeln('<p align="left">',DB[EntryNo][cDate],'</p>');
  document.writeln('</font></td><td aligh="right">');
  document.writeln('<font size=2 color="',DB[EntryNo][cFontColour],'">');
  document.write('<p align="right">')
  if (DB[EntryNo][cEmailUsr] != "")
  {
    emladr[emladr.length] = new Array(DB[EntryNo][cEmailUsr], DB[EntryNo][cEmailHost], '');
    document.write('<a href="javascript:openeml(',"'",DB[EntryNo][cEmailUsr],' ',emladr.length-1,"'",')"; name="Email',EntryNo,'"><font size=2 color="',DB[EntryNo][cFontColour],'">');
  }    
  document.write(DB[EntryNo][cName]);
  if (DB[EntryNo][cEmailUsr] != "")
    document.write('</font></a>');
  document.writeln('</p>');
  document.writeln('</font></td></tr></table>');  
  document.writeln('<img src="pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_M.gif" width="1" height="40" border="0">')
  document.writeln("</div>\n");  

  LayerName = "layer"+EntryNo;
  breite = document.getElementById(LayerName).offsetWidth;
  hoehe = document.getElementById(LayerName).offsetHeight;
  
  document.writeln('<div id="layer',EntryNo,'_sheet" style="background-color:',DB[EntryNo][cSheetColour],'; width:',DB[EntryNo][cXWidth],'px; height:',hoehe,'px; position:absolute; left:',DB[EntryNo][cXCoord],'px; top:190px; z-index:0; layer-background-color:',DB[EntryNo][cSheetColour],'; ">');
  
  document.writeln('<div id="layer',EntryNo,'_frm" style="width:',DB[EntryNo][cXWidth],'px; position:absolute; left:0px; top:0px; z-index:1;">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_OL.gif" width="40" height="40" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_O.gif" width="',breite-80,'" height="40" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_OR.gif" width="40" height="40" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_L.gif" width="40" height="',hoehe-80,'" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_M.gif" width="',breite-80,'" height="1" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_R.gif" width="40" height="',hoehe-80,'" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_UL.gif" width="40" height="40" border="0">');
  document.write('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_U.gif" width="',breite-80,'" height="40" border="0">');
  document.writeln('<img src="../pinboardpics/Sheet_',DB[EntryNo][cSheetName],'_UR.gif" width="40" height="40" border="0">');
  
  switch (DB[EntryNo][cPickerLayout])
  {
    case 1:
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',breite/2-20+DB[EntryNo][cPicker2XCoord],'px; top:',hoehe-30-DB[EntryNo][cPicker2YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');    
    case 0:
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',breite/2-20+DB[EntryNo][cPicker1XCoord],'px; top:',DB[EntryNo][cPicker1YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');
      break;
    case 3:
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',DB[EntryNo][cPicker2XCoord]-2,'px; top:',hoehe-26-DB[EntryNo][cPicker1YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',breite-28-DB[EntryNo][cPicker1XCoord],'px; top:',hoehe-28-DB[EntryNo][cPicker2YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');    
    case 2:
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',DB[EntryNo][cPicker1XCoord],'px; top:',DB[EntryNo][cPicker1YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');
      document.writeln('<div id="layer',EntryNo,'_picker" style="width:40px; position:absolute; left:',breite-30-DB[EntryNo][cPicker2XCoord],'px; top:',DB[EntryNo][cPicker2YCoord],'px; z-index:3;">');
      document.writeln('<img src="../pinboardpics/Picker_',DB[EntryNo][cPickerName],'.gif" border="0">');
      document.writeln('</div>');
      break;
  }
  document.writeln('</div></div><br>');
}

function PlaceMessage(EntryNo)
{
  LayerName = "layer"+EntryNo;
  xl = document.getElementById(LayerName).offsetLeft;
  xr = document.getElementById(LayerName).offsetWidth + xl;
  y = document.getElementById(LayerName).offsetTop + document.getElementById(LayerName).offsetHeight;
  yy = document.getElementById("layer0").offsetTop + document.getElementById("layer0").offsetHeight;
  
  FirstLayer = EntryNo - 5;
  if (FirstLayer < 0)
    FirstLayer = 0;
    
  BottomLayer = 1;

  for (Index=FirstLayer;Index<EntryNo;Index++)
  {
    LayerName = "layer"+Index;
    xxl = document.getElementById(LayerName).offsetLeft;
    xxr = document.getElementById(LayerName).offsetWidth + xxl;
    if (((xl <= xxl) && (xxl <= xr)) || ((xl <= xxr) && (xxr <= xr)) ||
        ((xxl <= xl) && (xl <= xxr)) || ((xxl <= xr) && (xr <= xxr)))
    {
      if (yy > document.getElementById(LayerName).offsetTop)
        yy = document.getElementById(LayerName).offsetTop;
      BottomLayer = 0;
    }
  }
  
  LayerName = "layer"+EntryNo;
  if (BottomLayer)
    MoveMessages(EntryNo,EntryNo,(yy - y));
  else
    if (yy < (y + DB[EntryNo][cYSpace]))
      MoveMessages(0,EntryNo-1,(y - yy + DB[EntryNo][cYSpace]));
    else
      MoveMessages(EntryNo,EntryNo,(yy - y - DB[EntryNo][cYSpace]));
}

function MoveMessages(StartIdx,EndIdx,Offset)
{
  for (EntryIdx=StartIdx;EntryIdx<=EndIdx;EntryIdx++)
  {
    LayerName = "layer"+EntryIdx;
    document.getElementById(LayerName).style.top = document.getElementById(LayerName).offsetTop + Offset;
    LayerName = LayerName+"_sheet";
    document.getElementById(LayerName).style.top = document.getElementById(LayerName).offsetTop + Offset;
  }
}

