// CODE FOR POPUP WINDOWS
function launch(newURL, newName, newFeatures, orgName){
  var remote = open(newURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
}

function popup(url, name, width, height){
	mywinpos = findscreencenter(width,height);
	settings=
	"toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=yes,"+
	"resizable=no,width="+width+",height="+height+",top="+mywinpos[0]+",left="+mywinpos[1];
	orgname="mymain";
	MyNewWindow=launch(url,name,settings,orgname);
	return MyNewWindow;
}

function findscreencenter( pwinwidth, pwinheight ){
    winpos = new Array(2);
    scrheight = screen.height;
    scrwidth = screen.width;
    wintop = (scrheight - pwinheight-100) / 2;
    winleft = (scrwidth - pwinwidth) / 2;
    winpos[0] = wintop;
    winpos[1] = winleft;
    return winpos;
}
function reportError(){
 	 alert('Errore nel collegamento con il server. Operazione non riuscita');
}
function resize(width, height){
	mywinpos = findscreencenter(width, height);
	self.resizeTo(width, height);
	self.moveTo(mywinpos[1],mywinpos[0]);
}
function chOpacity(id,n){
	var element=document.getElementById=(id);
	element.style.opacity="'"+n+"'";
	var n1=Math.round(n*100);
	element.style.filter = "alpha(opacity="+n1+")";
}
function fadeTo (id, time, interval, opacity){
	// opacità  da 0 a opacity
	var i;
	var j=(1.0-opacity)/interval;
	for(i=1.0;i>=opacity;i=i-j){
		timer = setTimeout(chOpacity(id,i),time/interval);
	}
}
function get(target, url, pars){
     var myajax=new Ajax.Updater(target, url, {method: 'get', 
                                               parameters: pars , 
                                               asynchronous: true,
                                               onFailure: reportError , 
                                               evalScripts: true, 
                                               onLoading: displayIcon(target)});
}
function post(frm, target, url){
     //var params = Form.serialize($('_form'));
     var pars = Form.serialize(frm);
     var myajax=new Ajax.Updater(target, url, {method: 'post', 
                                               parameters: pars , 
                                               onFailure: reportError, 
                                               evalScripts: true, 
                                               onLoading: displayIcon(target)});
}
function reportError(){
 	 alert('Errore nel collegamento con il server. Operazione non riuscita');
}
function displayIcon(target){
	 try {
	    t=$(target);
 	    t.innerHTML="<img src='img/loading.gif'> Attendere...";
	 } catch(e){
        return;
     }
}
