/* javascript components: scsi*/

/***********
class Server
***********/

Server.prototype.url;
Server.prototype.getUrl=function(){return this.url;};
Server.prototype.setUrl=function(url){this.url=url;};
Server.prototype.pendingCallbacks;
function Server(url){
	
	this.url=url;
	this.pendingCallbacks=new Array();
};
Server.prototype.submit=function(command,vararg,callback){
	parameters=new Array(arguments.length-2);
	var clbk=arguments[arguments.length-1];
	// escape the data for URL encoding and build the query string -------------
	
	var queryString="do="+command;
	
	for(var i=0;i<parameters.length;i++){
		parameters[i]=escape(arguments[i+1]);
		queryString+="&p"+i+"="+parameters[i];
	}
	
	// create an HTTP request ----------------------------------------------------
	
	var request=Server.createRequest();
	//alert("send request:"+queryString);
	try{
		request.open("POST",this.url,true);
		debug("set request headers");
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", queryString.length);
		request.setRequestHeader("Connection", "close");
		debug("assign request callback");
		request.onreadystatechange=function(){
			if(request.readyState==4){
				clbk(request.responseText);
			}
		}
		debug("send request:\n"+this.url+"?"+queryString);
		request.send(queryString);
	
	}catch(ex){
		alert("cannot open request:"+ex);
	}
};
Server.createRequest=function(){
	var xmlHttp;
	try{																// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		return xmlHttp;
	}catch(e){}
	
	try{																// Internet Explorer 6 and above
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		return xmlHttp;
	}catch(e){}
	
	try{																// Internet Explorer 5.5 and above
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		return xmlHttp;
	}catch(e){}
	
	alert("Your browser does not support AJAX!");
	return undefined;
};

Server.prototype.toString=function(){
	return "Server{"+this.url+"}";
};

Server.prototype.parse=function(response){
	var index=response.indexOf("%RETURN%");
	var info=response.substr(0,index);
	debug(info);
	var value=response.substr(index+8);
	return value;
	
	
	
};
Server.prototype.parseXML=function(response){
	var index=response.indexOf("%RETURN%");
	var info=response.substr(0,index);
	debug(info);
	var text=response.substr(index+8);
	text=text.substr(40);
	//alert(response+"\n\n"+text);
	
	try{ //Internet Explorer
	
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(text);
		return xmlDoc;
	}catch(e){}
	
	try{ //Firefox, Mozilla, Opera, etc.
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(text,"text/xml");
		return xmlDoc;
	}catch(e) {alert(e);}
	
	return null;
	
	
	
};
function onData(data){
	
};
