jQuery('#calendar_submit').livequery('click',function(){
	jf = jQuery('#job-from').val();
	jt = jQuery('#job-to').val();
	if (jf != '' && jt != '') {
		jQuery('#closed_job_div').html('<img src="/images/indicator.gif">')

		cal_data = 'job_from=' + jf + '&job_to=' + jt;
		jQuery.ajax({
			type: "GET",
			url:  "/jobs/ajax_closed_job_for_right",
			data: cal_data,
			success: function(msg){
				jQuery('#closed_job_div').html(msg)
			}
		});

	} else {
		jQuery('#closed_job_div').text('Please enter date range...')
	}

	return false;
});

	function set_price_of_order_item_in_cart(item_id){
				jQuery('#sub_total_' + item_id).html('recalculating...');
				jQuery('#total_tax_' + item_id).html('recalculating...');
				jQuery('#total_shipping_' + item_id).html('recalculating...');
				jQuery('#total_price_' + item_id).html('recalculating...');
				jQuery('#order_total_price').html('recalculating...');

				jQuery('.navi_bar_order_total').html('recalculating...');
				jQuery('.navi_bar_tax_total').html('recalculating...');
				jQuery('.navi_bar_shippping_total').html('recalculating...');
		jQuery.ajax({type: "GET"
			, url: '/shop/get_order_item_price_information_in_json'
			, data: "id=" + item_id
			, success: function(str){
				var tmp = null;
				tmp = eval("(" + str + ")");
				jQuery('#sub_total_' + item_id).html('$ ' + parseFloat(tmp.sub_total_price).toFixed(2));
				jQuery('#total_tax_' + item_id).html('$ ' + parseFloat(tmp.total_tax).toFixed(2));
				jQuery('#total_shipping_' + item_id).html('$ ' + parseFloat(tmp.total_shipping).toFixed(2));
				jQuery('#total_price_' + item_id).html('$ ' + parseFloat(tmp.total_price).toFixed(2));
				jQuery('#order_total_price').html('$ ' + parseFloat(tmp.order_total_price).toFixed(2));

				jQuery('.navi_bar_order_total').html('$ ' + parseFloat(tmp.order_total_price).toFixed(2));
				jQuery('.navi_bar_tax_total').html('$ ' + parseFloat(tmp.order_total_tax).toFixed(2));
				jQuery('.navi_bar_shippping_total').html('$ ' + parseFloat(tmp.order_total_shipping).toFixed(2));
		}});
		return false;
	}


	// Hides original and displays the updated upload div
	function Shoppingcart_UploadUpdate(object,filename){
		jQuery.facebox.close();
		var baseContainer = jQuery.facebox.lastclicked.parents('.shoppingCartItem:first');
		jQuery(baseContainer).find(".uploadOriginal").hide();
		jQuery(baseContainer).find(".uploadUpdate").show();
		jQuery(baseContainer).find(".uploadUpdate span").empty();
		jQuery(baseContainer).find(".uploadUpdate span").prepend(filename);
		return false;
	}

	// Hides original and displays the updated printing div
	function Shoppingcart_PrintingUpdate(object){
		jQuery.facebox.close();
		var baseContainer = jQuery.facebox.lastclicked.parents('.shoppingCartItem:first');
		jQuery(baseContainer).find(".printingOriginal").hide();
		jQuery(baseContainer).find(".printingUpdate").show();
		return false;
	}

	// Hides original and displays the updated shipping div
	function Shoppingcart_ShippingUpdate(object){
		jQuery.facebox.close();
		var baseContainer = jQuery.facebox.lastclicked.parents('.shoppingCartItem:first');
		jQuery(baseContainer).find(".shippingOriginal").hide();
		jQuery(baseContainer).find(".shippingUpdate").show();
		return false;
	}

	function set_email_for_proof(){
		tmp_id = jQuery('input[name="email"]:checked').val();

		if (tmp_id == 'n'){
			email = "(other: " + jQuery('.new_address').val().replace(/\s+/, '') + ")"
		}else{
			email = jQuery('input[name="email"]:checked').val();
		}

		if (jQuery('input[name="email"]:checked').val() == null){
			// alert check
			alert('Please select one of the emails');
		} else if (tmp_id == 'n' && jQuery('.new_address').val().replace(/\s+/, '') == ''){
			alert('Please provide email address for Soft Proof');
		}else{

			jQuery.ajax({type: "GET"
			, url: '/shop/set_email_for_proof'
			, data: "id=" + jQuery('#item_id_for_proof_popup').val() + "&prooftype=" + jQuery('#proof_type_for_proof_popup').val()
				+ "&email=" + email
			, success: function(str){
				jQuery.facebox.close();
				jQuery(".softproof_display_" + jQuery('#item_id_for_proof_popup').val()).text("email: " + email.replace(/^(|)$/g, ''));
			}});
		}

		return false;
	}

	function set_address_for_proof(){
		tmp_id = jQuery('input[name="address"]:checked').val();

		if (tmp_id == 'n'){
			address = encodeURIComponent("(other: " + jQuery('.new_address').val().replace(/\s+/, '') + ")");
		}else{
			address = jQuery('input[name="address"]:checked').val();
		}

		if (jQuery('input[name="address"]:checked').val() == null){
			// alert check
			alert('Please select one of the addresses');
		} else if (tmp_id == 'n' && jQuery('.new_address').val().replace(/\s+/, '') == ''){
			alert('Please provide address for Hard Proof');
		}else{

			jQuery.ajax({type: "GET"
			, url: '/shop/set_address_for_proof'
			, data: "id=" + jQuery('#item_id_for_proof_popup').val() + "&prooftype=" + jQuery('#proof_type_for_proof_popup').val()
				+ "&address=" + address
			, success: function(str){
				jQuery.facebox.close();
				jQuery(".hardproof_display_" + jQuery('#item_id_for_proof_popup').val()).text("address: " + decodeURIComponent(address).replace(/^(|)$/g, ''));
				set_price_of_order_item_in_cart(jQuery('#item_id_for_proof_popup').val());
			}});
		}

		return false;
	}

function set_proof_display(num){
	status = jQuery('#item_proof_status' + num).val();

	if (status != -1) {
		status_str = '';
		if (status == 0) status_str = 'noproof';
		if (status == 1) status_str = 'softproof';
		if (status == 2) status_str = 'hardproof';

		var baseSelector = jQuery("#box_body_div_" + num);
		jQuery(baseSelector).find(".proofRequestTypeSelected div.noproof,.proofRequestTypeSelected div.softproof,.proofRequestTypeSelected div.hardproof").hide();

			// Hide all proof request options
			jQuery(baseSelector).find(".proofRequestTypeSelected div.noproof,.proofRequestTypeSelected div.softproof,.proofRequestTypeSelected div.hardproof").hide();

			// Show selected proof request option via radio value
			jQuery(baseSelector).find(".proofRequestTypeSelected div." + status_str).show();

			// Hide radio options area to display information area
			jQuery(baseSelector).find(".proofRequestType").hide();

			// Clears previous proof request charge (in right column), then moves .proofRequestCharge (which is hidden) to the currentl proof request charge area.

			var proofRequestChargeActual = jQuery(baseSelector).find(".proofRequestChargeActual");
			jQuery(baseSelector).find(".proofRequestTypeSelected").show(); // Displays radio specific information
	}
	return false;
}

function set_upload_display(num) {
	status = jQuery('#file_upload_status' + num).val();

	if (status == 1) {
		jQuery('#uploadOriginal_div' + num).hide();
		jQuery('#uploadUpdate_div' + num).show();
	}

	return false;
}

function submitCpForm() {
	contact = jQuery("input[name='cup_contact']:checked").val();

	if (contact == 'phone' && jQuery("#cup_phone1").val() == "" && jQuery("#cup_phone2").val() == "") {
		alert("Please provide phone number to contact.");
	} else if (contact == 'email' && jQuery("#cup_email").val() == "") {
		alert("Please provide email address to contact.");
	} else if (contact == undefined) {
		alert("Please select a contact method.");
	} else if (jQuery("#cup_name").val() == "") {
		alert("Please provide your name.");
	} else if (jQuery("#cup_message").val() == "") {
		alert("Please provide your message.");
	} else {
		jQuery.ajax({type: "GET"
			, url: '/about/send_message_to_contact'
			, data: "smid=" + jQuery('#sm_contact_form').attr("smid")
				+ "&subject=" + jQuery("#cup_subject").val()
				+ "&message=" + encodeURIComponent(jQuery('#cup_message').val())
				+ "&name=" + encodeURIComponent(jQuery("#cup_name").val())
				+ "&email=" + encodeURIComponent(jQuery("#cup_email").val())
				+ "&phone1=" + encodeURIComponent(jQuery("#cup_phone1").val())
				+ "&phone2=" + encodeURIComponent(jQuery("#cup_phone2").val())
				+ "&method=" + jQuery("input[name='cup_contact']:checked").val()
			, success: function(str){
				jQuery("#rep-contact-form").fadeOut("normal"
					, function(){
						tmp = jQuery("#rep-contact-form").html();
						jQuery("#tmp").html(tmp);
						jQuery("#rep-contact-form").html(str);
						jQuery("#rep-contact-form").fadeIn("normal"
							, function (){
								setTimeout(initCpForm, 2500);
							});
				});
		}});
	}

	return false;
}

function initCpForm() {
	jQuery("#rep-contact-form").slideUp("slow"
		,function () {
		if (jQuery("#tmp").text() != "") jQuery("#rep-contact-form").html(jQuery("#tmp").html());
			jQuery("#tmp").text("");
			jQuery("#sm_pic").attr("src", "");
			jQuery("#sm_name").text("");
			jQuery("#sm_phone").text("");
			jQuery("#sm_email").text("");
			jQuery("#sm_email").attr("href", "");
			jQuery("#sm_id").attr("value", "");
		});
}

function setOptionPricingBox(id) {
	if (op_list) {
		jQuery("#main-contents").css("height","1400px");
		sku = op_list[id];
		box = jQuery("#option_pricing_box");
		mc = jQuery('#main-contents');
		mc.css('height', mc.height());
		box.slideUp("slow"
			, function(){
			jQuery("#pb-quantity").text(sku[0] + "");
			jQuery("#pb-colorway").text(sku[1] + " " + sku[2]);

			for (i = 0; i < sku[3].length; i++) {
				price_type = sku[3][i][0] == "Extra"? "Extra Value Pricing": sku[3][i][0];
				jQuery(".price-box:eq(" + i + ") > .pb-type").text(price_type + "");
				jQuery(".price-box:eq(" + i + ") > .pb-price").text(sku[3][i][1] + "");
				if (sku[3][i][0] == "NextDay") {
					jQuery(".price-box:eq(" + i + ") > .comp-in").text("Complete in 1 business day.");
					jQuery(".price-box:eq(" + i + ") > .comp-date").text(comp_day_list[0] + '*');
				} else if (sku[3][i][0] == "Express") {
					jQuery(".price-box:eq(" + i + ") > .comp-in").text("Complete in 2-3 business days.");
					jQuery(".price-box:eq(" + i + ") > .comp-date").text(comp_day_list[1] + '*');
				} else if (sku[3][i][0] == "Value") {
					jQuery(".price-box:eq(" + i + ") > .comp-in").text("Complete in 4-5 business days.");
					jQuery(".price-box:eq(" + i + ") > .comp-date").text(comp_day_list[2] + '*');
				} else if (sku[3][i][0] == "Extra") {
					jQuery(".price-box:eq(" + i + ") > .comp-in").text("Complete in 6-7 business days.");
					jQuery(".price-box:eq(" + i + ") > .comp-date").text(comp_day_list[3] + '*');
				}
				jQuery(".price-box:eq(" + i + ") > .pb-submit").attr("href", "/shop/add_to_cart/" + id + "/?price_type=" + sku[3][i][0]);
				jQuery(".price-box:eq(" + i + ")").show();
			}

			for (i; i < 4; i++) {
				jQuery(".price-box:eq(" + i + ") > .pb-type").text("");
				jQuery(".price-box:eq(" + i + ") > .pb-price").text("");
				jQuery(".price-box:eq(" + i + ") > .comp-in").text("");
				jQuery(".price-box:eq(" + i + ") > .dates-numbers").text("");
				jQuery(".price-box:eq(" + i + ") > .pb-submit").attr("href", "");
				jQuery(".price-box:eq(" + i + ")").hide();
			}
			box.slideDown("slow");
		});
	}

	return false;
}

function setStockCoatingOption(select) {
	if (co_list) {
		option = '';
		coatings = co_list[jQuery(select).val()][1];
		for (i = 0; i < coatings.length; i++) {
			option += '<option value="' + coatings[i][0] + '">' + coatings[i][1] + '</option>';
		}
		jQuery("#coating_selection").html(option);
	}
}

function logInPrompt() {
	jQuery.get('/shop/login_prompt',  function(data){jQuery.facebox(data)});
}

function editOrderName(order_id){
	div = jQuery('#order_name_submit_div');
	div.html('<img src="/images/indicator.gif">');
	jQuery.get('/shop/edit_order_name/', {id: order_id}, function (data) {
		if (data == '') {
			alert('Error...Please reflesh this page');
		} else {
			jQuery('#order_name_submit_span').html(data);
		}
	});

}

function setOrderName(order_id) {
	order_name = jQuery('#order_name_text').val().replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	if (order_name) {
		div = jQuery('#order_name_submit_div');
		button = div.html();
		div.html('<img src="/images/indicator.gif">');
		jQuery.get('/shop/save_order_name/', {id: order_id, value: order_name}, function (data) {
			if (data == '') {
				alert('Error...Please reflesh this page');
			} else {
				jQuery('#order_name_submit_span').html(data);
				jQuery('.current-cart-reference').text(order_name);
			}
		});
	} else {
		alert('Please enter reference name or PO#.');
	}
	return false;
}

function selectNewEmailForSoftproof(item_id) {
	jQuery('#softproof_email_select_' + item_id + '_n').attr('checked', 'checked');
}

function selectNewEmailForFileContact(item_id) {
	jQuery('#file_contact_email_select_' + item_id + '_n').attr('checked', 'checked');
}

function selectNewPhoneForFileContact(item_id) {
	jQuery('#file_contact_phone_select_' + item_id + '_n').attr('checked', 'checked');
}
//-- ajax functions for setting order items --

function clearItemNameText(item_id) {
	target = jQuery('#item_name_text_' + item_id)
	if (target.css('color') == 'rgb(152, 5, 5)') {
		target.val('').css('color', 'black');
	}
}

function editItemName(item_id) {
	div = jQuery('#item_name_submit_div_' + item_id);
	div.html('<img src="/images/indicator.gif">');
	jQuery.get('/shop/edit_item_name', {id: item_id}, function (data) {
		if (data == '') {
			alert('Error... Please refresh this page.');
		} else {
			jQuery('#item_name_submit_span_' + item_id).html(data);
		}
	});
}

function setItemName(item_id) {
	item_name = jQuery('#item_name_text_' + item_id).val().replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	if (item_name) {
		div = jQuery('#item_name_submit_div_' + item_id);
		button = div.html();
		div.html('<img src="/images/indicator.gif">');
		jQuery.get('/shop/save_item_name', {id: item_id, value: item_name}, function (data) {
			if (data == '') {
				alert('Error... Please refresh this page.');
			} else {
				jQuery('#item_name_submit_span_' + item_id).html(data);
			}
		});
	} else {
		alert('Please enter item name and press save button.');
	}
	return false;
}

function submitMyRepContactForm() {
	subject = jQuery('#cup_subject').val();
	message = jQuery('#cup_message').val();
	name = jQuery('#cup_name').val();
	email = jQuery('#cup_email').val();
	phone = jQuery('#cup_phone1').val();
	method = jQuery("input[name='message[contact_method]']:checked").val();
	if (subject == '') {
		alert('Please enter the subject.');
	} else if (message == '') {
		alert('Please enter the message.');
	} else if (name == '') {
		alert('Please enter your name.');
	} else if (method == undefined) {
		alert('Please select a method to contact.');
	} else if (method == 'email' && email == ''){
		alert('Please enter your email.');
	} else if (method == 'phone' && phone == '') {
		alert('Please enter your phone number.');
	} else {
		document.forms[1].submit()
	}
}

function submitContactUsForm() {
	subject = jQuery('#cup_subject').val();
	smid =  jQuery('#cup_smid').val();
	message = jQuery('#cup_message').val();
	name = jQuery('#cup_name').val();
	email = jQuery('#cup_email').val();
	phone = jQuery('#cup_phone1').val();
	method = jQuery("input[name='cup_contact']:checked").val();
	if (subject == '') {
		alert('Please enter the subject.');
	} else if (smid == '') {
		alert('Please select user/department');
	} else if (message == '') {
		alert('Please enter the message.');
	} else if (name == '') {
		alert('Please enter your name.');
	} else if (method == undefined) {
		alert('Please select a method to contact.');
	} else if (method == 'email' && email == ''){
		alert('Please enter your email.');
	} else if (method == 'phone' && phone == '') {
		alert('Please enter your phone number.');
	} else {
		json = {subject: subject, message: message, name: name, email: email, phone1: phone, method: method, smid: smid};
		jQuery.get('/about/submit_contact_us_form', json, function () {
			notice_dev = jQuery('#cup_notice');
			notice_dev.slideDown('normal', function () {
				notice_dev.fadeOut(5000, function () {
					jQuery('#cup_subject').val('');
					jQuery('#cup_message').val('');
				});
			});
		});
	}
}

function removeItem(id) {
	if (window.confirm('Are you sure to remove?')) {
		jQuery.get('/shop/remove_item', {id: id}, function () {
			jQuery('#item_' + id).slideUp('slow', function () {
				jQuery('#item_' + id).remove();
				change_price_display_for_cart();
			});
		});
	}
}

function setCompleteSection(item_id, section_num, xml) {
	var nav_flg = true;
	var chtml = '';
	var nhtml = '';
	var tmp_xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	chtml = String(tmp_xml.match(/<CurrentSection>.+<\/CurrentSection>/)).replace('<CurrentSection>', '').replace('</CurrentSection>', '');
	nhtml = String(tmp_xml.match(/<NextSection>.+<\/NextSection>/)).replace('<NextSection>', '').replace('</NextSection>', '');
	ctarget = jQuery('#cart_section' + section_num + '_' + item_id);
	next_section_num = section_num + 1;
	ntarget = jQuery('#cart_section' + next_section_num + '_' + item_id);
	exp = jQuery('#cart_section_expander' + section_num + '_' + item_id);
	cart_left_column = jQuery('#cart-left-column');
	cart_left_column.css('height', cart_left_column.height());
	exp.slideUp('slow', function () {
		document.getElementById('cart_section' + section_num + '_' + item_id).innerHTML = chtml;
		next_section = document.getElementById('cart_section' + next_section_num + '_' + item_id);
		if (next_section) next_section.innerHTML = nhtml;
		ctarget.html(chtml);
		ntarget.show();
		exp.slideDown('slow', function () {
			cart_left_column.css('height', 'auto');
		});

		if (section_num == 4) {
			hideNav(item_id);
		} else {
			setNav(item_id, xml);
		}

		change_price_display_for_cart();
	});
}

function setNextStep(item_id, section_num, xml) {
	xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	var lhtml = String(xml.match(/<Left>.+<\/Left>/));
	if (lhtml) lhtml = lhtml.replace('<Left>', '').replace('</Left>', '');
	var rhtml = String(xml.match(/<Right>.+<\/Right>/));
	if (rhtml) rhtml = rhtml.replace('<Right>', '').replace('</Right>', '');
	if (rhtml || lhtml) {
		target = jQuery('#cart_section' + section_num + '_main_' + item_id);
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
		target.slideUp('slow', function () {
			document.getElementById('cart_section' + section_num + '_left_' + item_id).innerHTML = lhtml;
			document.getElementById('cart_section' + section_num + '_right_' + item_id).innerHTML = rhtml;
			target.slideDown('slow', function () {
				cart_left_column.css('height', 'auto');
			});
			setNav(item_id, xml);
			cart_left_column.css('height', 'auto');
		});
	}
}

function setNextStepForMultipleShipping(item_id, section_num, xml) {
	var str = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	str = String(str.match(/<Content>.+<\/Content>/)).replace('<Content>', '').replace('</Content>', '');
	target = jQuery('#cart_section' + section_num + '_main_' + item_id);
	target.slideUp('slow', function () {
		document.getElementById('cart_section' + section_num + '_main_' + item_id).innerHTML = str;
		target.slideDown('slow', function () {
			setNav(item_id, xml);
		});
	});
}

function setNav(item_id, xml) {
	xml = String(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '').match(/<Nav>.+<\/Nav>/));
	if (xml) {
		xml = xml.replace('<Nav>', '').replace('</Nav>', '');
		nvtarget = jQuery('#cart_nav_' + item_id);
		nvtarget.fadeOut('slow', function () {
			document.getElementById('cart_nav_' + item_id).innerHTML = xml;
			nvtarget.fadeIn('slow');
		});
	}
}

function hideNav(item_id) {
	jQuery('#cart_nav_' + item_id).slideUp('slow');
}

function setPrice(xml) {
	xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	var st = String(xml.match(/<SubTotal>.+<\/SubTotal>/));
	if (st) st = st.replace('<SubTotal>', '').replace('</SubTotal>', '');
	var tp = String(xml.match(/<TotalPrice>.+<\/TotalPrice>/));
	if (tp) tp = tp.replace('<TotalPrice>', '').replace('</TotalPrice>', '');
	var tt = String(xml.match(/<TotalTax>.+<\/TotalTax>/));
	if (tt) tt = tt.replace('<TotalTax>', '').replace('</TotalTax>', '');
	var ts = String(xml.match(/<TotalShipping>.+<\/TotalShipping>/));
	if (ts) ts = ts.replace('<TotalShipping>', '').replace('</TotalShipping>', '');
	var checkout = String(xml.match(/<Checkoutable>.+<\/Checkoutable>/));
	if (checkout) checkout = checkout.replace('<Checkoutable>', '').replace('</Checkoutable>', '');
	if (tp && tt) {
		stpd = jQuery('#sub_total_price_display');
		tpd = jQuery('#total_price_display');
		ttd = jQuery('#total_tax_display');
		tsd = jQuery('#total_shipping_display');
		ch = jQuery('.checkout-button');
		stpd.fadeOut('fast', function () {
			tpd.fadeOut('fast', function () {
				ttd.fadeOut('fast', function () {
					tsd.fadeOut('fast', function () {
						ch.slideUp('fast', function () {
								document.getElementById('sub_total_price_display').innerHTML = currency_format(st);
								document.getElementById('total_tax_display').innerHTML = currency_format(tt);
								document.getElementById('total_shipping_display').innerHTML = currency_format(ts);
								document.getElementById('total_price_display').innerHTML = currency_format(tp);
//							ch.html(checkout);
								document.getElementById('checkout-button').innerHTML = checkout;
							stpd.fadeIn('fast', function () {
								ttd.fadeIn('fast', function () {
									tsd.fadeIn('fast', function () {
										tpd.fadeIn('fast', function () {
											ch.slideDown('fast');
										});
									});
								});
							});
						});
					});
				});
			});
		});
	}
}

function getFlagFromXml(xml) {
	var out = false;
	xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	xml = String(xml.match(/<Flag>.+<\/Flag>/));
	if (xml) {
		out = xml.replace('<Flag>', '').replace('</Flag>', '');
	}
	return out;
}

function requestProofStart(item_id) {
	check_ref_name_and_item_name(item_id);
	checkReferenceNameAndItemName(item_id);
	proof_type = jQuery("input[name='proof_start_" + item_id + "']:checked").val();
	if (proof_type == 1) {
		jQuery.get('/shop/request_proof_start_noproof', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 2, xml);
		});
	} else if (proof_type == 2) {
		jQuery.get('/shop/request_proof_start_softproof', {id: item_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	} else if (proof_type == 3) {
		jQuery.get('/shop/request_proof_start_hardproof', {id: item_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	} else {
		alert("Please select item's proof type before pressing next button.");
	}
}

function returnToRequestProofStart(item_id, checked) {
	jQuery.get('/shop/return_to_request_proof_start', {id: item_id, checked: checked}, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function softproofList(item_id) {
	check_ref_name_and_item_name(item_id);
	email = jQuery("input[name='softproof_email_select_" + item_id + "']:checked").val();
	new_email = jQuery('#new_email_field_' + item_id).val();
	if (email == 'n' && new_email == '') {
		alert('Please enter new email address to the field.');
	} else if (email == undefined) {
		alert('Please select email.');
	} else {
		jQuery.get('/shop/softproof_list', {id: item_id, email: email, new_email: new_email}, function (xml) {
			setCompleteSection(item_id, 2, xml);
		});
	}
}

function hardproofSelectShipping(item_id) {
	check_ref_name_and_item_name(item_id);
	proof_type = jQuery("input[name='select_shipping_" + item_id + "']:checked").val();
	if (proof_type == 1) {
		jQuery.get('/shop/hardproof_select_shipping_primary', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 2, xml);
		});
	} else if (proof_type == 2) {
		jQuery.get('/shop/hardproof_select_shipping_list', {id: item_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	} else if (proof_type == 3) {
		jQuery.get('/shop/hardproof_select_shipping_new_address', {id: item_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	} else {
		alert("Please select a shpping address before pressing next button.");
	}
}

function returnToHardproofSelectShipping(item_id, checked) {
	jQuery.get('/shop/return_to_hardproof_select_shipping', {id: item_id, checked: checked}, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function hardproofShippingList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		jQuery.get('/shop/hardproof_shipping_list', {id: item_id, shipping_id: shipping_id}, function (xml) {
			setCompleteSection(item_id, 2, xml);
		});
	}
}

function hardproofAddShippingForm(item_id, small_button_under_list) {
	tmp = (small_button_under_list == 1)? 1: 0;
	jQuery.get('/shop/hardproof_add_shipping_form', {id: item_id, small_button_under_list: tmp}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
		jQuery('#cart_address_' + item_id).slideUp('slow', function () {
			jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
				cart_left_column.css('height', 'auto');
			});
		});
	});
}

function hardproofAddShipping(item_id, small_button_under_list) {
	tmp = (small_button_under_list == 1)? 1: 0;
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account, small_button_under_list: tmp};
	jQuery.get('/shop/hardproof_add_shipping', json, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function hardproofEditShippingForm(item_id, small_button_under_list) {
	tmp = (small_button_under_list == 1)? 1: 0;
	edit_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (edit_id == null) {
		alert('Please select an address to edit');
	} else {
		jQuery.get('/shop/hardproof_edit_shipping_form', {id: item_id, edit_id: edit_id, small_button_under_list: tmp}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
			jQuery('#cart_address_' + item_id).slideUp('slow', function () {
				jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
					cart_left_column.css('height', 'auto');
				});
			});
		});
	}
}

function hardproofEditShipping(item_id, small_button_under_list) {
	tmp = (small_button_under_list == 1)? 1: 0;
	id_to_edit = jQuery('#id_to_edit_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, id_to_edit: id_to_edit, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account, small_button_under_list: tmp};
	jQuery.get('/shop/hardproof_edit_shipping', json, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function hardproofDeleteShipping(item_id) {
	delete_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (delete_id == null) {
		alert('Please select an address to delete');
	} else if  (window.confirm('Are you sure to delete selected address?')) {
jQuery('#address_list_' + item_id).val();
		jQuery.get('/shop/hardproof_delete_shipping', {id: item_id, delete_id: delete_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	}
}

function hardproofNewAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode};
	jQuery.get('/shop/hardproof_new_address', json, function (xml) {
		if (getFlagFromXml(xml) == 1) {
			setCompleteSection(item_id, 2, xml);
		} else {
			setNextStep(item_id, 2, xml);
		}
	});
}


function shippingInfoStart(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_type = jQuery("input[name='shipping_info_" + item_id + "']:checked").val();
	if (shipping_type == 1) {
		jQuery.get('/shop/shipping_info_start_ship_one_location', {id: item_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	} else if (shipping_type == 2) {
		jQuery.get('/shop/shipping_info_start_will_call', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 3, xml);
		});
	} else if (shipping_type == 3) {
		jQuery.get('/shop/shipping_info_start_ship_multiple_location', {id: item_id}, function (xml) {
			setNextStepForMultipleShipping(item_id, 3, xml);
		});
	} else if (shipping_type == 4) {
		jQuery.get('/shop/shipping_info_start_have_my_rep', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 3, xml);
		});
	} else if (shipping_type == 5) {
		// mailing services - americas mailer
		jQuery.get('/shop/shipping_info_start_americas_mailer', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 3, xml);
		});
	} else if (shipping_type == 6) {
		// mailing services - other
		jQuery.get('/shop/shipping_info_start_other_mailer', {id: item_id}, function (xml) {
			setCompleteSection(item_id, 3, xml);
		});
	} else {
		alert("Please select item's shipping type before pressing next button.");
	}
}

function returnToShippingInfoStart(item_id, checked) {
	jQuery.get('/shop/return_to_shipping_info_start', {id: item_id, checked: checked}, function (xml) {
		setNextStep(item_id, 3, xml);
	});
}

function returnToMultipleLocationAddress(item_id, checked, quantity) {
	json = {id: item_id, checked: checked, quantity: quantity};
	jQuery.get('/shop/shipping_info_start_ship_multiple_location', json, function (xml) {
		setNextStepForMultipleShipping(item_id, 3, xml);
	});
}

function selectShippingAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	address = jQuery("input[name='select_shipping_" + item_id + "']:checked").val();
	if (address == 1) {
		jQuery.get('/shop/select_shipping_address_primary', {id: item_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	} else if (address == 2) {
		jQuery.get('/shop/select_shipping_address_list', {id: item_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	} else if (address == 3) {
		jQuery.get('/shop/select_shipping_address_new', {id: item_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	} else {
		alert("Please select item's shipping address before pressing next button.");
	}
}

function returnToSelectShippingAddress(item_id, checked) {
	jQuery.get('/shop/return_to_select_shipping_address', {id: item_id, checked: checked}, function (xml) {
		setNextStep(item_id, 3, xml);
	});
}

function shippingList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		jQuery.get('/shop/shipping_list', {id: item_id, shipping_id: shipping_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	}
}

function returnToShippingList(item_id, secondary_shipping_id){
	jQuery.get('/shop/return_to_shipping_list', {id: item_id, secondary_shipping_id: secondary_shipping_id}, function (xml) {
		setNextStep(item_id, 3, xml);
	});
}

function shippingListAddAddressForm(item_id) {
	jQuery.get('/shop/shipping_list_new_address_form', {id: item_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
		jQuery('#cart_address_' + item_id).slideUp('slow', function () {
			jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
				cart_left_column.css('height', 'auto');
			});
		});
	});
}

function shippingListAddAddress(item_id) {
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/shipping_list_new_address', json, function (xml) {
		setNextStep(item_id, 3, xml);
	});
}

function shippingListDeleteAddress(item_id) {
	delete_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (delete_id == null) {
		alert('Please select an address to delete');
	} else if  (window.confirm('Are you sure to delete selected address?')) {
jQuery('#address_list_' + item_id).val();
		jQuery.get('/shop/shipping_list_delete_address', {id: item_id, delete_id: delete_id}, function (xml) {
			setNextStep(item_id, 3, xml);
		});
	}
}

function shippingListEditAddressForm(item_id) {
	edit_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (edit_id == null) {
		alert('Please select an address to edit');
	} else {
		jQuery.get('/shop/shipping_list_edit_address_form', {id: item_id, edit_id: edit_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
			jQuery('#cart_address_' + item_id).slideUp('slow', function () {
				jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
					cart_left_column.css('height', 'auto');
				});
			});
		});
	}
}

function shippingListEditAddress(item_id) {
	id_to_edit = jQuery('#id_to_edit_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, id_to_edit: id_to_edit, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/shipping_list_edit_address', json, function (xml) {
		setNextStep(item_id, 3, xml);
	});
}

function newShippingAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode};
	jQuery.get('/shop/new_shipping_address', json, function (xml) {
			setNextStep(item_id, 3, xml);
	});
}

function selectShippingMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_method = jQuery("input[name='shipping_method_" + item_id + "']:checked").val();
	if (shipping_method == undefined) {
		alert("Please select shipping method before pressing next button.");
	} else {
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
		price = jQuery("input[name='shipping_method_" + item_id + "']:checked").attr('price');
		json = {id: item_id, shipping_method: shipping_method, shipping_id: shipping_id, price: price, note: note, boxes: boxes, weight: weight};
		jQuery.get('/shop/select_shipping_method', json, function (xml) {
			setCompleteSection(item_id, 3, xml);
		});
	}
}

function multipleLocationAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	remaining = parseInt(jQuery('#remaining_' + item_id).val());
	quantity = jQuery('#quantity_' + item_id).val();
	shipping_select = jQuery("input[name='shipping_select_" + item_id + "']:checked").val();
	json = {id: item_id, quantity: quantity};
	if (quantity == '' || isNaN(quantity)  || parseInt(quantity) < 1 || parseInt(quantity) > remaining) {
		alert('Please set quantity for shipping between 1 to ' + remaining + ' before pressing next button.');
	} else if (shipping_select == null) {
		alert('Please select deilverly option before pressing next button.');
	} else if (shipping_select == 1) {
		jQuery.get('/shop/multiple_location_address_primary', json, function (xml) {
			setNextStepForMultipleShipping(item_id, 3, xml);
		});
	} else if (shipping_select == 2) {
		jQuery.get('/shop/multiple_location_new_shipping', json, function (xml) {
			setNextStepForMultipleShipping(item_id, 3, xml);
		});
	} else if (shipping_select == 3) {
		jQuery.get('/shop/multiple_location_address_list', json, function (xml) {
			setNextStepForMultipleShipping(item_id, 3, xml);
		});
	} else if (shipping_select == 4) {
		jQuery.get('/shop/multiple_location_address_willcall', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	} else if (shipping_select == 5) {
		jQuery.get('/shop/multiple_location_address_recycle', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	} else if (shipping_select == 6) {
		jQuery.get('/shop/multiple_location_address_americas_mailer', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	} else if (shipping_select == 7) {
		jQuery.get('/shop/multiple_location_address_other_mailer', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	}
}

function multipleLocationMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
		json = {id: item_id, shipping_id: shipping_id, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/multiple_location_method', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	}
}

function multipleLocationPriceListForNewShipping(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery('#shipping_id_' + item_id).val();
	quantity = jQuery('#quantity_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, shipping_id: shipping_id, quantity: quantity, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode}
	jQuery.get('/shop/multiple_location_price_list_for_new_shipping', json, function (xml) {
		setNextStepForMultipleShipping(item_id, 3, xml);
	});
}

function multipleLocationSetShippingForNewShipping(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_method = jQuery("input[name='shipping_method_" + item_id + "']:checked").val();
	if (shipping_method == undefined) {
		alert("Please select shipping method before pressing next button.");
	} else {
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
		price = jQuery("input[name='shipping_method_" + item_id + "']:checked").attr('price');
		json = {id: item_id, shipping_method: shipping_method, shipping_id: shipping_id, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight};
		jQuery.get('/shop/multiple_location_method', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	}
}

function returnToMultipleLocationNewShipping(item_id, quantity, shipping_id) {
	json = {id: item_id, shipping_id: shipping_id, quantity: quantity};
	jQuery.get('/shop/return_to_multiple_location_address', json, function (xml) {
		setNextStepForMultipleShipping(item_id, 3, xml);
	});
}

function multipleLocationList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_m_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		quantity = jQuery('#quantity_' + item_id).val();
		json = {id: item_id, shipping_id: shipping_id, quantity: quantity}
		jQuery.get('/shop/multiple_location_list', json, function (xml) {
				setNextStepForMultipleShipping(item_id, 3, xml);
		});
	}
}

function returnToMultipleLocationList(item_id, checked, quantity) {
	json = {id: item_id, checked: checked, quantity: quantity};
	jQuery.get('/shop/multiple_location_address_list', json, function (xml) {
		setNextStepForMultipleShipping(item_id, 3, xml);
	});

}

function multipleLocationListMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
  	json = {id: item_id, shipping_id: shipping_id, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/multiple_location_method', json, function (xml) {
			if (getFlagFromXml(xml) == 1) {
				setCompleteSection(item_id, 3, xml);
			} else {
				setNextStepForMultipleShipping(item_id, 3, xml);
			}
		});
	}
}

function printFileInfoStart(item_id) {
 alert('printFileInfoStart' + '/' + item_id);
}

function print_file_info_start(item_id) {
	check_ref_name_and_item_name(item_id);
	file_submit= jQuery("input[name='select_file_submission_" + item_id + "']:checked").val();
	json = {id: item_id};
	if (file_submit == undefined) {
		alert('Please select submission of your print files before pressiing next button');
	} else if (file_submit == 1) {
		jQuery.get('/shop/print_file_info_start_web', json, function (xml) {
			setNextStep(item_id, 4, xml);
		});
	} else if (file_submit == 2) {
		jQuery.get('/shop/print_file_info_start_mail', json, function (xml) {
			setNextStep(item_id, 4, xml);
		});
	} else if (file_submit == 3) {
		jQuery.get('/shop/print_file_info_start_rep', json, function (xml) {
			setNextStep(item_id, 4, xml);
		});
	}
}

function returnToPrintFileInfoStart(item_id, file_submission_method) {
json = {id: item_id, file_submission_method: file_submission_method};
	jQuery.get('/shop/return_to_print_file_info_start', json, function (xml) {
		setNextStep(item_id, 4, xml);
	});
}

function haveRepContactForFile(item_id) {
	check_ref_name_and_item_name(item_id);
	method = jQuery("input[name='file_contact_method_" + item_id + "']:checked").val();
	if (method == undefined) {
		alert('Please select a method APC rep to contact before click next button.');
	} else if (method == 1) {
		jQuery.get('/shop/have_rep_contact_for_file_phone', json, function (xml) {
			setNextStep(item_id, 4, xml);
		});
	} else if (method == 2) {
		jQuery.get('/shop/have_rep_contact_for_file_email', json, function (xml) {
			setNextStep(item_id, 4, xml);
		});
	}
}

function returnToHaveRepContactForFile(item_id, rep_type) {
	json = {id: item_id, rep_type: rep_type};
	jQuery.get('/shop/return_to_have_rep_contact_for_file', json, function (xml) {
		setNextStep(item_id, 4, xml);
	});
}

function haveRepEmailContactForFile(item_id) {
	check_ref_name_and_item_name(item_id);
	file_contact_email = jQuery("input[name='file_contact_email_select_" + item_id + "']:checked").val();
	new_email = jQuery('#file_contact_new_email_field_' + item_id).val();
	if (file_contact_email == 'n' && new_email == '') {
		alert('Please enter new email address.');
	} else if (file_contact_email == undefined) {
		alert('Please select email to contact');
	} else {
		json = {id: item_id, file_contact_email: file_contact_email, new_email: new_email};
		jQuery.get('/shop/have_rep_email_contact_for_file', json, function (xml) {
			setCompleteSection(item_id, 4, xml);
		});
	}
}

function haveRepPhoneContactForFile(item_id) {
	check_ref_name_and_item_name(item_id);
	file_contact_phone = jQuery("input[name='file_contact_phone_select_" + item_id + "']:checked").val();
	new_phone = jQuery('#file_contact_new_phone_field_' + item_id).val().replace(/^\s+|\s+$/g, "");
	if ((file_contact_phone == 'n'&& new_phone == '') || file_contact_phone == undefined){
		alert('Please enter your phone number or select one.');
	} else {
		json = {id: item_id, phone_id: file_contact_phone, new_phone: new_phone};
		jQuery.get('/shop/have_rep_phone_contact_for_file', json, function (xml) {
			setCompleteSection(item_id, 4, xml);
		});
	}
}

function sendFileByMail(item_id) {
	check_ref_name_and_item_name(item_id);
	jQuery.get('/shop/send_file_by_mail', json, function (xml) {
		setCompleteSection(item_id, 4, xml);
	});
}

function doneUploadingFiles(item_id) {
	jQuery.get('/upload/file_existance_check/' + item_id, function (result) {
		if (result == '0') {
			alert('Please upload file.');
		} else {
			jQuery.get('/shop/file_upload_completed/' + item_id, function (xml) {
				window.opener.setCompleteSection(item_id, 4, xml);
				window.close();
			});
		}
	});
}

function fileUploadCompletedAtCart(item_id) {
	check_ref_name_and_item_name(item_id);
	jQuery.get('/upload/file_existance_check/' + item_id, function (result) {
		if (result == '0') {
			alert('Please upload file.');
		} else {
			jQuery.get('/shop/file_upload_completed/' + item_id, function (xml) {
				setCompleteSection(item_id, 4, xml);
			});
		}
	});
}

function editCartSection(item_id, section_num, xml) {
	xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
	xml = String(xml.match(/<Content>.+<\/Content>/)).replace('<Content>', '').replace('</Content>', '');
	target_section = jQuery('#cart_section' + section_num + '_' + item_id);
	target_section.slideUp('slow', function () {
		document.getElementById('cart_section' + section_num + '_' + item_id).innerHTML = xml;
		target_section.slideDown('slow');
	});
}

function section2Edit(item_id) {
	jQuery.get('/shop/section2_edit/' + item_id, function (xml) {
		editCartSection(item_id, 2, xml);
	});
}

function editRequestProofStart(item_id) {
	check_ref_name_and_item_name(item_id);
	proof_type = jQuery("input[name='proof_start_" + item_id + "']:checked").val();
	if (proof_type == 1) {
		jQuery.get('/shop/edit_request_proof_start_noproof', {id: item_id}, function (xml) {
			editCartSection(item_id, 2, xml);
			change_price_display_for_cart();
		});
	} else if (proof_type == 2) {
		jQuery.get('/shop/edit_request_proof_start_softproof', {id: item_id}, function (xml) {
			editCartSection(item_id, 2, xml);
		});
	} else if (proof_type == 3) {
		jQuery.get('/shop/edit_request_proof_start_hardproof', {id: item_id}, function (xml) {
			editCartSection(item_id, 2, xml);
		});
	} else {
		alert("Please select item's proof type before pressing next button.");
	}
}

function editReturnToRequestProofStart(item_id, checked) {
	jQuery.get('/shop/edit_return_to_request_proof_start', {id: item_id, checked: checked}, function (xml) {
		editCartSection(item_id, 2, xml);
	});
}

function editSoftproofList(item_id) {
	check_ref_name_and_item_name(item_id);
	email = jQuery("input[name='softproof_email_select_" + item_id + "']:checked").val();
	new_email = jQuery('#new_email_field_' + item_id).val();
	if (email == 'n' && new_email == '') {
		alert('Please enter new email address to the field.');
	} else if (email == undefined) {
		alert('Please select email.');
	} else {
		jQuery.get('/shop/edit_softproof_list', {id: item_id, email: email, new_email: new_email}, function (xml) {
			editCartSection(item_id, 2, xml);
			change_price_display_for_cart();
		});
	}
}

function editHardproofSelectShipping(item_id) {
	check_ref_name_and_item_name(item_id);
	proof_type = jQuery("input[name='select_shipping_" + item_id + "']:checked").val();
	if (proof_type == 1) {
		jQuery.get('/shop/edit_hardproof_select_shipping_primary', {id: item_id}, function (xml) {
			editCartSection(item_id, 2, xml);
			change_price_display_for_cart();
		});
	} else if (proof_type == 2) {
		jQuery.get('/shop/edit_hardproof_select_shipping_list', {id: item_id, small_button_under_list: 1}, function (xml) {
			editCartSection(item_id, 2, xml);
		});
	} else if (proof_type == 3) {
		jQuery.get('/shop/edit_hardproof_select_shipping_new_address', {id: item_id}, function (xml) {
			editCartSection(item_id, 2, xml);
		});
	} else {
		alert("Please select a shpping address before pressing next button.");
	}
}

function editReturnToHardproofSelectShipping(item_id, checked) {
	jQuery.get('/shop/edit_return_to_hardproof_select_shipping', {id: item_id, checked: checked}, function (xml) {
		editCartSection(item_id, 2, xml);
	});
}

function editHardproofShippingList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		jQuery.get('/shop/edit_hardproof_shipping_list', {id: item_id, shipping_id: shipping_id}, function (xml) {
			editCartSection(item_id, 2, xml);
			change_price_display_for_cart();
		});
	}
}

function editHardproofAddShippingForm(item_id) {
	jQuery.get('/shop/hardproof_add_shipping_form', {id: item_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
		jQuery('#cart_address_' + item_id).slideUp('slow', function () {
			jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
				cart_left_column.css('height', 'auto');
			});
		});
	});
}

function editHardproofAddShipping(item_id) {
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/hardproof_add_shipping', json, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function editHardproofEditShippingForm(item_id) {
	edit_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (edit_id == null) {
		alert('Please select an address to edit');
	} else {
		jQuery.get('/shop/hardproof_edit_shipping_form', {id: item_id, edit_id: edit_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
			jQuery('#cart_address_' + item_id).slideUp('slow', function () {
				jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
					cart_left_column.css('height', 'auto');
				});
			});
		});
	}
}

function editHardproofEditShipping(item_id) {
	id_to_edit = jQuery('#id_to_edit_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, id_to_edit: id_to_edit, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/hardproof_edit_shipping', json, function (xml) {
		setNextStep(item_id, 2, xml);
	});
}

function editHardproofDeleteShipping(item_id) {
	delete_id = jQuery("input[name='address_list_h_" + item_id + "']:checked").val();
	if (delete_id == null) {
		alert('Please select an address to delete');
	} else if  (window.confirm('Are you sure to delete selected address?')) {
jQuery('#address_list_' + item_id).val();
		jQuery.get('/shop/hardproof_delete_shipping', {id: item_id, delete_id: delete_id}, function (xml) {
			setNextStep(item_id, 2, xml);
		});
	}
}

function editHardproofNewAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode};
	jQuery.get('/shop/edit_hardproof_new_address', json, function (xml) {
		editCartSection(item_id, 2, xml);
		change_price_display_for_cart();
	});
}

function section3Edit(item_id) {
	jQuery.get('/shop/section3_edit/' + item_id, function (xml) {
		editCartSection(item_id, 3, xml);
		change_price_display_for_cart();
	});
}

function editShippingInfoStart(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_type = jQuery("input[name='shipping_info_" + item_id + "']:checked").val();
	if (shipping_type == 1) {
		jQuery.get('/shop/edit_shipping_info_start_ship_one_location', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (shipping_type == 2) {
		jQuery.get('/shop/edit_shipping_info_start_will_call', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (shipping_type == 3) {
		jQuery.get('/shop/edit_shipping_info_start_ship_multiple_location', {id: item_id}, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_type == 4) {
		jQuery.get('/shop/edit_shipping_info_start_have_my_rep', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (shipping_type == 5) {
		jQuery.get('/shop/edit_shipping_info_start_americas_mailer', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (shipping_type == 6) {
		jQuery.get('/shop/edit_shipping_info_start_other_mailer', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else {
		alert("Please select item's shipping type before pressing next button.");
	}
}

function returnToEditShippingInfoStart(item_id, checked, quantity) {
	json = {id: item_id, checked: checked, quantity: quantity};
	jQuery.get('/shop/edit_shipping_info_start_ship_multiple_location', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
	});
}

function editReturnToShippingInfoStart(item_id, checked) {
	jQuery.get('/shop/edit_return_to_shipping_info_start', {id: item_id, checked: checked}, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editSelectShippingAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	address = jQuery("input[name='select_shipping_" + item_id + "']:checked").val();
	if (address == 1) {
		jQuery.get('/shop/edit_select_shipping_address_primary', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (address == 2) {
		jQuery.get('/shop/edit_select_shipping_address_list', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else if (address == 3) {
		jQuery.get('/shop/edit_select_shipping_address_new', {id: item_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	} else {
		alert("Please select item's shipping address before pressing next button.");
	}
}

function editReturnToSelectShippingAddress(item_id, checked) {
	jQuery.get('/shop/edit_return_to_select_shipping_address', {id: item_id, checked: checked}, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editShippingList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		jQuery.get('/shop/edit_shipping_list', {id: item_id, shipping_id: shipping_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function editReturnToShippingList(item_id, secondary_shipping_id){
	jQuery.get('/shop/edit_return_to_shipping_list', {id: item_id, secondary_shipping_id: secondary_shipping_id}, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editShippingListAddAddressForm(item_id) {
	jQuery.get('/shop/edit_shipping_list_new_address_form', {id: item_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
		jQuery('#cart_address_' + item_id).slideUp('slow', function () {
			jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
				editCartSection(item_id, 3, xml);
			});
		});
	});
}

function editShippingListAddAddress(item_id) {
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/edit_shipping_list_new_address', json, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editShippingListDeleteAddress(item_id) {
	delete_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (delete_id == null) {
		alert('Please select an address to delete');
	} else if  (window.confirm('Are you sure to delete selected address?')) {
jQuery('#address_list_' + item_id).val();
		jQuery.get('/shop/edit_shipping_list_delete_address', {id: item_id, delete_id: delete_id}, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function editShippingListEditAddressForm(item_id) {
	edit_id = jQuery("input[name='address_list_s_" + item_id + "']:checked").val();
	if (edit_id == null) {
		alert('Please select an address to edit');
	} else {
		jQuery.get('/shop/edit_shipping_list_edit_address_form', {id: item_id, edit_id: edit_id}, function (xml) {
		cart_left_column = jQuery('#cart-left-column');
		cart_left_column.css('height', cart_left_column.height());
			jQuery('#cart_address_' + item_id).slideUp('slow', function () {
				jQuery('#cart_address_' + item_id).html(xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '')).slideDown('slow', function () {
					editCartSection(item_id, 3, xml);
				});
			});
		});
	}
}

function editShippingListEditAddress(item_id) {
	id_to_edit = jQuery('#id_to_edit_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	shipper_account = jQuery('#shipper_account_' + item_id).val();
	json = {id: item_id, id_to_edit: id_to_edit, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode, shipper_account: shipper_account};
	jQuery.get('/shop/edit_shipping_list_edit_address', json, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editNewShippingAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode};
	jQuery.get('/shop/edit_new_shipping_address', json, function (xml) {
		editCartSection(item_id, 3, xml);
	});
}

function editSelectShippingMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_method = jQuery("input[name='shipping_method_" + item_id + "']:checked").val();
	if (shipping_method == undefined) {
		alert("Please select shipping method before pressing next button.");
	} else {
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
		price = jQuery("input[name='shipping_method_" + item_id + "']:checked").attr('price');
		json = {id: item_id, shipping_method: shipping_method, shipping_id: shipping_id, price: price, note: note, boxes: boxes, weight: weight};
		jQuery.get('/shop/edit_select_shipping_method', json, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function editMultipleLocationAddress(item_id) {
	check_ref_name_and_item_name(item_id);
	remaining = parseInt(jQuery('#remaining_' + item_id).val());
	quantity = jQuery('#quantity_' + item_id).val();
	shipping_select = jQuery("input[name='shipping_select_" + item_id + "']:checked").val();
	json = {id: item_id, quantity: quantity};
	if (quantity == '' || isNaN(quantity)  || parseInt(quantity) < 1 || parseInt(quantity) > remaining) {
		alert('Please set quantity for shipping between 1 to ' + remaining + ' before pressing next button.');
	} else if (shipping_select == null) {
		alert('Please select deilverly option before pressing next button.');
	} else if (shipping_select == 1) {
		jQuery.get('/shop/edit_multiple_location_address_primary', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 2) {
		jQuery.get('/shop/edit_multiple_location_address_list', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 3) {
		jQuery.get('/shop/edit_multiple_location_address_willcall', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 4) {
		jQuery.get('/shop/edit_multiple_location_address_recycle', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	}
}

function editMultipleLocationMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
  	json = {id: item_id, shipping_id: shipping_id, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/edit_multiple_location_method', json, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function editMultipleLocationList(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_m_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		quantity = jQuery('#quantity_' + item_id).val();
		json = {id: item_id, shipping_id: shipping_id, quantity: quantity}
		jQuery.get('/shop/edit_multiple_location_list', json, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function editMultipleLocationListMethod(item_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
  	json = {id: item_id, shipping_id: shipping_id, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/edit_multiple_location_method', json, function (xml) {
			editCartSection(item_id, 3, xml);
		});
	}
}

function validateNewCCForOneTimeUse() {
	var out = validateNewCCForPaymentPage()? true: false;
	return out;
}

function validateNewCCWithNumberStore() {
	if (out = validateNewCCForPaymentPage()) {
		if (jQuery('#card_reference_name1').val().replace(/\s+/g, '') == '') {
			alert('Please enter your "Card Reference"');
			out = false;
		}
	}
	return out;
}

function validateNewCCWithoutNumberStore() {
	if (out = validateNewCCForPaymentPage()) {
		if (jQuery('#card_reference_name2').val().replace(/\s+/g, '') == '') {
			alert('Please enter your "Card Reference"');
			out = false;
		}
	}
	return out;
}

function validateNewCCForPaymentPage() {
	var out = true;

	//-- check if card member name is not empty
	if (jQuery('#card_member_name').val().replace(/\s+/g, '') == '') {
		alert('Please enter your "Card Member Name"');
		out = false;
	}

	//-- check if card type is selected
	if (out) card_type = jQuery('#card_type').val();
	if (out && card_type == 0) {
		alert('Please select your "Card Type"');
		out = false;
	}

	//-- set card number
	if (out) card_number = jQuery('#card_number').val().replace(/\s+/g, '').replace(/\D/g, '');

	//-- check if card number is not empty
	if (out && card_number == '') {
		alert('Please enter your "Card Number"');
		out = false;
	}

	//-- set length of card number
	if (out) num_length = card_number.length;

	//-- check card number for appropriate card type
	if (out && card_type == 1 && (!(num_length == 13 || num_length == 16) || card_number.substring(0, 1) != '4')) {
		// visa
		alert('You have selected "Visa".\nPlease check your "Card Number".');
		out = false;
	} else if (out && card_type == 2 && (num_length != 15 || !(card_number.substring(0, 2) == '34' || card_number.substring(0, 2) == '37'))) {
		// amex
		alert('You have selected "Amex".\nPlease check your "Card Number".');
		out = false;
	} else if (out && card_type == 3 && (num_length != 16 || !(card_number.substring(0, 2) >= 51 && card_number.substring(0, 2) <= 55))) {
		// master
		alert('You have selected "Master Card".\nPlease check your "Card Number".');
		out = false;
	} else if (out && card_type == 5 && (num_length != 16 || card_number.substring(0, 4) != '6011')) {
		// discover
		alert('You have selected "Discover".\nPlease check your "Card Number".');
		out = false;
	}

	//-- check if the same card number exists
	if (out) {
		jQuery.ajax({
			async: false,
			type: 'GET',
			url: '/shop/duplecate_credit_card_check',
			data: 'card_num=' + card_number,
			success: function (flg) {
				if (flg == '0') {
					alert('This Credit Card information already exists in our database.');
					out = false;
				}
			}
		});
	}

	if (out && jQuery('#card_month').val() == '') {
		alert('Please select month of "Expiration Date"');
		out = false;
	}

	if (out && jQuery('#card_year').val() == '') {
		alert('Please select year of "Expiration Date"');
		out = false;
	}

	if (out && jQuery('#code').val().replace(/^\s+|\s+$/g, '') == '') {
		alert('Please enter your "Security Code"');
		out = false;
	}

	if (out && jQuery('#billing_address').val().replace(/\s+/g, '') == '') {
		alert('Please enter your "Billing Address"');
		out = false;
	}

	if (out && jQuery('#city').val().replace(/\s+/g, '') == '') {
		alert('Please enter your "City"');
		out = false;
	}

	if (out && jQuery('#state').val() == 0) {
		alert('Please select your "State"');
		out = false;
	}

	if (out && jQuery('#zipcode').val().replace(/\s+/g, '') == '') {
		alert('Please enter your "Zip"');
		out = false;
	}

	if (out && jQuery('#country').val() == 0) {
		alert('Please select your "Country"');
		out = false;
	}

	return out;
}

function checkBeforePlaceOrder() {
	out = true;
	if (jQuery("input:checkbox[name='accept_turms']:checked").val() != '1') {
		alert('Please read and check "Accept terms and conditions"');
		out = false;
	}
	else{
		jQuery('#place_order_form').hide();
		jQuery('#place_order_processing').show();
	}
	return out;
}

function edit_one_shipping_start(item_id, shipping_id) {
	json = {id: item_id, shipping_id: shipping_id};
	jQuery.get('/shop/edit_one_shipping_start', json, function (xml) {
		cs = jQuery('#cart_section3_' + item_id);
		cs.slideUp('slow', function () {
			cs.html(xml).slideDown('slow');
		});
	});
}

function edit_one_shipping(item_id, shipping_id) {
	check_ref_name_and_item_name(item_id);
	type = jQuery("input[name='shipping_select_" + item_id + "']:checked").val();
	json = {id: item_id, shipping_id: shipping_id, quantity: jQuery('#shipping_quantity_' + item_id).val()};
	if (type == 1) {
		jQuery.get('/shop/edit_one_shipping_prime', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (type == 2) {
		jQuery.get('/shop/edit_one_shipping_list', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (type == 3) {
		jQuery.get('/shop/edit_one_shipping_willcall', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (type == 4) {
		jQuery.get('/shop/edit_one_shipping_recycle', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (type == 5) {
		// mailing services - americas mailer
		jQuery.get('/shop/edit_one_shipping_americas_mailer', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (type == 6) {
		// mailing services - other
		jQuery.get('/shop/edit_one_shipping_other_mailer', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else {
		alert('Please select a delivery or pickup option.');
	}
}

function shipping_list_for_edit(item_id, shipping_id) {
	check_ref_name_and_item_name(item_id);
	shipping_address = jQuery("input[name='address_list_m_" + item_id + "']:checked").val();
	if (shipping_address == null) {
		alert('Please select an address for ship');
	} else {
		json = {id: item_id, shipping_id: shipping_id, shipping_address: shipping_address}
		jQuery.get('/shop/shipping_list_for_edit', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	}
}

function select_shipping_method_for_edit(item_id, shipping_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#shipping_quantity_' + item_id).val();
		sa_obj = jQuery('#shipping_address_' + item_id);
		shipping_address = sa_obj.val();
		boxes = sa_obj.attr('boxes');
		weight = sa_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
  	json = {id: item_id, shipping_id: shipping_id, shipping_address: shipping_address, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/select_shipping_method_for_edit', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function change_price_display_for_cart() {
	var st, tp, tt, ts, co, stpd, tpd, ttd, tsd, cod;
	jQuery.get('/shop/change_price_display_for_cart', function (xml) {
		if (xml == '') {
			alert('Error... Please refresh this page.');
		} else {
			xml = xml.replace(/\s+/g, ' ').replace(/^[ ]+|[ ]+$/g, '');
			var st = String(xml.match(/<SubTotal>.+<\/SubTotal>/));
			if (st) st = st.replace('<SubTotal>', '').replace('</SubTotal>', '');
			var tp = String(xml.match(/<TotalPrice>.+<\/TotalPrice>/));
			if (tp) tp = tp.replace('<TotalPrice>', '').replace('</TotalPrice>', '');
			var tt = String(xml.match(/<TotalTax>.+<\/TotalTax>/));
			if (tt) tt = tt.replace('<TotalTax>', '').replace('</TotalTax>', '');
			var ts = String(xml.match(/<TotalShipping>.+<\/TotalShipping>/));
			if (ts) ts = ts.replace('<TotalShipping>', '').replace('</TotalShipping>', '');
			var co = String(xml.match(/<CheckOut>.+<\/CheckOut>/));
			if (co) co = co.replace('<CheckOut>', '').replace('</CheckOut>', '');
			var nu = String(xml.match(/<ItemNum>.+<\/ItemNum>/));
			if (nu) nu = nu.replace('<ItemNum>', '').replace('</ItemNum>', '');
			if (tp && tt) {
				stpd = jQuery('#sub_total_price_display');
				tpd = jQuery('#total_price_display');
				ttd = jQuery('#total_tax_display');
				tsd = jQuery('#total_shipping_display');
				cod = jQuery('.checkout-button');
				nud = jQuery('#item_number_display');
				cod.html(co);
				stpd.fadeOut('fast', function () {
					ttd.fadeOut('fast', function () {
						tsd.fadeOut('fast', function () {
							tpd.fadeOut('fast', function () {
								nud.fadeOut('fast', function () {
									document.getElementById('sub_total_price_display').innerHTML = currency_format(st);
									document.getElementById('total_tax_display').innerHTML = currency_format(tt);
									document.getElementById('total_shipping_display').innerHTML = currency_format(ts);
									document.getElementById('total_price_display').innerHTML = currency_format(tp);
									document.getElementById('item_number_display').innerHTML = nu;
									stpd.fadeIn('fast', function () {
										ttd.fadeIn('fast', function () {
											tsd.fadeIn('fast', function (){
												tpd.fadeIn('fast', function (){
													nud.fadeIn('fast');
												});
											});
										});
									});
								});
							});
						});
					});
				});
			}
		}
	});
}

function currency_format(str) {
	if (str.match(/\.[0-9]{1}$/)) str = str + '0';
	return str;
}

function remove_item_shipping(item_id, shipping_id, location_id) {
	if (window.confirm('Are you sure to remove location ' + location_id + '?')) {
		json = {id: item_id, shipping_id: shipping_id};
		jQuery.get('/shop/remove_one_shipping', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function add_shipping(item_id) {
	check_ref_name_and_item_name(item_id);
	remaining = parseInt(jQuery('#remaining_' + item_id).val());
	quantity = jQuery('#quantity_' + item_id).val();
	shipping_select = jQuery("input[name='shipping_select_" + item_id + "']:checked").val();
	json = {id: item_id, quantity: quantity};
	if (quantity == '' || isNaN(quantity)  || parseInt(quantity) < 1 || parseInt(quantity) > remaining) {
		alert('Please set quantity for shipping between 1 to ' + remaining + ' before pressing next button.');
	} else if (shipping_select == null) {
		alert('Please select deilverly option before pressing next button.');
	} else if (shipping_select == 1) {
		jQuery.get('/shop/add_one_shipping_primary', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 2) {
		jQuery.get('/shop/add_one_shipping_new_form', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 3) {
		jQuery.get('/shop/add_one_shipping_list', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow');
			});
		});
	} else if (shipping_select == 4) {
		jQuery.get('/shop/add_one_shipping_willcall', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (shipping_select == 5) {
		jQuery.get('/shop/add_one_shipping_recycle', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (shipping_select == 6) {
		jQuery.get('/shop/add_one_shipping_americas_mailer', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	} else if (shipping_select == 7) {
		jQuery.get('/shop/add_one_shipping_other_mailer', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function returnToAddOneShippingList(item_id, shipping_id, quantity) {
	json = {id: item_id, shipping_id: shipping_id, quantity: quantity};
	jQuery.get('/shop/add_one_shipping_list', json, function (xml) {
		cs = jQuery('#cart_section3_' + item_id);
		cs.slideUp('slow', function () {
			cs.html(xml).slideDown('slow');
		});
	});
}

function add_one_shipping_new_shipping_rate(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery('#shipping_id_' + item_id).val();
	quantity = jQuery('#quantity_' + item_id).val();
	reference_name = jQuery('#reference_name_' + item_id).val();
	contact_name = jQuery('#contact_name_' + item_id).val();
	ph_ac = jQuery('#ph_ac_' + item_id).val();
	ph_exc = jQuery('#ph_exc_' + item_id).val();
	ph_num = jQuery('#ph_num_' + item_id).val();
	ph_ext = jQuery('#ph_ext_' + item_id).val();
	address = jQuery('#address_' + item_id).val();
	city = jQuery('#city_' + item_id).val();
	state = jQuery('#state_' + item_id).val();
	zipcode = jQuery('#zipcode_' + item_id).val();
	json = {id: item_id, shipping_id: shipping_id, quantity: quantity, reference_name: reference_name, contact_name: contact_name, ph_ac: ph_ac, ph_exc: ph_exc, ph_num: ph_num, ph_ext: ph_ext, address: address, city: city, state: state, zipcode: zipcode}
	jQuery.get('/shop/add_one_shipping_price_list_for_new_shipping', json, function (xml) {
		cs = jQuery('#cart_section3_' + item_id);
		cs.slideUp('slow', function () {
			cs.html(xml).slideDown('slow');
		});
	});
}

function add_one_shipping_set_shipping_for_new_shipping(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_method = jQuery("input[name='shipping_method_" + item_id + "']:checked").val();
	if (shipping_method == undefined) {
		alert("Please select shipping method before pressing next button.");
	} else {
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
		price = jQuery("input[name='shipping_method_" + item_id + "']:checked").attr('price');
		json = {id: item_id, shipping_method: shipping_method, shipping_id: shipping_id, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight};
		jQuery.get('/shop/add_one_shipping_set_shipping_for_new_shipping', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function return_to_add_one_shipping_new_form(item_id, shipping_id, quantity) {
	json = {id: item_id, shipping_id: shipping_id, quantity: quantity};
	jQuery.get('/shop/return_to_add_one_shipping_new_form', json, function (xml) {
		cs = jQuery('#cart_section3_' + item_id);
		cs.slideUp('slow', function () {
			cs.html(xml).slideDown('slow');
		});
	});
}

function add_one_shipping_rate(item_id) {
	check_ref_name_and_item_name(item_id);
	shipping_id = jQuery("input[name='address_list_m_" + item_id + "']:checked").val();
	if (shipping_id == null) {
		alert('Please select an address for ship');
	} else {
		quantity = jQuery('#quantity_' + item_id).val();
		json = {id: item_id, shipping_id: shipping_id, quantity: quantity}
		jQuery.get('/shop/add_one_shipping_rate', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function add_one_shipping_add(item_id) {
	check_ref_name_and_item_name(item_id);
	checked_input = jQuery("input[name='shipping_method_" + item_id + "']:checked");
	shipping_method = checked_input.val();
	if (shipping_method == undefined) {
		alert('Please select shpping method before pressing next button.');
	} else {
		price = checked_input.attr('price');
		quantity = jQuery('#quantity_' + item_id).val();
		si_obj = jQuery('#shipping_id_' + item_id);
		shipping_id = si_obj.val();
		boxes = si_obj.attr('boxes');
		weight = si_obj.attr('weight');
		note = jQuery('#shipping_method_note_' + item_id).val();
  	json = {id: item_id, shipping_id: shipping_id, shipping_method: shipping_method, price: price, note: note, quantity: quantity, boxes: boxes, weight: weight}
		jQuery.get('/shop/add_one_shipping_add', json, function (xml) {
			cs = jQuery('#cart_section3_' + item_id);
			cs.slideUp('slow', function () {
				cs.html(xml).slideDown('slow', function () {
					change_price_display_for_cart();
				});
			});
		});
	}
}

function setItemNumber() {
	num1 = 1;
	num2 = 1;
	jQuery(".item_number").each(function () {
		jQuery(this).text(num1);
		num1++;
	});

	jQuery(".item_number_top").each(function () {
		jQuery(this).text(num2);
		num2++;
	});
}

function all_item_name_check(order_id) {
		var out = false;
		jQuery.ajax({
			async: false,
			type: 'GET',
			url: '/shop/all_item_name_check/' + order_id,
			success: function (xml) {
				if (xml == 'true') {
					out = true;
				} else if (xml != 'false') {
					alert('Please name the job item ' + xml + ' before checkout.');
				}
			}
		});
	return out;
}

function checkReferenceNameAndItemName(item_id) {
	jQuery.get('/shop/check_reference_name_and_item_name', {id: item_id}, function (text) {
		if (text != '') alert(text);
	});
}

function check_ref_name_and_item_name(item_id) {
	ref_name = jQuery('#order_name_text').val();
	item_name = jQuery('#item_name_text_' + item_id).val();

	if (ref_name != undefined && ref_name != '') {
		div = jQuery('#order_name_submit_div');
		button = div.html();
		div.html('<img src="/images/indicator.gif">');
		jQuery.get('/shop/save_order_name_by_item_id/', {id: item_id, value: ref_name}, function (data) {
			jQuery('#order_name_submit_span').html(data);
			jQuery('.current-cart-reference').text(order_name);
		});
	}

	if (item_name != undefined && item_name != 'Name JOB ITEMS the same as the FILENAME') {
		setItemName(item_id);
	}
}



