/**
 * Changes src path of image.
 *
 * @param (string) imageName
 * @param (string) imagePath
 */
function imgSrc(imageName, imagePath) {
    eval("var image = document." + imageName);
    image.src = imagePath;
}

/**
 * Performs case-insensitive lookup of select field using search field value.
 *
 * Args:
 * @param (element) selectElement
 * @param (element) searchText
 * @return (boolean) found
 */
function selectLookup(selectElement, searchText) {
    if (searchText.length >= 0) {
        for (var i=0; i < selectElement.length; i++) {
            if (selectElement.options[i].text.toUpperCase().indexOf(searchText.toUpperCase()) == 0) {
                selectElement.options[i].selected = true;
                return true;
            }
        }
    }
    return false;
}

/**
 * Scrolls to bottom of page.
 *
 */
function scrollBottom() {

	// initialize document height to arbitrarily high value
	var docHeight = 10000;

	// get actual document height
    if (document.all) {
        docHeight = document.body.offsetHeight;
	} else if (document.layers) {
        docHeight = document.body.document.height;
	}

	// jump to botton
    window.scroll(0, docHeight);
}

/**
 * Cross-browser gets-element-by-ID
 *
 * @param (String) id
 * @return (element) element
 */
function getElement(id) {
   if (document.all) {
      return document.all[id];
   } else {
      return document.getElementById(id);
   }
}

/**
 * Triggers add record operation in popup window.
 *
 * @param (String) id
 * @param (String) windowName
 */
function addRecord(url, windowName) {

	var width = 650;
	var height = 650;

	window.open(url, windowName, "location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height);
}

/**
 * Triggers edit record operation in popup window.
 *
 * @param (String) id
 * @param (String) windowName
 */
function editRecord(url, windowName) {

	var width = 650;
	var height = 650;

	window.open(url, windowName, "location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height);
}

/**
 * Triggers delete record operation with confirmation.
 *
 * @param (String) url
 */
function deleteRecord(url) {
	if (confirm("Are you sure you wish to delete this record?")) {
		document.location.href = url;
	}
}

/**
 * Refreshes opener.
 *
 * @param (isRefresh)
 */
function refreshOpener(isRefresh) {
	if (isRefresh == "1") {
		window.opener.location.href = window.opener.location.href;
	}
}

