+/**
+ * Get the name of a function created like:
+ * <pre>function functionName(){}</pre>
+ * If a name is not found, attach the function to
+ * the window object with a new name and return that
+ * @param {Function} oFunc the function object
+ */
+Sarissa.getFunctionName = function(oFunc){
+ if(!oFunc || (typeof oFunc != 'function' )){
+ throw "The value of parameter 'oFunc' must be a function";
+ }
+ if(oFunc.name) {
+ return oFunc.name;
+ }
+ // try to parse the function name from the defintion
+ var sFunc = oFunc.toString();
+ alert("sFunc: "+sFunc);
+ var name = sFunc.substring(sFunc.indexOf('function') + 8 , sFunc.indexOf('('));
+ if(!name || name.length == 0 || name == " "){
+ // attach to window object under a new name
+ name = "SarissaAnonymous" + Sarissa._getUniqueSuffix();
+ window[name] = oFunc;
+ }
+ return name;
+};
+
+/**
+ *
+ */
+Sarissa.setRemoteJsonCallback = function(url, callback, callbackParam) {
+ if(!callbackParam){
+ callbackParam = "callback";
+ }
+ var callbackFunctionName = Sarissa.getFunctionName(callback);
+ //alert("callbackFunctionName: '" + callbackFunctionName+"', length: "+callbackFunctionName.length);
+ var id = "sarissa_json_script_id_" + Sarissa._getUniqueSuffix();
+ var oHead = document.getElementsByTagName("head")[0];
+ var scriptTag = document.createElement('script');
+ scriptTag.type = 'text/javascript';
+ scriptTag.id = id;
+ scriptTag.onload = function(){
+ // cleanUp
+ // document.removeChild(scriptTag);
+ };
+ if(url.indexOf("?") != -1){
+ url += ("&" + callbackParam + "=" + callbackFunctionName);
+ }
+ else{
+ url += ("?" + callbackParam + "=" + callbackFunctionName);
+ }
+ scriptTag.src = url;
+ oHead.appendChild(scriptTag);
+ return id;
+};
+