function registerButton(deptid, eltid, imgsrc) {
	try {
	    inviteButtons[eltid] = {id: deptid, img: imgsrc};
		document.write('<img src="https://rs.instantservice.com/resources/smartbutton' +
		  '/7491/' + deptid + '/available.gif?' + Math.floor(Math.random()*10001) +
		  '" style="width:0;height:0;visibility:hidden;position:absolute;"' +
		  ' onLoad="agentsAvailable(\'' + eltid + '\')" onError="agentsNotAvailable(\'' + eltid + '\')">');
	}catch (err){
		if(navigator.userAgent.indexOf('Firefox') > 0 && null != console && null != console.log){
			console.log(arguments);
			console.log(err);
		}
	}
}

function registerFMAButton(deptid, eltid, imgsrc) {
    try {
        inviteButtons[eltid] = { id: deptid, img: imgsrc };
        document.write('<img src="https://rs.instantservice.com/resources/smartbutton' +
		  '/7491/' + deptid + '/available.gif?' + Math.floor(Math.random() * 10001) +
		  '" style="width:0;height:0;visibility:hidden;position:absolute;"' +
		  ' onLoad="agentsAvailableFMA()" onError="agentsNotAvailableFMA()">');
    } catch (err) {
        if (navigator.userAgent.indexOf('Firefox') > 0 && null != console && null != console.log) {
            console.log(arguments);
            console.log(err);
        }
    }
}

function agentsAvailable(eltid) {
	var elt = document.getElementById(eltid);
	if (elt){
		elt.innerHTML =
		'<a href="" onClick="javascript:window.open(\'https://admin.instantservice.com/links' +
		'/7491/' + inviteButtons[eltid].id + '\',\'chat_client\',\'width=600,height=324,scrollbars=0\');' +
		'return false;"><img border="0" alt="Click for Live Chat" src="' + inviteButtons[eltid].img + '"></a>';
		return true;
	}
	else {
		return false;
	}
}

function agentsAvailableFMA() {
    $("#chatIconFMA").show();
    $("#chatIconStuff").text("Or give us a call.");
}

function agentsNotAvailable(eltid)
{
	var elt = document.getElementById(eltid);
	if(elt) {
		elt.innerHTML = '';
		return true;
	}
	else {
		return false;
	}
}

function agentsNotAvailableFMA() {
    
}

