/* identificazione del browser e della piattaforma */

var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var win = ((agt.indexOf("win") != -1) || (agt.indexOf("32bit") != -1));


function openPrintPopup(url, width, height)
{
    /*if (ie && win)
    {
        newWin = window.showModalDialog(url, null, "dialogHeight:"+height+"px;dialogWidth:"+width+"px;dialogTop:0px;dialogLeft:0px;status:no;scrollbars:no;resizable:no;");
    }
    else*/
    {
        /* funziona con IE 4.x e Netscape 6.x */
        newWin = window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resible=no,height="+height+",width="+width+",position=absolute,top=0px,left=0px");
    }
}


function showInfo(div, leftPos)
{
	//Set the left position of absolute div
	windowWidth = document.body.clientWidth;
	table = document.getElementById("tabella");


	tablewidth = table.offsetWidth;
	tableLeft = (windowWidth - tablewidth) / 2;

		if (tableLeft <= 0)
		{
			marginLeft = document.body.getAttribute("leftmargin");
			leftDiv = parseInt(marginLeft) + parseInt(leftPos);
		}
		else
			leftDiv = parseInt(tableLeft) + parseInt(leftPos)-4;

	div.style.posLeft = leftDiv;
	div.style.visibility = "visible";

}

function hideInfo(div)
{
	div.style.visibility = "hidden";
}

function showInfoLast(div, leftPos, id)
{
	//Set the left position of absolute div
	windowWidth = document.body.clientWidth;
	table = document.getElementById("tabella");
	tablewidth = table.offsetWidth;
	tableLeft = (windowWidth - tablewidth) / 2;

		if (tableLeft <= 0)
		{
			marginLeft = document.body.getAttribute("leftmargin");
			leftDiv = parseInt(marginLeft) + parseInt(leftPos) + 3;
		}
		else
			leftDiv = parseInt(tableLeft) + parseInt(leftPos) - parseInt(div.offsetWidth - a7.offsetWidth) - 5;

	div.style.posLeft = leftDiv;
	//showShadow(div, leftDiv);

	div.style.visibility = "visible";
}


function imgOn(imgName)
{
	if (document.images)
	{
    	document[imgName].src = eval(imgName + "on.src");
    }
}

function imgOff(imgName)
{
	if (document.images)
	{
		document[imgName].src = eval(imgName + "off.src");
	}
}

function navBar( tableCellRef, hoverFlag)
{
	if ( hoverFlag )
	{
		tableCellRef.style.backgroundColor = '#F3FEF1';
	}
	else
	{
		tableCellRef.style.backgroundColor = '#A2DDA7';
	}
}

function todayDate()
{
	var d = new Date()
	var weekday=new Array("domenica","luned&iacute;","marted&iacute;","mercoled&iacute;","gioved&iacute;","venerd&iacute;","sabato")
	var month=new Array("gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre")
	document.write(weekday[d.getDay()]+ " ")
	document.write(d.getDate()+ " ")
	document.write(month[d.getMonth()]+ " ")
	document.write(d.getFullYear())
}
/*******************************************************************************
/*********************************************************************************/
function winImageOpen(URL,features)
{
	if (features)
	{
		window.open(URL, null, features + "scrollbars=no,resizable=no");
	}
	else
	{
		window.open(URL, null, "width=660,height=510,scrollbars=no,resizable=no");
	}
}

function printResult()
{
	var divPrint = document.getElementById('print');
	divPrint.style.visibility = "hidden";
	window.print();

}


function openWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}


function openModal(indirizzo, parametri, width, height)
{
	strFeatures = "dialogWidth="+width+"; dialogHeight="+height+"; scroll=auto; center=yes; border=thin;"
	alert(strFeatures);
	finestra = window.showModalDialog(indirizzo, parametri ,  strFeatures);
}



function openDatePicker(dateCtrl)
{
	var dialogArguments = new Array();
	dialogArguments = [parent, dateCtrl];
	strFeatures = "dialogWidth=230px; dialogHeight=230px; scroll=no; center=yes; border=thin; help=no; status=no;"
	finestra = window.showModalDialog("/ccu/calendar/datepicker.htm", dialogArguments ,  strFeatures);
}

/**
 * La funzione setScreenInfo controlla attraverso JavaScript la risoluzione
 * video usata dall'utente. Se la risoluzione e' stabilita correttamente,
 * viene inserito in sessione un Cookie contenente il valore della risoluzione
 * nel formato 1024x768, 800x600, etc. Il Cookie scade al termine della sessione.
*/

function setScreenInfo()
{
	var screenSize;

	var width = screen.width;
	var height = screen.height;

	if ( !isNaN(width) && !isNaN(height) )
	{
		screenSize = width + "x" + height;
		document.cookie = "screensize=" + escape(screenSize);
	}
}


function deleteControlCheck(form, href, checksname)
{
	var i=0;
	var check = false;
	if (document.formDelete[checksname]) //controllo se c'è la lista di checkbox
	{
		if (!document.formDelete[checksname].length)
		{
			if (document.formDelete[checksname].checked)
			{
				check = true;
			}
		}
		else
		{
			while (i < document.formDelete[checksname].length)
			{
				if (document.formDelete[checksname][i].checked)
					check = true;

				i++;
			}
		}

		if (check == true)
			deleteConfirmation(form, href);
		else
			alert("Seleziona almeno un elemento");
	}
}

function deleteConfirmation(form,href)
{
	if (confirm("Vuoi eliminare l'elemento selezionato?")==true)
		CheckAndSubmit(form, href);
}


function addCheckAndSubmit(form, href, checksname)
{
	var i=0;
	var check = false;

	if (document.formAdd[checksname]) //controllo se c'è la lista di checkbox
	{
		if (!document.formAdd[checksname].length)
		{
			if (document.formAdd[checksname].checked)
			{
				check = true;
			}
		}
		else
		{
			while (i < document.formAdd[checksname].length)
			{
				if (document.formAdd[checksname][i].checked)
					check = true;

				i++;
			}
		}

		if (check == true)
		{
			form.action = href;
			form.submit();
		}
		else
			alert("Seleziona almeno un elemento");
	}
}


function printResult()
{
	var divPrint = document.getElementById('print');
	divPrint.innerHTML = "";
	window.print();

}
