// ajaxAdd.js
var xColorArray = new Array();
var xSkuArray = new Array;
var xProdImage = new Array;
function colorObj(seq,name,oprice,lprice,copy,image,skus,price){  
	this.seq = seq;  
	this.name = name; 
	this.oprice = oprice; 
	this.lprice = lprice; 
	this.copy = copy;
	this.image = image;
	this.skus = skus;
	this.price = price; 
}
function skuObj(sku,catentry,size,seq,backdate,backordered){
	this.sku = sku;  
	this.catentry = catentry; 
	this.size = size; 
	this.seq = seq;
	this.backdate = backdate;
	this.backordered = backordered;
}
function customSort(a,b){
   return(a.seq-b.seq);
}
function closeAddItem(){
	hideFadeCtn();
	if($old('EGCProdRight')){
		$old('EGCProdRight').parentNode.removeChild($old('EGCProdRight'));
		$old('EGCProdLeft').parentNode.removeChild($old('EGCProdLeft'));
	}
	var ua = navigator.userAgent.toLowerCase();
	if ((ua.indexOf("msie") != -1) && (parseFloat(navigator.appVersion.split("MSIE")[1]) < 7) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)){
		$("#size").attr('visibility','visible');
		$("#sizelist").attr('visibility','visible');
	}
}
var xml = null;
var currOrderItemId = null;
function editItem(product, cseq, page, orderItemId, category, slot, mainCategory){

	var ftype = product == 364927 ? 'egc' : null;
	currOrderItemId = orderItemId;
			
	var getstr = '/webapp/wcs/stores/servlet/EditItemDisplay?';
	getstr += "storeId=" + CONSTANTS.STOREID + "&";
	getstr += "langId=" + CONSTANTS.LANGID + "&";
	getstr += "catalogId=" + CONSTANTS.CATALOGID + "&";
	getstr += "productId=" + product;
	
	if(category != undefined){
		getstr += "&categoryId="+category;
	}	

	$.get(getstr, {
	
	}, function(data){
		//contactForm.init(contactUsType);
       	xml = $(data);
       	showProduct(seq, page, slot,mainCategory, product);
		return false;
	},'xml');			
	return false;
}

var template;
var selectedSize;
var prodCopy;
var xOnesize = false;
var xListObjsize;
var colNumber;
var colName;
var currSlot;
var currCat;
function showProduct(selectedSeq, page, slot, mainCategory, product){
	xOnesize = false;
	var colorFound = false;
	var numItems = xml.find('total')[0];
	if (numItems){
		if (numItems.childNodes[0].nodeValue > 0){
			var html = '';
	    	var htmlL = '';
	    	currSlot = slot;
	    	currCat = mainCategory;
	    	var name = xml.find('name')[0];
	    	var ppname = $old('prodTitle') ? $old('prodTitle').innerHTML : '';
	    	var collection = xml.find('collection')[0];
	    	colNumber = collection.childNodes[0].nodeValue;
	    	colName = name.childNodes[0].nodeValue;
	    	var parentCol = collection.childNodes[0].nodeValue;
	    	prodCopy = (xml.find('prodcopy')[0]).childNodes[0] ? (xml.find('prodcopy')[0]).childNodes[0].nodeValue : "";
	    	template = (xml.find('template')[0]).childNodes[0] ? (xml.find('template')[0]).childNodes[0].nodeValue : "";
	    	var colors = xml.find('color');
	    	var egc = colNumber == 'EGIFTCARD' ? true : false;
	    	if(!egc){
	    		if($old('EGCProdRight')){
	    			$old('EGCProdRight').parentNode.removeChild($old('EGCProdRight'));
	    		}
	    		if($old('EGCProdLeft')){
	    			$old('EGCProdLeft').parentNode.removeChild($old('EGCProdLeft'));
	    		}
	    		$("#editProdLft").css('display','block');
				$("#editProdRgt").css('display','block');
		    	if (template == 'v'){
		    		if(page == 'dept2'){
		    			htmlL += '<span style="width:316px; height:325px;"><img src="/kids/images/clear.gif" id="xProductImage" name="xProductImage" width="316px" alt=""/></span>';
		    			document.getElementById('bord').style.height = '350px';
		    		}else{
			    		htmlL += '<img src="/kids/onlinestore/collection/'+parentCol+'_01_b.jpg" id="xProductImage" name="xProductImage" style="padding-bottom:10px" alt=""/>';
			    	}
		    	} else{
		    		if(page == 'dept2'){
		    			htmlL += '<span style="width:316px; height:325px;"><img src="/kids/images/clear.gif" width="316px" alt=""/></span>';
		    			$('#bord').css('height','350px');
		    		}else{
		    			htmlL += '<img src="/kids/onlinestore/collection/'+parentCol+'_'+selectedSeq+'_b.jpg" id="xProductImage" name="xProductImage" style="padding-bottom:10px" alt=""/>';
		    		}
		    	} 
		    	if((page != 'cart') && (page != 'cartPromo') && (page != 'dept2')){ 
		    		//CM product view
		    		//cmCreateProductviewTag(collection.childNodes[0].nodeValue, 'CTL: SLOT '+slot+': '+mainCategory+': ' + ppname + ': ' + name.childNodes[0].nodeValue, eval(mainCategory.toString()+slot));
		    	}
		    	html += '<h1 class="prodName">'+name.childNodes[0].nodeValue+'</h1>';
		    	html += '<p id="xProdColor"></p>';
		    	html += '<p id="xProdPrice"><span id="xProdOff">&nbsp;</span></p>';
		    	html += '<p id="xProdText">';
				html += '<span id="xProdCopy" class="normCase"></span></p>';
				html += '<div id="xProdSwatch">';
				if(template == 'v'){
					var initOption = 'Select One';
					if(product == 75801) initOption = CONSTANTS.GC_DISPLAY_AMOUNTSELECT;					
					html += '<select name="xSizelist" class="product" onchange="setXColor(this.value, true)">';
					html += '<option value="">' + initOption + '</option>';
					for(var u = 0; u != colors.length; u++){
						var currSeq = (xml.find('cseq')[u]).childNodes[0].nodeValue;
						var currColor = (xml.find('colorname')[u]).childNodes[0].nodeValue;
						
						if (selectedSeq == currSeq){
							html += '<option value="'+currSeq+'" selected>'+currColor+'</option>';
						} else {
							html += '<option value="'+currSeq+'">'+currColor+'</option>';
						}
						if (selectedSeq == currSeq){
							colorFound = true;
						}
					}
					html += '</select>';
				}else if((template != 1) && (colors.length > 1)){
					for(var u = 0; u != colors.length; u++){
						var currSeq = (xml.find('cseq')[u]).childNodes[0].nodeValue;
						var currColor = (xml.find('colorname')[u]).childNodes[0].nodeValue;
						
						html += '<a href="#nogo" onclick="javascript:setXColor(\'' + currSeq + '\', true);"><img class="colorSwatch" src="/kids/onlinestore/collection/' +parentCol + '_' + currSeq + '.gif" height="20" width="20" alt=""/></a>'
						if (((u + 1) == 6) || ((u + 1) == 12) || ((u + 1) == 18) || ((u + 1) == 24) || ((u + 1) == 30)){
							html += '<br/>'
						} 
						if (selectedSeq == currSeq){
							colorFound = true;
						}
					}
					html += '<br/><br/>';
				} 	
				html += '<span id="xSizeBox"></span>';	
				html +='</div>';
				html += '<br/><br/>'
				if(page == 'cart'){
					html += '<a id="UpdateCheckoutCartButton" href="#" onclick="submitAdd(\'cart\');" class="prodPageButton"><span>UPDATE</span></a>';
					html += '<a id="CancelButton" href="#" onclick="closeAddItem();" class="prodPageButton"><span>CANCEL</span></a>';
				} else if(page == 'cartPromo'){
					html += '<a id="AddToBagButton" href="#" onclick="submitAdd(\'cartPromo\')" class="prodPageButton"><span>Add to Bag</span></a>';
					html += '<a id="CancelButton" href="#" onclick="closeAddItem()" class="prodPageButton"><span>CANCEL</span></a>';
				} else if(page == 'dept2'){
				
					html += '<a href="javascript:submitAdd(\'dept2\');"><img src="/kids/onlinestore/common/frag_add_bag.jpg"/></a>  <a href="javascript:closeAddItem();"><img src="/kids/onlinestore/common/frag_cancel.jpg"/></a>';
					
					document.getElementById('bord').style.backgroundImage='url("/kids/onlinestore/common/'+parentCol+'_01_b.jpg")';
				}else {
					html += '<a id="AddToBagButton" href="#" onclick="submitAdd()" class="prodPageButton"><span>Add to Bag</span></a>';	
					html += '<a id="CancelButton" href="#" onclick="closeAddItem();" class="prodPageButton"><span>CANCEL</span></a>';								
				}
				xListObjsize = document.editForm.size;
				xColorArray.length = 0;
				xProdImage.length = 0;
				for (var i=0;i<colors.length;i++){
					var colorSeq = (xml.find('cseq')[i]).childNodes[0].nodeValue;
					var name = (xml.find('colorname')[i]).childNodes[0].nodeValue;
					var fmtPrice = (xml.find('offer')[i]).childNodes[0].nodeValue;
					var listPrice = (xml.find('list')[i]).childNodes[0].nodeValue;
					var unfmtPrice = (xml.find('price')[i]).childNodes[0].nodeValue;
					var copy = '';
					if ((xml.find('colorcopy')[i]).childNodes[0] != null){
					 copy = (xml.find('colorcopy')[i]).childNodes[0].nodeValue;
					}
					var items = colors[i].getElementsByTagName("item");
		    		xSkuArray[i] = new Array();
		    		xProdImage[i] = new Image();
		    		xProdImage[i].src = '/kids/onlinestore/collection/'+parentCol+'_'+colorSeq+'_b.jpg';
		    		for (var x=0;x<items.length;x++){
		    			var sku = (items[x].getElementsByTagName("sku")[0]).childNodes[0].nodeValue;
		    			var cat = (items[x].getElementsByTagName("catentry")[0]).childNodes[0].nodeValue;
						var size = (items[x].getElementsByTagName("size")[0]).childNodes[0].nodeValue;
		    			var sizeSeq = (items[x].getElementsByTagName("seq")[0]).childNodes[0].nodeValue;
		    			var back = (items[x].getElementsByTagName("backordered")[0]).childNodes[0].nodeValue;
		    			var backdate = (items[x].getElementsByTagName("backdate")[0]).childNodes[0].nodeValue;
		    			
		    			xSkuArray[i][x] = new skuObj(sku, cat, size, sizeSeq, backdate, back);
					}
					xSkuArray[i].sort(customSort);
		    		xColorArray[i] = new colorObj(colorSeq, name, fmtPrice, listPrice, copy, xProdImage[i], xSkuArray[i], unfmtPrice);
		    	}
		    	
	  		  	$("#editProdLft").html(htmlL);		
				$("#editProdRgt").html(html);				
				
				
				$("#fadeUpContent").removeClass();
				$("#fadeUpContent").addClass("fadeUp");
				var ctntDiv = "#editItemCtn";
				$(".fadeUp").hide();
				$("#fadeContainer").hide();
				$("#fadeContainer").addClass("transparent");
				$("#fadeContainer").css("width", $.clientCoords().width);
				$("#fadeContainer").css("height", $.clientCoords().height);
				$("#fadeContainer").show();
				$(ctntDiv).css("left", ($.clientCoords().width - $(ctntDiv).width())/2);
				$(ctntDiv).fadeIn("slow");				
								
				
				var setPrice = true;
				if(product == 75801 && page == 'cartPromo'){setPrice = false;}				
				if (colorFound){
					setXColor(selectedSeq, setPrice, page);
				} else {
					var defaultSeq = (xml.find('init')[0]).childNodes[0].nodeValue;
					setXColor(defaultSeq, setPrice);
				}
			}else{
				/**** EGC Edit ****/
				$('#editProdLft').hide();
				$('#editProdRgt').hide();
				
				var mm = {
					0:{name:"January",value:"01"},
					1:{name:"February",value:"02"},
					2:{name:"March",value:"03"},
					3:{name:"April",value:"04"},
					4:{name:"May",value:"05"},
					5:{name:"June",value:"06"},
					6:{name:"July",value:"07"},
					7:{name:"August",value:"08"},
					8:{name:"September",value:"09"},
					9:{name:"October",value:"10"},
					10:{name:"November",value:"11"},
					11:{name:"December",value:"12"}
				}
				function buildMonths(){
					var go = true, mo = to.getMonth(), yr = to.getFullYear(), count = numDays(mo,yr);
					
					sm.options.length = 0;
					while(go){
						sm.options[sm.options.length] = new Option(mm[mo].name, mm[mo].value);
						sm.options[sm.options.length - 1].year = yr;
						sm.options[sm.options.length - 1].toshow = count > 60 ? 60 - (count - numDays(mo,yr)) : numDays(mo,yr);
						go = count < 60 ? true : false;
						
						if(mo + 1 <= 11){mo++;}
						else{mo = 0;yr++;}
						
						count += numDays(mo,yr);
					}
					buildDays();
				}
				function buildDays(e){
					sd.options.length = 0;
					var m = sm.options[sm.selectedIndex].value, mi, d, s;
					for(x in mm){
						if(mm[x].value == m){
							mi = x;
						}
					}
					s = to.getMonth() == mi ? to.getDate() : 1;
					e = sm.options[sm.selectedIndex].toshow;
					for(var x=0; x < e; x++){
						sd.options[sd.options.length] = new Option(s, s);
						s++;
					}
				}
				function numDays(iMonth, iYear){
					var n = 32 - new Date(iYear, iMonth, 32).getDate();
					if(iMonth != to.getMonth()){
						return n;
					}else{
						return n - to.getDate() + 1;
					}
				}
				function buildSkus(){
					for (var i=0;i<colors.length;i++){
						//get colorname for text
						var txt = colors[i].getElementsByTagName('colorname')[0].childNodes[0].nodeValue.replace(/&pound;/g,'\u00A3').replace(/&nbsp;/g,' ');
						var val = colors[i].getElementsByTagName('items')[0].getElementsByTagName('item')[0].getElementsByTagName('sku')[0].childNodes[0].nodeValue;
						var ce = colors[i].getElementsByTagName('items')[0].getElementsByTagName('item')[0].getElementsByTagName('catentry')[0].childNodes[0].nodeValue;
						var o = pn.options[pn.options.length] = new Option(txt, val);
						o.catentry = ce;
					}
				}
				function checkEGC(){
					f.email.value = f.email.value.toLowerCase();
					f.emailcheck.value = f.emailcheck.value.toLowerCase();
					
					var year = f.sendMonth.options[f.sendMonth.selectedIndex].year;
					var month = f.sendMonth.value;
					var day = f.sendDay.value;
					var buyer = f.buyer.value;
					var receiver = f.receiver.value;
					var email = f.email.value;
					var comments = f.comment.value.replace(/\#/g,'').replace(/[\n,\f,\r]/g,' ').replace(/[",']/g, '');
					var comment2="";
					var errmsg = "";
					if(f.receiver.value == "" || f.receiver.value == null){
						errmsg = CONSTANTS.GC_DISPLAY_RECIPIENT_ERROR;
					}
					if(f.buyer.value == "" || f.buyer.value == null){
						errmsg = CONSTANTS.GC_DISPLAY_SENDERNAME_ERROR;
					}
					if(f.partNumber.value == '0'){
						errmsg = CONSTANTS.GC_DISPLAY_VALIDAMOUNT_ERROR;
					}
					if(f.email.value != f.emailcheck.value){
						errmsg = CONSTANTS.GC_DISPLAY_EMAILMATCH_ERROR;
					}
					if(f.email.value == "" || f.email.value == null){
						errmsg = CONSTANTS.GC_DISPLAY_EMAILVALID_ERROR;
					}
					if(!IsEmailValid(f.email.value)){
						errmsg = CONSTANTS.GC_DISPLAY_EMAILVALID_ERROR;
					}
					if(comments.length > 0){
						comment2 = comment2.concat(comments.slice(0,40),'|',
						comments.slice(40,80),'|', comments.slice(80,120),'|',
						comments.slice(120,160),'|', comments.slice(160,200));
					}		
					var requestedShipDate = year + '-'+month +'-'+ day+' 00:00:00';
					var field2 = (receiver+'||'+buyer+'||'+email).replace(/[",']/g, '').replace(/\&/g, 'and');
					if (errmsg != "") {
						$('#error').html(errmsg);
					}else{
						f.requestedShipDate.value = requestedShipDate;
						f.field2.value = field2;
						f.comment.value = comment2;
						f.catEntryId.value = f.partNumber.options[f.partNumber.selectedIndex].catentry;
						f.URL.value = 'OrderItemDelete?orderItemId=' + currOrderItemId + '&URL=OrderItemDisplay?orderId=.';
						f.submit();
						closeAddItem();
					}
				}
				
				html = '<div style="width:275px;display:inline;" id="EGCProdRight">' +
				'	<h3>e-gift card</h3>' +
				'	<input type="hidden" name="requestedShipDate" value=""/>' +
				'	<input type="hidden" name="field2" value=""/>' +
				'	<input type="hidden" name="quantity" value="1"/>' +
				'	'+CONSTANTS.EGC_DISPLAY_TO+'<br/>' +
				'	<input type="text" name="receiver" size="35"  maxlength="40"/><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_FROM+'<br/>' +
				'	<input type="text" name="buyer" size="35"  maxlength="40"/><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_AMOUNTLABEL+'<br/>' +
				'	<select name="partNumber">' +
				'		<option value="">'+CONSTANTS.GC_DISPLAY_AMOUNTSELECT+'</option>' +
				'	</select><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_DELIVERLABEL+'<br/>' +
				'	<select name="sendMonth" style="width:100px;">' +
				'	</select>' +
				'	<select name="sendDay" style="width:40px">' +
				'	</select><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_EMAILLABEL+'<br/>' +
				'	<input type="text" name="email" size="35" maxlength="50"/><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_EMAILCONFIRMLABEL+'<br/>' +
				'	<input type="text" name="emailcheck" size="35" maxlength="50"/><br/>' +
				'	'+CONSTANTS.EGC_DISPLAY_MSG+'<br/>' +
				'	<textarea name="comment" rows="5" cols="37"></textarea>' +
				'	<br/>' +
				'	required*<br/><br/>' +
				'	<img src="/kids/onlinestore/common/edit_update.gif" id="updateEGC" />   <a href="javascript:closeAddItem();"><img src="/kids/onlinestore/common/edit_cancel.gif"/></a>' +
				'	<br/><br/>' +
				'	<span id="error"></span><br/><br/></div>';
				
				var f = document.forms.editForm; 
				
				$('#editCtn').css('width','670px');
				if(!$old('EGCProdRight')){
					f.innerHTML += '<div style="width:350px;" id="EGCProdLeft"><img src="/kids/onlinestore/common/egc_product.jpg"/></div>';
					f.innerHTML += html;
				}
				
				var sm = f.sendMonth, sd = f.sendDay, to = new Date(), currDay = to.getDate(), pn = f.partNumber;
				
				f.receiver.value = $old(currOrderItemId + '_recipientName').innerHTML;
				f.buyer.value = $old(currOrderItemId + '_from').innerHTML;
				f.comment.value = $old(currOrderItemId + '_comment').innerHTML.replace(/\|/g,'');
				f.email.value = $old(currOrderItemId + '_recipient').innerHTML;
				f.emailcheck.value = $old(currOrderItemId + '_recipient').innerHTML;
				
				addEvent(sm,'change', buildDays);
				addEvent(f.comment,'keyup',function(el){ return function(e){ limitChars(el,200); }; }(f.comment));
				
				addEvent($old('updateEGC'),'click',checkEGC);
				
				buildMonths();
				selectOption(sm,$old(currOrderItemId + '_senddate').innerHTML.substring(0,2));
				buildDays();
				var dayToSend = $old(currOrderItemId + '_senddate').innerHTML.substring(3,5);
				if(dayToSend.indexOf('0') == 0){ dayToSend = dayToSend.substring(1); }
				selectOption(sd,dayToSend);
				buildSkus();
				selectOption(f.partNumber,$old(currOrderItemId + '_egSku').innerHTML);
								
				$("#fadeUpContent").removeClass();
				$("#fadeUpContent").addClass("fadeUp");
				var ctntDiv = "#editItemCtn";
				$(".fadeUp").hide();
				$("#fadeContainer").hide();
				$("#fadeContainer").addClass("transparent");
				$("#fadeContainer").css("width", $.clientCoords().width);
				$("#fadeContainer").css("height", $.clientCoords().height);
				$("#fadeContainer").show();
				$(ctntDiv).css("left", ($.clientCoords().width - $(ctntDiv).width())/2);
				$(ctntDiv).fadeIn("slow");					
				
				//myEffects.fade('editCtn');
			}
		}
	}
}

function setXColor(seq,setPrice,page){
	xOnesize = false;
	for(var y = 0; y != xColorArray.length; y++){
		if(xColorArray[y].seq == seq){
			//Set Image
			if (template != 'v'){			
				$("#xProductImage").attr('src',xColorArray[y].image.src);				
			}
			//Set Color
			color = xColorArray[y].name;
			xColorStyle.value = color;
			if ((color.indexOf("$") != -1) || (color.indexOf("&pound;") != -1) || (color.indexOf("&euro;") != -1) || (color.indexOf("&yen;") != -1)){
				color = "";
			}
			
			//Set Price
			price = xColorArray[y].oprice;
			//Set Copy
			if (xColorArray[y].copy != 'null' && xColorArray[y].copy != ''){
				copy = xColorArray[y].copy;
			} else {
				copy = prodCopy;
			}
			//Set Sizes
			var html = '<select name="size" id="size" class="product"><option value="Select Size">' + CONSTANTS.PRODUCT_SELECTSIZE + '</option>';
			var htmlOne = "";
			today = new Date();
			month = today.getMonth() +1;
			day = today.getDate();
			
			if(month <10){ 
				month = "0"+month;
			}
			if(day<10){
				day = "0"+day;
			}
			
			now = today.getFullYear() +""+ month +""+ day;
			for(var t = 0; t != xColorArray[y].skus.length; t++){
				if (xColorArray[y].skus[t].size == 'ONE SIZE'){
					xOnesize = true;
					var htmlOne = '<input type="hidden" name="size" value="'+xColorArray[y].skus[t].catentry+'" />';
					if(xColorArray[y].skus[t].backordered == 'true'){
						shipDate = xColorArray[y].skus[t].backdate;
			        	if(shipDate <= now){
							htmlOne += '<br/><span class="backorder">'+CONSTANTS.MC_BACKORDERED+'</span><br/>';
						}else{
							shipStr = shipDate.substring(4,6) + "/" + shipDate.substring(6,8) + "/" + shipDate.substring(2,4)
							html += '<br/><span class="backorder">this item will ship ' + shipStr + '</span><br/>';
						}
					}
					
					break;
				} else {
					if (xColorArray[y].skus[t].backordered == 'true'){
						shipDate = xColorArray[y].skus[t].backdate;
										
						if(shipDate <= now){
							html += '<option value="'+xColorArray[y].skus[t].catentry+'">'+xColorArray[y].skus[t].size+' - backordered</option>';
						}else{
							shipStr = shipDate.substring(4,6) + "/" + shipDate.substring(6,8) + "/" + shipDate.substring(2,4);
							html += '<option value="'+xColorArray[y].skus[t].catentry+'">'+xColorArray[y].skus[t].size+' - will ship ' + shipStr + '</option>';
						}
					
					} else {
						html += '<option value="'+xColorArray[y].skus[t].catentry+'">'+xColorArray[y].skus[t].size+'</option>';
					}
				}
			}
			html += '</select>';
			var sizeHtml = '';
			if (htmlOne != ""){
				sizeHtml = htmlOne;
			} else {
				sizeHtml = html;
			}
			
			
			$("#xProdColor").html(color);
			if(setPrice){
				$("#xProdOff").html(price);
			}
			$("#xProdCopy").html(copy);
			$("#xSizeBox").html(sizeHtml);
		}	
	}
}			
var xCurrItemBackordered = false;
function submitAdd(page){
	xCurrItemBackordered = false;
	
	if((!xOnesize) && (document.editForm.size.selectedIndex == 0)) {
		alert('Please select a size.');
		return;
	} else if((template == 'v') && (document.editForm.size.value == '')){
		alert("Please select a style.");
		return;
	} else {
       catentry = xOrderItemUpdateObj.size.value;
       for(var y = 0; y != xColorArray.length; y++){
			if(xColorArray[y].name == xColorStyle.value){
				for(var t = 0; t != xColorArray[y].skus.length; t++){
					if (xColorArray[y].skus[t].catentry == catentry){
						xOrderItemUpdateObj.partnumber.value = xColorArray[y].skus[t].sku;
						var size = xColorArray[y].skus[t].size
						var price = xColorArray[y].price;
						xCurrItemBackordered = xColorArray[y].skus[t].backordered;
						break;
					}
				}
			}
		}
		xOrderItemUpdateObj.catEntryId.value = catentry;
		if(page == 'cart'){
			document.editForm.URL.value = 'OrderItemDelete?orderItemId=' + currOrderItemId + '&URL=OrderItemDisplay?orderId=.';
		} else if(page == 'cartPromo') {
			document.editForm.URL.value = 'OrderItemDisplay?orderId=.';
	   	} else {
			//Unique to product page only
	        document.editForm.URL.value = '/kids/onlinestore/html/blank1.html';
	        addDivToHiddenFrame(); /* write div element  */
	        timeid = setTimeout("updateTimer()",200);/* start the time to check for frame load (dancing around for MAC IE, otherwise use onload event) */
	      	document.editForm.target = 'HIDDENPOST'; 
	      	if(page != 'cart' && page != 'dept2'){ 
	      		//cmCreateAddToBagShop5Tag(colNumber, 'CTL: SLOT '+ currSlot +': ' + colName, 1, price, eval(currCat.toString()+ currSlot), size, xColorStyle.value, xOrderItemUpdateObj.partnumber.value);
	   		}
	    }
        document.editForm.submit(); 
        closeAddItem();
	}
}

function resetEditMode(type){
	var editCtnOffSet = 145;
	if((type == 'egc') || ($old('EGCProdRight') && $old('EGCProdRight').style.display != 'none')){
		editCtnOffSet = 100;
	}
	var nLeft = document.getElementById('wrapper').offsetLeft+"px";
	var nLeft2 = (document.getElementById('headerCtn').offsetLeft + editCtnOffSet)+"px";
	$("#editMode").css("left", nLeft);
	$("#editCtn").css("left", nLeft2);
}