var utilitySelected = 0;
var imgArray = ["other/None.gif",
				"Image-to-PDF-Desktop-Application-Buy-Image.png", 
				"Image-to-PDF-Command-Line-Tool-Buy-Image.png", 
				"Image-to-PDF-Dynamic-Link-Library-Buy-Image.png", 
				"PDF-Chart-Creator-Command-Line-Tool-Buy-Image.png", 
				"PDF-Chart-Creator-Dynamic-Link-Library-Buy-Image.png"
			   ];

var codeSelected = "";
var codeArray = ["",
				 "13871-1",
				 "13871-2",
				 "13871-3",
				 "13871-4",
				 "13871-5"
				]

var versionArray = ["",
					"2.01",
					"2.52",
					"2.52",
					"1.34",
					"1.2"
				]

var licenseSelected = 0;
var licArray = [new Array("",					"",							""),
				new Array("Per Workstation",	"Per Server",				"Per Site"),
				new Array("Per Workstation",	"Per Server",				"Unlimited/Internet"),
				new Array("Per Product",		"Unlimited Development",	""),
				new Array("Per Workstation",	"Per Server",				"Unlimited/Internet"),
				new Array("Per Product",		"Unlimited Development",	"")
			   ];

var priceSelected = "";
var priceArray = [new Array("",					"",							""),
				  new Array("29.99",			"99.99",					"249.99"),
				  new Array("29.99",			"99.99",					"249.99"),
				  new Array("99.99",			"249.99",					""),
				  new Array("14.99",			"59.99",					"249.99"),
				  new Array("59.99",			"249.99",					"")
			     ];

var quantitySelected = 0;
var quantityArray = [new Array(0,				0,							0),
					 new Array(5,				5,							1),
					 new Array(5,				5,							1),
					 new Array(5,				1,							0),
					 new Array(5,				5,							1),
					 new Array(5,				1,							0)
					];

function ChangeUtility(opt)
{
	var img = document.getElementById("UW-IMG");
	utilitySelected = opt.selectedIndex;
	img.src = imgArray[utilitySelected];
	if (utilitySelected == 1)
		img.height = 80;
	else
		img.height = 58;
	codeSelected = codeArray[utilitySelected];
	
	// maintain version
	document.getElementById("UW-VERSION").firstChild.nodeValue = versionArray[utilitySelected];

	// maintain licenses
	var opts = licArray[utilitySelected];
	var lic = document.getElementById("UW-LIC");
	var i;
	licenseSelected = 0;
	lic.selectedIndex = licenseSelected;
	for (i = 1; i < lic.length; i++)
		lic.options[i].text = opts[i - 1];

	// maintain price
	priceSelected = "";
	document.getElementById("UW-PRICE").firstChild.nodeValue = priceSelected;

	// maintain quantities
	quantitySelected = 0;
	var qty = document.getElementById("UW-QTY");
	qty.selectedIndex = 0
	for (i = 1; i < qty.options.length; i++)
		qty.options[i].text = "";
}

function ChangeLicense(opt)
{
	if (utilitySelected == 0)
	{
		priceSelected = "";
		opt.selectedIndex = 0;	
		alert("Please select a utility");
	}
	else
	{
		licenseSelected = opt.selectedIndex;
		var opts = priceArray[utilitySelected];
		if (licenseSelected == 0)
		{
			priceSelected = "";
			document.getElementById("UW-PRICE").firstChild.nodeValue = "";
			licenseSelected = 0;
			opt.selectedIndex = 0;

			var qty = document.getElementById("UW-QTY");
			qty.selectedIndex = 0
			for (i = 1; i < qty.options.length; i++)
				qty.options[i].text = "";

			alert("Please select a license type");
		}
		else
		{
			priceSelected = opts[licenseSelected - 1];
			document.getElementById("UW-PRICE").firstChild.nodeValue = "$" + priceSelected;
			
			// maintain quantities
			var qty = document.getElementById("UW-QTY");
			qty.selectedIndex = 0;
			opts = quantityArray[utilitySelected];
			for (i = 1; i < qty.options.length; i++)
			{
				if ((licenseSelected > 0) && (i <= opts[licenseSelected - 1]))
					qty.options[i].text = i;
				else
					qty.options[i].text = "";
			}
		}
	}
}

function ChangeUtilityQuantity(quantityOpt)
{
	if (utilitySelected == 0)
	{
	    quantityOpt.selectedIndex = 0;	
		quantitySelected = 0;
		alert("Please select a utility");
	}
	else if (licenseSelected == 0)
	{
	    quantityOpt.selectedIndex = 0;	
		quantitySelected = 0;
		alert("Please select a license type");
	}
	else if (quantityOpt.options[quantityOpt.selectedIndex].text == "")
	{
	    quantityOpt.selectedIndex = 0;	
		quantitySelected = 0;
		document.getElementById("UW-TOTAL").firstChild.nodeValue = "";
		alert("Please select a quantity");
	}
	else
	{
	    quantitySelected = quantityOpt.selectedIndex;
		document.getElementById("UW-TOTAL").firstChild.nodeValue = "$" + (quantitySelected * parseFloat(priceSelected));
	}
}

function BuyNow()
{
	if (utilitySelected == 0)
		alert("Please select a utility");
	else if (licenseSelected == 0)
		alert("Please select a license type");
	else if (quantitySelected == 0)
		alert("Please select a quantity");
	else
	{
		document.getElementById("pleasewait").style.visibility = "visible";
		setTimeout("RegNow()",100);
	}
	return false;
}

function RegNow()
{
	document.location = "https://www.regnow.com/softsell/nph-softsell.cgi?action=add_to_cart&items=" + codeSelected + "&quantity=" + quantitySelected + "&ordertype=" + document.getElementById("UW-LIC").options[licenseSelected].text;
}

function Terms(url, width, height, scrollbars)
{
	window.open(url, "_blank", "width=" + width + ",height=" + height + ",titlebar=yes,toolbar=no,directories=no,location=no,menubar=no,resizable=yes,scrollbars=" + scrollbars + ",status=no,fullscreen=no,channelmode=no");
}
