var liveChatLinkText = 'LiveChat';
var liveChatUsers = 'kvi,heh,mcc'; //liste med initialer adskilt af , (komma)
var liveChatUserOnline = false;
function insertLiveChat(){
	var d = new Date();
	//AjaxRequest( 'http://' + document.domain + '/i-Seven/i-publish.nsf/ag.int.i-Site.GetOnlineChatUser?openAgent&'+d.getTime(), liveChat );
	// 20-10-2009 Live chat disablet map/i-Seven
	//AjaxRequest( 'http://' + document.domain + '/servlet/getSTOnlineUser?users='+liveChatUsers+'&'+d.getTime(), liveChat );
}
/*
* onreadystatechange function
*/
function liveChat() {
	// If data received correctly
	if (AjaxRequestObject.readyState==4) {
		// if data is valid
		if (AjaxRequestObject.responseText.indexOf('invalid') == -1){ 
			var user = AjaxRequestObject.responseText;
			user = user.replace('\r\n', '');
			if (user.length != 0)
				document.getElementById("TopLiveChat").innerHTML = prepareSametimeLink(user, liveChatLinkText, false, 'text:off');
		}
	}
}
/*
* Main AJAX request
*/
function AjaxRequest(Url, ReqChange) {
	if(window.XMLHttpRequest) {
		try {
			AjaxRequestObject = new XMLHttpRequest();
		} catch(e) { 
			AjaxRequestObject = false;
		 }
	}else if(window.ActiveXObject){
		try {
			AjaxRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try { 
				AjaxRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				 AjaxRequestObject = false;
			 }
		}
	}
	// Prepare the request
	AjaxRequestObject.open("GET", Url , true);
	// Set the onreadystatechange function
	AjaxRequestObject.onreadystatechange = ReqChange;
	// IE wants this explicit
	AjaxRequestObject.setRequestHeader('Content-Type',  "text/xml");
	// Send
	AjaxRequestObject.send(null); 
}
//Overskrivning fra stlinks.js for at kunne skelne mellem livechat img og normale.
function getImgTag(statusType, tip, tagId)
{
	var liveChatImgWidth = 85;
	var liveChatImgHight = 28;
	if (typeof(tagId) == "undefined") {
		//Livechat not initialized
		return "<img" + 
			" border=0 align=absmiddle alt='" + tip.replace(/'/g, "&#039;") + 
			'\' src="'+ getImgUrlLiveChat(statusType) +'" width=' + liveChatImgWidth + ' height=' + liveChatImgHight +">";
	} else {
		if (ll_linkTxt[tagId]== liveChatLinkText) {
			return "<img" + 
				((typeof tagId != "undefined") ? " name=" + tagId : "")  + 
				" border=0 align=absmiddle alt='" + tip.replace(/'/g, "&#039;") + 
				'\' src="'+ getImgUrlLiveChat(statusType) +'" width=' + liveChatImgWidth + ' height=' + liveChatImgHight +">";
		} else {
			return "<img" + 
				((typeof tagId != "undefined") ? " name=" + tagId : "")  + 
				" border=0 align=absmiddle alt='" + tip.replace(/'/g, "&#039;") + 
				'\' src="'+ getImgUrl(statusType) +'" width=' + ICON_WIDTH + ' height=' + ICON_HEIGHT +">";
		}
	}
}
//Overskrivning fra stlinks.js for at tilføje tagId til getImgTag kald
function getInnerTag_IE(linkId,tagId,statusType,tip,options)
{
	var styleName = statusType == 0 ? options.offlineStyle : options.onlineStyle;
	var s = '<nobr><A ' + getHREF(linkId, tagId, (statusType != 0), options.bOfflineLink) + 
		" title='"+tip.replace(/'/g, "&#039;")+"'" + ' CLASS="' + styleName + '">';
	if (!options.bText)
		s += getImgTag(statusType, tip, tagId); //22-01-2009 i-seven/lac: tagID added
	else if (!options.bIcon)
		s += ll_linkTxt[tagId];
   else s+= getImgTag(statusType, tip, tagId) + getIconSpace(options.iconSpace) + '<span dir="ltr">' + ll_linkTxt[tagId] + '</span>'; //22-01-2009 i-seven/lac: tagID added to getImgTag
	return s + '</A></NOBR>';
}
function getImgUrlLiveChat(statusType)
{
	return webLibraryPath + "/i7_09_LiveChat" +
		(statusType == 0x20 ? "On" : "Off") + ".gif";
}
//Overskrivning fra stlinks.js for at kunne opdatere finde en ny online user, hvis den eksisterende disconnecter.
function updateLinkStatus(linkId, stat, desc)
{
	try
	{
		system.out("STLinks","updateLinkStatus(" + linkId + "," +  stat + "," +  desc + ")");
	}
	catch(err){}
	
	ll_status[linkId] = stat;
	ll_desc[linkId] = desc;
	for(var tagId in ll_IDs[linkId]) {
		if (document.getElementById(tagId) != null) {
			var uname = ll_linkTxt[tagId];
			if (uname==liveChatLinkText) {
				if (stat==32) 
					liveChatUserOnline = true;
				else if (liveChatUserOnline) {
					liveChatUserOnline = false;
					insertLiveChat();
				}
			}
			updateLinkHtml(tagId,linkId,stat, STLinksStatusTip(uname, stat, desc));
		}
	}
}
