//
// admin.js
// - contains javascript functions pertaining to Admin module
//
// last updated: 01/23/2007
// modified by : Slava Gurgov
//

// processRequest() asks user for input, sets up the form and submits
// it is used on pages that work with one field of data
// and pages that use the Prompter
// the form must contain the following fields:
//	do        => (add|update|delete)
//	item_id   => int
//	item_name => string
function processRequest(form, action, item_id, item_name)
{
	var input = "";
	if (action == "add")
	{
		input = trim(prompt("Please enter the item name:",""));
		if (input == null || input == "")
			return false;
	}
	else if (action == "update")
	{
		input = trim(prompt("Please enter the item name:", item_name));
		if (input == null || input == "" || input == item_name)
			return false;
	}
	else if (action == "delete")
	{
		if (!confirm("Are you sure you want to remove this item?"))
			return false;
	}
	else
	{
		// invalid action
		return false;
	}

	// on success submit form
	form['do'].value = action;
	form['item_id'].value = item_id;
	form['item_name'].value = input;

	form.submit();
	return true;
}

// hideStatus() calls hideStatusFunc() passing it the layer
// to hide after 'clearIn' seconds
var t, clearIn=10*1000;
function hideStatus(layerId)
{
	if (document.getElementById(layerId))
		window.setTimeout("document.getElementById('"+layerId+"').style.display='none'", clearIn);
}
function hideStatusFunc(layerId)
{
	var obj = document.getElementById(layerId);
	obj.display = "none";
	clearTimeout(t);
}

function addResource(form)
{
  return true;
  var errors = new Array();

  if (trim(form.res_name.value) == "") {
    errors[errors.length] = "Resource Name";
  }

  if (trim(form.description.value) == "") {
    errors[errors.length] = "Resource Description";
  }

  if (trim(form.url.value) == "" || trim(form.url.value) == "http://") {
    errors[errors.length] = "Resource URL";
  }

  if (errors.length > 0)
  {
    var msg = "The following items must be entered:\n";
    for (var i=0; i < errors.length; i++) {
      msg += " - "+ errors[i] +"\n";
    }
    alert(msg);
    return false;
  }
  return true;
}

function checkSearch(form)
{
  if (trim(form.keywords.value) == "")
  {
    alert("Please enter a keyword first");
    form.keywords.value="";
    form.keywords.focus();
    return false;
  }
  return true;
}
