/*************
Name:			productpage.js
Description:	Functionality for changing the price for mountings and validating purchases
Date:			04/07/2006
Author:			James Condliffe
**************/

// Setup on page load
addLoadEvent(radioButtonsSetup)
addLoadEvent(tooltipSetup)

function radioButtonsSetup()
{
	var form;

	if (form = document.getElementById("addtobasket"))
	{
		radiobuttons = getElementsByClassName(form,"input","mountingtypes");
		
		// Add event handlers to the radio buttons
		for (var i=0; i<radiobuttons.length; i++ )
		{
			radiobuttons[i].onclick = function(){priceChange(this);};
		}
	}
}

function tooltipSetup()
{
	// Grab the links
	var ttLinks = getElementsByClassName(document,"a","tooltip");

	// Add event handlers to the links
	for (var i=0; i<ttLinks.length; i++)
	{
		ttLinks[i].onmouseover = function(){toggleMountingInfo(this, 'on');};
		ttLinks[i].onmouseout = function(){toggleMountingInfo(this, 'off');};
		ttLinks[i].onclick = function(){return false;};
	}
}

function priceChange(obj)
{
	pricenode = document.getElementById("mainprice");
	pricenode.innerHTML = document.getElementById(obj.getAttribute("id")+"price").innerHTML;
}

function toggleMountingInfo(obj, toggle)
{
	var desc = document.getElementById(obj.id+"_desc");

	if (toggle=='on') // display the tooltip thingy
	{    
		if ((desc.style.top == '' || desc.style.top == 0) && (desc.style.left == '' || desc.style.left == 0))
		{			
			x = findPosX(obj)+20;
			y = findPosY(obj)+10;
			
			desc.style.top = y + 'px';
			desc.style.left = x + 'px';
		}
		desc.style.visibility = "visible";
	}
	else
	{
		desc.style.visibility = "hidden";
	}
}
