var DOC = "";

var itemsArr = new Array();
var uniquearr = new Array();
var duplicate = false;
var y,z; 

function itemObj(id, name, code, img, price, saleprice) {
	this.id=id.toLowerCase();
	this.name=name;
	this.code=code;	
	this.img=img;
	this.price=price;
	this.saleprice=saleprice;
	itemsArr[itemsArr.length] = this;	
}

function Parse(obj)
{
	var str1 = struct.replace(/\$\{name\}\$/, "<a href=" + obj.id + ".html>" + obj.name + "</a>");
	var str2 = str1.replace(/\$\{id\}\$/, obj.id);
	var str3 = str2.replace(/\$\{img\}\$/, "<a href=" + obj.id + ".html><img src=" + obj.img + " border=0></a>");	
	var str4 = str3.replace(/\$\{price\}\$/, regpriceTxt + " " + obj.price);
	if(obj.saleprice != ""){
	var str5 = str4.replace(/\$\{saleprice\}\$/, salepriceTxt + " " + obj.saleprice);
	}
	else {
	var str5 = str4.replace(/\$\{saleprice\}\$/," ");
	}
	var str6 = str5.replace(/\$\{code\}\$/, obj.code);
		
	DOC += str6;
}

function Exec()
{
	z = 0;
	if(howmany > itemsArr.length)
		howmany = itemsArr.length;

	while (z != howmany){
			y = Math.ceil(Math.random()*itemsArr.length-1);
			var repeatchk = uniquearr;

			for(i = 0; i < repeatchk.length; i++){
				if (y==repeatchk[i])
					duplicate=true;
			}

			if (duplicate == true){
				duplicate = false;
				continue;
			}
			if (duplicate == false){
				uniquearr[uniquearr.length] = y;
				z+=1;
			}
	} 


	var countStrs = Math.ceil(howmany / countCols);
	var current = 0;

	DOC += "<table border=0 cellspacing=0 cellpadding=0 width=475>";
	for (i=0; i<countStrs; i++)
	{
		DOC += "<tr>";
		for (j=0; j<countCols; j++)
		{
			DOC += "<td valign=top>";
			if (current < howmany) {
				Parse(itemsArr[uniquearr[current]]);
			}
			DOC += "</td>";			
			if (j<countCols-1)
			{
				DOC += "<td class=vertsep>&nbsp;</td>";
			}
			current++;
		}
		DOC += "</tr>";
		if (i<countStrs-1)
		{
			var colspan = countCols*2-1;
			DOC += "<tr><td class=horsep colspan=" + colspan + "></td></tr>";
		}
	}
	DOC += "</table>";
	document.write(DOC);
}
