
/*
-- ------ netsMap_Google ------ --
*/
function netsMap_Google(){}
//-- ------ #Parameters ------ --

netsMap_Google.prototype.sName="gsnavigationMap";
netsMap_Google.prototype.sAutoSize=0;
netsMap_Google.prototype.sClassname="MapChoose_1_Show";
netsMap_Google.prototype.sImgPath="Ui/Common/Img/Common/";

netsMap_Google.prototype.sMap=null;
netsMap_Google.prototype.sMakers=Array();
netsMap_Google.prototype.sMakerInfowindows=Array();
netsMap_Google.prototype.sGeocoder=null;

netsMap_Google.prototype.sMaker_Type=0;

netsMap_Google.prototype.sControl_MapX="";
netsMap_Google.prototype.sControl_MapY="";
netsMap_Google.prototype.sControl_MapIntroduct="";
netsMap_Google.prototype.sControl_Maker=null;
netsMap_Google.prototype.sControl_MakerInfowindows=null;

netsMap_Google.prototype.sSize_Width=400;
netsMap_Google.prototype.sSize_Height=300;
netsMap_Google.prototype.sCenter_X=0;
netsMap_Google.prototype.sCenter_Y=0;
netsMap_Google.prototype.sMakersIndex=0;
netsMap_Google.prototype.sMakerParameters=Array();


//-- ------ #Methods ------ --
netsMap_Google.prototype.showMap=function(){
	//-- ------ #Intitial ------ --
	//-- #CONTROL --
	document.getElementById(this.sName+"_Box").className=this.sClassname;
	if(this.sAutoSize==0){
		document.getElementById(this.sName+"_Box").style.width=this.sSize_Width;
		document.getElementById(this.sName+"_Box").style.height=this.sSize_Height;
		document.getElementById(this.sName+"_Box").innerHTML="";
	}
	document.getElementById(this.sName+"_SearchBox").className="";

    tmpCenterPosition=new google.maps.LatLng(this.sCenter_X,this.sCenter_Y);
    if(document.getElementById(this.sControl_MapX)!=undefined &&document.getElementById(this.sControl_MapY)!=undefined){
    	if(parseFloat(document.getElementById(this.sControl_MapY).value)!=0 && parseFloat(document.getElementById(this.sControl_MapX).value)!=0){
    		tmpCenterPosition=new google.maps.LatLng(parseFloat(document.getElementById(this.sControl_MapX).value),parseFloat(document.getElementById(this.sControl_MapY).value));
    	}
    }
    var tmpOptions={
      zoom: 10,
      center: tmpCenterPosition,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    this.sMap=new google.maps.Map(document.getElementById(this.sName+"_Box"),tmpOptions);
	
	//-- ------ #Set maker ------ --
	if(document.getElementById(this.sControl_MapX)!=undefined && 
		document.getElementById(this.sControl_MapY)!=undefined && 
		document.getElementById(this.sControl_MapIntroduct)!=undefined){
		//SET
		tmpTitle=document.getElementById(this.sControl_MapIntroduct).value;
		tmpImage=this.sImgPath+"map_maker_common.png";
		tmpLatLng=new google.maps.LatLng(parseFloat(document.getElementById(this.sControl_MapX).value),parseFloat(document.getElementById(this.sControl_MapY).value));
		if(parseFloat(document.getElementById(this.sControl_MapY).value)==0 || parseFloat(document.getElementById(this.sControl_MapX).value)==0){
			tmpLatLng=new google.maps.LatLng(this.sCenter_X,this.sCenter_Y);
		}
		tmpContent=document.getElementById(this.sControl_MapIntroduct).value;
		//MAKE
		this.sControl_Maker=new google.maps.Marker({
			title:tmpTitle,
			//icon:tmpImage,
			position:tmpLatLng,
			draggable:true,
			map:this.sMap

			});
		this.sControl_MakerInfowindows=new google.maps.InfoWindow({
			content:tmpContent
			});
		this.AttachSecretMessage(this.sControl_Maker,this.sControl_MakerInfowindows);

	}
	//-- ------ #Set maker ------ --
	var Coun0=0;
	while(this.sMakerParameters.length>Coun0){
		//SET
		this.sMakersIndex=Coun0;
		tmpTitle=this.sMakerParameters[Coun0][0];
		tmpImage=this.sImgPath+this.sMakerParameters[Coun0][1];
		tmpLatLng=new google.maps.LatLng(this.sMakerParameters[Coun0][2],this.sMakerParameters[Coun0][3]);
		tmpContent=this.sMakerParameters[Coun0][4];
		//MARKER
		if(this.sMaker_Type==0){
			this.sMakers[Coun0]=new google.maps.Marker({
				title:tmpTitle,
				icon:tmpImage,
				position:tmpLatLng,
				map:this.sMap

				});
			this.sMakerInfowindows[Coun0]=new google.maps.InfoWindow({
				content:tmpContent
				});
			this.AttachSecretMessage(this.sMakers[Coun0],this.sMakerInfowindows[Coun0]);
			
		}else{
			tmpBounds=new google.maps.LatLngBounds(tmpLatLng,tmpLatLng);
			tmpOverlay=new netsMap_Google_HtmlMarker(tmpBounds,tmpTitle,tmpContent,this.sMap);

		}
		Coun0++;
	}


	return 0;
}
netsMap_Google.prototype.hiddenMap=function(){
	//-- #CONTROL --
	document.getElementById(this.sName+"_Box").className="MapChoose_1";
	document.getElementById(this.sName+"_Box").innerHTML="请点击上面的链接来加载地图控件。";
	document.getElementById(this.sName+"_Box").innerHTML="";
	document.getElementById(this.sName+"_SearchBox").className="DHidden";
	
	
	return 0;
}
netsMap_Google.prototype.searchMap=function(pSTR){
	var tmpSEARCHSTR=document.getElementById(this.sName+"_SearchTxt").value;
	if(pSTR!=""){
		tmpSEARCHSTR=pSTR;
	}
	var tmpAPP=this;
	var tmpGeocoder=new google.maps.Geocoder();

	tmpGeocoder.geocode({"address":tmpSEARCHSTR},function(results,status){
		if(status==google.maps.GeocoderStatus.OK){
			tmpAPP.sMap.setCenter(results[0].geometry.location);

		}else{
			
		}
		});


	return 0;
}
netsMap_Google.prototype.ShowInfowindow=function(pIndex){
	if(pIndex==-1){
		this.sControl_MakerInfowindows.open(this.sMap,this.sControl_Maker);
	}else{
		this.sMakerInfowindows[pIndex].open(this.sMap,this.sMakers[pIndex]);
	}
	
	return 0;
}
netsMap_Google.prototype.AttachSecretMessage=function(pMarker,pInfowindow){
	google.maps.event.addListener(pMarker,"click",function(){
		var tmpAPP=tmpGsnavigation;
		pInfowindow.open(tmpAPP.sMap,pMarker);
		});
	google.maps.event.addListener(pMarker,"dragend",function(){
		var tmpAPP=tmpGsnavigation;
		tmpAPP.sMap.setCenter(pMarker.getPosition());
		pInfowindow.content=document.getElementById(tmpAPP.sControl_MapIntroduct).value;
		pInfowindow.open(tmpAPP.sMap,pMarker);
		document.getElementById(tmpAPP.sControl_MapX).value=pMarker.getPosition().lat();
		document.getElementById(tmpAPP.sControl_MapY).value=pMarker.getPosition().lng();
		});
		
	return 0;
}
/*
-- ------ netsMap_Google_HtmlMarker ------ --
*/

//-- ------ #Parameters ------ --
netsMap_Google_HtmlMarker.prototype=new google.maps.OverlayView();
function netsMap_Google_HtmlMarker(pBounds,pTitle,pHtml,pMap){
	this.bounds_=pBounds;
	this.title_=pTitle;
	this.image_=pHtml;
	this.map_=pMap;
	this.div_=null;
	
	this.setMap(pMap);
	
}
netsMap_Google_HtmlMarker.prototype.onAdd=function(){
	var tmpDiv=document.createElement("DIV");
	tmpDiv.style.borderStyle="none";
	tmpDiv.style.borderWidth="0px";
	tmpDiv.style.position="absolute";
	tmpDiv.style.borderStyle="none";
	tmpDiv.innerHTML=this.image_;
	this.div_=tmpDiv;
	var tmpPanes=this.getPanes();
	tmpPanes.overlayImage.appendChild(tmpDiv);
	
}
netsMap_Google_HtmlMarker.prototype.draw=function(){
	var tmpOverlayProjection=this.getProjection();
	var tmpSouthWest=tmpOverlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
	var tmpDiv=this.div_;
	tmpDiv.style.left = tmpSouthWest.x+"px";
	tmpDiv.style.top = tmpSouthWest.y+"px";
	tmpINT=this.title_.length*12+20;
	tmpDiv.style.width=tmpINT+"px";
	/*
	
	tmpDiv.style.height=120+"px";
	*/
	
}
netsMap_Google_HtmlMarker.prototype.onRemove=function(){
	this.div_.parentNode.removeChild(this.div_);
	this.div_=null;
}
