
var verifySKU = function(srcElm,idx,prefix) {
	if (typeof(prefix) == 'undefined')
		var prefix = '';

	// DID THEY ENTER ANYTHING FOR A SKU
	if (srcElm.value != '') {
		// PARSE OUT THE SKU DIGITS FROM WHATEVER THEY ENTERED
		var result = srcElm.value.match(/^[A-Za-z]{0,2}(\d{2}).?(\d{3})[A-Za-z]*$/i);

		// WE FOUND A VALID SKU FORMAT
		if (result != null) {
			var cleanSKU = result[1]+''+result[2];

			// LOOK IT UP USING AJAX
			new Ajax.Request('/checkout/catalog_quick_order_sku_lookup.cfm', {
				method: 'get',
				parameters: { sku:cleanSKU },
				asynchronous: true,
				evalScripts: false,
				// AJAX COMPLETED SUCCESSFULLY
				onSuccess: function(transport) {
					if (transport.responseText.strip().isJSON()) {
						var tmp = transport.responseText.strip().evalJSON();

						// POPULATE THE ITEM ID HIDDEN FIELD, DISPLAY THE SUCCESS ICON
						$(prefix+'qo_'+idx+'_item_id').value = tmp.item_id;
						$(prefix+'qo_'+idx+'_sku_no').value = tmp.sku_no;
						showFlag(prefix, idx, tmp.status);
					}
				},
				// AJAX FAILED DURING THE REQUEST
				onFailure: function(transport) {
					// CLEAR THE ITEM ID HIDDEN FIELD, DISPLAY THE ERROR ICON
					$(prefix+'qo_'+idx+'_item_id').value = '';
					$(prefix+'qo_'+idx+'_sku_no').value = '';
					showFlag(prefix, idx, 'error');
				}
			});
		// WE DID NOT FIND A VALID SKU FORMAT
		} else {
			// CLEAR THE ITEM ID HIDDEN FIELD, DISPLAY THE ERROR ICON
			$(prefix+'qo_'+idx+'_item_id').value = '';
			$(prefix+'qo_'+idx+'_sku_no').value = '';
			showFlag(prefix, idx, 'error');
		}
	// THEY DID NOT ENTER ANYTHING FOR SKU
	} else {
		// CLEAR THE ITEM ID HIDDEN FIELD
		$(prefix+'qo_'+idx+'_item_id').value = '';
		$(prefix+'qo_'+idx+'_sku_no').value = '';
		showFlag(prefix, idx, 'none');
	}
}

var showFlag = function(prefix,idx,state) {
	var flagElmID = prefix+'qo_'+idx+'_flag';
	var msgElmID = prefix+'qo_'+idx+'_msg'

	if (state == 'none') {
		$(flagElmID).setStyle({
			height:'10px',
			width:'10px',
			background:'none'
		});
		$(msgElmID).update('');
	}
	else if (state == 'error') {
		$(flagElmID).setStyle({
			height:'10px',
			width:'10px',
			background:'url(/_img/red_x.gif) no-repeat'
		});
		$(msgElmID).update('SKU Not found');
	}
	else if (state == 'info') {
		$(flagElmID).setStyle({
			height:'10px',
			width:'10px',
			background:'url(/_img/blue_info.gif) no-repeat'
		});
		$(msgElmID).update('This item requires you to select one or more options. After adding your quick order items to your cart, you may click on the link to this item and then make your selection(s).');
	}
	else if (state == 'success') {
		$(flagElmID).setStyle({
			height:'10px',
			width:'10px',
			background:'url(/_img/green_check.gif) no-repeat'
		});
		$(msgElmID).update('SKU found');
	}

	$(flagElmID).observe('mouseover', function(e){ if ($(msgElmID).innerHTML != '') $(msgElmID).show(); });
	$(flagElmID).observe('mouseout', function(e){ $(msgElmID).hide(); });
}

var qtyFormat = function(srcElm) {
	var clean = srcElm.value.replace(/[^0-9]/gi, "");
	if (srcElm.value != clean) {
		showFormatAlert(srcElm);
		srcElm.value = clean;
	}
}

var showFormatAlert = function(elm) {}