/* FOLLOW ME CART CODE */

/* See FollowMeCart.html for additional code and instruction and the css. */

/*Edit the draw_my_cart function to make it look how you want it to look. 
Edit css styles to control color of background and foreground colors */

/* Draws a table with the follow me cart information and a checkout button to go to the basket page. */
function draw_my_cart(){
	document.write("<table width=95% cellpadding=0 cellspacing=0><tr><td class=cartOutline>");
	
	document.write("<table border=0 cellspacing=1 cellpadding=3 valibn=bottom width=100%>");
	document.write("<tr><td class=cartHeader colspan=2 align=center><font size=1>");
	if (user_firstname!=""){
		document.write("<strong>"+user_firstname.toUpperCase()+"'S CART</strong> ");
	}
	else
	{
		document.write("<strong>YOUR CART</strong> ");
	}
	
	document.write("</font></td></tr><tr><td colspan=2 class=cartItems>");
	for (atn=0;atn< shopping_basket.items.length ;atn++){
		document.write("<a href=\"#\" onClick=\"return(visitargs('product.asp','dept_id="+shopping_basket.items[atn].dept_id+"&pf_id="+shopping_basket.items[atn].pf_id+"',''))\"><img width=30 height=30 border=0 src='assets/product_images/"+shopping_basket.items[atn].image+"'></a><font size=1>......$"+ OKStrOfPenny(shopping_basket.items[atn].item_total)+"<br></font>");
	}
	
	document.write("</td></tr><tr><td align=right class=cartBottom><font size=1>Items:</font></td><td class=cartBottom>");
	document.write("<font size=1><strong>" + shopping_basket.no_items+"</strong></font>");

	document.write("</td></tr><tr><td align=right class=cartBottom><font size=1>Total:</font></td><td class=cartBottom>");
	document.write("<font size=1>$" + OKStrOfPenny(shopping_basket.total_total)+"</strong></font></td></tr>");
	
	document.write("<tr><td class=cartBottom align=center colspan=2>");
	document.write("<a href=\"#\" onclick=\"return(visitargs('basket.asp','',''))\"><img src='assets/images/btntotal2.gif' border=0></a>");
	document.write("</td></table>");
	
	document.write("</td></tr></table>");
}

function draw_my_wish(){
	
}

/**
 * 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=3; }
		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 width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
			document.write("  <tr>");
			document.write("    <td colspan=\""+(desired_cols+1)+"\" valign=\"top\">"+message+"<\/td>");
			document.write("  <\/tr>");
			document.write("  <tr>");
			document.write("    <td colspan=\""+(desired_cols+1)+"\" valign=\"top\"><\/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;
					prodlink="<a href=\"" + Related_prod[arrIDs[i].rp_id].link + "\">";
					document.write(" <td class=\"relProduct\" VALIGN=\"top\" ALIGN=\"left\" 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><br>");
					//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>");
	}// end if (Related_prod.length>0)
}//end function draw_related

function arrtrack_struct()
{
	this.rp_id
	this.r_id
}