// JavaScript Document
var ilMaxOre = 24 

ua   = navigator.userAgent.toLowerCase();
ie6  = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
nnf  = (ua.indexOf("netscape")  != -1 && ua.indexOf("gecko") != -1);
nni  = (ua.indexOf("netscape")  != -1 && ua.indexOf("msie") != -1);
nn6  = (ua.indexOf("netscape")  != -1);
gek  = (ua.indexOf("gecko")     != -1);
ff1  = (ua.indexOf("firefox")   != -1);
opr  = (ua.indexOf("opera")     != -1);
mac  = (ua.indexOf("mac")       != -1);
web  = (ua.indexOf("webtv")     != -1);
saf  = (ua.indexOf("safari")    != -1);
kon  = (ua.indexOf("konqueror") != -1);
nn4  = (document.layers);

function chiudi() {
	self.close()	
}

function mostra(x,y,t1,t2) {
	
	if (document.getElementById(x).style.display == 'none')
	{
		document.getElementById(x).style.display = ''
	} else
	{
		document.getElementById(x).style.display = 'none'
	}
	
	
	
}

function apripop(x,a,b,c,d) {
var iMyWidth;
var iMyHeight;
if (c != null && d != null)
{
	iMyWidth = c
	iMyHeight = d
}
else
{
	
	iMyWidth = (window.screen.width/2) - (a/2 + 10);
	iMyHeight = (window.screen.height/2) - (b/2 + 50);
	
}

newWindow = window.open(x,"subwind","height="+b+",width="+a+"left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars")
newWindow.focus();
}	
function apripophidden(x) {
newWindow = window.open(x,"hidden")	
}
function apriEventDet(perchi,quale) {
param = 'showEventdet.cfm?chi='+perchi+'&quale='+quale;
newWindow = window.open(param,"subwind","height=700,width=800,scrollbars")
newWindow.focus();
}

function modEvent(quale) {
newWindow = window.open("modEvent1.cfm?id="+quale,"subwind","height=700,width=800,scrollbars")
newWindow.focus();
}

function vediEvent(quale) {
param = "id="+quale;
newWindow = window.open("viewEvent.cfm?"+param,"subwind","height=350,width=600,scrollbars")
newWindow.focus();
}

function nextInterval(variation) {
var offset = parseInt(document.actionForm.currentOffset.value);
var newOffset = offset + variation;
var url = "_homeCentralColumn.cfm?interval=" + newOffset;
ColdFusion.navigate(url, 'centralDiv');
}

function prevInterval(variation) {
var offset = parseInt(document.actionForm.currentOffset.value);
var newOffset = offset - variation;
var url = "_homeCentralColumn.cfm?interval=" + newOffset;
ColdFusion.navigate(url, 'centralDiv');
}

function cecca(sono,cosa) {
	if (sono == 2)
	{
		document.getElementById(cosa).style.display='';
	} else
	{
		document.getElementById(cosa).style.display='none';
	}
}
function chkInit(quale) {
	 
	if (quale != '')
	{
		var iparam = quale.split("&")
		var variab1 = iparam[0].split("=")
		if (variab1[0] == 'menuID' && variab1[1] == 2 && iparam.length >= 3 )
		{
			var variab2 = iparam[1].split("=") 
			{
				if (variab2[0] == 'apro')
				{
					variab3 = iparam[2].split("=")
					ColdFusion.navigate('viewsetup.cfm?id=' + variab3[1] + '&tab=tbl_project','myView')
					tmt.widget.expandpanel.util.openPanel('pannello', variab2[1] )}	
			}
			
		}
	
	}
		
}


/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		
		return false;
	} 
	else
	return true;
}      

function sommaOre() {
	
	var lungo = document.getElementById('ilform').length - 1
	var obj = document.getElementById('ilform')
	var iltotale = 0

	for (var i=0; i< lungo; i++)
	{
		ilcampo = obj[i].name.split("_")
		if (ilcampo[0] == 'prj' &&  obj[i].value != '' ) 
			{ iltotale += eval(obj[i].value) }
		
	}
	
	
	if ( iltotale > ilMaxOre )
	{
		alert('ATTENZIONE! Il totale delle ore inputate supera 24')
			
	} else if (iltotale == 0 ) 
	{
		alert('ATTENZIONE! Il totale delle ore inputate è 0 ')

	} else if (iltotale > 0 && iltotale < 8 ) 
	{ 
		if ( confirm('ATTENZIONE! Hai inputato ' + iltotale + ' ore e quindi un numero di ore inferiore a 8. Confermi?') )
		{ document.getElementById('totOre').value = iltotale ; obj.submit() }
		
	} else
	
	{ 
		if ( confirm('Hai inputato ' + iltotale + ' ore. Confermi?' ) )
		 { document.getElementById('totOre').value = iltotale ; obj.submit() }
	}
		
}

function x(obj,pv,y)
{
	obj.style.backgroundColor=pv;
	b = y;
	} 
function x2(obj,pv)
{
	obj.style.backgroundColor=pv;
	} 
function xx(obj,pv,y,z)
{
	obj.style.backgroundColor=pv;
	posUno = y
	dataUno = z
	} 
function xx2(obj,pv,y)
{
	obj.style.backgroundColor=pv;
	posDue = y
	parametroUrl = 'addevent.cfm?id=0&cella1='+posUno+'&cella2='+posDue+'&ladatain='+dataUno
	<!---ripulisco(posUno,posDue)--->
	apripop(parametroUrl,'600','500')
	} 
	
function move_keyword(quale,dove) {
	if (document.getElementById(dove).value == '')
	{   newNome = document.getElementById(dove).value + quale
	} else 
	{	newNome = document.getElementById(dove).value + "^" + quale
	}

	document.getElementById(dove).value = newNome
	
}

function reset_keywords(quale) {
	document.getElementById(quale).value = ''
}

function ceccami(quale,cosa) {
 	if (quale.value == '')
	
	{
		quale.value = cosa			
	} else
	{
 		var obj = quale.value.split(',')
 		var nuovo = ''
		var lVero = false
		for (var i=0; i<obj.length; i++ )
		{
 			if ( obj[i] != cosa )
			{ 
				if (nuovo == '')
				{
					nuovo = obj[i]  
				} else
				{
					nuovo = nuovo + ',' + obj[i]
				}
			} else
			{
				lVero = true
			}
		}
		if ( lVero == false)
		{
			nuovo = nuovo + ',' + cosa
		 }
		 
		quale.value = nuovo	
	}
	
} 





function loadProgetti (stato,id,tipo)
{
	var url = 'caricaProgetti.cfm'
	var param = 'stato=' + stato +'&ilfiltro='+id
	var myAjax
	
	if (tipo == 1)
	{
		myAjax = new Ajax.Request
		(
			url,
			{
				method: 'get',
				parameters: param,
				onComplete: loadDati2,
				onFailure: erroreDati
			}
		)
	}
	else
	{
			myAjax = new Ajax.Request
		(
			url,
			{
				method: 'get',
				parameters: param,
				onComplete: loadDati3,
				onFailure: erroreDati
			}
		)
	
		}
	
}

function loadDati2(ajaxResponse)
{
	eval(ajaxResponse.responseText)
	
	var selectList = document.getElementById('frm_progetto')
	
	selectList.options.length = 0
	
	
	for (var i in opzioniSelect)
	{
		selectList.options[selectList.options.length] = new Option(opzioniSelect[i], i++ )
	}
	
	sortSelect(selectList)
	 
}
function loadDati3(ajaxResponse)
{
	eval(ajaxResponse.responseText)
	
	var selectList = document.getElementById('frm_progetto2')
	
	selectList.options.length = 0
	
	
	for (var i in opzioniSelect)
	{
		selectList.options[selectList.options.length] = new Option(opzioniSelect[i], i++ )
	}
	
	sortSelect(selectList)
	 
}

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

function sortSelect(obj) {
var o = new Array();
if (!hasOptions(obj)) { return; }
for (var i=0; i<obj.options.length; i++) {
o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
}

if (o.length==0) { return; }
o = o.sort( 
function(a,b) { 
if ((a.text+"") < (b.text+"")) { return -1; }
if ((a.text+"") > (b.text+"")) { return 1; }
return 0;
} 
);

for (var i=0; i<o.length; i++) {
obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
}
}

function erroreDati ()
{
	alert('error loading data')
}

