function getSearch() {
	var element = document.getElementById('searchfield');
	
	if(element)
		return element.value.trim();
	return '';
}

function setSearch(search) {
	var element = document.getElementById('searchfield');
	
	if(element)
		element.value = search;
}

function getSort() {
	var sortSelect = document.getElementById('sort');
	
	var elementDesc = document.getElementById('desc');
	var desc = '';
	if(elementDesc && elementDesc.checked)
		desc = ' DESC';
	
	if(sortSelect)
		return sortSelect.options[sortSelect.selectedIndex].value + desc;
}

function setSort(sort) {
	var sortSelect = document.getElementById('sort');
	if(!sortSelect)
		return;
		
	// Sort by?
	var sorts = sort.split(" ");
	var sort = sorts[0];
	
	for (i = 0; i < sortSelect.options.length; i++) {
		if (sortSelect.options[i].value == sort || sortSelect.options[i].text == sort) {
			sortSelect.selectedIndex = i;
			break;
		}
	}
	
	// Desc?
	if(sorts[1])
		document.getElementById('desc').checked = true;
}

function getAmount() {
	var amountSelect = document.getElementById('amount');
	
	if(amountSelect)
		return amountSelect.options[amountSelect.selectedIndex].value;
}

function setAmount(amount) {
	var amountSelect = document.getElementById('amount');
	if(!amountSelect)
		return;
		
	for (i = 0; i < amountSelect.options.length; i++) {
		if (amountSelect.options[i].value == amount || amountSelect.options[i].text == amount) {
			amountSelect.selectedIndex = i;
			break;
		}
	}
}

/**
 * Adjust here your question
 */
function deleteMovie(id) {
	if(confirm('Are you sure you want to remove this movie?'))
		window.location.href='./?delete=' + id;
}

/**
 * Adjust here your question
 */
function removeCover(id) {
	var url = './?go=edit&id=' + id + '&removecover=1';
	if(confirm('Are you sure you want to remove this cover?')) {
		new Ajax.Request(url, {
			method: 'get',
		});
		//window.location.href='./?go=edit&id=' + id + '&removecover=1';
		return true;
	}
	return false;
}