function validate_coupon(formname, company_id) {
	//Using ajax to get the information from system
	var frm = document.forms[formname];
	var code = frm.coupon_code.value;
	if(code.length>0) check_coupon_ajax(formname, company_id, code);
	else {
		alert(lbl[34786]/*Please enter coupon code before clicking GO button*/);
		return false;
	}
}

function check_coupon_usage(formname, valid_code) {
	//  0 => invalid code, 1=> not authorized to use, 2=> date range out of valid, 3=> exceed max use, 99=> success
	switch(valid_code) {
		case '0':
			alert(lbl[34787]/*Error: Coupon code entered is not valid, please enter another coupon code*/);
			return false;
		break;    
		case '1':
			alert(lbl[34788]/*Error: You are not authorized to use this coupon*/);
			return false;
		break;
		case '2':
			alert(lbl[34789]/*Error: Coupon Expired*/);
			return false;
		break;
		case '3':
			alert(lbl[34790]/*Error: Coupon code entered reached it maximum usage limit*/);
			return false;
		break;
		case '4':
			alert(lbl[34791]/*Error: Product quantity did not reach coupon required minumum quantity*/);
			return false;
		break;
		case '5':
			alert(lbl[34792]/*Error: Please login before using coupon code*/);
			return false;
		break;
		case '6':
			alert(lbl[34793]/*Warning: Order Discount has higher priority than Coupon Order Discount, the coupon code entered is not applicable to this shopping cart*/);
			return false;
		break;
		case '99': {
			var frm = document.forms[formname];
			frm.action='commerce.html?submodule=cart&page=checkout';
			frm.faction.value='coupon_code_check';
			frm.submit();	
		}
		break;
	}
}

function system_redemption(formname, company_id, faction) {
	//Using ajax to do checking
	check_redemption_ajax(formname, company_id, faction);
}

function check_redemption_usage(formname, faction, valid_code, coupon_code, coupon_name) {
	//  0 => Order Coupon is not longer applicable to this shopping cart, 99=> success
	switch(valid_code) {
		case '0':
			alert(lbl[34794]/*Warning: Order Discount has hig*/+'('+coupon_code+')'+lbl[34795]/*is not applicable to this shopping cart*/);
		break;
	}
	var frm = document.forms[formname];
	frm.action='commerce.html?submodule=cart&page=shopping_cart';
	frm.faction.value=faction;
	//frm.submit();	
}

