product_number = null;

$(document).ready(function() {
	if($('#create_product').attr('value') == '1') {
		product_number = $('#product_number').attr('value');
		if(product_number.length >= 9 && product_number.length <= 10) {
			SupplierProducts.checkProduct(product_number, function(data, status) {
				if(data != false) {
					onProductExists();
				} else {
					showPriceEnquiry();
				}
			});
		} else {
			showPriceEnquiry();
		}
	}
});

function showPriceEnquiry() {
	$('#supplier_lookup').hide();
	$('#prisforesporgsel').show();
}

function onProductExists() {
	SupplierProducts.createProduct(product_number, function(data, status) {
		if(data != false) {
			document.location = data;
		} else {
			showPriceEnquiry();
		}
	});
}
