
var fdgl_hnd   = null;
var fdgl_width = 450;
var fdgl_height = 250;

function OpenFileDialog(url, codice, widthimg, heightimg, subfld)
{
	var frm = document.forms[0];
	var els = frm.elements;
	var chk = els['codice'];
	var	sel = 0;

	if(chk) {
		if(!chk.length){
			sel=chk.value;
		} else {
			for(var i=0; i<chk.length; i++){
				if(chk[i].checked){
						if(isNaN(chk[i].value)){
							alert(chk[i].value.substring(chk[i].value.length-1, chk[i].value.length));
							sel=chk[i].value.substring(chk[i].value.length-1, chk[i].value.length);
						}
						else
							sel=chk[i].value;
						break;
				}
			}
		}
	
		if(sel.length>0){
			if(fdgl_hnd){
				fdgl_hnd.close();
			}
			par = 'width=' + fdgl_width + ',height=' + fdgl_height + ', directories=no, location=no, menubar=no, scrollbars=no, status=yes, toolbar=no';
			
			if(arguments.length>4){
				url += '?idximg=' + sel + '&codice=' + codice+'&widthimg='+widthimg+'&heightimg='+heightimg+'&subfld='+subfld;
			} else {
				url += '?idximg=' + sel + '&codice=' + codice+'&widthimg='+widthimg+'&heightimg='+heightimg;
			}
			fdgl_hnd = window.open(url, 'fdgl_hnd', par);
			fdgl_hnd.moveTo((screen.width/2)-(fdgl_width/2), (screen.height/2)-(fdgl_height/2));
		} else {
			alert('Devi selezionare un\'immagine.');
		}
		
	} else {
		if(fdgl_hnd){
			fdgl_hnd.close();
		}
		par = 'width=' + fdgl_width + ',height=' + fdgl_height + ', directories=no, location=no, menubar=no, scrollbars=no, status=yes, toolbar=no';
		
		if(arguments.length>4){
			url += '?idximg=' + sel + '&codice=' + codice+'&widthimg='+widthimg+'&heightimg='+heightimg+'&subfld='+subfld;
		} else {
			url += '?idximg=' + sel + '&codice=' + codice+'&widthimg='+widthimg+'&heightimg='+heightimg;
		}
		fdgl_hnd = window.open(url, 'fdgl_hnd', par);
		fdgl_hnd.moveTo((screen.width/2)-(fdgl_width/2), (screen.height/2)-(fdgl_height/2));
		
	}
}


var fimg_hnd   = null;
function OpenImageZoom(ImagePath, w, h)
{	
		
		if(fimg_hnd){
			fimg_hnd.close();
		}
		ww = (w + 25);
		wh = (h + 40);

		url = '/dialog_img.php?src=' + ImagePath + '&w=' + w + '&h=' + h;
		par = 'width=' + ww + ',height=' + wh + ', directories=no, resizable=yes, location=no, menubar=no, scrollbars=yes, status=yes, toolbar=no'; 
		fimg_hnd = window.open(url, 'fimg_hnd', par);
		fimg_hnd.moveTo((screen.width/2)-(w/2), (screen.height/2)-(h/2));		
}


var fimg_hnd2   = null;
function OpenAlbumImageZoom(ImagePath, w, h, id)
{	
		
		if(fimg_hnd2){
			fimg_hnd2.close();
		}
		
		ww = (w * 1.0)>300?(w * 1.0)+50:300;
		wh = (h * 1.2)>300?(h * 1.0)+120:250;
		
		url = '/album_img.php?src=' + ImagePath + '&w=' + w + '&h=' + h + '&id=' + id;
		par = 'width=' + ww + ',height=' + wh + ', directories=no, resizable=yes, location=no, menubar=no, scrollbars=yes, status=yes, toolbar=no'; 

		fimg_hnd2 = window.open(url, 'fimg_hnd2', par);
		fimg_hnd2.moveTo((screen.width/2)-(w/2), (screen.height/2)-(h/2));		
}

function ChkSelectionAndGo(frmName, chkPrefix, idFldName, url)
{
		var frm = document.forms[frmName];
		var re  = new RegExp(chkPrefix, 'i');
		s = 0; el = -1;
		for(var i=0; i<frm.elements.length; i++){
				if(re.test(frm.elements[i].name) && frm.elements[i].checked){
						s++;
						el = frm.elements[i].value;
				}
		}
		if(s==0){
			alert('Selezionare un elemento da modificare');
			return;
		}
		
		if(s>1){
			alert('E\' possibile modificare un solo elemento per volta.');
			return;
		}
		frm.elements[idFldName].value = el;
		frm.action = url;
		frm.submit();
		return false;
}

function yearMove(year)
{
	alert(year);
	document.forms[0].elements.yearID.value = year;
	document.forms[0].submit();
}

function selectDay(year, month, day)
{
	document.forms[0].action = '/amministrazione/news.php';
	document.forms[0].elements.yearID.value = year;
	document.forms[0].elements.monthID.value = month;
	document.forms[0].elements.dayID.value = day;	
	document.forms[0].submit();
}
