	
var STARTEDDRAG = false;
var APPEARED = false;
var DONEWITHZOOMER = true;
var ZOOMHIDER;
var SLIDEROPENED = false;

var mainImageDimension = 284;
var largeImageDimension = 1420;
var zoomBoxDimension = 57;
var LARGESCALE = Math.round(largeImageDimension/mainImageDimension);

var SLIDING = false;

function showLargeImage(){
	if(!SLIDING){
		SLIDING = true;
		if(!SLIDEROPENED){
			new Effect.Move('UI_LargeProductImage_Wrapper', { x: 300, y: 0, mode: 'relative' });
			new Effect.Appear('UI_LargeProductImage', { duration: 1, queue: 'end', afterFinish: function(){SLIDING = false;} });
			SLIDEROPENED = true;
		}else{
			new Effect.Fade('UI_LargeProductImage', { duration: 1 });
			new Effect.Move('UI_LargeProductImage_Wrapper', { x: -300, y: 0, mode: 'relative', queue: 'end', afterFinish: function(){SLIDING = false;} });
			SLIDEROPENED = false;
		}
	}
}

function getMousePosition(event){

	if(!DISABLEZOOM){
		
		DONEWITHZOOMER = false;
		window.clearTimeout(ZOOMHIDER);
		
		var mouseX = Event.pointerX(event);
		var mouseY = Event.pointerY(event);
		
		var parentPosTopLeft = $('UI_ProductImage').cumulativeOffset();
		var parentPos = {left: parentPosTopLeft.left, top: parentPosTopLeft.top, right: (parentPosTopLeft.left+mainImageDimension), bottom: (parentPosTopLeft.top+mainImageDimension)};
		
		var largeParentPosTopLeft = $('UI_LargeProductImage').cumulativeOffset();
		var largeParentPos = {left: largeParentPosTopLeft.left, top: largeParentPosTopLeft.top, right: (largeParentPosTopLeft.left+largeImageDimension), bottom: (largeParentPosTopLeft.top+largeImageDimension)};
		
		var newPos = {left: (mouseX-parentPos.left), top: (mouseY-parentPos.top)}
		var newLargePos = {left: ((newPos.left)*LARGESCALE), top: ((newPos.top)*LARGESCALE)};
		
		//make sure it stays in box
		
		var halfMainImageDimension = Math.round(mainImageDimension/2);
		var halfLargeImageDimension = Math.round(largeImageDimension/2);
		var halfZoomBoxDimension = Math.round(zoomBoxDimension/2);
		
		// left side
		if((newPos.left-halfZoomBoxDimension)<0){
			newPos.left = halfZoomBoxDimension;
		}
		// right side
		else if((newPos.left+zoomBoxDimension-halfZoomBoxDimension)>mainImageDimension){
			newPos.left = (mainImageDimension-zoomBoxDimension+halfZoomBoxDimension);
		}
		
		// left side (large)
		if((newLargePos.left-halfMainImageDimension)<0){
			newLargePos.left = halfMainImageDimension;
		}
		// right side (large)
		else if((newLargePos.left+halfMainImageDimension)>largeImageDimension){
			newLargePos.left = (largeImageDimension-halfMainImageDimension);
		}
		
		// top side
		if((newPos.top-halfZoomBoxDimension)<0){
			newPos.top = halfZoomBoxDimension;
		}
		// bottom side
		else if((newPos.top+zoomBoxDimension-halfZoomBoxDimension)>mainImageDimension){
			newPos.top = (mainImageDimension-zoomBoxDimension+halfZoomBoxDimension);
		}
		
		// top side
		if((newLargePos.top-halfMainImageDimension)<0){
			newLargePos.top = halfMainImageDimension;
		}
		// bottom side
		else if((newLargePos.top+halfMainImageDimension)>largeImageDimension){
			newLargePos.top = (largeImageDimension-halfMainImageDimension);
		}
		
		$('UI_ZoomBox').setStyle({
			'left': (newPos.left-halfZoomBoxDimension) + 'px', 
			'top': (newPos.top-halfZoomBoxDimension) + 'px'
		});
		
		$('ZoomRegion').setStyle({
			'left': ((newLargePos.left-halfMainImageDimension)*-1) + 'px', 
			'top': ((newLargePos.top-halfMainImageDimension)*-1) + 'px'
		});
		
		if(!APPEARED){
			APPEARED = true;
			$('UI_ZoomBox').show();
		}
	
	}
	
}

function startHidingZoomer(event){
	if(!DISABLEZOOM){
		DONEWITHZOOMER = true;
		ZOOMHIDER = window.setTimeout("hideZoomer();", 50);
	}
}

function hideZoomer(){
	if(!DISABLEZOOM){
		if(DONEWITHZOOMER){
			APPEARED = false;
			DONEWITHZOOMER = true;
			$('UI_ZoomBox').hide();
			if(SLIDEROPENED){
				showLargeImage();
			}
		}
	}
}

var CONTENTHEIGHT_TALL = "365px"; //"345px";
var CONTENTHEIGHT_SHORT = "217px";

function showTabContent(atag, tab){
	var lnkDescription = $('lnkDescription');
	var lnkSpecification = $('lnkSpecification');
	var DescriptionContent = $('UI_Contents').select('span.DescriptionContent');
	// rad editor might have converted spans to font tags
	if(DescriptionContent.length < 1){
		DescriptionContent = $('UI_Contents').select('font.DescriptionContent');
	}
	// v2 table tags
	if(DescriptionContent.length < 1){
		DescriptionContent = $('UI_Contents').select('table.DescriptionContent');
	}
	var SpecificationContent = $('UI_Contents').select('span.SpecificationContent');
	// rad editor might have converted spans to font tags
	if(SpecificationContent.length < 1){
		SpecificationContent = $('UI_Contents').select('font.SpecificationContent');
	}
	// v2 table tags
	if(SpecificationContent.length < 1){
		SpecificationContent = $('UI_Contents').select('table.SpecificationContent');
	}
	if(lnkDescription && lnkSpecification){
		lnkDescription.className = "";
		lnkSpecification.className = "";
		if(tab == 'Specification' && SpecificationContent.length >= 1){
			DescriptionContent[0].hide();
			$('UI_Swatches_Wrapper').hide();
			$('UI_Contents_Wrapper').setStyle({
				height: CONTENTHEIGHT_TALL
			});
			SpecificationContent[0].show();
		}else if(DescriptionContent.length >= 1){
			SpecificationContent[0].hide();
			DescriptionContent[0].show();
			if(SWATCHES.length < 1){
				$('UI_Contents_Wrapper').setStyle({
					height: CONTENTHEIGHT_TALL
				});
			}else{
				$('UI_Contents_Wrapper').setStyle({
					height: CONTENTHEIGHT_SHORT
				});
				$('UI_Swatches_Wrapper').show();
			}
		}
		$(atag).className = "Current";
	}
}

function setupTabContent(productName){
	var SpecificationTab = $('UI_SpecificationTab');
	//alert($('UI_Contents').innerHTML);
	var SpecificationContent = $('UI_Contents').select('span.SpecificationContent');
	//alert(SpecificationContent.length);
	// rad editor might have converted spans to font tags
	if(SpecificationContent.length < 1){
		SpecificationContent = $('UI_Contents').select('font.SpecificationContent');
	}
	// v2 table tags
	if(SpecificationContent.length < 1){
		SpecificationContent = $('UI_Contents').select('table.SpecificationContent');
	}
	if(SpecificationContent.length < 1){
		SpecificationTab.hide();
		$('UI_SpacerTab').setStyle({
			width: '273px', 
			cssFloat: 'left', 
			backgroundColor: '#719EB8', 
			borderBottom: 'solid 1px #B7CFDB'
		}); // increase size of spacer tab by width of specification tab
	}else{
		SpecificationContent[0].hide();
		//alert(SpecificationContent[0].innerHTML);
		//alert(1);
	}
	if(SWATCHES.length < 1){
		$('UI_Contents_Wrapper').setStyle({
			height: CONTENTHEIGHT_TALL
		});
	}
	if(productName != ""){
		var h1 = Builder.node('h1');
		h1 = $(h1);
		h1.update(productName);
		var DescriptionContent = $('UI_Contents').select('span.DescriptionContent');
		// rad editor might have converted spans to font tags
		if(DescriptionContent.length < 1){
			DescriptionContent = $('UI_Contents').select('font.DescriptionContent');
		}
		// v2 table tags
		if(DescriptionContent.length < 1){
			DescriptionContent = $('UI_Contents').select('table.DescriptionContent td');
		}
		if(DescriptionContent.length < 1){
			$('UI_Contents').insert({top: h1});
		}else{
			DescriptionContent[0].insert({top: h1});
		}
	}
}

function IsNumeric(strString){
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	if (strString.length == 0) return false;
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			blnResult = false;
		}
	}
	return blnResult;
}

function VerifyQuantity(strElement_Name){
	var strSku, strNew_Element_Name;
	var quantity_textbox, add_checkbox;
	if(strElement_Name.indexOf("_") > -1){
		strSku = strElement_Name.substring(strElement_Name.indexOf("_") + 1, strElement_Name.length);
		if(strElement_Name.substring(0,8) == "quantity"){
			quantity_textbox = $(strElement_Name);
			if(IsNumeric(quantity_textbox.value)){
				strNew_Element_Name = "add_" + strSku;
				add_checkbox = $(strNew_Element_Name);
				if(Number(quantity_textbox.value) > 0){
					add_checkbox.checked = true;
				}else{
					add_checkbox.checked = false;
				}
			}else{
				quantity_textbox.value = 0;
			}
		}else if(strElement_Name.substring(0,3) == "add"){
			add_checkbox = $(strElement_Name);
			strNew_Element_Name = "quantity_" + strSku;
			quantity_textbox = $(strNew_Element_Name);
			if(add_checkbox.checked){
				if(Number(quantity_textbox.value) < 1){
					quantity_textbox.value = "1";
				}
			}else{
				quantity_textbox.value = "0";
			}
		}
	}
}

/* Standard Attributes */

var ATTRIBUTES = new Array();
var LABELS = new Array();
var PRICE = new Array();
var DEFAULTPRICE = new Array();
var ADDTOCARTBTN = new Array();
var ATTRFLDS = new Array();
var ATTRLBLS = new Array();
var QTYFLDS = new Array();
var SELECTINSTRUCTS = new Array("-- <replacementlabel> --", "-- <replacementlabel> (select <replacementpreviouslabel> first) --");
var SETTINGS = new Array();
var PRODUCTS = new Array();
	
function loadAttribute1(productid){
	var ddlAttribute1 = $(ATTRFLDS[productid].attribute1);
	var ddlAttribute2 = $(ATTRFLDS[productid].attribute2);
	var ddlAttribute3 = $(ATTRFLDS[productid].attribute3);
	var ddlAttribute4 = $(ATTRFLDS[productid].attribute4);
	var lblAttribute1 = ATTRLBLS[productid].attribute1;
	var lblAttribute2 = ATTRLBLS[productid].attribute2;
	if(ddlAttribute1){
		ddlAttribute1.options.length = 0;
		ddlAttribute1.options[0] = new Option("", "");
		if(ddlAttribute2){
			ddlAttribute2.options.length = 0;
			ddlAttribute2.options[0] = new Option("", "");
		}
		if(ddlAttribute3){
			ddlAttribute3.options.length = 0;
			ddlAttribute3.options[0] = new Option("", "");
		}
		if(ddlAttribute4){
			ddlAttribute4.options.length = 0;
			ddlAttribute4.options[0] = new Option("", "");
		}
		if(ATTRIBUTES[productid].length > 0){
			var moreThan1Attribute = false;
			var optionIndexStart = 0;
			if(!SETTINGS[productid].oneandone){
				ddlAttribute1.options[0].text = replaceSubstring(SETTINGS[productid].select, "<replacementlabel>", lblAttribute1);
				optionIndexStart++;
				$("UI_ProductAttributes" + productid).setStyle({
					width: "235px", 
					overflow: "hidden", 
					padding: 0,
					margin: "0 auto"
				});
			}else{
				var label = Builder.node('div');
				label.setStyle({
					textAlign: "left",
					overflow: "hidden", 
					fontSize: "14px",
					padding: "2px 2px 20px 4px"
				});
				label = $(label);
				var attributeinfo = ATTRIBUTES[productid][0].originalvalue;
				// -- start -- this removes the product name from the attribute, so just the size is shown
				/*var productname = PRODUCTS[productid].name;
				var productnameparts = productname.split(" ");
				var i = 0;
				for(i=0; i<productnameparts.length; i++){
					attributeinfo = replaceSubstring(attributeinfo, productnameparts[i] + " ", "");
				}*/
				// -- end --
				label.update(attributeinfo);
				ddlAttribute1.insert({before: label});
				$("UI_ProductAttributes" + productid).setStyle({
					height: "21px", 
					width: "230px", 
					overflow: "hidden", 
					border: "solid 1px #DCD1C3", 
					padding: 0,
					margin: "0 auto"
				});
			}
			//alert(ATTRIBUTES[productid][0].text);
			for(var a=0; a<=ATTRIBUTES[productid].length-1; a++){
				ddlAttribute1.options[(a+optionIndexStart)] = new Option(ATTRIBUTES[productid][a].text, ATTRIBUTES[productid][a].value);
				if(!moreThan1Attribute && ATTRIBUTES[productid][a].attribs.length > 0){
					moreThan1Attribute = true;
				}
			}
			if(moreThan1Attribute){
				//ddlAttribute1.observe("change", loadAttribute2);
				if(ddlAttribute2 && lblAttribute1){
					ddlAttribute2.options[0].text = replaceSubstring(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2), "<replacementlabel>", lblAttribute2);
				}
				if(ddlAttribute3 && lblAttribute1){
					ddlAttribute3.options[0].text = replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2);
				}
				if(ddlAttribute4 && lblAttribute1){
					ddlAttribute4.options[0].text = replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2);
				}
			}else{
				if(ddlAttribute2){
					ddlAttribute2.options[0].text = "";
				}
				if(ddlAttribute3){
					ddlAttribute3.options[0].text = "";
				}
				if(ddlAttribute4){
					ddlAttribute4.options[0].text = "";
				}
			}
		}
	}
}

function loadAttribute2(productid){
	var ddlAttribute1 = $(ATTRFLDS[productid].attribute1);
	var ddlAttribute2 = $(ATTRFLDS[productid].attribute2);
	var ddlAttribute3 = $(ATTRFLDS[productid].attribute3);
	var ddlAttribute4 = $(ATTRFLDS[productid].attribute4);
	var lblAttribute1 = ATTRLBLS[productid].attribute1;
	var lblAttribute2 = ATTRLBLS[productid].attribute2;
	var lblAttribute3 = ATTRLBLS[productid].attribute3;
	var attrib1val = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;
	if(ddlAttribute2 && lblAttribute1){
		ddlAttribute2.options.length = 0;
		ddlAttribute2.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2), "");
		if(ddlAttribute3 && lblAttribute1){
			ddlAttribute3.options.length = 0;
			ddlAttribute3.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2), "");
		}
		if(ddlAttribute4 && lblAttribute1){
			ddlAttribute4.options.length = 0;
			ddlAttribute4.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute1), "<replacementlabel>", lblAttribute2), "");
		}
		for(var a=0; a<=ATTRIBUTES[productid].length-1; a++){
			if(ATTRIBUTES[productid][a].value == attrib1val){
				if(ATTRIBUTES[productid][a].attribs.length > 0){
					var moreThan2Attribute = false;
					ddlAttribute2.options[0].text = replaceSubstring(SETTINGS[productid].select, "<replacementlabel>", lblAttribute2);
					for(var b=0; b<=ATTRIBUTES[productid][a].attribs.length-1; b++){
						ddlAttribute2.options[(b+1)] = new Option(ATTRIBUTES[productid][a].attribs[b].text, ATTRIBUTES[productid][a].attribs[b].value);
						if(!moreThan2Attribute && ATTRIBUTES[productid][a].attribs[b].attribs.length > 0){
							moreThan2Attribute = true;
						}
					}
					if(moreThan2Attribute){
						//ddlAttribute2.observe("change", loadAttribute3);
						if(ddlAttribute3 && lblAttribute2){
							ddlAttribute3.options[0].text = replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute2), "<replacementlabel>", lblAttribute3);
						}
						if(ddlAttribute4 && lblAttribute2){
							ddlAttribute4.options[0].text = replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute2), "<replacementlabel>", lblAttribute3);
						}
					}else{
						if(ddlAttribute3){
							ddlAttribute3.options[0].text = "";
						}
						if(ddlAttribute4){
							ddlAttribute4.options[0].text = "";
						}
					}
				}
			}
		}
	}
}

function loadAttribute3(productid){
	var ddlAttribute1 = $(ATTRFLDS[productid].attribute1);
	var ddlAttribute2 = $(ATTRFLDS[productid].attribute2);
	var ddlAttribute3 = $(ATTRFLDS[productid].attribute3);
	var ddlAttribute4 = $(ATTRFLDS[productid].attribute4);
	var lblAttribute2 = ATTRLBLS[productid].attribute2;
	var lblAttribute3 = ATTRLBLS[productid].attribute3;
	var lblAttribute4 = ATTRLBLS[productid].attribute4;
	if(ddlAttribute1 && ddlAttribute2 && lblAttribute2 && ddlAttribute3){
		var attrib1val = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;
		var attrib2val = ddlAttribute2.options[ddlAttribute2.selectedIndex].value;
		ddlAttribute3.options.length = 0;
		ddlAttribute3.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute2), "<replacementlabel>", lblAttribute3), "");
		if(ddlAttribute4 && lblAttribute2){
			ddlAttribute4.options.length = 0;
			ddlAttribute4.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute2), "<replacementlabel>", lblAttribute3), "");
		}
		for(var a=0; a<=ATTRIBUTES[productid].length-1; a++){
			if(ATTRIBUTES[productid][a].value == attrib1val){
				if(ATTRIBUTES[productid][a].attribs.length > 0){
					for(var b=0; b<=ATTRIBUTES[productid][a].attribs.length-1; b++){
						if(ATTRIBUTES[productid][a].attribs[b].value == attrib2val){
							if(ATTRIBUTES[productid][a].attribs[b].attribs.length > 0){
								var moreThan3Attribute = false;
								ddlAttribute3.options[0].text = replaceSubstring(SETTINGS[productid].select, "<replacementlabel>", lblAttribute3);
								for(var c=0; c<=ATTRIBUTES[productid][a].attribs[b].attribs.length-1; c++){
									ddlAttribute3.options[(c+1)] = new Option(ATTRIBUTES[productid][a].attribs[b].attribs[c].text, ATTRIBUTES[productid][a].attribs[b].attribs[c].value);
									if(!moreThan3Attribute && ATTRIBUTES[productid][a].attribs[b].attribs[c].attribs.length > 0){
										moreThan3Attribute = true;
									}
								}
								if(moreThan3Attribute){
									//ddlAttribute3.observe("change", loadAttribute4);
									if(ddlAttribute4 && lblAttribute3){
										ddlAttribute4.options[0].text = replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute3), "<replacementlabel>", lblAttribute4);
									}
								}else{
									if(ddlAttribute4){
										ddlAttribute4.options[0].text = "";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function loadAttribute4(productid){
	var ddlAttribute1 = $(ATTRFLDS[productid].attribute1);
	var ddlAttribute2 = $(ATTRFLDS[productid].attribute2);
	var ddlAttribute3 = $(ATTRFLDS[productid].attribute3);
	var ddlAttribute4 = $(ATTRFLDS[productid].attribute4);
	var lblAttribute3 = ATTRLBLS[productid].attribute3;
	var lblAttribute4 = ATTRLBLS[productid][4];
	var attrib1val = ddlAttribute1.options[ddlAttribute1.selectedIndex].value;
	var attrib2val = ddlAttribute2.options[ddlAttribute2.selectedIndex].value;
	var attrib3val = ddlAttribute3.options[ddlAttribute3.selectedIndex].value;
	if(ddlAttribute4){
		ddlAttribute4.options.length = 0;
		ddlAttribute4.options[0] = new Option(replaceSubstring(replaceSubstring(SETTINGS[productid].selectprevious, "<replacementpreviouslabel>", lblAttribute3), "<replacementlabel>", lblAttribute4), "");
		for(var a=0; a<=ATTRIBUTES[productid].length-1; a++){
			if(ATTRIBUTES[productid][a].value == attrib1val){
				if(ATTRIBUTES[productid][a].attribs.length > 0){
					for(var b=0; b<=ATTRIBUTES[productid][a].attribs.length-1; b++){
						if(ATTRIBUTES[productid][a].attribs[b].value == attrib2val){
							if(ATTRIBUTES[productid][a].attribs[b].attribs.length > 0){
								for(var c=0; c<=ATTRIBUTES[productid][a].attribs[b].attribs.length-1; c++){
									if(ATTRIBUTES[productid][a].attribs[b].attribs[c].value == attrib3val){
										if(ATTRIBUTES[productid][a].attribs[b].attribs[c].attribs.length > 0){
											ddlAttribute4.options[0].text = replaceSubstring(SETTINGS[productid].select, "<replacementlabel>", lblAttribute4);
											for(var d=0; d<=ATTRIBUTES[productid][a].attribs[b].attribs[c].attribs.length-1; d++){
												ddlAttribute4.options[(d+1)] = new Option(ATTRIBUTES[productid][a].attribs[b].attribs[c].attribs[d].text, ATTRIBUTES[productid][a].attribs[b].attribs[c].attribs[d].value);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
	
function loadPrice(what, productid, a1index, a2index, a3index, a4index){
	var newprice = null;
	var outofstock = false;
		//alert(outofstock)
	try{
		if(a4index){
			newprice = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].attribs[(a3index-1)].attribs[(a4index-1)].price;
			outofstock = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].attribs[(a3index-1)].attribs[(a4index-1)].soldout;
		}else if(a3index){
			newprice = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].attribs[(a3index-1)].price;
			outofstock = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].attribs[(a3index-1)].soldout;
		}else if(a2index){
			newprice = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].price;
			outofstock = ATTRIBUTES[productid][(a1index-1)].attribs[(a2index-1)].soldout;
		}else if(a1index){
			newprice = ATTRIBUTES[productid][(a1index-1)].price;
			outofstock = ATTRIBUTES[productid][(a1index-1)].soldout;
		}
	}catch(x){
		// do nothing on error
	}
	if($(QTYFLDS[productid][0]) && $(QTYFLDS[productid][2])){
		//alert(outofstock)
		if(outofstock){
			$(QTYFLDS[productid][0]).hide();
			$(QTYFLDS[productid][2]).show();
		}else{
			$(QTYFLDS[productid][2]).hide();
			$(QTYFLDS[productid][0]).show();
		}
	}
	if(!newprice || newprice == ""){
		newprice = DEFAULTPRICE[productid];
		$(QTYFLDS[productid][2]).hide();
		$(QTYFLDS[productid][0]).show();
		$(QTYFLDS[productid][1]).disable();
		$(QTYFLDS[productid][1]).value = 0;
	}else{
		showHideQuantity(what, QTYFLDS[productid][0], QTYFLDS[productid][2], QTYFLDS[productid][1]);
	}
	if($(PRICE[productid])){
		$(PRICE[productid]).innerHTML = newprice;
	}
}

function showHideQuantity(what, quantityid, outofstockid, quantityfldid){
	if(what.selectedIndex > 0){
		$(quantityfldid).enable();
		var val = what.options[what.selectedIndex].value;
		if(val == ""){
			$(quantityid).hide();
			$(outofstockid).show();
			$(quantityfldid).value = 0;
		}else{
			$(outofstockid).hide();
			$(quantityid).show();
			if(($(quantityfldid).value-0) == 0){
				$(quantityfldid).value = 1;
			}
		}
	}else{
		$(outofstockid).hide();
		$(quantityid).show();
		$(quantityfldid).disable();
		$(quantityfldid).value = 0;
	}
}



function checkQuantitiesAndAttributes(sender, args){
	// TODO: how do I get the product id here to check the right fields?
	//alert("Checking Quantities and Attributes...");
	args.IsValid = true;
}

function checkQuantity(sender, args){
	args.IsValid = true;
}
function checkAttribute1(sender, args){
	args.IsValid = true;
}
function checkAttribute2(sender, args){
	args.IsValid = true;
}
function checkAttribute3(sender, args){
	args.IsValid = true;
}
function checkAttribute4(sender, args){
	args.IsValid = true;
}
