var MAX_ITEM = 1
var n_count = 0

function MakeArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 0
	}
	this.maxlen = n
	this.len = 0
	return this
}

var goods = MakeArray(MAX_ITEM)

function Item(code, name, home, unit, price, comment) {
	this.code = code
	this.name = name
	this.home = home
	this.unit = unit
	this.price = price
	this.comment = comment
}

function Add(code, name, home, unit, price, comment) {
	goods.len++
	goods[goods.len] = new Item(code, name, home, unit, price, comment)
}

function DisplayList() {
	for (i = 1; i <= goods.len; i++) {
		if ((goods[i].code == "") || (i == 1)) {
			if (n_count > 0) {
				document.writeln("</table>")
				document.writeln("</td>")
				document.writeln("<td nowrap width=\"10\" class=\"space\"></td>")
				document.writeln("</tr>")
				document.writeln("</table>")
				document.writeln("</div>")
			}
			n_count++
			document.writeln("<table cellpadding=\"0\" border=\"0\" cellspacing=\"0\" class=\"nuggetHeader\">")
			document.writeln("<tr>")
			document.writeln("<td nowrap width=\"10\" class=\"space\"></td>")
			document.writeln("<td nowrap width=\"100%\" class=\"nuggetTitle\" valign=\"center\">")
			document.writeln("&nbsp;")
			if (goods[i].home != "") {
				document.writeln("<a target=\"_blank\" href=\"" + goods[i].home + "\" class=\"nuggetTitleText\">" + goods[i].name + "</a>")
			} else {
				document.writeln("<span class=\"nuggetTitleText\">" + goods[i].name + "</span>")
			}
			document.writeln("&nbsp;")
			document.writeln("</td>")
			document.writeln("<td nowrap class=\"nuggetButtonWrapper\">")
			document.writeln("<img id=\"nToggle" + n_count + "\" src=\"images/blank.gif\" title=\"Click to maximize / minimize\" onClick=\"document.all.nContent" + n_count + ".style.display=document.all.nContent" + n_count + ".style.display=='none'?'':'none';if(document.images)this.src=document.all.nContent" + n_count + ".style.display=='none'?imgMax.src:imgMin.src;\" WIDTH=\"17\" HEIGHT=\"17\">")
			document.writeln("</td>")
			document.writeln("<td nowrap width=\"10\" class=\"space\"></td>")
			document.writeln("</tr>")
			document.writeln("</table>")
			document.writeln("<div valign=\"top\" id=\"nContent" + n_count + "\">")
			if (n_count%2 == 0) {
				document.writeln("<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" class=\"nuggetBodyEven\">")
			} else {
				document.writeln("<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" class=\"nuggetBodyOdd\">")
			}
			document.writeln("<tr>")
			document.writeln("<td nowrap width=\"10\" class=\"space\"></td>")
			document.writeln("<td>")
			document.writeln("<table>")
		} else {
			if (i%2 == 0) {
				document.writeln("<tr class=\"lineEven\">")
			} else {
				document.writeln("<tr class=\"lineOdd\">")
			}
			if (goods[i].home != "") {
				document.writeln("<td><a target=\"_blank\" href=\"" + goods[i].home + "\">" + goods[i].name + "</a></td>")
			} else {
				document.writeln("<td>" + goods[i].name + "</td>")
			}
			document.writeln("<td>" + goods[i].unit + "</td>")
			document.writeln("<td align=\"right\">" + goods[i].price + "</td>")
			document.writeln("<td><a href=\"javascript:void(0)\" onClick=\"BasketInsert(" + i +")\"></a></td>")
			document.writeln("</tr>")
			if (goods[i].comment != "") {
				document.writeln("<tr>")
				document.writeln("<td colspan=\"4\">" + goods[i].comment + "</td>")
				document.writeln("</tr>")
			}
		}
	}
	document.writeln("</table>")
	document.writeln("</td>")
	document.writeln("<td nowrap width=\"10\" class=\"space\"></td>")
	document.writeln("</tr>")
	document.writeln("</table>")
	document.writeln("</div>")
}

function BasketInsert(i) {
	select_item = i
	oFormQ.document.FormQ.Q.value = 1
	ShowObjBelow(oFormQ,-100,10)
}

function QuantityOK() {
	HideObj(oFormQ)
	str = oFormQ.document.FormQ.Q.value
	if (checkNum(str)) {
		q = eval(str)
		i = select_item
		if (Math.round(q) > 0) { 
			parent.contents.glob_code = goods[i].code
			parent.contents.glob_name = goods[i].name
			parent.contents.glob_home = goods[i].home
			parent.contents.glob_unit = goods[i].unit
			parent.contents.glob_price = goods[i].price
			parent.contents.glob_quantity = q
			parent.contents.location.href="javascript:BasketSetAdd()"
		}
	}
}

function checkNum(str) {
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i+1)
		if ((ch < "0" || ch > "9") && ch != ".") {
			alert("invalid entry!")
			return false
		}
	}
	return true
}

function Regenerate() {
	window.location.reload()
}

function SetRegenerate() {
	setTimeout("window.onresize=Regenerate",450)
}

function HideObj(o) {
	if (ie) {
		o.filters.revealTrans.stop()
		o.style.visibility = "hidden"
	}
	if (n) {
		o.visibility = "hide"
	}
}

var giMousePosX = 0
var giMousePosY = 0
var sUserAgent = navigator.appName + " " + navigator.appVersion
var sAgentInfo = sUserAgent.substring(0, 12)

if (sAgentInfo >= "Netscape 4.0") {
	window.captureEvents(Event.MOUSEMOVE)
	window.onMouseMove = MouseHandler
}

function MouseHandler(evnt) {
	giMousePosX = evnt.pageX
	giMousePosY = evnt.pageY
}

function ShowObjBelow(o, iOffsetX, iOffsetY) {
	if (ie) {
		giMousePosY = event.clientY + document.body.scrollTop
		giMousePosX = event.clientX + document.body.scrollLeft
	}
	if (ie) {
		if (o.style.visibility != "visible") {
			o.style.ypos = giMousePosY + iOffsetY
			o.style.top = o.style.ypos
			o.style.xpos = giMousePosX + iOffsetX
			o.style.left = o.style.xpos
			o.filters.revealTrans.apply()
			o.style.visibility = "visible"
			o.filters.revealTrans.play()
		} else {
			HideObj(o)
		}
	}
	if (n) {
		if (o.visibility != "show") {
			o.ypos = giMousePosY + iOffsetY
			o.top = o.ypos
			o.xpos = giMousePosX + iOffsetX
			o.left = o.xpos
			o.visibility = "show"
		} else {
			HideObj(o)
		}
	}
}
