function finestra(nome_pagina,nome_fin)
{
	lafinestra=window.open(nome_pagina,nome_fin,"scrollbars=yes,fullscreen=yes,resizable=no");
}

function popUp(nome_pagina,nome_fin)
{
	lafinestra=window.open(nome_pagina,nome_fin,"scrollbars=yes, toolbar=no, width=400, height=500, left=0, top=0, resizable=yes");
}

function jdata(campo,MyData,dato) {
    day = new String("");
    month = new String("");
    year = new String("");
    d = eval("document.forms[0]."+campo+".value");
    cont=true
    if (d.length<=0){
		cont=false;
    }
    if (cont){
		if (NumericCheck(d)){
			n = d.indexOf("/")
			if (n != "-1"){
				var ss = new Array();
				ss = d.split("/")
				day = ss[0];
				month = ss[1];
				year = ss[2];
				if(year==undefined || month==undefined || day==undefined){
					eval("document.forms[0]."+campo+".focus()");
					eval("document.forms[0]."+campo+".select()");
					return(false);
				}
			}else{
				day = d.substring(0,2)
				month = d.substring(2,4)
				year = d.substring(4,d.length)
			}
			//pulisco i numeri
				if(day.length==2){
					if(day.substring(0,1)=='0'){
						day=day.substr(1,1);
					}
				}
				if(month.length==2){
					if(month.substring(0,1)=='0'){
						month=month.substr(1,1);
					}
				}
			if (day.length==0 || month.length==0 || year.length==0){
				alert("Data non valida")
				if (dato) {
					eval("document.forms[0]."+campo+".focus()");
					eval("document.forms[0]."+campo+".value = ''");
					return (false); 
				}else {
					eval("document.forms[0]."+campo+".focus()");
					eval("document.forms[0]."+campo+".value = ''");
					return (false);
				} 
			}else{
				if (parseInt(day)<=0 || parseInt(day)>31 || parseInt(month)<=0 || parseInt(month)>12){
					if (dato){
						eval("document.forms[0]."+campo+".focus()");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					}else{
						eval("document.forms[0]."+campo+".focus()");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					} 
				}
				if (year.length<0 || (year.length!=2 && year.length!=4)){
					alert("Data non valida")
					if (dato) {
						eval("document.forms[0]."+campo+".focus()");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					}else{
						eval("document.forms[0]."+campo+".focus()");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					} 
				}
				if (year.length == 2) {
					if(parseInt(year)<=50){
						year = "20" + year
					}else{
						year = "19" + year
					}		
				}
				day2 = new String("")
				month2 = new String("")
				year2 = new String("")
					if (dato){ 
						d2 = MyData
					}else{
						d2 = eval("document.forms[0]."+MyData+".value")
					}
				n = d2.indexOf("/")
				if (n != "-1"){
					 var ss1 = new Array();
					 ss1 = d2.split("/")
					 day2 = ss1[0];
					 month2 = ss1[1];
					 year2 = ss1[2];
				}else{
					 day2 = d2.substring(0,2)
					 month2 = d2.substring(2,4)
					 year2 = d2.substring(4,d.length)
				}
				if (year2.length == 2){
					if(parseInt(year2)<=50){
						year2 = "20" + year2
					}else{
						year2 = "19" + year2
					}	
				}
				//pulisco i numeri
				if(day2.length==2){
					if(day2.substring(0,1)=='0'){
						day2=day2.substr(1,1);
					}
				}
				if(month2.length==2){
					if(month2.substring(0,1)=='0'){
						month2=month2.substr(1,1);
					}
				}
				maggiore = false
				if (parseInt(year) > parseInt(year2)){
					maggiore = true
				}else{
					if 	(parseInt(year) == parseInt(year2)){
						if (parseInt(month) > parseInt(month2)){
							maggiore = true
						} 
						if (parseInt(month) == parseInt(month2)){
								if (parseInt(day) > parseInt(day2)){
									maggiore = true
								} 
						}
					}
				}
				if (maggiore){
					alert("Data superiore alla data corrente");
					if (dato){
						eval("document.forms[0]."+campo+".focus()");
						//eval("document.forms[0]."+campo+".value = MyData");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					}else{
						eval("document.forms[0]."+campo+".focus()");
						eval("document.forms[0]."+campo+".value = ''");
						return (false);
					} 
				}
			}
			var data1;
			var data2;
			
			//formato a 2 cifre
			if(day.length==1){
				day="0"+day;
			}
			if(month.length==1){
				month="0"+month;
			}
			
			data1= day + "/" + month + "/" + year
			data2= day2 + "/" + month2 + "/" + year2
		
			eval("document.forms[0]."+campo+".value = '" + data1 + "'");
        }else{
			eval("document.forms[0]."+campo+".focus()");
			eval("document.forms[0]."+campo+".select()");
			return(false);
        }
    }  
}

function NumericCheck(numero){ 
	nr1=numero; flg=0; str=""; spc=""; arw="";
	for (var i=0;i<nr1.length;i++){ cmp="0123456789/"; tst=nr1.substring(i,i+1)
		if (cmp.indexOf(tst)<0){ flg++; str+=" "+tst; spc+=tst; arw+="^"; } else{arw+="_";} }
	if (flg!=0){ 
		if (spc.indexOf(" ")>-1) { 
			str+=" and a space";
		}
		alert(nr1+"\r"+arw+"\rAttenzione. Il campo accetta solo valori numerici.");
		return(false);
	}
	else { return(true); }
}

function MultiDimensionalArray(iRows,iCols) 
{ 
var i; 
var j; 
   var a = new Array(); 
   for (i=0; i < iRows; i++) 
   { 
       a[i] = new Array(); 
       for (j=0; j < iCols; j++) 
       { 
           a[i][j] = ""; 
       } 
   } 
   return(a); 
} 

function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal){

        re = new RegExp(':' + aspCheckBoxID + '$')  //valido per la versione 1.x di asp.net in cui i nomi degli id iniziano con :

        for(i = 0; i < document.forms[0].elements.length; i++){

            elm = document.forms[0].elements[i]

            if (elm.type == 'checkbox'){

                if (re.test(elm.name)){

                    elm.checked = checkVal

                }
            }
        }
}

function CheckUncheckRow(theElement,checkVal){
	var theRow = theElement.parentElement.parentElement;
	var numCelle = theRow.childNodes.length;
	for(var i=0;i<numCelle;i++){
		var cella = theRow.childNodes[i];
            if (cella.childNodes[0].type == 'checkbox'){
                    cella.childNodes[0].checked = checkVal;
            }
	}
}
