var newwin;

function swap(){
	var i,j=0,x,a=swap.arguments;document.sr=new Array; for(i=0;i<(a.length-1);i+=2)
	if ((x=find(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+1];}
}
function swaprest(){
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function preload(){
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preload.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function send(n){
	var f=find(n); f.submit();
}

function popup(i,n,p){
	window.open(i,n,p);
}

function find(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&&i<d.layers.length;i++) x=find(n,d.layers[i].document); return x;
}

function zoom(img,w,h,tit){
	var popup,dim='width='+w+',height='+h;
	popup=open('','popup',dim);
	if(!tit) tit='Zoom';
	with (popup.document){
	open("text/html", "replace");
	write('<html><head><title>'+tit+'</title></head>\n');
	write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onload="self.focus()">\n');
	write('<a href="javascript:self.close()" title="Click to close"><img src="'+img+'" width='+w+' height='+h+' border=0></a>\n');
	write('</body></html>');
	close()}
}

function preview(obj){
	if (!newwin || (newwin && newwin.closed)) {
		newwin=window.open('','newwin','width=300,height=400,status=yes,scrollbars=yes,resizable=yes')
	}

	var ta=find(obj);

	if (document.selection) {
		//IE
		with (newwin.document){
			open("text/html", "replace");
			write('<html><head><title>Anteprima</title>\n<link href="/css/adm.css" rel="stylesheet" type="text/css">\n');
			write('</head><body><div class="normal4"></div></body></html>');
			close()
		}

		var preview = newwin.document.body.createTextRange();
		preview.pasteHTML(ta.value);
	} else if (ta) {
		//netscape
		with (newwin.document){
			open("text/html", "replace");
			write('<html><head><title>Anteprima</title>\n<link href="/css/adm.css" rel="stylesheet" type="text/css">\n');
			write('</head><body>');
			write('<span class="normal4">'+ta.value+'<span>');
			write('</body></html>');
			close()
		}
	}
	newwin.focus();
}

function inserisciDoppioTag(campo, tag) {
	myField = find(campo);
	if (document.selection && document.selection.createRange) { 
		myField.focus();
		var range = document.selection.createRange();
		range.text = '<' + tag + '>' + range.text + '<\/' + tag + '>' 
	} else if (myField && myField.selectionStart) { 
        // MOZILLA/NETSCAPE support 
        var startPos = myField.selectionStart; 
        var endPos = myField.selectionEnd; 
        if (startPos != 0 || endPos != 0) { 
	        var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd); 
	        mySelection =  '<' + tag + '>' + mySelection + '<\/' + tag + '>'; 
	        myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length); 
    	} 
   	} 
	else if (document.forms[0].myField) { 
    	myField.value += '<' + tag + '>' + range.text + '<\/' + tag + '>'; 
    }
} 

function inserisciTag(campo, tag) {
	var myField = find(campo);
	if (document.selection && document.selection.createRange) { 
		myField.focus();
		var range = document.selection.createRange();
		range.text = range.text + '<' + tag + '>' 
	} else if (myField && myField.selectionStart) { 
        // MOZILLA/NETSCAPE support 
        var startPos = myField.selectionStart; 
        var endPos = myField.selectionEnd; 
        if (startPos != 0 || endPos != 0) { 
	        var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd); 
	        mySelection =  mySelection + '<' + tag + '>'; 
	        myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length); 
    	} 
   	} 
	else if (document.forms[0].myField) { 
    	myField.value += range.text + '<' + tag + '>'; 
    }
} 

function inserisciLink(campo) { 
	var myField = find(campo);
	if (document.selection && document.selection.createRange) { 
    	address = prompt('Immettere l\'indirizzo internet relativo al link da inserire:', 'http://'); 
		myField.focus();
		var range = document.selection.createRange();
        range.text = '<a href=\"' + address + '\">' + range.text + '<\/a>'; 
    } else if (myField && myField.selectionStart) { 
	    // MOZILLA/NETSCAPE support 
        address = prompt('Immettere l\'indirizzo internet relativo al link da inserire:', 'http://'); 
        var startPos = myField.selectionStart; 
        var endPos = myField.selectionEnd; 
        if (startPos != 0 || endPos != 0) { 
	        var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd); 
            mySelection =  '<a href=\"' + address + '\">' + mySelection + '<\/a>'; 
			myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length); 
        }
	}
	else if (document.forms[0].myField) { 
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
