// funzione per evidenziare righe di tabelle dinamicamente
function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
	return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
	var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
	var theCells = theRow.cells;
    }
    else {
	return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
	theCells[c].style.backgroundColor = thePointerColor;
    }

    return true;
}			

function hidepass() {
	document.auth.password.value = document.auth.password2.value;
	document.auth.password2.value = "";
}

function comune(valore) {   
	window.opener.document.forms[0].comune.value = valore;
	window.opener.document.forms[0].comune.select();
	window.opener.document.forms[0].comune.focus();
	window.close();
}

function setmedico(valore) {   
	window.opener.document.forms[0].medico.value = valore;
	window.opener.document.forms[0].medico.select();
	window.opener.document.forms[0].medico.focus();
	window.close();
}

function mywindowopen(mypage,myname,w,h){
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no,fullscreen=no,channelmode=no,menubar=no,toolbar=no,location=no,status=no';
	win = window.open(mypage,myname,settings);
	if(win.window.focus){win.window.focus();}
}

function attivo(input) {
	input.style.backgroundColor="#ffffcc";
}

function normale(input) {
	input.style.backgroundColor="#ffffff";
}

function controlla_glicemia(valore) {
	if( parseInt(valore) > 126 ) {
		document.schedaima.diabete.selectedIndex = 1;
		alert('Valore Glicemia > 126 mg/dl\nDiabete "Si" impostato automaticamente ');
	}
}

function controlla_PAS(valore) {
	if( parseInt(valore) > 140 ) {
		document.schedaima.ipert_arteriosa.selectedIndex = 1;
		alert('Valore PAS > 140 mmHg\nIpertensione arteriosa "Si" impostata automaticamente ');
	}
}

function controlla_PAD(valore) {
	if( parseInt(valore) > 90 ) {
		document.schedaima.ipert_arteriosa.selectedIndex = 1;
		alert('Valore PAD > 90 mmHg\nIpertensione arteriosa "Si" impostata automaticamente ');
	}
}

function controlla_LDL(valore) {
	if( parseInt(valore) > 100 ) {
		document.schedaima.ipercolesterolemia.selectedIndex = 1;
		alert('Valore LDL-Colesterolo > 100 mg/dl\nIpercolesterolemia "Si" impostata automaticamente ');
	}
}

function controlla_trigliceridi(valore) {
	if( parseInt(valore) > 200 ) {
		document.schedaima.trigliceridemia.selectedIndex = 1;
		alert('Valore Trigliceridi > 200 mg/dl\nIpertrigliceridemia "Si" impostata automaticamente ');
	}
}

function controlla_circadd(sesso,valore) {
	if( sesso == 'M') {
		if( parseInt(valore) > 102 ) {
			document.schedaima.sovrappeso.selectedIndex = 1;
			document.schedaima.obesita.selectedIndex = 1;
			alert('Valore Circonferenza Addominale > 102 cm\nSovrappeso/Obesità "Si" impostati automaticamente ');
		}
	}
	else {
		if( parseInt(valore) > 89 ) {
			document.schedaima.sovrappeso.selectedIndex = 1;
			document.schedaima.obesita.selectedIndex = 1;
			alert('Valore Circonferenza Addominale > 89 cm\nSovrappeso/Obesità "Si" impostati automaticamente ');
		}
	}
}

function controlla_BMI(valore) {
	if( parseInt(valore) >= 25 ) {
		if( parseInt(valore) >= 30 ) {
			document.schedaima.sovrappeso.selectedIndex = 1;
			document.schedaima.obesita.selectedIndex = 1;
			alert('Valore BMI > 29.9 Kg/m2\nSovrappeso/Obesità "Si" impostati automaticamente ');
		}
		else {
			document.schedaima.sovrappeso.selectedIndex = 1;
			alert('Valore BMI compreso tra 25 e 29.9 Kg/m2\nSovrappeso "Si" impostato automaticamente ');
		}
	}
}

/*
**************************************
* Event Listener Function v1.4       *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/

addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

/**************************************
» Autor: Jonas Raoni Soares Silva
» Site: http://www.joninhas.ath.cx:666
**************************************/

enterAsTab = function(){
	for( i = ( f = document.forms ).length; i; addEventListener( f[--i], "keypress", function( evt ){
		var el, l, k = evt.key == 13, e = evt.target;
		if( k && !/textarea|select/i.test( e.type ) && !evt.preventDefault() ){
			for( l = k = ( el = e.form.elements ).length; el[--k] != e; );
			while( !(e = el[ k = ++k * ( k < l ) ]).type || e.disabled );
			e.focus();
		}
	} ) );
};