		var _timerID=0;
		var _timerID2=0;
		var _maxXmlHTTPConnections=5;
		var _openConnections=null;
		var _pollingInterval=2000;
		var colours = ["aliceblue","lightblue","lightsteelblue","lightskyblue","cyan","aqua","aquamarine","white","white","white","white","white","white","white","white","white","white","white","white","white","white"];
//		var bidcolours = [ "rgb(254,245,206)", "rgb(254,245,206)", "rgb(254,245,206)", "rgb(254,245,206)", "rgb(255,236,217)", "rgb(255,229,229)", "rgb(243,221,255)", "rgb(192,209,248)", "rgb(213,239,255)", "rgb(204,255,255)", "rgb(159,255,255)", "rgb(147,255,219)", "rgb(83,255,185)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)" ];
//		var offercolours = [ "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(83,255,185)", "rgb(147,255,219)", "rgb(159,255,255)", "rgb(204,255,255)", "rgb(213,239,255)", "rgb(192,209,248)", "rgb(243,221,255)", "rgb(255,229,229)", "rgb(255,236,217)", "rgb(254,245,206)", "rgb(254,245,206)", "rgb(254,245,206)", "rgb(254,245,206)" ];
		var bidcolours = [ "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(254,245,206)", "rgb(255,236,217)", "rgb(255,229,229)", "rgb(243,221,255)", "rgb(192,209,248)", "rgb(213,239,255)", "rgb(204,255,255)", "rgb(159,255,255)", "rgb(147,255,219)", "rgb(83,255,185)", "rgb(0,204,153)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)" ];
		var offercolours = [ "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(0,204,153)", "rgb(83,255,185)", "rgb(147,255,219)", "rgb(159,255,255)", "rgb(204,255,255)", "rgb(213,239,255)", "rgb(192,209,248)", "rgb(243,221,255)", "rgb(255,229,229)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)", "rgb(224,230,207)" ];
		var hlcolour = "rgb(0,255,0)";
		var lasttime = null;
		var newdate = new Date();
		var make = 0;
		var model = 0;
		var bid = 0;
		var bidindex = 0;
		var	offerindex = 0;
						
		var i_index = 0;
		
		var i_id = i_index++;
//?		var i_qty =  i_index++;
		var i_make =  i_index++;
		var i_model =  i_index++;
		var i_version =  i_index++;
		var i_price =  i_index++;
		var i_disc =  i_index++;
		var i_code =  i_index++;
//?		var i_time =  i_index++;
//?		var i_realtime= i_index++;
		var i_localtime =  i_index++;
//		var i_screen =  i_index++;
//		var i_priceex =  i_index++;
//		var i_base =  i_index++;
//		var i_unit =  i_index++;
//		var i_deliv =  i_index++;
//		var i_image =  i_index++;
//		var i_selltrade= i_index++;
//		var i_buytrade= i_index++;
//		var i_member= i_index++;
//		var i_base2 =  i_index++;
//		var i_price2 =  i_index++;
//		var i_priceex2 =  i_index++;
//		var i_unit2 =  i_index++;
		var i_lastentry =  i_index-1;
		var cCurrency=0;
					
		function SetFocus()
		{
			if( document.Form1['tUser'] )
				document.Form1['tUser'].focus();
		}

		function popitup(url)
		{
			var newwindow = null;
			newwindow=window.open(url,'','width=800, height=600, toolbar=yes, menubar=yes, resizable=yes, status=yes, scrollbars=yes');
			if (!newwindow.opener) newwindow.opener = self;

			if (window.focus) {newwindow.focus()}
			return false;
		}
		
 		function formatplus( num ){
 			return num; //Math.round(num);
			var ans = new String( Math.round(num));
//			var num = new Number(num);
			if ( num >= 0 )
				ans = '+' + ans;
			return ans;
		}
		
		function unformatCurrency(num) {
			var ans = 0;
			for (var i = 0; i < num.length; i++)
			{
				if( num.substring(i,i+1) != ',' )
				{
					ans = 10 * ans + new Number(num.substring(i,i+1));
				}
			}
			return ans;
		}
		function formatCurrency(num) {
			num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
			if(cents<10)
			cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + num );//+ '.' + cents);
			}

		//This is our Polling function.  It will get called based on the interval passed to StartPolling.
		//This function will fire of a "GET", which in this case is handled by UpdateHandler.axd.
		//A WebForm can be used as well, though it has some performance implications.

		function getObj(name)
		{
		/* DHTML Micro API
		* Source: http://www.quirksmode.org/js/dhtmloptions.html
		*/
		if (document.getElementById) // test if browser supports document.getElementById
		{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
		}
		else if (document.all) // test if browser supports document.all
		{
		this.obj = document.all[name];
		this.style = document.all[name].style;
		}
		else if (document.layers) // test if browser supports document.layers
		{
		this.obj = document.layers[name];
		this.style = document.layers[name].style;
		}
}

		function GetUpdates()
		{
			//alert('getupdates');
			
			//get XMLHttp for mozilla or ie.
			var req=null;
			if(_openConnections!=null&&_openConnections.length>=_maxXmlHTTPConnections){
				//We will just ignore this request, we can not serve it.
				return;
			}
			//if(freeConnections!=null&&freeConnections.length>0){
			//	req=freeConnections.pop();
			//}
			if  (req==null)
			{
				req=getXmlHTTP();
			}
			if(_openConnections==null)_openConnections=new Array();
			_openConnections.push(req);
			//We need to hook up onreadystatechange since this is an async call.  
			//When the response is received, this annonymous function will be called, which will in turn call LoadUpdates
			//document.getElementById("openConnections").innerHTML=_openConnections.length;
			req.onreadystatechange=LoadUpdates;

			
			//Send the Request
			//Date d;
			//document.getElementById("lDate").value=d;
			newdate = new Date();
			var s = '';
			if( lasttime )
			{
			s += lasttime.getFullYear() + '-';
			//alert( 'l: ' + lasttime + ' s: ' + s + ' y: ' + lasttime.getYear() );
			if (lasttime.getMonth()+1 < 10 ) 
				s = s + '0';
			s = s  + (lasttime.getMonth()+1)  + '-';
			if (lasttime.getDate() < 10 ) 
				s = s + '0';
			s = s  + lasttime.getDate()  + ' ';
			if (lasttime.getHours() < 10 ) 
				s = s + '0';
			s = s  + lasttime.getHours()  + ':';
			if (lasttime.getMinutes() < 10 ) 
				s = s + '0';
			s = s + lasttime.getMinutes()  + ':';
			if (lasttime.getSeconds() < 10 ) 
				s = s + '0';
			s = s+ lasttime.getSeconds() ;
			
			s = s + '.';
			
			if (lasttime.getMilliseconds() < 100 ) 
				s = s + '0';
			if (lasttime.getMilliseconds() < 10 ) 
				s = s + '0';
			s = s + lasttime.getMilliseconds() ;
			}
			else
			{
				var t = new getObj('lTime');
				s = t.obj.innerHTML;
			}
			
			//alert('getupdates');
			
			var ss = "HomeHandler.axd?Time=" + s;
			//alert(ss);
			req.open("GET",ss ,true);
			req.send(null);
		}

		function ClearTable( bid, grid, now )
		{
			if( !grid || !grid.Rows )
				return;
				
			var index = grid.Rows.length;
			for( ; index > 0 ; index-- )
			{
				var row=grid.Rows.getRow(index-1);
//				var sd = row.getCell(i_realtime).getValue();

				var time = null;
				
//				if( sd.length > 22 )
//					time = new Date( sd.substring(13,17) ,sd.substring(18,20) -1,sd.substring(21,23),sd.substring(0,2) ,sd.substring(3,5),sd.substring(6,8),sd.substring(9,12));
//				else
//					time = new Date( sd );

				time = row.getCell(i_localtime).getValue();
				var diff = now-time;
//				if( index==1)
//					alert(time + ',' + now + ',' + diff + ',' + 10000);
				if( diff > 10000 )
				{
					CheckRowColour( bid, row );
				}
			}
		}
		
		function CheckRowColour( gridtype, row )
		{
			var ans = new Number(row.getCell(i_disc).getValue()); //discount

			ans = 100 + ans;
			if( ans > 125 )
				ans = 125;
				
			if( ans < 65 )
				ans = 65;

			var index = Math.abs( Math.round( ans/5 ) ) - 10 ;
			if ( gridtype == 1 )
				color = bidcolours[ index ];	
			else
				color = offercolours[ index ];	
			
			var colour2 = color;
			
			var code = row.getCell(i_code).getValue();
			if( code == "PEND" )
			{
				if( row.getCell(i_make).getElement().style.backgroundColor != "red" ) //choose one
					color = "red";
			}
			
			var loop = 0;
			
			for( loop = 0; loop <= i_lastentry ; loop++ )
				row.getCell(loop).getElement().style.backgroundColor=color;
		}
		
		
		function ParseTable( grid1, grid2, node )
		{
			var retval = 0;
			var sd = node.getAttribute("time");
			//alert('sd: ' + sd + ' y: ' + sd.substring(13,17) + ' m: ' + sd.substring(18,20) + ' d: ' + sd.substring(21,23) );
			var newdate = new Date( sd.substring(13,17) ,sd.substring(18,20)-1,sd.substring(21,23),sd.substring(0,2) ,sd.substring(3,5),sd.substring(6,8),sd.substring(9,12));
//			alert( lasttime + ', ' + newdate );
			if( lasttime == null || newdate > lasttime )
				lasttime = newdate;

			var index = 1;
			var gridtype = node.getAttribute("type");
			var myindex = 0;
			if ( gridtype == 1 )
			{
				grid = grid1;
				myindex = bidindex++;
			}
			else
			{
				grid = grid2;
				myindex = offerindex++;
			}
				
// replace entries in row(myindex)
// changed = changed flag...
				var added = 0;
				//alert( myindex );
				if( myindex > grid.Rows.length -1 )
				{
					if( grid == grid1 )
					{
						igtbl_addNew('U1',0);
						added = 1;
					}
					else
					{
						igtbl_addNew('U2',0);
						added = 1;
					}
				}	
				var row=grid.Rows.getRow(myindex);
				var crate = 1.0;
				
//				row.getCell(i_screen).setValue(new Number(node.getAttribute("screen")));
//?				row.getCell(i_qty).setValue(new Number(node.getAttribute("qty")));
//				row.getCell(i_base2).setValue(new Number(node.getAttribute("baseprice")));
//				row.getCell(i_price2).setValue(new Number(node.getAttribute("price")));
				
//				row.getCell(i_base).setValue(crate * new Number(node.getAttribute("baseprice")));
				row.getCell(i_price).setValue(crate * new Number(node.getAttribute("price")));
				
				row.getCell(i_disc).setValue(formatplus(new Number(node.getAttribute("discount")))); 
				row.getCell(i_code).setValue(node.getAttribute("code"));
//?				row.getCell(i_time).setValue(new String(node.getAttribute("time")).substring(0,8));
				row.getCell(i_id).setValue(node.getAttribute("id"));
				row.getCell(i_make).setValue(node.getAttribute("make"));
				row.getCell(i_model).setValue(node.getAttribute("model"));
				row.getCell(i_version).setValue(node.getAttribute("version"));
//				row.getCell(i_deliv).setValue(node.getAttribute("delivery"));
//				row.getCell(i_image).setValue(node.getAttribute("imageurl"));
//?				row.getCell(i_realtime).setValue(node.getAttribute("time"));
//				row.getCell(i_selltrade).setValue(node.getAttribute("sellcdate"));
//				row.getCell(i_buytrade).setValue(node.getAttribute("buycdate"));
//				row.getCell(i_member).setValue(node.getAttribute("member"));
				row.getCell(i_localtime).setValue( new Date().getTime() );
//				row.getCell(i_priceex2).setValue(node.getAttribute("priceex"));
//				row.getCell(i_unit2).setValue(node.getAttribute("unit"));
//				row.getCell(i_priceex).setValue(crate * new Number(node.getAttribute("priceex")));
//				row.getCell(i_unit).setValue(crate * new Number(node.getAttribute("unit")));
				
				CheckRowColour( gridtype, row );
				var ch = new Number(node.getAttribute("changed"));
				if( ch > 0 )
				{
//?					row.getCell(i_qty).getElement().style.backgroundColor=hlcolour;
					if( added = 0 )
					{
						row.getCell(i_price).getElement().style.backgroundColor=hlcolour;
						row.getCell(i_disc).getElement().style.backgroundColor=hlcolour;
					}
					retval = 1; //bid
					if ( gridtype != 1 )
						retval = 2; //offer
					var dt = new Date();
					row.getCell(i_localtime).setValue(dt.getTime());
				}
			
			return retval;
		}

		function ClearUpdates( start )
		{
			var now = new Date();
			var grid=igtbl_getGridById("U1");
			var grid2=igtbl_getGridById("U2");
				
			if( start == 1 )
			{
				now = new Date( now.getTime() + 30000 );
			}
			
			ClearTable( 1, grid, now ); //bid
			ClearTable( 0, grid2, now ); //offer
		}
				
		function LoadUpdates()
		{
			var req=null;
			for(var i=0;i<_openConnections.length;i++){
				if(_openConnections[i].readyState==4||_openConnections[i].readyState=='complete'){
					req=_openConnections[i];
					_openConnections.splice(i,1);
					break;
				}
			}
			if(req==null)return;
			//We can use responseText or responseXML.  I prefer responseXML because it is easier to navigate.
			var response=req.responseXML;
			
			if(response.childNodes!=null&&response.childNodes.length>0){
				var updatesNode=response.firstChild;
				//Mozilla will add text nodes for things like "/r/n".  We want to skip over those nodes.
				while(updatesNode!=null&&updatesNode.nodeName!="updates")updatesNode=updatesNode.nextSibling;
				if(updatesNode==null)return;
				
				var children=updatesNode.childNodes;
				var bids = 0;
				var offers = 0;
				bidindex = 0;
				offerindex = 0;
				if(children!=null&&children.length>0)
				for( var i=0;i<children.length;i++){
					var node=children[i];
					
					//If the node isn't a "record" it is likely a text node.  Either way, we can skip it.
					if(node.nodeName!="record")continue;
					if(node!=null){
//						lasttime = newdate; // no more - use the time I send back in the record set
						//Now that we have a valid record, lets update our data based on the record
						var x = ParseTable( igtbl_getGridById("U1"), igtbl_getGridById("U2"), node );
						if( x==1 )
							bids = 1;
						if( x==2 )
							offers=1;
						//sort the lists
						}
				}
				
/* will be sorted
				if( navigator.userAgent.indexOf("Firefox") != -1 )
				{
					if( bids > 0 )
						igtbl_getGridById("UltraWebGrid1").sort();
					if( offers > 0 )
						igtbl_getGridById("Ultrawebgrid2").sort();
				}					
*/
			}
			//IE has an xml property which will return the xmldom serialized out to a string.
			var xmlData=response.xml;
			//Mozilla does not have an xml property, but instead have an XMLSerializer
			if(xmlData==null&& typeof XMLSerializer != "undefined"){
				var serializer=new XMLSerializer();
				xmlData=serializer.serializeToString(response);
			}
			//Just some raw data presentation.  The TextArea shows the raw XML.
			if( document.getElementById("textArea") != null )
				document.getElementById("textArea").value=xmlData;
			//document.getElementById("totalBytes").innerHTML=parseInt(document.getElementById("totalBytes").innerHTML)+xmlData.length;
			//document.getElementById("openConnections").innerHTML=_openConnections.length;
			req=null;
			delete req;
		}
		
		//Call this function to start live update, with a specific interval.
		function StartPolling(/*int*/ refresh, /*int*/ clear)
		{
			//SetFocus();
			
			if(!refresh)
				refresh=_pollingInterval;
				
//			if(!_updatedRecordChange)
//				UpdateGridRecordChange();
				
			//document.getElementById("startButton").disabled=true;
			//document.getElementById("stopButton").disabled=false;
			_timerID=window.setInterval("GetUpdates();",refresh);
			_timerID2=window.setInterval("ClearUpdates(0);",clear);
			
			GetUpdates();
			//ClearUpdates(1);
			document.getElementById("oContainer").style.display="block"; //show content
			document.getElementById("LOAD").style.display="none"; //hide loading message
			
		}		//Stop updating
		
		function StopPolling()
		{
			if( _timerID > 0 )
			{
				window.clearInterval(_timerID);
				_timerID=0;
			}

			if( _timerID2 > 0 )
			{
				window.clearInterval(_timerID2);
				_timerID2=0;
			}
			//document.getElementById("startButton").disabled=false;
			//document.getElementById("stopButton").disabled=true;
		}
		
/*
		//Update the interval used for polling
		function WebNumericEdit1_ValueChange(oEdit, oldValue, oEvent)
		{
			_pollingInterval=oEdit.getValue()*1000;
			StopPolling();
			StartPolling(_pollingInterval,30000);
		}
*/

		function PopBids(){
			if( document.getElementById('BidsDiv').style.display=='none')
				document.getElementById('BidsDiv').style.display='block';
			else
				document.getElementById('BidsDiv').style.display='none';
		}
		function PopOffers(){
			if( document.getElementById('OffersDiv').style.display=='none')
				document.getElementById('OffersDiv').style.display='block';
			else
				document.getElementById('OffersDiv').style.display='none';
		}
		
		function pShowFilter(){
			if( document.getElementById('FilterDiv').style.display=='none')
			{
				document.getElementById('FilterDiv').style.display='block';
				document.getElementById('OrdersDiv').style.display='none';
			}
			else
			{
				document.getElementById('FilterDiv').style.display='none';
				document.getElementById('OrdersDiv').style.display='block';
			}
		}
		
		function pShowData(){
			if( document.getElementById('DataDiv').style.display=='none')
				document.getElementById('DataDiv').style.display='block';
			else
				document.getElementById('DataDiv').style.display='none';
		}
		
