//$Id: cs_utils.js,v 1.54 2010/03/21 21:29:26 rrkramer Exp $
function display_one(igid,image,name,text,first,last,no_prices,price,color_tag,size_tag,style_tag,hdr,go) {
	if (! go ) {
		return false;
	}
	first = Number(first);
	last = Number(last);
	var j, k, w, items, i_num0, qlbl="", tmp, sel = "";
	var s = ks_main.sub_main;
	Page = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r';
	Page += '<HTML><HEAD><TITLE>Catalog</TITLE>\r';
	Page += '<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">\r';
	Page += '<LINK REL="stylesheet" TYPE="text/css" HREF="'+Style_sheet+'">\r';
	Page += '<'+'SCRIPT TYPE="text/javascript" DEFER=true>\r';
	var colors=false, sizes=false, styles=false, n=last-first+1;
	Page += 'var no_prices='+no_prices+';\r';
	Page += 'var i_nums=new Object('+n+');\r';
	Page += 'var items=new Object('+n+');\r';
	Page += 'var qtys=new Object('+n+');\r';
	Page += 'var idxs=new Object('+n+');\r';
	Page += 'var ordered=new Object();\r';

	Page += 'var pItems = new Array("'+s.pItems.slice(first,last).join('","')+'");\r';
	Page += 'var pI_nums = new Array("'+s.pI_nums.slice(first,last).join('","')+'");\r';
	Page += 'var pForm_names = new Array("'+s.pForm_names.slice(first,last).join('","')+'");\r';
	Page += 'var pUnits = new Array("'+s.pUnits.slice(first,last).join('","')+'");\r';
	Page += 'var pQty_units = new Array("'+s.pQty_units.slice(first,last).join('","')+'");\r';
	Page += 'var pPus = new Array("'+s.pPus.slice(first,last).join('","')+'");\r';
	Page += 'var pQty_pus = new Array("'+s.pQty_pus.slice(first,last).join('","')+'");\r';
	Page += 'var pPrices = new Array("'+s.pPrices.slice(first,last).join('","')+'");\r';
	Page += 'var pFlags = new Array("'+s.pFlags.slice(first,last).join('","')+'");\r';
	Page += 'var pWbps = new Array("'+s.pWbps.slice(first,last).join('","')+'");\r';
	Page += 'var pMfgrs = new Array("'+s.pMfgrs.slice(first,last).join('","')+'");\r';
	Page += 'var pVpart_nos = new Array("'+s.pVpart_nos.slice(first,last).join('","')+'");\r';
	Page += 'var pGroup_ids = new Array("'+s.pGroup_ids.slice(first,last).join('","')+'");\r';
	Page += 'var pColors = new Array("'+s.pColors.slice(first,last).join('","')+'");\r';
	Page += 'var pSizes = new Array("'+s.pSizes.slice(first,last).join('","')+'");\r';
	Page += 'var pStyles = new Array("'+s.pStyles.slice(first,last).join('","')+'");\r';
	Page += 'var pComments = new Array("'+s.pComments.slice(first,last).join('","')+'");\r';
	Page += 'var pQty_limits = new Array("'+s.pQty_limits.slice(first,last).join('","')+'");\r';
	Page += 'var pMin_ord_qtys = new Array("'+s.pMin_ord_qtys.slice(first,last).join('","')+'");\r';
	Page += 'var pG_options = new Array("'+s.pG_options.slice(first,last).join('","')+'");\r';
	if (last - first == 1) {
		i_num0 = s.pI_nums[first];
		Page += 'var i_num_active = "'+i_num0+'";\r';
	} else {
		Page += 'var i_num_active = "";\r';
	}
	if (no_prices) {
		price = "";
	}
	if (! color_tag) {
		color_tag = "Color";
	}
	if (! size_tag) {
		size_tag = "Size";
	}
	if (! style_tag) {
		style_tag = "Style";
	}
	var qty_per_min=1,qty_per_max=1;
	for (j=first; j < last; j++) {
		qty_per_min = Math.min(s.pQty_units[j],qty_per_min);
		qty_per_max = Math.min(s.pQty_units[j],qty_per_max);

		Page += 'i_nums["\t';

		if (s.pColors[j]) {
			colors = true;
			Page += standardize(s.pColors[j])+'\t';
		}
		if (s.pSizes[j]) {
			sizes = true;
			Page += standardize(s.pSizes[j])+'\t';
		}
		if (s.pStyles[j]) {
			styles = true;
			Page += standardize(s.pStyles[j])+'\t';
		}

		if (! colors && ! sizes && ! styles) {
			Page += '\t';
		}

		Page += '"]="'+s.pI_nums[j]+'";\r';
		Page += 'items['+s.pI_nums[j]+']="'+escape(s.pItems[j])+'";\r';
		Page += 'idxs['+s.pI_nums[j]+']='+Number(j-first)+';\r';
	}
	var not_avail = "item";
	var thingy = not_avail;
	if (colors && sizes && styles) {
		thingy = color_tag.toLowerCase()+", "+size_tag.toLowerCase()+" and "+style_tag.toLowerCase();
		not_avail = thingy+" combination";
	} else if (colors && sizes && ! styles) {
		thingy = color_tag.toLowerCase()+" and "+size_tag.toLowerCase();
		not_avail = thingy+" combination";
	} else if (colors && ! sizes && styles) {
		thingy = color_tag.toLowerCase()+" and "+style_tag.toLowerCase();
		not_avail = thingy+" combination";
	} else if (! colors && sizes && styles) {
		thingy = size_tag.toLowerCase()+" and "+style_tag.toLowerCase();
		not_avail = thingy+" combination";
	} else if (! colors && ! sizes && styles) {
		not_avail = thingy = style_tag.toLowerCase();
	} else if (colors && ! sizes && ! styles) {
		not_avail = thingy = color_tag.toLowerCase();
	} else if (! colors && sizes && ! styles) {
		not_avail = thingy = size_tag.toLowerCase();
	}

	Page += 'var not_avail="'+not_avail+'";\r';
	Page += 'var thingy="'+thingy+'";\r';
	if (colors) {
		Page += 'var did_color=false,Colors=true;\r';
	} else {
		Page += 'var did_color=true,Colors=false;\r';
	}
	if (sizes) {
		Page += 'var did_size=false,Sizes=true;\r';
	} else {
		Page += 'var did_size=true,Sizes=false;\r';
	}
	if (styles) {
		Page += 'var did_style=false,Styles=true;\r';
	} else {
		Page += 'var did_style=true,Styles=false;\r';
	}
	Page += '</'+'SCRIPT>\r';
	Page += '<STYLE TYPE="text/css">\r';
	Page += ' .prices {position:relative; top:-8px; left:5%; margin:5px; width:400px; font-size:10px;}\r';
	Page += ' .ptbl{border-collapse:collapse; border:3px ridge; empty-cells:show; padding: 0 5px 0 5px; margin:0;}\r';
	Page += ' .pttd{border:3px ridge; padding: 0 5px 0 5px; margin: 0; font-size:11px; font-weight:bold; text-align:right; white-space:nowrap;}\r';
	Page += '</STYLE>\r';
	// if the item is non orderable, do not run onload..
	if (s.pG_options[first] & 0x1) {
		Page += '</HEAD><BODY>';
		colors="",sizes="",styles="";
	} else {
		Page += '</HEAD><BODY onLoad="parent.parent.getQty(false);parent.parent.init_one()';
		if (Do_cs_stock_check == 2) {
			Page += ';parent.parent.checkStock_setup()';
		}
		Page += '">\r';
	}
	Page += '<DIV CLASS="title" STYLE="text-align:left;">'+hdr+'</DIV>\r';
	Page += '<FORM METHOD=post ACTION="javascript:history.back();" onSubmit="if(parent.parent.set_item_name_qty()){void parent.parent.Order(document.forms[0].qty)}">\r';
	Page += '<DIV CLASS="subheadertext">\r';
	Page += '<INPUT TYPE="hidden" NAME="item">\r';
	Page += '<INPUT TYPE="hidden" NAME="item_grouping_id" VALUE="'+igid+'">\r';
	Page += '<INPUT TYPE="hidden" NAME="key" VALUE='+Key+'>\r';
	for (j=first; j<last; j++) {
		Page += '<INPUT TYPE="hidden" NAME="qty:'+skrunch(s.pItems[j])+'" VALUE="">\r';
	}
	if (last-first == 1) {
		qlbl = skrunch(s.pItems[first]);
	}
	Page += '<B>&nbsp;Item:</B>&nbsp;'+name;
	if (! no_prices) {
		Page += '&nbsp;&nbsp;&nbsp;&nbsp;<B>Price:</B>&nbsp;'+price+'\r';
	}
	if (Show_cs_item_detail) {
		var Has_quantity_limits;
		if (Show_quantity_limits) {
			for (j=first; j < last; j++) {
				if (s.pQty_limits[j] > 0 & s.pQty_limits[j] != '999999999') {
					Has_quantity_limits = 1;
				}
			}
		}
		var td_switch = 'FFFFFF';
		Page += '<TABLE CELLPADDING=0 CELLSPACING=0><TR><TD>\r';
		Page += '<BR><IMG SRC="'+image+'"><BR>\r';
		Page += '</TD><TD WIDTH=10></TD><TD VALIGN=top><BR>\r';
		Page += '<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0><TR><TD CLASS="reverse">&nbsp;\r';
		Page += 'Item Number&nbsp;</TD>\r';
		if (colors) {
			Page += '<TD CLASS="reverse">&nbsp;' + color_tag + '&nbsp;</TD>\r';
		}
		if (sizes) {
			Page += '<TD CLASS="reverse">&nbsp;' + size_tag + '&nbsp;</TD>\r';
		}
		if (styles) {
			Page += '<TD CLASS="reverse">&nbsp;' + style_tag + '&nbsp;</TD>\r';
		}
		if (Has_quantity_limits) {
			Page += '<TD CLASS="reverse">&nbsp;Max Order Qty.&nbsp;</TD>\r';
		}
		Page += '</TR>\r';
		for (j=first; j < last; j++) {
			Page += '<TR><TD BGCOLOR="#' + td_switch + '" CLASS="subheadertext">&nbsp;' + s.pItems[j] + '&nbsp;</TD>\r';
			if (colors) {
				Page += '<TD BGCOLOR="#' + td_switch + '" CLASS="subheadertext">&nbsp;' + s.pColors[j] + '&nbsp;</TD>\r';
			}
			if (sizes) {
				Page += '<TD BGCOLOR="#' + td_switch + '" CLASS="subheadertext">&nbsp;' + s.pSizes[j] + '&nbsp;</TD>\r';
			}
			if (styles) {
				Page += '<TD BGCOLOR="#' + td_switch + '" CLASS="subheadertext">&nbsp;' + s.pStyles[j] + '&nbsp;</TD>\r';
			}
			if (Has_quantity_limits) {
				Page += '<TD ALIGN="center" BGCOLOR="#' + td_switch + '" CLASS="subheadertext">&nbsp;' + s.pQty_limits[j] + '&nbsp;</TD>\r';
			}
			if (td_switch == 'FFFFFF') {
				td_switch = 'DDDDDD';
			} else {
				td_switch = 'FFFFFF';
			}
		}
		Page += '</TABLE></TD></TR></TABLE><BR>\r';
	} else {
		Page += '<BR><BR><IMG SRC="'+image+'"><BR><BR>\r';
	}
	if (text) {
		Page += text+'<BR><BR>\r';
	}
	var nodup = new Array();
	var sorted = new Array();
	if (colors) {
		k = 0;
		for (j=first; j < last; j++) {
			if (typeof nodup[standardize(s.pColors[j])] == "undefined") {
				nodup[standardize(s.pColors[j])] = "";
				sorted[k++] = s.pColors[j];
			}
		}
		sorted.sort();
		sel = "";
		if (k == 1) {
			sel = " SELECTED";
		}
		Page += '<SELECT NAME="select_color" onChange="parent.parent.item_name_qty(true)">\r';
		if (k > 1) {
			var an = "a";
			if (color_tag.match(/^[aeiou]/i)) {
				an = "an";
			}
			Page += '<OPTION VALUE="" SELECTED>--Select '+an+' '+color_tag+'--\r';
		}
		for (j = 0; j < k; j++) {
			Page += '<OPTION VALUE="'+sorted[j]+'"'+sel+'>'+sorted[j]+'\r';
		}
		Page += '</SELECT>&nbsp;&nbsp;&nbsp;\r';
	}
	if (sizes) {
		for (k in sorted) {
			delete sorted[k];
		}
		for (k in nodup) {
			delete nodup[k];
		}
		k = 0;
		var a, x;
		for (j=first; j < last; j++) {
			if (typeof nodup[standardize(s.pSizes[j])] == "undefined") {
				nodup[standardize(s.pSizes[j])] = "";
				a = s.pSizes[j];
				x = 0;

				while (a.substr(0,1) == "X") {
					x++;
					a = a.substring(1);
				}
				if (x) {
					if (a.charAt(0) == "L" || a.charAt(0) == "") {
						a = "               ".substr(0,x) + a;
					} else {
						a = "XXXXXXXXXXXXXXX".substr(0,x) + a;
					}
				} else {
					if (a.search(/^\d+X[LS]/i) == 0) {
						x = parseInt(a);
						if (x > 0 && x < 15) {
							a=a.replace(/\d+X/,"");
							if (a.charAt(0) == "L" || a.charAt(0) == "") {
								a = "               ".substr(0,x) + a;
							} else {
								a = "XXXXXXXXXXXXXXX".substr(0,x) + a;
							}
						}
					}
				}
				sorted[k++] = a+"\t"+s.pSizes[j];
			}
		}

		if (DontSortSize) {
			var newsort = new Array();
			for (l in SortSize) {
				for (m in sorted) {
					a = sorted[m].substring(sorted[m].indexOf("\t")+1);
					if (SortSize[l] == a) {
						newsort.push(sorted[m]);
						break;	
					}
				}
			}
			sorted = newsort;
		} else { 
			sorted.sort();
		}
		sel = "";
		if (k == 1) {
			sel = " SELECTED";
		}
		Page += '<SELECT NAME="select_size" onChange="parent.parent.item_name_qty(true)">\r';
		if (k > 1) {
			var an = "a";
			if (size_tag.match(/^[aeiou]/i)) {
				an = "an";
			}
			Page += '<OPTION VALUE="" SELECTED>--Select '+an+' '+size_tag+'--\r';
		}
		for (j = 0; j < k; j++) {
			if (typeof sorted[j] != "undefined") {
				a = sorted[j].substring(sorted[j].indexOf("\t")+1);
				Page += '<OPTION VALUE="'+a+'"'+sel+'>'+a+'\r';
			}
		}
		Page += '</SELECT>&nbsp;&nbsp;&nbsp;\r';
	}
	if (styles) {
		for (k in sorted) {
			delete sorted[k];
		}
		for (k in nodup) {
			delete nodup[k];
		}
		k = 0;
		for (j=first; j < last; j++) {
			if (typeof nodup[standardize(s.pStyles[j])] == "undefined") {
				nodup[standardize(s.pStyles[j])] = "";
				sorted[k++] = s.pStyles[j];
			}
		}
		sorted.sort();
		Page += '<SELECT NAME="select_style" onChange="parent.parent.item_name_qty(true)">\r';
		if (k > 1) {
			var an = "a";
			if (style_tag.match(/^[aeiou]/i)) {
				an = "an";
			}
			Page += '<OPTION VALUE="" SELECTED>--Select '+an+' '+style_tag+'--\r';
		}
		sel = "";
		if (k == 1) {
			sel = " SELECTED";
		}
		for (j = 0; j < k; j++) {
			if (sorted[j]) {
				Page += '<OPTION VALUE="'+sorted[j]+'"'+sel+'>'+sorted[j]+'\r';
			}
		}
		Page += '</SELECT>&nbsp;&nbsp;&nbsp;\r';
	}
	if (Permit & 1) {
		Page += '<BR><TABLE>\r';
		if (!(s.pG_options[first] & 0x1)) {
			Page += '<TR><TD VALIGN="top" CLASS="subheadertext">Quantity&nbsp;<INPUT ID="qty" TYPE="text" SIZE=4 MAXLENGTH=7 NAME="qty:'+qlbl+'" VALUE="">\r';
		} else {
			Page += '<TR><TD VALIGN="top" CLASS="subheadertext"><INPUT ID="qty" TYPE="hidden" NAME="qty:'+qlbl+'" VALUE="">\r';
		}
		if (!(s.pG_options[first] & 0x1)) {
			if (qty_per_min != qty_per_max) {
				Page += '&nbsp;Various Package Quantites&nbsp;';
			} else if (s.pUnits[first] != "EA") {
				Page += '&nbsp;'+s.pFancy_uis[first]+'&nbsp;';
			}
			if (IsMSIE) {
				Page += '<TD VALIGN="top">&nbsp;&nbsp;<INPUT TYPE="button" CLASS="button" STYLE="border-color:#CCCCCC #5C5C5C #5C5C5C #CCCCCC !important;" onClick="if(parent.parent.set_item_name_qty()){void parent.parent.Order(document.forms[0].qty);}window.scrollBy(0,1500);" VALUE="'+Tags["addToOrder"]+'">\r'; 
			} else {
				Page += '<TD VALIGN="top">&nbsp;&nbsp;<INPUT TYPE="button" CLASS="button" onClick="if(parent.parent.set_item_name_qty()){void parent.parent.Order(document.forms[0].qty);window.scrollBy(0,1500);}" VALUE="'+Tags["addToOrder"]+'">\r'; 
			}
	
			if (Do_cs_stock_check == 2) {
				Page += '<TD STYLE="white-space:nowrap;"><SPAN ID="stock_avail">';
				if (i_num0 && typeof On_hand[i_num0] != "undefined" && On_hand[i_num0]) {
					Page += 'Available: '+On_hand[i_num0];
				} else if (!i_num0 && typeof On_hand[s.pI_nums[first]] != "undefined") {
					Page += 'Select a '+thingy+' to see availability.';
				}
				Page += '</SPAN>&nbsp;&nbsp;&nbsp;<A HREF="#" onMouseOver="status=&#039;&#039;;return true" onClick="parent.parent.checkStock_setup();return false;"><IMG SRC="'+DocDir+'/catalog/pic/stockstatus.gif" TITLE="Stock Availability" NAME="stock_status" BORDER=0>&nbsp;Check&nbsp;availability</A>\r';
				Page += '<TR><TD><TD>\r';
			}
			if (Show_cs_item_detail) {
				Page += '</TR><TR><TD COLSPAN=2>';
			} else {
				Page += '<TD>';
			}
			Page += '<DIV ID="tbl_div" STYLE="visibility:hidden;">';
			if (Do_cs_stock_check == 1) {
				tmp = '<SPAN STYLE="white-space:nowrap;"><A HREF="#" onMouseOver="status=&#039;&#039;;return true" onClick="parent.parent.checkStock();return false;"><IMG SRC="'+DocDir+'/catalog/pic/stockstatus.gif" TITLE="Stock Availability" BORDER=0>&nbsp;Check&nbsp;availability&nbsp;&nbsp;</A></SPAN>';
				Page += '<DIV ID="legend" STYLE="font-size: 10px;text-align:right;margin-right:2px;">'+tmp+'</DIV>\r';
			}
			Page += '<TABLE ID="tbl" CLASS="tgen">\r';
			Page += '<TR><TD CLASS="reverse" STYLE="width:150px">Item';
			if (colors) {
				Page += '<TD CLASS="reverse" STYLE="width:50px">'+color_tag;
			}
			if (sizes) {
				Page += '<TD CLASS="reverse" STYLE="width:50px">'+size_tag;
			}
			if (styles) {
				Page += '<TD CLASS="reverse" STYLE="width:50px">'+style_tag;
			}
			if (! no_prices) {
				Page += '<TD CLASS="reverse" STYLE="width:50px">Price';
			}
			Page += '<TD CLASS="reverse" STYLE="width:50px">Qty\r';
			if (Do_cs_stock_check == 1) {
				w = 40;
				if ( typeof document.all != "undefined" ) { // MSIE
					w += 12;
				}
				Page += '<TH STYLE="width:'+w+'px" CLASS="reverse"><A HREF="#" onMouseOver="status=&#039;&#039;;return true" onClick="parent.parent.checkStock();return false;"><IMG SRC="'+DocDir+'/catalog/pic/stockstatus.gif" TITLE="Stock Availability"  NAME="stock_status" BORDER=0></A>\r';
			}
			Page += '</TABLE></DIV>\r';
		}
		Page += '</TABLE></DIV>\r';
		if (! no_prices) {
			var pshow = false;
			var pvis = "hidden";
			if (! colors && ! sizes && ! styles && s.pComments[first]) {
				pshow = true;
				pvis = "visible";
			}
			if (Show_cs_item_detail) {
				Page += '<BR>\r';
			}
			Page += '<DIV ID="prices" STYLE="visibility:'+pvis+';">'+make_table(s.pComments[first],pshow,s.pMin_ord_qtys[first])+'</DIV>\r';
		}
	}
	if (continueShoppingHistoryGo) {
		Page += '<A HREF="Javascript:history.go(-1);">';
	} else if (typeof LastCatPage.args != "undefined" && LastCatPage.args) {
		Page += '<A HREF="'+LastCatPage.args+'">';
	} else if (typeof LastCatPage.cat != "undefined") {
		LastCatPage.desc = LastCatPage.desc.replace(/%27/g, "%5C%2527");
		Page += '<A HREF="javascript:parent.parent.menu_go(';
		Page += "'"+LastCatPage.cat+"','"+LastCatPage.desc+"','"+LastCatPage.status+"','"+LastCatPage.id+"'";
		Page += ",'"+LastCatPage.target+"','"+LastCatPage.nxt+"','"+LastCatPage.fids+"','"+LastCatPage.limit+"'";
		Page += ",'"+LastCatPage.prod_code_sort+"'";
		Page += ')" onMouseOver="status=&#039;&#039;;return true">';
	} else {
	}
	Page += 'Continue Shopping</A>';
	if (Permit & 1) {
		Page += '&nbsp;|&nbsp;<A HREF="javascript:parent.parent.show_basket()">'+Tags["showbask"]+'</A>';
		if (! Force_view_basket) {
			Page += '&nbsp;|&nbsp;<A HREF="javascript:parent.parent.finish_ord()">Checkout</A>';
		}
	}
	Page += '\r</FORM><IFRAME NAME="talk_to" HEIGHT=1 WIDTH=1 STYLE="visibility:hidden;" SRC="/catalog/closet.html"></IFRAME></BODY></HTML>\r';
	var d = s.document;
	d.open();
	d.write(Page);
	d.close();
	if (!IsMSIE) {
		return false;
	}
}

function set_item_name_qty() {
	return item_name_qty(false,true);
}
	
function item_name_qty(do_qty,set_qty) {
	var sw = ks_main.sub_main;
	sw.i_num_active = "";
	var d = sw.document;
	var j, s, i_num, skitem, ikey = "";

	var el = d.getElementById("stock_avail");
	var goAnyway;
	if (sw.Colors || sw.Sizes || sw.Styles) {
		ikey = "\t";
	} else {
		ikey = "\t\t";
	}
	if (sw.Colors) {
		s = d.forms[0].select_color;
		if (s.selectedIndex > 0 || s.length == 1) {
			ikey += standardize(s[s.selectedIndex].value)+"\t";
			sw.did_color=true;
		}
	}
	if (sw.Sizes) {
		s = d.forms[0].select_size;
		if (s.selectedIndex > 0 || s.length == 1) {
			ikey += standardize(s[s.selectedIndex].value)+"\t";
			sw.did_size=true;
		}
	}
	if (sw.Styles) {
		s = d.forms[0].select_style;
		if (s.selectedIndex > 0 || s.length == 1) {
			ikey += standardize(s[s.selectedIndex].value)+"\t";
			sw.did_style=true;
		}
	}

	if (sw.did_color && sw.did_size && sw.did_style || ! do_qty) {
		if (typeof sw.i_nums[ikey] == "undefined") {
			alert("This "+sw.not_avail+" is not available, please re-select.");
			return false;
		}
		i_num = sw.i_nums[ikey];
		sw.i_num_active = i_num;
		if (el) {
			if (typeof On_hand[i_num] != "undefined" && On_hand[i_num] != "") {
				el.innerHTML = "Available: "+On_hand[i_num];
			} else {
				el.innerHTML = "";
			}
		}
		j = sw.idxs[i_num];

		if (! sw.no_prices) {
			var el_pr = d.getElementById("prices");
			if (el_pr) {
				if (sw.pComments[j]) {
					el_pr.innerHTML = make_table(sw.pComments[j],true,sw.pMin_ord_qtys[j]);
					el_pr.style.visibility = "visible";
				} else {
					el_pr.style.visibility = "hidden";
				}
			}
		}
		if (Permit & 1) {
			var el_qty = d.getElementById("qty");
			if (! (sw.pFlags[j] & (1<<9)) && sw.pQty_limits[j] >= 0) {
				var item = unescape(sw.items[i_num]);
				el_qty.name = "qty:"+item;
				if (set_qty) {
					skitem = skrunch(item);
					sw.qtys[skitem] = d.forms[0].qty.value;
					sw.ordered[i_num] = 1;
					show_cs_ordered();
				}
				if (do_qty) {
					if (!sw.qtys[skrunch(item)]) {
						sw.qtys[skrunch(item)] = "";
					}
					d.forms[0].qty.value = sw.qtys[skrunch(item)];
					show_cs_ordered();
				}
			} else {
				return alert("This "+sw.not_avail+" is not available, please re-select.");
			}
		}
	} else if (el) {
		el.innerHTML = "";
	}
	return true;
}

function make_table(comments,show,minQtys) {
	if (! comments || ! show) {
		return "";
	}
	var tbl1 = "<TABLE CLASS='ptbl'><TR><TD CLASS='pttd'>Quantity";
	var tbl2 = "<TR><TD CLASS='pttd'>Price";
	var cols = new Array();
	var qp = new Array();
	var j;
	cols = comments.split(";");
	if (typeof minQtys != "undefined") {
		minTest = cols[0].replace(/^1-/,"");
		minTest = minTest.replace(/:(.*)/,"");
		if (minTest != minQtys) {
			cols[0] = cols[0].replace(/^1-/,minQtys + "-");
		} else {
			cols[0] = cols[0].replace(/^1-/,"");
		}
	}
	for (j = 0; j < cols.length; j++) {
		qp = cols[j].split(":");
		tbl1 += "<TD CLASS='pttd' CLASS='reverse'>"+qp[0];
		tbl2 += "<TD CLASS='pttd'>\$"+qp[1];
	}
	tbl1 += "\+";
	return tbl1+tbl2+"</TABLE><BR>";
}

function show_cs_ordered() {
	var s = ks_main.sub_main;
	var j,k,idx,item,i_num,price,ncp,skitem,done1="";
	var row,cell,tbl = s.document.getElementById("tbl");
	var iStat,wpb_arr = new Array(3);
	while (tbl.rows.length > 1) {
		tbl.deleteRow(1);
	}
	for (i_num in s.ordered) {
		j = s.idxs[i_num];
		item = unescape(s.items[i_num]);
		skitem = skrunch(item);
		if (s.qtys[skitem] > 0) {
			done1 = 1;
			row = tbl.insertRow(-1);
			cell = row.insertCell(0);
			cell.innerHTML = item;
			cell.className = "gen";
			k = 1;
			if (s.Colors) {
				cell = row.insertCell(k++);
				cell.innerHTML = s.pColors[j];
				cell.className = "gen";
			}
			if (s.Sizes) {
				cell = row.insertCell(k++);
				cell.innerHTML = s.pSizes[j];
				cell.className = "gen";
			}
			if (s.Styles) {
				cell = row.insertCell(k++);
				cell.innerHTML = s.pStyles[j];
				cell.className = "gen";
			}
			if (! s.no_prices) {
				cell = row.insertCell(k++);
				price = s.pPrices[j];
				ncp = s.pFlags[j] & 0x000F;
				if (ncp > 0) {
					wpb_arr = s.pWbps[j].split("|");
					price = compute(price,Number(s.qtys[skitem]),ncp,wpb_arr[1]+"",wpb_arr[2]+"");
				}
				if ((price == "" || Number(price) == 0) && No_price_text) {
						price = No_price_text;
				} else {
					price = dollars(price);
					if (doPricePerPU) {
						price += "/"+s.pPus[j];
					}
				}
				cell.innerHTML = price;
				cell.align = "right";
			}
			cell.className = "gen";
			cell = row.insertCell(k++);

			if (Number(s.qtys[skitem]) > s.pQty_limits[j] & s.pQty_limits[j] != '999999999') {
				s.qtys[skitem] = s.pQty_limits[j];
			} else if (Number(s.qtys[skitem]) < s.pMin_ord_qtys[j]) {
				s.qtys[skitem] = s.pMin_ord_qtys[j];
			}

			if (s.pUnits[j] != "EA") {
				cell.innerHTML = s.qtys[skitem]+" "+s.pUnits[j]+"/"+s.pQty_units[j];
			} else {
				cell.innerHTML = s.qtys[skitem];
			}
			cell.className = "gen";
			cell.align = "right";
			if (Do_cs_stock_check == 1) {
				iStat = "&nbsp;";
				for (j = 1; j <= Item_cnt; j++) {
					if (On_order[j].i_num == i_num) {
						if ( On_order[j].status != null && On_order[j].status != "") {
							iStat = On_order[j].status;
						}
						break;
					}
				}
				cell = row.insertCell(k++);
				cell.innerHTML=iStat;
				iStat = "";
				cell.id="0ss"+i_num;
				cell.className = "gen";
				cell.align = "right";
			}
		}
		if (Do_cs_stock_check == 2) {
			if (typeof On_hand[i_num] != "undefined") {
			}
		}
	}
	if (done1) {
		s.document.getElementById("tbl_div").style.visibility="visible";
	} else {
		s.document.getElementById("tbl_div").style.visibility="hidden";
	}
	s.document.getElementById("qty").focus();
}

function init_one() {
	var s = ks_main.sub_main;
	var j, k, elem, i_num, skitem, f=s.document.forms[0];
	for (j = 0; j < f.elements.length; j++) {
		elem = f.elements[j];
		if (elem.type == "hidden" && "qty" == elem.name.substring(0,3)) {
			skitem = elem.name.substring(4);
			s.qtys[skitem] = elem.value;
			k = hasItemOrder(skitem);
			if (k) {
				i_num = On_order[k].i_num;
				s.ordered[i_num] = 1;
			}
		}
	}
	if (Permit & 1) {
		show_cs_ordered();
	}
}
function checkStock_setup() {
	var s=ks_main.sub_main;
	var j, item, items="";
	var inums = s.pI_nums.join("%1E");
	for (j = 0; j < s.pI_nums.length; j++) {
		item = unescape(s.items[s.pI_nums[j]]);
		items += skrunch(item) + "%1C5E55%1E";
	}
	checkStock(items,inums);
}
function standardize(str) {
	return str.replace(/\s/g, "").toUpperCase();
}
