//(C) C.Tarozzi 2003
var maxchars=250;

function CheckLength()   {
 with (document.modulo){
    chars=testo.value
    if (chars.length > maxchars) {
		testo.value=chars.substr(0,maxchars);
		testo.blur();
		alert('massimo ' + maxchars + ' caratteri!')
	}
    chr.value=maxchars-testo.value.length;
 }
}

function nof_input_e() {
	document.qform.oeta.value=document.qform.neta.value; 
	document.qform.os_anni.value=document.qform.neta.value;
	document.qform.seta.value=document.qform.neta.value;		
} 

function nof_input_p() {
	document.qform.opeso.value=document.qform.npeso.value; 
	document.qform.os_peso.value=document.qform.npeso.value;
	document.qform.speso.value=document.qform.npeso.value;		
}
 
function orai_input_e() {
	document.qform.neta.value=document.qform.oeta.value; 
	document.qform.os_anni.value=document.qform.oeta.value;
	document.qform.seta.value=document.qform.oeta.value;		
} 

function orai_input_p() {
	document.qform.npeso.value=document.qform.opeso.value; 
	document.qform.os_peso.value=document.qform.opeso.value;
	document.qform.speso.value=document.qform.opeso.value;		
} 

function osiris_input_e() {
	document.qform.neta.value=document.qform.os_anni.value; 
	document.qform.seta.value=document.qform.os_anni.value;
	document.qform.oeta.value=document.qform.os_anni.value;		
} 

function osiris_input_p() {
	document.qform.npeso.value=document.qform.os_peso.value; 
	document.qform.speso.value=document.qform.os_peso.value;
	document.qform.opeso.value=document.qform.os_peso.value;		
} 

function score_input_e() {
	document.qform.neta.value=document.qform.seta.value; 
	document.qform.os_anni.value=document.qform.seta.value;
	document.qform.oeta.value=document.qform.seta.value;		
} 

function score_input_p() {
	document.qform.npeso.value=document.qform.speso.value; 
	document.qform.os_peso.value=document.qform.speso.value;
	document.qform.opeso.value=document.qform.speso.value;		
}

//(C) C.Tarozzi 2003
function statcalc() {
    var vtp=eval(document.scalc.tp.value);
	var vtn=eval(document.scalc.tn.value); 
	var vfp=eval(document.scalc.fp.value);
	var vfn=eval(document.scalc.fn.value);
	if(isNaN(vfn) || isNaN(vtn) ||	isNaN(vfp) || isNaN(vfn)) {
	alert("introduci tutti idati");
	return(false)
	}
	//	
	document.scalc.t.value=vtp+vtn+vfp+vfn;
	document.scalc.tpm.value=vtp+vfn;	
	document.scalc.tps.value=vtn+vfp;
	document.scalc.tpp.value=vtp+vfp;
	document.scalc.tpn.value=vtn+vfn;
	pvpt=Math.round(vtp/document.scalc.tpp.value*100)/100;
	pvnt=Math.round(vtn/document.scalc.tpn.value*100)/100;
	acc=Math.round((vtp+vtn)/document.scalc.t.value*100)/100; 
	sen=Math.round(vtp/document.scalc.tpm.value*100)/100;
	spe=Math.round(vtn/document.scalc.tps.value*100)/100;	
	//
	document.scalc.accu.value=acc;
	document.scalc.sens.value=sen;
	document.scalc.spec.value=spe;
	document.scalc.vptp.value=pvpt;	
	document.scalc.vptn.value=pvnt;
	//

}

function calcola() {		// bmi e superficie corporea
    var p = eval(document.bmi.peso.value);
    var a = eval(document.bmi.altezza.value)/100;
    var flag = true,risultato=0;
    if (p<30 || p>160){
        alert("range: da Kg.30 a Kg. 160");
        flag=false; 
    }
    if (a<1.10 || a>2.10){
        alert("range: da cm.110 a 210");
        flag=false;
    }   
    risultato= Math.round(p/(a*a));    
    if (isNaN( Math.round(p/(a*a))) ){
    	flag = false; 
    }   
    if (flag) {
        document.bmi.massa.value=risultato;
        if(risultato <19 )
            document.bmi.commento.value="Sottopeso";
        if(risultato >=19 && risultato <=25)
            document.bmi.commento.value="Normopeso";
        if(risultato >25 && risultato <=30)
            document.bmi.commento.value="Sovrappeso";
        if(risultato >30 && risultato <=35)
            document.bmi.commento.value="Obesita' grado 1";
        if(risultato >35 && risultato <=40)
            document.bmi.commento.value="Obesita' grado 2";
        if(risultato >40)
            document.bmi.commento.value="Obesita' grado 3";
        }
    	
    	scrisultato=Math.round( (Math.pow(a*100,0.725)*Math.pow(p,0.425)*0.007184)*100)/100;
   	    document.bmi.supco.value=scrisultato;
	    //return flag2
                

    	//return flag
}

function help(){
	alert('Ricerca in Archivio\nIntrodurre uno o vari termini di ricerca\ne cliccare su "cerca"\nSi possono usare anche\ngli operatori logici AND e OR (maiuscoli!)');
}

function checkform(f) {
	var error='';
	if(f.cerca.value.length<3)
		error+=' una parola di almeno tre lettere';
	if (error != '') {
		alert('Prego, introdurre ' + error);
	} 
	return error=='';
}

// window.open sempre focus

var child_window=null;
var parent_window=window;

function popUponClick(f){
	child_window = window.open("rasmus.html", "mySelect", "status=0,width=250,height=311,resizable=1"); 
	parent_window.onclick = blurify;
	parent_window.onfocus = blurify;
	return false;
}

function blurify(){
	if(child_window){
		if(parent_window)
			parent_window.blur();
		child_window.focus();
	}
}			
