/* 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 stampaGiocata()
{
	var url = "/Totocalcio.pdf?action=stampa&gioco=totocalcio&giocata=";
	url += document.schedina.getGiocataAsOctalString();
	window.open(url, 'stampa', "width=600,height=400,scroll=auto,border=thin,status=no,resizable=yes,navigation=no,toolbar=no");
	//document.location=url;
	return false;
}

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&igrave;","marted&igrave;","mercoled&igrave;","gioved&igrave;","venerd&igrave;","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)
{

	// Set default width and height:

	var width = 660;
	var height = 510;

	// Check if width or height are provided with the features:

	if (features)
	{
		var index;
		var tmpstring;

		// Search for definition of width:

		index = features.indexOf('width=');
		if (index > -1)
		{
			tmpstring = features.substring(index+6,features.length)
			index = tmpstring.indexOf(",");
			if (index < 0)
			{
				index = tmpstring.length;
			}
			// Get the provided width:
			width = tmpstring.substring(0,index);
		}

		// Search for definition of height:

		index = features.indexOf('height=');
		if (index > -1)
		{
			tmpstring = features.substring(index+7,features.length)
			index = tmpstring.indexOf(",");
			if (index < 0)
			{
				index = tmpstring.length;
			}
			// Get the provided height:
			height = tmpstring.substring(0,index);
		}
	}

	// Calculate window position:
	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;

	// Set the right features:

	features = "width="+width+",height="+height+",scrollbars=yes,resizable=yes,location=no,left="+left+",top="+top;

	// Open the window:
	window.open(URL, "", features);

}


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=220px; scroll=no; center=yes; border=thin; help=no; status=no;"
	finestra = window.showModalDialog("/script/datepicker.xwb", 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();

}