function doVoucher()
{
	document.sProcessor = "./custom/voucherInterface.php";
	http.open("POST", "./custom/voucherInterface.php?action=doVoucher", true);
	http.onreadystatechange = viewProcessor;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http.send(null);
}

function continueVoucher(sFormId)
{
	document.sProcessor = "./custom/voucherInterface.php";
	http.open("POST", "./custom/voucherInterface.php?action=continueVoucher", true);
	http.onreadystatechange = viewProcessor;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	sFormData = null;
	if(sFormId != null)
		sFormData = encodeForm(sFormId);
	http.send(sFormData);
}

function prevVoucherStep()
{
	http.open("POST", "./custom/voucherInterface.php?action=prevVoucher", true);
	http.onreadystatechange = viewProcessor;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(null);
}

function skipVoucher()
{
	if(document.checkingVoucher)
	{
		setTimeout("skipVoucher()",100);
		return;
	}
	document.sProcessor = "./custom/cartInterface.php";
	http.open("POST", "./custom/cartInterface.php?action=skipVoucher", true);
	http.onreadystatechange = viewProcessor;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(null);
}


function processVoucherPayment()
{
	changeElement('siteProcessor', "<div class=\"userForm\">Please wait while we process your payment. This could take a few moments to complete.</div>");

	http.open("POST", "./custom/voucherInterface.php?action=processVoucherPayment", true);
	http.onreadystatechange = viewProcessor;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http.send(null);
}

function toggleVoucherForm()
{
	showElement('voucherDetailsForm');
	changeElement('btnSkip','Skip <img src=\'images/layout/arrow.jpg\'/>');
	hideElement('btnYes');
}

function checkVoucher(sFormId)
{
	if(getElementValue('Serial_Number').length < 1 || getElementValue('Redemption_Code').length < 1)
		return;

	document.checkingVoucher = true;

	http.open("POST", "./custom/voucherInterface.php?action=checkVoucher", true);
	http.onreadystatechange = updateVoucherFields;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	sFormData = null;
	if(sFormId != null)
		sFormData = encodeForm(sFormId);
	http.send(sFormData);
}

function updateVoucherFields()
{
	if(http.readyState == 4 && http.status == 200)
	{
		document.checkingVoucher = false;
		if(http.responseXML != null)
		{
			xmlData = http.responseXML.documentElement;
			eNode = xmlData.firstChild;

			fTotal = parseInt(getElementValue('Total_Due').slice(1));
			fBalance = xmlData.getElementsByTagName('balance')[0] != null?xmlData.getElementsByTagName('balance')[0].getAttribute('value'):"";
			sError = xmlData.getElementsByTagName('error')[0] != null?xmlData.getElementsByTagName('error')[0].getAttribute('value'):"";

			changeElement("errorMsg", sError);
			setElementValue("Balance_Available",fBalance);

			if(sError.length)
				setElementValue("Amount_to_Redeem","");
			else
			{
				if(fBalance < fTotal)
					setElementValue("Amount_to_Redeem",fBalance);
				else
					setElementValue("Amount_to_Redeem",fTotal);
			}
		}
	}
}
