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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newwindow=window.open(theURL,winName,features);
  
  if (window.focus) {newwindow.focus()}

}

/*function voce(cosa, authority, poscampo)
{
	//alert("voce:"+cosa+"\n aut:"+authority+"\n"+poscampo);
	//if(voce=="")
		document.getElementById('aut_autori').src = "../../cgi-bin/wxis.exe?IsisScript=napoli/napoli.xis&dbaf="+authority+"&option=voce&autore_principale_p=a"+"&poscampo="+poscampo;
	
	else
		parent.frames.aut_autori.location.href="http://localhost/cgi-bin/wxis.exe?IsisScript=napoli/napoli.xis&dbaf="+authority+"&option=voce&autore_principale_p="+cosa+"&poscampo="+poscampo;
	
}*/

/*function insvoce(autorisel, ritcampo)
{
	//alert("1"+autorisel+"\n2"+ritcampo);
	
	if (eval("parent.document.inte."+ritcampo+".type == 'textarea'"))
		eval("parent.document.inte."+ritcampo+".value += autorisel");
	else
		eval("parent.document.inte."+ritcampo+".value = autorisel");
}*/
function insvoce(autorisel, ritcampo)
{
	//alert("1"+autorisel+"\n2"+ritcampo); //solo per debug
	if (eval("parent.document.inte."+ritcampo+".type == 'textarea'"))
		eval("parent.document.inte."+ritcampo+".value += autorisel +'\\r\\n'");
	else
		eval("parent.document.inte."+ritcampo+".value = autorisel");
}


if (document.images) {
offButton = new Image;
onButton = new Image;

offButton.src = "images/bt_authority.gif";
onButton.src = "images/bt_authority_hi.gif";
}
else {
offButton = "" ;
onButton = "";

document.myButton = "";
}

function chibussa()
{
	window.open('login.php','login', 'resizable=no,width=300,height=450,top=0,left=0,noresize,scrollbars=no');
}

function addOptions(ritcampo, scelto) {//inserisci opzione
    //alert(scelto+"\n"+ritcampo);
	
	
	if(ritcampo == 'autore_principale_p' || ritcampo == 'autore_ente' || ritcampo =='titolo_uniforme'){
			
			if(ritcampo == 'autore_principale_p'){
				document.inte.autore_ente.value = '';
				document.inte.titolo_uniforme.value = '';
			}
			else if(ritcampo == 'autore_ente'){
				document.inte.autore_principale_p.value = '';
				document.inte.titolo_uniforme.value = '';
			}
			else if(ritcampo == 'titolo_uniforme'){
				document.inte.autore_principale_p.value = '';
				document.inte.autore_ente.value = '';
			}


	}
	
	
    if (eval("parent.document.inte."+ritcampo+".type == 'select-multiple'")){//campo ripetibile
        if(confirm("Vuoi aggiungere questo record?\n\n"+scelto)){
            //var selbox = parent.document.inte.autore_ente;
            var selbox = eval("parent.document.inte."+ritcampo);
            if (selbox.options[0].value == " ")
                selbox.options.length = 0;
            var fnd = 0;
            for (n=0;n<selbox.length;n++){
                if(selbox.options[n].text == scelto)
                    fnd = 1;
            }
            if (!fnd){
                selbox.options[selbox.options.length] = new Option(scelto, scelto);
               for(var i = 0;i < selbox.length;i++){
                    selbox.options[i].selected = true;
               }
			   ritcampoHID=ritcampo.replace("mat", "");
			   eval("parent.document.inte."+ritcampoHID+".value += scelto+'@#@'");
            }
        }
    }
    else if (eval("parent.document.inte."+ritcampo+".type == 'textarea'")){
		eval("parent.document.inte."+ritcampo+".value += scelto");
    }
    else //campo non ripetibile
    {
        if(confirm("Vuoi inserire questo record?\n\n"+scelto))
            eval("parent.document.inte."+ritcampo+".value = scelto");
    }

    newwindow.close();

}

function delOptions(ritcampo, scelto) {//cancella opzione
    //var selbox = document.inte.autore_ente;
     if (eval("document.inte."+ritcampo+".type == \'select-multiple\'")){//campo ripetibile
        var selbox = eval("document.inte."+ritcampo);
		ritcampoHID=ritcampo.replace("mat", "");
        if (selbox.options[0].value != " ") {
            nomatch = new Array();
            for (n=0;n<selbox.length;n++){
                if(selbox.options[n].text != scelto)
                    nomatch[nomatch.length] = new Array(selbox.options[n].value, selbox.options[n].text);
            }
            selbox.options.length = 0;
            if (nomatch.length == 0){
                selbox.options[0]= new Option("Selezionare da AF"," ");
				eval("parent.document.inte."+ritcampoHID+".value = ''");
			}
            else{
				eval("parent.document.inte."+ritcampoHID+".value = ''");
                for (n=0;n<nomatch.length;n++){
                    selbox.options[n] = new Option(nomatch[n][1], nomatch[n][0]);
					//alert(nomatch[n][0]);
					eval("parent.document.inte."+ritcampoHID+".value += nomatch[n][0]+'@#@'");
				}
            }
        }
    } 
    else{
        eval("parent.document.inte."+ritcampo+".value = ''");
    }
}

function beddamatrix(campomat){
    splitcampomat = campomat.split(",")
    var matrice = "";
    for(var x = 0;x < splitcampomat.length;x++){
        var quanti = (splitcampomat[x].length-3);
        var campohid = splitcampomat[x].substring(0, quanti);
        var selbox =  eval("document.inte."+splitcampomat[x]);
        for(var i = 0;i < selbox.length;i++){
            selbox.options[i].selected = true;
        }
        for (n=0;n<selbox.length;n++){
            matrice += selbox.options[n].value+"@taglia@";
        }
        //alert(campohid+"--"+x);
        var matricetot = matrice.length;
        var matricequanti = (matrice.length-8);
        matrice = matrice.substring(0, matricequanti);
        eval("document.inte."+campohid+".value=matrice");
        var matrice = "";
    }
}

function setCheckBox(bCheck) {
  // ciclo su tutti i controlli del modulo
  for (var i = 0; i < document.mioform.length; i++) {
  	// se il nome del controllo inizia con "chk"
    if (document.mioform.elements[i].type == "checkbox") {
      // imposto il valore = parametro bCheck
      document.mioform.elements[i].checked = bCheck;
    }
  }
}


function Popup(apri) 		{        window.open(apri, '', 'top=10, left=10, width=500, height=400, resizable=no, scrollbars=yes, toolbar=no, status=no, menubar=no');	    }



function sendSC(poscampo, note, valore) {
	
	eval("var noteRE = /\\^"+note+"/g");
	
	eval("var campo = document.inte."+poscampo+"mat");
	
	
	if (campo){
		
		if(eval("document.inte."+poscampo+"mat.options[0].value") != ' '){
			
			eval("var selOpt = document.inte."+poscampo+"mat.options[document.inte."+poscampo+"mat.selectedIndex].text");

			var res = selOpt.search(noteRE);

			if ( res == -1) {

				eval("document.inte."+poscampo+"mat.options[document.inte."+poscampo+"mat.selectedIndex].text += '^"+note+valore+"'");

				eval("document.inte."+poscampo+".value = ''");

				eval("var len = document.inte."+poscampo+"mat.options.length");

				for (n=0;n<len;n++){
					eval("document.inte."+poscampo+".value += document.inte."+poscampo+"mat.options["+n+"].text+'@#@'");
				}

			}
			else{
				alert('Attenzione!\n^'+note+' già presente');
			}
		}
		else{
		
			alert("Campo "+poscampo+" vuoto\nImpossibile aggiugere un sottocampo");
		
		}
		
	}
	else{
		eval("var valCampo = document.inte."+poscampo+".value");
	
		if(eval("document.inte."+poscampo+".value != ''")) {
			
			var res = valCampo.search(noteRE);

			if ( res == -1) {
				
				eval("document.inte."+poscampo+".value += '^"+note+valore+"'");
			}
			else{
			
				alert('Attenzione!\n^'+note+' già presente');
			
			}
		}
		else {
			alert("Campo "+poscampo+" vuoto\nImpossibile aggiugere un sottocampo");
		}

	}

}


function confirm_del_auth(voce) {
	
	var answer = confirm ("Premi OK per cancellare la voce "+voce+"\n dall'authority o CANCEL per annullare l'operazione");
	
	if (answer)
		return true;
	else
		return false;


}        