var Core = {

	Locations : {
		Root : location.protocol + '//www.collectionstation.com/'
	},
	CacheBuster : {

		Add : function(url, cacheBusterOnly) {
			if(url == '')
				return '';

			if(!cacheBusterOnly)
				url += (url.indexOf('?') == -1 ? '' : ''); //+ 'cache=' + new Date().getTime();
			else
				url = (url.indexOf('?') == -1 ? '' : ''); //+ 'cache=' + new Date().getTime();

			return url;
		}

	},
	Cookie : {

		Get : function(name, defaultValue) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return defaultValue;
		},
		Set : function(name, value, days, cleared) {
			if(!cleared)
				Core.Cookie.Clear(name);
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";

		},
		Clear : function(name) {
			Core.Cookie.Set(name, '', -1, true);
		}

	},
	CSS : {
		/*
			Function				:	Core.CSS.Load(path, media, callback);
			Params				:	path(string), media(string),callback(function)
			Description		:	Attempts to load a css file, if callback is provided, 
								fire callback when css has loaded.
			Example			:	Core.CSS.Load('File.css', 'screen', function() { alert('loaded'); });
		 */
		Load : function(path, media, callback) {

			var head = Core.DOM.GetHead();
			if(!head) {
				alert('An unknown error has occurred');
				return;
			}
			var id = 'css_' + Core.Generic.md5(path);
			if(Core.DOM.GetEl(id))
				return;

			var lib = Core.DOM.CreateEl('LINK', {
				rel : 'stylesheet',
				media : media,
				type : 'text/css',
				id : id,
				onload : (typeof(callback) != 'undefined' ? function() {
					callback(name)
				} : function() {}),
				href : (path.indexOf('http') == -1 ? Core.Locations.Root + 'assets/css/' + path : path) + Core.CacheBuster.Add(path, true)
			}, head);

		},
		SetCSS : function(path, name, value) {

			var id = 'css_' + Core.Generic.md5(path);
			var ss = Core.DOM.GetEl(id);
			if(!ss)
				return false;

			var rules = ss.cssRules ? ss.cssRules: ss.rules;
			var rule = false;
			for (i=0; i < rules.length; i++) {
				if(rules[i].selectorText.toLowerCase()==name){ 
					rule = myrules[i];
					break;
				}
			}
			if(rule != false) {
				rule;
				zz
			}
		}
	},
	Library : {
		PollLoaded : function(name, callback) {
			var libC = eval('Core.' + name.replace('/', ''));
			if(!libC || typeof(libC) == 'undefined') {
				setTimeout(function() {
					Core.Library.PollLoaded(name, callback);
				}, 10);
			} else{
				callback(name);
			}
		},
		/*
			Function				:	Core.Library.Load(name, callback);
			Params				:	name(string), callback(function)
			Description		:	Attempts to load an external library file, if callback is provided, 
								fire callback when library has loaded.
			Example			:	Core.Library.Load('Ajax', function() { alert('loaded'); });
		 */
		Load : function(name, callback) {
			var head = Core.DOM.GetHead();
			if(!head) {
				alert('An unknown error has occurred');
				return;
			}
			if(Core.DOM.GetEl(name.replace('/', '') + '_library') == null) {
				var lib = Core.DOM.CreateEl('SCRIPT', {
					type : 'text/javascript',
					id : name.replace('/', '') + '_library',
					src : Core.Locations.Root + 'assets/javascript/Core/' + name + '_library.js' + Core.CacheBuster.Add(name, true)
				}, head);
			}

			if(callback)
				Core.Library.PollLoaded(name, callback);
		},
		/*
			Function				:	Core.Library.Unload(name);
			Params				:	name(string)
			Description		:	Unloads an external library file.
			Example			:	Core.Library.Unload('Ajax');
		 */
		Unload : function(name) {
			var library = Core.DOM.GetEl(name.replace('/', '') + '_library');
			if(!library) return;
			Core.DOM.RemoveEl(library);
		}

	},
	Helper : {
		/*
			Function				:	Core.Helper.Load(name, callback);
			Params				:	name(string), callback(function)
			Description		:	Attempts to load an external helper file, if callback is provided, 
								fire callback when library has loaded.								
			Example			:	Core.Helper.Load('Ajax', function() { alert('loaded'); });
		 */
		Load : function(name) {

			var head = Core.DOM.GetHead();
			if(!head) {
				alert('An unknown error has occurred');
				return;
			}
			var id = 'helper_' + Core.Generic.md5(name);
			if(Core.DOM.GetEl(id))
				return;
			Core.DOM.CreateEl('SCRIPT', {
				type : 'text/javascript',
				id : id,
				src : Core.Locations.Root + 'assets/javascript/Helpers/' + Core.CacheBuster.Add(name)
			}, head);

		},
		GetPath : function(name, noCacheBuster) {
			return Core.Locations.Root + 'assets/javascript/Helpers/' + (typeof(noCacheBuster) != 'undefined' && noCacheBuster == true ? Core.CacheBuster.Add(name) : name);
		}

	},
	EventHandler : {
		/*
			Function				:	Core.EventHandler.Add(element, event, callback)
			Params				:	element(object), event(string), callback(function)
			Description		:	Attatches a callback to the element when the required event is fired.
			Example			:	Core.EventHandler.Add(window, 'load', function() { alert('This page has loaded!'); });
		 */
		QuickOnload : function(callback) {
			if(!Core.DOM.GetEl('jsloader')) {
				setTimeout(function() {
					Core.EventHandler.QuickOnload(callback);
				}, 10);
				return;
			}
			callback();
		},
		/*
			Function				:	Core.EventHandler.Add(element, event, callback)
			Params				:	element(object), event(string), callback(function)
			Description		:	Attatches a callback to the element when the required event is fired.
			Example			:	Core.EventHandler.Add(window, 'load', function() { alert('This page has loaded!'); });
		 */
		Add : function(element, event, callback) {
			if (element.addEventListener)
				element.addEventListener(event, function(e) {
					if(!e) e = window.event;
					return callback.call(element, e);
				}, false);
			else if (element.attachEvent) {
				element["e"+event+callback] = callback;
				element[event+callback] = function() {
					return element["e"+event+callback].call(element, window.event);
				};
				element.attachEvent("on"+event, element[event+callback]);
			}
		},
		/*
			Function				:	Core.EventHandler.Remove(element, event, callback)
			Params				:	element(object), event(string), callback(function)
			Description		:	Removes the attached callback from the element.
			Example			:	Core.EventHandler.Remove(window, 'load', function() { alert('This page has loaded!'); });
		 */
		Remove : function(element, event, callback) {

			if ( element.detachEvent ) {
				element.detachEvent( 'on'+event, element[event+callback] );
				element[event+callback] = null;
			} else
				element.removeEventListener( event, callback, false );

		},
		Observe : function(name, callback) {
			if(typeof(name) == 'undefined') {
				setTimeout(function() {
					Core.EventHandler.Observe(name, callback);
				}, 10);
				return;
			}
			callback();
		},
		Cancel : function(e) {
			if(!e) e = window.event;

			try {
				e.preventDefault();
			} catch(e){}
			try {
				e.cancelBubble = true;
			} catch(e){}
			try {
				e.stopPropagation();
			} catch(e) {}
			try {
				e.returnValue = false;
			} catch(e){}

			return false;
		}
	},
	DOM : {

		GetEl : function(el, parent) {
			var original = el;
			if(!parent) parent = document;
			if(typeof(el) == 'string') {
				if(el.indexOf('.') == 0) {
					el = el.substring(1, el.length);
					var elements = Core.DOM.GetElementsByClassName(el, '*', parent);
					if(elements.length == 1)
						return elements[0];
					else if(elements.length == 0)
						el = null;
					else
						el = elements;
				} else if(el.indexOf('.') > 0) {
					var parts = el.split('.');
					var elements = Core.DOM.GetElementsByClassName(parts[1], parts[0], parent);
					if(elements.length == 1)
						el = elements[0];
					else if(elements.length == 0)
						el = null;
					else
						el = elements;
				} else
					el = document.getElementById(el);
			}
			return el;
		},
		CreateEl : function(type, attributes, parent) {

			var el = document.createElement(type);
			for(var attribute in attributes) {
				try {
					el[attribute] = attributes[attribute];
				} catch(e) {
					alert('Unable to create element of type [' + type + '] as the attribute [' + attribute + '] does not exist!');
					return false;
				}
			}
			if(typeof(parent) != 'undefined')
				parent.appendChild(el);
			return el;

		},
		RemoveEl : function(el) {
			el.parentNode.removeChild(el);
		},
		GetValue : function(el) {

			var el = Core.DOM.GetEl(el);
			if(!el || !el.nodeName)
				return '';

			switch(el.nodeName.toLowerCase()) {
				case 'input' :

					switch(el.type.toLowerCase()) {
						case 'checkbox' :
						case 'radio' :
							return el.checked;
							break;
						case 'text' :
						case 'textarea' :
						case 'hidden' :
							return el.value;
							break;
					}

					break;
				case 'select' :

					if(el.options.length > 0)
						return el.options[el.selectedIndex].value;

					break;
				case 'textarea' :

					return el.value;

					break;
			}

			return '';

		},
		GetHead : function() {
			var heads = document.getElementsByTagName('HEAD');
			if(heads.length == 0)
				return false;
			return heads[0];
		},
		GetBody : function() {
			var bodies = document.getElementsByTagName('BODY');
			if(bodies.length == 0)
				return false;
			return bodies[0];
		},
		GetForm : function(id) {
			if(id)
				return Core.DOM.GetEl(id);
			var forms = document.getElementsByTagName('FORM');
			if(forms.length == 0)
				return false;
			return forms[0];
		},
		SetAttributes : function(el, attributes) {
			for(var attribute in attributes) {
				try {
					el[attribute] = attributes[attribute];
				} catch(e) {
					alert('Unable to set attribute [' + attribute + '] as it does not exist!');
					return false;
				}
			}
			return true;
		},
		Disable : function(el) {
			var el = Core.DOM.GetEl(el);
			el.disabled = true;
		},
		Enable : function(el) {
			var el = Core.DOM.GetEl(el);
			el.disabled = false;
		},
		AppendText : function(text, el, clearFirst) {
			if(clearFirst)
				el.innerHTML = '';
			el.appendChild(document.createTextNode(text));
		},
		RemoveEl : function(el) {
			el = Core.DOM.GetEl(el);
			if(!el)
				return;
			el.parentNode.removeChild(el);
		},	
		GetElementsByName : function(name, parent) {
			var root = document;
			if(parent)
				root = parent;
			var elements = root.getElementsByTagName('*');
			var ret = [];
			for(var i = 0; i < elements.length; i++) {
				if(elements[i].name && elements[i].name == name)
					ret.push(elements[i]);
			}
			return (ret.length == 1 ? ret[0] : ret);
		},
		GetElementsByClassName : function(className, tag, elm){
			var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
			var tag = tag || "*";
			var elm = elm || document;
			var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
			var returnElements = [];
			var current;
			var length = elements.length;
			for(var i=0; i<length; i++){
				current = elements[i];
				if(testClass.test(current.className)){
					returnElements.push(current);
				}
			}
			return returnElements;
		},
		GetPosition : function(el) {

			var curleft = curtop = 0;
			if (el.offsetParent) {
				do {
					curleft += el.offsetLeft;
					curtop += el.offsetTop;
				} 
				while (el = el.offsetParent);
			}
			return {
				Left : curleft,
				Top : curtop
			};

		}

	},
	Generic : {

		Browser : {

			IsIE : function() {
				return navigator.userAgent.toLowerCase().indexOf('msie')>-1;
			},
			IsFirefox : function() {
				return navigator.userAgent.toLowerCase().indexOf('firefox')>-1;
			}

		},
		Copy : function(inElement) {
			if (inElement.createTextRange) {
				var range = inElement.createTextRange();
				if (range && BodyLoaded==1)
					range.execCommand('Copy');
			} else {
				var flashcopier = 'flashcopier';
				if(!document.getElementById(flashcopier)) {
					var divholder = document.createElement('div');
					divholder.id = flashcopier;
					document.body.appendChild(divholder);
				}
				document.getElementById(flashcopier).innerHTML = '';
				var divinfo = '<embed src="' + Core.Locations.Root + 'assets/javascript/Helpers/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
				document.getElementById(flashcopier).innerHTML = divinfo;
			}
		},
		Status : function(status) {
			if(window.status)
				window.status = status;
		},
		StripInvalidChars : function(rules, e, text) {
			var output = '';
			for(var i = 0; i < text.length; i++) {
				if(Core.Generic.ValidateKeyPress(rules, e, text.charAt(i)))
					output += text.charAt(i);
			}
			return output;
		},
		Action : {

			Post : function(url, params, target) {
				var body = document.body;
				var form = Core.DOM.CreateEl('FORM', {
					action : url,
					method : 'post'
				}, body);
				if(target)
					form.target = target;
				if(params) {
					for(var i in params) {
						Core.DOM.CreateEl('INPUT', {
							type : 'hidden',
							name : i,
							value : params[i]
						}, form);
					}
				}
				form.submit();
			},
			Get : function(url) {
				location.href = url;
			}

		},
		JSON : {
			
			Encode : function(mixed_val) {
				// http://kevin.vanzonneveld.net
				// +      original by: Public Domain (http://www.json.org/json2.js)
				// + reimplemented by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// *     example 1: json_encode(['e', {pluribus: 'unum'}]);
				// *     returns 1: '[\n    "e",\n    {\n    "pluribus": "unum"\n}\n]'
			 
				/*
					http://www.JSON.org/json2.js
					2008-11-19
					Public Domain.
					NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
					See http://www.JSON.org/js.html
				 */
				
				var indent;
				var value = mixed_val;
				var i;
			 
				var quote = function (string) {
					var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
					var meta = {    // table of character substitutions
						'\b': '\\b',
						'\t': '\\t',
						'\n': '\\n',
						'\f': '\\f',
						'\r': '\\r',
						'"' : '\\"',
						'\\': '\\\\'
					};
			 
					escapable.lastIndex = 0;
					return escapable.test(string) ?
					'"' + string.replace(escapable, function (a) {
						var c = meta[a];
						return typeof c === 'string' ? c :
						'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
					}) + '"' :
					'"' + string + '"';
				}
			 
				var str = function(key, holder) {
					var gap = '';
					var indent = '';
					var i = 0;          // The loop counter.
					var k = '';          // The member key.
					var v = '';          // The member value.
					var length = 0;
					var mind = gap;
					var partial = [];
					var value = holder[key];
			 
					// If the value has a toJSON method, call it to obtain a replacement value.
					if (value && typeof value === 'object' &&
						typeof value.toJSON === 'function') {
						value = value.toJSON(key);
					}
					
					// What happens next depends on the value's type.
					switch (typeof value) {
						case 'string':
							return quote(value);
			 
						case 'number':
							// JSON numbers must be finite. Encode non-finite numbers as null.
							return isFinite(value) ? String(value) : 'null';
			 
						case 'boolean':
						case 'null':
							// If the value is a boolean or null, convert it to a string. Note:
							// typeof null does not produce 'null'. The case is included here in
							// the remote chance that this gets fixed someday.
			 
							return String(value);
			 
						case 'object':
							// If the type is 'object', we might be dealing with an object or an array or
							// null.
							// Due to a specification blunder in ECMAScript, typeof null is 'object',
							// so watch out for that case.
							if (!value) {
								return 'null';
							}
			 
							// Make an array to hold the partial results of stringifying this object value.
							gap += indent;
							partial = [];
			 
							// Is the value an array?
							if (Object.prototype.toString.apply(value) === '[object Array]') {
								// The value is an array. Stringify every element. Use null as a placeholder
								// for non-JSON values.
			 
								length = value.length;
								for (i = 0; i < length; i += 1) {
									partial[i] = str(i, value) || 'null';
								}
			 
								// Join all of the elements together, separated with commas, and wrap them in
								// brackets.
								v = partial.length === 0 ? '[]' :
								gap ? '[' + gap +
								partial.join(',' + gap) + '' +
								mind + ']' :
								'[' + partial.join(',') + ']';
								gap = mind;
								return v;
							}
			 
							// Iterate through all of the keys in the object.
							for (k in value) {
								if (Object.hasOwnProperty.call(value, k)) {
									v = str(k, value);
									if (v) {
										partial.push(quote(k) + (gap ? ': ' : ':') + v);
									}
								}
							}
			 
							// Join all of the member texts together, separated with commas,
							// and wrap them in braces.
							v = partial.length === 0 ? '{}' :
							gap ? '{' + gap + partial.join(',' + gap) + '' +
							mind + '}' : '{' + partial.join(',') + '}';
							gap = mind;
							return v;
					}
				};
			 
				// Make a fake root object containing our value under the key of ''.
				// Return the result of stringifying the value.
				return str('', {
					'': value
				});

			},
			Decode : function(str) {
				return eval('(' + str + ')');
			}

		}, 
		Base64 : {

			Encode : function(data) {
				// Encodes string using MIME base64 algorithm  
				// 
				// version: 909.322
				// discuss at: http://phpjs.org/functions/base64_encode
				// +   original by: Tyler Akins (http://rumkin.com)
				// +   improved by: Bayron Guevara
				// +   improved by: Thunder.m
				// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// +   bugfixed by: Pellentesque Malesuada
				// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// -    depends on: utf8_encode
				// *     example 1: base64_encode('Kevin van Zonneveld');
				// *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
				// mozilla has this native
				// - but breaks in 2.0.0.12!
				//if (typeof this.window['atob'] == 'function') {
				//    return atob(data);
				//}
					
				var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
				var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

				if (!data) {
					return data;
				}

				data = Core.Generic.utf8_encode(data+'');
				
				do { // pack three octets into four hexets
					o1 = data.charCodeAt(i++);
					o2 = data.charCodeAt(i++);
					o3 = data.charCodeAt(i++);

					bits = o1<<16 | o2<<8 | o3;

					h1 = bits>>18 & 0x3f;
					h2 = bits>>12 & 0x3f;
					h3 = bits>>6 & 0x3f;
					h4 = bits & 0x3f;

					// use hexets to index into b64, and append result to encoded string
					tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
				} while (i < data.length);
				
				enc = tmp_arr.join('');
				
				switch (data.length % 3) {
					case 1:
						enc = enc.slice(0, -2) + '==';
						break;
					case 2:
						enc = enc.slice(0, -1) + '=';
						break;
				}

				return enc;
			},
			Decode : function(val) {
				// Decodes string using MIME base64 algorithm  
				// 
				// version: 909.322
				// discuss at: http://phpjs.org/functions/base64_decode
				// +   original by: Tyler Akins (http://rumkin.com)
				// +   improved by: Thunder.m
				// +      input by: Aman Gupta
				// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// +   bugfixed by: Onno Marsman
				// +   bugfixed by: Pellentesque Malesuada
				// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// +      input by: Brett Zamir (http://brett-zamir.me)
				// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
				// -    depends on: utf8_decode
				// *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
				// *     returns 1: 'Kevin van Zonneveld'
				// mozilla has this native
				// - but breaks in 2.0.0.12!
				//if (typeof this.window['btoa'] == 'function') {
				//    return btoa(data);
				//}

				var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
				var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

				if (!data) {
					return data;
				}

				data += '';

				do {  // unpack four hexets into three octets using index points in b64
					h1 = b64.indexOf(data.charAt(i++));
					h2 = b64.indexOf(data.charAt(i++));
					h3 = b64.indexOf(data.charAt(i++));
					h4 = b64.indexOf(data.charAt(i++));

					bits = h1<<18 | h2<<12 | h3<<6 | h4;

					o1 = bits>>16 & 0xff;
					o2 = bits>>8 & 0xff;
					o3 = bits & 0xff;

					if (h3 == 64) {
						tmp_arr[ac++] = String.fromCharCode(o1);
					} else if (h4 == 64) {
						tmp_arr[ac++] = String.fromCharCode(o1, o2);
					} else {
						tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
					}
				} while (i < data.length);

				dec = tmp_arr.join('');
				dec = Core.Generic.utf8_decode(dec);

				return dec;

			}

		},
		Dump : function(arr,level) {
			var dumped_text = "";
			if(!level) level = 0;
			
			//The padding given at the beginning of the line.
			var level_padding = "";
			for(var j=0;j<level+1;j++) level_padding += "    ";
			
			if(typeof(arr) == 'object') { //Array/Hashes/Objects 
				for(var item in arr) {
					var value = arr[item];
					
					if(typeof(value) == 'object') { //If it is an array,
						dumped_text += level_padding + "'" + item + "' ...\n";
						dumped_text += Core.Generic.Dump(value,level+1);
					} else {
						dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
					}
				}
			} else { //Stings/Chars/Numbers etc.
				dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
			}
			return dumped_text;
		},
		ValidateKeyPress : function(rules, e, text) {

			if(!e) e = window.event;
			var keyCode = e.which | e.keyCode;

			if(text)
				keyCode = text.charCodeAt();

			var shift = (typeof(e.shiftKey) != 'undefined' ? e.shiftKey : false);

			var defaults = [8,9,46,48,49,35,36,37,38,39,40];
			for(var i = 0; i < defaults.length; i++) {
				if(defaults[i] == keyCode && !shift)
					return true;
			}

			if(e.ctrlKey && (keyCode == 65 || keyCode == 86 || keyCode == 67))
				return true;

			if(typeof(rules.Single) != 'undefined') {
				for(var key in rules.Single) {
					var single = rules.Single[key];
					if(shift == single.Shift && single.Key == keyCode)
						return true;
				}
			}
			if(typeof(rules.Range) != 'undefined') {
				for(var name in rules.Range) {
					var range = rules.Range[name];
					if(shift == range.Shift && keyCode >= range.From && keyCode <= range.To)
						return true;
				}
			}
			return false;
		},
		nl2br : function(str) {
			return str.replace(/\n/g, '<br />');
		},
		br2nl : function(str) {
			str = str.replace(/\n|\r/g, '');
			str = str.replace(/<br \/>/g, "\n");
			str = str.replace(/<br>/g, "\n");
			return str;
		},
        createDropDown: function(str){
            var drop = jQuery('<select>');
            str = str.split("<br \/>");
            for( var i = 0; i < str.length; i++){
                var tmp = jQuery('<option>'+str[i]+'</option>').appendTo(drop);
            }
            return drop;
        },
		Unescape : function(str) {
			var ret = str;
			try
			{
				var ta = document.createElement("textarea");
				ta.innerHTML=str.replace(/</g,"<").replace(/>/g,">");
				ret = ta.value;
				ta = null;
			}
			catch(e) {}
			return ret;
		},
		Trim : function(str, chars) {
			return Core.Generic.LTrim(Core.Generic.RTrim(str, chars), chars);
		},
		LTrim : function(str, chars) {
			chars = chars || "\\s";
			return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
		},
		RTrim : function(str, chars) {
			chars = chars || "\\s";
			return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
		},
		md5 : function( str ) {
			// http://kevin.vanzonneveld.net
			// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
			// + namespaced by: Michael White (http://getsprink.com)
			// +    tweaked by: Jack
			// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// -    depends on: utf8_encode
			// *     example 1: md5('Kevin van Zonneveld');
			// *     returns 1: '6e658d4bfcb59cc13f96c14450ac40b9'
		 
			var RotateLeft = function(lValue, iShiftBits) {
				return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
			};
		 
			var AddUnsigned = function(lX,lY) {
				var lX4,lY4,lX8,lY8,lResult;
				lX8 = (lX & 0x80000000);
				lY8 = (lY & 0x80000000);
				lX4 = (lX & 0x40000000);
				lY4 = (lY & 0x40000000);
				lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
				if (lX4 & lY4) {
					return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
				}
				if (lX4 | lY4) {
					if (lResult & 0x40000000) {
						return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
					} else {
						return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
					}
				} else {
					return (lResult ^ lX8 ^ lY8);
				}
			};
		 
			var F = function(x,y,z) {
				return (x & y) | ((~x) & z);
			};
			var G = function(x,y,z) {
				return (x & z) | (y & (~z));
			};
			var H = function(x,y,z) {
				return (x ^ y ^ z);
			};
			var I = function(x,y,z) {
				return (y ^ (x | (~z)));
			};
		 
			var FF = function(a,b,c,d,x,s,ac) {
				a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
				return AddUnsigned(RotateLeft(a, s), b);
			};
		 
			var GG = function(a,b,c,d,x,s,ac) {
				a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
				return AddUnsigned(RotateLeft(a, s), b);
			};
		 
			var HH = function(a,b,c,d,x,s,ac) {
				a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
				return AddUnsigned(RotateLeft(a, s), b);
			};
		 
			var II = function(a,b,c,d,x,s,ac) {
				a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
				return AddUnsigned(RotateLeft(a, s), b);
			};
		 
			var ConvertToWordArray = function(str) {
				var lWordCount;
				var lMessageLength = str.length;
				var lNumberOfWords_temp1=lMessageLength + 8;
				var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
				var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
				var lWordArray=Array(lNumberOfWords-1);
				var lBytePosition = 0;
				var lByteCount = 0;
				while ( lByteCount < lMessageLength ) {
					lWordCount = (lByteCount-(lByteCount % 4))/4;
					lBytePosition = (lByteCount % 4)*8;
					lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount)<<lBytePosition));
					lByteCount++;
				}
				lWordCount = (lByteCount-(lByteCount % 4))/4;
				lBytePosition = (lByteCount % 4)*8;
				lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
				lWordArray[lNumberOfWords-2] = lMessageLength<<3;
				lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
				return lWordArray;
			};
		 
			var WordToHex = function(lValue) {
				var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
				for (lCount = 0;lCount<=3;lCount++) {
					lByte = (lValue>>>(lCount*8)) & 255;
					WordToHexValue_temp = "0" + lByte.toString(16);
					WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
				}
				return WordToHexValue;
			};
		 
			var x=Array();
			var k,AA,BB,CC,DD,a,b,c,d;
			var S11=7, S12=12, S13=17, S14=22;
			var S21=5, S22=9 , S23=14, S24=20;
			var S31=4, S32=11, S33=16, S34=23;
			var S41=6, S42=10, S43=15, S44=21;
		 
			str = Core.Generic.utf8_encode(str);
			x = ConvertToWordArray(str);
			a = 0x67452301;
			b = 0xEFCDAB89;
			c = 0x98BADCFE;
			d = 0x10325476;
			
			xl = x.length;
			for (k=0;k<xl;k+=16) {
				AA=a;
				BB=b;
				CC=c;
				DD=d;
				a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
				d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
				c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
				b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
				a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
				d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
				c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
				b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
				a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
				d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
				c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
				b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
				a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
				d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
				c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
				b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
				a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
				d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
				c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
				b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
				a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
				d=GG(d,a,b,c,x[k+10],S22,0x2441453);
				c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
				b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
				a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
				d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
				c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
				b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
				a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
				d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
				c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
				b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
				a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
				d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
				c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
				b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
				a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
				d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
				c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
				b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
				a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
				d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
				c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
				b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
				a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
				d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
				c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
				b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
				a=II(a,b,c,d,x[k+0], S41,0xF4292244);
				d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
				c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
				b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
				a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
				d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
				c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
				b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
				a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
				d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
				c=II(c,d,a,b,x[k+6], S43,0xA3014314);
				b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
				a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
				d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
				c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
				b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
				a=AddUnsigned(a,AA);
				b=AddUnsigned(b,BB);
				c=AddUnsigned(c,CC);
				d=AddUnsigned(d,DD);
			}
		 
			var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
		 
			return temp.toLowerCase();
		},
		Date : function ( format, timestamp ) {
			// http://kevin.vanzonneveld.net
			// +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
			// +      parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html)
			// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   improved by: MeEtc (http://yass.meetcweb.com)
			// +   improved by: Brad Touesnard
			// +   improved by: Tim Wiel
			// +   improved by: Bryan Elliott
			// +   improved by: Brett Zamir (http://brettz9.blogspot.com)
			// +   improved by: David Randall
			// +      input by: Brett Zamir (http://brettz9.blogspot.com)
			// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   improved by: Brett Zamir (http://brettz9.blogspot.com)
			// +   improved by: Brett Zamir (http://brettz9.blogspot.com)
			// +   derived from: gettimeofday
			// %        note 1: Uses global: php_js to store the default timezone
			// *     example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
			// *     returns 1: '09:09:40 m is month'
			// *     example 2: date('F j, Y, g:i a', 1062462400);
			// *     returns 2: 'September 2, 2003, 2:26 am'
			// *     example 3: date('Y W o', 1062462400);
			// *     returns 3: '2003 36 2003'
			// *     example 4: x = date('Y m d', (new Date()).getTime()/1000); // 2009 01 09
			// *     example 4: (x+'').length == 10
			// *     returns 4: true
		 
			var jsdate=(
				(typeof(timestamp) == 'undefined') ? new Date() : // Not provided
				(typeof(timestamp) == 'number') ? new Date(timestamp*1000) : // UNIX timestamp
				new Date(timestamp) // Javascript Date()
				); // , tal=[]
			var pad = function(n, c){
				if( (n = n + "").length < c ) {
					return new Array(++c - n.length).join("0") + n;
				} else {
					return n;
				}
			};
			var _dst = function (t) {
				// Calculate Daylight Saving Time (derived from gettimeofday() code)
				var dst=0;
				var jan1 = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
				var june1 = new Date(t.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
				var temp = jan1.toUTCString();
				var jan2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
				temp = june1.toUTCString();
				var june2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
				var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
				var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
		 
				if (std_time_offset === daylight_time_offset) {
					dst = 0; // daylight savings time is NOT observed
				}
				else {
					// positive is southern, negative is northern hemisphere
					var hemisphere = std_time_offset - daylight_time_offset;
					if (hemisphere >= 0) {
						std_time_offset = daylight_time_offset;
					}
					dst = 1; // daylight savings time is observed
				}
				return dst;
			};
			var ret = '';
			var txt_weekdays = ["Sunday","Monday","Tuesday","Wednesday",
			"Thursday","Friday","Saturday"];
			var txt_ordin = {
				1:"st",
				2:"nd",
				3:"rd",
				21:"st",
				22:"nd",
				23:"rd",
				31:"st"
			};
			var txt_months =  ["", "January", "February", "March", "April",
			"May", "June", "July", "August", "September", "October", "November",
			"December"];
		 
			var f = {
				// Day
				d: function(){
					return pad(f.j(), 2);
				},
				D: function(){
					var t = f.l();
					return t.substr(0,3);
				},
				j: function(){
					return jsdate.getDate();
				},
				l: function(){
					return txt_weekdays[f.w()];
				},
				N: function(){
					return f.w() + 1;
				},
				S: function(){
					return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
				},
				w: function(){
					return jsdate.getDay();
				},
				z: function(){
					return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
				},
		 
				// Week
				W: function(){
					var a = f.z(), b = 364 + f.L() - a;
					var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
		 
					if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
						return 1;
					}
					if(a <= 2 && nd >= 4 && a >= (6 - nd)){
						nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
						return date("W", Math.round(nd2.getTime()/1000));
					}
					return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
				},
		 
				// Month
				F: function(){
					return txt_months[f.n()];
				},
				m: function(){
					return pad(f.n(), 2);
				},
				M: function(){
					var t = f.F();
					return t.substr(0,3);
				},
				n: function(){
					return jsdate.getMonth() + 1;
				},
				t: function(){
					var n;
					if( (n = jsdate.getMonth() + 1) == 2 ){
						return 28 + f.L();
					}
					if( n & 1 && n < 8 || !(n & 1) && n > 7 ){
						return 31;
					}
					return 30;
				},
		 
				// Year
				L: function(){
					var y = f.Y();
					return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
				},
				o: function(){
					if (f.n() === 12 && f.W() === 1) {
						return jsdate.getFullYear()+1;
					}
					if (f.n() === 1 && f.W() >= 52) {
						return jsdate.getFullYear()-1;
					}
					return jsdate.getFullYear();
				},
				Y: function(){
					return jsdate.getFullYear();
				},
				y: function(){
					return (jsdate.getFullYear() + "").slice(2);
				},
		 
				// Time
				a: function(){
					return jsdate.getHours() > 11 ? "pm" : "am";
				},
				A: function(){
					return f.a().toUpperCase();
				},
				B: function(){
					// peter paul koch:
					var off = (jsdate.getTimezoneOffset() + 60)*60;
					var theSeconds = (jsdate.getHours() * 3600) +
					(jsdate.getMinutes() * 60) +
					jsdate.getSeconds() + off;
					var beat = Math.floor(theSeconds/86.4);
					if (beat > 1000) {
						beat -= 1000;
					}
					if (beat < 0) {
						beat += 1000;
					}
					if ((String(beat)).length == 1) {
						beat = "00"+beat;
					}
					if ((String(beat)).length == 2) {
						beat = "0"+beat;
					}
					return beat;
				},
				g: function(){
					return jsdate.getHours() % 12 || 12;
				},
				G: function(){
					return jsdate.getHours();
				},
				h: function(){
					return pad(f.g(), 2);
				},
				H: function(){
					return pad(jsdate.getHours(), 2);
				},
				i: function(){
					return pad(jsdate.getMinutes(), 2);
				},
				s: function(){
					return pad(jsdate.getSeconds(), 2);
				},
				u: function(){
					return pad(jsdate.getMilliseconds()*1000, 6);
				},
		 
				// Timezone
				e: function () {
					/*                var abbr='', i=0;
						if (this.php_js && this.php_js.default_timezone) {
							return this.php_js.default_timezone;
						}
						if (!tal.length) {
							tal = timezone_abbreviations_list();
						}
						for (abbr in tal) {
							for (i=0; i < tal[abbr].length; i++) {
								if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
									return tal[abbr][i].timezone_id;
								}
							}
						}
					 */
					return 'UTC';
				},
				I: function(){
					return _dst(jsdate);
				},
				O: function(){
					var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
					t = (jsdate.getTimezoneOffset() > 0) ? "-"+t : "+"+t;
					return t;
				},
				P: function(){
					var O = f.O();
					return (O.substr(0, 3) + ":" + O.substr(3, 2));
				},
				T: function () {
					/*                var abbr='', i=0;
						if (!tal.length) {
							tal = timezone_abbreviations_list();
						}
						if (this.php_js && this.php_js.default_timezone) {
							for (abbr in tal) {
								for (i=0; i < tal[abbr].length; i++) {
									if (tal[abbr][i].timezone_id === this.php_js.default_timezone) {
										return abbr.toUpperCase();
									}
								}
							}
						}
						for (abbr in tal) {
							for (i=0; i < tal[abbr].length; i++) {
								if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
									return abbr.toUpperCase();
								}
							}
						}
					 */
					return 'UTC';
				},
				Z: function(){
					return -jsdate.getTimezoneOffset()*60;
				},
		 
				// Full Date/Time
				c: function(){
					return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
				},
				r: function(){
					return f.D()+', '+f.d()+' '+f.M()+' '+f.Y()+' '+f.H()+':'+f.i()+':'+f.s()+' '+f.O();
				},
				U: function(){
					return Math.round(jsdate.getTime()/1000);
				}
			};
		 
			return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){
				if( t!=s ){
					// escaped
					ret = s;
				} else if( f[s] ){
					// a date function exists
					ret = f[s]();
				} else{
					// nothing special
					ret = s;
				}
				return ret;
			});
		},
		utf8_encode : function( string ) {
			// http://kevin.vanzonneveld.net
			// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
			// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   improved by: sowberry
			// +    tweaked by: Jack
			// +   bugfixed by: Onno Marsman
			// *     example 1: Core.Generic.utf8_encode('Kevin van Zonneveld');
			// *     returns 1: 'Kevin van Zonneveld'
		 
			string = (string+'').replace(/\r\n/g,"\n");
			var utftext = "";
			var start, end;
			var stringl = 0;
		 
			start = end = 0;
			stringl = string.length;
			for (var n = 0; n < stringl; n++) {
				var c1 = string.charCodeAt(n);
				var enc = null;
		 
				if (c1 < 128) {
					end++;
				} else if((c1 > 127) && (c1 < 2048)) {
					enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
				} else {
					enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
				}
				if (enc != null) {
					if (end > start) {
						utftext += string.substring(start, end);
					}
					utftext += enc;
					start = end = n+1;
				}
			}
		 
			if (end > start) {
				utftext += string.substring(start, string.length);
			}
		 
			return utftext;
		},
		utf8_decode : function( str_data ) {
			// Converts a UTF-8 encoded string to ISO-8859-1  
			// 
			// version: 909.322
			// discuss at: http://phpjs.org/functions/utf8_decode
			// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
			// +      input by: Aman Gupta
			// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   improved by: Norman "zEh" Fuchs
			// +   bugfixed by: hitwork
			// +   bugfixed by: Onno Marsman
			// +      input by: Brett Zamir (http://brett-zamir.me)
			// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// *     example 1: utf8_decode('Kevin van Zonneveld');
			// *     returns 1: 'Kevin van Zonneveld'
			var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
			
			str_data += '';
			
			while ( i < str_data.length ) {
				c1 = str_data.charCodeAt(i);
				if (c1 < 128) {
					tmp_arr[ac++] = String.fromCharCode(c1);
					i++;
				} else if ((c1 > 191) && (c1 < 224)) {
					c2 = str_data.charCodeAt(i+1);
					tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
					i += 2;
				} else {
					c2 = str_data.charCodeAt(i+1);
					c3 = str_data.charCodeAt(i+2);
					tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
					i += 3;
				}
			}

			return tmp_arr.join('');
		},
		htmlentities : function(string, quote_style) {
			// http://kevin.vanzonneveld.net
			// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   improved by: nobbler
			// +    tweaked by: Jack
			// +   bugfixed by: Onno Marsman
			// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +    bugfixed by: Brett Zamir (http://brett-zamir.me)
			// +      input by: Ratheous
			// -    depends on: get_html_translation_table
			// *     example 1: htmlentities('Kevin & van Zonneveld');
			// *     returns 1: 'Kevin &amp; van Zonneveld'
			// *     example 2: htmlentities("foo'bar","ENT_QUOTES");
			// *     returns 2: 'foo&#039;bar'
		 
			var hash_map = {}, symbol = '', tmp_str = '', entity = '';
			tmp_str = string.toString();
			
			if (false === (hash_map = Core.Generic.get_html_translation_table('HTML_ENTITIES', quote_style))) {
				return false;
			}
			hash_map["'"] = '&#039;';
			for (symbol in hash_map) {
				entity = hash_map[symbol];
				tmp_str = tmp_str.split(symbol).join(entity);
			}
			
			return tmp_str;
		},
		get_html_translation_table : function(table, quote_style) {
			// http://kevin.vanzonneveld.net
			// +   original by: Philip Peterson
			// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
			// +   bugfixed by: noname
			// +   bugfixed by: Alex
			// +   bugfixed by: Marco
			// +   bugfixed by: madipta
			// +   improved by: KELAN
			// +   improved by: Brett Zamir (http://brett-zamir.me)
			// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
			// +      input by: Frank Forte
			// +   bugfixed by: T.Wild
			// +      input by: Ratheous
			// %          note: It has been decided that we're not going to add global
			// %          note: dependencies to php.js, meaning the constants are not
			// %          note: real constants, but strings instead. Integers are also supported if someone
			// %          note: chooses to create the constants themselves.
			// *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
			// *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
			
			var entities = {}, hash_map = {}, decimal = 0, symbol = '';
			var constMappingTable = {}, constMappingQuoteStyle = {};
			var useTable = {}, useQuoteStyle = {};
			
			// Translate arguments
			constMappingTable[0]      = 'HTML_SPECIALCHARS';
			constMappingTable[1]      = 'HTML_ENTITIES';
			constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
			constMappingQuoteStyle[2] = 'ENT_COMPAT';
			constMappingQuoteStyle[3] = 'ENT_QUOTES';
		 
			useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
			useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
		 
			if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
				throw new Error("Table: "+useTable+' not supported');
			// return false;
			}
		 
			entities['38'] = '&amp;';
			if (useTable === 'HTML_ENTITIES') {
				entities['160'] = '&nbsp;';
				entities['161'] = '&iexcl;';
				entities['162'] = '&cent;';
				entities['163'] = '&pound;';
				entities['164'] = '&curren;';
				entities['165'] = '&yen;';
				entities['166'] = '&brvbar;';
				entities['167'] = '&sect;';
				entities['168'] = '&uml;';
				entities['169'] = '&copy;';
				entities['170'] = '&ordf;';
				entities['171'] = '&laquo;';
				entities['172'] = '&not;';
				entities['173'] = '&shy;';
				entities['174'] = '&reg;';
				entities['175'] = '&macr;';
				entities['176'] = '&deg;';
				entities['177'] = '&plusmn;';
				entities['178'] = '&sup2;';
				entities['179'] = '&sup3;';
				entities['180'] = '&acute;';
				entities['181'] = '&micro;';
				entities['182'] = '&para;';
				entities['183'] = '&middot;';
				entities['184'] = '&cedil;';
				entities['185'] = '&sup1;';
				entities['186'] = '&ordm;';
				entities['187'] = '&raquo;';
				entities['188'] = '&frac14;';
				entities['189'] = '&frac12;';
				entities['190'] = '&frac34;';
				entities['191'] = '&iquest;';
				entities['192'] = '&Agrave;';
				entities['193'] = '&Aacute;';
				entities['194'] = '&Acirc;';
				entities['195'] = '&Atilde;';
				entities['196'] = '&Auml;';
				entities['197'] = '&Aring;';
				entities['198'] = '&AElig;';
				entities['199'] = '&Ccedil;';
				entities['200'] = '&Egrave;';
				entities['201'] = '&Eacute;';
				entities['202'] = '&Ecirc;';
				entities['203'] = '&Euml;';
				entities['204'] = '&Igrave;';
				entities['205'] = '&Iacute;';
				entities['206'] = '&Icirc;';
				entities['207'] = '&Iuml;';
				entities['208'] = '&ETH;';
				entities['209'] = '&Ntilde;';
				entities['210'] = '&Ograve;';
				entities['211'] = '&Oacute;';
				entities['212'] = '&Ocirc;';
				entities['213'] = '&Otilde;';
				entities['214'] = '&Ouml;';
				entities['215'] = '&times;';
				entities['216'] = '&Oslash;';
				entities['217'] = '&Ugrave;';
				entities['218'] = '&Uacute;';
				entities['219'] = '&Ucirc;';
				entities['220'] = '&Uuml;';
				entities['221'] = '&Yacute;';
				entities['222'] = '&THORN;';
				entities['223'] = '&szlig;';
				entities['224'] = '&agrave;';
				entities['225'] = '&aacute;';
				entities['226'] = '&acirc;';
				entities['227'] = '&atilde;';
				entities['228'] = '&auml;';
				entities['229'] = '&aring;';
				entities['230'] = '&aelig;';
				entities['231'] = '&ccedil;';
				entities['232'] = '&egrave;';
				entities['233'] = '&eacute;';
				entities['234'] = '&ecirc;';
				entities['235'] = '&euml;';
				entities['236'] = '&igrave;';
				entities['237'] = '&iacute;';
				entities['238'] = '&icirc;';
				entities['239'] = '&iuml;';
				entities['240'] = '&eth;';
				entities['241'] = '&ntilde;';
				entities['242'] = '&ograve;';
				entities['243'] = '&oacute;';
				entities['244'] = '&ocirc;';
				entities['245'] = '&otilde;';
				entities['246'] = '&ouml;';
				entities['247'] = '&divide;';
				entities['248'] = '&oslash;';
				entities['249'] = '&ugrave;';
				entities['250'] = '&uacute;';
				entities['251'] = '&ucirc;';
				entities['252'] = '&uuml;';
				entities['253'] = '&yacute;';
				entities['254'] = '&thorn;';
				entities['255'] = '&yuml;';
			}
		 
			if (useQuoteStyle !== 'ENT_NOQUOTES') {
				entities['34'] = '&quot;';
			}
			if (useQuoteStyle === 'ENT_QUOTES') {
				entities['39'] = '&#39;';
			}
			entities['60'] = '&lt;';
			entities['62'] = '&gt;';
		 
		 
			// ascii decimals to real symbols
			for (decimal in entities) {
				symbol = String.fromCharCode(decimal);
				hash_map[symbol] = entities[decimal];
			}
			
			return hash_map;
		}

	},
	TextBoxList : {

		Init : function(name) {

			/*if(typeof(MooTools) == 'undefined') {
				Core.Helper.Load('mootools/mootools-1.2.1-core.js');
				setTimeout(function() {
					Core.TextBoxList.Init(name);
				}, 10);
				return;
			}*/

			if(typeof(jQuery) == 'undefined') {
				Core.Helper.Load('jquery-1.4.2.min.js');
				setTimeout(function() {
					Core.TextBoxList.Init(name);
				}, 10);
				return;
			}

			if(typeof(TextboxList) == 'undefined') {
				Core.Helper.Load('textboxlist/TextboxList.js');
				setTimeout(function() {
					Core.TextBoxList.Init(name);
				}, 10);
				return;
			}

			var elements = Core.DOM.GetEl(name);
			if(name[0] != '.')
				elements = [elements];

			var seed = new Date().getTime();
			for(var i = 0; i < elements.length; i++) {
				if(!elements[i].id || elements[i].id == '')
					elements[i].id = 'input-' + seed++;
				//if(elements[i].nodeName != 'INPUT' || (elements[i].nodeName == 'INPUT' && elements[i].type != 'TEXT'))
				//	continue;
				var items = elements[i].value.split(',');
				var t = new TextboxList(elements[i].id);
				elements[i].TextBox = t;

				for(var item = i; item < items.length; item++)
					t.add(items[item]);
			}

		}

	},
	Search : {

		Instance : null,
		Instances : Array(),
		PageInit : function() {

			if(typeof(Core.Tab) == 'undefined') {
				Core.Library.Load('Tab');
				setTimeout(function() {
					Core.Search.PageInit();
				}, 10);
				return;
			} 
			Core.Tab.Init();

			var current = Core.DOM.GetEl('current');
			if(current) {
				var a = current.getElementsByTagName('A')[0];
				if(a)
					Core.Tab.ShowTab(a.id, a.id);
			}

		},
		Init : function() {

			if(typeof(bsn) == 'undefined'){
				setTimeout(function() {
					Core.Search.Init();
				}, 10);
				return
			}
			var inst = new bsn.AutoSuggest('search_input_text', {
				script		: function(input) {
					return Core.Locations.Root + 'ajax/search';
				},
				meth		: 'POST',
				json		: true,
				maxresults	: 10,
				delay		: 1,
				minchars	: 0,
				params		: {
					type	: 'collectibles',
					input	: ''
				} 
			});

			Core.Search.Instance = inst;

			var criteria = Core.DOM.GetEl('criteria');
			Core.EventHandler.Add(criteria, 'change', function(e) {
				Core.Search.Instance.oP.params.type = this.value;
				var form = this.form;
				form.action = Core.Locations.Root + 'search/' + this.value
			});

			var searches = Core.DOM.GetElementsByClassName('search_inputs');
			if(typeof(searches) != 'undefined' && typeof(searches.length) != 'undefined' && searches.length>0){
				for(i =0; i<searches.length; i++){
					searches[i].form.action = Core.Locations.Root + 'search/' + searches[i].readAttribute('rel');
					var instance = new bsn.AutoSuggest(searches[i].id, {
						script		: function(input) {
							return Core.Locations.Root + 'ajax/search';
						},
						meth		: 'POST',
						json		: true,
						maxresults	: 10,
						delay		: 1,
						params		: {
							type	: searches[i].readAttribute('rel'),
							input	: ''
						}
					});

									Core.Search.Instances.push(instance);
				//
				//					criteria = Core.DOM.GetEl('.input_criteria',searches[i].parentNode);
				//					Core.EventHandler.Add(criteria, 'change', function(e) {
				//						Core.Search.Instances[Core.Search.Instances.length].oP.params.type = this.value;
				//						var form = this.form;
				//						form.action = Core.Locations.Root + 'search/' + this.value
				//					});
				}
			}

		}

	}

};

Core.EventHandler.QuickOnload(function() {


	
	if(Core.DOM.GetEl('global_signin_wrapper')) {
		var username_input = Core.DOM.GetEl('username_input');
		var password_input = Core.DOM.GetEl('password_input');

		var header_login_go_to = Core.DOM.GetEl('header_login_go_to');
		header_login_go_to.style.display = 'none';

		username_input.className = 'sign_in_default_text';
		username_input.onfocus = function() {
			this.CurrentValue = this.value;
			this.value = '';
			username_input.className = '';
			Core.DOM.GetEl('header_login_go_to').style.display = '';
		}
		username_input.onblur = function() {
			if(this.value == ''){
				this.value = this.CurrentValue;
				username_input.className = 'sign_in_default_text';
			}
		}
		
		// For displaying password on home page      - Vishy
		password_input.className = 'sign_in_default_text';
		password_input.onfocus = function() {
			if (password_input.value == password_input.defaultValue)
			{
				this.CurrentValue = this.value;
				this.type = "password";
				this.value = '';
				Core.DOM.GetEl('header_login_go_to').style.display = '';
			}
		}
		
		password_input.onblur = function() {
			if(this.value == ''){
				this.type= "text";
				this.value = this.CurrentValue;
				password_input.className = 'sign_in_default_text';
			}
		}

		
    
	/*if(password_input.value == ''){
      var pass2 = password_input.cloneNode(false);
      pass2.className = 'sign_in_default_text';
      pass2.type='text';
      pass2.value = 'Password';
    }
		pass2.onfocus = function() {
      var x = this.cloneNode(false);
			x.CurrentValue = x.value;
      x.className = '';
      x.type="password";
			x.value = '';
    pass2.parentNode.replaceChild(x,pass2)
			Core.DOM.GetEl('header_login_go_to').style.display = '';
		}
		pass2.onblur = function() {
			if(this.value == ''){
        //password_input.className = 'sign_in_default_text';
        //password_input.type = 'text';
        //password_input.value = 'Password';
      }
		}
    password_input.parentNode.replaceChild(pass2,password_input);*/
	}

	if(Core.DOM.GetEl('global_msg_box_wrapper')) {

		var close = Core.DOM.GetEl('global_msg_box_close');
		if(close) {
			Core.Library.Load('Ajax', function() {
				var close = Core.DOM.GetEl('global_msg_box_close');
				close.onclick = function(e) {
					Core.Ajax.QuickRequest('ajax', 'user', {
						Action : 'addnotificationfilter',
						'NotificationID' : this.getAttribute('rel')
					}, function(res) {
						var resp = Core.Ajax.RequestToJSON(res);
						if(!resp) {
							Core.Ajax.ErrorHandler(res);
							return;
						}
						if(resp.Error) {
							Core.Ajax.ErrorHandler(resp);
							return;
						}

						var box = Core.DOM.GetEl('global_msg_box_wrapper');
						if(box)
							box.parentNode.removeChild(box);
					});
				}
			});
		}

	}

	Core.Search.Init();


	Core.Library.Load('Tip');
	Core.Library.PollLoaded('Tip', function() {
		Core.Tip.Init();
		
		Core.Tip.Enable('.cstooltip');
	});
/*Core.EventHandler.Observe('Tip', function() {
	});

		var cstooltip = Core.DOM.GetEl('.cstooltip');
		if(!cstooltip)
			return;
		if(typeof(cstooltip.push) == 'undefined')
			cstooltip = [cstooltip];
		for(var i = 0; i < cstooltip.length; i++) {
			var text = cstooltip[i].getAttribute('rel');
			if(!text || text.length == 0)
				continue;
			var obj = false;
			try
			{
				obj = eval('(' + text + ')');
			}
			catch(e){}
			if(!obj)
				obj = {
					Text : text,
					Options : {}
				};

			new Tip(cstooltip[i], obj.Text, obj.Options);
		}
	});*/

});

