document.write('<div width="100px" class="tagFlyingContainer" id="tagFlyingContainer"> 	<div><input class="tagCloseBtn" type="button" value="X" onclick="closeTagFlyingDiv();" /></div> 	<div class="clearFloat"></div> 	<div class="content" id="flyingDivContent"></div> </div>');

        
        function initTagFlyingDiv(obj)
		{
			obj.getElementsByTagName('div')[2].innerHTML = '<b>Loading...</b>';
		}


		
		function openTagFlyingDiv(tagArticleId, e)
		{
            var containerObj = $('tagFlyingContainer');
			if (containerObj == null)
			{
				return false;
			}
			

            var deltaX =  window.pageXOffset
                        || document.documentElement.scrollLeft
                        || document.body.scrollLeft
                        || 0;
            var deltaY =  window.pageYOffset
                        || document.documentElement.scrollTop
                        || document.body.scrollTop
                        || 0;


            var top = (e.y ? e.y : e.clientY) + deltaY;
            var left = (e.x ? e.x : e.clientX) + deltaX;


            containerObj.style.display = 'block';
            containerObj.style.top = top + 'px'; 
			containerObj.style.left = left + 'px';
			
			initTagFlyingDiv(containerObj);

			// setup Ajax request
			ajaxRequest("", "&tagArticleId=" + tagArticleId, onSuccess_openTagFlyingDiv)
			
			return false;
		}


        function onSuccess_openTagFlyingDiv(response)
		{
            
            var tmpObj = $("flyingDivContent")
			if (tmpObj != null)
			{
                tmpObj.innerHTML = ""

                var div = document.createElement("div");
                div.innerHTML = response.responseText;

                tmpObj.appendChild(div)
			}
		}
		
		function closeTagFlyingDiv()
		{

			var containerObj = $('tagFlyingContainer');
			if (containerObj != null)
			{
				containerObj.style.display = 'none';
			}
			
			return false;
		}


		function tagsSend()
		{
			var tags = $("tagFlyingDivTags").value;
			var tagArticleId = $("tagArticleId").value;

            initTagFlyingDiv($("tagFlyingContainer"));

			ajaxRequest(null, "&tagArticleId="+ tagArticleId + "&tags=" + escape(tags), onSuccess_openTagFlyingDiv)
		}


function ajaxRequest(url, params, CompleteHandler, FailureHandler, ExceptionHandler)
{
    try {
        if (undefined == CompleteHandler || null == CompleteHandler || 'function' != typeof CompleteHandler) {
            CompleteHandler = _onCompleteHandler;
        }
        if (undefined == FailureHandler || null == FailureHandler || 'function' != typeof FailureHandler) {
            FailureHandler = _onFailureHandler;
        }
        if (undefined == ExceptionHandler || null == ExceptionHandler || 'function' != typeof ExceptionHandler) {
            ExceptionHandler = _onExceptionHandler;
        }
        if (undefined == params || null == params) {
            params = '';
        }
        url = strTrim(strValue(url));
        if ('' == url) {
            url = document.location;
		}
        
        
        if (params == undefined)
        {
            params = "";
        }


//url += '?tmprRand=' + Math.random();
        
        params += "&isAjax=1";

        var request = new Ajax.Request(url, { method : 'post', postBody : params, onSuccess : CompleteHandler, onFailure : FailureHandler, onException : ExceptionHandler });
    }
    catch(e) {
        alert("Exception: " + getExceptionText(e));
    }
}


function strTrim(source)
{
    try {
        if (typeof(source)) {
            source = source.toString();
            source = source.replace(/^\s+/, '');
            source = source.replace(/\s+$/, '');
            return(source);
        }
    }
    catch (e) {
    }
    return('');
}


function strValue(source)
{
    try {
        if (undefined != source && null != source) {
            return(source.toString());
        }
    }
    catch (e) {
    }
    return('');
}


function dumpObject(o)
{
	var tmpSt = '';

	for  (var i in o)
	{
		tmpSt += i + " = " + o[i] + "\n";
	}
	
	return tmpSt;
}

function _onCompleteHandler(originalRequest)
{
    alert("def AJAX success");
}

function _onFailureHandler(request, json)
{
    alert("def AJAX request failed: [" + request.status + "] " + request.statusText);
}

function _onExceptionHandler(request, e)
{
    alert("def AJAX request raised exception: " + getExceptionText(e));
}


function getExceptionText(source)
{
    return((typeof(source) == "string") ? source : ((source.message) ? source.message : "Unknown Error"));
}