/**
 * @author pversai
 */

/**
 * The RDCOM object is the single global object used by YUI Library.  It
 * contains utility function for setting up namespaces, inheritance, and
 * logging.
 * @module rdcom
 * @title  RDCOM Global
 */

if(typeof RDCOM == "undefined"){
	/**
	 * The RDCOM global namespace object
	 * @class RDCOM
	 * @static
	 */
	var RDCOM = {};
};

if(typeof RDCOM.utils == "undefined"){
	RDCOM.utils = {};
};

/**
 * @method include
 * @classDescription includes any file to a page as js.
 * @param {Object} strPath
 */
RDCOM.utils.includeFile = function(strPath){
	var head = document.getElementsByTagName('head').item(0);
	script = document.createElement('script');
	script.src = strPath;
	script.type = 'text/javascript';
	head.appendChild(script);
	return script;
}

/**
 * @method include
 * @classDescription user friendly class import function.
 * @param {Object} strNamespace
 */
RDCOM.utils.include = function(strNamespace){
	var namespaceList = Array();
	namespaceList["Array"] = "/js/lib/rd/Array.js";
	namespaceList["Events"] = "/js/lib/rd/EventRouter.js";
	namespaceList["ValidateForm"] = "/js/lib/offer/validateForm.js";
	namespaceList["Ajax"] = "/js/lib/rd/net.js";
	return RDCOM.utils.includeFile(namespaceList[strNamespace]);
}

/**
 * @method URL
 * @classDescription Manipulates url in the string to get appropreate parameters
 */
RDCOM.utils.URL = function(){
	var URL = this.getURL();
	var AddressParameters = URL.split("?");
	if (AddressParameters[1]){
		var parameters = AddressParameters[1].split("&");
		for (var i=0; i<parameters.length; i++){
			var params_values = parameters[i].split("=");
			this.parameters[params_values[0]] = params_values[1];
		}
	}
}
RDCOM.utils.URL.prototype = {
	parameters:new Array(),
	getURL:function (){
		return document.URL;
	},
	getParameter:function(paramName){
		if (typeof this.parameters[paramName] ==  "undefined")
			return null;
		
		return this.parameters[paramName];
	}
}

/**
 * Adds event listner object to specifyed element
 * @param {Function} fn
 * @param {Object} elm Element to register the event on
 * @param {String} evType Event type
 * @param {Boolean} useCpature event registration type
 */
RDCOM.utils.addEvent = function(elm, evType, fn, useCapture) {
	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;
	}
}
/**
 * Wrapper objects
 */
var rdOnloadManager = {
	addListener: function(func){
		RDCOM.utils.addEvent(window, "load", func, false);
	}
}
var rdInclude = RDCOM.utils.includeFile;