$(function(){
	if(!xpoint || !ypoint){relocation();}    
	$('.popmask').click(function(){
		//$('.popmask').addClass('hide');
		$('.popmask').hide();
		$('.shop_switch').addClass('hide');
		$(".user_ewm").hide();
	})
});
//浏览器定位
function relocation(){
	if(navigator.geolocation){
		 var geolocationOptions={timeout:10000,enableHighAccuracy:true,maximumAge:5000};		 
		 navigator.geolocation.getCurrentPosition(getPositionSuccess, getPositionError, geolocationOptions);
	}else{
	     bdPosition();
	}
}
//h5定位成功回调
function getPositionSuccess(p){
	has_location = 1;//定位成功; 
    m_latitude = p.coords.latitude; //纬度
    m_longitude = p.coords.longitude;    
    var x = m_longitude;
    var y = m_latitude;
    //console.log('定位：' + x+' x '+y);
    var ggPoint = new BMap.Point(x,y);
    var convertor = new BMap.Convertor();
    var pointArr = [];
    pointArr.push(ggPoint);
    convertor.translate(pointArr, 1, 5, translateCallback);
}
//h5定位失败回调
function getPositionError(error){
    var ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
         wxlocation();
    }else{
        bdPosition();
    }    
}
//h5定位转换回调
function translateCallback(data){
  if(data.status === 0) {
    var points=data.points[0];
    //console.log('转换定位：' + points.lng +' x '+points.lat);
     userxypoint(points.lat, points.lng);
  }
}
//使用百度定位
function bdPosition(){
    var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
	    if(this.getStatus() === 0) {
			userxypoint(r.latitude,r.longitude);
	    }
	    else {
			console.log('定位失败，原因：' + this.getStatus());
	    }        
	},{enableHighAccuracy: true});
}
//将坐标返回到服务端;
function userxypoint(latitude,longitude){
	var query = new Object();
	var geo_url = APP+'Home/ajax/Cashgeo.html';
	query.ypoint = latitude;
	query.xpoint = longitude;
	$.ajax({
		url:geo_url,
		data:query,
		type:"post",
		dataType:"json",
		success:function(data){
			if(data.status == 1){
				if(data.reload){
					if(data.reload.length>17){
						$('.city_header').text(data.reload.substr(0,17));
						$('.city_header').html('<i class="hc-iconfont">&#xe6da</i>'+$('.city_header').html()+'...');
					}else{
						$('.city_header').html('<i class="hc-iconfont">&#xe6da</i>'+data.reload);
					}
				}
                var isindex=$('#isindex').val();
                if(isindex==1) reloadindex();
                else if(isindex==2) reloadgoods();
                else window.location.reload();
			}
			
		},error:function(){}
    });		 		
}