BrowserDetect.init();

jQuery.preventError = false;

// Error Tracking via http://blogs.cozi.com/tech/2008/04/javascript-error-tracking-why-windowonerror-is-not-enough.html
// Error tracking function
// err: a string or an Error object
function trackError( err )
{
	var msg = 'Unknown error';
	if ( err.message )
	{
		msg = err.message;
	}
	else if ( typeof err == 'string' || typeof err == 'String' )
	{
		msg = err;
	}
	$.post('/bylog.php', {message: msg + ' in ' + window.location.toString() + ' ('+BrowserDetect.browser+' '+BrowserDetect.version+'/'+BrowserDetect.OS+')'});
};

// override jQuery.fn.bind to wrap every provided function in try/catch
var jQueryBind = jQuery.fn.bind;
jQuery.fn.bind = function( type, data, fn ) { 
	if ( !fn && data && typeof data == 'function' )
	{
		fn = data;
		data = null;
	}
	if ( fn )
	{
		var origFn = fn;
		var wrappedFn = jQuery.proxy(origFn,function() { 
			try 
			{
				return origFn.apply( this, arguments );
			}
			catch ( ex )
			{
				trackError( ex );
				// re-throw ex iff error should propogate
				if (!jQuery.preventError)
				{
					throw ex;
				}
		       }
		});
		fn = wrappedFn;
	}
	return jQueryBind.call( this, type, data, fn );
};

// Attach trackError to window's onerror event;
// use onerror instead of $(window).error( ... ) in order to get url and lineNo
window.onerror = function( msg, url, lineNo ) 
{ 
	trackError( [ msg, lineNo ].join('; ') );
	// return true to stop error from propogating, false to allow propogation
	return jQuery.preventError; 
};
    
// Normal Page init

var BY = new BYApp();
jQuery(document).ready(function(){
	BY.run();	
});
// Some helpers
/**
 * Checks if an item is defined
 */
var $defined = function(v)
{
	if(typeof v == 'string')
	{
		v = $(v);
	}
	return (v != '' && typeof v != 'undefined');
}

// Checks if an element exists
var $chk = function(val)
{
	return ($(val).length > 0);
}


/*
 * BY Application Functions
 */


function BYApp() {
	
	var self = this;
	
	this.globals = {};
	
	this.run = function() {
	      
		// Handler for EXPLAIN THIS links
		$('.why').click(function(event){
			var trigger = this;
			$(this).parent().next('.why-explaination').slideToggle(function(){
					  
				if($(trigger).parent().next('.why-explaination').is(':visible'))
				{
					$(trigger).fadeOut(250,function(){
						$(trigger).text('Hide Explaination');
					});
					$(trigger).fadeIn(250);
				}
				else
				{
					$(trigger).fadeOut(250,function(){
						$(trigger).text('Explain This');
					});
					$(trigger).fadeIn(250);
				}
			});
		});
	
		var ajaxPending = false;
		
		// If there is no ajax-status element, go ahead and make it.
		if ($("#ajax-status").get().length < 1)
		{
			$("body").append('<div id="ajax-status"><div>&nbsp;</div></div>');
		}
	  
		$("#ajax-status")
		.ajaxStart(function(){
			ajaxPending = true;
			$(this)/*.positionStatus()*/.removeClass('success error').find('div').html('Please wait...').end().animate({opacity:1.0},600,function(){
				if (ajaxPending) {
					$(this).slideDown('fast');
				}
			});
		})
		.ajaxStop(function(){
			ajaxPending = false;
			if (! ($(this).hasClass('success') || $(this).hasClass('error')))
			{
				$(this).slideUp("fast");
			}
		});
	      
		if($("#tabs").length > 0)
		{
			$("#tabs").tabs();
		}
	  
		$('form').map(function(){
			if(!$('input[type=submit], button[type=submit], input[type=image]',this).hasClass('noajax')){
				$(this).unbind('submit').submit(function(){
					self.submitFormWithAjax(this);
					return false;
				});
			}
		});
		if($('#flashNotice').length >= 0) {
			$('#flashNotice').fadeIn('slow');
			setTimeout(function(){
				$('#flashNotice').slideUp('slow');
			},3000);
		}
		$('#login').unbind('submit').submit(function(){
			self.login.auth(this);
			return false;
		});
		$('a.button').unbind('click').click(function(){
			$(this).blur();
		});
		$('a.submit').unbind('click').click(function (){
			$(this).parent('form').submit();
		});
		$('a.dialog').unbind('click').click(self.dialog);
		    
		if (typeof jQuery.fn.cluetip == 'function') $('.help').unbind('click').click(function(e)
		{
			if ($(this).attr('href') == "#" || $(this).attr('href') == '')
			{
				e.preventDefault();
			}
		}).cluetip({
			splitTitle: '|'
		}
		);
	/*
	  $(window).scroll(function() {
	    if ($('#ajax-status').is(':visible')) {
	      $('#ajax-status').css('top', $(this).scrollTop()+'px');
	    }
	  });
	 */
	}; // END this.run = function() 
	
	
	/***
	       * Simulate php array_merge function
	       *
	       * @param {Object/Array} arr1
	       * @param {Object/Array} arr2
	       * var a1 = {'aa':100, 'bb':2, 'cc':[6,7], 'dd':[12,13], 'ee':{'15':15,'16':16}};
	       * var b1 = {'xx':101, 'bb':5, 'cc':8, 'dd':[14,15], 'ee':{'17':17,'18':18}};
	       * var c = array_merge(a1, b1);
	       * console.log(c) [in firebug]
	       * Output: {'aa':100, 'bb': 5, 'cc':[6,7], 'dd':[12,13,14,15], 'ee':{'15':15,'16':16,'17':17,'18':18}, 'xx':101}
	       */
	this.array_merge = function(arr1, arr2)
	{
		if((arr1 && (arr1 instanceof Array)) && (arr2 && (arr2 instanceof Array))){
			for (var idx in arr2)
			{
				arr1.push(arr2[idx]);
			}
		}
		else if((arr1 && (arr1 instanceof Object)) && (arr2 && (arr2 instanceof Object)))
		{
			for( var idx in arr2 )
			{
				if( idx in arr1 )
				{
					if (typeof arr1[idx] == 'object' && typeof arr2 == 'object')
					{
						arr1[idx] = array_merge(arr1[idx], arr2[idx]);
					}
					else
					{
						arr1[idx] = arr2[idx];
					}
				}
				else
				{
					arr1[idx] = arr2[idx];
				}
			}
		}
		return arr1;
	}; // END this.array_merge
	
	
	this.dialog = function(params) {
		if (typeof params != 'object')
		{
			params = JSON.parse(params);
		}
	      
		if (params.title == undefined) params.title = 'Attention!';
		if (params.message == undefined) params.message = 'No message';
		if (params.modal == undefined) params.modal = true;
		if (params.buttons == undefined)
		{
			params.buttons = {
				OK: function() {
					$(this).dialog('close');
				}
			};
		}
		if (params.width == undefined)
		{
			params.width = 'auto';
		}
		if(params.iframe == undefined)
		{
			var dialog = $('div').attr('id','dialog').html(params.message);
		}
		else
		{
			var dialog = $('iframe').attr('id','dialog').attr('src',params.target);
		}
		dialog.dialog({
			title: params.title,
			modal: params.modal,
			buttons: params.buttons,
			close: function() {
				$(this).remove();
			},
			width: params.width
		});
	};
	
	this.expandable = function(e)
	{
		$(this).parents('div.view-item').toggleClass('active');
		$(this).parents('div.view-item').find('div').slideToggle('fast');
		e.preventDefault();
	};
	
	this.featureRestricted = function(e)
	{
		if (typeof e == 'object')
		{
			e.preventDefault();
		}
		self.dialog({
			title: 'This Feature Is Unavailable',
			message: 'In order to use this feature, you need to upgrade your account.',
			buttons: {
				'OK': function() {
					$('#dialog').dialog('close');
				},
				'Upgrade Now!': function() {
					document.location='/members/account#Features';
				}
			}
		});	      
		return false;
	};
	this.signup = function(e){	
		if (typeof e == 'object')
		{
			e.preventDefault();
		}
		self.dialog({
			'message':'test'
		});
		return false;
	};
	this.login = {
		auth: function(form) {
			$('button', form).attr('disabled', 'disabled');
			$('input', form).addClass('disabled');
		    
			var email = $(form).find("input[name='email']").val();
			var pwd = $(form).find("input[name='password']").val();
			var secure = $(form).attr('action').indexOf('https://') > -1 ? true : false;
			$.cookie('email', email, {
				path: '/members/login',
				domain: '.'+window.location.hostname,
				secure: secure
			});
			$.cookie('pwd', pwd, {
				path: '/members/login',
				domain: '.'+window.location.hostname,
				secure: secure
			});
			$.ajax({
				url: $(form).attr('action') + '?c=?',
				dataType: 'json',
				global: false,
				success: function(data)
				{
					var code = data.code;
					if (code == '100')
					{
						self.login.success(data.redirect);
					}
					else
					{
						$('input, button', form).removeAttr('disabled');
						$('button:submit', form).html('<span>Login</span>');
						self.login.error(code,data.message);
					}
				},
				beforeSend: function() {
					$('input, button', form).attr('disabled',true);
					$('button:submit', form).html('<span>Logging In...</span>');
				}
			});
			return false;
		},
		success: function(redir) {
			document.location = unescape(redir);
		},
		error: function(code,message) {
			$('button:submit').removeAttr('disabled');
		    
			switch (code)
			{
				case '202':
					message = 'Your e-mail address or password is invalid. Please try again.';
					break;
				
				case '203':
					message = "Looks like you haven’t activated your account yet. Check your inbox for an email with the subject line “Welcome to Brand-Yourself!”, and <a href='+BY.globals.secureRoot+'/members/activate'>activate your account</a>.";
					break;
				
				case '204':
					message = 'Your account has been suspended by an administrator.';
					break;
				
				default:
				  message = 'There was an error logging you into your account. Please try again.';
			}
			
			$('#login-status').fadeOut(250,function(){
				$('#login-status').addClass('error');
				$('#login-status').html('<p>'+message+'</p>');
				$('#login-status').fadeIn();
			});
		}
	};
	
	this.page = {
		/**
		  * Reloads a section of the current page specified by `selector`, which can be
		  * any valid jQuery selector. Callback specifies a function to be executed after
		  * the reload is complete.
		  */
		reload: function(selector, callback) {
			$.get(document.location.pathname, function(html) {
				$(selector).each(function(i) {
					$(this).html( $(selector + ':eq(' + i + ')', html).html() ); // Set the HTML
					$('form', this).unbind('submit').submit(function(){
						self.submitFormWithAjax(this);
						return false;
					}); // Re-bind any forms that are in the reloaded HTML
				})
				if (typeof self.page.wireHandlers == 'function') self.page.wireHandlers();
				if (typeof callback == 'function') callback();
			}, 'html');
		}
	};
	
	
	/**
	 * Quick method to show an AJAX Status message
	 *
	 * Example: BY.ajaxStatus('You win!', 'success');
	 * 
	 * @param txt is the text you want to show
	 * @param type is either error or success
	 * @return void
	 * @author Wesley Roberts, 2010
	 */
	this.ajaxStatus = function(txt, type, duration) {
		var duration = duration || 3000;
		var type = type || 'success';
		$('#ajax-status').find('div').html(txt).end().removeClass('error success').addClass(type).slideDown('fast').animate({opacity:1.0},duration,function(){
			$(this).slideUp('fast');
		});
	};
	
	
	//! Auto Ajax :)
	this.submitFormWithAjax = function(form)
	{
		form = $(form);
		if (typeof jQuery.fn.validate == 'function')
		{
			if (!form.valid())
			{
				return false;
			}
		}
	      
		// Disable the submit button
		form.find('button[type=submit]').attr('disabled', 'disabled');
	      
		if (typeof BY.page.beforeFormSubmit == 'function')
		{
			BY.page.beforeFormSubmit(form);
		}
	      
		$.ajax({
			url: form.attr('action') != '' ? form.attr('action') : document.location.pathname,
			data: form.serialize(),
			type: form.attr('method') ? form.attr('method') : (form.find("input[name='_method']").val() ? form.find("input[name='_method']").val() : 'post'),
			dataType: 'json',
			success: function(resp) {
				if (typeof resp.callback != 'undefined')
				{
					var args = new Array();
					if (typeof resp.args != 'undefined')
					{
						for(var i in resp.args)
						{
							args.push(resp.args[i]);
						}
					}
					var f = eval(resp.callback);
					if (f == undefined)
					{
						throw 'Callback function ' + resp.callback + ' is not defined';
					}
					args.push(resp.status);
					args.push(resp.text);
					args.push(resp.code);
					f.apply(form, args);
				}
				else
				{
					$('#ajax-status').find('div').html(resp.text).end().addClass('success').slideDown('fast').animate({opacity:1.0},3000,function(){
						$(this).slideUp('fast');
					});
				}
			},
			error: function(xhr) {
				try {
					var resp = JSON.parse(xhr.responseText);
					if (typeof resp.callback != 'undefined')
					{
						var args = new Array();
						if (typeof resp.args != 'undefined')
						{
							for(var i in resp.args)
							{
								args.push(resp.args[i]);
							}
						}
						var f = eval(resp.callback);
						if (f == undefined)
						{
							throw 'Callback function ' + resp.callback + ' is not defined';
						}
						args.push(resp.status);
						args.push(resp.text);
						args.push(resp.code);
						f.apply(form, args);
					}
					else
					{
						var msg = "There was a problem and your request could not be completed.";
						if (resp.text)
						{
							msg = resp.txt;
						} // attempts to replace the default text
						$('#ajax-status').find('div').html(resp.text).end().addClass('error').slideDown('fast').animate({opacity:1.0},3000,function(){
							$(this).slideUp('fast');
						});
					}
				}
				catch(e) {
					if (self.globals.env === 'development')
					{
						var msg = '';
						if (typeof e == 'object')
						{
							for(var i in e)
							{
								msg += '<p><strong>' + i + ':</strong> ' + e[i] + '</p>';
							}
						}
						else
						{
							msg = '<p>' + e + '</p>';
						}
				      
						msg += '<p><strong>Server Response:</strong></p>';
						msg += xhr.responseText;
						self.dialog({
							title: 'Javascript Error Caught',
							message: msg,
							width: 500
						});
					}
				}
			},
			complete: function() {
				form.find('button[type=submit]').removeAttr('disabled');
				if (typeof BY.page.afterFormSubmit == 'function')
				{
					BY.page.afterFormSubmit(form);
				}
			}
		});	      
		return false;
	};
	
	this.triggerAnalyticsPageView = function(page) {
		if (typeof pageTracker == 'object')
		{
			pageTracker._trackPageview(page);
		}
	};
  
} // end function BYApp();


/**
 * Allows simple loading of BY
 * javascript elements
 */
BY.load = {
	self: this,
	plugin: function(l,callback)
	{
		$.getScript('/js/plugins/'+l+'.js',callback);
		return self;
	},
	element: function(l,callback)
	{
		$.getScript('/js/elements/'+l+'.js',callback);
		return self;
	},
	template: function(l,callback){
		$.getScript('/js/templates/'+l+'.tpl.js',callback);
		return self;
	},
	css: function(file) {
		$("head").append("<link>");
		css = $("head").children(":last");
		css.attr({
			rel:  "stylesheet",
			type: "text/css",
			href: file
		});
	}
}
  
/**
 * Allows you to debug your javascript code
 * by creating a cross-browser console.
 *
 * Example: BY.console.log("testing console");
 *
 * @author Wesley Roberts, 2010
 * @since [4100]
 */
BY.console = {
	id : 'by-console',
	element : false,
	ensure : function() {
		if (this.element)
		{
			return true;
		}
		if ($('#'+this.id).length)
		{
			this.element = $('#'+this.id);
			return true;
		}
		$('<pre id="'+this.id+'"></pre>').appendTo('body');
		this.element = $('#'+this.id);
	},
	log : function(msg, level) {
		this.ensure();
		$(this.element).append(msg+"\n");
	}
};


/**
 * Recursive print (returns a string).
 * Works great with BY.console.log()
 *
 * @param <mixed> item
 * @return <string>
 * @author Wesley Roberts, 2010
 * @since [4100]
 */
BY.pr = function(item, level){
	var level = level || 0;
	var prefix = '';
	for (x=0; x<level; x++)
	{
		prefix += ' ';
	}
	var nl = "\n"+prefix;
	var output = prefix;
	if (item.constructor == Array || (!isUndefined(item)) && (typeof( item ) == 'object'))
	{
		for (i in item)
		{
			if (isUndefined(item[i]))
			{
				output += prefix + i + ' => null' + nl;
			}
			else if ($.isFunction(item[i]))
			{
				// do nothing
			}
			else if (item[i].constructor == Array || item[i].constructor == Object)
			{
				output += '['+i+'] => '+typeof(item[i])+nl;
				output += BY.pr(item[i],level+1) + nl;
			}
			else
			{
				output += prefix + i + ' => ' + item[i] + nl;
			}
		}
	}
	return output;
};


BY.pageRedirect = function(data)
{
	window.location = data;
};

function checkAll(ele){
	$(':checkbox').attr('checked',ele.checked);
}
function ajaxStatus(txt, type, duration) {
	var duration = duration || 3000;
	var type = (type === undefined) ? 'success' : type;
	$('#ajax-status').find('div').html(txt).end().removeClass('success error').addClass('success').slideDown('fast').animate({opacity:1.0},duration,function(){
		$(this).slideUp('fast');
	});
}
jQuery.fn.positionStatus = function() {
	var scrollTop = $(window).scrollTop();
	this.each(function() {
		$(this).css('top', scrollTop+'px');
	});
	
	return this;
};

function supports_video() {
	return !!document.createElement('video').canPlayType;
}

 
/* randomUUID.js - Version 1.0
*
* Copyright 2008, Robert Kieffer
*
* This software is made available under the terms of the Open Software License
* v3.0 (available here: http://www.opensource.org/licenses/osl-3.0.php )
*
* The latest version of this file can be found at:
* http://www.broofa.com/Tools/randomUUID.js
*
* For more information, or to comment on this, please go to:
* http://www.broofa.com/blog/?p=151
*/
 
/**
* Create and return a "version 4" RFC-4122 UUID string.
*/
function randomUUID() {
	var s = [], itoh = '0123456789ABCDEF';
	
	// Make array of random hex digits. The UUID only has 32 digits in it, but we
	// allocate an extra items to make room for the '-'s we'll be inserting.
	for (var i = 0; i <36; i++)
	{
		s[i] = Math.floor(Math.random()*0x10);
	}
	
	// Conform to RFC-4122, section 4.4
	s[14] = 4;  // Set 4 high bits of time_high field to version
	s[19] = (s[19] & 0x3) | 0x8;  // Specify 2 high bits of clock sequence
	
	// Convert to hex chars
	for (var i = 0; i <36; i++)
	{
		s[i] = itoh[s[i]];
	}
	
	// Insert '-'s
	s[8] = s[13] = s[18] = s[23] = '-';
	
	return s.join('');
}


/**
 * Returns true if the argument is a number
 */
function is_numeric(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}
 


// Some basic jQuery Functions
if (jQuery){
	(function($){
		$.fn.center = function () {
			this.css("position","absolute");
			this.css("top", Math.max(0, ( $(window).height() - this.height() ) / 2+$(window).scrollTop()) + "px");
			this.css("left", Math.max(0, ( $(window).width() - this.width() ) / 2+$(window).scrollLeft()) + "px");
			return this;
		};
	      
		$.fn.spinner = function(size,hover)
		{
			var i = $.create('img',{
				'src':'/images/elements/progress/large_dark_on_transparent_spinner.gif',
				'class':'loadingIcon'
			});
		    
			// Create the container
			var c = $.create('div',{
				'id':'loadingWrapper'
			});
			$(c).html($(i)).css({
				'zIndex':100
			});
			if(hover)
			{
				$(c).addClass('hover');
				$(this).offsetParent().append($(c));
			}
			else
			{
				$(this).html($(c));
			}
			return c;
		}
	
	})(jQuery);
}

jQuery.create = function() {
	if (arguments.length == 0) return [];
	var args = arguments[0] || {}, elem, elements;
	var siblings = null;
	
	// In case someone passes in a null object,
	// assume that they want an empty string.
	args = args || "";
	if (args.constructor == String)
	{
		if (arguments.length > 1) {
			var attributes = arguments[1];
			if (attributes.constructor == String)
			{
				elem = document.createTextNode(args);
				elements = [];
				elements.push(elem);
				siblings =
				jQuery.create.apply(null, Array.prototype.slice.call(arguments, 1));
				elements = elements.concat(siblings);
				return elements;
		    
			}
			else
			{
				elem = document.createElement(args);
			  
				// Set element attributes.
				var attributes = arguments[1];
				for (var attr in attributes)
				{
					jQuery(elem).attr(attr, attributes[attr]);
				}
			  
				// Add children of this element.
				var children = arguments[2];
				if(typeof children == 'object')
				{
					children = jQuery.create.apply(null, children);
					jQuery(elem).append(children);
				}
			  
				// If there are more siblings, render those too.
				if (arguments.length > 3)
				{
					siblings =
					jQuery.create.apply(null, Array.prototype.slice.call(arguments, 3));
					return [elem].concat(siblings);
				}
				return elem;
			}
		}
		else
		{
			return document.createTextNode(args);
		}
	}
	else
	{
		elements = [];
		elements.push(args);
		siblings =
		jQuery.create.apply(null, (Array.prototype.slice.call(arguments, 1)));
		elements = elements.concat(siblings);
		return elements;
	}
};

/**
 * Easy way to create HTML elements using jquery
 * Example $.ele('div',{'class':'something'}).appendTo(sommething);
 *
 * Just as easy IMO: $('<tag />').attr(...);
 *
 * $('<tag />');
 * $.ele('tag'); 
 */
jQuery.ele = function(tag, args){
	var item = this('<'+tag+'></'+tag+'>');
	if(args)
	{
		item.attr(args);
	}
	return item;
}


/**
 * Standardized BY Progress Bars
 *
 * @since 2010-12-01
 */
$.fn.byProgress = function(v)
{
	return $(this).each(function(){
		if (isNaN(v))
		{
			v = $(this).html().trim();
		}
		var $pbi = $(this).find('.byProgressInner');
		if ($pbi.length)
		{
			v = Math.max(0,v);
			$pbi.animate({
				'width' : v+'%',
				'background-color' : progressColor(v)
			});
		}
		else
		{
			var cont = $.ele('div',{
				'class':'byProgressOuter'
			}).css('width','100%');//$(this).width());
			$.ele('div',{
				'class':'byProgressInner'
			}).css({
				'width':v+'%',
				'background':progressColor(v)
			}).appendTo(cont);
			$(this).empty().append(cont);
		}
	});
}

$.fn.centered = function () {
	var w = $(this).width();
	this.css("position","absolute");
	var top = Math.max(0, ( $(window).height() - this.height() ) / 2+$(window).scrollTop());
	var left = Math.max(0, ( $(window).width() - this.width() ) / 2+$(window).scrollLeft());
	this.css("top", (top - 200) + "px");
	this.css("left", left + "px");
	return this;
}

/**
 * You can use popover.js instead
 */
var popUrl = function (url,options) {
	var opts = $.extend({}, {
		'width':400,
		'height':300,
		'id':'popUrl'
	}, options);
	
	opts.src = url;
	
	if($chk('#postBox')) $('#postBox').remove();
	var over = $.ele('div',{
		'class':'loadingOverlay'
	});
	
	var box = $.ele('div',{
		'id':'postBox'
	}).append(over).css({
		'zIndex':1000,
		'width':'auto',
		'height':'auto'
	}).centered();
	
	$('body').append(box);
	var f = $.ele('iframe',opts)
	.appendTo(box)
	.load(function(){
		$(over).fadeOut();
		$.ele('div',{
			'class':'close'
		}).appendTo(box).click(function(){
			$(box).fadeOut(function(){
				$(box).remove();
			});
		});
		$('#popUrl').contents().find('a').click(function(){
			window.location = $(this).attr('href');
			return false;
		});
	});
	
	return this;
}

/**
 * Circumvents all of this typeof x == 'undefined'
 * x === null kind of crap.
 */
function isUndefined(x) { var u; return (x===u); }

/**
 * Returns a CSS-ready RGB color expression
 * based on the percentage given, p
 * 
 * @author Dwayne Maye
 * @author Wesley Roberts
 */
function progressColor(p){
	var r = p < 50 ? 100 : 100 - (p-50)*2;
	var g = p < 50 ? p*2 : 100;
	var b = 58; 
	r = Math.min(Math.round(r * 2.22) + b, 222);
	g = Math.min(Math.round(g * 2.22) + b, 222);
	return "rgb(" + r + "," + g + "," + b + ")";
}

// Prototypes
String.prototype.ucFirst = function () {
	return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
};

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


