
// called from ajax.js
function processGallery(obj){
      try {

      vNum1 = 0;
      // get all the data
      a=obj.getElementsByTagName('title');
      b=obj.getElementsByTagName('image');
      c=obj.getElementsByTagName('year');
      d=obj.getElementsByTagName('media');
      e=obj.getElementsByTagName('size');
      f=obj.getElementsByTagName('price');
      if (a.length == 0) {
      	processError(errorOutput);
        return;
      	}
      insertData = "";

      insertData += "<div id='thumbnails'>";
      insertData += "<table border=0><tr><td align=centre valign=top><h3>" + vRolloverHeader + "</h3>";
      while (vNum1<b.length) {
	  // lets deal with those pesky empties	
	  doConvertBlanks(vNum1)
      	
	  insertData += "<a class=gallerylink href = 'javascript:return;' onmouseover = 'doRollover("+vNum1+")' onmouseout = 'doRollover(-1)'>";
	  insertData += "<img name='Image"+vNum1+"' src='"+graphicDir + vImage+"' alt='"+ vTitle +"'></a>&nbsp;&nbsp;";
 		if ((vNum1+1)%vRolloverLength == 0) {
		insertData += "<br><br>";
		}
            vNum1++;

	}
      insertData += "</div>";
      
      insertData += "<br><br></td><td align=centre width=50></td><td><center>";
      insertData += "<div id='rollovercontainer'>";
      insertData += "<img name=picture src='"+graphicDir + blankImage+"'>";
      insertData += "<br><form name='gallery'>";
      insertData += "<textarea name='title' readonly disabled></textarea><br>";
      insertData += "</form></center></td></tr></table>";
      insertData += "</div>";

      document.getElementById ('dataArea').innerHTML = insertData;

      }
      catch (errorOutput) {
	  processError(errorOutput);
      }
}

// not using ajax
function doRollover(num) {
      try {

      // deal with the empty area
      if (num == -1) {
	document['picture'].src=graphicDir + blankImage;
	document.gallery.title.value = "";

      // otherwise we show the picture
      } else {

	// lets deal with those pesky empties	
	doConvertBlanks(num)

	vText = vTitle;
	// display only what is there
	if (vYear != "") {		
		vText += "\n" + vYear;
	}
	if (vMedia != "") {		
		vText += "\n" + vMedia;
	}
	if (vSize != "") {		
		vText += "\n" + vSize;
	}
	if (vPrice != "") {		
		vText += "\n" + vPrice;
	}
	
	document['picture'].src=graphicDir + vImage;
	document.gallery.title.value = vText;

      }

      }
      catch (errorOutput) {
	  processError(errorOutput);
      }
}

// called from ajax.js
function processPopup(obj){
      try {

      vNum1 = 0;
      // get all the data
      a=obj.getElementsByTagName('title');
      b=obj.getElementsByTagName('image');
      c=obj.getElementsByTagName('year');
      d=obj.getElementsByTagName('media');
      e=obj.getElementsByTagName('size');
      f=obj.getElementsByTagName('price');
      if (a.length == 0) {
      	processError(errorOutput);
        return;
      	}
      insertData = "";
      
      insertData += "<div id='popupcontainer'>";
      insertData += "<h3>" + vPopupHeader + "</h3>";
      insertData += "<div id='thumbnails'>";
      while (vNum1<b.length) {
      	
	      // lets deal with those pesky empties	
	      doConvertBlanks(vNum1)
	
	      insertData += "<a href=javascript:popupWindow("+vNum1+");>";
	      insertData += "<img name='Image"+vNum1+"' src='"+graphicDir + vImage +"' alt='"+ vTitle +"'></a>&nbsp;&nbsp;";
	 	if ((vNum1+1)%vRowLength == 0) {
			insertData += "<br><br>";
		}
	 	vNum1++;
      }

      insertData += "<br><br></div></div>";

      document.getElementById ('dataArea').innerHTML = insertData;
  
      }
      catch (errorOutput) {
	  processError(errorOutput);
      }

}


function popupWindow(num){
      try {
	
	// lets deal with those pesky empties	
	doConvertBlanks(num)

	// open the window
	newwin = window.open("","poppic","scrollbars=yes,width=750,height=750,resizable,top=20,left=20");

	// write html
   	newwin.document.write("<html><head><title>Popup Picture</title>");
   	newwin.document.write("<link href='general.css' rel='stylesheet' type='text/css'></head>");

   	newwin.document.write("<body><center><br><br>");

   	// create table for border
   	newwin.document.write("<table border='0' cellspacing='0' cellpadding='20'>");
	newwin.document.write("<tbody><tr><td class='artBorder' align=center>");
	
	// display image and info	
   	newwin.document.write("<img name='Image1' border='0' src='"+ graphicDir + vImage + "' alt='" + vTitle + "'>");
   	newwin.document.write("<br><br>");
   	newwin.document.write(vTitle + "<br>");
	// display only what is there
	if (vYear != "") {		
   	newwin.document.write(vYear + "<br>");
	}
	if (vMedia != "") {		
   	newwin.document.write(vMedia +"<br>");
	}
	if (vSize != "") {		
   	newwin.document.write(vSize + "<br>");
	}
	if (vPrice != "") {		
   	newwin.document.write(vPrice + "<br>");
	}
    	newwin.document.write("");
   	newwin.document.write("</center>");
    	newwin.document.write("</td></tr></tbody>");
    	
    	// start new table for the close 'button' so there is no border
    	newwin.document.write("<table border='0' cellspacing='0' cellpadding='5'><tbody><tr><td align=center>");
  	newwin.document.write("<div id='navvertical'>");
     	newwin.document.write("<br><a href='javascript:self.close();'>Close</a><br>");
     	newwin.document.write("</div>"); 	
    	newwin.document.write("</td></tr></tbody></table>");
   	newwin.document.write("</body></html>");
	newwin.document.close();

      }
      catch (errorOutput) {
	  processError(errorOutput);
      }
}


// not using ajax
function doConvertBlanks(num) {
      try {

	vImage = "";
	vTitle = "";
	vYear = "";
	vMedia = "";
	vSize = "";
	vPrice = "";
	
	// deal with any possible undetailed values
	if (a[num].firstChild.data != 'n/a') {
		vTitle = a[num].firstChild.data;
	} 
	if (b[num].firstChild.data != 'n/a') {
		vImage = b[num].firstChild.data;
	} 
	if (c[num].firstChild.data != 'n/a') {
		vYear = c[num].firstChild.data;
	} 
	if (d[num].firstChild.data != 'n/a') {
		vMedia = d[num].firstChild.data;
	} 
	if (e[num].firstChild.data != 'n/a') {
		vSize = e[num].firstChild.data;
	} 
	if (f[num].firstChild.data != 'n/a') {
		vPrice = f[num].firstChild.data;
	} 

      }
      catch (errorOutput) {
	  processError(errorOutput);
      }
}

