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 aprifine(url, name, w, h) 
{
  popupWin =window.open(url,name,'width='+w+',height='+h+',left=20,top=10,scrollbars=yes,resizable=yes');
}

function confirmLink(theLink, confirmMsgNum )
{

  var confirmMsg = new Array();

    confirmMsg[1] = "Sicuro di voler eliminare il contenuto? Verranno eliminati tutti i sottocontenuti.";

    var is_confirmed = confirm(confirmMsg[confirmMsgNum]);
    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="These fields are required.\nEmpty fields: " + empty_fields + "\n";
			alert(msg);
		}
		return false;
 } 



function controlla2(f)
{
 var msg;
 var cat_id, c_type;

            for (var i=0;i<f.length;i++) 
		{
		var e=f.elements[i];
                if (e.name == "c_id_cat")   
			{
			cat_id = e.value;
			}
		    if (e.name == "c_type")   
			{
			c_type = e.value;
			}

		} // for
		
            if ( ((cat_id ==null) || (cat_id =="") || isBlank(cat_id)) || ((c_type ==null) || (c_type =="") || isBlank(c_type)) )
		{
			msg = "All fields are required:\n";
			msg += ((cat_id ==null) || (cat_id =="") || isBlank(cat_id))?"content category is not selected\n":"";
			msg += ((c_type ==null) || (c_type =="") || isBlank(c_type))?"content type is not selected":"";
			alert(msg);
			return false;
		}
		
 } 

function controlla3(f)
{
 var msg;
 var t_content, t_group;

            for (var i=0;i<f.length;i++) 
		{
		var e=f.elements[i];
                if (e.name == "t_content")   
			{
			t_content = e.value;
			}
		    if (e.name == "t_group")   
			{
			t_group = e.value;
			}

		} // for
		
            if ( ((t_content ==null) || ( t_content =="") || isBlank(t_content)) || ((t_group == null) || (t_group =="") || isBlank(t_group)) )
		{
			msg = "All fields are required:\n";
			msg += ((t_content == null) || (t_content == "") || isBlank(t_content))?"task interacting content is not selected\n":"";
			msg += ((t_group == null) || (t_group == "") || isBlank(t_group))?"user group is not selected":"";
			alert(msg);
			return false;
		}
		
 } 



function controlla4(f)
{
 var msg;
 var t_content, t_id;

            for (var i=0;i<f.length;i++) 
		{
		var e=f.elements[i];
                if (e.name == "t_content")   
			{
			t_content = e.value;
			}
		    if (e.name == "t_id")   
			{
			t_id = e.value;
			}

		} // for
		
            if ( ( (t_id == null) || (t_id == "") || isBlank(t_id ) ) && ( ! ( (t_content == null) || (t_content == "") || isBlank(t_content) ) ) )
		{
			msg = "Task is not selected!\n";
			alert(msg);
			return false;
		}
		else return true; 
		
 } 



// questa funzione controlla che almeno una scelta sia stata fatta nel form


function get_elem_value(f, el_name)
{
            for (var i=0; i<f.length; i++) 
		{
			var el = f.elements[i];
			if ( el.name == el_name )
				{
					return el.value;
				}
		} // for

		return;
 } 



function controlla_mod_cat_form(f)
{
 var msg = '';
 
            for (var i=0; i<f.length; i++) 
		{
			var e = f.elements[i];
			var el_name = ' ' + e.name;

				if ( (e.type == "checkbox") && ( el_name.indexOf('del_cat') > 0) && e.checked)
				{
				 n = el_name.substr(el_name.indexOf('[') + 1, el_name.length - el_name.indexOf('[') - 2);
				 cat_name = "cat_name[" + n + "]";
				 msg += (msg)? "\n"  + get_elem_value(f, cat_name) : get_elem_value(f, cat_name);
				}
		} // for

			if (msg)
				{
				msg = "Confermi l'eliminazione delle categorie selezionate?\n\n" + msg;
				msg += "\n\nL'operazione eliminerà anche i contenuti della categoria ed è irreversibile!";
	        		return confirm(msg);
			}
			
		return true;
 } 



function add_user() 
{
var all_users = document.forms[0].elements[1];
group_users = document.forms[0].elements[5];
n_user = all_users.length;


for(var i = 0; i < n_user; i++) 
  {
	if (all_users.options[i].selected) 
	{
		pos = group_users.length; 
		group_users.options[pos] = new Option(all_users.options[i].text, all_users.options[i].value);
  		all_users.options[i] = null;
		i--;
	}
   }

} 

function remove_user() 
{
 var all_users = document.forms[0].elements[1];
 group_users = document.forms[0].elements[5];
 n_gr_user = group_users.length;

 for(var i = 0; i < n_gr_user; i++) 
  {		
	if (group_users.options[i].selected) 
	{
		pos = all_users.length; 
		all_users.options[pos] = new Option(group_users.options[i].text, group_users.options[i].value);
  		group_users.options[i] = null;
		i--;
	}
   }
} 


function select_all() 
{
 var group_users = document.forms[0].elements[5];
 
 for(var i = 0; i < group_users.length; i++) 
  {		
	group_users.options[i].selected = true; 
   }
 return true;
} 
