function showDay(date) {
        document.getElementById('day' + date).style.visibility = 'visible';
        document.getElementById('day' + date).style.display = 'block';
        return true;
    }    

    function hideDay(date) {
        document.getElementById('day' + date).style.visibility = 'hidden';
        document.getElementById('day' + date).style.display = 'none';
        return true;
    }

function confirmLink(theLink, confirmMsg )
{
    var is_confirmed = confirm(confirmMsg);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
} 




function isBlank(s) {
for (var j=0;j<s.length;j++) {
     var c=s.charAt(j);
     var rtn=String.fromCharCode(13);
     var crg=String.fromCharCode(10);
     if ((c !=' ') && (c !='\n') && (c != '\t') && (c != rtn) && (c != crg)) return false;
 }
return true;
}

// funzione che controlla se i campi obbligatori sono stati compilati
// ritorna, in caso contrario, una finestra di alert con un messaggio di errore

function controlla(f){
 var msg;
 var empty_fields ="";

            for (var i=0;i<f.length;i++) {
		var e=f.elements[i];
                if (e.obbligatorio || e.almenouno)   {
			if ((e.value==null) || (e.value=="") || isBlank(e.value)) {
				   if (e.almenouno) {
						altri=false;
						es=f.elements[i+e.item];
						if ((es.value!=null) && (es.value!="") && !isBlank(es.value)) altri=true;
						if (!altri) empty_fields +="\n          " + e.tip;
				} else {
				 empty_fields +="\n          " + e.tip;
				}
			}
		   }
		} // for
		
                if (!empty_fields) return true; 
		else {
			msg="il modulo non è stato compilato correttamente\n";
	        	msg+="i seguenti campi obbligatori risultano vuoti:" + empty_fields + "\n";
			alert(msg);
		}
		return false;
 } 


// questa funzione controlla che almeno una scelta sia stata fatta nel form


function controlla_almeno_uno(f){
var msg;
var no_empty_fields =0;

for (var i=0;i<f.length;i++) {
var e=f.elements[i];
if ((e.type!="submit") && (e.type!="reset") && (!e.nocontrol)) {
                 if ((e.value!=null) && (e.value!="") && (!isBlank(e.value))) {
                       	no_empty_fields = 1;
			return true;
			}
		} // for
}
                if (!no_empty_fields) 
		 {
			msg="Nel modulo non è stata introdotto nessun criterio di ricerca!\n";
	        	msg+="Bisogna introdurre almeno un criterio!";
			alert(msg);
		}

 return false;
} 

function enabledisablebyindex(indx) {
var e=document.addcontent.elements[indx];
if (e) {
 if (e.disabled) {
	e.disabled=false;
	e.focus();
 } else e.disabled=true;
}

}

function enabledisablebyname(name) {
eval("var e=document.addcontent." + name);
if (e) {
 if (e.disabled) {
	e.disabled=false;
	e.focus();
 } else e.disabled=true;
}

}

function enabledisableoption(selvalue,indx) {
var e=document.addcontent.elements[indx];
if (e) {
 if (selvalue>0) {
	if (!e.disabled) e.disabled=true;
 } else e.disabled=false;
}
}

function setoption(seltext,indx) {
var allclassi=new Array();
allclassi["4A"]=1;
allclassi["5C"]=2;
allclassi["5D"]=3;
allclassi["2A"]=4;
allclassi["3A"]=5;
allclassi["teacher"]=6;
allclassi["POSEIDON_Class"]=7;

var e=document.addcontent.elements[indx];
if (e) {
  if (seltext!="root") {
	var classi=seltext.match(/\([^w]+\)/);
	classilist=classi[0].substring(1,classi[0].length-1);
	classarr=classilist.split(",");
   	for(var i=e.length-1;i>=0;i--){
	   e.options[i]=null;
    		}
   	for(var i=0;i<classarr.length;i++) {
	  e.options[i]=new Option(classarr[i],allclassi[classarr[i]]);
   	}
  } else {
   	for(var i=e.length-1;i>=0;i--){
	   e.options[i]=null;
    	}
	i=0;
	for(var c in allclassi) {
	  e.options[i]=new Option(c,allclassi[c]);
	  i++;
	}

  }
 }
}

function aprifine(url, name, w, h) {
  popupWin =window.open(url,name,'width='+w+',height='+h+',left=20,top=10,scrollbars=yes,resizable=yes');
}


function viewtask() {
 var e=document.addcontent.c_idt;
 if (e) {
   if ((e.value==null) || (e.value=="") || (isBlank(e.value))) {
                  alert("Choose the document category!!"); 
	} else {
 	  url="../readtask.php?tID=" + e.value;
	  aprifine(url,"task", 600, 200)
	}
 }
}

