/** Product Grid Tab Display **/

var errorDisplayed = false;
var newwindowImage;

function Set_CookieMinutes( name, value, expires, path, domain, secure ) 
{
	Set_Cookie(name, value, ((expires/60)/24), path, domain, secure)
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

Set_Cookie("LLBTestCookie", "true", "", "/","","");

if (document.cookie.indexOf("LLBTestCookie") == -1)
{
	alert("Your browser has to be set to accept cookies before you can place an order at llbean.com/business.  Please visit our Help Desk section for more information.");
}

function notifyEmptyGrid()
{
	alert("Please click the Update/Add link next to your quantities in step 2 to continue to step 3.");
}

function notifyCartContents()
{
	showConfirm("cartContents", "We are unable to provide the quantity requested.  Please update your selected quantites in Step 4.");
}

function ManageTabPanelDisplay() {
	//
	// Between the parenthesis, list the id's of the div's that 
	//     will be effected when tabs are clicked. List in any 
	//     order. Put the id's in single quotes (apostrophes) 
	//     and separate them with a comma -- all one line.
	//
	var idlist = new Array('tab1focus','tab2focus','tab1ready','tab2ready','content1','content2');

	// No other customizations are necessary.
	if(arguments.length < 1) { 
		return; 
	}
	
	for(var i = 0; i < idlist.length; i++) {
   		var block = false;
   	
   		for(var ii = 0; ii < arguments.length; ii++) {
   			if(idlist[i] == arguments[ii]) {
        			block = true;
        			break;
         		}
      		}
   		if(block) { 
   			document.getElementById(idlist[i]).style.display = "block"; 
   		} else { 
   			document.getElementById(idlist[i]).style.display = "none"; 
   		}
   	}
}

function clickColor(piccolor, picimage) {
	setTimeout("document['picture'].src='" + picimage + "';", 100);
	document.getElementById('txtColor').innerHTML = piccolor;
	newHref = document.getElementById('largepicturepopup').href;
	newHref = newHref.substring(0,newHref.lastIndexOf("=")+1) + piccolor + "')";
	document.getElementById('largepicturepopup').href = newHref;
	document.getElementById('largepicturepopup0').href = newHref;
	document.getElementById('largepicturepopup1').href = newHref;
}

 /* The product details popup */
function largeImagePopup(URL) {
 	newwindowImage=open(URL,"popup","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=yes,status=yes,width=625,height=575");
 	newwindowImage.focus();

}

function strfilter(str)
{
	return str.replace(" ", "_");
}

function toNestedJS(str)
{
	return str.replace("'", "\'");
}


/** Messaging Class **/

var curNote;
var curToken;
var curId;

curToken = 1;

var curConfirm;
var curConfirmToken;
var curConfirmId;

curConfirmToken = 1;



function initHover(name)
{
	var obj;
	obj = document.createElement("div");
	obj.id = name;
	obj.className = "notePopup";
	obj.style.display = "none";
	
	document.body.appendChild(obj);
	
	return obj;
}

function killHover(token)
{
	if (token == curToken)
	{
		new Effect.Fade(curNote, {duration: 0.5 });
		//curNote.style.display = "none";
	}
}

//var curNote = initHover("noteHoverObject");

function showHover(evt, id, msg)
{
	if (curId != id)
	{
		curId = id;
	if (!evt) evt = window.event; // Get event details for IE
	var obj = this;
	var startX = evt.clientX + Geometry.getHorizontalScroll();
	var startY = evt.clientY + Geometry.getVerticalScroll();

	if ((document.body.clientWidth - evt.clientX) < 180)
	{
	 startX = (document.body.clientWidth-200);
	}
	
	if (!curNote)
	{
		curNote = initHover("noteHoverObject");
	}
	
	curNote.style.display = "none";

	curNote.innerHTML = msg;
	
	curNote.style.top = startY + 25 + "px";
	curNote.style.left = startX + 50 + "px";
	
	//display event performance details

	new Effect.Appear(curNote, {duration: 0.5 });
	setTimeout("killHover(" + ++curToken + ");", 2000);
	}
}


function initConfirm(name)
{
	var obj;
	obj = document.createElement("div");
	obj.id = name;
	obj.className = "confirmPopup";
	obj.style.display = "none";
	
	document.body.appendChild(obj);
	
	return obj;
}

function killConfirm(token)
{
	if (token == curConfirmToken)
	{
		new Effect.Fade(curConfirm, {duration: 0.5 });
		curId = "";
		//new Effect.Fade(document.getElementById("fade"), {duration: 0.5});
		//curNote.style.display = "none";
	}
}

function showConfirm(id, msg)
{
	if (curId != id)
	{
		curId = id;
	var startX = Geometry.getHorizontalScroll();
	var startY = Geometry.getVerticalScroll();


	startX = Geometry.getViewportWidth() / 2 - 150 + Geometry.getHorizontalScroll();
	startY = Geometry.getViewportHeight() / 2 - 100 + Geometry.getVerticalScroll();

	if ((Geometry.getViewportWidth()) < 180)
	{
	 startX = (Geometry.getViewportWidth()-200);
	}
	
	if (!curConfirm)
	{
		curConfirm = initConfirm("confirmHoverObject");
	}
	
	curConfirm.style.display = "none";

	var closeText = "<br><br><div class='confirmClose'><a href='javascript:void(0);' onClick='killConfirm(curConfirmToken);'>OK</a></div>";

	curConfirm.innerHTML = msg + closeText;
	
	curConfirm.style.top = startY + "px";
	curConfirm.style.left = startX + "px";
	
	//display event performance details

	//document.getElementById("fade").style.display="block";
	
	//new Effect.Appear(objfade, {duration: 0.5 });	
	new Effect.Appear(curConfirm, {duration: 0.5 });
	
	}
}



function showPopup(evt)
{
	if (!evt) var evt = window.event;
	
	var obj = this;
	var startX = evt.clientX + Geometry.getHorizontalScroll();
	var startY = evt.clientY + Geometry.getVerticalScroll();
	

	if (!styleWindow)
	{
	
		myDiv = document.createElement("div");
		myDiv.id = "popupWindow";
		myDiv.className = "logoPopup"; 
		myDiv.style.top = startY + windowY + "px";
		myDiv.style.left = startX + windowX + "px";
	
		document.body.appendChild(myDiv);
		
		
		strInner = '<div class="popupHeader"><span class="popupTitle">Saved Logos:</span> Click a logo below to select it.</div>';
		strInner += '<div class="popupClose"><div class="closeImage"> <img src="/llbean/templates/_current/images/arrow-green-tan.gif" width="7" height="12" alt="" border="0"/></div><div class="closeText"><a href="javascript:void(0);" onClick="killPopup();">close</a></div></div><br clear="all"/>';
		strInner += '<div class="popupInstructions"><div class="popupInstructionsImage"><img src="/llbean/templates/_current/images/arrow-red-tan.gif" width="5" height="8" alt="" border="0"/></div><div class="popupInstructionsDetail">Saved logos that match your fabric and placement selection | Other saved logos</div></div><br clear="all"/>';
		
		
		strInner += '<div class="popupFrame"></div>';
		
		myDiv.innerHTML = strInner;
		
		styleWindow = myDiv;
	} else {
		styleWindow.style.top =  startY + windowY + "px";
		styleWindow.style.left = startX + windowY + "px";
		new Effect.Appear(styleWindow, {duration: 0.5 });
	}
	
}









/** Product Grid Class **/
	
	var SIZETABLE;
	
	function productGrid() {
		this._horizontal = 0;
		this._rawData = new Array();
		this._rawOrderData= new Array();
		this._rawPersonalizations = new Array();
		this._rawLogoData = new Array();
		this._rawBackorder = new Array();
		this._rawStock = new Array();
		this._reset = "true";
		this._numEmbroidery = 0;
		this._productId = productId;
		this._hasCart = 0;
		this._hasPersonalizations = 0;
		this._personalizationNum = 0;
		this._currentSessionKey = "";

	}
	
	productGrid.prototype._curEmbroidery;
	productGrid.prototype._numEmbroidery;
	productGrid.prototype._productId;
	productGrid.prototype._color;
	productGrid.prototype._colorid;
	productGrid.prototype._rawData;
	productGrid.prototype._rawOrderData;
	productGrid.prototype._rawLogoData;
	productGrid.prototype._rawBackorder;
	productGrid.prototype._rawStock;
	productGrid.prototype._rawPersonalizations;
	productGrid.prototype._nextColor;
	productGrid.prototype._horizontal;
	productGrid.prototype._personalizationNum;
	productGrid.prototype._reset;
	
	productGrid.prototype._hasCart;
	
	productGrid.prototype._tempPlacement;
	productGrid.prototype._tempInstructions;
	
	productGrid.prototype._hasPersonalizations;

	productGrid.prototype._currentSessionKey;

	productGrid.prototype._step1 = 1;
	productGrid.prototype._step2 = 0;
	productGrid.prototype._step3 = 0;
	productGrid.prototype._step4 = 0;
	productGrid.prototype._fabric = "";

	productGrid.prototype.setPersonalizations = function (result)
	{
		if (result != "")
			this._hasPersonalizations = 1;
			
	}

	productGrid.prototype.setFabric = function (strFabric)
	{
		this._fabric = strFabric;
	}

	productGrid.prototype.getFabric = function ()
	{
		return this._fabric;
	}

	productGrid.prototype.setHorizontal = function ()
	{
		this._horizontal = 1;
	}

	productGrid.prototype.getHorizontal = function ()
	{
		return this._horizontal;
	}

	productGrid.prototype.getPersonalizations = function ()
	{
		return this._hasPersonalizations;
	}

	productGrid.prototype.hasCart = function ()
	{
		return this._hasCart;
	}



	productGrid.prototype.setPersonalizationNum = function (num)
	{
		this._personalizationNum = num;
	}

	productGrid.prototype.getPersonalizationNum = function ()
	{
		return this._personalizationNum;
	}



	productGrid.prototype.setCurEmbroidery = function(embId)
	{
		this._curEmbroidery=embId;
	}
	productGrid.prototype.getCurEmbroidery = function()
	{
		if (errorDisplayed == true)
			return false;

	 	if (this._numEmbroidery >= 2)
		{
			return false;
		}
		return this._curEmbroidery;
	}
	
	productGrid.prototype.getStock = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		var stock = this._rawData[color][product][size]["stocklevel"];
		
		if (stock == "" || stock == " ")
		{
			stock = 0;
		}
		
		return stock;
	}
	
	productGrid.prototype.getBackorder = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		var stock = this._rawData[color][product][size]["backordered"];
		
		if (stock == "" || stock == " ")
		{
			stock = 0;
		}
		
		return stock;
	}
	
		
	productGrid.prototype.getStockLevel = function(sku)
	{
		return this._rawStock[sku];
	}
	
	productGrid.prototype._retrievedSessionTime = -1; // Session time retrieved by below function
	
	// LLB-1239: Session time should be checked when the 'Add Logo' button is pressed (for file upload)
	// This function sets the above variable and returns true if a valid server response is received, else false and variable = -1
	productGrid.prototype.getSessionTime = function()
	{
		var url = "/llbean/xml/getSessionTime.jsp";
		
		var httpRequest;
		
		// For Firefox, Safari, etc.
		try {
			httpRequest = new XMLHttpRequest();
		}
		
		// For Internet Explorer
		catch(e) {
			try {
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			
		catch(e) {
		
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch(e) {
				this._retrievedSessionTime = -1;
				return false;
			}
		}
		}
		
		httpRequest.open("GET", url, false);		
		httpRequest.send(null);
		
		if( httpRequest.readyState == 4 ) {
				if( httpRequest.status == 200 ) {
				
					this._retrievedSessionTime = httpRequest.responseText * 1;
					return true;
				}
				else {
				
					this._retrievedSessionTime = -1;
					return false;
				}
		}
		else {
			
			this._retrievedSessionTime = -1;
			return false;
		}		
	}
	
	productGrid.prototype.addEmbroidery = function(embId, placementName, instructions, thefile, docheck, thelogo, wherefrom)
	{	
		//alert(embId + " / " + placementName + " / " + thefile);
		
		// LLB-1239: Get session time and check it
		if( pg.getSessionTime() && this._retrievedSessionTime != -1 ){
			pg.checkSession(this._retrievedSessionTime);
		}
			
	if (!this.hasCart())
	{
		alert("We're sorry, more information is needed to order this item. Please select all options for this item and Add to Bag.");
		return false;
	} 
	
	
	if (thelogo[wherefrom].checked || thelogo[2].checked || thelogo[3].checked)
	{
	
   	if (errorDisplayed == false) {

	    if (this._numEmbroidery >= 2)
	    {
	    	if (docheck) alert("Only 2 embroideries are allowed.");
    	  	//errorDisplayed = true;
	    	return false;
	    }
	    if (placementName.options[placementName.selectedIndex].value == "")
	    {
	    	if (docheck) alert("Please select a placement in Step A.");
	    	//errorDisplayed = true;
	    	return false;
	    }

	    if (this.getCurEmbroidery() == "" && thefile.value.length <= 0)
	    {
	    	if (docheck) alert("Please select an embroidery in Step B.");
	    	//errorDisplayed = true;
	    	return false;
	    }
	    

	    if (thefile.value.length > 4)
	    {
		/*var extension = thefile.value.substring(thefile.value.length -3, thefile.value.length).toUpperCase(); 	    
		if ((extension != "EPS") && (extension != "PDF") && (extension != "JPG") && 
			(extension != "GIF") && (extension != "BMP") && (extension != "PSD")) {

		    	//errorDisplayed = true;
			if (docheck) alert("We're sorry, you have attached a file in a invalid format.\nWe can only accept image files in one of the following formats:\n eps, pdf, jpg, gif, bmp, psd.\n\nPlease select another file and try again.");
			//document.uploadForm.logoFile = "";
			//thefile.value.length = 0;
			var stepc = document.uploadForm.instructions.value;
			var stepa = document.uploadForm.placement.selectedIndex;
			document.uploadForm.reset();
			document.uploadForm.instructions.value = stepc;
			document.uploadForm.placement.selectedIndex = stepa;
			return false;
			}
		*/
	    } 
	}
	    errorDisplayed = false;
	    if (this.getPersonalizations())
	    {
		if (thefile.value != "" && embId == "")
		{
			this._tempPlacement = placementName.options[placementName.selectedIndex].value;
			this._tempInstructions = instructions.value;
			this.setCurEmbroidery("");
			
			//alert(this._tempPlacement + " " + this._tempInstructions);
			return true;
		} else {
		
	
		strPlacement = placementName.options[placementName.selectedIndex].value;
		placementName.selectedIndex = 0;
		
		tempInstructions = instructions.value;
		instructions.value = "";
		
		strInstructions = tempInstructions.replace("+","&#043;");
		
		objImg = document.getElementById("logoHolder");
		objImg.innerHTML = "";
		
		strEmbId = embId;
		
		this.setCurEmbroidery("");
		
		var recentLogoOne = new Ajax.Request(
			"/llbean/xml/getRecentLogo_first.jsp",
			{
				method: 'get',
				onComplete: handleRecentLogoOne
			}		
		);
		var recentLogoTwo = new Ajax.Request(
			"/llbean/xml/getRecentLogo_second.jsp",
			{
				method: 'get',
				onComplete: handleRecentLogoTwo
			}		
		);
		
		document.uploadForm.reset();
		
		//alert("/llbean/xml/addPersonalization.jsp?embId=" + strEmbId+ "&placementName=" + strPlacement + "&instructions=" + strInstructions + "&aa=" + Math.floor(Math.random()*50000));
		var myAjax = new Ajax.Request(
			"/llbean/xml/addPersonalization.jsp?embId=" + strEmbId+ "&placementName=" + strPlacement + "&instructions=" + escape(strInstructions) + "&aa=" + Math.floor(Math.random()*50000),
			{
				method: 'get',
				onComplete: handleAddedPersonalization
			}
		
		);
	
		this._reset = "false";
		return false;
		}
		
	    } else {
		alert("Embroidery not available on this item.");
		return false;

	    }
	    return false;
	    } 
	    return false;
	    
	}
	
	function handleRecentLogoOne(reqNew)
	{
		var data = eval("(" + reqNew.responseText + ")");
		//alert(reqNew.responseText);
		
		var embId = data.embId;
		var filename = data.filename;
		
		var row = document.getElementById('recentUpload_first');
		for (var i = 0; i < 3; i = i + 1)
		{
			row.deleteCell(0);
		}

		var cell_0 = document.createElement('td');
		row.appendChild(cell_0);
		
		cell_0.className = "new_logoCellFirst";
		cell_0.innerHTML = "<input type=\"radio\" name=\"logoType\" value=\"choose\" onClick=\"parent.setEmb('" + embId + "','construct','" + filename + "',0,'1');\"/>";
		
		var cell_1 = document.createElement('td');
		row.appendChild(cell_1);
		
		cell_1.innerHTML = "&nbsp;";
		
		var cell_2 = document.createElement('td');
		row.appendChild(cell_2);
		
		cell_2.className = "new_logoCellFirst_text";
		cell_2.innerHTML = "<a href=\"javascript:void(0);\" onClick=\"parent.setEmb('" + embId + "','construct','" + filename + "',0,'1');\">Recently Uploaded: " + filename + "</a>";
		
		//alert(row.innerHTML);
		//document.getElementById("recentUpload_first").innerHTML = 'hello';
	}
	
	function handleRecentLogoTwo(reqNew)
	{
		var data = eval("(" + reqNew.responseText + ")");
		//alert(reqNew.responseText);
		
		var embId = data.embId;
		var filename = data.filename;
		
		var row = document.getElementById('recentUpload_second');
		for (var i = 0; i < 3; i = i + 1)
		{
			row.deleteCell(0);
		}
		
		var cell_0 = document.createElement('td');
		row.appendChild(cell_0);
		
		cell_0.className = "new_logoCellSecond";
		cell_0.innerHTML = "<input type=\"radio\" name=\"logoType\" value=\"choose\" onClick=\"parent.setEmb('" + embId + "','construct','" + filename + "',1,'1');\"/>";
		
		var cell_1 = document.createElement('td');
		row.appendChild(cell_1);
		
		cell_1.innerHTML = "&nbsp;";
		
		var cell_2 = document.createElement('td');
		row.appendChild(cell_2);
		
		cell_2.className = "new_logoCellSecond_text";
		cell_2.innerHTML = "<a href=\"javascript:void(0);\" onClick=\"parent.setEmb('" + embId + "','construct','" + filename + "',1,'1');\">Recently Uploaded: " + filename + "</a>";
		
		//alert(row.innerHTML);
		//document.getElementById("recentUpload_second").innerHTML = reqNew.responseText;
	}
	
	// Changes for LLB-1742, LLB-1743, LLB-1744 follow
	productGrid.prototype.resetEmbroideries = function()
	{		
		for (i=0; i<this._rawPersonalizations.length; i++)
		{
			embId = this._rawPersonalizations[i]["embId"];
			placement = this._rawPersonalizations[i]["placement"];
			placementId = this._rawPersonalizations[i]["placementId"];
		
			this.removeEmbroidery(embId, placementId, 1); // Added flag to indicate the call is coming from the 'Skip' button
		}
		pg.resetPersonalization();										// Reset the raw data
		pg.displayPersonalizations();									// Refresh the display area
		document.getElementById("logoHolder").innerHTML = "";			// Clear the logo holder display (left of step 3 after selecting logo)
		document.getElementById("placementSelect").selectedIndex = 0;	// Reset the placement select box
		this.toggleStep(3, 0);											// Close step 3
	}
	
	productGrid.prototype.removeEmbroidery = function(embId, placementName, fromSkipButton)
	{
		
		if (fromSkipButton == 1) {
		
			var myAjax = new Ajax.Request(
				"/llbean/xml/removePersonalization.jsp?embId=" + embId+ "&placementName=" + placementName + "&aa=" + Math.floor(Math.random()*50000),
				{
					method: 'get',
					onComplete: handleRemovedPersonalization // Mimics handleAddedPersonalizations, but does not call displayPersonalizations()
				}		
			);
	
			this._reset = "false";
			
		} else {
		
			var myAjax = new Ajax.Request(
				"/llbean/xml/removePersonalization.jsp?embId=" + embId+ "&placementName=" + placementName + "&aa=" + Math.floor(Math.random()*50000),
				{
					method: 'get',
					onComplete: handleAddedPersonalization
				}		
			);
	
			this._reset = "false";
		}
	}
	
	productGrid.prototype.updateEmbroideries = function ()
	{
		
		var myAjax = new Ajax.Request(
			"/llbean/xml/getPersonalization.jsp?aa=" + Math.floor(Math.random()*50000),
			{
				method: 'get',
				onComplete: handleAddedPersonalization
			}
		
		);
		
		this._reset = "false";		
	}

	function handleRemovedPersonalization(reqNew)
	{
		//alert(reqNew.responseText);
		var data = eval("(" + reqNew.responseText + ")");
		pg.checkSession(data.sess);
		
		pg.resetPersonalization();
		
		for (var i=0; i<parseInt(data.personalizations.length); i++)
		{
		//	alert(data.personalizations[i].llbEmbId);
			pg.addDataPersonalization(i, data.personalizations[i].embId, data.personalizations[i].placement, data.personalizations[i].instructions,  data.personalizations[i].filename,  data.personalizations[i].url,  data.personalizations[i].llbEmbId, data.personalizations[i].placementId);
		}
		if (i > 0)
		{
			pg.setPersonalizationNum(i);
		}
		pg._numEmbroidery = parseInt(data.personalizations.length);
		//pg.displayPersonalizations();
	}

	function handleAddedPersonalization(reqNew)
	{
		//alert(reqNew.responseText);
		var data = eval("(" + reqNew.responseText + ")");
		pg.checkSession(data.sess);
		
		pg.resetPersonalization();
		
		for (var i=0; i<parseInt(data.personalizations.length); i++)
		{
		//	alert(data.personalizations[i].llbEmbId);
			pg.addDataPersonalization(i, data.personalizations[i].embId, data.personalizations[i].placement, data.personalizations[i].instructions,  data.personalizations[i].filename,  data.personalizations[i].url,  data.personalizations[i].llbEmbId, data.personalizations[i].placementId);
		}
		if (i > 0)
		{
			pg.setPersonalizationNum(i);
		}
		pg._numEmbroidery = parseInt(data.personalizations.length);
		pg.displayPersonalizations();
	}
	
	productGrid.prototype.resetPersonalization = function ()
	{
		this._rawPersonalizations = new Array();
		this.setPersonalizationNum(0);
	}
	
	productGrid.prototype.addDataPersonalization = function (index, embId, placement, instructions, filename, url, llbEmbId, placementId)
	{



/*
		if (!this._rawData[color])
		{
			this._rawData[color] = new Array();
		}
		
		if (!this._rawData[color][product])
		{
			this._rawData[color][product] = new Array();
		}
		
		if (!this._rawData[color][product][size])
		{
			this._rawData[color][product][size] = new Array();
		}
		
*/


		

	
		if (!this._rawPersonalizations[index])
		{	
			
			this._rawPersonalizations[index] = new Array();
		}
		
		//alert("PID: " + placementId);
		
		if (!llbEmbId) llbEmbId = "";
		this._rawPersonalizations[index]["llbEmbId"] = llbEmbId;
		this._rawPersonalizations[index]["embId"] = embId;
		this._rawPersonalizations[index]["placement"] = placement;
		this._rawPersonalizations[index]["placementId"] = placementId;
		this._rawPersonalizations[index]["instructions"] = instructions;
		this._rawPersonalizations[index]["filename"] = filename;
		this._rawPersonalizations[index]["url"] = url;
		
		
		//alert(this._rawPersonalizations[index]["placement"]);
		
	}

	productGrid.prototype.getDataState = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		return this._rawData[color][product][size]["state"];
	}
	
	productGrid.prototype.getDataQty = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		return this._rawData[color][product][size]["qty"];
	}
	
	productGrid.prototype.getDataSku = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		return this._rawData[color][product][size]["sku"];
	}
	
	productGrid.prototype.getDataBackorder = function(color, product, size)
	{
		// LLB-1641
		color = color.replace("'","");
		
		return this._rawData[color][product][size]["backorder"];
	}
	
	productGrid.prototype.resetCart = function ()
	{
		this._hasCart = 0;
		var myAjax = new Ajax.Request(
				"/llbean/xml/addCart.jsp?sku=&productId=&qty=&reset=" + this._reset+ "&aa=" + Math.floor(Math.random()*50000),
				{
					method: 'get'
				}
		);

		//this._reset = "false";
		
	}
	
	productGrid.prototype.addCart = function (sku, productid, qty, stock)
	{
		if (qty > stock)
		{
			showConfirm("message-" + sku, "Only " + stock + " of this item are currently in stock.  Additional quantities are available for backorder, and will be listed separately in \"Your Selections\" (Step 4 below).");
			/*if (!confirm("Only " + stock + " of this item are currently in stock.  Additional quantities are available for backorder, and will be listed separately in \"Your Selections\" (Step 4 below)."))
			{
				return;
			}*/
		}
		
		if (parseInt(qty)!=qty-0)
		{
			alert("You have entered an invalid quantity. Please enter a number of 1 or greater in the quantity field.");
			return;
		} else {
			// it's an int
			if (parseInt(qty) <= 0)
			{
				alert("You have entered an invalid quantity. Please enter a number of 1 or greater in the quantity field.");
				return;
			}
			
		}
		
		var myAjax = new Ajax.Request(
			"/llbean/xml/addCart.jsp?sku=" + sku + "&productId=" + productid + "&qty=" + qty + "&reset=" + this._reset + "&aa=" + Math.floor(Math.random()*50000),
			{
				method: 'get',
				onComplete: handleAdd
			}
		
		);
	
		this._reset = "false";
	}
	
 	productGrid.prototype.updateCartItem = function (sku, productid, pqty, stock, backorder)
 	{

		//alert(pqty + " / " + stock + " / " + backorder);

 		backorder = parseInt(backorder);
 		var total = stock + backorder;
 		
 		var strBackorder = "";
 		var strInstock = "";
 		
 		var neededBack = pqty - stock;
 		
 		if (neededBack <= backorder)
 		{
 			neededBack = neededBack;
 		} else {
 			neededBack = backorder;
 		}
 		
 		
		if (pqty > stock)
		{
			if (backorder > 0)
			{
				strBackorder = neededBack + " available for backorder. ";
				
				//showConfirm("message-" + sku, "Only " + stock + " of this item are currently in stock.  " + neededBack + " are available for backorder.  Please update your requested quantity to " + total + " in Step 4 below.");
			}
			
			if (stock > 0)
			{
				strInstock = "Only " + stock + " of this item are currently in stock. ";
			}
			
			if (total > 0)
			{
				if (pqty > total)
				{
					showConfirm("message-" + sku, strInstock + strBackorder + "Please update your requested quantity to " + total + " in Step 4 below.");
				} else {
					showConfirm("message-" + sku, strInstock + strBackorder);
				}
			} else {
				showConfirm("message-" + sku, "Please remove this item in Step 4.");
			}

		}
 	
		var set = 0;
		for (var i=0; i<this._rawOrderData.length; i++)
		{

			var id = this._rawOrderData[i]["id"];
			var cartid = this._rawOrderData[i]["cartid"];

			if (sku == id)
			{
				set = 1;
				this.updateCart(cartid, pqty);
				break;
			}

		}			
		
		if (set==0)
		{
			this.addCart(sku, productid, pqty);
		}

 	}
	
	productGrid.prototype.cartContentsValid = function ()
	{
		
		for (var i=0; i<this._rawOrderData.length; i++)
		{
			var qty = parseInt(this._rawOrderData[i]["qty"]);
			var orderable = parseInt(this._rawOrderData[i]["orderable"]);
			//alert("testing: " + i + " -- " + qty + " > " + orderable);

			if (qty > orderable) return false;
		}	
		return true;
	}
	
	productGrid.prototype.updateCart = function (pcartid, pqty)
	{
			var targ = "/llbean/cart/productGridOrder_cart.jsp";
			var targ2 = "/llbean/cart/productGridOrder_cart_contents.jsp";
			
			var targ = "/llbean/xml/getCart.jsp";
			var targ2 = "/llbean/xml/getCart.jsp";
			
			var postVars = "";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingSuccessURL=/llbean/index.jsp&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.expressCheckoutErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoSuccessURL=../checkout/shipping.jsp&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponSuccessURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update.x=&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update.y=&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateSuccessURL=" + targ + "&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.checkout=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShopping=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.expressCheckoutErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateSuccessURL=&";
			
			//postVars += "_DARGS=/llbean/cart/productGridOrder_cart_contents.jsp&";
			postVars += "_DARGS=" + targ2 + "&";
			postVars += "_dyncharset=UTF-8&";
			postVars += "reset=" + this._reset + "&";
			
			for (var i=0; i<this._rawOrderData.length; i++)
			{

				var id = this._rawOrderData[i]["id"];
				var cartid = this._rawOrderData[i]["cartid"];
				
				if (pcartid != cartid)
					postVars += cartid + "=" + document.theform2[cartid].value + "&";
				else 
					postVars += cartid + "=" + pqty + "&";
		
			}			
			
		
			var myAjax = new Ajax.Request(
				"/llbean/xml/getCart.jsp",
				{
					method: 'post',
					postBody: postVars,
					onComplete: handleAdd
				}
			
			);
			
			
			this._reset = "false";
		}
	
	productGrid.prototype.updateFullCart = function ()
		{

			var targ = "/llbean/cart/productGridOrder_cart.jsp";
			var targ2 = "/llbean/cart/productGridOrder_cart_contents.jsp";
			var targ = "/llbean/xml/getCart.jsp";
			var targ2 = "/llbean/xml/getCart.jsp";
			
			var postVars = "";
			var postVars2 = "";
			
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingSuccessURL=/llbean/index.jsp&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.expressCheckoutErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoSuccessURL=../checkout/shipping.jsp&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponSuccessURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update.x=&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update.y=&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateErrorURL=" + targ + "&";
			postVars += "/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateSuccessURL=" + targ + "&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.checkout=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShopping=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.continueShoppingSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.expressCheckoutErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.moveToPurchaseInfoSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.removeCouponSuccessURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.update=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateErrorURL=&";
			postVars += "_D:/atg/llbean/commerce/order/purchase/ProductGridOrderFormHandler.updateSuccessURL=&";
			
			//postVars += "_DARGS=/llbean/cart/productGridOrder_cart_contents.jsp&";
			postVars += "_DARGS=" + targ2 + "&";
			postVars += "_dyncharset=UTF-8&";
			postVars += "reset=" + this._reset + "&";
			
			for (var i=0; i<this._rawOrderData.length; i++)
			{

				var id = this._rawOrderData[i]["id"];
				var qty = this._rawOrderData[i]["qty"];
				var cartid = this._rawOrderData[i]["cartid"];
				var display = this._rawOrderData[i]["display"];
				var size = this._rawOrderData[i]["size"];
				var color = this._rawOrderData[i]["color"];
				var price = this._rawOrderData[i]["price"];
				var priceTotal = this._rawOrderData[i]["priceTotal"];
				var backorder = this._rawOrderData[i]["backorder"];
				var stocklevel = this._rawOrderData[i]["stocklevel"];
				var stock = this._rawOrderData[i]["stock"];

				
				var cartid_qty =document.theform2[cartid].value;
				if ((cartid_qty=="") || (cartid_qty==null))
					cartid_qty=0;
				
				postVars += cartid + "=" + document.theform2[cartid].value + "&";
				postVars2 += cartid + "=" + document.theform2[cartid].value + "&";
		
			}			
			//alert(postVars2);
			
			var myAjax = new Ajax.Request(
				"/llbean/xml/getCart.jsp",
				{
					method: 'post',
					postBody: postVars,
					onComplete: handleAdd
				}
			
			);
			
			
			this._reset = "false";
		}
	
	
	productGrid.prototype.removeCart = function (cartid)
	{
//		alert("Removing cart ID: " + cartid);
		this.updateCart(cartid, 0);
	}
	
	function handleAdd()
	{

		pg.loadOrderData();
	}
	
	productGrid.prototype.addData = function(color, product, size, state, backorder, qty, sku, stock, iibackorder, fabricType)
	{
	
		// LLB-1641
		color = color.replace("'","");
		
		if (!this._rawData[color])
		{
			this._rawData[color] = new Array();
		}
		
		if (!this._rawData[color][product])
		{
			this._rawData[color][product] = new Array();
		}
		
		if (!this._rawData[color][product][size])
		{
			this._rawData[color][product][size] = new Array();
		}		
	
		// If there are only backorderable quantites left, set the state accordingly (related to LLB-1746)
		if (stock <= 0 && iibackorder > 0 && state == "available")
		{
			state = "backorderable";
		}
		
		/*
		this will automatically set items in the grid to out of stock if the available quantity is 0
		*/
		if (stock <= 0 && iibackorder <= 0 && state == "available")
		{
			//state = "inshoppingbag";
			state = "outofstock";
		}
		
		// LLB-1746,  do the same if the state is backorderable
		if (stock <= 0 && iibackorder <= 0 && state == "backorderable")
		{
			state = "outofstock";
		}		
		
		this._rawData[color][product][size]["state"] = state;
		this._rawData[color][product][size]["qty"] = qty;
		this._rawData[color][product][size]["sku"] = sku;
		this._rawData[color][product][size]["product"] = product;
		this._rawData[color][product][size]["backorder"] = backorder;
		this._rawData[color][product][size]["backordered"] = iibackorder;
		this._rawData[color][product][size]["stocklevel"] = stock;
		this._rawData[color][product][size]["fabricType"] = fabricType;
		
		this.setFabric(fabricType);

		this._rawStock[sku] = stock;
	}
	
	productGrid.prototype.hasOrder = function ()
	{
		if (this._rawOrderData.length > 0)
		{
			return 1;
		} else {
			return 0;
		}
	}
	
	productGrid.prototype.hasColor = function ()
	{
		if (this._color != "" && this._color != null)
		{
			return 1; 
		} else {
			return 0;
		}
	}
	
	
	
	
	productGrid.prototype.addOrder = function(id, qty, display, size, color, product, price, priceTotal, backorder, stock, cartid, stocklevel, allocated, backordered, availability, orderable)
	{
	

		if (!this._rawOrderData)
		{
			this._rawOrderData = new Array();
		}
		
		var next = this._rawOrderData.length;
		
		if (!this._rawOrderData[next])
		{
			this._rawOrderData[next] = new Array();
		}
		
		// LLB-1750: Must get true stocklevel from xml for redirect
		//stocklevel = this.getStockLevel(id);	
		
		this._rawOrderData[next]["id"] = id;
		this._rawOrderData[next]["qty"] = qty;
		this._rawOrderData[next]["cartid"] = cartid;
		this._rawOrderData[next]["display"] = display;
		this._rawOrderData[next]["size"] = size;
		this._rawOrderData[next]["color"] = color;
		this._rawOrderData[next]["product"] = product;
		this._rawOrderData[next]["price"] = price;
		this._rawOrderData[next]["priceTotal"] = priceTotal;
		this._rawOrderData[next]["backorder"] = backorder;
		this._rawOrderData[next]["stocklevel"] = stocklevel;
		this._rawOrderData[next]["stock"] = stock;
		this._rawOrderData[next]["allocated"] = allocated;
		this._rawOrderData[next]["backordered"] = backordered;
		this._rawOrderData[next]["availability"] = availability;	
		this._rawOrderData[next]["orderable"] = parseInt(orderable);
		//this._rawOrderData[next]["orderable"] = parseInt(allocated) + parseInt(backordered);
		
		this._hasCart = 1;
		
		//alert(id + " | " + qty + " | " + cartid + " | " + display + " | " + size + " | " + color + " | " + price + " | " + priceTotal + " | " + backorder + " | " + stocklevel + " | " + stock);
		
		
	}
	
	
	productGrid.prototype.resetOrder = function()
	{
		this._hasCart = 0;
		this._rawOrderData = new Array();
	}
	
	
	productGrid.prototype.addDataProductName = function(color, product)
	{
		// LLB-1641
		color = color.replace("'","");
		
		if (!this._rawData[color])
		{
			this._rawData[color] = new Array();
		}
		
		if (!this._rawData[color]["_productNames"])
		{
			this._rawData[color]["_productNames"] = new Array();
		}
		

		this._rawData[color]["_productNames"][this._rawData[color]["_productNames"].length] = product;
	}
	
	
	productGrid.prototype.addDataProductSku = function(color, sku)
	{
	
		// LLB-1641
		color = color.replace("'","");
		
		if (!this._rawData[color])
		{
			this._rawData[color] = new Array();
		}
		
		if (!this._rawData[color]["_productSkus"])
		{
			this._rawData[color]["_productSkus"] = new Array();
		}
		

		this._rawData[color]["_productSkus"][this._rawData[color]["_productSkus"].length] = sku;
		
	}
	
	
	productGrid.prototype.addDataSize = function(color, size)
	{
	
		// LLB-1641
		color = color.replace("'","");
		
		if (!this._rawData[color])
		{
			this._rawData[color] = new Array();
		}
		
		if (!this._rawData[color]["_sizes"])
		{
			this._rawData[color]["_sizes"] = new Array();
		}
		

		this._rawData[color]["_sizes"][this._rawData[color]["_sizes"].length] = size;
			
		
	}
	
	
	
	productGrid.prototype.setProductId = function(productId)
	{
		this._productId = productId;
		if (Get_Cookie("LLB-product") == productId)
		{
			this._color = " ";
			this.setColor(Get_Cookie("LLB-color"));
			this.handleColorId(Get_Cookie("LLB-colorid"));
			this.loadOrderData();
			this.updateEmbroideries();
			this._reset = false;
			setTimeout("pg.toggleStep(4, 1);", 250);
			setTimeout("pg.toggleStep(3, 1);", 500);
			setTimeout("pg.resetCookie()", 1000);
		} else {
			setTimeout("pg.resetCart()", 1000);
		}
	}

	productGrid.prototype.getProductId = function()
	{
		return this._productId;
	}


	productGrid.prototype.setColor = function(color)
	{

		this._color = color;
		this.loadData(color);
		
		var doc = document.getElementById("step2title");
		doc.innerHTML = "<img src=\"/llbean/templates/_current/images/arrow-green-solid.gif\" alt=\"\" border=\"0\">&nbsp;<b>Step 2:</b> Select Size(s) for " + color + "<br/>"
		
	}

	productGrid.prototype.handleColorId = function (colorid)
	{
		setTimeout("handleClick" + colorid + "();", 1);
	}

	productGrid.prototype.setColorId = function(colorid)
	{
		this._colorid = colorid;
	}

	productGrid.prototype.getColorId = function()
	{
		return this._colorid;
	}

	productGrid.prototype.getColor = function ()
	{
		return this._color;
	}


	productGrid.prototype.loadData = function (color)
	{
		// LLB-1641
		color = color.replace("'","");
		
		if (this._rawData[color])
		{
			// load cached
			this.populateSizes(color);
			
		} else {
		
			this._nextColor = color;
			
			var myAjax = new Ajax.Request(
			"/llbean/xml/getSizes.jsp?categoryId=" + this.getProductId() + "&color=" + this.getColor() + "&aa=" + Math.floor(Math.random()*50000),
			{
				method: 'get',
				onComplete: handleLoadData
			
			}
		
		);
		
		}

	}
	

	function handleLoadData(reqNew)
	{

		
			var data = eval("(" + reqNew.responseText + ")");
			pg.checkSession(data.sess);
			
//			var data = reqNew.responseText.evalJSON();
			
			for (var i=0; i<parseInt(data.titles.productNames.length); i++)
			{

				pg.addDataProductName(data.options[0].color, data.titles.productNames[i]);
			}

			for (var i=0; i<parseInt(data.titles.productSkus.length); i++)
			{
				pg.addDataProductSku(data.options[0].color, data.titles.productSkus[i]);
			}

			for (var i=0; i<parseInt(data.titles.sizes.length); i++)
			{
				pg.addDataSize(data.options[0].color, data.titles.sizes[i]);
			}

			for (var i=0; i<parseInt(data.options.length); i++)
			{
				pg.addData(data.options[i].color, data.options[i].product, data.options[i].size, data.options[i].state, data.options[i].backorder, data.options[i].qty, data.options[i].sku, data.options[i].iistocklevel, data.options[i].iibackorderLevel, data.options[i].fabricType);
			}
			
			
			pg.loadedData();
/*
		} else {
			// Error loading AJAX data
		}
*/
	}

	productGrid.prototype.loadedData = function ()
	{
		this.populateSizes(this._nextColor);
		this._nextColor = "";
	}
	
	
	
	productGrid.prototype.addLogo = function (id, filename, colorway, lastused, llbembid, url, afilter)
	{
	
		var next = this._rawLogoData.length;
	
		if (!this._rawLogoData[next])
		{
			this._rawLogoData[next] = new Array();
		}
		
		this._rawLogoData[next].id = id;
		this._rawLogoData[next].filename = filename;
		this._rawLogoData[next].colorway = colorway;
		this._rawLogoData[next].lastused = lastused;
		this._rawLogoData[next].llbembid = llbembid;
		this._rawLogoData[next].url = url;
		this._rawLogoData[next].filter = afilter;
		
	}
	
	productGrid.prototype.resetLogoData = function ()
	{
		this._rawLogoData = new Array();
	}
	
	function handleLoadLogoData(reqNew) 
	{
		var data = eval("(" + reqNew.responseText + ")");
		pg.checkSession(data.sess);
		
		pg.resetLogoData();
		
		//alert(this._rawLogoData.length);
		
		for (var i=0; i<parseInt(data.logos.length); i++)
		{
		
			pg.addLogo(data.logos[i].id, data.logos[i].filename, data.logos[i].colorway, data.logos[i].lastused, data.logos[i].llbembid, data.logos[i].url, data.logos[i].filter);
		}
		
		
	}
	
	
	productGrid.prototype.loadLogoData = function(placement, fabric)
	{
		killPopup();
		var myAjax = new Ajax.Request(
			"/llbean/xml/getLogos.jsp?fabric=" + fabric + "&placement=" + placement + "&a=" + Math.floor(Math.random()*50000),
			{
				method: 'get',
				onComplete: handleLoadLogoData
			
			}		
		)
	}
	
	
	productGrid.prototype.loadOrderData = function ()
	{
		if (this._rawOrderData && 1==0)
		{
			// load cached, disabled
			this.populateOrder();
			
		} else {
			
			var myAjax = new Ajax.Request(
						"/llbean/xml/getCart.jsp?a=" + Math.floor(Math.random()*50000),
						{
							method: 'get',
							onComplete: handleLoadOrderData
						
						}
					
			);

		}
	}
	
	function handleLoadOrderData(reqNew)
	{
		var data = eval("(" + reqNew.responseText + ")");
		pg.checkSession(data.sess);
			
		pg.resetOrder();
			
		for (var i=0; i<parseInt(data.cart.length); i++)
		{
			// LLB-1750: Now takes iistocklevel for sake of redirect (getStock is undefined on page reload, iistocklevel comes from xml; see addOrder)
			pg.addOrder(data.cart[i].id, data.cart[i].qty, data.cart[i].display, data.cart[i].size, data.cart[i].color, data.cart[i].product, data.cart[i].price, data.cart[i].priceTotal, data.cart[i].backorder, data.cart[i].stock, data.cart[i].cartid, data.cart[i].iistocklevel, data.cart[i].iiallocated, data.cart[i].iibackordered, data.cart[i].iiavailability, data.cart[i].iiorderable);
		}
		
		pg.loadedOrderData();
	}

	productGrid.prototype.loadedOrderData = function ()
	{
		this.populateOrder();
	}
	
	productGrid.prototype.loadDataCurrent = function ()
	{
		this.loadData(this.getColor());
	}
	
	function resetCell(color, product, size, bottom, stock, cellid, backorder)
	{
		obj = document.getElementById(cellid);
		
		//alert("1: " + obj.innerHTML);
		
		while (obj.firstChild) obj.removeChild(obj.firstChild);
		obj.innerHTML = "";
		//obj.innerHTML = "TEST";
		obj.className = "";
		obj.appendChild(pg.generateCell(color, product, size, bottom, stock, cellid, backorder));
		
		//alert("2: " + obj.innerHTML);
	}
	
	productGrid.prototype.generateCell = function (color, product, size, bottom, stock, cellid, backorder)
	{
		// LLB-1641
		color = color.replace("'","");
		cellid = cellid.replace("'","");
		
		var ok = 0;
		var link = document.createElement('DIV');
		var linkid = "link-" + strfilter(color + "_" + product + "_" + size);
		link.id = linkid;

		var sku = this.getDataSku(color, product, size);
		var state = this.getDataState(color, product, size);
		
		if (parseInt(bottom))
		{
			var linkClass = " bottomRow";
		} else {
			var linkClass = "";
		}	
		switch(state)
		{
			case "notoffered":
				link.className = "pgTableCellNotOffered" + linkClass;
				break;
			case "available":
			
				var defaultCell = document.createElement("DIV");
				defaultCell.className = "on";
				defaultCell.innerHTML = "<span class='pgUl'>In stock</span>";
				//defaultCell.title = "header=[click to add to your selections]";
				
				link.appendChild(defaultCell);
				
				var active = document.createElement("DIV");
				active.className = "off";
				
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update</a> /<br><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Add</a></div>";
				
				
				//alert("resetCell(" + linkid + ", '" + toNestedJS(color) + "', '" + toNestedJS(product) + "', '" + toNestedJS(size) + "', '" + toNestedJS(bottom) + "', '" + toNestedJS(stock) + "')");
				//alert("\"resetCell('" + linkid + "', '" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "')\"");
				//alert("<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + linkid + "', '" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>");
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "');\">Update /<br>Add</a></div>";
				active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + strfilter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + strfilter(color + "_" + product + "_" + size)+"'].value, " + stock + ", " + backorder + ");resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "');\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div>";
				//alert(active.innerHTML);


			
				link.appendChild(active);
			
				link.className = "pgTableCell" + linkClass;
			/*	link.innerHTML = "In stock";				*/
				link.onmouseover = function (evt) {
				
					if (ok == 0)
					{
						this.className = "pgTableCell inStockHighlight" + linkClass;
						showHover(evt, linkid, "click to add to your selections");
					}
				}
				link.onmouseout = function () {
					if (ok == 0)
					{
						this.className = "pgTableCell" + linkClass;
					}
				}
				
				link.onclick = function () {
					killHover(curToken);
					setShadow(2);
					if (ok == 0)
					{
						ok = 1;
							
						link.className = "active pgTableCell" + linkClass;
					
						defaultCell.className = "off";
						active.className = "on";
						
						document.theform["qty-" + strfilter(color + "_" + product + "_" + size)].focus();
					}
				}
				

				break;




			case "backorderable":
			
				var defaultCell = document.createElement("DIV");
				defaultCell.className = "on";
				defaultCell.innerHTML = "<span class='pgUl'>Avail. " + this.getDataBackorder(color, product, size) + "</span>";
				//defaultCell.title = "header=[click to add to your selections]";
				
				link.appendChild(defaultCell);
				
				var active = document.createElement("DIV");
				active.className = "off";
				
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update</a> /<br><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Add</a></div>";
				
				
				//alert("resetCell(" + linkid + ", '" + toNestedJS(color) + "', '" + toNestedJS(product) + "', '" + toNestedJS(size) + "', '" + toNestedJS(bottom) + "', '" + toNestedJS(stock) + "')");
				//alert("\"resetCell('" + linkid + "', '" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "')\"");
				//alert("<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + linkid + "', '" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>");
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + filter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + filter(color + "_" + product + "_" + size)+"'].value, " + stock + ");resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "');\">Update /<br>Add</a></div>";
				active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div><div class=\"pgQty\">Qty.</div><div class=\"pgInput\"><input maxlength=\"4\" type=\"text\" name=\"qty-" + strfilter(color + "_" + product + "_" + size) + "\" value=\"\" size=\"1\" class=\"pgInputBox\"/></div><div class=\"pgActions\"><a href=\"javascript:void(0);\" onclick=\"pg.updateCartItem('" + pg.getDataSku(color,product,size) + "', '" + product + "', document.theform['qty-" + strfilter(color + "_" + product + "_" + size)+"'].value, " + stock + ", " + backorder + ");resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "');\">Update /<br>Add</a></div>";
				//active.innerHTML = "<div class='pgClose'><a href=\"javascript:void(0);\" onClick=\"resetCell('" + color + "', '" + product + "', '" + size + "', '" + bottom + "', '" + stock + "', '" + cellid + "', '" + backorder + "')\"><img src=\"/llbean/templates/_current/images/pgClose.gif\" alt=\"Close\" border=\"0\"/></a></div>";
				//alert(active.innerHTML);


			
				link.appendChild(active);
			
				link.className = "pgTableCell" + linkClass;
			/*	link.innerHTML = "In stock";				*/
				link.onmouseover = function (evt) {
				
					if (ok == 0)
					{
						this.className = "pgTableCell inStockHighlight" + linkClass;
						showHover(evt, linkid, "click to add to your selections");
					}
				}
				link.onmouseout = function () {
					if (ok == 0)
					{
						this.className = "pgTableCell" + linkClass;
					}
				}
				
				link.onclick = function () {
					killHover(curToken);
					setShadow(2);
					if (ok == 0)
					{
						ok = 1;
							
						link.className = "active pgTableCell" + linkClass;
					
						defaultCell.className = "off";
						active.className = "on";
						
						document.theform["qty-" + strfilter(color + "_" + product + "_" + size)].focus();
					}
				}
				

				break;
			
			/********* Commented out for LLB-1740, copied logic from cas availaible (above) *************************************************************************
			 ********************************************************************************************************************************************************
				link.className = "pgTableCell" + linkClass;
				link.innerHTML = "Avail. " + this.getDataBackorder(color, product, size);

				link.onmouseover = function () {
					this.className = "pgTableCell inStockHighlight" + linkClass;
				}
				link.onmouseout = function () {
					this.className = "pgTableCell" + linkClass;
				}
				
				link.onclick = function () {
					
					//this.className = "pgTableInputCell" + linkClass;
					//this.innerHTML = "<img src=\"/templates/_current/images/buttons/pgClose.gif\" alt=\"Close\" border=\"0\"/><div class=\"qty\">Qty <input maxlength=\"4\" type=\"text\" name=\"qty\" value=\"1\" size=\"2\"/></div><div class=\"actions\">Update<br>Add</div>";
					
		
					pg.addCart(pg.getDataSku(color,product,size), product, 1);
				}

				break;
			*********************************************************************************************************************************************************
			*********************************************************************************************************************************************************/
			
			case "outofstock":
				link.className = "pgTableCell soldOut" + linkClass;
				link.innerHTML = "Sold Out";
				break;
				
			case "inshoppingbag":
				link.className = "pgTableCell soldout" + linkClass;
				link.innerHTML = "In Shopping Bag";
				break;
			default:
				link.className = "pgTableCell" + linkClass;
				link.innerHTML = state;
				break;
		}



		//link.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.addCart('" + this.getDataSku(color,product,size) + "', '" + product + "', 1);\">" + this.getDataState(color,product,size) + "</a>";

		return link;

	}
	
	function returnsToHTML(str)
	{	
		while (str.indexOf("\n") != -1)
		{
			str = str.replace("\n", "<BR>");
		}
		return str;
	}
	
	productGrid.prototype.displayPersonalizations = function () 
	{
		var outputstr;
		var embId;
		var placement;
		var placementId;
		var instructions;

		outputstr = document.createElement("DIV");

		var target = document.getElementById("logoDetails");
			
		while(target.firstChild) target.removeChild(target.firstChild);

		
		for (i=0; i< this._rawPersonalizations.length; i++)
		{
		
			llbEmbId = this._rawPersonalizations[i]["llbEmbId"];
			embId = this._rawPersonalizations[i]["embId"];
			placement = this._rawPersonalizations[i]["placement"];
			placementId = this._rawPersonalizations[i]["placementId"];
			instructions = this._rawPersonalizations[i]["instructions"];
			filename = this._rawPersonalizations[i]["filename"];
			url = this._rawPersonalizations[i]["url"];
			
			curObj = document.createElement("DIV");
			
			curObj.className = "logoDetailLineHighlight";
			curObj.innerHTML = "<div class='placementLeft'><b>Placement #" + (i + 1) + "</b></div><div class='placementRemove'><a href='javascript:void(0);' onClick='removeEmbroidery(\"" +placementId + "\",\"" + embId + "\");'>Remove</a></div><br clear='all'/>" + placement;
			//alert("<div class='placementLeft'><b>Placement #" + (i + 1) + "</b></div><div class='placementRemove'><a href='javascript:void(0);' onClick='removeEmbroidery(\"" +placementId + "\",\"" + embId + "\");'>Remove</a></div><br clear='all'/>" + placement);
			target.appendChild(curObj);
			
			curObj = document.createElement("DIV");
			
			curObj.className = "logoDetailLineBorder";
			
			if (llbEmbId != "")
			{
				curObj.innerHTML = "<img src='" + url + "' width=60 alt='' border=0/><br><b>Logo:</b><br>" + filename;
			} else {
				curObj.innerHTML = "<b>Logo:</b><br>" + filename + " - uploaded";
			}
			target.appendChild(curObj);
			
			curObj = document.createElement("DIV");
			
			curObj.className = "logoDetailLine";
			curObj.innerHTML = "<b>Special Instructions:</b><br>" + returnsToHTML(instructions);
			target.appendChild(curObj);
			
		}

		if (i != 0)
		{

		curObj = document.createElement("DIV");
		
		curObj.className = "logoDetailCompleteLine";
		curObj.innerHTML = "&nbsp;";
		target.appendChild(curObj);
		
		pg.toggleStep(3, 1);

		} else {
		
		curObj = document.createElement("DIV");
		
		curObj.className = "logoDetailLine";
		curObj.innerHTML = "Complete Steps A, B and C for each logo placement (up to two) and click \"Confirm Logo.\"";
		target.appendChild(curObj);
	
		}
		
		
		target.appendChild(outputstr);

	}
	
	productGrid.prototype.populateSizes = function (color)
	{
		// LLB-1641
		color = color.replace("'","");
		
		var table;
		table = document.createElement("TABLE");
		table.setAttribute("cellSpacing", "0");
		table.setAttribute("cellPadding", "0");
		table.setAttribute("border", "0");
		
		
		var tbody;
		tbody = document.createElement("TBODY");
		table.appendChild(tbody);
		
		var row;
		row = document.createElement("TR");
		
		var cell;
		cell = document.createElement("TD");
		
		// first blank cell
		cell.appendChild(document.createTextNode(""));
		row.appendChild(cell);
		

		
		for (var i=0; i<this._rawData[color]["_productNames"].length; i++)
		{
			
			cell = document.createElement("TD");
			var div = document.createElement("DIV");
			div.className = "pgTableProduct";
			div.innerHTML = this._rawData[color]["_productNames"][i];
			
			cell.appendChild(div);
			
			row.appendChild(cell);
		}
		
		tbody.appendChild(row);
	
		for (var i=0; i<this._rawData[color]["_sizes"].length; i++)
		{
			row = document.createElement("TR");
			
			cell = document.createElement("TD");


			var div = document.createElement("DIV");
			div.className = "pgTableSize";

			if ((i+1) == this._rawData[color]["_sizes"].length)
			{
				div.className += " bottomRow";
			}

			div.innerHTML = this._rawData[color]["_sizes"][i];
			
			cell.appendChild(div);
					
			row.appendChild(cell);

			var size = this._rawData[color]["_sizes"][i];
			
			for (var j=0; j<this._rawData[color]["_productSkus"].length; j++)
			{
				var product = this._rawData[color]["_productSkus"][j];

				stock = this.getStock(color, product, size);
				backorder = this.getBackorder(color, product, size);
				cell = document.createElement("TD");
				var cellid = "link-" + strfilter(color + "_" + product + "_" + size);
				cell.id = cellid;
				
				if ((i+1) == this._rawData[color]["_sizes"].length)
				{
					cell.appendChild(pg.generateCell(color, product, size, 1, stock, cellid, backorder));
		
				} else {
					cell.appendChild(pg.generateCell(color, product, size, 0, stock, cellid, backorder));
				}

				row.appendChild(cell);
			}
			
			tbody.appendChild(row);
		}


		var target = document.getElementById("steptwotable");
	
	
		//target.innerHTML="<table cellpadding=0 cellspacing=0 border=0>" + table.innerHTML + "</table>";
		
		while(target.firstChild) target.removeChild(target.firstChild);


		target.appendChild(table);
	

	
		this.toggleStep(2, 1);

		
	}
	
	productGrid.prototype.populateOrder = function ()
	{

		var table;
		table = document.createElement("TABLE");
		table.setAttribute("cellSpacing", "0");
		table.setAttribute("cellPadding", "0");
		table.setAttribute("border", "0");
		
		
		var tbody;
		tbody = document.createElement("TBODY");
		table.appendChild(tbody);

		
		var row;
//		row = document.createElement("TR");
		
		var cell;
//		cell = document.createElement("TD");
		
		
		for (var i=0; i<this._rawOrderData.length; i++)
		{

			row = document.createElement("TR");
			if (i % 2 == 1)
			{
				row.className = "pgOrderRowHighlight";
			}
			
			cell = document.createElement("TD");

			var id = this._rawOrderData[i]["id"];
			var qty = this._rawOrderData[i]["qty"];
			var cartid = this._rawOrderData[i]["cartid"];
			var display = this._rawOrderData[i]["display"];
			var size = this._rawOrderData[i]["size"];
			var color = this._rawOrderData[i]["color"];
			var product = this._rawOrderData[i]["product"];
			var price = this._rawOrderData[i]["price"];
			var priceTotal = this._rawOrderData[i]["priceTotal"];
			var backorder = this._rawOrderData[i]["backorder"];
			var stock = this._rawOrderData[i]["stock"];
			var stocklevel = this._rawOrderData[i]["stocklevel"];
			
			var allocated = this._rawOrderData[i]["allocated"];
			var backordered = this._rawOrderData[i]["backordered"];
			var availability = this._rawOrderData[i]["availability"];
			var orderable = this._rawOrderData[i]["orderable"];
			
			
			
			var name = cartid;
			
			cell = document.createElement("TD");
			cell.setAttribute("valign", "top");
			//cell.appendChild(document.createTextNode(qty));	
			cell.innerHTML = "<input maxlength='4' class='gridQuantity' type='text' size='3' style='width: 30px' value='" + qty + "' name='" + cartid + "' onFocus='setShadow(4);'/>";
			cell.className = "pgOrderQuantityCell";
			row.appendChild(cell);
			
			cell = document.createElement("TD");
			cell.setAttribute("valign", "top");
			cell.appendChild(document.createTextNode(display + ": " + size + ", " + color + ", " + product));	
			cell.appendChild(document.createElement("BR"));
			cell.appendChild(document.createTextNode("Price: " + price));	
			cell.className = "pgOrderNameCell";
			row.appendChild(cell);
			
			cell = document.createElement("TD");
			cell.setAttribute("valign", "top");
			
			if (parseInt(stocklevel) == 0)
			{
				availMonth = availability.substring(5, 7);
				availYear = availability.substring(0, 4);
				availDay = availability.substring(8, 10);
				
				strDate = availMonth + "/" + availDay + "/" + availYear;
				
				str = "";
				
				// LLB-1750: If this line is executed, red qty level appears if user adds amount qty = stocklevel
				// Should be handled as below
				
				//str = "" + allocated + " in stock";
				
				if (backordered > 0)
				{
					str += "" + allocated + " in stock and " + backordered + " available on " + strDate;
				}
				
				if (orderable < qty) {
					if (orderable <= 0)
					{
						str += ", please remove this item.";
						
					} else {						
						if (backordered > 0)
						{
							str = "";
						}
						
						str += "" + allocated + " in stock and " + backordered + " available on " + strDate + ", please update your quantity to " + orderable + ".";
					}
				}
				
				/*if (backorder !=  "")
				{
					str += "<br>" + backorder;
				}*/
			} else {
				str = "";
			}
			cell.appendChild(document.createTextNode(str));	
			cell.className = "pgOrderBackorderCell";
			row.appendChild(cell);
			
			cell = document.createElement("TD");
			cell.setAttribute("valign", "top");
			cell.innerHTML = "<b>" + priceTotal + "</b><br><a href=\"javascript:void(0);\" onclick=\"pg.removeCart('" + cartid + "');\" class='remove'>Remove</a>";
			cell.className = "pgOrderTotalCell";
			row.appendChild(cell);
			

			tbody.appendChild(row);
		}


		var target = document.getElementById("stepfourtable");
		
		while(target.firstChild) target.removeChild(target.firstChild);

		target.appendChild(table);
		
		if (hasPlacement == "yes") 
 			this.toggleStep(3, 1);		
		
		this.toggleStep(4, 1);

		
	}
	
	
	productGrid.prototype.showLogos = function (evt, curPlacement, curFabric)
	{
	
		if (hasPlacement == "yes" && curPlacement.selectedIndex != 0)
		{


			if (!evt) var evt = window.event;

			var obj = this;
			var startX = evt.clientX + Geometry.getHorizontalScroll();
			var startY = evt.clientY + Geometry.getVerticalScroll();


			if (!styleWindow)
			{
				myDiv = document.createElement("div");
				myDiv.id = "popupWindow";
				myDiv.className = "logoPopup"; 
				myDiv.style.top = startY + windowY + "px";
				myDiv.style.left = startX + windowX + "px";

				document.body.appendChild(myDiv);

				if (gStatus == 1)
				{
				strInner = '<div class="popupHeader"><span class="popupTitle">Saved Logos:</span> Click a logo below to select it.</div>';
				strInner += '<div class="popupClose"><div class="closeImage"><img src="/llbean/templates/_current/images/arrow-green-tan.gif" width="7" height="12" alt="" border="0"/></div><div class="closeText"><a href="javascript:void(0);" onClick="killPopup();">close</a></div></div><br clear="all"/>';
				strInner += '<div class="popupInstructions" id="popupInstructions"><div class="popupInstructionsImage"><img src="/llbean/templates/_current/images/arrow-red-tan.gif" width="5" height="8" alt="" border="0"/></div><div class="popupInstructionsDetail">Saved logos that match your fabric and placement selection | <a href="javascript:void(0);" onClick="setTimeout(\'pg.setPopupFrame(0);\', 50);">Other saved logos</a></div></div><br clear="all"/>';
				} else {
                strInner = "<div class='popupHeader'><span class='popupTitle'>Saved Logos:</span> You are not currently logged in.</div>";
                strInner += '<div class="popupClose"><div class="closeImage"><img src="/llbean/templates/_current/images/arrow-green-tan.gif" width="7" height="12" alt="" border="0"/></div><div class="closeText"><a href="javascript:void(0);" onClick="killPopup();">close</a></div></div><br clear="all"/>';
				strInner+="<div class='popupInstructions_new' id='popupInstructions_new'><a href='javascript:void(0);' onclick='pg.redirectPG();'>Log in to see your saved logos</a>.</div>"
				}

				strInner += '<div class="popupFrame" id="popupFrame">';
				
				var inserted = 0;
		
				for (i = 0; i< this._rawLogoData.length; i++)
				{
					id = this._rawLogoData[i].id;	
					filename = this._rawLogoData[i].filename;
					filter = this._rawLogoData[i].filter;
					colorway = this._rawLogoData[i].colorway;	
					lastused = this._rawLogoData[i].lastused;	
					llbembid = this._rawLogoData[i].llbembid;	
					url = this._rawLogoData[i].url;	
					
					logoInner = "";


					if (filename.length > 11) {
						filename = filename.substr(0, 11) + "...";
					} else {
						filename = filename;
					}
					
					
					
					
					if (llbembid != "" && filter == "1")
					{
						logoInner += "<div class=\"logoPreview\">";
						logoInner += "<br/><div class=\"image\"><a href=\"javascript:void(0);\" onClick=\"parent.setEmb('" + id + "', '" + url + "', '" + filename + "', '" + '0' + "', '" + '0' + "');\"><img align=\"center\" height=\"60\" border=\"0\" src=\"" + url + "\"/></a></div>";
						logoInner += "<div class=\"information\">";
						logoInner += "<div class=\"item\"><div class=\"label\">File name: </div><div class=\"labelvalue\">" + filename + "</div></div>";
						logoInner += "<div class=\"item activeLogo\"><div class=\"label\">Colorway: </div><div class=\"labelvalue\">" + colorway + "</div><br clear=\"all\"/></div>";
						logoInner += "<div class=\"item\"><div class=\"label\">Last Used On: </div><div class=\"labelvalue\">" + lastused + "</div></div></div>";
						logoInner += "</div>";

						//alert(logoInner);


						inserted = 1;
					}
					strInner += logoInner;

					

				}

				
				if (inserted == 0)
				{
					if (gStatus == 1)
					{
						strInner += "<div class='popupMessage'>You do not have any saved logos available for this product selection.  Click <a href=\"javascript:void(0);\" onclick=\"setTimeout('pg.setPopupFrame(0);', 50);\">Other saved logos</a> to view alternate selections.</div>";
						//alert(strInner);
					} else {
						strInner += "<div class='popupMessage'>You do not have any saved logos available at this time.  <a href='javascript:void(0);' onclick='pg.redirectPG();'>Click here to log in</a> and access saved logos.";
					}
				}
				
				strInner += '&nbsp;<br clear="all">&nbsp;<br>&nbsp;</div>';

				myDiv.innerHTML = strInner;

				styleWindow = myDiv;
				
				setTimeout("pg.setPopupFrame('1')", 50);
			} else {
				styleWindow.style.top =  startY + windowY + "px";
				styleWindow.style.left = startX + windowY + "px";
				new Effect.Appear(styleWindow, {duration: 0.5 });
				setTimeout("pg.setPopupFrame('1')", 50);
			}

		} else if (hasPlacement != "yes") {
			alert("Embroidery not available on this item.");
		} else {
			alert("Please select a placement in Step A before selecting a logo.");
		}


	}
	
	productGrid.prototype.showFile = function (curPlacement, curRadio)
	{
	
		if (hasPlacement == "yes" && curPlacement.selectedIndex != 0)
		{
			curRadio[1].checked = true;
			objImg = document.getElementById("logoHolder");
			objImg.innerHTML = "";
			this.setCurEmbroidery("");
			
		} else if (hasPlacement != "yes") {
			curRadio[1].checked = true;
			alert("Embroidery not available on this item.");
		} else {
			curRadio[1].checked = true;
			alert("Please select a placement in Step A.");
		}


	}
	
	// This method calls a jsp that sets SessionBean.values.loginSuccessURL explicitly before redirect, build 70, LLB-285
	productGrid.prototype.setSessionBeanSuccessURL = function(page)
	{
		var pageUrl;
		var categoryId = this.getProductId();
		
		if (page == "horizontal")
		{
			pageUrl = "/llbean/browse/pg_horizontal.jsp?categoryId=" + categoryId;
		}
		else
		{
			pageUrl = "/llbean/browse/pg.jsp?categoryId=" + categoryId;
		}
				
		var myAjax = new Ajax.Request(
			"/llbean/xml/setSessionBeanSuccessURL.jsp?url=" + pageUrl,
			{
				method: 'get',
				onComplete: doNothing			
			}		
		);
	}
	
	function doNothing(reqNew)
	{
		// The AJAX call is setting a bean value on the server, no further action is necessary
		return;
	}
	
	productGrid.prototype.redirectPG = function ()
	{
		Set_CookieMinutes( "LLB-product", this.getProductId(), 15, "", "", "") ;
		Set_CookieMinutes( "LLB-color", this.getColor(), 15, "", "", "") ;
		Set_CookieMinutes( "LLB-colorid", this.getColorId(), 15, "", "", "") ;		

		startPosition = redirectUrl.indexOf('"');
		endPosition = redirectUrl.indexOf('"', startPosition + 1);
		redirectUrl = redirectUrl.substring(startPosition + 1, endPosition);
		redirectUrl = "location.href = '" + redirectUrl + "';";

		// Changes for build 70:
		
		if (this.getHorizontal())
		{
			pg.setSessionBeanSuccessURL("horizontal");
		}
		else
		{
			pg.setSessionBeanSuccessURL();
		}
		
		var strRedirect = "location.href = '/llbean/global/util/login_redirect.jsp';";
		
		setTimeout(strRedirect, 100);
		
		//strHorizontal = redirectUrl;
		//strVertical = redirectUrl;

		/* The following is the code used prior to build 70 with the exception of the section marked by '!!!!!!!!!!!!', this was not in use
		
//		var strHorizontal = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&_DAV=/llbean/browse/pg_horizontal.jsp?categoryId=" + this.getProductId() + "&productId=null';";
//		var strVertical = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&_DAV=/llbean/browse/pg.jsp?categoryId=" + this.getProductId() + "&productId=null';";
		var strHorizontal = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A&_DAV=/llbean/browse/pg_horizontal.jsp?categoryId=" + this.getProductId() + "&productId=null';";
		var strVertical = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A&_DAV=/llbean/browse/pg.jsp?categoryId=" + this.getProductId() + "&productId=null';";

		/*
		!!!!!!!!!!!!!!!!!!!!!
		var FFVertical = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&_DAV=/llbean/browse/pg.jsp?categoryId=" + this.getProductId() + "&productId=null';";
		var FFHorizontal = "location.href = '/llbean/global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&_DAV=/llbean/browse/pg_horizontal.jsp?categoryId=" + this.getProductId() + "&productId=null';";
		
		var browser = navigator.userAgent;
		if (browser.indexOf("Firefox") != -1)
		{
			strHorizontal = FFHorizontal;
			strVertical = FFVertical;
		}
		!!!!!!!!!!!!!!!!!!!!!
		
		
		if (this.getHorizontal())
		{			
			//setTimeout("location.href = '../global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&amp;_DAV=/llbean/browse/pg_horizontal.jsp%3FcategoryId%3D" + this.getProductId() + "%26productId%3Dnull';", 100);
			setTimeout(strHorizontal, 100);
		} else {
			
			//setTimeout("location.href = '../global/util/login_redirect.jsp?_DARGS=/llbean/modules/_current/navigation/toolbox.jsp_A:_D:/atg/b2cblueprint/profile/SessionBean.values.loginSuccessURL&amp;_DAV=/llbean/browse/pg.jsp%3FcategoryId%3D" + this.getProductId() + "%26productId%3Dnull';", 100);
			setTimeout(strVertical, 100);
		}
		*/
		
	}
	
	productGrid.prototype.checkSession = function (sessionKey)
	{
		strTimeout = "/llbean/session_expired.jsp";
		strTimeout = "location.href='" + strTimeout + "';";
		
		if (this._currentSessionKey == "")
		{
			// new session key assigned to page
			this._currentSessionKey = sessionKey;
		
		} else {
			// we already had a session key
			if (this._currentSessionKey != sessionKey)
			{
				// the session key does not line up, we take action
				setTimeout(strTimeout, 100);
			} else {
				// session key is ok, continue uninterrupted
				
			}
		}
		
		
	}
	
	productGrid.prototype.resetCookie = function ()
	{
		Set_CookieMinutes( "LLB-product", "", 1, "", "", "") ;
		Set_CookieMinutes( "LLB-color", "", 1, "", "", "") ;
	}
	
	
	productGrid.prototype.setPopupFrame = function (status)
	{
		//alert("Going: " + status);
		if (styleWindow)
		{
			myTarget = document.getElementById("popupFrame");
			while (myTarget.firstChild) myTarget.removeChild(myTarget.firstChild);
			myTarget.innerHTML = "";

			strInner = "";
				
			myTarget2 = document.getElementById("popupInstructions");
			while (myTarget2.firstChild) myTarget2.removeChild(myTarget2.firstChild);
			myTarget2.innerHTML = "";



				var inserted = 0;
				
				
				// Status Check
				if (gStatus != 0)
				{
				
				
				for (i = 0; i< this._rawLogoData.length; i++)
				{
					
					id = this._rawLogoData[i].id;	
					filename = this._rawLogoData[i].filename;	
					colorway = this._rawLogoData[i].colorway;	
					lastused = this._rawLogoData[i].lastused;	
					llbembid = this._rawLogoData[i].llbembid;	
					filter = this._rawLogoData[i].filter;
					url = this._rawLogoData[i].url;	
					
					logoInner = "";

					if (filename.length > 11) {
						filename = filename.substr(0, 11) + "...";
					} else {
						filename = filename;
					}


					if (llbembid != "" && status == filter)
					{

					logoInner += "<div class=\"logoPreview\">";
					logoInner += "<br/><div class=\"image\"><a href=\"javascript:void(0);\" onClick=\"parent.setEmb('" + id + "', '" + url + "', '" + filename + "', '" + '0' + "', '" + '0' + "');\"><img align=\"center\" height=\"60\" border=\"0\" src=\"" + url + "\"/></a></div>";
					logoInner += "<div class=\"information\">";
					logoInner += "<div class=\"item\"><div class=\"label\">File name: </div><div class=\"labelvalue\">" + filename + "</div></div>";
					logoInner += "<div class=\"item activeLogo\"><div class=\"label\">Colorway: </div><div class=\"labelvalue\">" + colorway + "</div><br clear=\"all\"/></div>";
					logoInner += "<div class=\"item\"><div class=\"label\">Last Used On: </div><div class=\"labelvalue\">" + lastused + "</div></div></div>";
					logoInner += "</div>";

						//alert(logoInner);


					inserted = 1;
					}
					strInner += logoInner;


				}
				} else {
					inserted = 0;
				}

					if (status == 1)
					{
						myTarget2.innerHTML = '<div class="popupInstructionsImage"><img src="/llbean/templates/_current/images/arrow-red-tan-large.gif" alt=""  border="0"/></div><div class="popupInstructionsDetail">Saved logos that match your fabric and placement selection | <a href="javascript:void(0);" onClick="setTimeout(\'pg.setPopupFrame(0)\', 50);">Other saved logos</a></div>';

					} else {
					
						myTarget2.innerHTML = '<div class="popupInstructionsDetail"><a href="javascript:void(0);" onClick="setTimeout(\'pg.setPopupFrame(1);\', 50);">Saved logos that match your fabric and placement selection</a> |&nbsp;</div><div class="popupInstructionsImage"><img src="/llbean/templates/_current/images/arrow-red-tan-large.gif" alt=""  border="0"/></div><div class="popupInstructionsDetail">Other saved logos</div>';

					}
					
				if (inserted == 0)
				{
					if (gStatus == 1)
					{
						if (status == 1)
						{
							strInner += "<div class='popupMessage'>You do not have any saved logos available for this product selection.  Click <a href=\"javascript:void(0);\" onclick=\"setTimeout('pg.setPopupFrame(0);', 50);\">Other saved logos</a> to view alternate selections.</div>";					
						} else {
							strInner += "<div class='popupMessage'>You do not have any saved logos available at this time.</div>";
						}
					} else {
						// anonymous user, cannot access saved logos
						strInner += "<div class='popupMessage'>You do not have any saved logos available at this time.  <a href='javascript:void(0);' onclick='pg.redirectPG();'>Click here to log in</a> and access saved logos.";
					}
				}
				
				strInner += '&nbsp;<br clear="all">&nbsp;<br>&nbsp;';
			
			myTarget.innerHTML = strInner;
			
			
		}
	}
	

	
	function handleBlindUp(strObj, strStyle)
	{
		document.getElementById(strObj).className = strStyle;
	}
	
	function handleBlindUp1()
	{
		handleBlindUp("step1", "productGridStep");
	}
	
	function handleBlindUp2()
	{
		handleBlindUp("step2", "productGridStep");
		switcher = document.getElementById('step2box');
		switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(2, 1);\"><img src=\"/llbean/templates/_current/images/buttons/btn_plus.gif\" alt=\"\" border=\"0\"/></a>";
		
		if (pg.hasOrder())
		{
			setShadow(4);
		} else {
			setShadow(1);
		}
	}
	
	function handleBlindUp3()
	{
		handleBlindUp("step3", "productGridStep");
		switcher = document.getElementById('step3box');
		switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(3, 1);\"><img src=\"/llbean/templates/_current/images/buttons/btn_plus.gif\" alt=\"\" border=\"0\"/></a>";
		
		
		if (pg.hasOrder())
		{
			setShadow(4);
		} else if (pg.hasColor())
		{
			setShadow(2);
		} else {
			setShadow(1);
		}
	}
	
	function handleBlindUp4()
	{
		handleBlindUp("step4", "productGridStepLast");
		switcher = document.getElementById('step4box');
		switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(4, 1);\"><img src=\"/llbean/templates/_current/images/buttons/btn_plus.gif\" alt=\"\" border=\"0\"/></a>";
		
		if (pg.hasColor())
		{
			setShadow(1);
		} else {
			setShadow(1);
		}
	
	}
	
	function clearShadows(step)
	{
		for (i=1; i<=4; i++)
		{
			if (step != i)
			{
				//alert("Removing: " + i);
				removeShadow(i);

			}
		}
	}
	
	function addShadow1()
	{
		//clearShadows(1);
		addShadow(1);
	}
	
	function addShadow2()
	{
		//clearShadows(2);
		addShadow(2);
	}
	
	function addShadow3()
	{
		//clearShadows(3);
		addShadow(3);
	}
	
	function addShadow4()
	{
		//clearShadows(4);
		addShadow(4);
	}
	
	function removeShadow(step)
	{
		var obj;
		var append;
		if (pg.getHorizontal() && step == 1)
		{
			append = "-horizontal";	
		} else {
			append = "";
		}
		obj = document.getElementById("step" + step + "shadow");
		obj.className = "offshadow" + step + append;
		
		if (step == 4)
		{
			removeCorner(step);
		}
	}
	
	function addShadow(step)
	{
		var obj;
		var append;
		if (pg.getHorizontal() && step == 1)
		{
			append = "-horizontal";	
		} else {
			append = "";
		}
		obj = document.getElementById("step" + step + "shadow");
		obj.className = "shadow" + step + append;
		if (step == 4)
		{
			addCorner(step);
		}
	}
	
	function removeCorner(step)
	{
		var obj;
		obj = document.getElementById("step" + step + "corner");
		
		obj.className = "step" + step + "cornerOff";
	}
	
	function addCorner(step)
	{
		var obj;
		obj = document.getElementById("step" + step + "corner");
		obj.className = "step" + step + "cornerOn";
	}
	
	function setShadow(step)
	{
		clearShadows(step);
		if (pg.stepStatus(step) == 1)
		{
			addShadow(step);
		} else {
			pg.toggleStep(step, 1);
		}
	}	
	
	productGrid.prototype.validateAddtobag = function ()
	{
		
		if (!this.hasCart())
		{
			notifyEmptyGrid();
			return false;
		}
		
		if (!this.cartContentsValid())
		{
			notifyCartContents();
			return false;
		}
		
		var logoFileValue = document.uploadForm.logoFile.value;
		//alert(logoFileValue);
		//alert(document.getElementById("logoHolder").innerHTML);
		//alert(document.getElementById("logoHolder").innerHTML=="");
		//alert(this._curEmbroidery);
		
		if (this._curEmbroidery=="" && logoFileValue=="")
		{
			return true;
		}
		else
		{
			//alert("not empty");
			var answer = confirm("Click OK if you would like to continue without a logo. Click Cancel to return to Step 3 and click Confirm Logo to add your logo.");
			if (answer)
			{
				return true;
			}
			else
			{
				return false;
			}
			return false;
		}
		
		return true;
	}
	
	productGrid.prototype.stepStatus = function(n)
	{
		switch(n)
		{
			case 1:
				return this._step1;
				break;
			case 2:
				return this._step2;
				break;
			case 3:
				return this._step3;
				break;
			case 4:
				return this._step4;
				break;
		}
	}
	
	productGrid.prototype.toggleStep = function (step, action)
	{
		switch(step)
		{
			case 1:
				// nothing happens to step 1
				break;
			case 2: 
				if (this._step2 && (action == null || action == 0))
				{
					removeShadow(2);
					obj = document.getElementById('step2container');
					new Effect.BlindUp(obj, {afterFinish: handleBlindUp2});
					this._step2 = 0;
				} else if (this._step2 == 0 && this.hasColor()) {
					clearShadows(2);
					par = document.getElementById('step2');
					par.className = "productGridStepOpen";
					obj = document.getElementById('step2container');
					switcher = document.getElementById('step2box');
					switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(2, 0);\"><img src=\"/llbean/templates/_current/images/buttons/btn_minus.gif\" alt=\"\" border=\"0\"/></a>";
					new Effect.BlindDown(obj, {afterFinish: addShadow2});
					this._step2 = 1;
				} else if (this._step2 == 0)
				{
					alert("Please complete Step 1 to enter your quantities in Step 2.");
				}
				break;
			case 3: 
				if (this._step3 && (action == null || action == 0))
				{
					removeShadow(3);
					obj = document.getElementById('step3container');
					new Effect.BlindUp(obj, {afterFinish: handleBlindUp3});
					this._step3 = 0;
				} else if (  (this._step3 == 0 && this.hasCart() && hasPlacement == "yes") || this.getPersonalizationNum() > 0 ) {
					//this.loadLogoData();
					clearShadows(3);
					par = document.getElementById('step3');
					par.className = "productGridStepOpen";
					obj = document.getElementById('step3container');
					switcher = document.getElementById('step3box');
					switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(3, 0);\"><img src=\"/llbean/templates/_current/images/buttons/btn_minus.gif\" alt=\"\" border=\"0\"/></a>";
					new Effect.BlindDown(obj, {afterFinish: addShadow3});
					this._step3 = 1;
				} else if ( !this._step3 && hasPlacement == "yes") {
					alert("Please click the Update/Add link next to your quantities in step 2 to continue to step 3.");
				} else if ( !(hasPlacement == "yes") ) {
					alert("This product cannot be personalized.");
				}
				break;
			case 4: 
				if (this._step4 && (action == null || action == 0))
				{
					removeShadow(4);
					obj = document.getElementById('step4container');
					new Effect.BlindUp(obj, {afterFinish: handleBlindUp4});
					this._step4 = 0;
				} else if (this._step4 == 0 && this.hasColor()) {
					clearShadows(4);
					par = document.getElementById('step4');
					par.className = "productGridStepLastOpen";
					obj = document.getElementById('step4container');
					switcher = document.getElementById('step4box');
					switcher.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"pg.toggleStep(4, 0);\"><img src=\"/llbean/templates/_current/images/buttons/btn_minus.gif\" alt=\"\" border=\"0\"/></a>";
					new Effect.BlindDown(obj, {afterFinish: addShadow4});
					this._step4 = 1;
				} else if (this._step4 == 0)
				{
					alert("Please complete Step 2 to view your selections in Step 4.");
				}
				break;
				
		
		}
	}
	








