    var http_request = false;
    var autodisp = true;
    var command = false;
    var commandName = "";
	var otimerid = null;
	var comtimerid = null;
	var sendcount = 0;
	var processing = false;
	var first = true;
	var init = true;

	var sendurl = "/location/laipacact?";

	var baseurl = "/location/assetact?";
	var basegpsurl = "/location/laipacact?";

	if(window.XMLHttpRequest)
	{
		http_request=new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		http_request=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	//var icon;

	var locIcon =  "images/star.gif";
	var locMarker = null;


	var myMarker = null;
	//var gmarkers = [];
    var map;
	var pinID = 2;


    function onLoad() {
      // Click Handling
      //
      // When you click the map, we create a new marker at that point. When you
      // click a marker, we remove it from the map.
      

	  //var bounds = new GLatLngBounds( new GLatLng( 32.24,-118.05) ,new GLatLng( 47.98,-81.90 )  );
	 // map.setCenter(new GLatLng(40.11, -99.975), map.getBoundsZoomLevel(bounds));
//	  ebi('map').style.width = screen.width - 390;
//	  ebi('map').style.height = screen.width  - 680;
	  var ww = getWindowWidth() - 225;//- 180;
	  if(ww < 50) ww = 50;

	  var hh = getWindowHeight();//  - 260;
	  if(hh < 50) hh = 50;

	  ebi('map').style.width = ww;
	  ebi('map').style.height = hh;
	  
	  //Add By tony on Dec.08,2009
	   ebi('window').style.left = 319;
	   ebi('window').style.top = hh-80;

	  initMap();


//	  setChagCountry();
    }

    function onUnload() {
		if(otimerid != null)
			clearTimeout(otimerid);
    }

	function initMap() {
		if(!init) return;

		init = false;

		map = new VEMap('map');

		if( !http_request) 
			return;
		var url = baseurl + "command=countryzone&userId=" + ebiByName('userId')[0].value;//By Qing 
		//alert(url);
		http_request.open("GET", url, true);
		http_request.onreadystatechange = handleInitstatusResponse;
		http_request.send(null);
	}

	function handleInitstatusResponse() {
		  if (http_request.readyState == 4 && http_request.status == 200) {
				  var xmlString = http_request.responseXML;
					   var lon1 =  parseFloat(  xmlString.documentElement.getElementsByTagName( "LongtMin" ).item(0).firstChild.data ) ;
					   var lat1 =  parseFloat(  xmlString.documentElement.getElementsByTagName( "LatMin" ).item(0).firstChild.data ) ;
					   map.LoadMap();
					   var locs = [];

					   var sw = new VELatLong( lat1,lon1 );
					   locs.push(sw);

					   //alert("lolat--" + lon1 + "---" + lat1);

					   var lon2 =  parseFloat(  xmlString.documentElement.getElementsByTagName( "LongtMax" ).item(0).firstChild.data ) ;
					   var lat2 =  parseFloat(  xmlString.documentElement.getElementsByTagName( "LatMax" ).item(0).firstChild.data ) ;
					   //alert("lolat--" + lon2 + "---" + lat2);
						var ne = new VELatLong( lat2,lon2 );
						locs.push(ne);
						map.SetMapView(locs);

					   otimerid=setTimeout("doEvent()",2000);

		  }
	}


	function doEvent() { 
		otimerid=setTimeout("doEvent()",30000);//By Qing Zhang
		fillstatusvalue();
//		otimerid=setTimeout("fillstatusvalue()",2000);
	}

	function search() { 
		var where = ebi('street').value;
		map.FindLocation(where);
	}


	function fillstatusvalue(){
		if( !http_request) 
			return;
		var url = baseurl + "command=groupstatus&userId=" + ebiByName('userId')[0].value;//By Qing Zhang
		http_request.open("GET", url, true);
		http_request.onreadystatechange = handleHttpResponse;
		http_request.send(null);
	}

	function handleHttpResponse() {
		  if (http_request.readyState == 4 && http_request.status == 200) {
			  var xmlString = http_request.responseXML;
 			  var nodeListPast = xmlString.documentElement.getElementsByTagName( "Asset" );
			  if(nodeListPast.length > 0) {
				  if(myMarker != null)
					map.DeleteAllPushpins();
				  //alert("mes1");
				  var locs = [];
				  for( var i = 0 ; i < nodeListPast.length ; i++ ) {
						var lon =  parseFloat( nodeListPast[ i ].getAttribute("Longitude") ) ;
						var lat =  parseFloat( nodeListPast[ i ].getAttribute("Latitude") ) ;
						var icon = nodeListPast[ i ].getAttribute("Icon");

					    var html = "Speed: <b>" + nodeListPast[ i ].getAttribute("Speed") + "</b><br />" 
								+ "Address: <b>" + nodeListPast[ i ].getAttribute("Location") + "</b><br />" 
								+ "Time: <b>" + nodeListPast[ i ].getAttribute("StatusDate") + "</b>";
						var pnt = new VELatLong(lat,lon);
						locs.push(pnt);

						  myMarker = new VEPushpin(pinID, 
							pnt, 
							icon,
							nodeListPast[ i ].getAttribute("Name"),
							html
							);
						  map.AddPushpin(myMarker);
						  pinID++;

				  }

					if(first ) {
						//if(locs.length > 0)
							map.SetMapView(locs);
						first = false;
					} 

					if(autodisp) {
						//if(locs.length > 0)
							map.SetMapView(locs);
					} 

//				  var loc = ebi('error');
//				  loc.style.display='none';

			  } else {
//				  var loc = ebi('error');
//				  loc.style.display='block';
//				  loc.innerHTML="No Data Report!";
			  }


		  }
	}

	function createMarker(point, icon, html) {
		  var marker = new GMarker(point, icon);
		  marker.tooltip = '<div class="tooltip">'+html+'</div>';

		  // Show this marker's index in the info window when it is clicked.
		  GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		  });

		  GEvent.addListener(marker,"mouseover", function() {
			  showTooltip(marker);
			});        
		  GEvent.addListener(marker,"mouseout", function() {
			tooltip.style.visibility="hidden"
			});        



		  return marker;
	}

    function showTooltip(marker) {
      	tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var height=tooltip.clientHeight;
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
      }


	function ebi(a){
		return document.getElementById(a);
	}
     //By Qing Zhang 
    function ebiByName(a){
		return document.getElementsByName(a);
	}



	function turnoff_onchange()
	{
		var select = ebi('turnoff');
		if (select.checked==true)
			autodisp = true;
		else
			autodisp = false;
		//storeorderinfo();
	}

//Add by tony Dec.08,2009
function showControl() {
ebi('controlmin').style.display="none";
ebi('window').style.display="";

	  var hh = getWindowHeight() ;  
	  if(hh < 50) hh = 50;
	  
	   ebi('window').style.left = 319;
	   ebi('window').style.top = hh-145;

}

function hideControl() {
ebi('controlmin').style.display="";
ebi('window').style.display="none";

	  var hh = getWindowHeight() ;  
	  if(hh < 50) hh = 50;
	  
	   ebi('controlmin').style.left = 220;
	   ebi('controlmin').style.top = hh-25;
}





