var djConfig = { isDebug: true }; 

dojo.require("dojo.io.*");
dojo.require("dojo.event.*");

var statusDiv = "LOADSTATUS";
var dojoHistory = {};

function dojoSubmit(formId, url, targetDiv, thwartBack) {
	if (!thwartBack) thwartBack = false;
	return dojoRequest(url, targetDiv, thwartBack, formId);
}

function dojoRequest(url, targetDiv, thwartBack, formId) {
    // targetDiv, thwartBack, & formid are optional
    // blank.html (a mostly blank page) and iframe_history.html (from dojo distro)
    // must be co-located in the same subdirectory as the parent html document 
    var targetElem = document.getElementById(targetDiv);
    var statusElem  = document.getElementById(statusDiv);

    if (statusElem) {	
    	statusElem.innerHTML = "Processing..."; 
    	statusElem.style.visibility = "visible";
    }

    if (!dojoHistory[targetDiv]) { dojoHistory[targetDiv] = []; }

    var request = {
        url: url,
        //mimeType: "text/xml",
        load: function (response, data, e) {
	    if (targetElem) {
            	// save previous location
            	dojoHistory[targetDiv].push(targetElem.innerHTML);
            	// load new content
            	targetElem.innerHTML = data;
	    }
	    if (statusElem) statusElem.style.visibility = "hidden";
        }
    };
    
    if (formId) {
		request.method = "post";
		request.formNode = document.getElementById(formId);
    }	

    if (!thwartBack && targetElem) {
        request.backButton = function () {
            // restore previous content
            targetElem.innerHTML = dojoHistory[targetDiv].pop();
        }
    }

    dojo.io.bind(request);
}