﻿$(document).ready(function(){
	
	var options = { 
			dataType:  'json',
			beforeSubmit: validate, 
			success:    processJson
	};
	$('#editVoucherForm').ajaxForm(options);
	
	function validate(formData, jqForm, options) { 	

		
		$('#note-code').hide();
		
		var msgError = false
		
		var form = jqForm[0];
		
		if (!form.code.value) {
			$('#note-code').removeClass();
			$('#note-code').addClass('form-error');
			$('#note-code').text('优惠券代码不能为空！');
			$('#note-code').show();
			msgError = true; 
		}

		if (msgError == true)
			return false;
			
	}
		
	function processJson(data) {
		
		if (data.success=="true"){
			window.location= 'shoppingcart_first.php';
				//$('#note-code').removeClass();
				//$('#note-code').addClass('form-success');
				//$('#note-code').text(data.message);
				//$('#note-code').show();
		}
		else{
			if (data.message!=null){
				$('#note-code').removeClass();
				$('#note-code').addClass('form-error');
				$('#note-code').text(data.message);
				$('#note-code').show();
			}
		}
		return true;
	}
	
});

function ShoppingCart_AddItemToTemporaryShelf(product_id,license_id){
	$.ajax({
		url: 'ShoppingCart_AddItemToTemporaryShelf.php',
		type:'GET',
		data:{product_id:product_id,license_id:license_id},
		dataType:'json',
		success:function(data)
		{
			alert (data.result);
		}
	});
}
