//<!-- Copyright (c) 1999-2004 UniteU Technologies Inc.  All rights reserved.   //-->
//<!--

var number_rows=0;
//useVariantPrice = "True";
//This sorts the product array by attr_value1 then attr_value2 alphabetically only.
function value1_sort(a,b){
	if(a.attr_value1==b.attr_value1){
		if(a.attr_value2 >= b.attr_value2){return 1;}else{return -1;}
	}else{
		if(a.attr_value1 > b.attr_value1){return 1;}else{return -1;}
	}
}

//After the buy button is hit, it goes through all the rows of products and makes the list of skus to add and their quantities.
function qt_validator(){
	var skustr="";
	var qtystr="";

	//number_rows is actually the number of unique styles (not colors) for this product.  This is done on the display section in draw_sku_option2
	for(i=0;i<number_rows;i++){
		//alert(eval("document.all.form1.qty_" + i + ".value") + "-" + eval("document.all.form1.sku_" + i + "[document.all.sku_" + i + ".selectedIndex].value"));
		if(eval("document.all.form1.qty_" + i + ".value") != "0"){
			//we got a value that's NOT zero.  do note that we're not checking for negatives, characters, etc.
			// The ASP on orderform_additem should take care of anything funny.  default add-to is 1.
			if (skustr!=""){skustr=skustr + ","; qtystr=qtystr + ",";}
			skustr=skustr + eval("document.all.form1.sku_" + i + "[document.all.sku_" + i + ".selectedIndex].value");
			qtystr=qtystr + eval("document.all.form1.qty_" + i + ".value");
		}
	}

	//assign the strings we've built to the normal sku and quantity inputs.
	document.all.form1.qty.value=qtystr;
	document.all.form1.sku.value=skustr;
	
	//return true to commit the submit to the next page.  If there are any errors then this is the place to stop it.  return false to stay on the page.
	return true;
}

//draw_sku_option3
function draw_sku_option3()
{
	if (Dept_products.length >= 1 )
	{
		if(Dept_products.length==1)
		{
			var atn=0;
			if (useVariantPrice=="True")
			{
				if (on_sale=="True")
				{
					price_string = "$" + OKStrOfPenny(Dept_products[atn].price_sale);
				}else{ 
					price_string = "$" + OKStrOfPenny(Dept_products[atn].price_list);
				}
			}else{
				price_string = "$" + OKStrOfPenny(Dept_products[atn].price_list);
			}
			document.write("<INPUT TYPE=HIDDEN  NAME='sku' VALUE='' >");
			document.write("<INPUT TYPE=HIDDEN NAME='qty' VALUE='0'>");
			document.write("<TD  ALIGN=center> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 BGCOLOR=DADAEE>");
			document.write("<TR valign=middle bgcolor=B2B2E1><TD>&nbsp;&nbsp;</td><TD><B>Qty.</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD><B>Description</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD><B>Option</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD><B>Price</B></TD><td>&nbsp;&nbsp;</td></TR>");
			document.write("<TR VALIGN=middle><TD></TD><TD><Input type=text size=2 maxlength=2 name='qty' value=0></TD><TD></TD><TD>" + Dept_products[0].name + " - " + Dept_products[0].attr_value1 + "</TD><TD></TD><TD>");
			document.write(Dept_products[0].attr_value2 + "</TD><TD></TD><TD>" + Dept_products[0].price_str + "</TD><TD></TD>");
			document.write("<INPUT TYPE=HIDDEN  NAME='sku' VALUE='" + Dept_products[0].sku + "'>");
			document.write("</TR></TABLE></TD>");
			/*
			document.write("<TD  ALIGN=center> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
			document.write("<TR VALIGN=TOP ><TD class=ProductAttrlabel >" + attr_label[0] + "</TD><TD>");
			document.write("&nbsp;" + Dept_products[0].attr_value1 + "&nbsp;" + price_string + "</TD>");
			document.write("<INPUT TYPE=HIDDEN  NAME='sku' VALUE='" + Dept_products[0].sku + "'>");
			document.write("</TR></TABLE></TD>");*/
	    }else{
			document.write("<INPUT TYPE=HIDDEN  NAME='sku' VALUE='' >");
			document.write("<INPUT TYPE=HIDDEN NAME='qty' VALUE='0'>");
			
			//sort the array by value 1
			Dept_products.sort(UUSort);
			
			document.write("<TD ALIGN=center> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor=#DADAEE>");
			//~ i=attr_values.length-1;
			//~ labelstr="";
			//~ while (attr_label[i]!= "" && i >=0 ) 
			//~ {
				//~ labelstr=labelstr + attr_label[i] + " ";
				//~ i=i-1;
			//~ }
			//~ document.write(sel_values[0]);
			//var used to know when to switch to next listing
			var next_line=false;
			var opt_txt=""; //option text, to be built every loop, and emptied into select options at the end of each attr_value1 set
			var opt_count=0; //option count, to be able to count it easily to determine size
			var price_string="";
			
			//print column headers
			document.write ("<tr bgcolor=B2B2E1><TD>&nbsp;&nbsp;</td><TD><B>Qty.</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><B>Description</B></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><B>Option</B></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><B>Price</B></td><td>&nbsp;&nbsp;</td></tr>");
			
			for (atn=0;atn< Dept_products.length ;atn++){
				if (Dept_products[atn].onsale=="True"){
						price_string = "$" + OKStrOfPenny(Dept_products[atn].price_sale);
					}else{ 
						price_string = "$" + OKStrOfPenny(Dept_products[atn].price_list);
					}
				//~ if (atn+1 == Dept_products.length){
					//~ next_line=true;
				//~ }else{
					//~ if(Dept_products[atn].skus[0].attr_value1 != Dept_products[atn+1].skus[0].attr_value1){next_line=true;}
				//~ }
				
				//increment the count and make the option
				opt_count++;
		
				opt_txt=opt_txt + "<Option value='" + Dept_products[atn].skus[0].sku + "'>" +Dept_products[atn].skus[0].attr_value1+" - "+Dept_products[atn].skus[0].attr_value2 + "</Option>";
				
				//If this IS the last part of a color option, then write the row.
				//~ if (next_line)
				//~ {
					//var matches=0;
					//~ switch (leaf_tree[0].dept_name.toLowerCase())
					//~ {
						//~ case "duvet covers":
							//~ if (Dept_products[atn].attr_value1.toLowerCase().indexOf("duvet cover") != -1)
								//~ matches=1;
					//~ }
					//~ if (matches==0)
					//~ {
						document.write("<TR>");
					//~ }else{
						//~ document.write("<TR BGCOLOR=white>");
					//~ }
					document.write ("<td>&nbsp;&nbsp;</td><TD><Input type=text size=2 maxlength=2 name='qty_" + number_rows + "' value=0></TD><td>&nbsp;&nbsp;</td><td valign=middle>" + Dept_products[0].name + " - " + Dept_products[0].short_desc + "</td><td>&nbsp;&nbsp;</td><td valign=middle>");
					//document.write("<Select style='width: 100px' name='sku_" + number_rows + "'>" + opt_txt + "</Select>");
					document.write ("</td><td>&nbsp;&nbsp;</td><TD ALIGN='right'>" + Dept_products[0].price_str + "</Td><td>&nbsp;&nbsp;</td></tr>");
					
					//reset variables and increment number of rows.
					opt_count=0;
					opt_txt="";
					next_line=false;
					number_rows++;
				//~ }
			}//end for
			document.write("</td></TR></TABLE></TD>");
		}//end else
	}//end if
}//end function

function display_spanner_links(intCurrentPage,intMaxPages,spanner_links){document.write(" Paged: "+ intCurrentPage + " of " + intMaxPages + " <BR> Select page <B> &lt; </B>" + spanner_links + "<B> &gt; </B><BR>");}
function display_dept(){if(dept_depts.length>0){display_dept_gen(dept_depts);}}  
function display_label(pf_id,label){document.write("<TD>" + label + "</TD>");}
function display_products(){if (Dept_products.length>0){display_products_gen(Dept_products);}}

function display_product_link(purl,pname,short_desc,price_str,s_id,dept_id,pf_id,basket_enable){
	document.write("<a HREF=\"" + purl + "\" class=\"deptlinkP\" target=\"_top\">" + pname + "</a>&nbsp;" + short_desc );
	//document.write(price_str);
}

function OKStrOfPenny(X) { 
	var T, S=new String(Math.round(X))
	while (S.length<3) S='0'+S
	return S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2);
}

function Display_sku(pf_name,pf_id,dept_id,sku,price_level,price_level2,price_level3,AvailabilitySTR,attr_value1,attr_value2,attr_value3,attr_value4,attr_value5,enable_basket,available,list_string,sale_string){
 	document.write(attr_value1 +" "+ attr_value2 +"SKU:"+ sku );
	document.write(AvailabilitySTR);

	//prices
	document.write("</TD><TD>"+ list_string +"</TD><TD>"+ sale_string +"</TD><TD>");
	
	onc ="return(visitargs('shopper_lookup.asp','target=xt_orderform_additem.asp&addto=1&auto_reg=1&pf_id="+ pf_id +"&dept_id="+ dept_id +"&attr_value1="+attr_value1+"&attr_value2="+attr_value2+"&attr_value3="+attr_value3+"&attr_value4="+attr_value4+"&attr_value5="+attr_value5+"'));"
	document.write("<A href=\"#\" onclick=\""+ onc +"\" ><b>Order Now</b></font></A>");
	document.write("</TD><TD>");
	onc="return(visitargs('product.asp','pf_id="+ pf_id +"&dept_id="+ dept_id +"&attr_value1="+attr_value1+"&attr_value2="+attr_value2+"&attr_value3="+attr_value3+"&attr_value4="+attr_value4+"&attr_value5="+attr_value5+"'));"
	document.write("<A href=\"#\" onclick=\""+ onc +"\" ><b>More Info</b></font></A>");
	document.write("</TD><TD>"); 
}
function sku_sorter(a,b){
	if (a.attr_value1>b.attr_value1){return 1;}else{return -1;}
}

function display_dept_2nd(display_dept_gen){  
	if (display_dept_gen.length >= 1){
		var n_dept=0;
		var atn; 
		
		document.write(s_top_HTML);
		document.write(style_UL_open);	
		for (atn=0;atn< display_dept_gen.length ;atn++){
			if (n_dept==0 || d_display_type!=4){document.write(style_LI_1_open + style_font_2_open);}
			n_dept=n_dept+1 ;
			if (s_image_align=="CENTER"){             
				document.write("<TABLE width=100% BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=CENTER > <TR><TD ALIGN=CENTER >"+ style_font_2_open);
			}
			if (display_dept_gen[atn].dept_image_1_file!="" && s_image_src == "PRODUCT"){
				document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id=" + display_dept_gen[atn].dept_id +"&','SURL')); class=\"deptlinkM\" target=_top >");
				document.write("<IMG ALIGN="+ s_image_align +" ");
				if(s_image_width==""){
					if (display_dept_gen[atn].dept_image_1_width!=""){
						document.write(" WIDTH="+ display_dept_gen[atn].dept_image_1_width +" ");				
					}
				}else{
					document.write(" WIDTH ="+ s_image_width + " ");
				}
				document.write(" BORDER=0  VSPACE=5  HSPACE=5  ALT=\""+ display_dept_gen[atn].dept_name +"\" ");  	
				document.write(" SRC=\"assets/product_images/"+ display_dept_gen[atn].dept_image_1_file +"\"></A>");  	
				if (s_image_align=="CENTER"){ 
					document.write(" </TD></TR> <TR><TD ALIGN=CENTER >"+ style_font_2_open);
				}		
			}
			if (display_dept_gen[atn].dept_disable_name=="" || display_dept_gen[atn].dept_disable_name < 2){
				if (display_dept_gen[atn].dept_display_type==1 || display_dept_gen[atn].dept_display_type==4){
					document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id="+ display_dept_gen[atn].dept_id +"&','SURL')); class=\"deptlinksub\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");
				}else if (display_dept_gen[atn].dept_display_type==2){
					document.write("<A HREF=\"#\" onClick=return(visitargs('frameset.asp','target="+ display_dept_gen[atn].dept_hyperlink +"&','SURL')); class=\"deptlinksub\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");	
				}else{
					document.write("<A HREF=\"#\" onClick=return(visitargs('"+ display_dept_gen[atn].dept_hyperlink +"','','SURL')); class=\"deptlinkP\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");							
				}
			}
			document.write(display_dept_gen[atn].dept_short_description+"test");
		
			if (display_dept_gen[atn].attached_depts!=null && display_dept_gen[atn].attached_depts.length>0){
				document.write("2ndlevelDEPT");
				//display_dept_gen(display_dept_gen[atn].attached_depts);
			}
			if (s_image_align=="CENTER"){document.write(" </TABLE>");}
			if (d_display_type==4){
				if (n_dept==dept_cols){
					n_dept=0;
					document.write(style_LI_1_close);
				}else{
					document.write(style_font_2_close +"</TD><TD>" + style_font_2_open);
				}
			}else{
				document.write(style_LI_1_close);
			}
				
		} //end loop
		document.write(style_UL_close);
	}
}//end display_dept_2nd

function display_dept_gen(display_dept_gen){  
	if (display_dept_gen.length >= 1){
		var n_dept=0;
		var atn; 
		document.write(s_top_HTML);
		document.write(style_UL_open);	
		   
		for (atn=0;atn< display_dept_gen.length ;atn++){
			if (n_dept==0 || d_display_type!=4){document.write(style_LI_1_open + style_font_2_open);}
			n_dept=n_dept+1 ;
			if (s_image_align=="CENTER"){             
				document.write("<TABLE width=100% BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=CENTER > <TR><TD ALIGN=CENTER >"+ style_font_2_open);
			}
			if (display_dept_gen[atn].dept_image_1_file!="" && (s_image_src == "PRODUCT" || s_image_src == "IMAGE" )){
				document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id=" + display_dept_gen[atn].dept_id +"&','SURL')); class=\"deptlinkM\" target=_top >");
				document.write("<IMG ALIGN="+ s_image_align +" ");
				if(s_image_width==""){
					if (display_dept_gen[atn].dept_image_1_width!=""){
						document.write(" WIDTH="+ display_dept_gen[atn].dept_image_1_width +" ");				
					}
				}else{
					document.write(" WIDTH ="+ s_image_width + " ");
				}
				document.write(" BORDER=0  VSPACE=5  HSPACE=5  ALT=\""+ display_dept_gen[atn].dept_name +"\" ");  	
				if (s_image_src=="PRODUCT"){
					document.write(" SRC=\"assets/product_images/"+ display_dept_gen[atn].dept_image_1_file +"\"></A>");  	
				}else{
					document.write(" SRC=\"assets/images/"+ display_dept_gen[atn].dept_image_1_file +"\"></A>");  				    
				}
				if (s_image_align=="CENTER"){ 
					document.write(" </TD></TR> <TR><TD ALIGN=CENTER >"+ style_font_2_open);
				}		
			}
			if(display_dept_gen[atn].dept_disable_name=="" || display_dept_gen[atn].dept_disable_name < 2){
				if (display_dept_gen[atn].dept_display_type==1 || display_dept_gen[atn].dept_display_type==4){
					document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id="+ display_dept_gen[atn].dept_id +"&','SURL')); class=\"deptlinkM\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");
				}else if (display_dept_gen[atn].dept_display_type==2){
					document.write("<A HREF=\"#\" onClick=return(visitargs('frameset.asp','target="+ display_dept_gen[atn].dept_hyperlink +"&','SURL')); class=\"deptlinksub\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");	
				}else{
					document.write("<A HREF=\"#\" onClick=return(visitargs('"+ display_dept_gen[atn].dept_hyperlink +"','','SURL')); class=\"deptlinkP\" target=_top >"+ display_dept_gen[atn].dept_name +"</A>");							
				}
			}
			document.write(display_dept_gen[atn].dept_short_description+"test2");
			
			if (display_dept_gen[atn].attached_products!=null && display_dept_gen[atn].attached_products.length>0){
				display_products_gen(display_dept_gen[atn].attached_products,1);
			}
			if (display_dept_gen[atn].attached_depts!=null && display_dept_gen[atn].attached_depts.length>0){
				display_dept_2nd(display_dept_gen[atn].attached_depts);
			}
			if  (s_image_align=="CENTER"){document.write(" </TABLE>");}
			if(d_display_type==4){
				if (n_dept==dept_cols){
					n_dept=0;
					document.write(style_LI_1_close);
				}else{
					document.write(style_font_2_close +"</TD><TD>" + style_font_2_open);
				}
			}else{
				document.write(style_LI_1_close);
			}	
		} //end loop
		document.write(style_UL_close);
	}
} //end display_dept_gen 

function display_products_gen(Dept_products_gen,p_display_type){ 
	if (p_display_type==null){
		p_display_type=display_type;
	}

	if (Dept_products_gen.length >= 1){
		var sku_index;
		var n_product=0;
		var atn;
		var n_columns=2;
		var index_wide=0;
		var showing_prices=false;
		atn=0;
		
		//addto form
		document.write("<Form name=addtobasket method=GET action=\"shopper_lookup.asp\">");
		document.write("<Input type=hidden name=target value='xt_orderform_additem.asp'>");
		document.write("<Input type=hidden name=auto_reg value='1'>");
		document.write("<Input type=hidden name=sku id=sku value=''>");
		document.write("<Input type=hidden name=qty id=qty value='1'>");
		document.write("<Input type=hidden name=addto id=addtoform value='1'>");
		document.write("<Input type=hidden name=s_id value='" + s_id + "'>");
		document.write("<Input type=hidden name=dept_id id=dept_id value=''>");
		document.write("<Input type=hidden name=pf_id id=pf_id value=''>");
		document.write("</Form>");
		
		document.write(p_top_HTML);
		document.write(style_UL_open);
		document.write("<Table border=0 cellpadding=3 cellspacing=3 BGCOLOR=#ffffff><TR><TD>");
		document.write("<Table border=0 cellpadding=3 cellspacing=3 BGCOLOR=#ffffff>");
		document.write("<tr valign=top><td colspan=5 align=right>");
		document.write("<Input type=image align=absmiddle onclick=\"return add_all_items(" + Dept_products_gen.length + ",'1');\" name=\"addall\" SRC=\"assets/images/departments/btn_collections_add_to_cart.gif\">");
		document.write("&nbsp;&nbsp;&nbsp;");
		document.write("<Input type=image onclick=\"return add_all_items(" + Dept_products_gen.length + ",'4');\" name=\"addall\" src=\"assets/images/departments/btn_collections_add_to_registry.gif\">");
		document.write("&nbsp;&nbsp;&nbsp;");
		document.write("<input type=image src=\"assets/images/departments/btn_collections_set_1_of_each.gif\" alt=\"Add one of each\" onclick=\"add_one_of_each(" + Dept_products_gen.length + ");\">");
		document.write("<tr><td BGCOLOR=#ffffff><b>Name</b></td><td BGCOLOR=#ffffff><b>Attributes</b></td>");
		if(Dept_products_gen[0].enable_basket=="0"){
			document.write("</tr>");
		}else{
			document.write("<td BGCOLOR=#ffffff><b>Qty.</b></td><td BGCOLOR=#ffffff><b>List Price</b></td><td BGCOLOR=#ffffff><b>Sale Price</b></td></tr>");
			showing_prices=true;
		}
		
		//for each product
		for (atn=0; atn<Dept_products_gen.length; atn++){
		
			document.write("<tr><td>");
		
			
			display_product_link("product.asp?s_id="+ s_id +"&dept_id="+ dept_id +"&pf_id="+ Dept_products_gen[atn].pf_id +"&"+ ptargetc,Dept_products_gen[atn].name,Dept_products_gen[atn].short_desc,Dept_products_gen[atn].price_str,s_id,Dept_products_gen[atn].dept_id,Dept_products_gen[atn].pf_id,Dept_products_gen[atn].enable_basket);
			document.write("</TD><TD>");
			//sku array
			if(Dept_products_gen[atn].skus.length>1){
				Dept_products_gen[atn].skus.sort(sku_sorter);
				//dropdown for skus
				//jas 19.JUN.08 added fix for no available skus in dropdown for product
				var my_tmp = "";
				var skus_available = false;
				for (sku_index=0;sku_index<Dept_products_gen[atn].skus.length ;sku_index++){
					if (Dept_products_gen[atn].skus[sku_index].avail!="0"){
						skus_available = true;
						my_tmp+="<Option value=\"" + Dept_products_gen[atn].skus[sku_index].sku + "\">";
						//attributes
						my_tmp+=Dept_products[atn].skus[sku_index].attr_value1+" - "+Dept_products[atn].skus[sku_index].attr_value2;
						//stock msg
						my_tmp+="</Option>";
					}
				}
				if(skus_available)
				{
					document.write("<Input type=hidden id=\"sku_" + atn + "\" name=\"sku_" + atn + "\" value=\"multiple\">");
					document.write("<Select id=\"sel_" + atn + "\" name=\"sel_" + atn + "\">");
					//document.write("<Option value=''>Color Size</Option>");
					document.write(my_tmp);
					document.write("</Select>");
				}
				else
				{
					document.write("<Input type=hidden id=\"sku_" + atn + "\" name=\"sku_" + atn + "\" value=\"" + Dept_products_gen[atn].skus[0].sku + "\">");
					document.write(Dept_products[atn].skus[0].attr_value1);
				}
			}else{
				//single sku instance
				document.write("<Input type=hidden id=\"sku_" + atn + "\" name=\"sku_" + atn + "\" value=\"" + Dept_products_gen[atn].skus[0].sku + "\">");
				document.write(Dept_products[atn].skus[0].attr_value1);
			}
			
			//qty input
			document.write("</td><td>");
			if(showing_prices){
				if(Dept_products_gen[0].enable_basket=="1"){
					document.write("<Input type=text size=2 value='0' maxlength=2 name=\"qty_" + atn + "\" id=\"qty_" + atn + "\">");
				}else{
					document.write("Not available for purchase at this time.");
					document.write("<Input type=HIDDEN size=2 value='noadd' maxlength=2 name=\"qty_" + atn + "\" id=\"qty_" + atn + "\">");
				}
			}else{
				document.write("<Input type=text size=2 value='0' maxlength=2 name=\"qty_" + atn + "\" id=\"qty_" + atn + "\">");
			}
			
			//price str
			document.write("</td><td>" + "$" + OKStrOfPenny(Dept_products[atn].skus[0].price_list));
			document.write("</td><td><font color=red>");
			if (Dept_products[atn].onsale=="True")
			{
				document.write("$"+OKStrOfPenny(Dept_products[atn].skus[0].price_sale));
			}
			n_product=n_product+1;		
			document.write("</font></TD></TR>");
		}

		document.write("<tr valign=top><td align=right colspan=5 NOWRAP>");
		document.write("<Input type=image align=absmiddle onclick=\"return add_all_items(" + Dept_products_gen.length + ",'1');\" name=\"addall\" SRC=\"assets/images/departments/btn_collections_add_to_cart.gif\">");
		document.write("&nbsp;&nbsp;&nbsp;");
		document.write("<Input type=image onclick=\"return add_all_items(" + Dept_products_gen.length + ",'4');\" name=\"addall\" src=\"assets/images/departments/btn_collections_add_to_registry.gif\">");
		document.write("&nbsp;&nbsp;&nbsp;");
		document.write("<input type=image src=\"assets/images/departments/btn_collections_clear_quantity.gif\" alt=\"Clear Quantities\" onclick=\"clear_qty(" + Dept_products_gen.length + ");\">");
		document.write("</td></tr>");
		
		document.write("</Table></TD></TR></Table>");
		document.write(style_UL_close);	
	}else{
		document.write(style_font_1_open + p_no_product_HTML + style_font_1_close);
	}
}
function dept_add_item(prod_index){
	
	var selsku,elt;
	selsku="";
	//get the selected sku
	elt=document.getElementById("sku_" + prod_index);
	if (elt.value=="multiple"){
		//get the selected index off the dropdown
		elt=document.getElementById("sel_" + prod_index);
		selsku=elt[elt.selectedIndex].value;
	}else{
		selsku=elt.value;
	}
	//alert(Dept_products[prod_index].dept_id + ", " + selsku);
	//return false;
	
	if(selsku!=""){
		//set it to sku value
		document.getElementById("sku").value=selsku;
		document.getElementById("pf_id").value=Dept_products[prod_index].pf_id;
		document.getElementById("dept_id").value=Dept_products[prod_index].dept_id;
		//submit form
		return true;
	}else{return false;}
}

function add_all_items(i_prodcount,addto){
	var errmsg="";
	var elt;
	var prodname="";
	var skulist="";
	var sku9="";
	var qtystr="";
	var qtyi;
	
	//first check to make sure all items have a chosen sku
	for (kk=0;kk<i_prodcount;kk++){
		sku9="";
		if(document.getElementById("sku_" + kk).value=="multiple"){
			elt=document.getElementById("sel_" + kk);
			if(elt){sku9=elt[elt.selectedIndex].value;}
		}else{
			sku9=document.getElementById("sku_" + kk).value;
		}
		if(sku9==''){
			prodname=document.getElementById("prodname_" + kk).value
			errmsg=errmsg + "\There was no color picked for " + prodname + ".\n";
		}else{
			qtyi=document.getElementById("qty_" + kk)
  			//set tempvar to qty if possible
  			if(qtyi){tempvar=qtyi.value}else{tempvar=0;}
  			//if qty is valid then add the item
  			if((tempvar != "0") && (IsNumeric(tempvar)) && (tempvar.length>0)){
  				if (skulist!=""){
  				  skulist=skulist + ",";
  				  qtystr=qtystr + ",";
  				}
  				qtystr=qtystr + qtyi.value;
  				skulist=skulist + sku9;
  			}
  		}
	}

	//if we have all skus properly, submit the add, otherwise give msg and return false.
	if(errmsg.length>0){
		alert(errmsg);
		//return false;
	}else{
		document.getElementById("sku").value=skulist;
		document.getElementById("qty").value=qtystr;
		document.getElementById("addtoform").value=addto;
		document.addtobasket.submit();
		//return true;
	}
}

function add_one_of_each(i_prodcount){
	for (kk=0;kk<i_prodcount;kk++){
		if(document.getElementById("qty_" + kk).value != "noadd"){document.getElementById("qty_" + kk).value='1';}
	}
}

function clear_qty(i_prodcount){
	for (kk=0;kk<i_prodcount;kk++){
		if(document.getElementById("qty_" + kk).value != "noadd"){document.getElementById("qty_" + kk).value='0';}
	}
}

//////// HELPER FUNCTION FOR qt_validator //////////////
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var myChar;

   for (q = 0; q < sText.length && IsNumber == true; q++)
   {
     myChar = sText.charAt(q);
     if (ValidChars.indexOf(myChar) == -1)
     {
       IsNumber = false;
     }
   }
   return IsNumber;
}