document.write("\<div id=\"ptlStatusResult\"\>\</div\>");

var _PTL_ACCOUNT = "";
var _PTL_ONLINE="";
var _PTL_OFFLINE="";

function ptlLaunch(){
	window.open ("http://piertechlive.com/chat/window.html?account=" + _PTL_ACCOUNT,
                'piertechlive','width=460,height=400,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no' );
}

function messageLaunch(){
window.open ("http://"+_PTL_ACCOUNT+".piertechlive.com/support/requests/message",
                'piertechlive','width=400,height=320,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no' );
}

function ptlTrim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function ptlResponse(originalRequest)
{
	//put returned XML in the textarea
        if(ptlTrim(originalRequest) == "available"){
        	document.getElementById('ptlStatusResult').innerHTML = '<a href="#" onclick="ptlLaunch()"><img src="'+_PTL_ONLINE+'" border="0" /></a>';
        }else{
        	document.getElementById('ptlStatusResult').innerHTML = '<a href="#" onclick="messageLaunch()"><img src="'+_PTL_OFFLINE+'" border="0" /></a>';
        }
}

function displayStatus(account,online,offline){
_PTL_ACCOUNT=account;
_PTL_ONLINE=online;
_PTL_OFFLINE=offline;
var imageCall = new Image();
var randomnumber=Math.random();
var url = 'http://piertechlive.com/plugins/apresence/status?account=' + account + '&random=' + randomnumber;
imageCall.onload=function(){imageCall.width == 4 ? ptlResponse("available") : ptlResponse("unavailable");}
imageCall.onerror=function(){ptlResponse("unavailable");}
imageCall.src = url;
}
