function movepic(img_name,img_src) 
{
	document[img_name].src=img_src;
}
//Apertura Popup
function OpenPopUp(MyURL, MyWidth, MyHeight)
{
	var newWindow;
	var myurl = MyURL;
			
	var MyLeft=(screen.width - MyWidth) / 2;
	var MyTop=(screen.height - MyHeight) / 2;


	if (navigator.appName == "Microsoft Internet Explorer") 
		{
		 var props = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',left=' + MyLeft + ',top=' + MyTop ;
		}
	else 
		{
		var props = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',screenX=' + MyLeft + ',screenY=' + MyTop;
		}
				
	newWindow = window.open(myurl, "NewsWindow", props);
}

//Apertura Popup Parametrica
function OpenPopUpParametric(MyURL, MyWidth, MyHeight, Title, scrollbars, resizable)
{
	var newWindow;
	var myurl = MyURL;

			
	var MyLeft=(screen.width - MyWidth) / 2;
	var MyTop=(screen.height - MyHeight) / 2;
			
	if (navigator.appName == "Microsoft Internet Explorer") 
		{
		 var props = 'scrollBars=' + scrollbars + ',resizable=' + resizable + ',toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',left=' + MyLeft + ',top=' + MyTop ;
		}
	else 
		{
		var props = 'scrollBars=' + scrollbars + ',resizable=' + resizable + ',toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',screenX=' + MyLeft + ',screenY=' + MyTop;
		}

	newWindow = window.open(MyURL,Title, props);
}


//Chiusura Window
function CloseWindow()
{
	window.close();
}


//Chiamata dalla OpenIMG2
function OpenIMG2(){
	var h=this.height+30;
	var w=this.width+20;
	newWindow = window.open('','_blank','resizable=no,width='+w+',height='+h);
	newWindow.document.write('<HEAD><TITLE>'+ Appoggio +'</TITLE></HEAD>')
	newWindow.document.write('<BODY bgcolor="#dfdec9"><CENTER><IMG src=\''+ this.src +'\'></CENTER></BODY>')
}

//Apertura popup con immagine e auto size
function OpenIMG(imgURL,Title) {
	Appoggio=Title;
	var image = new Image();
	image.onload=OpenIMG2;
	image.src = imgURL;
}


//Funzioni trim

function rTrim(sValue)
{
    var i;

    for (i=sValue.length; i > 0; i--)
    {
    	if (sValue.substr(i-1,1) != " ")
    	{
    	    return sValue.substr(0,i);
       	}
    }

    return( "" );
}

function lTrim(sValue)
{
    var i;

    for (i=0; i < sValue.length; i++)
    {
    	if (sValue.substr(i,1) != " ")
    	{
    	    return sValue.substr(i);
    	}
    }

    return( "" );
}

function trim(sValue)
{
    return rTrim(lTrim(sValue));
}



// Controlla e taglia il contenuto di una un campo (TEXTAREA) a  una lunghezza determinata
function doLengthCheck(Field, MaxLength) 
{
	
	if (Field.value.length > MaxLength) 
	{
		var txt = Field.value;
		Field.value = txt.slice(0,MaxLength-1);
	}
}


//restituisce il numero di decimali in un numero
function FindNumDecimal(valore, Separatore)
{
	var DecimalSeparator;
	var Length;
	
	Length = valore.length;
	DecimalSeparator = valore.indexOf(Separatore);
	
	if (DecimalSeparator>0)
		return Length - (DecimalSeparator+1)
	else
		return 0
}

function FormatJapanDate(DataIN)
{
	var NewDate;
	NewDate = DataIN.substr(6,4) + DataIN.substr(3,2) + DataIN.substr(0,2);
	return NewDate;
}

function SubstChar(Valore, CharSource, CharReplace)
{
	var Tag;
	var Length;
	var NewString;
	
	//Length = valore.length;
	
	Tag = Valore.indexOf(CharSource);
	if (Tag>0)
		NewString = Valore.substr(0, Tag) + CharReplace + Valore.substr(Tag +1);
	else
		NewString = Valore;
	
	return NewString
}


function FindNumDecimal(valore, Separatore)
{
	var DecimalSeparator;
	var Length;
	
	Length = valore.length;
	DecimalSeparator = valore.indexOf(Separatore);
	
	if (DecimalSeparator>0)
		return Length - (DecimalSeparator+1)
	else
		return 0
}



function isComboSelected(cmbCombo)
{
	vValue=cmbCombo.options[cmbCombo.selectedIndex].value
	return vValue!=-1
}

		
function isEmpty(txtText)
{
	re=/^\s*$/
	return re.test(txtText)
}

			
function isNumeric(txtText)
{
	re=/^\d+$/
	return re.test(txtText)
}


function isFloat(txtText)
{
	re=/(^\d+$)|(^\d+\,\d+$)|(^\d+\.\d+$)/
	return re.test(txtText)
}			


function isDate(txtText)
{
	//Verifica la corretta formattazione della stringa #0/#0/0000
	re=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/
	if (!re.test(txtText)) return 0
				
	//Suddivide la data in giorno, mese e anno
	vDatePart=re.exec(txtText)
	vDay=parseInt(vDatePart[1],10)
	vMonth=parseInt(vDatePart[2],10)
	vYear=parseInt(vDatePart[3],10)

	sDay=vDatePart[1]
	sMonth=vDatePart[2]

	if (sDay.length < 2) return 0
	if (sMonth.length < 2) return 0

	//Verifica il mese
	if (vMonth<1||vMonth>12) return 0
				
	//Determina il numero di giorni presenti nel mese
	switch(vMonth)
	{
		case 2:
			vDaysPerMonth=((vYear % 4 == 0) && ( (!(vYear % 100 == 0)) || (vYear % 400 == 0) ) ) ? 29 : 28
			break
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			vDaysPerMonth=31
			break
		case 4:
		case 6:
		case 9:
		case 11:
			vDaysPerMonth=30
			break
	}
				
	//Verifica se il giorno è corretto
	if (vDay<1||vDay>vDaysPerMonth) return 0
				
	//La data è valida
	return -1
}


function Replace(strString,CharOut,CharIn)
{
	strToSplit = new String (strString)

	pattern = CharOut

	ArrayString = strToSplit.split (pattern)

	FinalString=""
	for ( i = 0; i < ArrayString.length; i++) {
	   if (i==ArrayString.length-1)
			{	   
			FinalString=FinalString+(ArrayString[i])
			}
	   else
			{	   
			FinalString=FinalString+(ArrayString[i] + CharIn)
			}		
	}
	return FinalString;
}


function CheckEmail(TextBoxValue)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(TextBoxValue))
	{
	return (true)
	}
	return (false)
}


function CloseWindow()
{
	window.close();
}

// Inizio Generazione Password (Funzione GetPassword)-->
function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra) {
var numberChars = "0123456789";
var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
var charSet = extra;
if (number == true)
charSet += numberChars;
if (lower == true)
charSet += lowerChars;
if (upper == true)
charSet += upperChars;
if (other == true)
charSet += otherChars;
return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length) {
var rc = "";
if (length > 0)
rc = rc + getRandomChar(false, true, false, false, '');
for (var idx = 1; idx < length; ++idx) {
rc = rc + getRandomChar(false, true, false, false, '');
}
return rc;
}
// Fine Generazione Password -->


