/**
* http://www.smelzo.it/html2js/
*/
function cmfAjaxEveryWhereV1HtmlToDom(html){
};

function cmfcFunction() {
	
};
cmfcFunction.callUserFunction=function (name,params) {
	if (params) {
		var paramsStr='';
		var comma='';
		for (i in params) {
			paramsStr+=comma+'params["'+i+'"]';
			comma=',';
		}
	}

	if (typeof(name)=='string') {
		var s=name+'('+paramsStr+')';
		var result=eval(s);
	} else if (typeof(name)=='array' || typeof(name)=='object') {
		var s='name[0].'+name[1]+'('+paramsStr+')';
		var result=eval(s);
	}
	
	return result;
};

function cmfcUrl() {
};

/**
*	parseUri 1.2.1
*	(c) 2007 Steven Levithan <stevenlevithan.com>
*	http://blog.stevenlevithan.com/archives/parseuri
*	MIT License
*/
cmfcUrl.parse=function(str) {
	var	o   = cmfcUrl.parse.options,
	m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
	uri = {},
	i   = 14;

	while (i--) {
		uri[o.key[i]] = m[i] || "";
	}
	
	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) {
			uri[o.q.name][$1] = $2;
		}
	});
	
	return uri;
};


cmfcUrl.parse.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

/**
 * 
 */
 cmfcUrl.encode=function ( str ) {
	// http://kevin.vanzonneveld.net
	// +   original by: Philip Peterson
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: AJ
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
	// *     example 1: urlencode('Kevin van Zonneveld!');
	// *     returns 1: 'Kevin+van+Zonneveld%21'
	// *     example 2: urlencode('http://kevin.vanzonneveld.net/');
	// *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
	// *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
	// *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
									 
	var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
	var ret = str.toString();
	
	var replacer = function(search, replace, str) {
		var tmp_arr = [];
		tmp_arr = str.split(search);
		return tmp_arr.join(replace);
	};
	
	// The histogram is identical to the one in urldecode.
	histogram['!']   = '%21';
	histogram['%20'] = '+';
	
	// Begin with encodeURIComponent, which most resembles PHP's encoding functions
	ret = encodeURIComponent(ret);
	
	for (search in histogram) {
		replace = histogram[search];
		ret = replacer(search, replace, ret); // Custom replace. No regexing
	}
	
	// Uppercase for full PHP compatibility
	return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
		return "%"+m2.toUpperCase();
	});
	
	return ret;
};

function cmfcArray() {
	
};
/**
 * merge 2 dimensional arrays
 */
cmfcArray.merge=function () {
    // http://kevin.vanzonneveld.net
    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Nate
    // -    depends on: is_int
    // %          note: Relies on is_int because !isNaN accepts floats     
    // *     example 1: arr1 = {"color": "red", 0: 2, 1: 4}
    // *     example 1: arr2 = {0: "a", 1: "b", "color": "green", "shape": "trapezoid", 2: 4}
    // *     example 1: array_merge(arr1, arr2)
    // *     returns 1: {"color": "green", 0: 2, 1: 4, 2: "a", 3: "b", "shape": "trapezoid", 4: 4}
    // *     example 2: arr1 = []
    // *     example 2: arr2 = {1: "data"}
    // *     example 2: array_merge(arr1, arr2)
    // *     returns 2: {1: "data"}
    
	this.is_int=function ( mixed_var ) {
	    // http://kevin.vanzonneveld.net
	    // +   original by: Alex
	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +    revised by: Matt Bradley
	    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // %        note 1: 1.0 is simplified to 1 before it can be accessed by the function, this makes
	    // %        note 1: it different from the PHP implementation. We can't fix this unfortunately.
	    // *     example 1: is_int(23)
	    // *     returns 1: true
	    // *     example 2: is_int('23')
	    // *     returns 2: false
	    // *     example 3: is_int(23.5)
	    // *     returns 3: false
	    // *     example 4: is_int(true)
	    // *     returns 4: false
	 
	    if (typeof mixed_var !== 'number') {
	        return false;
	    }
	 
	   if (parseFloat(mixed_var) != parseInt(mixed_var, 10)) {
		   return false;
	   }
	    
	   return true;
	};
    
    var args = Array.prototype.slice.call(arguments);
    var retObj = {}, k, j = 0, i = 0;
    var retArr;
    //args.push(this);
    
    for (i=0, retArr=true; i < args.length; i++) {
        if (!(args[i] instanceof Array)) {
            retArr=false;
            break;
        }
    }
    
    if (retArr) {
        return args;
    }
    var ct = 0;
    
    for (i=0, ct=0; i < args.length; i++) {
        if (args[i] instanceof Array) {
            for (j=0; j < args[i].length; j++) {
                retObj[ct++] = args[i][j];
            }
        } else {
            for (k in args[i]) {
                if (this.is_int(k)) {
                    retObj[ct++] = args[i][k];
                } else {
                    retObj[k] = args[i][k];
                }
            }
        }
    }
    
    return retObj;
};


cmfcArray.mergeRecursive=function (arr1, arr2) {
		
    // http://kevin.vanzonneveld.net
    // +   original by: Subhasis Deb
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: array_merge
    // *     example 1: arr1 = {'color': {'favourite': 'read'}, 0: 5}
    // *     example 1: arr2 = {0: 10, 'color': {'favorite': 'green', 0: 'blue'}}
    // *     example 1: array_merge_recursive(arr1, arr2)
    // *     returns 1: {'color': {'favorite': {0: 'red', 1: 'green'}, 0: 'blue'}, 1: 5, 1: 10}
 
    var idx = '';
 
    if ((arr1 && (arr1 instanceof Array)) && (arr2 && (arr2 instanceof Array))) {
        for (idx in arr2) {
            arr1.push(arr2[idx]);
        }
    } else if ((arr1 && (arr1 instanceof Object)) && (arr2 && (arr2 instanceof Object))) {
        for (idx in arr2) {
            if (idx in arr1) {
                if (typeof arr1[idx] == 'object' && typeof arr2 == 'object') {
                    arr1[idx] = cmfcArray.merge(arr1[idx],arr2[idx]);
                } else {
                    arr1[idx] = arr2[idx];
                }
            } else {
                arr1[idx] = arr2[idx];
            }
        }
    }
    
    return arr1;
};


function cmfcString() {
	
};



/**
* replace variables with replacements in string
* @param replacements array
* @param text string
*/
cmfcString.replaceVariables=function (replacements,text) {
	for (key in replacements) {
		value=replacements[key];
		text=text.replace(key,value);
		
	}
	return text;
};



/*
File: Math.uuid.js
Version: 1.3
Change History:
  v1.0 - first release
  v1.1 - less code and 2x performance boost (by minimizing calls to Math.random())
  v1.2 - Add support for generating non-standard uuids of arbitrary length
  v1.3 - Fixed IE7 bug (can't use []'s to access string chars.  Thanks, Brian R.)
  v1.4 - Changed method to be "Math.uuid". Added support for radix argument.  Use module pattern for better encapsulation.

Latest version:   http://www.broofa.com/Tools/Math.uuid.js
Information:      http://www.broofa.com/blog/?p=151
Contact:          robert@broofa.com
----
Copyright (c) 2008, Robert Kieffer
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Robert Kieffer nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
 * Generate a random uuid.
 *
 * USAGE: Math.uuid(length, radix)
 *   length - the desired number of characters
 *   radix  - the number of allowable values for each character.
 *
 * EXAMPLES:
 *   // No arguments  - returns RFC4122, version 4 ID
 *   >>> Math.uuid()
 *   "92329D39-6F5C-4520-ABFC-AAB64544E172"
 * 
 *   // One argument - returns ID of the specified length
 *   >>> Math.uuid(15)     // 15 character ID (default base=62)
 *   "VcydxgltxrVZSTV"
 *
 *   // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
 *   >>> Math.uuid(8, 2)  // 8 character ID (base=2)
 *   "01001010"
 *   >>> Math.uuid(8, 10) // 8 character ID (base=10)
 *   "47473046"
 *   >>> Math.uuid(8, 16) // 8 character ID (base=16)
 *   "098F4D35"
 */
function cmfcHtml() {	  
};
cmfcHtml.uniqueId = (function() {
  // Private array of chars to use
  var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); 

  return function (len, radix) {
    var chars = CHARS, uuid = [], rnd = Math.random;
    radix = radix || chars.length;

    if (len) {
      // Compact form
      for (var i = 0; i < len; i++) uuid[i] = chars[0 | rnd()*radix];
    } else {
      // rfc4122, version 4 form
      var r;

      // rfc4122 requires these characters
      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
      uuid[14] = '4';

      // Fill in random data.  At i==19 set the high bits of clock sequence as
      // per rfc4122, sec. 4.1.5
      for (var i = 0; i < 36; i++) {
        if (!uuid[i]) {
          r = 0 | rnd()*16;
          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
        }
      }
    }

    return uuid.join('');
  };
})();

// Deprecated - only here for backward compatability





function cmfcClassesCore() {
	this.messagesValue=new Array();
	this.message;

	/**
	* 
	*/
	this.raiseError=function (message, code , mode , options , userinfo , error_class , skipmsg ) {

		if (this.messagesValue[code] && !message) {
			message=this.messagesValue[code];
		}
		if (userinfo && typeof(userinfo)!='string' && message ) {
			var replacements=new Array();
			for (key in userinfo) {
				value=userinfo[key];
				replacements['%'+key+'%']=value;
			}
			message=cmfcString.replaceVariables(replacements,message);
		}
		if (!message) { 
			message=' No error message defined!! ';
		}
		return message;
	};

	/**
	* assign object validation methods to handle form validation
	*/
	this.prepare=function () {
	};
	
	/**
	* do the preapre on page load
	*/
	this.prepareOnLoad=function () {
	};
};


var cmfImplementObservable;
(function() {

    var cmfcObservable = { 

    		observers: new Array(),
    		
    		addObserver: function (event, observer,parameters) {
    			if (!this.observers[event]) {
    				this.observers[event]=new Array();
    			}
    			this.observers[event].push(observer);
    		},
    		
    		removeObserver: function (event, observer) {
    			if (this.observers[event]) {
    				for (i in this.observers[event]) {
    					var observer=this.observers[event][i];
    					if (typeof(observer)!='function') {
    						if (this.observers[event]==observer) {
    							this.observers[event].splice(i);
    						}
    					}
    				}
    			}
    		},
    		
    		prependObserver: function (event, observer,parameters) {
    			if (!this.observers[event]) {
    				this.observers[event]=new Array();
    			}
    			this.observers[event].unshift(observer);
    		},
    		
    		hasObserver: function (event) {
    			if (this.observers[event]) {
    				for (i in this.observers[event]) {
    					var observer=this.observers[event][i];
    					if (typeof(observer)!='function') {
    						return true;
    					}
    				}
    			} else {
    				return false;
    			}
    		},
    		
    		notifyObservers: function (event,params) {
    			if (this.observers[event])
    			for (i in this.observers[event]) {
    				var observer=this.observers[event][i];
    				if (typeof(observer)!='function') {
    					cmfcFunction.callUserFunction(observer,{'obj':this,'event':event,'params':params});
    				}
    			}
    		}
      
    };
    
    cmfImplementObservable = function (subject) {
        for (var p in cmfcObservable) {
            subject[p] = cmfcObservable[p];
        }
    }
    
})();


var cmfcCommandable;
(function() {
	
	var cmfcCommandable = {

		commandHandlers: new Array(),
		
		addCommandHandler: function (cmd, commandHandler,parameters) {
			if (!this.commandHandlers[cmd]) {
				this.commandHandlers[cmd]=new Array();
			}
			this.commandHandlers[cmd].push(commandHandler);
		},
		
		removeCommandHandler: function (cmd, commandHandler) {
			if (this.commandHandlers[cmd]) {
				for (i in this.commandHandlers[cmd]) {
					var commandHandler=this.commandHandlers[cmd][i];
					if (typeof(commandHandler)!='function') {
						if (this.commandHandlers[cmd]==commandHandler) {
							this.commandHandlers[cmd].splice(i);
						}
					}
				}
			}
		},
		
		prependCommandHandler: function (cmd, commandHandler,parameters) {
			if (!this.commandHandlers[cmd]) {
				this.commandHandlers[cmd]=new Array();
			}
			this.commandHandlers[cmd].unshift(commandHandler);
		},
		
		hasCommandHandler: function (cmd) {
			if (this.commandHandlers[cmd]) {
				for (i in this.commandHandlers[cmd]) {
					var commandHandler=this.commandHandlers[cmd][i];
					if (typeof(commandHandler)!='function') {
						return true;
					}
				}
			} else {
				return false;
			}
		},
		
		//http://api.drupal.org/api/function/module_invoke_all/6
		runCommand: function (cmd,params) {
			if (this.commandHandlers[cmd])
			for (i in this.commandHandlers[cmd]) {
				var commandHandler=this.commandHandlers[cmd][i];
				if (typeof(commandHandler)!='function') {
					return cmfcFunction.callUserFunction(commandHandler,{'obj':this,'cmd':cmd,'params':params});
				}
			}
		},
		
		/**
		 * 
		 */
		runCommands: function (cmd,params) {
			
		}
	};
	
	cmfImplementCommandable = function (subject) {
        for (var p in cmfcCommandable) {
            subject[p] = cmfcCommandable[p];
        }
    }
    
})();
