if (typeof PRESENCESPACE_INITIALIZED == "undefined") {
// Chat window width (pixels)
PRESENCESPACE_CHAT_WINDOW_WIDTH=350;
// Chat window height (pixels)
PRESENCESPACE_CHAT_WINDOW_HEIGHT=450;
// Default/initial live support button image URL
PRESENCESPACE_DEFAULT_IMAGE_URL='';
// Time in ms before the default image appears
PRESENCESPACE_DEFAULT_IMAGE_TIMEOUT=3000;
// Online live support button image URL
PRESENCESPACE_ONLINE_IMAGE_URL='';
// Offline live support button image URL
PRESENCESPACE_OFFLINE_IMAGE_URL='';
// Offline page (when all operators are unavailable)
PRESENCESPACE_OFFLINE_URL='';
// Default live support group
PRESENCESPACE_GROUP='';
	
/*** Do not edit below this line ***/
if (typeof presencespace!='function')
	function presencespace(){};
if (typeof presencespace.chat!='function')
	presencespace.chat=function(){};
(function() {
presencespace.chat.buttonCounter=0;
presencespace.chat.params=[];

presencespace.chat.getElementById=function(id) {
	var elem;
	if(document.getElementById)
		elem = document.getElementById(id);
	else if (document.all)
		elem = document.all[id];
	return elem;
};
 
presencespace.chat.probeLoaded=function(pos) {
    var clientId=10242;
    var onlineUrl = 'http://www.presencespace.com/chat/app/app.svc'+'?client='+clientId;
    if (PRESENCESPACE_OFFLINE_URL=='') {
        var offlineUrl=onlineUrl+'&offline=1';
        var needPopup = 1;
    } else {
        var offlineUrl=PRESENCESPACE_OFFLINE_URL;
        var needPopup = 0;
    }
	var onlineFragment=presencespace.chat.params[pos][0];
	var offlineFragment=presencespace.chat.params[pos][1];
	var initFragmentId=presencespace.chat.params[pos][2];
	var probeImageId=presencespace.chat.params[pos][3];
	var newLink=document.createElement('span');
	var probe=presencespace.chat.getElementById(probeImageId);
	var probeWidth = probe.offsetWidth;
	var timerId = presencespace.chat.params[pos][4];
    clearTimeout(timerId);
   
	probeSpan=probe.parentNode;
	probeSpan.parentNode.removeChild(probeSpan);
	if (probeWidth == 2) {
		var newLinkContentFragment=onlineFragment;
		var newLinkUrl=onlineUrl;
		needPopup++;
	} else if (probeWidth == 1) {
		var newLinkContentFragment=offlineFragment;
		var newLinkUrl=offlineUrl;
	} else {
		return;
	}
	
	if (needPopup > 0) {
	    var width=PRESENCESPACE_CHAT_WINDOW_WIDTH;
	    var height=PRESENCESPACE_CHAT_WINDOW_HEIGHT;
	    newLink.innerHTML="<a onclick=\"javascript:window.open('"+newLinkUrl+"','chat"+
    		clientId+"','resizable=no,scrollbars=yes,status=no,width="+width+
    		",height="+height+"');return false;\" target='chat"+clientId+
    		"' href='#'>"+newLinkContentFragment+"</a>";
    } else {
		newLink.innerHTML="<a onclick=\"javascript:self.location = '"+newLinkUrl+
			"';return false;\" href='#'>"+newLinkContentFragment+"</a>";
	}
		
	var oldFragment=presencespace.chat.getElementById(initFragmentId);
	var parent=oldFragment.parentNode;
	parent.replaceChild(newLink, oldFragment);		
};


presencespace.chat.probeError = function(pos){
    var timerId = presencespace.chat.params[pos][4];
    clearTimeout(timerId);
    presencespace.chat.appearDefaultImage(pos);
};


presencespace.chat.appearDefaultImage = function(pos) {
    var timerId = presencespace.chat.params[pos][4];
    clearTimeout(timerId);
    var imageId = 'presencespace-chat-posId-'+pos;
    var imageSpan = presencespace.chat.getElementById(imageId);
    imageSpan.style.display="inline";
}


presencespace.chat._button=function(init, online, offline, group, generic) {
	var clientId=10242;
	var probeImgUrl='https://www.presencespace.com/chat/link/image.svc?type=presence'+'&client='+clientId;
	var numId = presencespace.chat.buttonCounter++;
	var probeImageId = 'presencespace-chat-probeImage-'+numId;
	var initFragId = 'presencespace-chat-posId-'+numId;
		
	if (group != '') {
		psURL=psURL+'&group='+group;
		probeImgUrl=probeImgUrl+'&group='+group;
	}
	if (generic == false) {
		var initFragment= '<img src="'+init+'"/>' ;
		var onlineFragment= '<img src="'+online+'"/>' ;
		var offlineFragment= '<img src="'+offline+'"/>' ;
	} else {
		var initFragment= init;
		var onlineFragment= online;
		var offlineFragment= offline;
	}
	var timerId = setTimeout("presencespace.chat.appearDefaultImage("+numId+")",
	               PRESENCESPACE_DEFAULT_IMAGE_TIMEOUT);
	presencespace.chat.params[numId]=[onlineFragment, offlineFragment, 
		initFragId, probeImageId, timerId];
	document.write("<span style='position:absolute;left:-50px;top:-50px;'>"+
		"<img src='"+probeImgUrl+"' id='"+probeImageId+
		"' onload=\"presencespace.chat.probeLoaded("+numId+
		")\" onerror=\"presencespace.chat.probeError("+numId+
		")\"></img></span>");
    document.write("<span id='"+initFragId+"' style='display:none;' >"+initFragment+"</span>");
};
presencespace.chat.imageButton=function(initImg, onlineImg, offlineImg, group){
	if (group) {
		presencespace.chat._button(initImg,onlineImg,offlineImg,group,false);
	} else {
		presencespace.chat._button(initImg,onlineImg,offlineImg,PRESENCESPACE_GROUP,false);
	}
};
presencespace.chat.htmlButton=function(initHTML, onlineHTML, offlineHTML, group){
	if (group) {
		presencespace.chat._button(initHTML, onlineHTML, offlineHTML,group,true);
	} else {
		presencespace.chat._button(initHTML, onlineHTML, offlineHTML,PRESENCESPACE_GROUP,true);
	}
};
presencespace.chat.button=function(group){
	var init,online,offline,generic;
	
	if (PRESENCESPACE_DEFAULT_IMAGE_URL == '' && 
		PRESENCESPACE_ONLINE_IMAGE_URL =='' &&
		PRESENCESPACE_OFFLINE_IMAGE_URL =='') {
		init="<span>Live Support(Checking availability...)</span>";
		online="<span>Live Support: Click to chat.</span>";
		offline="<span>Live Support: Send us a message.</span>";
		generic=true;
	} else {
		if (PRESENCESPACE_DEFAULT_IMAGE_URL == '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL =='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL !='') {
			init = PRESENCESPACE_OFFLINE_IMAGE_URL;
			online = PRESENCESPACE_OFFLINE_IMAGE_URL;
			offline = PRESENCESPACE_OFFLINE_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL == '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL !='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL =='') {
			init = PRESENCESPACE_ONLINE_IMAGE_URL;
			online = PRESENCESPACE_ONLINE_IMAGE_URL;
			offline = PRESENCESPACE_ONLINE_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL == '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL !='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL !='') {
			init = PRESENCESPACE_OFFLINE_IMAGE_URL;
			online = PRESENCESPACE_ONLINE_IMAGE_URL;
			offline = PRESENCESPACE_OFFLINE_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL != '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL =='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL =='') {
			init = PRESENCESPACE_DEFAULT_IMAGE_URL;
			online = PRESENCESPACE_DEFAULT_IMAGE_URL;
			offline = PRESENCESPACE_DEFAULT_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL != '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL =='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL !='') {
			init = PRESENCESPACE_DEFAULT_IMAGE_URL;
			online = PRESENCESPACE_DEFAULT_IMAGE_URL;
			offline = PRESENCESPACE_OFFLINE_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL != '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL !='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL =='') {
			init = PRESENCESPACE_DEFAULT_IMAGE_URL;
			online = PRESENCESPACE_ONLINE_IMAGE_URL;
			offline = PRESENCESPACE_DEFAULT_IMAGE_URL;
		} else if (PRESENCESPACE_DEFAULT_IMAGE_URL != '' &&
			PRESENCESPACE_ONLINE_IMAGE_URL !='' &&
			PRESENCESPACE_OFFLINE_IMAGE_URL !='') {
			init = PRESENCESPACE_DEFAULT_IMAGE_URL;
			online = PRESENCESPACE_ONLINE_IMAGE_URL;
			offline = PRESENCESPACE_OFFLINE_IMAGE_URL;
		} else {
		}
		generic=false;
	} 
	if (group) {
		presencespace.chat._button(init,online,offline,group,generic);
	} else {
		presencespace.chat._button(init,online,offline,PRESENCESPACE_GROUP,generic);
	}
};
})();
}

