// JavaScript Document
// All the javascript involved in the Books to Prisoners sytem.

// klappe function taken from oink.me.uk
function klappe(id)
{
	var klappText = document.getElementById(id);
	var klappBild = document.getElementById(id); 

	if (klappText.style.display == 'none') {
  		klappText.style.display = 'block';
  		// klappBild.src = 'images/blank.gif';
	}
	else {
  		klappText.style.display = 'none';
  		// klappBild.src = 'images/blank.gif';
	}
}


// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function check_obj(id) {
	x = findObj(id);
	x.checked = true;
	}
function uncheck_obj(id) {
	x = findObj(id);
	x.checked = false;
	}
	
// sets the focus to what we need it to.
function set_focus(obj) {
	x = findObj(obj);
	x.focus();
	}

function confirm_go(url)
{
	if (confirm("Are you really completing this request?"))
		window.location = url;
}
function set_focus(obj) {

	if(obj=='searchForm') {

		x = findObj('searchISBN');

    }

	if(obj=='results') {

		x = findObj('genre');

		}

	x.focus();

	}

// handles onkeyup event for the genres dropdown

function genres_keyboard(event) {

	if(event.keyCode == 13) {

		document.saveForm.submit();

		}

	else {

		// alert(event.keyCode);

		}

	}


function checkscript() {
	if (document.inmate_search.search_firstName.value == "" || document.inmate_search.search_lastName.value == "" || document.inmate_search.search_inmate_id.value == "" || document.inmate_search.search_facility.value == "")
	{
		// something is wrong
		alert('All fields must be filled out.');
		return (false);
	}

	// If the script makes it to here, everything is OK,
	// so you can submit the form

	return (true);
}


