
function getLoadingSign(type, sectionId, elementId, version) {

	var linkSpanId = 'linkSpan_' + type + '_' + sectionId + '_' + elementId + '_' + version;

	if ($(linkSpanId)) {
		new Ajax.Updater(linkSpanId, '/loadingsign.php', {
			parameters: { version   : version},
			requestHeaders: {'X-requestType' : 'Ajax'}
		});
	}
}


function getLinkButton(type, sectionId, elementId, version)
{
	var linkSpanId = 'linkSpan_' + type + '_' + sectionId + '_' + elementId + '_' + version;
	returnUrl = location.href;

	if ($(linkSpanId)) {
		new Ajax.Updater(linkSpanId, '/linkbuttons.php', {
			parameters: {   type      : type,
							sectionId : sectionId,
							elementId : elementId,
							returnUrl : returnUrl,
                            version   : version},
			requestHeaders: {'X-requestType' : 'Ajax'}
		});
	}
}

function getLinkCount(type, sectionId, elementId)
{
	var countSpanId = 'linkCountSpan_' + type + '_' + sectionId + '_' + elementId;
	if ($(countSpanId)) {
		new Ajax.Updater(countSpanId, '/linkCount.php', {
			parameters: {   sectionId : sectionId,
							elementId : elementId,
							type      : type}
		});
	}
}

function setLink(type, sectionId, elementId, version)
{
	new Ajax.Request('/linkit.php', {
		method  : 'get',
		parameters: {   sectionId : sectionId,
						elementId : elementId,
						type      : type},
		onSuccess: function(transport) {getLinkButton(type, sectionId, elementId, version); getLinkCount(type, sectionId, elementId);},
		requestHeaders: {'X-requestType' : 'Ajax'}
	});
}

function fillLinkSpans()
{
	var spans = window.document.getElementsByTagName("span");
	for (var i=0; i < spans.length; i++ ) {
		if(spans[i].id.substring(0,8) == "linkSpan" || spans[i].id.substring(0,13) == "linkCountSpan") {
			var ids = spans[i].id.split("_");
			var type = ids[1];
			var sectionId = ids[2];
			var elementId = ids[3];
            var version = ids[4];
			if (type == 'favorite' || type == 'tip' || type == 'artist' && (sectionId > 0 && elementId > 0)) {
				if (spans[i].id.substring(0,8) == "linkSpan") {
					getLinkButton(type, sectionId, elementId, version);
				} else {
					getLinkCount(type, sectionId, elementId, version);
				}
			}
		}
	}
}