function SaveOrder(type)
{
	
	var total = parseFloat($("#sys_carttotal").html());
	var deliverynames = new Array();
	var deliveryvalues = new Array();
	var errors = new Array();
	var paymentmethod = $("input[name=sys_paymethod]:checked").val();
	var textalert;
	
	$("#sys_deliverydetails input, #sys_deliverydetails select, #sys_deliverydetails textarea").each(function(){
		deliverynames.push($(this).attr('name'));
		deliveryvalues.push($(this).val());
		if ($(this).attr('rel') == "required" && $(this).val() == ""){
			errors.push($(this).attr('name'));
		}
	});
	if ($("input[name=sys_textalert]").length > 0){
		textalert = $("input[name=sys_textalert]").val();
		if (textalert != ""){
			textalert = textalert.replace(/\D/g, '');
			if (textalert[0] == "3"){
				textalert = textalert.substr(3);
			}
			if (textalert[0] == "0"){
				textalert = textalert.substr(1);
			}
			if (textalert.length != 9 || textalert[0] != "8"){
				errors.push("Incorrect Mobile Phone Number.  This system only accepts ROI mobile numbers");
			}	
		}
	}
	var name = $(".sys_custname").val();
	var email = $(".sys_custemail").val();
	var address= new Array();
	$(".sys_custaddress").each(function(){
		address.push($(this).val());
	});
	address = serialize(address);

	if (total < 0.01){
		errors.push('Your cart may be empty or equal to 0');
	}	
	
	if (errors.length > 0){
		msguser('There are problems with your order:<br /><br />'+errors.join("<br />"));
		return;
	}
	else 
	{
		deliverynames = serialize(deliverynames);
		deliveryvalues = serialize(deliveryvalues);
		
		$.post(root+"scripts/php/saveorder.php", {deliverynames: deliverynames, deliveryvalues: deliveryvalues, total: total, method: paymentmethod, status: 'Incomplete', name: name, email: email, address: address}, function(data){
			data = data.split("|");
			if (data[0] == 1){
				$("#sys_paypalFormOrderId").val(data[1]);
				$("#sys_paypalFormAmount").val(total);
				if(type=="phone"){ 
				msguser("<h5>To complete the order over the phone with your Laser or Credit Card, please call us at:</h5><br><h2>087 614 8090</h2><br><h5>Please remember that:<br>- Order will not be processed until payment has been received<br>- Note for delivery - only items under 5 kg will be posted.<br>- Large clearance items must be collect by client<br><br>Thank you for your order.</h5>"); 
				}
				if(type=="cheque"){ 
				msguser("<h5>To complete the order, please send the cheque to: <br><br>Jenny Hamilton<br>Regans Business Park<br> Drum Road, Rathcormac<br>Sligo, Ireland<br><br>Please remember that:<br>- Cheque needs a 6 days wait to clear<br>- Order will not be processed until payment has been received<br>- Note for delivery - only items under 5 kg will be posted.<br>- Large clearance items must be collect by client<br><br>Thank you for your order.</h5>");
				}
			}
			else {
				msguser(data[1]);
				return;
			}
		});
	}
}
