function showGallery (index, imgname)
{
  toggleLayer('gallery',1); 
  toggleLayer('template',0);
  loadImg(index);

  var elem, vis, txt;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( imgname );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[imgname];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[imgname];
    
  elem.src = "img\/" + img[0] + "-large.jpg";
  caption.innerHTML = cap[0];
  caption.innertext = cap[0];
  galleryTitle.innerHTML = title;
  galleryTitle.innertext = title;
/*
  var tag = document.getElementById('caption');
  if (tag.innerHTML) { 
    tag.innerHTML = cap[0];
  } else if (tag.innertext) { 
    tag.innertext = cap[0]; 
  } 
*/
  for (var i=0; i < length; i++) {
    var thmnlname = "thmnl" + i;
    if( document.getElementById ) // this is the way the standards work
      elem = document.getElementById( thmnlname );
    else if( document.all ) // this is the way old msie versions work
      elem = document.all[thmnlname];
    else if( document.layers ) // this is the way nn4 works
      elem = document.layers[thmnlname];
  
    if (i < img.length) {
      elem.src  = "img\/" + img[i] + "-thmnl.jpg";
    } else {
      elem.src = "img\/spacer.gif";
    }
  }
}

function loadPic (index) {
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( 'popup' );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all['popup'];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers['popup'];

  if (index < img.length) {
    elem.src = "img\/" + img[index] + "-large.jpg";    

    var tag = document.getElementById('caption');
    caption.innerHTML = cap[index];
    caption.innertext = cap[index];
    if (tag.innerHTML) { 
      tag.innerHTML = cap[index];
    } else if (tag.innertext) { 
      tag.innertext = cap[index]; 
    } 
  }
}


function toggleLayer( whichLayer, show )
{

  var disp = show ? 'block' : 'none';
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = disp;
  vis.display = disp;

//    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
//  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function showTemplate(left, right) {
  toggleLayer('template', 1);
  toggleLayer('gallery',0);
  var elem;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( 'tplt0' );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all['tplt0'];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers['tplt0'];

  elem.src = "img\/template\/" + left + ".jpg";   
 
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( 'tplt1' );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all['tplt1'];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers['tplt1'];

  elem.src = "img\/template\/" + right + ".jpg";   
}

function writeGallery() {
/* 
 * Gallery Popup
 */
document.write('<div id="gallery">\n');

document.write('<table width="100%" height="100%" border="0"><tr align=center><td>\n');
document.write('<table width=610 height=360 class="body" valign=top cellspacing=5><tr><td>\n');
document.write('<table width=600 height=350 class="border" valign=top><tr><td>\n');
document.write('  <table width=600 height=350 cellspacing=10 valign=top  class="body">\n');
document.write('    <tr>\n');
document.write('      <td width=100% align="center">\n');
document.write('      <span id="galleryTitle"></span><br><br>\n');
//document.write('      <img id="popup" border=0 height=300 width=300 src="img/spacer.gif" galleryimg="no">\n');
document.write('      <img id="popup" border=0 src="img/spacer.gif" galleryimg="no">\n');
document.write('      <br><span id="caption"></span><br>\n');
document.write('      </td>\n');
document.write('    </tr>\n');
document.write('    <tr><td>\n');
    var wrap = 10; 
    var text = "";
    var i;
    for ( i=0; i<length; ++i ){
      text  = "<a href='javascript:loadPic(" + i + ");'>";
      text += "<img id='thmnl" + i + "' height=50 width=50 src='img\/spacer.gif' border=1>&nbsp;";
      text += "</a>";
      if (i!=0 && (i%wrap)==0) {
        text += "<br>";
      }
      document.write(text);
    }

document.write('    </td></tr>\n');
document.write('    <tr width=100%><td align=right>\n'); 
document.write('      <a href="javascript:toggleLayer(\'gallery\',0)">[close]</a></td></tr>\n');
document.write('  </table>\n');
document.write('</td></tr>\n');
document.write('</table>\n');
document.write('</td></tr></table>\n');
document.write('</td></tr></table>\n');
document.write('</div>\n');

/*
 * Template Popup
 */
document.write('<div id="template">\n');
document.write('<table width="100%" height="100%" border="0"><tr align=center><td>\n');
document.write('<table width=660 height=360 class="body" valign=top cellspacing=0><tr><td>\n');
document.write('<table width=660 height=350 class="border" valign=top><tr><td>\n');
document.write('  <table width=640 height=350 cellspacing=10 valign=top  class="body">\n');
document.write('    <tr>\n');
document.write('      <td width=100% align="center">\n');
document.write('      <img id="tplt0" border=0 height=300 width=300 src="img/spacer.gif" galleryimg="no">\n');
document.write('      <img id="tplt1" border=0 height=300 width=300 src="img/spacer.gif" galleryimg="no"> \n');     
document.write('       </td>\n');
document.write('    </tr>\n');
document.write('    <tr width=100%><td align=right>\n');
document.write('      <a href="javascript:toggleLayer(\'template\',0)">[close]</a></td></tr>\n');
document.write('  </table>\n');
document.write('</td></tr>\n');
document.write('</table>\n');
document.write('</td></tr></table>\n');
document.write('</td></tr></table>\n');
document.write('</div>\n');
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()


