String.prototype.trim = function(){return this.replace(/^\s+|\s+$/, '');};
String.prototype.Blength = function() {
	var arr = this.match(/[^\x00-\xff]/ig);
	return  arr == null ? this.length : this.length + arr.length;
};
String.prototype.utf8 = function() {
	var arr = this.match(/[^\x00-\xff]/ig);
	return arr!=null;
};

var baseCKEditorToolbar=[
	[ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ]
];

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

var showMessage=function( msg ){
	$("#messagePnl").html(msg).prepend(
		'<span class="ui-icon ui-icon-arrowthickstop-1-n" style="float: left; margin-right: .3em;" id="hideMsgBtn"></span>'
	).show("drop").effect("pulsate");//.effect('highlight', {color:'#FFB0B0'}, 3000);
	$('#showMsgBtn').hide('drop');
	$("#hideMsgBtn").css({cursor:'pointer'}).click(function(){
		$("#messagePnl").hide("drop")
		$('#showMsgBtn').show('drop');
	});
};

var initDatePicker=function( jqueryStr ){
	return $(jqueryStr).attr({size:10}).datepicker({
		dateFormat: 'yy-mm-dd'
		,changeMonth: true
		,changeYear: true
		,showOn: 'button'
		,buttonImage: 'http://www.uzone21.com/images/calendar.gif'
	});
};

var handleCKEditor=function(){
	$('.CKEditor').each(function(){ 
		$(this).ckeditorGet().updateElement(); 
		var value=$(this).val();
		var trim=value.replace(/<\/?[^>]+(>|$)/g, "").trim();
		if(trim.length < 1){
			$(this).val('');
		}
	});
};

var submitWithValidation=function(){
	handleCKEditor();
	if(!$(this).valid())return false;
	if(typeof($(this).attr('ajaxTarget'))=='undefined')return true;
	
	//Ajax Form
	$(this).ajaxSubmit({
		url:$(this).attr('action')
		,target: $(this).attr('ajaxTarget')
		,type: 'post'
	});
	return false;
};

var initBtn=function( jqueryStr ){
	return $(jqueryStr).css({cursor:'pointer','text-decoration':'underline'}).hover(
		function(){$(this).css({'text-decoration':'',color:'red'});}
		,function(){$(this).css({'text-decoration':'underline',color:''});}
	);
};

var initIconBtn=function( jqueryStr ){
	return $(jqueryStr).css({cursor:'pointer'}).hover(
		function(){$(this).addClass("ui-state-hover");}
		,function(){$(this).removeClass('ui-state-hover');}
	).addClass('ui-state-default');
};

var initBaseCKEditor=function( textAreaId ){
	if(typeof(CKEDITOR.instances[textAreaId])!='undefined')
		CKEDITOR.remove(CKEDITOR.instances[textAreaId]);
	$('textarea#'+textAreaId).ckeditor(function(){}, {toolbar: [
	         ['Source'],['Bold','Italic','Underline', 'Strike','Subscript','Superscript']
	   		,['NumberedList','BulletedList','Outdent','Indent','Blockquote']
	   		,['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
	   		,['Image','Flash','HorizontalRule','SpecialChar','Link','Unlink']
	   		, '/'
	   		,['Styles','Format','Font','FontSize']
	   		,['TextColor','BGColor','HorizontalRule','Smiley']
		]});
	return true;
};

function isArray(obj) {
//returns true is it is an array
if (obj.constructor.toString().indexOf('Array') == -1)
	return false;
else
	return true;
};

//Format 
var formatMsg=function( src, param ){
	if(typeof(param)=="undefined" || param==null)return src;
	if(isArray(param)){
		var size=param.length;
		for(var i=0; i<size; i++)
			src=src.replace('{'+i+'}', param[i]);
		return src;
	}else
		return src.replace('{0}', param);
};

var swapImage=function(){
	var tmp=$(this).attr('src');
	$(this).attr('src', $(this).attr('osrc'));
	$(this).attr('osrc', tmp);
};
