/* Subversion: $Id: content.js 35 2005-03-18 17:34:36Z rhorton $ */

var MULTIPLE_EDIT = 0;

function showCalendar(calendar, link, format, inputId) {

	var i = document.getElementById(inputId);
	calendar.select(i, link, format, i.value);

	return false;
}


// invoked when a user clicks the checkbox to either expire or delete a record
function SetExpireFlag(b) {
  var f = document.forms['confirmDelete'];
  if (b) {
	  f.expiryFlag.value = 1;
  } else {
  	f.expiryFlag.value = 0;
  }
//	f.submit();
}



function clickContentBox(box, trueValue, falseValue) {

	var pattern = box.id.replace(/checkbox_/, "");
	var checkbox = get(pattern);

	if (! checkbox) {
		alert('System error - this field may not be updated in the database');
	}

	if (box.checked) {
		checkbox.value = trueValue;
	} else {
		checkbox.value = falseValue;
	}
}

function clickMultipleEdit(checked) {

	if (checked) { 
		MULTIPLE_EDIT++;
	} else {
		MULTIPLE_EDIT--;
	}

	var button = document.getElementById('submitMultipleEdit');
	if (MULTIPLE_EDIT) {
		button.removeAttribute('disabled');
	} else {
		button.setAttribute('disabled', 'disabled');
	}
}

function SubmitSearch() {
	document.claeroForm.action.value = "search";
	document.claeroForm.submit();
}

function CancelSearch() {
	document.claeroForm.action.value = "cancel_search";
	document.claeroForm.submit();
}

function SubmitAdd() {
	document.claeroForm.action.value = "add";
	document.claeroForm.submit();
}

function RecordDetail(id) {;
  var f = document.forms['claeroForm'];
	f.action.value = "detail";
	f.id.value = id;
	f.submit();
}

function RecordEdit(id) {
  var f = document.forms['claeroForm'];
  f.elements['action'].value = "edit";
	f.id.value = id;
	f.submit();
}

function RecordDelete(id) {
	if (confirmDelete(id)) {
	  var f = document.forms['claeroForm'];
		f.action.value = "delete";
		f.id.value = id;
		f.submit();
	}
}
	
function confirmDelete(name) {
//	input_box=confirm("Are you sure you want to remove '" + name + "' ?");
//	if (input_box==true) {
		return true;
//	}
}

function EditRecords() {

	var f = document.forms['claeroForm'];

	if (countCheckedBoxes('claeroForm', 'ids[]')) { 
		f.action.value = "edit_multiple";
		f.submit();
	} else {
			alert('Please select atleast one record to edit.');
	}
}

function RecordAdd(theRecord) {
	var f = document.forms['claeroForm'];
	f.action.value = "add";
	f.id.value = theRecord;
	f.submit();
}

function CancelForm(theForm, url) {

    // no url was passed, so submit the form
    if (arguments.length == 1) {
	    theForm.action.value = "cancel";
	    theForm.submit();

    // a url was passed, so use that to redirect the browser
    } else {
        document.location = url;
    }
}

function Download(url) {
	
//	var win = window.open(url, "download");
	document.location = url;
}

function EditRecord(theForm) {
	theForm.action.value = "edit";
	theForm.submit();
}
