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 str4 = "";
	var str5 = "";
	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>");	
	
	if (obj.price != "")
	{
		str4 = str3.replace(/\$\{price\}\$/, regpriceTxt + " " + obj.price);
	}else
	{
		str4 = str3.replace(/\$\{price\}\$/, "");
	}
	
	if (obj.saleprice != "")
	{
		str5 = str4.replace(/\$\{saleprice\}\$/, salepriceTxt + " " + obj.saleprice);
	}else
	{
		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 += "<div style=\"background-color:#c0c0c0;padding-left:6px;padding-bottom:9px;\"><table cellspacing=0 cellpadding=0>";
	for (i=0; i<countStrs; i++)
	{
	    DOC += "<tr>";
		for (j=0; j<countCols; j++)
		{
		    DOC += "<td valign=top width=134><img src=/lib/bestbrandsclub/prod-im1.gif /></td>";
		    DOC += "<td class=vertsep width=1><img width=4 src=/lib/bestbrandsclub/spacer.gif></td>";
		}
		DOC += "</tr><tr>";
		for (j=0; j<countCols; j++)
		{
			DOC += "<td valign=top width=134 style=\"background-color:#ffffff;\">";
			if (current < howmany) {
				Parse(itemsArr[uniquearr[current]]);
			}
			DOC += "</td>";			
			if (j<countCols-1)
			{
				DOC += "<td class=vertsep width=1><img width=4 src=/lib/bestbrandsclub/spacer.gif></td>";
			}
			current++;
		}
		DOC += "</tr><tr>";
		for (j=0; j<countCols; j++)
		{
		    DOC += "<td valign=top width=134><img src=/lib/bestbrandsclub/prod-im2.gif /></td>";
		    DOC += "<td class=vertsep width=1><img width=4 src=/lib/bestbrandsclub/spacer.gif></td>";
		}
		DOC += "</tr>";
		if (i<countStrs-1)
		{
			var colspan = countCols*2-1;
			DOC += "<tr><td height=1 colspan=" + colspan + "><img height=24 src=/lib/bestbrandsclub/spacer.gif></td></tr>";
		}
	}
	DOC += "</table></div>";
	document.write(DOC);
}
