function init()
{
}


/////////////////////////////////////////////////////////////
function showSupportHelp()
/////////////////////////////////////////////////////////////
{
	dbNetPage.openDialog("/shared/support_info.aspx", "support", null , true, 'status=yes;help=no;resizable=yes')
}

/////////////////////////////////////////////////////////////
function showVersionHelp()
/////////////////////////////////////////////////////////////
{
	dbNetPage.openDialog("/shared/version_info.aspx", "version", null , true, 'status=yes;help=no;resizable=yes')

}

/////////////////////////////////////////////////////////////
function removeFromCart(cpid)
/////////////////////////////////////////////////////////////
{
	var xml = 
		"<root>" +
		buildNode("cpid", cpid) + "</root>"

	if (XmlServer.call(xml, "remove"))
		refreshCartDisplay()
}

/////////////////////////////////////////////////////////////
function changeQuantity(event, cpid)
/////////////////////////////////////////////////////////////
{
	var srcElement = dbNetPage.getEventSrcElement(event)
	var xml = 
		"<root>" +
		buildNode("cpid", cpid) + 
		buildNode("quantity", srcElement.value )  + 
		"</root>"

	if (XmlServer.call(xml, "quantity"))
		refreshCartDisplay()
}

/////////////////////////////////////////////////////////////
function changeVersion(event, cpid)
/////////////////////////////////////////////////////////////
{
	var srcElement = dbNetPage.getEventSrcElement(event)
	var xml = 
		"<root>" +
		buildNode("cpid", cpid) + 
		buildNode("version", srcElement.value )  + 
		"</root>"

	if (XmlServer.call(xml, "version"))
		refreshCartDisplay()
}

/////////////////////////////////////////////////////////////
function changeSupport(event, cpid)
/////////////////////////////////////////////////////////////
{
	var srcElement = dbNetPage.getEventSrcElement(event)
	var xml = 
		"<root>" +
		buildNode("cpid", cpid) + 
		buildNode("product", srcElement.value )  + 
		"</root>"

	if (XmlServer.call(xml, "support"))
		refreshCartDisplay()
}

/////////////////////////////////////////////////////////////
function processPromo()
/////////////////////////////////////////////////////////////
{
	var promoCode = document.getElementById("promoCode").value
	var xml = "<root>" + buildNode("promoCode",promoCode) + "</root>"
	if (XmlServer.call(xml, "promotion"))
	{
		if (XmlServer.getNodeValue("status") == "ok")
			refreshCartDisplay()
		else
			alert(XmlServer.getNodeValue("status"), true)
	}
}

/////////////////////////////////////////////////////////////
function refreshCartDisplay()
/////////////////////////////////////////////////////////////
{
	if (XmlServer.call("<root></root>", "refresh"))
	{
		var shoppingCartContainer = document.getElementById("shoppingCartContainer")
		cartItemCount = XmlServer.getNodeValue("ItemCount")
		cartValue = parseInt( XmlServer.getNodeValue("CartValue") )

		if (cartItemCount == 0)
			shoppingCartContainer.innerHTML = "<DIV>Your shopping cart is empty</DIV>"
		else
			shoppingCartContainer.innerHTML  = XmlServer.getNodeValue("Table")
		
	}
}

/////////////////////////////////////////////////////////////
function selectNavigationTab(pageIndex)
/////////////////////////////////////////////////////////////
{
	if (cartItemCount == 0)
	{
		alert("You must select at least one product or service", true)
		return
	}
		
	var cart = document.getElementById("shoppingCartTable");
	var versionSupplied = true;

	for (var i=1; i<cart.rows.length; i++)
	{
		var version = DbNetLink_getElementById(cart.rows[i], 'version');
		if (version)
		{
			if (version.value == '0')
			{
				alert("You must select the version for all components");
				versionSupplied = false;
				version.focus();
				break;
			}
		}
	}
	if (!versionSupplied)
		return;
	/* step through each data row in the shopping cart. If an element with an id of 'version' 
	   exists, then the item is a component and the version must be selected */

	document.location.href = "cartpage2.aspx"
}

//////////////////////////////////////////////////////////////////////////////////////////////
function DbNetLink_getElementById(rootNode, id)
//////////////////////////////////////////////////////////////////////////////////////////////
{
	if (rootNode == null) alert("root node is null " + id)
	if (rootNode.all)
		return rootNode.all[id];
	else
	{
		if (rootNode.getElementsByTagName) 
		{		
			var all = rootNode.getElementsByTagName('*');	
			for (i=0; i < all.length; i++) 
			{
				if (all[i].getAttribute)
					if (all[i].getAttribute('id'))
						if (all[i].getAttribute('id').toLowerCase() == id.toLowerCase()) 
							return all[i];	
			}
		}	
	}
	return null;
}

