﻿
var web4s = {
	mapType : "mapabc",
	
    webSite : "http://business.365car.com.cn",//营销服务器地址必须修改
    agentSite : "http://port.365car.com.cn", //agent
    fileWebSite : "http://fileservice.365car.com.cn:88/fileService",//文件服务器地址必须是TOMCAT端口必须修改
    bizSite : "http://port.365car.com.cn/bizservice",//biz地址
    mapKey : "c901a37a4f65fd140b594d73507ba6645d920ece22860a8e62ab931bec16ce6628d222cf9a4853ca", //mapabc key
    serviceIp : 'www.365car.com.cn', //服务器IP必须修改
    servicePort : "80", //服务器端口必须修改；
    safetyFolksId : "361108190007", //平安亲人商品ID，必须修改
	shareWebSiteHtml : null,
    context_path: '/web4s',
	noSessionSendHttpUrl : "/web4s/sendHttp.action",
	sendHttpUrl : "/web4s/user/user_sendHttp.action",
	findHotCommodityList : "/agent/interface/commodity_findHotCommodityList.action", //加载商品列表
	findMerchantLittleTypeList:'/marketing/api/findMerchantLittleTypeList', //查询服务商户的类型列表
    defaultUid : 10000,
	
	downGPSSeparator : "<<<<<",
	
	findMerchantList : '/marketing/api/findMerchantList',  //获取服务商列表
	findMerchantDetail : '/marketing/api/findMerchantDetail', //根据商户ID查询服务商详情
	
	getAllBrands : "/agent/interface/merchantManager_getAllBrands.action", //查询所有品牌
	getMerListByBrandCode : "/agent/interface/merchantManager_getMerListByBrandCode.action",//根据ID查询 商户信息列表
	getMerchantBrandList : "/agent/interface/merchantManager_getMerchantBrandList.action", //查询商户的
	
	key :  "7b8d36f4a5b2f163ba2f2f271f3f8449", //文件上传KEY
	fId :  "w_photo",  // 文件上传FID
	shareType : {"defa":0,"life":1,"tuan":2}, //来源类型 
	defaultLatLng : {lat : 22.508642039663355, lng : 113.92650716018677},
	
	bizTokenkey : "cd877e4274a4306e20f910c1439ee9f6e86c7d412aaaf364d987a0de1067c4093dd985b5a9a5a258ffb28b31f658fbd3",//biz  tokenkey
	
	gpsPhoto : {
		large : '/images_3/gps/large/',
		small : '/images_3/gps/small/',
		common : '/images_3/gps/common/'
	},
	
	/**
     * 所有分享类型
     */
	shareTypePage : function(cb){
    	
    	 if(web4s.shareWebSiteHtml){
    		 if(cb)
    			 cb(web4s.shareWebSiteHtml);
    	 }else{
    		 var shearWebsite = [{id : 'synch_sina', title:"新浪",nStyle : "shzIco sinaGrayIco",hStyle : "shzIco sinaIco"},
        	                     {id : 'synch_qq',   title:"腾讯",nStyle : "shzIco qqGrayIco",hStyle   : "shzIco qqIco"},
        	                     {id : 'synch_sohu', title:"搜狐",nStyle : "shzIco sohuGrayIco",hStyle : "shzIco sohuIco"},
        	                     {id : 'synch_netyi',title:"网易",nStyle : "shzIco netyiGrayIco",hStyle: "shzIco netyiIco"},
        	                     {id : 'synch_dou',  title:"豆瓣",nStyle : "shzIco douGrayIco",hStyle  : "shzIco douIco"}];
	    	 $.ajax( {
	            url : web4s.context_path + "/share_shareWebsiteList.action",
	            type : "post",
	            dataType : "json",
	            success : function(data) {
	               if(data.result.success){
	            	   web4s.shareWebSiteHtml = "";
	            	   var website = data.shareWebList;
	            	   website = website.reverse();
	            	   for(var i in website){
	            		   if(i != "in_array"){
		            		   //1:新浪,2:腾讯,3:搜狐,4:网易,5:豆瓣
		            		   shearWebsite[website[i].type-1].state = true;
	            		   }
	            		   //shearWebsite.splice(0,0,shearWebsite.splice(website[i].type-1,1)[0]);
	            	   }
	            	   for(var j in shearWebsite){
	            		   if(j != "in_array")
	            			   web4s.shareWebSiteHtml += '<a class="'+(shearWebsite[j].state?shearWebsite[j].hStyle:shearWebsite[j].nStyle)+'" id="'+shearWebsite[j].id+'" href="javascript:void(0);">'+shearWebsite[j].title+'</a>';
	            	   }
	            	   if(cb)
	            		   cb(web4s.shareWebSiteHtml);
	               }else{
	            	   for(var j in shearWebsite){
	            		   if(j != "in_array")
	            			   web4s.shareWebSiteHtml += '<a class="'+(shearWebsite[j].state?shearWebsite[j].hStyle:shearWebsite[j].nStyle)+'" id="'+shearWebsite[j].id+'" href="javascript:void(0);">'+shearWebsite[j].title+'</a>';
	            	   }
	            	   if(cb)
	            		   cb(web4s.shareWebSiteHtml);
	               }
	            }
	        });
    	 }
    },
	 /**
	 * 地理位置信息转换
	 * 根据经纬度转化为地理位置
	 */
	geocoderCastLatLng : function(latlng , cb){
    	var _this = this;
    	this.geocoder = new google.maps.Geocoder(),  //map 地址反解析对象
    	window.setTimeout(function(){
    		_this.geocoder.geocode({'latLng': latlng}, function(results, status) {
    			var _addressInfo = '';
    			var flag = true;
    			if (status == google.maps.GeocoderStatus.OK) {
    		        if (results[0]) {
    		        	_addressInfo = results[0].formatted_address;
    		        	_addressInfo = $.trim(_addressInfo.substring(0,(_addressInfo.indexOf("邮政编码")>0?_addressInfo.indexOf("邮政编码"):_addressInfo.length)));
    		        }
    			}else {
    				_addressInfo = "无此地理信息描述!";
    				flag = false;
    		    }
    			if(cb)
            		cb({'address' : _addressInfo ,'flag' : flag},_this);
    		});
    	}, 50);
    	
    	return _this;
	},
	
	/**
     * 初始化省份
     */
    initProvinces : function(cb) {
        $.ajax( {
            url : web4s.context_path + "/getProvinces.action",
            type : "get",
            dataType : "json",
            success : function(data) {
                var option = "<option value=''>--请选择--</option>";
                $.each(data.provinces, function(i, v) {
                    option = option + "<option value='" + v + "'>" + v
                            + "</option>";
                });
                $('#province').html(option);
                if (cb){
                	cb();
                }else{
                	$('#province').bind("change", function(){
                        web4s.getCitys();
                    });
                }
            }
        });
    },

    /**
     * 根据省份获取的城市
     */
    getCitys : function() {
        var province = $('#province').val();
        if (province) {
            $.ajax( {
                url : web4s.context_path + "/findCitys.action",
                type : "post",
                dataType : "json",
                data : "province=" + province,
                success : function(data) {
                    var option = "<option value='0'>--请选择--</option>";
                    $.each(data.citys, function(i, c) {
                        option += "<option value='" + c.cityId + "'>"
                                + c.cityName + "</option>";
                    });
                    $('#city').html(option);
                    $('#city').sSelect();
                }
            });
        } else {
            $('#city').html('<option value="0">--请选择--</option>');
            $('#city').sSelect();
        }
    }
};
/***
 * 地图关键字查询
 */
var gLocalSearch = {
		gLocalSearch : null,
		LARGE_RESULTSET : 200,//本地搜索最大结果数
		poiKey : "2010web4SonlineASDFSFWEFASDFAs",
		
		
		/***
		 * 参数说明
		 * keyword\关键字
		 * latLng：纬度经度对象
		 * cb:回调函数
		 */
		search : function(){
	       this.gSearch = function(param,cb){
	          this.cb = cb;
	    	  var _this = this;
              var isResult = false;
              var map = param.map?param.map:carFriendLife_module_index.map;
	    	  this.gSearch = new GlocalSearch();
	    	  this.gSearch.setSearchCompleteCallback(null, function(){
					var resultArray = [];
					for(var i in _this.gSearch.results){
					 var obj = gLocalSearch.getData(_this.gSearch.results[i]);
					 obj.id = i+obj.lat+obj.lon;
					 resultArray.push(obj);
					}
					if(cb){
					    isResult = true;
					    window.clearTimeout(_this.timeOut);
						cb(resultArray);
					}
				});
				this.gSearch.setResultSetSize(GSearch.LARGE_RESULTSET); //设置本地搜索最大结果数
				this.gSearch.setCenterPoint(map.getCenter());
				this.gSearch.execute(param.keyword);
	       };
	       
	       /**
	        * 根据关键字查询.
	        */
	       this.gKSearch = function(param,cb){
  	    	 	$.ajax({
	  	            url : web4s.context_path + "/searchPoi/searchPoiByContext.action",
	  	            type : "post",
	  	            // data : {"userId":'10020', "sign":("10020"+gLocalSearch.poiKey).MD5(32), Keyword:"香蜜湖",Count:100,cityId:"1103",pageSize:5,currentPage:1},
	  	            data : {"userId":'10020',"Keyword":param.keyword,"Count":100,"cityId" : param.cityId,"sign":("10020"+gLocalSearch.poiKey).MD5(32),"pageSize" : param.pageSize,"currentPage" : param.currentPage},
	  	            dataType : "json",
	  	            success : function(data) {
	  	            	if(cb)
	  	            		cb(data);	
	  	            }
	  	        });
	       };
	       
	       /**
	        * 根据经纬度查询.
	        */
	       this.gLSearch = function(param,cb){
 	    	 	$.ajax({
	  	            url : web4s.context_path + "/searchPoi/searchPoiByRLL.action",
	  	            type : "post",
	  	            data : {"userId" : '10020',"keyword" : param.keyword,"lat" : param.lat,"lng" : param.lng,"range" : param.range,"cityId" : param.cityId,"sign" : ("10020"+gLocalSearch.poiKey).MD5(32),"pageSize" : param.pageSize,"currentPage" : param.currentPage},
	  	            dataType : "json",
	  	            success : function(data) {
	  	            	console.log(data);	
	  	            }
	  	        });
	       };
	       
	       return this;
		},
		
		
		
		getData : function(result){
		   var obj = {};
		   obj.name = result.titleNoFormatting;
		   obj.addr = result.streetAddress;
		   obj.lat = result.lat;
		   obj.lon = result.lng;
		   return obj;
		}
};
/**
 * Map操作类
 * 返回地图操作实例
 */
mapControl = { 
	initialize : function(callback){
		if(web4s.mapType == "google"){
			var gmap  = new Msd.gMap();
			window.setTimeout(function(){
				if(callback)
					callback(gmap);
			}, 500);
		}else if(web4s.mapType == "mapabc"){
			var amap  = new Msd.aMap();
			window.setTimeout(function(){
				if(callback)
					callback(amap);
			}, 1500);
		}
	},
	init : function(){
		if(web4s.mapType == "google"){
			document.write('<script src="http://maps.google.com/maps/api/js?sensor=true"></script>');
			document.write('<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxQ82LsCgTSsdpNEnBsExtoeJv4cdBSUkiLH6ntmAr_5O4EfjDwOa0oZBQ" type="text/javascript"></script>');
		}else if(web4s.mapType == "mapabc"){
			document.write(' <script type="text/javascript" src="http://app.mapabc.com/apis?&t=ajaxmap&v=2.1.2&key=205c646fad76cbedb1b55ed1b7bf9a0bd7ce513bc6f9db12d2d284fd768f9578c731f4f0c1d4abd1"></script> ');
		}
	}
};
///公用组件
//固定滚动
jQuery.fn.autoscroll = function(selector) {
	  $('html,body').animate(
	    {scrollTop: $(this.selector).offset().top},
	    500
	  );
};
//清除默认值..
jQuery.fn.defaultValue = function(selector) {
	    swap_val = [];
	    $(this.selector).each(function(i){
	        swap_val[i] = $(this).val();
	        $(this).focusin(function(){
	            if ($(this).val() == swap_val[i]) {
	                $(this).val("");
	            }
	        }).focusout(function(){
	            if ($.trim($(this).val()) == "") {
	                $(this).val(swap_val[i]);
	            }
	        });
	    });
};

