/* 
 Copyright Information
 This code copyright 2007, Masala, Inc. 
 This code contains proprietary information which is a trade secret of Masala, Inc. 
 and also is protected as an unpublished work under applicable copyright law. 
 Recipients are to retain this code in confidence and are not permitted to use or 
 make copies thereof other than as permitted in a written agreemnet with Masala, Inc.
*/

/*
#######################################################################################
#######################################################################################
						customevents.js
#######################################################################################
#######################################################################################
*/

/*
	This array is used to stored the callbacks with defined events.
	This array will become two dimensional array when we register some event and callback method using RegisterCallback.	
*/
var mycallbacks=new $A();
/*
	This function is used to store callback against some defined events. A event can contain many callback methods.
	And when we call TriggerCallBacks with event name then all methos that are registered for this event will be 
	called with specified argument.
*/
function RegisterCallback(name,callback)
{
	try{		
		if(typeof(mycallbacks[name]) == "undefined")
		{	
			mycallbacks[name] = new $A();
		}
		mycallbacks[name].push(callback);
		return true;
	}catch(ex)
	{
		return false;
	}
}

/*
	TriggerCallBacks will call all methods that are registered against particular event-name with specific argument.
	Right now, its limited to single argument but it will be convert to arguments array for making parameter passing generic
*/
function TriggerCallbacks(eventname,firstargument)
{
	try{		
		if(typeof(mycallbacks[eventname]) != "undefined")
		{
			mycallbacks[eventname].each(function(callbackname){
			callbackname(firstargument);	
			});
			return true;
		}
	} catch(ex) {
		return false;
	}		
}



/*
#######################################################################################
#######################################################################################
						jsonparsing.js
#######################################################################################
#######################################################################################
*/
/*
Class: JSONArrayParse
Description: JSONArrayParse class is about returning Hash after parsing of a JSON row. This class is made for making process
of generating html generic for different widget.
Reference : This code is based on the code of the JSON Editor that builds a tree from your JSON, and lets you walk the tree.
			http://ajaxian.com/archives/simple-tree-based-json-editor
			http://braincast.nl/samples/jsoneditor/
Implemented: 18-Sep-2007 Junaid Malik
Updated: 18-Sep-2007 Junaid Malik
*/


var JSONArrayParse;
JSONArrayParse = Class.create()
JSONArrayParse.prototype={
	/*constructor*/
	initialize:function()
	{
	}
}

/*
	static method of JSONArrayParse
*/
JSONArrayParse.isTypeOf = function(thing){
	var t = typeof(thing);
	if (t == 'object'){ 
		if (JSONArrayParse.isArray(thing)) return 'array';  // an object can be an array too!
		if (thing == null) return 'null';
	}
	return t
}

JSONArrayParse.isArray = function(thing){
	if (thing == null) return false; 
	if (typeof(thing) != 'object') return false;
	if (typeof(thing.length) == 'undefined') return false; 
	return true;
}

JSONArrayParse.isObject = function(thing) {
	if (thing == null) return false; // null is not a f-ing object!
	if (typeof(thing) != 'object') return false; 
	if (typeof(thing.length) != 'undefined') return false; 
	return true; 
}


JSONArrayParse.makeTree = function(content,i)
{	
	//GLog.write("Content: " + content + ", i: " + i);	
	var out = $H({});
	
	/*if (typeof(content) == 'function') return '';*/ //'function'; 
	/*else if (JSONArrayParse.isArray(content)){
		 log_exceptions("Is array found in json");
		for (var i=0; i<content.length; i++){	
			out.merge(JSONArrayParse.makeTree(content[i]));
		}
	}else */

	if(typeof(content) == 'string'){  
		//log_exceptions(i);
		/*var h = $H({});//$H(({eval(i)) : (eval(content))});
		h[i] = content;
		out.merge(h);*/
		out[i] = content;
	}
	else if(JSONArrayParse.isObject(content)){
		//log_exceptions("this is object");		
		for(var i in content){			
			if (i !== "toJSONString"){
				if(typeof(content[i]) == 'string')
				{
					out[i] = content[i];
					//log_exceptions(content[i] + " :: " + i);
				}
				//out.merge(JSONArrayParse.makeTree(content[i], i));
			}			
		}	
	}
	return out; 	
}

