//<!-- 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=10 CELLPADDING=0 CELLSPACING=5 BGCOLOR=afbcc0>");
			document.write("<TR valign=middle bgcolor=e7e7e0><TD style='color:#ffffff;font-size:12px'>&nbsp;&nbsp;</td><TD><B>Qty.</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD style='color:#ffffff;font-size:12px'><B>Description</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD style='color:#ffffff;font-size:12px'><B>Option</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><TD style='color:#ffffff;font-size:12px'><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=1 CELLPADDING=3 CELLSPACING=3 bgcolor=#e7e7e0>");
			//~ 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=e7e7e0><TD>&nbsp;&nbsp;</td><TD style='color:#ffffff;font-size:12px'><B>Qty.</B></TD><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='color:#ffffff;font-size:12px'><B>Description</B></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='color:#ffffff;font-size:12px'><B>Option</B></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='color:#ffffff;font-size:12px'><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_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 + "<br> - " + 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'>" <br>+ 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(" Page: "+ 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=\"1\" 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>"+ p_top_HTML +"</p>");
		

		//document.write(style_UL_open);
		//document.write("<Table border=0 cellpadding=3 cellspacing=3 ><TR><TD>");
		document.write("<Table width='700' border=0 cellpadding=0 cellspacing=0 style=\"padding:0px 0px 0px 0px; margin:0px 0px 0px 5px; \">");
		//document.write("<tr><td colspan=6 align=right>");
		//document.write("<input type=image src=\"assets/images/btn_clearqty.gif\" alt=\"Clear Quantities\" onclick=\"clear_qty(" + Dept_products_gen.length + ");\">");
		document.write("<tr><td colspan=2 BGCOLOR=#afbcc0 style='color:#ffffff;font-size:12px' ><b>" + dept_name + "</b></td><td BGCOLOR=#afbcc0 style='color:#ffffff;font-size:12px'><b>Sizes</b></td><td BGCOLOR=#afbcc0 style='color:#ffffff;font-size:12px'><b>Color</b></td>");
		if(Dept_products_gen[0].enable_basket=="0"){
			document.write("<td colspan=3 BGCOLOR=#afbcc0>&nbsp;</td></tr>");
		}else{
			document.write("<td BGCOLOR=#afbcc0 style='color:#ffffff;font-size:12px' colspan=2><b>Price</b></td><td BGCOLOR=#afbcc0 style='color:#ffffff;font-size:12px' align='center'><b>Quantity</b></td></tr>");
			showing_prices=true;
		}
		
		var count = 0; //used for inputs
		
		//for each product
		for (atn=0; atn<Dept_products_gen.length; atn++){
			
			//add a blank row at beginning
			document.write('<tr>');
			document.write('<td colspan="7" BGCOLOR=#e7e7e0>&nbsp;</td>');
			document.write('</tr>');
		
			document.write("<tr><td BGCOLOR=#e7e7e0>&nbsp;</td><td BGCOLOR=#e7e7e0>");
		
			//display product name
			//document.write(Dept_products_gen[atn].name);
			
			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].price_str,s_id,Dept_products_gen[atn].dept_id,Dept_products_gen[atn].pf_id,Dept_products_gen[atn].enable_basket);
			
			//sort skus
			Dept_products_gen[atn].skus.sort(UUSort);
			
			//sizes
			document.write("</TD><TD BGCOLOR=#e7e7e0 style='font-size:12px;'>");
			
			//if(Dept_products_gen[atn].skus.length>1){
				//dropdown for skus
				//document.write("<Input type=hidden id=\"sku_" + atn + "\" name=\"sku_" + atn + "\" value=\"multiple\">");
				//document.write("<Option value=''>Color Size</Option>");
				
				var curSize = "";
				var curSelect = "";
				
				
				for (sku_index=0;sku_index<Dept_products_gen[atn].skus.length ;sku_index++){
						if(curSize != Dept_products[atn].skus[sku_index].attr_value1)
						{
							curSize = "";
							curSelect = "";
							
						}
						
						if(curSize == "")
						{							
							
							//show size
							document.write(Dept_products[atn].skus[sku_index].attr_value1);
							curSize = Dept_products[atn].skus[sku_index].attr_value1;
							
							//colors
							document.write("</TD><TD BGCOLOR=#e7e7e0 style='font-size:12px;'>");
							
							//start select and show first color
							curSelect = "sel_" + count;
							
							//jas 02.APR.08 -- fixed code for only one sku (see else statement below)
							//document.write("<Input type=hidden id=\"sku_" +count+ "\" name=\"sku_" +count+ "\" value=\"multiple\">");
							
							
							if(Dept_products_gen[atn].skus.length>1){
								document.write("<Input type=hidden id=\"sku_" +count+ "\" name=\"sku_" +count+ "\" value=\"multiple\">");
								document.write("<Select style='font-size:12px;' id=\"sel_" +count+ "\" name=\"sel_" +count+ "\">");							
								document.write("<Option value=\"" + Dept_products_gen[atn].skus[sku_index].sku + "\">");
							}
							else if (Dept_products_gen[atn].skus.length==1)
							{
								document.write("<Input type=hidden id=\"sku_" +count+ "\" name=\"sku_" +count+ "\" value=\""+Dept_products_gen[atn].skus[sku_index].sku+"\">");
							}
							
							document.write(Dept_products[atn].skus[sku_index].attr_value2);
							//stock msg
							document.write(" (" + Dept_products[atn].skus[sku_index].avail_msg + ")");
							
							if(Dept_products_gen[atn].skus.length>1){
								document.write("</Option></select>");
							}
							
							//price str
							if(Dept_products[atn].onsale =="True" && Dept_products[atn].skus[sku_index].price_sale!=0 && Dept_products[atn].skus[sku_index].price_sale != Dept_products[atn].skus[sku_index].price_list)
							{
								document.write("</td><td BGCOLOR=#e7e7e0 colspan=2 style='font-size:12px;' nowrap align=top>" + "<font style=\"text-decoration:line-through;\">$" + OKStrOfPenny(Dept_products[atn].skus[sku_index].price_list) + "</font><br>SALE $" + OKStrOfPenny(Dept_products[atn].skus[sku_index].price_sale));
							}
							else
							{
								document.write("</td><td BGCOLOR=#e7e7e0 colspan=2 style='font-size:12px;'>" + "$" + OKStrOfPenny(Dept_products[atn].skus[sku_index].price_list));
							}
							//avail 
							//document.write("</td><td BGCOLOR=#e7e7e0>");
							
							//qty input
							document.write("</td><td BGCOLOR=#e7e7e0 align='center' style='font-size:12px;'>");
							if(showing_prices){
								if(Dept_products_gen[atn].enable_basket=="1"){
									document.write("<Input type=text size=2 value='0' maxlength=2 name=\"qty_" +count+ "\" id=\"qty_"+count + "\">");
									document.write("&nbsp;<Input type=image onclick=\"return add_all_items(" + (count+1) + ",'1');\" name=\"addall\" SRC=\"assets/images/btnbuy.gif\">");
								}else{
									document.write("Not available.");
									document.write("<Input type=HIDDEN size=2 value='noadd' maxlength=2 name=\"qty_"+count + "\" id=\"qty_"+count + "\">");
								}
							}else{
								document.write("<Input type=text size=2 value='0' maxlength=2 name=\"qty_"+count + "\" id=\"qty_"+count + "\">");
							}
							
							//end cell and row and start a new row
							document.write("</td></tr><tr><td BGCOLOR=#e7e7e0 colspan=2>&nbsp;</td><td BGCOLOR=#e7e7e0 style='font-size:12px;'>");
							count++;
						}						
						else if(curSize == Dept_products[atn].skus[sku_index].attr_value1) //if on curSize
						{
							//add color option
							var theSel = document.getElementById(curSelect);
							theSel.options[theSel.length] = new Option(Dept_products[atn].skus[sku_index].attr_value2 + ' (' + Dept_products[atn].skus[sku_index].avail_msg + ')', Dept_products_gen[atn].skus[sku_index].sku);
						}

				}//end for each sku
				
			n_product=n_product+1;		
			document.write("&nbsp;</td><td BGCOLOR=#e7e7e0 colspan=4>&nbsp;</TD></TR>");
			
			//add a blank row and a row with line
			//blank row
			
			
			//line row
			document.write('<tr>');
			document.write('<td colspan="7" valign="top" BGCOLOR=#e7e7e0 height=1 style="padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;"><img src="assets/images/spacer.gif" width="1" height="1"></td>');
			document.write('</tr>');
			
		} //end for each produt

		if(showing_prices){
			document.write("<tr><td align=right colspan=5 BGCOLOR=#afbcc0>");
			document.write("<Input type=image align=right onclick=\"return add_all_items(" + count + ",'1');\" name=\"addall\" SRC=\"assets/images/btnpurchase2.gif\">");
		}else{
			document.write("<tr><td align=right colspan=3 BGCOLOR=#e7e7e0>");
			document.write("<Input type=image align=right onclick=\"return add_all_items(" + count + ",'3');\" name=\"addall\" src=\"assets/images/btnaddquote.gif\">");
		}
		document.write("</td><td BGCOLOR=#e7e7e0 colspan=2>");
		document.write("<Input type=image align=right onclick=\"return add_all_items(" + count + ",'4');\" name=\"addall\" src=\"assets/images/btnaddwish.gif\">");
		document.write("</td></tr>");
		
		document.write("</Table>");
		//document.write("</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(count,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<count;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(skulist.length==0)
		errmsg = "Make the quantity greater than 0 to add a specific product to cart.";
	//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;
}