//class servcom

function Servcom(onResponse){
this.onResponse=onResponse;
}//end function

Servcom.prototype.init=function Servcom_init(q_stat){
this.myStat=q_stat;
if(gServcom){
}else{
	alert("Global object gServcom has not been defined.");
}//end if
}//end function

Servcom.prototype.request=function Servcom_request(q_url,q_data){
if(q_url>""){
	gServcom.myStat.reg("request");
	this.lastrequest=q_url;
	this.myAjax = new Ajax.Request(q_url,{method: 'post', parameters: q_data, onComplete:Servcom_response,onFailure:Servcom_failure});
	return true;
}else{
	return false;
}//end if
}//end function

Servcom.prototype.arrayRequest=function Servcom_request(q_url,q_array){
var q_data="ARRAY="+escape(array2tab(q_array));
this.request(q_url,q_data);
}//end function


function Servcom_response(originalRequest){
if(gServcom.myStat){gServcom.myStat.reg("response");}//end if
if(div("led")){ledblink();}//end if
this.last=originalRequest.responseText;
gServcom.onResponse(originalRequest.responseText,originalRequest);
}//end function

function Servcom_failure(originalRequest){
if(gServcom.myStat){gServcom.myStat.reg("failure");}//end if
if(div("led")){ledblink("red");}//end if
if(originalRequest){
	gServcom.error=originalRequest.responseText;
}else{
	gServcom.error="failure and originalRequest undefined";
}//end if
}//end function

function Servcom_timeout(){
Servcom_failure();
}//end function

function Ajax_callInProgress (xmlhttp) {
switch (xmlhttp.readyState) {
	case 1: case 2: case 3:
	return true;
	// Case 4 and 0
	default:
	return false;
}//end switch
}//end function

// Register global responders that will occur on all AJAX requests
Ajax.Responders.register({
onCreate: function(request) {
request['timeoutId'] = window.setTimeout(function(){
// If we have hit the timeout and the AJAX request is active, abort it and let the user know
if(Ajax_callInProgress(request.transport)) {
	request.transport.abort();
	Servcom_timeout();
	// Run the onFailure method if we set one up when creating the AJAX object
	if (request.options['onFailure']) {
		request.options['onFailure'](request.transport, request.json);
	}//end if
}//end if
}//end function
,5000);
},
onComplete: function(request){
// Clear the timeout, the request completed ok
window.clearTimeout(request['timeoutId']);
}//end function
});
