function mmenu(mID) {
	var menu = document.getElementById(mID);
	var display = menu.style.display;
	menu.style.display = (display == "block")?"none":"block";
}

function checkForm(formname){
	formname = document.getElementById(formname);
	countbox = 0;
	boxchecked = 1;
	for(i=0; i<formname.length; i++){
		if(formname.elements[i].type == "text" || formname.elements[i].type == "textarea"){
			if(formname.elements[i].className == "required"){
				if(formname.elements[i].value == ""){
					alert("il campo "+formname.elements[i].id+" è vuoto.");
					return false;
				}
			}
		}
		if(formname.elements[i].type == "select-one"){
			if(formname.elements[i].className == "required"){
				if(formname.elements[i].options[formname.elements[i].selectedIndex].value == ""){
					alert("il campo "+formname.elements[i].id+" è vuoto.");
					return false;
				}
			}
		}
		if(formname.elements[i].type == "radio"){
			if(formname.elements[i].className == "required"){
				radiochecked = 0;
				radiogroup = formname.elements[formname.elements[i].name];				
				for(j = 0; j < radiogroup.length; j++){
					if(radiogroup[j].checked){
						radiochecked = 1;
					}
				}
				if(radiochecked == 0) {
					alert("il campo "+formname.elements[i].name+" è vuoto.");
					return false;
				}
			}
		}
		if(formname.elements[i].type == "checkbox"){
			if(formname.elements[i].className == "required"){
				if(countbox == 0){
					countbox = 1;
					boxchecked = 0;
				}
				if(formname.elements[i].checked){
					boxchecked = 1;
				}
			}
		}
		if(formname.elements[i].id == "email"){
			if(formname.elements[i].className == "required"){
				if(checkEmail(formname.elements[i].value) == false){
					alert("il campo "+formname.elements[i].id+" non è un indirizzo di posta valido.");
					return false;
				}
			}
		}
	}
	if(boxchecked == 0){
		alert("Alcuni campi sono stati lasciati vuoti.");
		return false;
	}
	return true;
}

function checkEmail(email){
	var str = Trim(email);
	var val_mail = "^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
	var link_reg_exp = new RegExp(val_mail);
	if(str != ""){
		if(link_reg_exp.test(str)){
			return true;
		} else{
			return false;
		}
	}
}

function Trim(field) { 
return field.replace(/\s+$|^\s+/g,""); 
}

function ApriImmagini(file, w, h){
	//w = w + 20;
	//h = h + 20;
	var prop = "width=" + w + ", height=" + h + ", top=100, left=100"; // Altre proprietà... eccetto width ed height!
	window.open(file, null, prop);
}

function formSend(frm) {
	if(checkForm(frm)){
		formname = document.getElementById(frm);
		formname.submit();
	}
}


function switchDivGraph(origin) {
	var orig = document.getElementById(origin);
	var dest = document.getElementById('graficiSfondo');
	dest.innerHTML = orig.innerHTML;
	switchLabelGraph(origin);
}

function switchLabelGraph(label) {
	var labelsDiv = document.getElementById('graficiMenu');
	var labels = labelsDiv.getElementsByTagName('a');
	for( var i = 0; i < labels.length; i++ ) {
	if ( labels[i].id == 'grafico-' + label ) {
			labelsDiv.style.backgroundImage = 'url(/img/graficiMenu_' + label + '.jpg)';
		}
	}
}

function showFaqOnLoad(){
	if(window.location.hash != ''){
		if(window.location.hash.indexOf('#faq-') > -1) {
			id = window.location.hash.replace('#faq-', "");
			if(document.getElementById('submenu-' + id))
				document.getElementById('submenu-' + id).style.display = 'block';
		}
	}
}

function showGlossarioOnLoad(){
	if(window.location.hash != ''){
		if(window.location.hash.indexOf('#glossario-') > -1) {
			id = window.location.hash.replace('#glossario-', "");
			if(document.getElementById('submenu-' + id))
				document.getElementById('submenu-' + id).style.display = 'block';
		}
	}
}
