	var storeid=0;
	var verbosestatus="closed";	
	//Browser is declared in javascript_LB.js
	
	function getColorInfo(prodid,colorid,returntype) {     
		if (typeof(returntype)=='undefined') returntype='row';
		var arr=eval("product_"+prodid+"_colorinfo");		
		for (z=0; z<arr.length; z++) {
			if ( arr[z][0].toString().toUpperCase()==colorid.toString().toUpperCase() ) {
				if ( returntype.toString().toLowerCase()=='row' ) {
					return(arr[z][1]);
				} else { 
					return(arr[z][2]);             
				}         
			}     
		}
	}
	
	function getSwatchMatrixURL(imageid) {
		var sURL=Application("root") & "/frames/rpc/productdisplay_swatchmatrix.aspx?productdisplayid="+productdisplayid+"&imageid="+escape(imageid);
		var colorcount=0;
		//var smsg="";
		for (m=0; m<=productids.length-1; m++) 
		{
			//smsg+="productid"+productids[m]+"=>"+eval("product_"+productids[m]+"_lastcolorid")+"\n";
			if ( eval("product_"+productids[m]+"_lastcolorid") != null ) 
			{
				colorcount++;
				sURL+="&productid"+colorcount+"="+productids[m]+"&productcolorid"+colorcount+"="+eval("product_"+productids[m]+"_lastcolorid")
			}
		}
		//alert(smsg+"\n"+sURL);
		return (sURL);
	}
	
	function colorswatchdesc(productid,row,column,numcolumns,totalswatches,colorname,imgwidth,padding) {		
		var numinrow = 0;
		var totalrows = (totalswatches / numcolumns);
		if (totalrows < 1 ) {
			totalrows = 1;
		} else if ( totalrows > Number(totalrows) ) {
			totalrows = Number(totalrows)+1;
		} else {
			totalrows = Number(totalrows);
		}
		if ( totalswatches < numcolumns ) {
			numinrow=totalswatches
		} else if ( totalswatches = numcolumns ) {
			numinrow=numcolumns;
		} else if ( totalswatches > numcolumns ) {
			if ( totalswatches == totalrows*numcolumns || row < totalrows ) {
				numinrow = numcolumns;
			} else {
				numinrow = totalswatches % numcolumns;
			}
		}
		
		var shtml="<table width='100%' cellpadding='"+padding+"' cellspacing='0'><tr>";
		for (i=0; i<=numcolumns; i++) {
			shtml+="<td width='"+imgwidth+"' nowrap height='1'></td>";
		}
		shtml+="</tr><tr>";
		
		if ( column == 0 ) {
			shtml += "<td colspan='"+(numcolumns+1)+"' align='left' class='swatchlink'>"+colorname+"</td>";
		} else if ( column == numcolumns ) {
			shtml += "<td colspan='"+(numcolumns+1)+"' align='right' class='swatchlink'>"+colorname+"</td>";
		} else if ( column == numinrow ) {
			shtml += "<td colspan='"+(column+1)+"' align='right' class='swatchlink'>"+colorname+"</td>";
			for (i=column+2; i<=numcolumns; i++) {
				shtml+="<td></td>";
			}
		} else {
			for (i=0; i<column-1; i++) {
				shtml+="<td></td>";
			}	
			shtml+="<td colspan='3' align='center' class='swatchlink'>"+colorname+"</td>";
			for (i=column+2; i<=numcolumns; i++) {
				shtml+="<td></td>";
			}			
		}
		shtml += "</tr></table>";
		//shtml += "<br />row: "+row+",column: "+column+",numcolumns: "+numcolumns+"<br />totalrows: "+totalrows+", columns in row: "+numinrow;
			
		obj=getElement("colorswatch_"+productid+"_"+row);
		obj.innerHTML=shtml;
	}
	
	function formatverbosedesc(id,requireclose) {
		xhtml="<html>";
		xhtml+="<head>";		
		xhtml+="</head>";
		xhtml+="<body leftmargin='0' rightmargin='0' topmargin='0' bottommargin='0' style='background-image: url(" + root + "/assets/header2/iFrameBorder.gif);'>";
		xhtml+="<table width='100%' cellspacing='0' cellpadding='2' style='heigh:100;'>";
		if ( requireclose == true ) {
			xhtml+="<tr><td colspan='2' height='10' nowrap></td></tr>";
			xhtml+="<tr><td width='10' nowrap rowspan='2'></td><td width='100%'><B>"+eval("verbosetitle"+id)+"</B></td><td nowrap class='closebutton'><a href='javascript:parent.hidedesc(true);'>X</a>&nbsp;&nbsp;&nbsp;</td></tr>";
			xhtml+="<tr valign='top'><td colspan='2'>";
			xhtml+=eval("verbosedesc"+id);
			xhtml+="<br /><a href='javascript:parent.hidedesc(true);'><img src='"+root+"/assets/secure/closewindow.gif' onmouseover=\"this.src='"+root+"/assets/secure/closewindow_over.gif';\" onmouseout=\"this.src='"+root+"/assets/secure/closewindow.gif';\" border='0' align='absmiddle'></a>";
			xhtml+="</td></tr></table>";
		} else {
			xhtml+="<tr><td colspan='2' height='5' nowrap></td></tr>";
			xhtml+="<tr><td width='10' nowrap rowspan='2'></td><td width='100%'><B>"+eval("verbosetitle"+id)+"</B></td></tr>";
			xhtml+="<tr valign='top'><td>";
			xhtml+=eval("verbosedesc"+id);
			xhtml+="</td></tr>";
			xhtml+="<tr><td colspan='2' height='100' nowrap></td></tr></table>";
		}		
		xhtml+="</body>";
		xhtml+="</html>";
		return xhtml;
	}
	
	function hidedesc(fromwindow) {
		if ( verbosestatus=="open" || (verbosestatus=="lockedopen" && fromwindow == true) ) {
			var x = getElement('verbosewindow');
			x.style.display="none";					
			verbosestatus="closed";
			document.body.onclick = null;
		}
	}
		
	function showdesc(obj,id,requireclose) {
		if (requireclose==true || (requireclose==false && verbosestatus != "lockedopen") ) {
			offsetx=80;
			offsety=28;
			var newX = findPosX(obj)+offsetx;
			var newY = findPosY(obj)+offsety;
			var x = getElement('verbosewindow');
			if (Browser == "NN") { 
				x.moveTo(newX, newY); 
			} else if (Browser == "IE" || Browser == "DOM") { 
				x.style.left = newX + "px"; 
				x.style.top = newY + "px"; 
			} 	
			x.style.display="block";
			var iframeDoc = x.contentDocument || (x.contentWindow && x.contentWindow.document); 			
			iframeDoc.body.innerHTML=formatverbosedesc(id,requireclose);
			document.body.onclick=new Function("hidedesc(true);");
			if ( requireclose == true ) {
				verbosestatus = "lockedopen";
			} else {
				verbosestatus = "open";
			}
		}
	}	
		
	function getsizechartlink(sizechartid) {
		if ( sizechartid=='J' ) {
			return '/popups/sizes_junior.aspx';
		} else if ( sizechartid=='C' ) {
			return '/popups/sizes_contemporary.aspx';
		} else if ( sizechartid=='S' ) {
			return '/popups/sizes_swimwear.aspx';
		} else if ( sizechartid=='T' ) {
			return '/popups/sizes_teen.aspx';
		} else {
			return '/popups/sizes.aspx';
		}
	}
	
	function getsizechart(productid) {
		if ( eval("product_"+productid+"_sizechart") != null) {
			return eval("product_"+productid+"_sizechart")
		} else {
			return '';
		}	
	}

	function setcolortext(name,productid) {		
		getElement('activecolor_'+productid).innerHTML = "<font class='redtext'><strong>"+name+"</strong></font>";
	}
	
	function erasecolor(productid) {
		getElement('activecolor_'+productid).innerHTML = "Roll Over Color";
	}
	
	function doublearraysort(arr1, arr2) {
		var minval, minidx, temp1, temp2, i, j, bcontinue; 
		if (arr1.length > 0 && arr2.length > 0 && arr1.length == arr2.length)
		{
			for (j=0; j<arr1.length; j++)
			{							   
				minval = arr1[j];
				minidx = j;				 
				for (i=j; i<arr1.length; i++)
				{
					if (arr1[i] < minval)
					{
						minval = arr1[i];
						minidx = i;					
					}
				}
				temp1 = arr1[minidx];
				temp2 = arr2[minidx];
				arr1[minidx] = arr1[j];
				arr2[minidx] = arr2[j];
				arr1[j] = temp1;
				arr2[j] = temp2;				   				
			}
		}	
	}
	
	function getminmax(productid,min,max) {		
		min = -1;
		max = -1;
		for (i=0; i<po_prices.length; i++) {
			if ( po_productid[i] == productid && po_availabilityflag[i] == 1 ) {
				if ( parseFloat(po_prices[i]) > parseFloat(max) || max == -1 ) {
					max = parseFloat(po_prices[i]);
				}
				if ( parseFloat(po_prices[i]) < parseFloat(min) || min == -1) {
					min = parseFloat(po_prices[i]);
				}				
			}
		}
		output="&nbsp;&nbsp;&nbsp;$"+min;
			if ( max != min ) {
				output+= " - $" + max;
			} 
		output+=" </strong>"+eval("product"+productid+"_qtymsg");
		return output;
	}
	
	function removechar(instr,character) {
		while ( instr.indexOf(character) != -1 ) {
			instr=instr.replace(character,"");
		}
		return instr;
	}
	
	function setuparrays() {
		//: Setup ProductID Arrays
		for (j=0; j<=productids.length-1; j++) {					
			scolorids="";
			scolornames="";
			ssizeids="";
			ssizenames="";			
			for (k=0; k<=po_productid.length-1; k++) {
				if ( po_productid[k] == productids[j] && po_availabilityflag[k] == 1 ) {					
					if ( scolorids.indexOf("'"+po_colorids[k]+"'") == -1 && po_colorids[k] != '' && po_colorids[k] != ' ' ) {
						scolorids+="'"+po_colorids[k] + "',";
						scolornames+=po_colornames[k] + ",";
					} 										
					if ( ssizeids.indexOf("'"+po_sizeids[k]+"'") == -1 && po_sizeids[k] != '' && po_sizeids[k] != ' ' ) {
						ssizeids+="'"+po_sizeids[k] + "',";
						ssizenames+=po_sizenames[k] + ",";
					} 
				}				
			}									
			ssizeids = removechar(ssizeids,"'");
			scolorids = removechar(scolorids,"'");
			if ( ssizeids.substring(ssizeids.length-1,ssizeids.length) == "," ) {
				ssizeids=ssizeids.substring(0,ssizeids.length-1);
				ssizenames=ssizenames.substring(0,ssizenames.length-1);
			}
			if ( scolorids.substring(scolorids.length-1,scolorids.length) == "," ) {
				scolorids=scolorids.substring(0,scolorids.length-1);
				scolornames=scolornames.substring(0,scolornames.length-1);
			}				
			if ( ssizeids.length == 0 ) {
				eval("sizeids_"+productids[j]+"=new Array();");
			} else {
				eval("sizeids_"+productids[j]+"=ssizeids.split(',');");
			}
			if ( ssizenames.length == 0 ) {
				eval("sizenames_"+productids[j]+"=new Array();");
			} else {
				eval("sizenames_"+productids[j]+"=ssizenames.split(',');");
			}
			if ( scolorids.length == 0 ) {
				eval("colorids_"+productids[j]+"=new Array();");
			} else {
				eval("colorids_"+productids[j]+"=scolorids.split(',');");
			}			
			if ( scolornames.length == 0 ) {
				eval("colornames_"+productids[j]+"=new Array();");
			} else {
				eval("colornames_"+productids[j]+"=scolornames.split(',');");
			}
						
			//: Sort colornames,colorids
			doublearraysort(eval("colornames_"+productids[j]),eval("colorids_"+productids[j]));
						
			//: Set ranges				
			var srange = "";
			
			//if ( eval("sizeids_"+productids[j]+"[0]") != null && eval("sizeids_"+productids[j]+"["+Number(eval("sizeids_"+productids[j]+".length")-1)+"]") != null && Number( eval("sizeids_"+productids[j]+".length")-1 ) != 0 ) {
			//	srange+="Sizes "+eval("sizeids_"+productids[j]+"[0]")+"-"+eval("sizeids_"+productids[j]+"["+Number(eval("sizeids_"+productids[j]+".length")-1)+"]")+ "&nbsp;&nbsp;";
			//}			
			//var min = 0;			
			//var max = 0;
								
			//srange+=getminmax(productids[j],min,max);
			srange="<div style=\"line-height:4px;\">&nbsp;</div>&nbsp;<strong><font size=\"1\" class=\"redtext\"><a href=\"javascript:sizechartpopup(getsizechart("+productids[j]+").toString())\">Size Chart</a></font></strong><br />";
			getElement('range'+productids[j]).innerHTML = srange;			
		}				
		return true;
	}
	
	
	function getprice(optionprice, productid, qty, pricegroup) {		
		if ( qty == "-99" ) {
			qty = 1;
		}			
			numproducts = eval("product"+productid+"_initialcartqty");
			numproducts = numproducts + eval("pricegroup_"+pricegroup);
			
			//: Get # selected for SAME product or other products in price group
			for (m=0; m<=productids.length-1; m++) {
				if ( productids[m] == productid || eval("product_"+productids[m]+"_pricegroup") == eval("product_"+productid+"_pricegroup") ) {
					for (i=1; i<=5; i++) {
						if ( eval("document.forms[0].qty"+productids[m]+"_"+i) != null ) {
							//: Check to see if selected
							if (  
									( eval("document.forms[0].colors"+productids[m]+"_"+i) == null || eval("document.forms[0].colors"+productids[m]+"_"+i+".value") != "-99" ) 
									&& ( eval("document.forms[0].sizes"+productids[m]+"_"+i) == null || eval("document.forms[0].sizes"+productids[m]+"_"+i+".value") != "-99" ) 
									&& ( eval("document.forms[0].qty"+productids[m]+"_"+i+".value") != "-99" )
								) 
									{							
										numproducts=numproducts+Number(eval("document.forms[0].qty"+productids[m]+"_"+i+".value"));																
									}													
						} else {
							//: That was last Element
							break;
						}	
					}
				}
			}
			
					
			
			x = eval("product"+productid+"_discounts.length");
			if ( numproducts > qty ) {
				if ( numproducts-1 > x-1 ) {
					discvalue = eval("product"+productid+"_discounts["+(x-1)+"]");
				} else {
					discvalue = eval("product"+productid+"_discounts["+(numproducts-1)+"]");
				}
			} else {
				discvalue = eval("product"+productid+"_discounts["+(qty-1)+"]");
			}		
			//: check to see if option is on sale and less than qty disc
			if ( parseFloat(optionprice) < parseFloat(discvalue) ) {
				return optionprice;
			} else {
				return discvalue;
			}		
	}
	
	
	function checkqtyselection(productid, instanceno) {
	bsizeselected = true;
	bcolorselected = true;
	bsizeavail = false;
	bcoloravail = false;
		if ( getFormElement('sizes'+productid+'_'+instanceno) != null ) {
			bsizeavail = true;
			if ( getFormElement('sizes'+productid+'_'+instanceno).value.toString() == "-99" ) {
				bsizeselected = false;
			}
		} else {
			bsizeselected = false;
		}
		if ( getFormElement('colors'+productid+'_'+instanceno) != null ) {
			bcoloravail = true;
			if ( getFormElement('colors'+productid+'_'+instanceno).value.toString() == "-99" ) {
				bcolorselected = false;
			}
		} else {
			bcolorselected = false;
		}
		if ( (!(bsizeselected) && bsizeavail) || (!(bcolorselected) && bcoloravail) ) {
			getFormElement('qty'+productid+'_'+instanceno).selectedIndex = 0;
			getFormElement('sku'+productid+'_'+instanceno).value=0;
			if ( bsizeavail && bcoloravail ) {
				alert("Please select a Size & Color first.");
			} else if ( bsizeavail ) {
				alert("Please select a Size first.");
			} else if ( bcoloravail ) {
				alert("Please select a Color first.");
			}
			return false;			
		} else {
			return true;
		}
	}

	function pcase(instring){
		var strReturn_Value = "";
		var iTemp = instring.length;
		if(iTemp==0){
			return"";
		}
		var UcaseNext = false;
		strReturn_Value += instring.charAt(0).toUpperCase();
		for(var iCounter=1;iCounter < iTemp;iCounter++){
			if(UcaseNext == true){
				strReturn_Value += instring.charAt(iCounter).toUpperCase();
			}
			else{
				strReturn_Value += instring.charAt(iCounter).toLowerCase();
			}
			var iChar = instring.charCodeAt(iCounter);
			if(iChar == 32 || iChar == 45 || iChar == 47 ){
				UcaseNext = true;
			}
			else{
				UcaseNext = false
			}
		}
		return strReturn_Value;
	}

	function injectddl(spanprefix, productnumber, instanceno, productid, bsetmoreproducts) {
	colorsempty = false;
	sizesempty = false;
	bonesize = false;
	bonecolor = false;
	
	if ( bsetmoreproducts == true ) { bsetmoreproducts = 1; }
		
	var sHTML = '';
		sHTML += '<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">';
		sHTML += '<tr>';
		
		//: Size DDL
		x = eval('sizeids_'+productid);
		y = eval('sizenames_'+productid);		
		if ( x.length == 0 && y.length == 0 ) {
			sizesempty = true;
		} else {
			sHTML += '<td nowrap><select style=\"z-index: 100;\" class=\"medium\" name=\"sizes'+productid+'_'+instanceno+'\" onchange=\"getavailabilityproduct('+productid+', '+instanceno+')\">\n';
			sHTML += '<option value=\"-99\">Size</option>\n';
			for (k=0; k<=x.length-1; k++) {			
				sHTML += '<option value=\"' + x[k] + '\"';
				if ( x.length-1 == 0 ) {
					//: only one element
					bonesize = true;
					sHTML += ' selected ';
				}
				if (y[k].length > 3)
					sHTML += '>' + pcase(y[k]) + '</option>\n';			
				else
					sHTML += '>' + y[k].toUpperCase() + '</option>\n';			

			}
			sHTML += '</select>';
			sHTML += '</td>';
		}
		
		//: Color DDL
		x = eval('colorids_'+productid);
		y = eval('colornames_'+productid);		
		if ( x.length == 0 && y.length == 0 ) {
			colorsempty = true;
		} else {
			sHTML += '<td nowrap><select style=\"z-index: 100;\" class=\"medium\" name=\"colors'+productid+'_'+instanceno+'\" onchange=\"getavailabilityproduct('+productid+', '+instanceno+');announcecolor('+productid+',this.value,this.options[this.selectedIndex].text)\">\n';
			sHTML += '<option value=\"-99\">Color</option>\n';		
			for (k=0; k<=x.length-1; k++) {
				sHTML += '<option value=\"' + x[k] + '\"';
				if ( x.length-1 == 0 ) {
					//: only one element
					sHTML += ' selected ';
					bonecolor = true;
				}
				sHTML += '>' + pcase(y[k]) + '</option>\n';
			}		
			sHTML += '</select>';
			sHTML += '</td>';
		}						
		
		//: Quantity DDL
		sHTML += '<td align=\"left\" nowrap>';
		sHTML += '<select style=\"z-index: 100;\" class=\"medium\" name=\"qty'+productid+'_'+instanceno+'\" onchange=\"checkqtyselection('+productid+', '+instanceno+');';
		sHTML += 'getavailabilityproduct('+productid+', '+instanceno+',1);'
		sHTML += '\">\n';		
		sHTML += '<option value=\"-99\">Qty</option>\n';
		for (k=1; k<=10; k++) {
			sHTML += '<option value=\"' + (k) + '\">' + (k) + '</option>\n';			
		}		
		sHTML += '</select>';
		//: Sku Hidden Field		
		sHTML += '</td><td width=\"100%\">';
		sHTML += '<input type=\"hidden\" name=\"sku'+productid+'_'+instanceno+'\" value=\"0\" >';
		sHTML += '<input type=\"hidden\" name=\"productdisplayid'+productid+'_'+instanceno+'\" value=\"'+eval("product_"+productid+"_productdisplayid")+'\" >';
		//: Availability
		sHTML += '<span class=\"small\" id=\"availability'+productid+'_'+instanceno+'\" class=\"medium\"></span>\n';
		sHTML += '</td></tr></table>';		
		
		getElement(spanprefix+productnumber+'_'+instanceno).innerHTML=sHTML;	
		if ( bsetmoreproducts == 1 && (!(bonecolor && bonesize)) ) { 
			setmoreproducts(); 
		}

		if ( parseFloat(instanceno) > parseFloat(1) ) {
			//: Set Size
			if ( getFormElement('sizes'+productid+'_'+instanceno) != null ) {
				getFormElement('sizes'+productid+'_'+instanceno).selectedIndex = getFormElement('sizes'+productid+'_'+Number(instanceno-1)).selectedIndex;
			}
		}	
		
	}

	function getindexof(pid,cid,sid) {
		output = -1;
		var stest = "";		
		for (z=0; z<=po_productid.length-1; z++) {			
			if (po_productid[z] == pid && (po_colorids[z] == cid || cid=='') && (po_sizeids[z] == sid || sid=='')) {
				output = z;
				break;
			}
		}				
		return output;				
	}


function getavailability(productid, instanceno, fromqty, originstance, donotset) {
		if ( donotset == null ) {
			donotset = false;
		}

		//: If qty is selected then set qty back to 'qty' if there is not 
		//: both of the required criteria
			bsizeselected = true;
			bcolorselected = true;
			bsizeavail = false;
			bcoloravail = false;
				
			if ( getFormElement('sizes'+productid+'_'+instanceno) != null ) {
				bsizeavail = true;
				if ( getFormElement('sizes'+productid+'_'+instanceno).value == "-99" ) {
					bsizeselected = false;
				}
			} else {
				bsizeselected = false;
			}
			if ( getFormElement('colors'+productid+'_'+instanceno) != null ) {
				bcoloravail = true;
				if ( getFormElement('colors'+productid+'_'+instanceno).value == "-99" ) {
					bcolorselected = false;
				}
			} else {
				bcolorselected = false;
			}
			
			if ( ( (!(bsizeselected) && bsizeavail) || (!(bcolorselected) && bcoloravail) ) && getFormElement('qty'+productid+'_'+instanceno).selectedIndex != 0 ) {
				getFormElement('qty'+productid+'_'+instanceno).selectedIndex = 0;
				getFormElement('sku'+productid+'_'+instanceno).value=0;
			} 
					
		indexno = "";
		if ( getFormElement('qty'+productid+'_'+instanceno) != null ) {
			
			if ( getElement('availability'+productid+'_'+instanceno) != null ) {
					if ( getFormElement('colors'+productid+'_'+instanceno) != null ) {
						var colorvalue = getFormElement('colors'+productid+'_'+instanceno).value;
					} else {
						var colorvalue = "";
					}
					if ( getFormElement('sizes'+productid+'_'+instanceno) != null ) {
						var sizevalue  = getFormElement('sizes'+productid+'_'+instanceno).value;
					} else {
						var sizevalue  = "";
					}										
					indexno = getindexof(productid,colorvalue,sizevalue);				
										
				if ( output == -1 && ((getFormElement('colors'+productid+'_'+instanceno) == null || colorvalue != "-99") && (getFormElement('sizes'+productid+'_'+instanceno) == null || sizevalue != "-99")) ) {
					getElement('availability'+productid+'_'+instanceno).innerHTML="<img src='"+root+"/assets/warning.gif' border='0' align='absmiddle'>&nbsp;<font class='redtext'><b>Not Available</b></font>";
					getFormElement('qty'+productid+'_'+instanceno).value="-99";
					getFormElement('sku'+productid+'_'+instanceno).value=0;	
				} else if ( indexno == -1 ) {										
					//: Not Found
					getElement('availability'+productid+'_'+instanceno).innerHTML=""
					getFormElement('sku'+productid+'_'+instanceno).value=0;					
				} else {											
					//: Found					
					//: Set qty to 1 if currently 0
					
					if ( !donotset ) {					
						if ( (fromqty != true ) && (po_availabilityflag[indexno] == 1) && (getFormElement('qty'+productid+'_'+instanceno).value == "-99") ) {						
							if ( originstance == null || originstance == instanceno ) {
								getFormElement('qty'+productid+'_'+instanceno).value = 1;
							}
						} else if ( (fromqty == true ) && getFormElement('qty'+productid+'_'+instanceno).value.toString() == "-99" ) {											
							//: If from qty ddl and set to 0, leave at 0 and wipe out availability
							getElement('availability'+productid+'_'+instanceno).innerHTML="";
							getFormElement('sku'+productid+'_'+instanceno).value=0;
						}	
					} 	
					
						if ( po_availabilityflag[indexno] != 1 ) { //&& getFormElement('qty'+productid+'_'+instanceno).value.toString() != "-99") {
							getElement('availability'+productid+'_'+instanceno).innerHTML = po_availability[indexno];
							getFormElement('sku'+productid+'_'+instanceno).value="0";
							getFormElement('qty'+productid+'_'+instanceno).value="-99";
						} else if ( getFormElement('qty'+productid+'_'+instanceno).value.toString() != "-99") {
							getElement('availability'+productid+'_'+instanceno).innerHTML = po_availability[indexno]+"<span class='small'><font color='#333333'>&nbsp;$"+getprice(po_prices[indexno],productid,getFormElement('qty'+productid+'_'+instanceno).value,po_pricegroup[indexno])+" ea.</font></span>";
							getFormElement('sku'+productid+'_'+instanceno).value=po_skus[indexno];
						}
				}				
			} 
		} 	
	}

function getavailabilityproduct(productid, instanceno, fromqty) {
		getavailability(productid, instanceno, fromqty, instanceno);		
		for (n=1; n<=5; n++) {		
			if ( getFormElement('qty'+productid+'_'+n) != null ) {				
				if ( n != instanceno ) {
					getavailability(productid, n, false,instanceno);					
				}								
			} else {
				break;
			}
		}
				
		//: Check other products in the same pricegroup
		for (pcnt=0; pcnt<=productids.length-1; pcnt++) {
			if ( productids[pcnt] != productid && eval("product_"+productids[pcnt]+"_pricegroup") == eval("product_"+productid+"_pricegroup") ) {
				for (n=1; n<=5; n++) {		
					if ( getFormElement('qty'+productids[pcnt]+'_'+n) != null ) {				
							getavailability(productids[pcnt], n, false,instanceno,true);		
							//alert('getavailability('+productids[pcnt]+','+n+',false,'+instanceno+');');			
					} else {
						break;
					}
				}	
			}		
		}
		
		//checkadd();		
		return true;
	}
	
	
	function injectinitial() {		
		setuparrays();
		for (j=0; j<=productids.length-1; j++) {					
			injectddl('ddl',Number(j+1),1,productids[j],0);
		}
		setmoreproducts();
	}
	
	function setmoreproducts() {	
		for (m=0; m<=productids.length-1; m++) {	
		bonecolor = false;
		bonesize = false;
		bcoloravail = true;
		bsizeavail = true;
		lastinstance = 6;				
			for (l=1; l<=5; l++) {
				if ( getFormElement('qty'+productids[m]+'_'+l) != null ) {
					//: Element Exists
					lastinstance = l;
				} else {
					//: That was last Element
					break;
				 }
			}
			
			if ( ( getFormElement('sizes'+productids[m]+'_'+lastinstance) != null || getFormElement('colors'+productids[m]+'_'+lastinstance) != null) && Number(lastinstance+1) < 6 ) {
				//: make sure there is more than one item on sizes or colors
				if ( getFormElement('sizes'+productids[m]+'_'+lastinstance) != null ) {
					if ( getFormElement('sizes'+productids[m]+'_'+lastinstance).options.length < 3 ) {
						bonesize=true;
					}	
				} else {
					bsizeavail = false;
				}
				
				if ( getFormElement('colors'+productids[m]+'_'+lastinstance) != null ) {
					if ( getFormElement('colors'+productids[m]+'_'+lastinstance).options.length < 3 ) {
						bonecolor=true;
					}	
				} else {
					bcoloravail = false;
				}
				
				bsetmore = false;
				selectmoremessage="Select Multiple Sizes/Colors";
				if ( bsizeavail && bcoloravail ) {
					if ( !bonesize && !bonecolor ) {
						bsetmore=true;						
						selectmoremessage="Select Multiple Sizes/Colors";
					} else if (!bonesize && bonecolor) {
						bsetmore=true;						
						selectmoremessage="Select Multiple Sizes";
					} else if (bonesize && !bonecolor) {
						bsetmore=true;						
						selectmoremessage="Select Multiple Colors";
					}
				} else if ( bsizeavail && !bcoloravail ) {
					if ( !(bonesize) ) {
						bsetmore=true;
						selectmoremessage="Select Multiple Sizes";
					}
				} else if ( !bsizeavail && bcoloravail ) {
					if ( !(bonecolor) ) {
						bsetmore=true;
						selectmoremessage="Select Multiple Colors";
					}				
				}
									
				if ( bsetmore ) {
					getElement('ddl'+Number(m+1)+'_'+Number(lastinstance+1)).innerHTML="&nbsp;<font class='bluetext'><font class='small' style='font-weight:normal'><a href='javascript:injectddl(\"ddl\","+Number(m+1)+","+Number(lastinstance+1)+","+productids[m]+",1);'>"+selectmoremessage+" ></a></font></font>";
				}
			}			
		}
	}
	
	function checkadd() {
		itemfound=false;		
		for (m=0; m<=productids.length-1 && itemfound==false; m++) {					
				for (l=1; l<=5; l++) {
					if ( getFormElement('qty'+productids[m]+'_'+l) != null ) {
						//: Element Exists
						lastinstance = l;
						//: Check to see if selected
						if ( (getFormElement('colors'+productids[m]+'_'+l) == null || getFormElement('colors'+productids[m]+'_'+l).value != "-99") && ( getFormElement('sizes'+productids[m]+'_'+l) == null || getFormElement('sizes'+productids[m]+'_'+l).value != "-99") && getFormElement('qty'+productids[m]+'_'+l).value != "-99" && getFormElement('sku'+productids[m]+'_'+l).value != "0" ) {							
							itemfound=true;
							break;
						}													
					} else {
						//: That was last Element
						break;
					}
				}				
		}
		obj=getElement('addtocartbutton');
		if ( obj != null ) {
			if ( itemfound ) {			
					obj.src='/assets/secure/bag_on.gif';
					//obj.onmouseout=new Function("this.src='/assets/secure/cart.gif';");
					//obj.onmouseover=new Function("this.src='/assets/secure/cart_over.gif'");
			} else {
					obj.src='/assets/secure/bag_off.gif';
					//obj.onmouseout=new Function("this.src='/assets/secure/additemstocart.gif';");
					//obj.onmouseover=new Function("this.src='/assets/secure/additemstocart_over.gif'");
			}
		}
	}
	
	var processingaddtocart=false;
	function addtocart(dest) {
		if (!processingaddtocart) {
			if ( dest == null ) {
			dest=defaultdestination;
			}
			numproducts = 0;
			spost = "";
			for (m=0; m<=productids.length-1; m++) {					
					for (l=1; l<=5; l++) {
						if ( getFormElement('qty'+productids[m]+'_'+l) != null ) {
							//: Element Exists
							lastinstance = l;
							//: Check to see if selected
							if ( (getFormElement('colors'+productids[m]+'_'+l) == null || getFormElement('colors'+productids[m]+'_'+l).value != "-99") && ( getFormElement('sizes'+productids[m]+'_'+l) == null || getFormElement('sizes'+productids[m]+'_'+l).value != "-99") && getFormElement('qty'+productids[m]+'_'+l).value != "-99" && getFormElement('sku'+productids[m]+'_'+l).value != "0" ) {
								numproducts=numproducts+1;							
								spost+="&productsku"+numproducts+"="+escape( getFormElement('sku'+productids[m]+'_'+l).value )+"&productqty"+numproducts+"="+escape( getFormElement('qty'+productids[m]+'_'+l).value)+"&productdisplayid"+numproducts+"="+escape(getFormElement('productdisplayid'+productids[m]+'_'+l).value);
							}													
						} else {
							//: That was last Element
							break;
						}
					}				
			}
			if ( numproducts == 0 ) {
				alert("Please select an item/qty first.");					
			} else {
				processingaddtocart=true;
				if ( productdisplayid != 0 ) {
				    spost = root + dest + "?storeid=" + storeid + "&productdepartmentid=" + escape(productdepartmentid) + "&isclearance=" + isclearance + "&redirecturl=" + escape(redirecturl) + "&source=" + escape(source) + "&productdisplayid=" + productdisplayid + "&BRANCH=" + branch + "&numformitems=" + numproducts + spost;
					if (dest != "/addtowishlist.aspx" && dest != "/catqorder_addtocart.aspx") {
						var addtocartiframeobj; 
						rpc(addtocartiframeobj,spost,'addtocartiframe');
					}	
					else {location.href=spost;}
				} else if ( productdisplaygroupid != null ) {
					spost = root + dest + "?storeid="+storeid+"&productdepartmentid="+escape(productdepartmentid)+"&isclearance="+isclearance+"&redirecturl="+escape(redirecturl)+"&source="+escape(source)+"&productdisplaygroupid="+productdisplaygroupid+"&BRANCH="+branch+"&numformitems="+numproducts+spost;
					location.href=spost;
				}
			}
		}
	}
	

	function setcolor(obj,val) {
		obj.value=val;
	}

	function emptyddl() {
		for (i=0; i<productids.length; i++ ) {
			for (j=1; j<=5; j++) {				
				//obj=parent.getElement('ddl'+(Number(i)+1)+'_'+j);
				//obj.innerHTML="";
							
					if ( getFormElement('qty'+productids[i]+'_'+j) != null ) {
						obj=getFormElement('qty'+productids[i]+'_'+j);
						obj.selectedIndex=0;
						
						if ( getFormElement('colors'+productids[i]+'_'+j) != null ) {
							obj=getFormElement('colors'+productids[i]+'_'+j);
							obj.selectedIndex=0;
						}
						if ( getFormElement('sizes'+productids[i]+'_'+j) != null ) {
							obj=getFormElement('sizes'+productids[i]+'_'+j);
							obj.selectedIndex=0;
						}
					} else {
						//: That was last Element
						break;
					}
			
			}
		}
	}
