// JavaScript Document
// the IFRAME is IFRAME_PREFIX + XX. The constant below defines
// the value of the prefix
var IFRAME_PREFIX = "i";
// Transfer the HTML within the BODY tag from an IFRAME to the specified target.
// The convention followed is that content from an IFRAME called iXX is loaded
// into an element XX.
function transferHTML(target) {
   // The name of the IFRAME into which the external document is loaded
   var srcIFrame = document.getElementById(IFRAME_PREFIX + target);
   // The content in the IFrame contained within the body tag
   var srcContent = (srcIFrame.contentDocument) ? srcIFrame.contentDocument.getElementsByTagName("BODY")[0].  innerHTML : (srcIFrame.contentWindow) ? srcIFrame.contentWindow.document.body.innerHTML : "";
   // Set the content of the target document
   document.getElementById(target).innerHTML = srcContent;
}

function deleteUser(url) {
	message = "Are you sure you want to delete the selected user? \n" + 
					"Press OK to delete the selected user and \n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

function deleteEntity(url, entity, name) {
	message = "Are you sure you want to delete " + entity + ": '" + name +"'? \n" + 
					"Press OK to delete the " + entity +"\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// update a hidden field from a checkbox
function updateHiddenField(fieldName) {
	if (document.getElementById(fieldName + "_checkbox").checked) {
		// set the hidden field value to true
		document.getElementById(fieldName).value = "Hot";
	} else {
		// set the hidden field value to true
		document.getElementById(fieldName).value = "Ordinary";
	}
}

// Returns false if the field is empty, null, or has the string "null", and pops up
// the message passed to the function
function isNotNullOrEmptyString(fieldName, message) {
	if (isNullOrEmpty(document.getElementById(fieldName).value)) {	
		alert(message);		
		return false;
	}
	return true;
}

// general purpose function to see if an input value has been
// entered at all or if the input value has a value "null"
function isNullOrEmpty(inputStr) {
	if (isEmpty(inputStr) || inputStr == "null") {
		return true;
	}
	return false;
}

// general purpose function to see if an input value has been
// entered at all
function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {
		return true;
	}
	return false;
}
