<!-- hide from JavaScript-challenged browsers
var g_FormOk = true;

function calcAmt()
{
	// validate quantity field
	if (((!isPositiveInteger(document.PREORDERFORM.QuantityVax.value) && 
		  !isPositiveInteger(document.PREORDERFORM.QuantityVaxRenew.value)) || 
		 (document.PREORDERFORM.QuantityVax.value == 0 && 
		  document.PREORDERFORM.QuantityVaxRenew.value == 0)) &&
		(!document.PREORDERFORM.VaxPersonal || !document.PREORDERFORM.VaxPersonal.checked))
	{
		document.PREORDERFORM.QuantityVax.focus();
		if (document.PREORDERFORM.VaxPersonal)
			alert("Please enter a valid order quantity or click Personal license.");
		else
			alert("Please enter a valid order quantity.");
		g_FormOk = false;
		return false;
	}
	return true;
}

function IsOKtoPost()
{
	// save status before reset
	var retval = g_FormOk;
	// reset status for the next invocation
	g_FormOk = true;
	// return old status
	return retval;
}

function isPositiveInteger(s)
{
	var i;
	if ((s == null) || (s.length == 0)) 
		return false;
	
	// Search through string's characters one by one
	// until we find a non-numeric character.
	// When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
	{   
	    // Check that current character is number.
	    var c = s.charAt(i);
	    if (!(c >= "0" && c <= "9"))
	    	return false;
	}
	// All characters are numbers.
	return true;
}

// VA will call this URL with product and quantity params if the user chooses
// to buy a license or a renewal from the Buy/Try dialog.
function parseArgs()
{
	var anonymousArgs = new Array();
	var ref = window.location.href;
	// strip everything up to and including the '?'
	var pos = ref.search("[?]");
	if (pos != -1)
	{
		ref = ref.substring(pos + 1, ref.length);
		var pairs = ref.split("&");
		var idx;
		var qty = 0;
		var product = "default";
		for (idx = 0; idx < pairs.length; ++idx)
		{
			var curSet = pairs[idx].split("=");
			if (curSet.length == 2)
			{
				if (curSet[0] == "product")
				{
					product = curSet[1];
				}
				else if (curSet[0] == "quantity")
				{
					qty = curSet[1];
				}
				else if (curSet[0] == "payment")
				{
					parseArgPayment(curSet[1]);
				}
				else
				{
					// handle Anonymous Args
					var anonymousArg = 
					{
						name: curSet[0],
						value: curSet[1]
					};
					anonymousArgs[anonymousArgs.length] = anonymousArg;
				}
			}
		}

		if (qty < 1)
			qty = 1;
		parseArgProduct(product, qty);
	}

	if (anonymousArgs.length)
	{
		var str = "";
		var i;
		for (i = 0; i < anonymousArgs.length; i++)
		{
			var tmpStr;
			tmpStr = '<input type="hidden" name="' 
				+ anonymousArgs[i].name
				+ '" value="'
				+ anonymousArgs[i].value
				+ '">';
			str += tmpStr;
		}
		var extraArgsDiv = document.getElementById("extraArgs");
		extraArgsDiv.innerHTML = str;
	}

	return true;
}

function parseArgPayment(p)
{
	if (p == "cc")
	{
		document.PREORDERFORM.payType[0].click();
	}
	else if (p == "paypal")
	{
		document.PREORDERFORM.payType[1].click();
	}
}

function parseArgProduct(p, q)
{
	if (p == "vaxrenew" || p == "vaxrenewal")
	{
		document.PREORDERFORM.QuantityVax.value = 0;
		document.PREORDERFORM.QuantityVaxRenew.value = q; 
	}
	else
	{
		// default selection - vax
		document.PREORDERFORM.QuantityVax.value = q;
		document.PREORDERFORM.QuantityVaxRenew.value = 0;
	}
}
// done hiding -->
