function FufiGetJson ( Url, Parameters, Callback ) {
	Url = 'http://' + window.location.hostname + '/' + Url;
	$.getJSON (
		Url,
		Parameters,
		function ( Response ) {
			Callback ( Response );
		}
	);
}

function FufiGet ( Url, Parameters, Callback ) {
	Url = 'http://' + window.location.hostname + '/' + Url;
	$.get (
		Url,
		Parameters,
		function ( Response ) {
			if ( Callback != undefined ) {
				Callback ( new AjaxResponse ( Response ) );
			}
		}
	);
}

function FufiPost ( Url, Parameters, Callback ) {
	Url = 'http://' + window.location.hostname + '/' + Url;
	$.post (
		Url,
		Parameters,
		function ( Response ) {
			if ( Callback != undefined ) {
				Callback ( new AjaxResponse ( Response ) );
			}
		} 
	);
}

function FufiPostMessage ( Url, Parameters, MessageDiv, Callback ) {
	FufiPost (
		Url,
		Parameters,
		function ( Response )
		{
			ShowMessage ( MessageDiv, Response );

			if ( Callback != undefined ) {
				Callback ( Response );
			}
		}
	);
}

function AjaxResponse ( Response ) {
	this.response = Response;

	this.IsError = function () {
		if ( this.response.substr ( 0, 1 ) == '1' ) {
			return true;
		} else {
			return false;
		}
	}

	this.GetContent = function () {
		return this.response.substr ( 2 );
	}

	this.GetRawContent = function () {
		return this.response;
	}
}

function Nl2Br ( Str ) {
	return Str.replace ( /(\r\n|\r|\n)/g, '<br />' );
}

function StripSlashes ( Str ) {
	Str = Str.replace ( /\\'/g, '\'' );
	Str = Str.replace ( /\\"/g, '"' );
	Str = Str.replace ( /\\\\/g, '\\' );
	Str = Str.replace ( /\\0/g, '\0' );

	return Str;
}

$.fn.insertAtCaret = function ( myValue ) {
	return this.each ( function () {
		//IE support
		if ( document.selection ) {
			this.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
			this.focus();
		} else if ( this.selectionStart || this.selectionStart == '0' ) {
			var startPos = this.selectionStart;
			var endPos = this.selectionEnd;
			var scrollTop = this.scrollTop;
			this.value = this.value.substring ( 0, startPos ) + myValue + this.value.substring ( endPos, this.value.length );
			this.focus();
			this.selectionStart = startPos + myValue.length;
			this.selectionEnd = startPos + myValue.length;
			this.scrollTop = scrollTop;
		} else {
			this.value += myValue;
			this.focus();
		}
	} );
};