// JavaScript Document
//**************************************************************		
// posizione del Div dynamico
	function Point(x, y) {
		this.x = x;
		this.y = y;
	}
		
	function getObjCoords(o, ByElement, y, x) 
	{

		var oX = 0;
		var oY = 0;
		if (o.offsetParent) {
			while (1) {
				oX+=o.offsetLeft;
				oY+=o.offsetTop;
					if (!o.offsetParent) {
						break;
					}
				o=o.offsetParent;
			}
		} else if (o.x) {
			oX+=o.x;
			oY+=o.y;
		}
	
		var oY = oY+y
		var oX = oX+x
		
		document.getElementById(ByElement).style.top = oY
		document.getElementById(ByElement).style.left = oX
	}
//**************************************************************		
//	ridimensiona la select box
function sel_ridimensiona(event,campoCombo,campoTxt,campoDiv)
	{

		if (document.getElementById(campoCombo).style.display == 'inline')
			{				
				document.getElementById(campoCombo).style.display = 'none'
			}
		else
			{	
				if (window.event)
					{
						document.getElementById(campoCombo).style.display = 'inline'															
						getObjCoords(document.getElementById(campoTxt), campoDiv, 17, 1)
					}
				else
					{	
					
						var coords = {x: 0, y: 0 };
						var el = event.target;
						
						do 
						{
							coords.x += el.offsetLeft;
							coords.y += el.offsetTop;
							}
							while ((el = el.offsetParent));
							var offsetX = event.clientX - coords.x;
							var offsetY = event.clientY - coords.y;
						document.frmdettaglio.selsel_year.style.display = 'inline'
						document.getElementById(campoDiv).style.posTop = (event.clientY - offsetY) 
						document.getElementById(campoDiv).style.left = (event.clientX - offsetX)
					}	
				document.getElementById(campoCombo).focus();	
			}
	}	
//**************************************************************	
// seleziona dalla select box al txt	
	function sel_seleziona(campotxt,campoCombo,campoHidden)
	{
		document.getElementById(campotxt).value = document.getElementById(campoCombo).options[document.getElementById(campoCombo).selectedIndex].text			
		document.getElementById(campoHidden).value = document.getElementById(campoCombo).value;
		document.getElementById(campoCombo).style.display = 'none'
	}	
//**************************************************************	
//nasconde la selectbox	
	function sel_nascondi(campoCombo)
	{
		document.getElementById(campoCombo).display = 'none'
	}		
//**************************************************************		
	function cambioCdr()
	{
		if (document.frmCambioCdr.CdrAssociato.value == "")
		{
		alert('E neccessario che seleziona il Cdr da associare.   ');
		return;
		}
		document.frmCambioCdr.submit();
	}
//*************************************************************************
	function checkCdr(ByText)
	{
		var Text = document.getElementById('CdrAssociato').options[document.getElementById('CdrAssociato').selectedIndex].text
		if (Text == "Errore")
		{
		document.getElementById('SpanCdrSelezionato').innerHTML = '';
		alert('Seleziona un altro Cdr')
		document.getElementById('CdrAssociato').value = '';
		return;
		}
		else
		{
		document.getElementById('btnCambiaCdr').disabled = false;
		document.getElementById('SpanCdrSelezionato').innerHTML = Text;
		}
	}
//*****************************************************************************	
	// Removes leading whitespaces
	function LTrim( value ) {
		
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
		
	}
	
	// Removes ending whitespaces
	function RTrim( value ) {
		
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
		
	}
	
	// Removes leading and ending whitespaces
	function trim( value ) {
		
		return LTrim(RTrim(value));
	}

//************************************************************
//tronca
	function Left(str, n)
	{
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}
	
	function Right(str, n)
	{
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
	}
//************************************************************
//	window.moveTo(0,0);
//	window.resizeTo(screen.width,screen.height-30);
//************************************************************
/*	function onError()
	{
	return true
	}
	window.onerror = onError
*///************************************************************
	function chidiTb(ByTb, BySpan, ById, ByTxtApri, ByTxtChiudi)
	{
		if (document.getElementById(ByTb+ById).style.display == 'none')
		{
		document.getElementById(ByTb+ById).style.display = 'inline'
			if (document.getElementById(BySpan+ById) != null)
			{
			document.getElementById(BySpan+ById).innerHTML = ByTxtChiudi
			}
		}
		else
		{
		document.getElementById(ByTb+ById).style.display = 'none'
			if (document.getElementById(BySpan+ById) != null)
			{
			document.getElementById(BySpan+ById).innerHTML = ByTxtApri
			}
		}
	}
	
/*********************************************************************************************************
funzione per richiamare una determina di riferimento impegno/accertamento a fronte di una prenotazione
*/
	function RichiestaRiferimento()
	{
		IDRichiesta = document.frmDatiDetermina.idImpegnoRiferimento.value;
		idTipoDDRiferimento = document.frmDatiDetermina.IDTipoDetermina.value;
		//alert('idTipoDDRiferimento = '+idTipoDDRiferimento)
		
		location.href='ComeNuovaRichiesta.asp?IDRichiesta='+IDRichiesta+'&provenienza=riferimento&idTipoDDRiferimento='+idTipoDDRiferimento
		return false
	}
/*********************************************************************************************************
*/	
	function InStr(String1, String2)
	{
		var a = 0;
	
		if (String1 == null || String2 == null)
			return (false);
	
		String1 = String1.toLowerCase();
		String2 = String2.toLowerCase();
	
		a = String1.indexOf(String2);
		if (a == -1)
			return 0;
		else
			return a + 1;
	}	
/*********************************************************************************************************/

/*Funzione per scrivere in una text solo numeri onkeydown*/
	function Numero()
	{	
	//alert('tasto = ' + event.keyCode )	
	/*Solo numeri*/
	if (((event.keyCode < 48))  || (event.keyCode > 57))
		/* Tasto canc e tasto back e tasto freccia sinistra e destra*/
		if (((event.keyCode != 46))  && (event.keyCode != 8) && (event.keyCode != 37) && (event.keyCode != 39))		
			event.returnValue = false;
	}
	
//**************************************************************************************	
function txtColorIn(element)
{
document.getElementById(element).style.backgroundColor = '#FFFFFF';
document.getElementById(element).style.borderColor = '#FF0000';
}

//**************************************************************************************

function txtColorOut(element)
{
document.getElementById(element).style.backgroundColor = '';
document.getElementById(element).style.borderColor = '';
}
//**************************************************************************************
// SOSTITUISCE all'interno di una stringa piu' valori
function sostituisci(OldString,OldReplace,NewReplace)
{ 

	NewString = "" + OldString;
	while (NewString.indexOf(OldReplace)>-1) 
		{
		PosReplace = NewString.indexOf(OldReplace);
		NewString = "" + (NewString.substring(0, PosReplace) + NewReplace + NewString.substring((PosReplace + OldReplace.length), NewString.length));
		} 
		
return (NewString);
}

/*********************************************************************************************************/
	function maxChars(ta, count, byDiv) 
	{
		var ta;
		ta = document.getElementById(ta.name).value

		if (ta.length >= count) 
		{
			//alert('if')
			ta = ta.substring(0, (count - 1));
			document.getElementById(byDiv).innerHTML = 'Massimo caratteri raggiunto!';
		} 
		else 
		{
			document.getElementById(byDiv).innerHTML = 'Carattere: ' + parseInt(ta.length) + ' di ' + count;
		}
	}
/*********************************************************************************************************/

	//disabled back button
	window.history.forward(1);

//******************************************************************

	function disableEnterKey(e)
	{
		 var key;
	
		if(window.event)
			  key = window.event.keyCode;     //IE
		 else
			  key = e.which;     //firefox
	
		 if(key == 13)
			  return false;
		 else
			  return true;
	}
//******************************************************************

	function seldata(frmform,ogg)
	{			
		url='calendar.asp?date_form='+frmform+'&date_field=' + ogg;	
		//alert('evento Y ='+ event.screenY)
		//alert('evento X ='+ event.screenX)
		//return;
		window.open(url,"_blank","height=200,width=420, resizable=yes, top=200,left=300");//+",left="+event.screenX-1);
	}
		function seldataarea(frmform,ogg)
	{			
		url='../calendar.asp?date_form='+frmform+'&date_field=' + ogg;	
		//alert('evento Y ='+ event.screenY)
		//alert('evento X ='+ event.screenX)
		//return;
		window.open(url,"_blank","height=180px,width=390px, resizable=yes, top=200,left=300");//+",left="+event.screenX-1);
	}