//////////////////////////////////////////////////////////
// *******************************************************
// Begin Parts Ordering JavaScript
// *******************************************************
//////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////
	// Updates the quantity fields on the page.  It increases
	// or decreases the quantity by the 'increment' value passed
	// into the function.
	//////////////////////////////////////////////////////////	
	function changeQty(fieldId,increment) 
	{
		field = document.getElementById(fieldId);
		quantity = parseInt(field.value);
		sum =  quantity + increment;
		
		// we don't want the quantity to be less than 1
		if (sum >= 1)
			field.value = sum;
	}
	
	//////////////////////////////////////////////////////////
	// Validates the "Quick Order" form.  If any problems occur,
	// an error message is displayed to the user.
	//////////////////////////////////////////////////////////	
	function validateQuickOrder(theForm)
	{
		var noPartNumbers = true;
		var invalidQuantity = false;
		var partNumberField;
		var messageField = document.getElementById('quickOrderMsgDiv');
		
		for (i=1; i<=6; i++)
		{
			partNumberField = document.getElementById('partNumber_' + i);
			quantityField = document.getElementById('quantity_' + i);
			if (partNumberField.value.length > 0)
			{
				noPartNumbers = false;
				if (quantityField.value.length == 0 || quantityField.value <= 0)
				{
					invalidQuantity = true;
					break;
				}
			}
		}
		
		if (noPartNumbers)
		{
			messageField.innerHTML = 'Please enter at least one part number.';
			messageField.className = 'error show_section';
		}
		else if (invalidQuantity)
		{
			messageField.innerHTML = 'The quantity must be greater than zero.';
			messageField.className = 'error show_section';
		}
		else
		{
			// hide any previous errors displayed to user
			messageField.className = 'hide_section';
			
			// display a message indicating that adding the items to your cart
			// is in progress.  Also, hide the "add to cart" button.
			document.getElementById("addPartsButton").style.display='none';
			document.getElementById("addPartsPleaseWait").style.display='block';
			
			// gather all form values
			/*
			var url = 'ZExpressPartsOrderAdd';
			var param1 = 'storeId='+theForm.storeId.value;
			var param2 = '&catalogId='+theForm.catalogId.value;
			var param3 = '&langId='+theForm.langId.value;
			var param4 = '&orderId='+theForm.orderId.value;
			var param5 = '&errorViewName='+theForm.errorViewName.value;
			var param6 = '&calculationUsageId='+theForm.calculationUsageId.value;
			var param7 = '&shouldCachePage='+theForm.shouldCachePage.value;
			var param8 = '&skuId='+theForm.skuId.value;
			var param9 = '&categoryId='+theForm.categoryId.value;
			var param10 = '&top='+theForm.top.value;
			var param11 = '&partNumber_1='+theForm.partNumber_1.value;
			var param12 = '&partNumber_2='+theForm.partNumber_2.value;
			var param13 = '&partNumber_3='+theForm.partNumber_3.value;
			var param14 = '&partNumber_4='+theForm.partNumber_4.value;
			var param15 = '&partNumber_5='+theForm.partNumber_5.value;
			var param16 = '&partNumber_6='+theForm.partNumber_6.value;
			var param17 = '&quantity_1='+theForm.quantity_1.value;
			var param18 = '&quantity_2='+theForm.quantity_2.value;
			var param19 = '&quantity_3='+theForm.quantity_3.value;
			var param20 = '&quantity_4='+theForm.quantity_4.value;
			var param21 = '&quantity_5='+theForm.quantity_5.value;
			var param22 = '&quantity_6='+theForm.quantity_6.value;
			var param23 = '&URL='+escape(theForm.URL.value);
			var params = param1 + param2 + param3 + param4 + param5 + param6 + 
						param7 + param8 + param9 + param10 + param11 + param12 + 
						param13 + param14 + param15 + param16 + param17 + param18 + 
						param19 + param20 + param21 + param22 + param23;
			*/
			
			// The call is made using the standard XMLHttpRequest because the version of DoJo
			// we are using (0.41) does not support "dojo.xhrPost" and the "dojo.io.bind" will be
			// obsolete when we upgrade (no longer availabe in 1.x versions).  This should still
			// work after an upgrade, but it should be revisited so we can use "dojo.xhrPost".
			//makeHttpPostRequest(url, params, 'addPartsCallBack');
			
			var params = [];
			params.orderId = theForm.orderId.value;
			params["storeId"] = theForm.storeId.value;
			params["catalogId"] = theForm.catalogId.value;
			params["langId"] = theForm.langId.value;
			params["errorViewName"] = theForm.errorViewName.value;
			params["calculationUsageId"] = theForm.calculationUsageId.value;
			params["shouldCachePage"] = theForm.shouldCachePage.value;
			params["skuId"] = theForm.skuId.value;
			params["categoryId"] = theForm.categoryId.value;
			params["top"] = theForm.top.value;
			params["partNumber_1"] = theForm.partNumber_1.value;
			params["partNumber_2"] = theForm.partNumber_2.value;
			params["partNumber_3"] = theForm.partNumber_3.value;
			params["partNumber_4"] = theForm.partNumber_4.value;
			params["partNumber_5"] = theForm.partNumber_5.value;
			params["partNumber_6"] = theForm.partNumber_6.value;
			params["quantity_1"] = theForm.quantity_1.value;
			params["quantity_2"] = theForm.quantity_2.value;
			params["quantity_3"] = theForm.quantity_3.value;
			params["quantity_4"] = theForm.quantity_4.value;
			params["quantity_5"] = theForm.quantity_5.value;
			params["quantity_6"] = theForm.quantity_6.value;
			params["URL"] = escape(theForm.URL.value);
			params["calculateOrder"] = theForm.calculateOrder.value;
			
			wc.service.invoke("AjaxPartsOrderAdd",params);
			cursor_wait();
		}
	}

	//////////////////////////////////////////////////////////
	// Processes the AJAX response from the server after 
	// adding one or more parts to the shopping cart.
	//
	// NOTE:  currently not in use.  This was original callback
	// function being use to add parts to cart via AJAX.
	//////////////////////////////////////////////////////////	
	/*
	function addPartsCallBack(text) 
	{
		var messageField = document.getElementById('quickOrderMsgDiv');
		
		if (text.trim() != '') 
		{
			var isValid = text.match("addtocart:success");
			messageField.innerHTML = text;
			
			if (isValid == 'addtocart:success')
				messageField.className = 'success show_section';
			else
				messageField.className = 'error show_section';
		}
		
		document.getElementById("addPartsButton").style.display='block';
		document.getElementById("addPartsPleaseWait").style.display='none';
	}
	*/


//////////////////////////////////////////////////////////
// *******************************************************
// End Parts Ordering JavaScript
// *******************************************************
//////////////////////////////////////////////////////////

