var childwin;
var btnDisabled;

//Funzione di apertura della finestra popup di Uploading File...
function OpenUpLoadWindow(url,nomeControllo)
{  
	//var ctrl = document.getElementById('boxadinsert_Multimedia');
	var ctrl = document.getElementById(nomeControllo);
	if(ctrl.value != null && ctrl.value != '')
	{
		var leftdist = screen.width/2 -340/2; 
		var topdist =  screen.height/2 -180/2; 
					
		childwin = window.open(url, 'smuploading', 'width=340,height=180,top=' + topdist + ',left=' + leftdist +  ',status=yes,toolbar=no'); 
	}
}

//Funzione per la validazione dei formati dei file supportati dal controllo HTML InputFile 
//I valori dei file supportati verranno configurati nei file XML XmlForInputXXX...
function validateFileType(file,nomeControllo) 
{	
	//var btn = document.getElementById('boxadinsert_btnAddFile');
	var btn = document.getElementById(nomeControllo);
	if ( file.accept == null || file.accept == '' || file.value == '') return true; 
	
	var temp = file.value.split("."); 
	// Ricavo l'estensione del file...
	var ext = temp[temp.length-1]; 
	//..e l' array dei tipi validi...
	var types = file.accept.split(","); 
	
	for ( var t = 0; t < types.length; ++t ) 
	{ 
		temp =  types[t].split("/"); 
		
		if ( temp[1].toLowerCase() == ext.toLowerCase() ) 
		{
			btn.disabled = false;
			btnDisabled = false;
			return true; 
		}
	} 
	alert("Il tipo di file selezionato non e' compatibile con i formati validi: [" + types + "]."); 
	btn.disabled = true;
	btnDisabled = true;
	return false; 
} 

//Funzione generica di apertura window popup (Anteprima file/immagine)
function OpenWindowMultimedia(url,titolo,width,height,isResizable)
{ 
	var childWindow; 
	var destination;
	var withScrollBars;
	
	if (childWindow != null)
	{
		if (childWindow.closed) 
			childWindow=null;
	}		
		
	if (childWindow == null)
	{
		var winwidth = 320;
		var winheight = 200;
		if(width!=null)
			winwidth = width;
		if(height!=null)
			winheight = height;
		
		var leftdist = 0; 
		var topdist = 0; 
		
		childWindow = window.open('','',"height=" + winheight + ",width=" + winwidth + ",top=0,left=0,scrollbars=no,resizable=" + isResizable + ",menubar=no,status=yes");
		
		childWindow.document.title = titolo;
		childWindow.location = url;
	
	}			
	else
	{
		if (!childWindow.closed)
			childWindow.focus();
	}
}

//Funzione per abilitare/disabilitare il bottone AggiungiFile
function EnableButtonAddFile(file,nomeControllo) 
{	
	//var btn = document.getElementById('boxadinsert_btnAddFile');
	var btn = document.getElementById(nomeControllo);
	if (btnDisabled != true)
	{
		if(file.value == '')
			btn.disabled = true;
		else
			btn.disabled = false;
	}
	else
		btn.disabled = true;
} 