/*
 * @element - element to inject html widget
 * @message - custom message to show
 * */
function er_showError(element, message){
	var error_widget = '<div style="margin-top: 20px; margin-bottom: 20px;" class="ui-widget">' + 
							'<div style="padding: 1em;" class="ui-state-highlight ui-corner-all">' +
								'<span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"/>'
								 + message + 		
							'</div>'+
						'</div>';
	$(element).html(error_widget).effect("shake", { times:2, distance:5 }, 200);
}


/*
 * Image upload ui
 * @returns image up-loading box html
 * */
function getLoadingContainer() {
return '<span class="img-just-uploaded-frame clearfix ui-corner-all">' +
			'<span class="img-loading-container img-container clearfix"></span>'+
		'</span>';
}

/*
 * Image upload ui
 * @returns first dummy box
 * */
function getDummyContainer() {
return '<span class="thumbnail thumbnail_dummy">'+
		'<span class="img-just-uploaded-frame clearfix ui-corner-all">' +
			'<span class="img-container clearfix"></span>'+
		'</span>'+
	   '</span>';
}

/*
 * strip special chars + space from a string (file name, ...)
 * used in image upload ui to get clean file id
 * */
function getCleanedStr(str){
	return str.replace(/[.(),;:!*?%#$�'" _+=\\/-]*/g,'');
}


/*
 * alternative to php's sprintf()
 * e.g. sprintf('This image {0} has been already uploaded.', file)  .... may have more ... {0} .. {1,2,...}
 * */
function sprintf(source, params) {
	if ( arguments.length == 1 ) 
		return function() {
			var args = $.makeArray(arguments);
			args.unshift(source);
			return $.validator.format.apply( this, args );
		};
	if ( arguments.length > 2 && params.constructor != Array  ) {
		params = $.makeArray(arguments).slice(1);
	}
	if ( params.constructor != Array ) {
		params = [ params ];
	}
	$.each(params, function(i, n) {
		source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
	});
	return source;
}


