// JavaScript Document

		function renderProduct(currentRow, dataSheet, labelImage, shelfTalker, wineName, wineRegion) {
		
			// Create a "td" and add to the currrent row that is passed in
			var dataElement = document.createElement("td");
			dataElement.setAttribute("width", "175px"); // Element containing the table is 22% of the screen width		
			currentRow.appendChild(dataElement);
			
			// Create a table for this "td" and add it in
			var elementTable = document.createElement("table");
			elementTable.setAttribute("class", "detailTable");
			dataElement.appendChild(elementTable);
			
			// Add a row for the cell containing the labelimage and data sheet link			
			var imageRow = elementTable.insertRow(0);
			var imageDataElement = imageRow.insertCell(0);
			imageDataElement.setAttribute("class", "labelImageTD");

			imageDataElement.setAttribute("align", "center");

			
			// Create the anchor (link) and add an image then attach to the data element
			var imageAnchorElement = document.createElement("a");
			imageAnchorElement.setAttribute("href", dataSheet);
			var imageImageElement = document.createElement("img");
			imageImageElement.src = labelImage;
			imageImageElement.setAttribute("height", "110");
			imageImageElement.setAttribute("width", "150");
			imageAnchorElement.appendChild(imageImageElement);
			imageDataElement.appendChild(imageAnchorElement);
			
			// Add empty column to this row
			imageRow.insertCell(1).innerHTML = "&nbsp";
			
			//
			// Next row for this element holds the text and shelf talker link
			//
			var textRow = elementTable.insertRow(1);
			var textDataElement = textRow.insertCell(0);		
			textDataElement.setAttribute("class", "detailText");
			textDataElement.setAttribute("valign", "top");
			var textPara = document.createElement("p");
			textPara.innerHTML = wineName + "<br />" + wineRegion + "<br />"
			var textAnchor = document.createElement("a");
			textAnchor.href = shelfTalker;
			textAnchor.innerHTML = "<small>Downlad Shelf Talker</small>";
			textPara.appendChild(textAnchor);
			textDataElement.appendChild(textPara);
			
			// add Empty Cell
			textRow.insertCell(1).innerHTML = "&nbsp";
		
			
		}
		
		

		function newProductRow(productTable) {
			return productTable.insertRow(-1);
		}
		
		var xmlhttp;
		
		function getCatalog(country, tableID)
		{
			
			var productTable = document.getElementById(tableID);	
			
			if (window.XMLHttpRequest) {
  				// code for IE7+, Firefox, Chrome, Opera, Safari
  				xmlhttp=new XMLHttpRequest();
  			}
			else if (window.ActiveXObject) {
  				// code for IE6, IE5
  				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  			}
			else {
  				alert("Your browser does not support XMLHTTP!");
  			}
			xmlhttp.onreadystatechange=function() {
			
				if(xmlhttp.readyState==4) {
					if (xmlhttp.status==200) {
						setupPage(country);
						processCatalog(xmlhttp.responseXML.documentElement.getElementsByTagName("product"), productTable);
					} else {
    					alert("Problem retrieving XML data:" + xmlhttp.statusText);
					}
    			}
			}
			
			xmlhttp.open("GET","catalog/" + country + ".xml",true);
			xmlhttp.send(null);
		}
		
		function processCatalog(products, productTable) {
			var productsPerRow = 3;
			var thumbNail;
			var techSheet;
			var wineName;
			var wineRegion;
			var shelfTalker;
			var currentRow = newProductRow(productTable);
			var x;
			
			for(i=0; i < products.length; i++) {
				if((i % productsPerRow) == 0) {
					if(i > 0)
						currentRow = newProductRow(productTable);
				}
				x = products[i].getElementsByTagName("wineName");				
				wineName = x[0].firstChild.nodeValue;

				x = products[i].getElementsByTagName("wineRegion");
				wineRegion = x[0].firstChild.nodeValue;
				
				x = products[i].getElementsByTagName("wineTechSheet");
				techSheet = x[0].firstChild.nodeValue;
				
				x = products[i].getElementsByTagName("wineShelfTalker");
				shelfTalker = x[0].firstChild.nodeValue;
				
				x = products[i].getElementsByTagName("wineLabelImage");
				thumbNail = x[0].firstChild.nodeValue;
				
				renderProduct(currentRow, techSheet, thumbNail, shelfTalker, wineName, wineRegion);
				
			}
		} 
		
		
		function setupPage(country) {
			// document.write('<table border="0" cellspacing="0" cellpadding="2" width="610">');
    		// document.write('<tr> <td colspan="7" class="pageName">' + country + '</td> </tr>');
		}
                
		
			
