function GetProgram(programId, channelSigla)
{ 
	if (document.getElementById("programId") != null && programId != null)
	{
		document.getElementById("programId").value = programId;
	}
	else
	{
		document.getElementById("programId").value = "";
	}

	if (document.getElementById("SelectedSigla") != null && channelSigla != null)
	{
		document.getElementById("SelectedSigla").value = channelSigla;
	}
	else
	{
		document.getElementById("SelectedSigla").value = "";
	}
	
	document.getElementById("operation").value = "xpto";
	
	var program = document.getElementById("programId").value;
	var channel = document.getElementById("SelectedSigla").value;
	var escapedChannel = encodeURIComponent(channel).replace("+", "%2b");

	document.location.href = "Programacao.aspx?programId=" + program + "&channelSigla=" + escapedChannel;
}

function ClearDescription()
{
	document.getElementById("operation").value = "clear";
}

function SetOperation(operation)
{
	document.getElementById("operation").value = operation;
}

function GetSelection(dropdownlist, controlId)
{
	document.getElementById(controlId).value = dropdownlist.selectedIndex.toString();
	
	if (controlId == 'SelectedChannel')
	{          
		document.getElementById("SelectedSigla").value = dropdownlist.value;
	}
	else if (controlId == 'SelectedCategory')
	{          
		document.getElementById("SelectedCategory").value = dropdownlist.value;
	}
}

function SelectCategory(radiobuttonlist)
{
	var inputsList = document.getElementsByTagName("input");
	
	var selectedCategory = "";
	
	for (var x = 0; x < inputsList.length; x++)
	{
		if (inputsList[x].id.substring(0, radiobuttonlist.length) == radiobuttonlist && inputsList[x].checked)
		{
			selectedCategory = inputsList[x].value;
		}
	}
	
	if (selectedCategory == 'Todas as categorias')
	{
		document.getElementById("SelectedCategory").value = " ";
	}
	else
	{
		document.getElementById("SelectedCategory").value = selectedCategory;
	}
} 

function SetIntervalStart(seconds)
{
	if (document.getElementById("IntervalStart") != null && document.getElementById("IntervalStart").value.length > 0)
	{
		document.getElementById("IntervalStart").value = (parseInt(document.getElementById("IntervalStart").value) + seconds).toString();
		SubmitForm();
	}
}

function SubmitForm()
{
	document.forms[0].action = document.location.href;
	document.forms[0].submit();
}

/*
Submit do formulário, mas este é feito para as páginas de EPG com MasterPage (form[1])
*/
function SubmitForm2()
{
	try{
	    document.forms[1].action = document.location.href;
	    document.forms[1].submit();
	} catch (exception)
	{
	    //SubmitForm();
	    alert('Erro ao fazer submit.');
	}
}

function SetSigla(channelSigla)
{
	document.getElementById("SelectedSigla").value = channelSigla;
	SetOperation('changeInterval');
}