// JavaScript Document

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function applyRadiusSettings(tl, tr, bl, br) {
	var settings = {
	  tl: { radius: tl },
	  tr: { radius: tr },
	  bl: { radius: bl },
	  br: { radius: br },
	  antiAlias: true
	}
	return settings;
}



function updateComissionFee(return_amount_or_message) {
	var wholesale_price = document.getElementById('wholesalePrice').value;
	var retail_price = document.getElementById('recommendedPrice').value;
	var commission_fee;
	var message;
	
	if(document.getElementById('commissionBy').value=="wholesale") {
		commission_fee = wholesale_price*0.15;
		commission_fee = commission_fee.toFixed(2);
			message = 'You are about to be charged a commission fee of $'+commission_fee+' (15% of your specified wholesale price of $'+wholesale_price+').<br /><br />This will be automatically charged to your Atuthentic Greenstone account when you click \'OK\'.<br /><br />Otherwise click \'Cancel\'.';
	} 
	if(document.getElementById('commissionBy').value=="retail") {
		commission_fee = retail_price*0.075;
		commission_fee = commission_fee.toFixed(2);
			message = 'You are about to be charged a commission fee of $'+commission_fee+' <br />(7.5% of your specified recommended retail price of $'+retail_price+').<br /><br />This will be automatically charged to your Atuthentic Greenstone account when you click \'OK\'.<br /><br />Otherwise click \'Cancel\'.';
	}
	if(return_amount_or_message!=null) {return commission_fee; } else {return message;}
}



function submitUploadImage(upload_max) {
	var image_rows = $("#image_row_counter").val();
	if(image_rows >= upload_max ) {
		$("#upload_maxed").css("display","");
		$("#reset_button").click();
		return false;
	}		
	$("#upload_maxed").css("display","none");
	$("#file_type_error").css("display","none");
	$("#upload_error").css("display","none");
	$("#status").css("display","");
	$("#uploadfile_form").submit();
	$("label.error").css("display","none");
}

function checkMainImage(type, objectId) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;}
	
	var url="AJAX_actions.php?action=check_main_image";
	url=url+"&type="+type;
	url=url+"&objectId="+objectId;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() { // is main image set for this object? true = yes it is, false = no it's not...
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert("wtf "+xmlhttp.responseText);
			if(xmlhttp.responseText != '' && xmlhttp.responseText != 0) { $("#main_image_id_"+xmlhttp.responseText).click(); }
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
}

function deleteImage(image_row_id, image_id, type/*product or stone or user*/) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	 
	var url="upload_image.php?action=delete_image";
	url=url+"&imageId="+image_id;
	url=url+"&type="+type;
	url=url+"&sid="+Math.random();
	
	//alert(url);
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert(xmlhttp.responseText);
			var tr_to_be_removed = 'uploaded_images_row_'+image_row_id;
			$("#"+tr_to_be_removed).remove();
			
			// -1 from image row counter...
			var image_rows = $("#image_row_counter").val(); image_rows = parseInt(image_rows); image_rows--; $("#image_row_counter").val(image_rows);$("#upload_maxed").css("display","none");
			
			var elements_by_class = getElementsByClass("main_image");
			var new_main_checked = false;
			var class_id;
			if(elements_by_class.length!=0) {
				//alert(elements_by_class.length); 
				for(i=0; i<elements_by_class.length; i++) { // first check to see that another main image is not already chosen...
					class_id = elements_by_class[i].id;
					if($("#"+class_id).attr('checked')) {
						new_main_checked = true; 
						//alert('another main image is already chosen...'); 
					}
				}
				for(i=0; i<elements_by_class.length; i++) {
					class_id = elements_by_class[i].id;
					if(new_main_checked!=true) { // check if process is already complete...
						if(xmlhttp.responseText!='done') { // this means a new main image has been passed...
							var string_break_down = class_id.split("id_");
							var image_id = string_break_down[1];
							if(image_id==xmlhttp.responseText) {
								$("#"+class_id).click();
								new_main_checked = true;
								//alert('a new main image has been passed...'); 
							}
						}
						else { // just check the first one...
							$("#"+class_id).click();
							new_main_checked = true;
							//alert('just check the first one...'); 
						}
					}
				}
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function GetXmlHttpObject()
	{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

function updateShippingCost(total_cost, total_weight) {
	if($('#pickup').is(':checked')){
		$('#shipping_cost').text(0.00);
		total_cost = parseFloat(total_cost).toFixed(2);
		$('#total_cost').text(total_cost);
		$('#Amount').attr('value', total_cost);
	} else{
		var deliveryArea = $('#deliveryArea').attr('value');
		//alert(deliveryArea);	
		var xmlhttp;
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null){
		  alert ("Your browser does not support XMLHTTP!");
		  return;
		} 
		var url="get_shipping_cost.php?action='update_shipping_cost'";
		url=url+"&areaId="+deliveryArea;
		url=url+"&weight="+total_weight;
		//url=url+"&total_cost="+total_cost;
		url=url+"&sid="+Math.random();
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
				//alert (xmlhttp.responseText);
				var amount = parseFloat(xmlhttp.responseText); 
				//alert ('total_cost = '+total_cost);
				total_cost = parseFloat(total_cost);  total_cost = total_cost+amount; 
				total_cost = total_cost.toFixed(2);
				amount = amount.toFixed(2);
				//alert ('shipping = '+amount);
				//alert ('new_total_cost = '+total_cost);
				//profits.toFixed(2)
				$('#shipping_cost').text(amount);
				$('#total_cost').text(total_cost);
				$('#Amount').attr('value', total_cost);
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);	
	}
}


function add_remove_from_cart(id, lightbox) {
	//alert('hi');
	var action = 'not set';
	var classes = $('.lightbox_addToCart_button_inner_'+id);
	if(classes.length==0) {button_val=='In Cart';} else {var button_val = trim(classes[0].innerHTML);}
	//alert(button_val); return;
	if(button_val=='Add to Cart') {action = 'add_to_cart';} else {action = 'remove_from_cart';}
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert(action);
	var url="add_to_cart_AJAX.php?action="+action;
	url=url+"&id="+id;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			if(xmlhttp.responseText=='done') {
				if(action=='add_to_cart') {
					if(lightbox) {
						var html = '<div class="lightbox_addToCart_button_inner lightbox_addToCart_button_inner_'+id+'">In Cart</div><div class="cart_widget_remove_button lightbox_remove_button  button2"></div>';
					} else {
						var html = '<div class="lightbox_addToCart_button_inner lightbox_addToCart_button_inner_'+id+'">In Cart</div><div class="cart_widget_remove_button lightbox_remove_button  button2"></div>';
					}
				}else{
					if(lightbox) {
						var html = '<div class="lightbox_addToCart_button_inner lightbox_addToCart_button_inner_'+id+'">Add to Cart</div>';
					} else {
						var html = '<div class="lightbox_addToCart_button_inner lightbox_addToCart_button_inner_'+id+'">Add to Cart</div>';
					}
				}
				$('.lightbox_addToCart_button_'+id).html(html);
				if(lightbox) {
					//var show_again = true;
					//if ( jQueryMatchedObj.length == 1 ) {var show_again = false;}
					$('#jquery-lightbox').remove();
					$('#jquery-overlay').remove();
					//if(show_again) {$('#light_box_link_'+id).click();}
					$('#light_box_link_'+id).click();
				}
				updateCart();
			} else {alert('error adding to cart');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function updateWpCart(action, id) {
	var url = "/AJAX_actions.php?action=" + action + "&id=" + id;
	if ( action == "add_wp_to_cart" ) {
		url = url + "&quantity=" + $( "#quantity_" + id ).val();
	}
	url = url + "&sid=" + Math.random();
	
	$.ajax({
		url: url,
		success: function () {
			getWPCart();
			getWPCheckout();
		}
	});
}

function getWPCart() {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert('hi');
	var url="get_cart_content_AJAX.php";
	url=url+"?sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert('hi '+xmlhttp.responseText);
			$("#wp_cart").html(xmlhttp.responseText);
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function drawTabAngles(class_name, color){
	
	//break;
	var classes = getElementsByClass(class_name);
	//alert(classes.length); 
	var canvas;
	//var canvas = document.getElementById(id_tag);
	for(i=0; i<classes.length; i++) {
		canvas = classes[i];
		//alert(classes[i].id); break;
		if (canvas.getContext){
			//alert(classes[i].id); break;
			var ctx = canvas.getContext("2d");
			ctx.fillStyle = color;  
			ctx.beginPath();
			//ctx.moveTo(x, y);
			ctx.moveTo(8,9);
			ctx.lineTo(0,30);
			ctx.lineTo(8,30);	
			ctx.fill();
			//alert('done'); break;
		} else {//alert('fail'); break;
		}
	}
}

					
function updateCart() {
	//alert('hi');
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
		
	var url="get_cart_content_AJAX.php?sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			if(xmlhttp.responseText!='error') {
				$('#sidebar_cart_table').html(xmlhttp.responseText);
			} else {alert('error updating to cart');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function updateCartContents() {
	//alert('hi');
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
		
	var url="cart_page_contents_AJAX.php?sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			if(xmlhttp.responseText!='error') {
				$('#cart_page_contents').html(xmlhttp.responseText);
			} else {alert('error updating to cart');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function updateStoneActiveStatus(id) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert($('#stone_active_status_'+id+':checked').length); return;
	if($('#stone_active_status_'+id).attr('checked')) {var active = 1;} else {var active = 0;}
	var url="update_stone_active_status_AJAX.php?sid="+Math.random();
	url += "&active="+active;
	url += "&id="+id;
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert(xmlhttp.responseText);
			if(xmlhttp.responseText!='done') {alert(xmlhttp.responseText);}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function updateBarcodeBatchSentStatus(alph_value, user_id) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert($('#stone_active_status_'+id+':checked').length); return;
	if($('#barcode_batch_sent_status_'+alph_value+'_'+user_id).attr('checked')) {var sent = 1;} else {var sent = 0;}
	var url="save_field_AJAX.php?sid="+Math.random();
	url += "&fieldName=barcodeBatchSentStatus";	
	url += "&sent="+sent;
	url += "&alph_value="+alph_value;
	url += "&user_id="+user_id;
	//alert(url); return;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert(xmlhttp.responseText);
			if(xmlhttp.responseText!='done') {alert(xmlhttp.responseText);}
			else {
				if($('#barcode_batch_sent_status_'+alph_value+'_'+user_id).attr('checked')) {
					$('#needs_to_be_sent_row_'+alph_value+'_'+user_id).css('color','#999');
					$('#barcode_batch_sent_status_'+alph_value+'_'+user_id).attr('disabled','disabled');
					$('#barcode_batch_sent_save_'+alph_value+'_'+user_id).attr('disabled','disabled');
						
				}
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}



function updateBarcodeBatchPrintedStatus(alph_value) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert($('#stone_active_status_'+id+':checked').length); return;
	if($('#barcode_batch_printed_status_'+alph_value).attr('checked')) {var printed = 1;} else {var printed = 0;}
	var url="save_field_AJAX.php?sid="+Math.random();
	url += "&fieldName=barcodeBatchPrintedStatus";
	url += "&printed="+printed;
	url += "&alph_value="+alph_value;
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert(xmlhttp.responseText);
			if(xmlhttp.responseText!='done') {alert(xmlhttp.responseText);}
			else { 
				if($('#barcode_batch_printed_status_'+alph_value).attr('checked')) { $('#barcode_batch_printed_status_cell_'+alph_value).css("background-color","white"); }
				else { $('#barcode_batch_printed_status_cell_'+alph_value).css("background-color","orange"); }
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}






function remove_from_cart(id, lightbox) {
	//alert('hi');
	var action = 'not set';
	var classes = $('.lightbox_addToCart_button_'+id);
	if(classes.length==0) {button_val=='In Cart';} else {var button_val = trim(classes[0].innerHTML);}
	//alert(button_val); return;
	if(button_val=='Add to Cart') {action = 'add_to_cart';} else {action = 'remove_from_cart';}
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	//alert(action);
	var url="add_to_cart_AJAX.php?action="+action;
	url=url+"&id="+id;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			if(xmlhttp.responseText=='done') {
				if(lightbox) {
					//var show_again = true;
					//if ( jQueryMatchedObj.length == 1 ) {var show_again = false;}
					$('#jquery-lightbox').remove();
					$('#jquery-overlay').remove();
					//if(show_again) {$('#light_box_link_'+id).click();}
					//$('#light_box_link_'+id).click();
				}
				updateCartContents(); 
				//$('#stone_shop_plate_'+id).remove();
				//updateCart();
			} else {alert('error adding to cart');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function showArtisan(id) {
	//alert(id);
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	
	var url="get_licensed_artisan.php?id="+id;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				$('.licensed_artisan').css('background-image', '');
				$('.licensed_artisan').css('color', '#999');
				$('#artisan_details_window').html(xmlhttp.responseText);
				$('#licensed_artisan_'+id).css('background-image', 'url(/assets/images/artisan_arrow_active.gif)');
				$('#licensed_artisan_'+id).css('color', '#7BA039');
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function updateDisplay(url) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				$('#display_window').html(xmlhttp.responseText);
				$('.display_menu ul li').removeClass('loading');
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function updateSelectedWorks(featured_work_num, user_id, product_id) {
	//alert(product_id);
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	
	var url="update_featured_works_AJAX.php?featured_work_num="+featured_work_num;
	url=url+"&user_id="+user_id;
	url=url+"&product_id="+product_id;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
				if(xmlhttp.responseText!='') {
					$('#featured_work_image_'+featured_work_num).html(xmlhttp.responseText);
					if(product_id==0) {
						$('#featured_work_buttons_select_'+featured_work_num).css('display', 'block');
						$('#featured_work_buttons_change_delete_'+featured_work_num).css('display', 'none');
					} else {
						$('#featured_work_buttons_select_'+featured_work_num).css('display', 'none');
						$('#featured_work_buttons_change_delete_'+featured_work_num).css('display', 'block');
					}
				} else {alert('error');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function saveField(fieldName) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	var value = $('#'+fieldName).attr('value').replace(/\n/g,"~~~~");
	
	var url="save_field_AJAX.php?fieldName="+fieldName;
	url=url+"&value="+value;
	//url=url+"&product_id="+product_id;
	url=url+"&sid="+Math.random();
	//alert(fieldName + ' ' + value + ' ' + url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
				//if(xmlhttp.responseText!='') {alert('done');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function saveMainImage(type, objectId, imageId) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	
	var fieldName = 'mainImage';
	
	var url="save_field_AJAX.php?fieldName="+fieldName;
	url=url+"&type="+type;
	url=url+"&objectId="+objectId;
	url=url+"&imageId="+imageId;
	url=url+"&sid="+Math.random();
	
	//alert(url);
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
				//if(xmlhttp.responseText!='') {alert('done');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function showBarcodesSubTable(alph_value) {
	$('body').css('cursor','wait');
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	
	var url="AJAX_actions.php?action=populate_barcode_sub_table";
	url=url+"&alph_value="+alph_value;
	url=url+"&sid="+Math.random();
	
	if($('#barcodes_show_link_'+alph_value).text() == 'show') {
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
					$('#barcodes_sub_table_td_div_'+alph_value).html(xmlhttp.responseText);
					$('#barcodes_sub_table_td_'+alph_value).slideDown();
					$('#barcodes_show_link_'+alph_value).text('hide');
					$('body').css('cursor','default');
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	} else {
		$('#barcodes_sub_table_td_div_'+alph_value).html('');
		//$('#barcodes_sub_table_td_'+alph_value).slideUp();
		$('#barcodes_show_link_'+alph_value).text('show');
		$('body').css('cursor','default');
	}
}

function saveRequestByDate(id) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	var value = $('#datepicker_'+id).attr('value');
	
	var url="save_field_AJAX.php?fieldName=requestByDate";
	url=url+"&value="+value;
	url=url+"&id="+id;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
				//if(xmlhttp.responseText!='') {alert('done');}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function saveWPQuantity(id) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	var value = $('#quantity_'+id).attr('value');
	
	var url="save_field_AJAX.php?fieldName=wp_quantity";
	url=url+"&value="+value;
	url=url+"&id="+id;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function saveWPQuantity(id) {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	var value = $('#quantity_'+id).attr('value');
	
	var url="save_field_AJAX.php?fieldName=wp_quantity";
	url=url+"&value="+value;
	url=url+"&id="+id;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 		
				//alert(xmlhttp.responseText);
				getWPCheckout();
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function getWPCheckout() {
	var xmlhttp;xmlhttp=GetXmlHttpObject();if(xmlhttp==null){alert("Your browser does not support XMLHTTP!"); return;} 
	var url="get_cart_content_AJAX.php?wp_checkout=1";
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			//alert('hi '+xmlhttp.responseText);
			$("#wp_checkout_list").html(xmlhttp.responseText);
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
