
//begin calculations functions
function updCCA(CB, noHL)
{
	checkNum(CB, CB.checked);
	if(!noHL)
	{
		if(CB.checked)
			updhL(CB);
		else
			upddL(CB);
	}
}

function updhL(E)
{
	while(E.tagName != 'TR')
	{
		E = E.parentNode;
	}
	E.className = 'calc_tr_hover';
}

function upddL(E){
	while(E.tagName != 'TR')
	{
		E = E.parentNode;
	}
	E.className = '';
}
//end calculations functions


function uphL(E)
{
	while(E.tagName!="TABLE")
	{
		E = E.parentNode;
	}
	while(E.tagName != "TR")
	{
		E = E.parentNode;
	}
	E.className="calc_tr_hover";
}

function updL(E)
{
	while(E.tagName != 'TABLE')
	{
		E = E.parentNode;
	}
	while(E.tagName!="TR")
	{
		E = E.parentNode;
	}
	E.className = "";
}

//-------------------------------------------------------------
function checkNum(obj) {
	var num = 0;
	for(var i = 0; i < document.updatescompare.elements.length; i++) {
		if (document.updatescompare.elements[i].type == "checkbox") {
			if (document.updatescompare.elements[i].checked == true) {
				num++;
			}
		}
	}
	if(num == 3) {
		obj.checked = false;
		alert("Puoi confrontare solo due voci."); //
		
	}
}
	
function checkUpdComp(tf)
{
	var num = 1;
	for (var i = 0; i < document.updatescompare.elements.length; i++) {
		if (document.updatescompare.elements[i].type == "checkbox") {
			if (document.updatescompare.elements[i].checked == true) {
				num++;
				
			}
		}
	}
	if (num != 3) {
        	alert("Devi selezionare due prodotti da confrontare."); //
			return(false);
	}
	else {
		for (var i = 0; i < document.updatescompare.elements.length; i++) {
			if (document.updatescompare.elements[i].type == "checkbox") {
				if (document.updatescompare.elements[i].checked == true) {
					num++;
					
				}
				else {
				document.updatescompare.elements[i].value = "";
				}
			}
		}
		return(true);
	}
}
//-------------------------------------------------------------
// author:	Alessandro Parodi
// date:	11-04-2006
// description: functions to set a custom class to the rows which are group
// 				headers

var group_icon = 'group_icon';		// the attribute name of the group icon images
var tooltip_icon = 'tooltip_icon';	// the attribute name of the tooltips' icons
var group_style = 'group';			// class to be applied to the TD in wich the group images are

/// gets all the images in the document with name group_icon and returns an array of references to html objects
function SetStyleToGroupHeaders()
{
	if(document.images)
		for(var i = 0; i < document.images.length; i++)
			if(document.images[i].name == group_icon)
				if(document.images[i].parentNode.tagName.toUpperCase() == 'TD')
					document.images[i].parentNode.className += ' ' + group_style;
}

/// puts the tooltip by the text
function FixTolltipPosition()
{
	if(document.images)
		for(var i = 0; i < document.images.length; i++)
			if(document.images[i].name == tooltip_icon)
				if(document.images[i].parentNode.firstChild.tagName != null)
					if(document.images[i].parentNode.firstChild.tagName.toUpperCase() == 'TABLE')
					{
						var table = document.images[i].parentNode.firstChild;
						table.firstChild.firstChild.childNodes[1].appendChild(document.images[i]);
					}
}

/// on load sets all the selected products tr class
function FixClasses()
{
	if(document.updatescompare == null) return;
	var elmts = document.updatescompare.elements;
	for(var i = 0; i < elmts.length; i++)
		if(elmts[i].type == 'checkbox') updCCA(elmts[i]);
};

function onLoadUpdateFunction()
{
	SetStyleToGroupHeaders();
	FixTolltipPosition();
	FixClasses();
}

//Table help

function hiddenDisp(idDiv)
{
	var tipsParent = document.getElementById('tipsParent');
	for(var i = 0; i < tipsParent.childNodes.length; i++)
	{
		var temp = tipsParent.childNodes[i];
		if(temp.nodeName != '#text' && temp.tagName == 'DIV')
		{
			if(temp.id == idDiv) temp.style.display = (temp.style.display == '')?'none':'';
			else temp.style.display = 'none';
		}
	}
}