function checkAll()
{
	var nb;
	var chk;

	if (document.f2.SEL_ALL.value == 0)
	{
		chk=1;
		document.f2.visto.src="/img/visto_on.gif";
	}
	else
	{
		chk=0;
		document.f2.visto.src="/img/visto_off.gif";
	}

	nb = document.f2.recipe.length
	if( nb>0 )
	{
		for (var i=0;i<nb;i++)
		{
			var e = document.f2.recipe[i];
			e.checked = chk
		}
	}
	else
	{
		document.f2.recipe.checked=chk;
	}
	document.f2.SEL_ALL.value = chk;
}

function addCtg()
{
	//Caso in cui non ci siano checkbox = 0 categorie	
	if( document.f1.descCtg.value != "" ) {
			window.opener.document.f3.descNewCtg.value = document.f1.descCtg.value;
			window.opener.document.f3.submit();
			window.close();
	}
	else
	{
		alert(js_notvalidctgAlert);
	}
}

function winOpen()
{
	window.open('/recipebook/help.htm','help','resizable=yes,scrollbars=yes,width=552,height=550');
}

function OpenWindow()
{
	if( document.f1.totCtg.value >= 12 )
	{
		alert(js_notcreatectgAlert);
	}
	else
	{
		 
		window.open("rec_book_newctg.jsp","AddCategory",'width=400,height=130'); 
		
	}
}
		
function modifyCtg()
{
	var ctgSel = 0;
	//Caso in cui non ci siano checkbox = 0 categorie	
	if(document.f1.category)
	{
		//Caso in cui ci siano pił checkbox = pił categorie
		if ( document.f1.category.length > 0) {	
			for (i=0; i<document.f1.category.length; i++) { 
				if (document.f1.category[i].checked) {
				   	var thisField = "document.f1.descCtg" + document.f1.category[i].value + ".value";
				   	var descCtg = eval(thisField);
					if(descCtg == "") {
						ctgSel = 0;
						i = document.f1.category.length;
					}
					else
						ctgSel = 1;
				}
			}
		}//Caso in cui ci sia un solo checkbox = 1 categoria	
		else { 
			var thisField = "document.f1.descCtg" + document.f1.category[i].value + ".value";
		   	var descCtg = eval(thisField);
			if (document.f1.category.checked && descCtg != "")
				ctgSel = 1;
		}
		
		if(ctgSel>0) {
			document.f1.actionToDo.value = "MODIFY";
			document.f1.submit();
		}
		else
			alert(js_modifyAlert);
	}
	else
		alert(js_notmodifiedAlert);
}

function deleteCtg() {
	var ctgSel = 0;
	if(document.f1.category) {
		if ( document.f1.category.length > 0) {	
			for (i=0; i<document.f1.category.length; i++) { 
				if (document.f1.category[i].checked) {
					ctgSel = 1;
					i = document.f1.category.length;
				}
			}
		}
		else {	
			if (document.f1.category.checked) {
				ctgSel = 1;
			}
		}
		
		if(ctgSel>0) {
			if(confirm (js_delctgAlert)) {
				document.f1.actionToDo.value = "DELETE";
				document.f1.submit();
			}
		}
		else 
			alert(js_ctgtodelAlert);
	}
	else
		alert(js_notctgtodelAlert);
}

function changeCategory() {
	for (var i = 0; i < document.f1.ctg.length; i++) {         
		if (document.f1.ctg[i].selected) 
			document.f1.submit();
	}


}

function moveRecipes() {
	var recipeSel = 0;
	if(document.f2.recipe) {
		if ( document.f2.recipe.length > 0) {
			for (i=0; i<document.f2.recipe.length; i++) {
				if (document.f2.recipe[i].checked) {
					recipeSel = 1;
					i = document.f2.recipe.length;
				}
			}
		}
		else {	
			if (document.f2.recipe.checked) {
				recipeSel = 1;
			}
		}
		
		if(recipeSel>0 && document.f2.category.options[document.f2.category.selectedIndex].value > 0) {
			document.f2.actionToDo.value = "MODIFY";
			document.f2.submit();
		}
		else {
			if( document.f2.category.options[document.f2.category.selectedIndex].value > 0 ) {
				alert(js_moveAlert);
				document.f2.category.value = -1;
			}
		}
	}
	else
		alert(js_notmovedAlert);
}

function deleteRecipes() {
	var recipeSel = 0;
	if(document.f2.recipe) {
		if ( document.f2.recipe.length > 0) {	
			for (i=0; i<document.f2.recipe.length; i++) { 
				if (document.f2.recipe[i].checked) {
					recipeSel = 1;
					i = document.f2.recipe.length;
				}
			}
		}
		else {	
			if (document.f2.recipe.checked) {
				recipeSel = 1;
			}
		}
		
		if(recipeSel>0) {
			if(confirm (js_delrecipeAlert))	{
				document.f2.actionToDo.value = "DELETE";
				document.f2.submit();
			}
		}
		else
			alert(js_recipetodelAlert);
	}
	else
		alert(js_notrecipetodelAlert);
}


function windowOpen(sUrl)
{
	window.open(sUrl,'help','resizable=yes,scrollbars=yes,width=552,height=550');
}