var campiExists = new Array();
var campiX = 0;

function ApriFinestra(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=550,height=420,top=50,left=50'); 
  pop.focus();
}


function ApriFinestra(_finestra, _pagina)
{
  pop=window.open(_pagina ,_finestra,'toolbar=no,scrollbars=yes,width=550,height=420,top=50,left=50'); 
  pop.focus();
}

function ApriFinestraSmall(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=350,height=220,top=50,left=50'); 
  pop.focus();
}

function ApriFinestraBig(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=700,height=500,top=50,left=50'); 
  pop.focus();
}

function ApriFinestraUpload(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=550,height=420,top=50,left=50'); 
  pop.focus();
}

function ApriFinestraCalendario(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=350,height=440,top=50,left=50'); 
  pop.focus();
}

function ApriFinestraEditor(_finestra)
{
  pop=window.open('',_finestra,'toolbar=no,scrollbars=yes,width=800,height=600,top=50,left=50'); 
  pop.focus();
}

function UniformaData( campo ) 
{
	var valore = campo.value;    
        if (valore!="")	{
	var check = new Boolean();
	check=false;
	var data = new String(valore);
	var dim = new Array();
	dim = data.split("/");
	var giorno = dim[0];
	var mese = dim[1];
	var anno = dim[2];	
	if ( dim.length == 3) check = true;
	if (check) {
	
		if ( (giorno >= 1) && (giorno <= 31)  && (check) && (giorno != '')) {
		  check = true;
		  if (giorno.length<2) giorno = "0" + giorno;		  		  
		} else {
		  check=false
		}
		
		if ( (mese >= 1) && (mese <= 12) && (check) && (mese != '')) {
			check = true;
			if (mese.length<2) mese = "0" + mese;		  		  
		} else {
			check=false;	
		}
	

		if ( (anno >= 0) && (anno <= 2099) && (check) && (anno != '') && (anno.length>1)){
			check = true; 
			if (anno.length<3) anno = "0" + anno;		  		  
			if (anno.length<4) anno = "2" + anno;		  		  

		} else {
			check=false
		}
	}        
	if (!check) {	        	    	 	        
     
            alert('Campo ' + campo.name + ' in formato errato (gg/mm/aaaa)');
            //campo.focus();
    } else {
	    campo.value = giorno + "/" + mese + "/" + anno;
	}			
    }	
}


function mustExists(campo) {
    if (campo.value=='') alert('il campo ' + campo.name + ' deve esistere');
    addExists(campo);    
}

function addExists(campo) {
    campiExists[campiX] = campo;
    campiX++;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

