function HttpConnector(pName,pWin) 
{
var t=this;
t.http;
t.name=pName;
t.win=pWin;
t.loginKey="";
t.msg="<div style='width=40;FONT-FAMILY: Verdana;FONT-WEIGHT: bold;FONT-SIZE: 12px;COLOR:'>Fetching ..</div>";
t.delay=500;
t.timeOut=60;

t.timeOutErr;
t.response;
t.cell=null;
t.count=-1;

if(navigator.appName=="Microsoft Internet Explorer")
	t.http=new ActiveXObject("Microsoft.XMLHTTP");
else
	t.http=new XMLHttpRequest();

t.execCmd=function execCmd(pHandleResponse,pCmd,pParams)
{
	lParams=pParams+"&Cmd="+pCmd+"&LoginKey="+t.loginKey;
	lResp=t.send(pHandleResponse,"../ControllerServlet",lParams,"POST");
	if (lResp!=null) return t.splitData(lResp);
}
t.send=function send(pHandleResponse,pServlet,pParams,pMethod)
{
	if (pHandleResponse==null) lAsync=false;
	else lAsync=true;
	t.startTimer();
	t.http.open(pMethod,pServlet,lAsync);
	t.http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    if (lAsync) t.http.onreadystatechange=pHandleResponse;
    t.http.send(pParams);
	if (!lAsync)
	{
		t.pauseTimer();
		return t.http.responseText;
	}
	else
		return null;
}
t.getResponse=function getResponse()
{
	if(t.done()&&!t.timeOutErr)
		return t.splitData(t.http.responseText);
	else
		return null;
}
t.getTextResponse=function getTextResponse()
{
	if(t.done()&&!t.timeOutErr)
		return t.http.responseText;
	else
		return null;
}
t.splitData=function splitData(pData) //Splits the responseText into a 2D array.
{
	var lRecords,lRows;
	if ((pData!="")&&(pData.length>0))
	{		
		if (pData.substring(pData.length-1)=="~") pData=pData.substring(0,pData.length-1);
		lRecords=pData.split("~")
		var lMaxRows=lRecords.length;
		lRows= new Array(lMaxRows);
		for (lCount=0; lCount < lMaxRows; lCount++)
		{
			lRows[lCount]=(lRecords[lCount]).split("|");
		}
	}
	else
		lRows=[[""]];
	return lRows;
}
t.done=function done()
{
	if (t.http.readyState==4)
	{
		t.pauseTimer();
		if (t.timeOutErr) t.win.alert("Server did not respond in time.");
		return true;
	}
	else return false;
}
t.startTimer=function startTimer()
{
	if (t.count>=0) return;
	t.count=0;
	t.timeOutErr=false;
	t.checkTimeout();
}
t.pauseTimer=function pauseTimer()
{
	t.count=-1;
	if (t.cell!=null) t.cell.innerHTML="&nbsp;"
}
t.checkTimeout=function checkTimeout()
{
	if (t.count<0) return;
	t.count++;
	if (t.count>t.timeOut)
	{
		t.timeOutErr=true;
		t.pauseTimer();
		t.http.abort();
		return;
	}
	if (t.cell!=null)
	{
		if (t.cell.innerHTML=="&nbsp;") t.cell.innerHTML=t.msg;
		else t.cell.innerHTML="&nbsp;"
	}
	setTimeout(eval("t.win."+t.name+".checkTimeout"),t.delay);
}
}
