function draw_sku_option()
{
	if (product_var.length >= 1 ){
		if(product_var.length==1){
			document.write("<TD>"); 
			if(product_var[0].attr_value2!="") document.write(product_var[0].attr_value2);
			if(product_var[0].attr_value2!="" && product_var[0].attr_value1!="") document.write(" - ");
			if(product_var[0].attr_value1!="") document.write(product_var[0].attr_value1);
			if(product_var[0].attr_value1!="" || product_var[0].attr_value2!="") document.write(" - ");
			document.write(product_var[0].avail_msg);
			document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
			document.write("</TD>");
		}else{	
			document.write("<TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>");
			document.write("<TR VALIGN=TOP ><TD >");
			document.write("<SELECT class=ProductAttr NAME=sku  style='font-size:12px;'>");
			i=attr_values.length;
			labelstr="- Select";
			while (i > -1) {
				if(attr_label[i]!= "") labelstr+= " "+attr_label[i] + " -";
				i--;
			}
			writeoption("",labelstr ,sel_values[0]);
			for (atn=0;atn< product_var.length ;atn++){
				//build option value
				var option_val = "";
				if(product_var[atn].attr_value2!="") option_val+= product_var[atn].attr_value2;
				if(option_val!="") option_val += " - ";				
				if(product_var[atn].attr_value1!="") option_val+= product_var[atn].attr_value1;
				
				if (useVariantPrice=="True"){
					if (on_sale=="True"){
						writeoption(product_var[atn].sku,(option_val + " - $"+ OKStrOfPenny(product_var[atn].price_sale)) + " - " + product_var[atn].avail_msg + "" ,sel_values[0]);
					}else{
						writeoption(product_var[atn].sku,(option_val + " - $"+ OKStrOfPenny(product_var[atn].price_list)) + " - " + product_var[atn].avail_msg + "" ,sel_values[0]);
					}
				}else{
					if (product_var[atn].avail_msg==""){
						product_var[atn].avail_msg=" ";
					}
					writeoption(product_var[atn].sku,(option_val) + " - " + product_var[atn].avail_msg + "",sel_values[0]);
				}
			}
			document.write("</SELECT></TD>");	
			document.write("</TR></TABLE></TD>");
		}
	}
} //end draw_sku_option


//builds and formats option value for sku dropdown
function get_option_val(atn)
{
	var option_val = "";
	if(product_var[atn].attr_value1!="") option_val += product_var[atn].attr_value1;
	if(product_var[atn].attr_value2!="") option_val+= " - " + product_var[atn].attr_value2;				
	if(option_val!="") option_val += " - ";				
	option_val += product_var[atn].avail_msg;
	return option_val;
}


/**
 * Returns true if 'e' is contained in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

/* draws related items vertically (display=1) or horizontally (display=0) on basket.asp */
function draw_related(type,display,message,rel_image_enable,rel_image_width,rel_list_pricelab,rel_sale_pricelab,rel_our_pricelab,desired_cols)
{
	if (Related_prod.length >0)
	{
		//set default values if null
		if (typeof type=="undefined"){ type="0"; }
		if (typeof display=="undefined"){ display=1; }
		if (typeof message=="undefined"){ message=""; }
		if (typeof rel_image_enable=="undefined"){ rel_image_enable="PRODUCT"; }
		if (typeof rel_image_width=="undefined"){ rel_image_width=""; }
		if (typeof rel_list_pricelab=="undefined"){ rel_list_pricelab="Price "; }
		if (typeof rel_sale_pricelab=="undefined"){ rel_sale_pricelab="Sale Price"; }
		if (typeof rel_our_pricelab=="undefined"){ rel_our_pricelab="Our Price"; }
		if (typeof desired_cols=="undefined"){ desired_cols=2; }
		var show_price=1;
		var arrItems = 0;
		var arrIDs = new Array();
		
		//search for related items with matching type
		for (itematn=0;itematn< Related_prod.length ;itematn++)
		{
			//for (atn=0;atn< Related_prod[itematn].related.length ;atn++)
			//{
				//if (Related_prod[itematn].related[atn].crosstype==type)
				if(Related_prod[itematn].crosstype==type)
				{
					arrIDs[arrItems] = new arrtrack_struct();
					arrIDs[arrItems].rp_id = itematn;
					arrIDs[arrItems].r_id = atn;
					arrItems++;
				}
			//}
		}
		//if we have some matching product then proceed
		if (arrIDs.length>0)
		{
			var prodlink="";
  		var col_width = 100/(desired_cols+1);
			
			var itemCount = 0; //used to keep track of number of items -- to close row after desired_cols in horizontal view
			shownItems=new Array(); //used to keep track of items that were already displayed
			var rowCount = Math.ceil(arrIDs.length/3); //used to keep track of number of rows -- for "header" rowspan
			

			document.write("<table cellpadding=\"1\" cellspacing=\"0\" border=\"0\" width=\"100%\" ><tr><td>");
			document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"10\">");
			document.write("  <tr>");
			//document.write("    <td colspan=\""+(desired_cols+1)+"\" valign=\"top\">"+message+"<\/td>");
			document.write("    <td colspan=\""+(desired_cols+1)+"\" valign=\"top\"><img src='assets/images/btn_maywesuggest.jpg'><\/td>");
			document.write("  <\/tr>");
			document.write("  <tr>");
			//document.write("    <td rowspan=\"" + rowCount + "\" valign=\"top\" width=\""+col_width+"%\">");
			//document.write("      <div class=\"DeptPageFeature\">" + message + "<\/div><\/td>");   
			for(i=0;i<arrIDs.length;i++)
			{
			//if the product was not already shown...
				if (!contains(shownItems,Related_prod[arrIDs[i].rp_id].name) && !contains(shownItems,Related_prod[arrIDs[i].rp_id].pf_id))
				{						
					itemCount++; //incr itemCount to track number of items being displayed.
					//add item to array of shown items 
					shownItems[itemCount] = Related_prod[arrIDs[i].rp_id].name;
					shownItems[itemCount] = Related_prod[arrIDs[i].rp_id].pf_id;
					var temp_link = Related_prod[arrIDs[i].rp_id].link;
					//remove last amp if there is one
					if(temp_link.charAt(temp_link.length-1)=='&') temp_link=temp_link.substring(0,temp_link.length-1);
					//build anchor tag using cleaned up temp_link and add dl_id=61
					prodlink="<a href=\"" + temp_link + "&dl_id=61\">";
					
					document.write(" <td class=\"relProduct\" VALIGN=\"bottom\" ALIGN=\"center\" width=\""+col_width+"%\">");
					//product image & link
					if ((Related_prod[arrIDs[i].rp_id].image!="")&&(rel_image_enable!="NONE"))
					{
						document.write(prodlink);
						document.write("<img ALIGN=CENTER BORDER=0 VSPACE=0 HSPACE=0 ALT=\"" + Related_prod[arrIDs[i].rp_id].name + "\" ");
						document.write("SRC=\"assets/product_images/"+ Related_prod[arrIDs[i].rp_id].image +"\"");
						if (rel_image_width !="")
						{
							document.write(" WIDTH =\"" + rel_image_width + "\"");
						}
						document.write("><\/a>");
						document.write("<BR>");
					}
					//product name link
					document.write(prodlink + Related_prod[arrIDs[i].rp_id].name + "<\/a>");
					//product price (if enabled)
					if ((show_price==1)&&(Related_prod[arrIDs[i].rp_id].list_price!=""))
					{
						if (Related_prod[arrIDs[i].rp_id].on_sale!="False" && Related_prod[arrIDs[i].rp_id].sale_price!="" && Related_prod[arrIDs[i].rp_id].sale_price!="$0.00" && Related_prod[arrIDs[i].rp_id].sale_price!=Related_prod[arrIDs[i].rp_id].list_price)
						{
							document.write("<font class=ListPricewSaleR>" + rel_list_pricelab + Related_prod[arrIDs[i].rp_id].list_price + "<\/font>");
							document.write("<font class=SalePriceR>" + rel_sale_pricelab + Related_prod[arrIDs[i].rp_id].sale_price + "<\/font>");
						}else{
							document.write("<font class=ListPricewoSaleR>" + rel_our_pricelab + Related_prod[arrIDs[i].rp_id].list_price + "<\/font>");
						}
					}
					document.write("<\/TD>");
					if (itemCount%desired_cols==0)
					{
						if((itemCount)!=arrIDs.length)
						{
							document.write("</tr>");
						}
					}else{
						if (itemCount==arrIDs.length)
						{
							document.write("<td colspan=" + (itemCount%desired_cols) + ">&nbsp;</td>");
						}
					}					
				}// end if !contains
			}// end for(i=0;i<arrIDs.length;i++)
		}// end if (arrIDs.length>0)
		document.write("<\/TR><\/TABLE></TD></TR></TABLE>");
	}// end if (Related_prod.length>0)
}//end function draw_related

function arrtrack_struct()
{
	this.rp_id
	this.r_id
}