// javascript for list tags
function disablePagingFields(form) {
	// disable non required fields
	form.firstResult.disabled = true;
	form.maxResults.disabled = true;
	form.visiblePageSize.disabled = true;
	form.orderBy.disabled = true;
	form.orderType.disabled = true;
}


function listSort(form, order, type) {
	form.orderBy.value = order;
	form.orderType.value = type;
	form.submit();
}

function listSelection(form) {
	// do we have only one item?
	if (form.id.length == null) {
		form.id.checked = form.selected_item_selector.checked;
	} else {
		for(i = 0; i < form.id.length; i++) {
			form.id[i].checked = form.selected_item_selector.checked;
		}
	}
}

function listSelectFirst(form) {
	// do we have only one item?
	if (form.id.length == null) {
		form.id.checked = true;
	} else {
		form.id[0].checked = true;
	}
}

function listSubmitAdd(form, action) {
	// disable non required fields
	disablePagingFields(form);
	// disable all checked items so that it does
	// not submit ID parameter along with form data.
	if (form.id.length == null) {
		form.id.checked = false;
	} else {
		for(i = 0; i < form.id.length; i++) {
			form.id[i].checked = false;
		}
	}	
	
	form.action = action;
	form.submit();
}

function listSubmitEdit(form, action, msg) {
	// disable non required fields
	disablePagingFields(form);
	
	var total = 0;
	// do we have only one item?
	if (form.id.length == null) {
		if (form.id.checked == true)
			total++;
	} else {
		for(i = 0; i < form.id.length; i++) {
			if (form.id[i].checked == true)
				total++;
		}
	}	

	if (total == 0) {
		alert(msg);
		return;
	}
	
	form.action = action;
	form.submit();
}

function listSubmitDelete(form, action, msg) {
	var total = 0;
	// do we have only one item?
	if (form.id.length == null) {
		if (form.id.checked == true)
			total++;
	} else {
		for(i = 0; i < form.id.length; i++) {
			if (form.id[i].checked == true)
				total++;
		}
	}	

	if (total == 0) {
		alert(msg);
		return;
	}
	
	form.action = action;
	form.method = 'POST';
	form.submit();
}

function listSubmitSearch(form, action) {
	// disable non required fields
	disablePagingFields(form);
	// disable all checked items so that it does
	// not submit ID parameter along with form data.
	if (form.id.length == null) {
		form.id.checked = false;
	} else {
		for(i = 0; i < form.id.length; i++) {
			form.id[i].checked = false;
		}
	}	
	
	form.action = action;
	form.submit();
}

function listSubmitPost(form, action, msg) {
	var total = 0;
	// do we have only one item?
	if (form.id.length == null) {
		if (form.id.checked == true)
			total++;
	} else {
		for(i = 0; i < form.id.length; i++) {
			if (form.id[i].checked == true)
				total++;
		}
	}	

	if (total == 0) {
		alert(msg);
		return;
	}
	
	form.action = action;
	form.method = 'POST';
	form.submit();
}

function listSubmitPopup(form, action, msg, name, w, h) {
	var total = 0;
	// do we have only one item?
	if (form.id.length == null) {
		if (form.id.checked == true)
			total++;
	} else {
		for(i = 0; i < form.id.length; i++) {
			if (form.id[i].checked == true)
				total++;
		}
	}	

	if (total == 0) {
		alert(msg);
		return;
	}

	window.open('', name, 'scrollbars=1,toolbars=1,width='+w+',height='+h);            
	form.target= name;
	form.action = action;
	form.submit();
}
