// code taken and modified from : http://developer.yahoo.com/javascript/samples/dynamic/jsr_class.js
//
// Constructor -- pass a REST request URL to the constructor
function JSONScriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 

    // Keep IE from caching requests
    this.noCacheIE = '&ts=' + (new Date()).getTime();

    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);

    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONScriptRequest.scriptCounter++;
}

// Static script ID counter
JSONScriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONScriptRequest.prototype.buildScriptTag = function () {
    // Create the script tag
    this.scriptObj = document.createElement("script");
	 
	 // url encode everything after the "http://"
	 this.fullUrl = url_encode ( this.fullUrl ) ;

    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE ) ;
    this.scriptObj.setAttribute("id", this.scriptId);
}

// removeScriptTag method
JSONScriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
JSONScriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}
//
// end of modified code




// performs a json request
// Parameters :
//   p_url -> the url to submit
function json_perform_request ( p_url ) {

	 // submit the url and grab the result
	 var req = new JSONScriptRequest( p_url ) ;
	 req.buildScriptTag() ;
	 req.addScriptTag() ;

	 // worry about removing the tag later!
	 // worry about removing the tag later!
	 // worry about removing the tag later!

}
