var ThisArtist = "Unknown Artist";
var Art = new Image( );	
var SaveThumbImage = "Huh";
var SaveDescription = "Duh"; 
var ImageWidth = new Number(75);
 

function ShowImage(ThumbImage,resize)
{
   var HTMLStuff = '<html><head><title>Gallery One - ' + ThisArtist + '</title></head>';
   var s = 'style="border-style: none" title = "Click here to return to ' + ThisArtist + '">';

   HTMLStuff = HTMLStuff + '<body>';
   HTMLStuff = HTMLStuff + '<center>';
   HTMLStuff = HTMLStuff + '<a href = "index.htm">';

   if (resize > 504)      // Seven inches at 72 dpi 
   {
	  s = '<img src = "' + ThumbImage+ '" height = "504" ' + s;
   }
   else if (resize < 576 && resize != 0)
   {
      s = '<img src = "' + ThumbImage + '" width = "576" ' + s;
   }
   else
   {
      s = '<img src = "' + ThumbImage + '" ' + s;
   }; 
   
   HTMLStuff = HTMLStuff + s;
   HTMLStuff = HTMLStuff + '</a></center></body></html>';
   document.write();
   document.write(HTMLStuff);
   document.close( );  
   return false;
} 
function TrimString(sString)// Removes all characters which are not digits or decimal from a string   
{ 
   var sNumericOnly = ""; 
   var sValidChars = "1234567890."; 
   for (var iCharPos = 0; iCharPos < sString.length; iCharPos++) 
   { 
      if (sValidChars.indexOf(sString.charAt(iCharPos)) != -1) 
      { 
         sNumericOnly = sNumericOnly + sString.charAt(iCharPos); 
      } 
   } 
   return sNumericOnly; 
}
function formatCurrency(num) 
   {
   var Framed = '';
   if (num.search('old') > 0) 
   {return ('Sold');}
   if (num.search('amed') > 0) Framed=' framed'
   num = num.toString().replace(/\$|\,/g,'');
   if (TrimString(num.valueOf()) == '')
   {return ('&nbsp;');}
   else
   {num = TrimString(num.valueOf());}
   if(isNaN(num))
   num = "0";
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
    num = Math.floor(num/100).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
   return (((sign)?'':'-') + '$' + num + Framed);
}

function WriteCell(ColumnNumber, ThumbImage, Description, Size, Medium, Price)
   {
   var resize = 0; 
	var ThumbExists =	"<img border='0' vspace='10' src='Thumb_" + ThumbImage + 
					   "' title='Click here to view a larger image of \""  +
					   Description +  "\" by " + ThisArtist +"'>"; 	 
   
   Art.src = ThumbImage;
	  
	if (Art.width > 576)
   {resize = -Art.width;}    // landscape format
   if (Art.height > 504)
   {resize = Art.height;};   // portrait format
   
   if (ColumnNumber == 1){document.write('<tr>')};	
   document.write('<td width="100" style="vertical-align:top; text-align:center";>');
   document.write('<a onclick="ShowImage('+"\'"+ThumbImage+"\'" +','+resize+')">');
	
	document.write(ThumbExists);
  
   document.write('<td width="10">&nbsp;</td>');	
   
   document.write('<td valign="top" width="150" ><p class="PhotoLabel">');
   document.write(RemoveChar(Description) + '</p>');
   document.write('<p class="Description">');
   document.write(RemoveChar(Size));
   document.write('<br>' + Medium);
   if (Price != ''){document.write('<br>' + formatCurrency(Price))};
   document.write('&nbsp;</p></td>');
   if (ColumnNumber == 1)
   {document.write('<td width="10">&nbsp;</td>')}
   else
   {document.write('</tr>')}
   Art.src='';		 
}
function DrawHorizontalRules(HowMany)
  { 
   document.write('<tr>');                                                             
   document.write('<td colspan="3" height="1"><hr noshade="" width="100%" style="height:1;color:black;"></td>');
   if(HowMany == 2){
     document.write('<td width="10">&nbsp;</td>');
     document.write('<td colspan="3" height="1"><hr noshade="" width="100%" style="height:1;color:black;"></td>');
     document.write('<td width="10">&nbsp;</td>');
   }
   document.write('</tr>')
}
function StartArtist(Artist)
  { 
   ThisArtist = RemoveChar(Artist);
   document.write();
   document.write('<table width="550" cols ="100,10,150,10,100,10,150" height="100" border="0" align="left">');
}
function ConvertToFraction(number)
  { 
   var n = number.indexOf(".",1)
 
	if( n == false ){return number;}
	else
	{
	var s1 = number.substring(0,n);
	var s2 = number.substring(n,number.length); 
 
	if ( s2 == ".5" ) {s1 = s1 + "½"}
	else if ( s2 == ".25" ) {s1 = s1 + "¼"} 
	else if ( s2 == ".75" ) {s1 = s1 + "¾"} 
	else 
	   {alert("Undefined fractional value for '" + number + "'");	
	    return number;};	
	}
	return s1;
}
function RemoveChar(s) 
{
   var n;

   do {     // Replace e' with é
	n = s.indexOf("e'",1); 
	if (n > 0){s = s.substring(0,n) + "é" + s.substring(n+2,s.length);} 
	}while (n > 0 ); 

   do {     // Replace 1/2 with ½
	n = s.indexOf("1/2",1); 
	if (n > 0){s = s.substring(0,n) + "½" + s.substring(n+3,s.length);} 
	}while (n > 0 ); 

   do {     // Replace 1/4 with ½
	n = s.indexOf("1/4",1); 
	if (n > 0){s = s.substring(0,n) + "¼" + s.substring(n+3,s.length);} 
	}while (n > 0 ); 

   do {     // Replace 1/8 with &#8539;
	n = s.indexOf("1/8",1); 
	if (n > 0){s = s.substring(0,n) + "&#8539;" + s.substring(n+3,s.length);} 
	}while (n > 0 ); 

   do {     // Replace 5/8 with &#8541;
	n = s.indexOf("5/8",1); 
	if (n > 0){s = s.substring(0,n) + "&#8541;" + s.substring(n+3,s.length);} 
	}while (n > 0 ); 

	return s;
}


