function saveContest()
{
	if ((checkDate($("da").value))&&(checkDate($("a").value)))
	{
		$("newcontest").submit();
	}
	else
	{
		if (!checkDate($("da").value)) err="starting date is not valid\n";
		if (!checkDate($("a").value)) err+="ending date is not valid\n";
		alert(err);
	}
}

function addContest(id,tipo)
{
	var XmlHttpC;
	
	xmlHttpC = new Ajax.Request("/upd_contest.php?action=add&idc="+id+"&idt="+tipo,
									{
										method: 'get',
										onComplete: function(resp)
										{
											// alert(resp.responseText);
											ris=resp.responseText;
											if (ris=="OK") alert("Content added to current contest");
											if (ris=="FULL") alert("You have already reached the maximum contents added to current contest");
											if (ris=="USED") alert("This content has been already used for contest");
											if (ris=="NOCONTEST") alert ("No contest are scheduled now");
											window.location.reload();
										}
									});
}

function deleteContest(id)
{
	var XmlHttpC;
	
	xmlHttpC = new Ajax.Request("/upd_contest.php?action=delete&idc="+id,
									{
										method: 'get',
										onComplete: function(resp)
										{
											// alert(resp.responseText);
											ris=resp.responseText;
											if (ris=="OK") alert("Content deleted from current contest");
											window.location.reload();
										}
									});
}

function creaCal(id)
{
	if (id==1) cal.select($("da"),"anc1","dd/MM/yyyy");
	if (id==2) cal.select($("a"),"anc2","dd/MM/yyyy");
}

function winnerContest(id,cont)
{
	xmlHttp = new Ajax.Request("/upd_contest.php?action=winnercontest&idwin="+id+"&idc="+cont,
			{
				method: 'get',
				onComplete: function(resp)
				{
					// alert(resp.responseText);
				}
			})
}
