//////////////////////////////////////////////////////////////////////
// 51ditu maps obj

//////////////////////////////////////////////////////////////////////
var		g_ltMapObj = null;

// JavaScript Document
function getNameFromStr( str ){
	var name;
	var	len;
	
	len = str.indexOf("\n");
	if( len != -1 ){
		name = str.substr(0, len );		
	}
	else{
		name = str;
	}	
	return	name;
}


function getltmapx( x ){
	
	return x*100000+460;	
}
function getltmapy( y ){
	
	return y*100000-270;	
}
function initMap( divName, cityName ){

	if( g_ltMapObj == null ){	
		g_ltMapObj = new oLTMaps( divName, cityName );
		g_ltMapObj.loadmap();
	}
}
function oltmapobj()
{
	this.iid;
	this.obj=null;
	this.obj2=null;
}

function oLTMaps( tagName, cityName ){	
	
  	this.arrmapobj=new Array(); 	
  	this.ltmaps = null;
  	this.tagname = tagName;
  	this.cityname = cityName;
}

_p = oLTMaps.prototype;

_p.loadmap = function( ){
	this.ltmaps = new LTMaps( this.tagname );    
	this.ltmaps.cityNameAndZoom ( this.cityname, 5 ); 		
	this.ltmaps.addControl( new LTStandMapControl() );
	this.ltmaps.addControl( new LTScaleControl());	
	this.ltmaps.handleKeyboard(); 
	this.ltmaps.handleMouseScroll(); 
	this.ltmaps.addControl(new LTStandMapControl());
	this.oLTOverviewMapControl = new LTOverviewMapControl();
	//this.oLTOverviewMapControl.changeView() ;
	this.ltmaps.addControl(this.oLTOverviewMapControl);
	this.oLTPolyLine = new LTPolyLineControl();
	this.oLTPolyLine.setVisible(false);             
	this.ltmaps.addControl( this.oLTPolyLine );
}

_p.getmapobj = function( iid )
{
	var obj = null;
	var name = getNameFromStr( iid );
	
	for (var i=0; i<this.arrmapobj.length; i++){
		if (this.arrmapobj[i].iid==name){
			obj=this.arrmapobj[i];	
			break;
		}
	}
	if ( obj == null){
		obj=new oltmapobj();
		obj.iid=name;
		//this.arrmapobj[this.arrmapobj.length]=obj;
	}	
	
	return obj;
}
_p.setmapobj = function( mapobj ){
	
	for(var i=0; i<this.arrmapobj.length; i++){
		if (this.arrmapobj[i].iid == mapobj.iid){
			break;
		}
	}	
	this.arrmapobj[i] = mapobj;
	return;	
}
_p.addMarker=function( name, iconurl, lon, lat ){
	
	var mapobj = this.getmapobj( name );
	
	if( mapobj.obj != null ){
		this.ltmaps.removeOverLay(mapobj.obj);
		mapobj.obj = null;	
	}
	if( mapobj.obj2 != null){
		this.ltmaps.removeOverLay(mapobj.obj2);
		mapobj.obj2 = null;
	}
	var	icon = new LTIcon();
	icon.setImageUrl( iconurl );	
	var point =new LTPoint( getltmapx(lon) , getltmapy(lat) );	
	
	var markobj = new LTMarker( point, icon );	
	var textobj = new LTMapText( markobj );
	textobj.setLabel( name ); 	
	
	this.ltmaps.addOverLay( markobj );	
	this.ltmaps.addOverLay( textobj );	
	
	mapobj.obj = markobj;	
	mapobj.obj2 = textobj;
	this.setmapobj( mapobj );
}

_p.deleteMarker = function( Name )
{
	var			mapobj;
	mapobj = this.getmapobj( Name );
	if( mapobj.obj ){
		this.ltmaps.removeOverLay(mapobj.obj);	
		mapobj.obj = null;
	}
	if( mapobj.obj2 ){
		this.ltmaps.removeOverLay(mapobj.obj2);
		mapobj.obj2 = null;
	}
	mapobj = null;
}
_p.deleteAll = function()
{
	this.ltmaps.clearOverLays();
}
_p.center = function( Lon, Lat )
{
	this.ltmaps.moveToCenter ( new LTPoint( getltmapx(Lon), getltmapy(Lat) ) );
}
_p.addLine = function(name, linedata){
		
	var mapobj = this.getmapobj( name );
		
	if( mapobj.obj ){
		this.ltmaps.removeOverLay(mapobj.obj);	
		mapobj.obj = null;
	}
	if( mapobj.obj2 ){
		this.ltmaps.removeOverLay(mapobj.obj2);
		mapobj.obj2 = null;
	}
	
	
	var points = new Array();	
	
	//var icon_point = new LTIcon();
	//icon_point.setImageUrl( "image/icon_point.jpg" );
	
	for(var i=0; i<linedata.length; i++)
	{
		points.push( new LTPoint(getltmapx(linedata[i].x), getltmapy(linedata[i].y) ) );		
	}	
	var polyLine = new LTPolyLine( points );		
	this.ltmaps.addOverLay( polyLine );		
	mapobj.obj = polyLine;	
	
	this.setmapobj( mapobj );
}
_p.bestMaps = function ( arrPoints ) {
	
	var points = new Array();	
	
	for(var i=0; i<arrPoints.length; i++)
	{
		points.push( new LTPoint(getltmapx(arrPoints[i].x), getltmapy(arrPoints[i].y) ) );		
	}	
	this.ltmaps.getBestMap( points );
}

////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// maps operation
function mapGetIconUrl( speed, direction, alarm ){	
	if( alarm  == true ){	
		return	"image/icon_red.gif";
	}
	else if( speed > 10 ){
		return	"image/icon_blue.gif";		
	}
	else {
		return	"image/icon_black.gif";		
	}
}
function mapAddMarker( name, iconurl, lon, lat ){
	
	if( g_ltMapObj != null ){
		g_ltMapObj.addMarker( name , iconurl, lon, lat);	
	}		
}

function mapDeleteMarker( name ){
	
	if( g_ltMapObj != null ){
		g_ltMapObj.deleteMarker( name );	
	}		
	
}
function mapZoomIn( ){
	if( g_ltMapObj != null ){
		g_ltMapObj.ltmaps.zoomIn();		
	}	
}
function mapZoomOut( ){
	if( g_ltMapObj != null ){
		g_ltMapObj.ltmaps.zoomOut();	
	}	
}
function mapReload( ){
	g_ltMapObj.ltmaps.resizeMapDiv();
}
function mapFull( ){
	g_ltMapObj.ltmaps.centerAndZoom( "xian", 13);
}
function mapPrint (){
	map = g_ltMapObj.ltmaps;
	
	var html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
	html += (document.all)?"<html xmlns:v=\"urn:schemeas-microsoft-com:vml\">":"<html>";
	html += "\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n<title>Print Maps<\/title>\n";
	html += "<style type=\"text\/css\">\nbody {margin: 0px;}\n";
	html += (document.all)?"v\\:*{ Behavior:url(#default#VML);}":"";
	html += "\n</style>\n";
	html += "<\/head>\n";
	html += "<body><center>\n";
	html += map.getMapContent(1)+"<br>";
//	html += "<object  id=\"WebBrowser\"  width=0  height=0  classid=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></object> ";  
//	html += "<input type=button value='Print map' onclick=\"document.all.WebBrowser.ExecWB(7,1);\">";
	html += "\n<\/center><\/body>\n<\/html>";

	var win = document.open("","win","menubar=1,width="+map.container.offsetWidth+",height="+(map.container.offsetHeight-20));
	win.document.writeln(html);
	win.document.close();
}

function mapCenter( lon, lat ){
	if( g_ltMapObj != null ){
		g_ltMapObj.center(lon, lat);	
	}		
}

////////////////////////////////////////
var ShowUserInfo		= " ";
var EditUserInfo		= " ";
var ChildUserManager 	= " ";
var EditCarList 		= " ";
var CarDistribute 		= " ";	
var ShowCarMileage 		= " ";	
var ShowCarAlarm 		= " ";
var TopChildMenu1 		= " ";
var TopChildMenu2 		= " ";
var TopChildMenu3 		= " ";
var TopChildMenu4 		= " ";	
var TopChildMenu5 		= " ";
var setTheme0 			= " ";
var setTheme1 			= " ";
var setTheme2 			= " ";
var OperationHelp 		= " ";
var About 				= " ";


