var baseURL = window.location.href.substr(0, window.location.href.lastIndexOf("/")+1);
var dataChanged = false;

function addEvent(elm, evType, fn, useCapture) {
     // cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
     // By Scott Andrew
//     alert ("Adding event " + fn);
     if (elm.addEventListener) {
          elm.addEventListener(evType, fn, useCapture);
          return true;
     } else if (elm.attachEvent) {
          var r = elm.attachEvent('on' + evType, fn);
          return r;
     } else {
          elm['on' + evType] = fn;
     }
}

function getFormObject(id) {
	testObj = document.getElementById(id);
	if ((typeof(testObj) == "object") && (testObj !== null)) {
		return testObj;
	}
	return;
}

function get_help(item) {
    var targetWidth;
    var targetHeight;
    var availWidth = screen.availWidth;
    var availHeight = screen.availHeight;
	if (availWidth < 1000) {
         targetWidth = availWidth;
	} else {
         targetWidth = 1000;
	}
    if (availHeight < 700) {
         targetHeight = availHeight;
    } else {
         targetHeight = 700;
    }
    var attributes = "width=" + targetWidth + ",height=" + targetHeight + ",dependent=yes,resizable=yes,scrollbars=yes,title=yes";    
    window.open(baseURL + "getHelp.php?section=" + item, "help", attributes);
}

function checkDataLoss(e) {
	if (dataChanged) {
		e.returnValue = "You have unsaved changes that will be lost if you leave this page without saving them.  Do you want to continue?";
		return "You have unsaved changes that will be lost if you leave this page without saving them.  Do you want to continue?";
	}
}

function checkUnstoredData() {
    if (dataChanged) {
        if (confirm("You have unsaved changes.  Click \"OK\" to exit without saving the changes, or \"Cancel\" to return to your design.")) {
            dataChanged = false;
            location.href = baseURL + "index.php";
        }
    } else {
        location.href = baseURL + "index.php";
    }
}

addEvent(window, "beforeunload", checkDataLoss, false);

