function Apri(immagine, nomeFinestra, larghezza, altezza, bgcolor) {
    newWindow = window.open("", nomeFinestra, "status=no,width="+larghezza+",height="+altezza+"");
    newWindow.document.open();
    newWindow.document.write('<html><title>'+nomeFinestra+'</title><body leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" bgcolor='+bgcolor+' onClick=\"self.close()\">');
    newWindow.document.write('<table width='+larghezza+' border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" height='+altezza+' ><tr><td>');
    newWindow.document.write('<img src=\"'+immagine+'\" width=\"'+larghezza+'\" height=\"'+altezza+'\" alt=\"Chiudi\"  />');
    newWindow.document.write('</td></tr></table></body></html>');
    newWindow.document.close();
    newWindow.focus();
}

/*function ApriSWF(immagine, nomeFinestra, larghezza, altezza, bgcolor) {
    newWindow = window.open("", nomeFinestra, "width="+larghezza+",height="+altezza);
    newWindow.document.open();
    newWindow.document.write('<html><title>'+nomeFinestra+'</title><body leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" bgcolor='+bgcolor+' onClick=\"self.close()\">');
    newWindow.document.write('<table width='+larghezza+' border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" height='+altezza+' ><tr><td>');
    newWindow.document.write('<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"
									 ID=\"'+nomeFinestra+'\" WIDTH=\"'+larghezza+'\" HEIGHT=\"'+altezza+'\" ALIGN=\"\"> 
									 <PARAM NAME=movie VALUE=\"'+immagine+'"> <PARAM NAME=quality VALUE=high>
									  <EMBED src=\"'+immagine+'" quality=high WIDTH=\"'+larghezza+'\" HEIGHT=\"'+altezza+'\" swLiveConnect=true 
									 ID=\"'+nomeFinestra+'\" NAME=\"'+nomeFinestra+'\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>
									</OBJECT>');
    newWindow.document.write('</td></tr></table></body></html>');
    newWindow.document.close();
    newWindow.focus();
}*/

function changeImg(targ,selObj){
	var movie = selObj.options[selObj.selectedIndex].text;
	if(movie.indexOf(".swf")==-1){
		document.images[targ].src = selObj.options[selObj.selectedIndex].value;
	} else { 
		document.images[targ].src = "gif/banflash.gif";
	}
	document.getElementById("data"+targ).value = selObj.options[selObj.selectedIndex].text;
}

function confirmDelete() {
 	return (confirm('Sicuro di voler cancellare questa riga?\n L\'operazione non può essere annullata!'));
}
function loadImg(id, image, w, h){
	var imag = document.getElementById(id);
	imag.src = image;
	imag.width = w;
	imag.height = h;	
	var ratio = w/h;
	var winSize = getPageSize();
	var windowWidth = winSize[0];
	var windowHeight = winSize[1];

	if(imag.width>windowWidth){
		imag.width = windowWidth-100;
		imag.height = imag.width/ratio;
	}
	if(imag.height>windowHeight){
		imag.height = windowHeight-100;
		imag.width = imag.height*ratio;
	}
	//alert('winW='+windowWidth+'\r\nwinH='+windowHeight+'\r\nimgW='+imag.width+'\r\nimgH='+imag.height);
	
	var mydiv = document.getElementById("imgWindow");
	mydiv.style.left = (windowWidth-imag.width)/2;
	mydiv.style.top = (windowHeight-imag.height)/2;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		windowWidth 	= self.innerWidth;
		windowHeight 	= self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth 	= document.documentElement.clientWidth;
		windowHeight 	= document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth 	= document.body.clientWidth;
		windowHeight 	= document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function Chiudi(id){
	document.getElementById(id).style.visibility  = 'hidden';
}

function updAtt(id,cat_id){
	var attivo;
	var radioGrp =  eval('document.updattivo.attivo'+id);
	for (var i = 0; i< radioGrp.length; i++) {
		if (radioGrp[i].checked) {
			attivo = radioGrp[i].value;
		}
	} 
	switch(attivo){
		case "si":
			attivo="no";
			break;
		case "no":
			attivo="si";
			break;
	}
	//alert(attivo);
	location.href = '?lista=1&cmd=updAtt&cat_id='+cat_id+'&id='+id+'&attivo='+attivo;
}

// Movimento layer ###########################################################
function init(){
var Giu = true; 
var L, T, X, Y;
document.onmouseup = Su;
}

function Muovi(id) { 
//alert("event :"+event.srcElement.id+" id ="+id);	
  if (window.event.srcElement.id != "imag"){ 
//alert("move");	
    Giu = true; 
    document.onmousemove = function(){
		chgPos(id);
	}; 
    L = document.getElementById(id).style.pixelLeft; 
    T = document.getElementById(id).style.pixelTop; 
    X = event.clientX; 
    Y = event.clientY; 
  } 
} 

function chgPos(id) { 
  if (Giu){ 
   	document.selection.clear( );
    document.getElementById(id).style.pixelLeft = L + event.clientX - X; 
    document.getElementById(id).style.pixelTop = T + event.clientY - Y; 
  } 
} 
function Su() { Giu = false; } 

function hideMenu(id) { 
	if (document.all) { 
		if ( document.all[id].style.visibility=="visible") document.all[id].style.visibility="hidden"; 
		else document.all[id].style.visibility="visible"; 
		/*cambio la visibilità da visibile a invisibile con IE*/ 
	} else if (document.layers){ //NN4 
		if (document.layers[id].visibility=="show") document.layers[id].visibility="hide"; 
		else document.layers[id].visibility="show"; 
	} else if (document.getElementById) { //NN6 ed Opera 
		if (document.getElementById(id).style.visibility=="visible") document.getElementById(id).style.visibility="hidden"; 
		else document.getElementById(id).style.visibility="visible"; 
	} 
}
//#############################################################################

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+2];
			if (obj.style) { 
				obj=obj.style; 
				v=(v=='show')?'visible':(v=='hide')?'hidden':v;
				obj.visibility=v;
			}
		}
	}

}
function today(){
	var now = new Date( );
	var giorno = now.getDate();
	var mese = now.getMonth()+1;
	var anno = now.getFullYear();
	if(giorno<10) giorno = "0"+giorno;
	if(mese<10) mese = "0"+mese;

	document.getElementById("gg").value = giorno;
	document.getElementById("mm").value = mese;
	document.getElementById("aa").value = anno;
}


function confirmDelete(cosa) {
 	return (confirm('Sicuro di voler cancellare '+cosa+'? L\'operazione non può essere annullata!'));
}

function movieDelete() {
 	return (confirm('Sicuro di voler cancellare questa riga?\n L\'operazione non può essere annullata!'));
}



function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_findObj(n, d) {
    var p, i, x;
    if (!d) {
        d = document;
    }
    if ((p=n.indexOf("?"))>0 && parent.frames.length) {
        d = parent.frames[n.substring(p+1)].document;
        n = n.substring(0, p);
    }
    if (!(x=d[n]) && d.all) {
        x = d.all[n];
    }
    for (i=0; !x && i<d.forms.length; i++) {
        x = d.forms[i][n];
    }
    for (i=0; !x && d.layers && id.layers.length; i++) {
        x = findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}

function MM_validateForm() {
    var i, p, q, nm, test, num, min, max, errors = '', args = validateForm.arguments;
    for (i=0; i<(args.length-2); i += 3) {
        test = args[i+2];
        val = findObj(args[i]);
        if (val) {
            nm = val.name;
            if ((val=val.value) != "") {
                if (test.indexOf('isEmail') != -1) {
                    p = val.indexOf('@');
                    if (p<1 || p == (val.length-1)) {
                        errors += '- '+nm+' deve essere un indirizzo valido.\n';
                    }
                } else if (test != 'R') {
                    num = parseFloat(val);
                    if (isNaN(val)) {
                        errors += '- '+nm+' deve essere un numero.\n';
                    }
                    if (test.indexOf('inRange') != -1) {
                        p = test.indexOf(':');
                        min = test.substring(8, p);
                        max = test.substring(p+1);
                        if (Number(num)<min || max<Number(num)) {
                            errors += '- '+nm+' deve contenere un numero compreso tra '+min+' e '+max+'.\n';
                        }
                    }
                }
            } else if (test.charAt(0) == 'R') {
                errors += '- '+nm+' è un campo richiesto.\n';
            }
        }
    }
    if (errors) {
        alert('Si sono verificati i seguenti errori:\n'+errors);
    }
    document.returnValue = (errors == '');
}
function movieDelete() {
 	return (confirm('Sicuro di voler cancellare questa riga?\n L\'operazione non può essere annullata!'));
}

function findObj(n, d) {
    var p, i, x;
    if (!d) {
        d = document;
    }
    if ((p=n.indexOf("?"))>0 && parent.frames.length) {
        d = parent.frames[n.substring(p+1)].document;
        n = n.substring(0, p);
    }
    if (!(x=d[n]) && d.all) {
        x = d.all[n];
    }
    for (i=0; !x && i<d.forms.length; i++) {
        x = d.forms[i][n];
    }
    for (i=0; !x && d.layers && id.layers.length; i++) {
        x = findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}

function validateForm() {
    var i, p, q, nm, test, num, min, max, errors = '', args = validateForm.arguments;
    for (i=0; i<(args.length-2); i += 3) {
        test = args[i+2];
        val = findObj(args[i]);
        if (val) {
            nm = val.name;
            if ((val=val.value) != "") {
                if (test.indexOf('isEmail') != -1) {
                    p = val.indexOf('@');
                    if (p<1 || p == (val.length-1)) {
                        errors += '- '+nm+' deve essere un indirizzo valido.\n';
                    }
                } else if (test != 'R') {
                    num = parseFloat(val);
                    if (isNaN(val)) {
                        errors += '- '+nm+' deve essere un numero.\n';
                    }
                    if (test.indexOf('inRange') != -1) {
                        p = test.indexOf(':');
                        min = test.substring(8, p);
                        max = test.substring(p+1);
                        if (Number(num)<min || max<Number(num)) {
                            errors += '- '+nm+' deve contenere un numero compreso tra '+min+' e '+max+'.\n';
                        }
                    }
                }
            } else if (test.charAt(0) == 'R') {
                errors += '- '+nm+' è un campo richiesto.\n';
            }
        }
    }
    if (errors) {
        alert('Si sono verificati i seguenti errori:\n'+errors);
    }
    document.returnValue = (errors == '');
}
