
/*
 * 页面公共参数
 * */
var osType = "";
var params = null;

//分享链接使用的参数
var title = window["shareData"].title;
var weixinDec = window["shareData"].decs;  
var weixinUrl= window["shareData"].url;
var pictureURL= window["shareData"].imgUrl;


var App = {
	/**
	 * 初始化 应用入口
	 */
	init : function() {
		Fw.log("---init start---", "App");
		App.initParams();
		App.getLocation();
		App.initWebkitTitleBar();
		Fw.log("--init--end-", "App");
	},
	/*
	 * 调用标题
	 * */
	initWebkitTitleBar : function (){
		setWebitEvent("App.initWebkitTitleBar3()", "02");
	},
	initWebkitTitleBar3 : function(){
		return '{"title":"标题","leftButton":{"exist":"false"},"rightButton":{"exist":"false"}}';
	},

	/*
	 * 初始化url中带过来的参数
	 * */
	initParams : function(){
		var url = window.location.href;
		var search = document.location.search;
		localStorage.setItem("search",search);
		params = Fw.utilcx.getUrlParams(url);
		Fw.utilcx.setphost();
		var apptype = "";
		    osType = "";
		var appversion = "";
		var version = "";
	    params.appId ? apptype = params.appId : appId = "";
		params.ostype ? osType = params.ostype : osType = "";
		params.clientVersion ? appversion = params.clientVersion : appversion = "";
		params.version ? version = params.version : version = "";
		//重新拼装head
		var headJson = {
						"apptype":apptype,
						"osType":osType,
						"appversion":appversion,
						"version":version,
						} ;
		localStorage.setItem("head", YT.JsonToStr(headJson));	//当前报文头
		
	},
	
	//获取经纬度
	getLocation : function(){
		var osType2
		var ua = navigator.userAgent.toLowerCase();
		
		if (ua.match(/android/i)) {
		    osType2 = true
		}else{
			osType2 = false
		}

		if(osType2){
		 	window.SysClientJs.getLatLongitude("getClientLocation(@,@)");
		 }else{
			setWebitEvent("getClientLocation(@,@)", "location");
		}
	},
	
	/*分享*/
	showSharePanel : function(){
		//var osType = localStorage.getItem("osType");
		if(osType == 'android'){
			var contextCfg = eval("App.sendJsonArray()");
			window.SysClientJs.shareToOther(contextCfg);//2.7
		}else{
			setWebitEvent("App.sendJsonArray()", "CMBC_SHARE");
			var contextCfg = eval("App.sendJsonArray()");
			window.SysClientJs.shareToOther(contextCfg);//2.7
		}
	},
	//将JSON数组返回给客户端
	sendJsonArray : function(){
		//var osType = localStorage.getItem("osType");	//设备类型
		var jsonArray = null;
		if(osType == 'android'){
			var backJsonDataStr=eval("App.backJsonData()");
			var backJsonDataStr1=eval("App.backJsonData1()");			
			var QQZoomStr=eval("App.QQZoom()");
			var jsonArray='{"sharePanelData":[{"id":"SH001","callback":'+backJsonDataStr+'},{"id":"SH002","callback":'+backJsonDataStr1+'}]}';			
			//jsonArray='{"CallBack":"App.CallBack","WXCallBack":"App.WXCallBack","sharePanelData":[{"id":"SH001","callback":'+backJsonDataStr+'},{"id":"SH002","callback":'+backJsonDataStr1+'}]}';
		}else{
			var jsonArray='{"sharePanelData":[{"id":"SH001","callback":"App.backJsonData()"},{"id":"SH002","callback":"App.backJsonData1()"}]}';
			//jsonArray='{"CallBack":"App.CallBack","WXCallBack":"App.WXCallBack","sharePanelData":[{"id":"SH001","callback":"App.backJsonData()"},{"id":"SH002","callback":"App.backJsonData1()"}]}';	
		}
		return jsonArray;
	},

	//获取分享页面参数，并返回给客户端   微信好友
	backJsonData : function(){
		var json={
				"title":title,
				"text":weixinDec,
				"URL":weixinUrl,
				"pictureURL":pictureURL
			};
		return YT.JsonToStr(json);
	},
	//获取分享页面参数，并返回给客户端   微信朋友圈
	backJsonData1 : function(){
		var json={
				"title":weixinDec,
				"text":"",
				"URL":weixinUrl,
				"pictureURL":pictureURL
		};
		return YT.JsonToStr(json);
	},
	//QQ空间,图片地址中不能有"端口号的:",否则会导致图片分享不了
	QQZoom : function(){
		var urlAddress='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+weixinUrl;
		var json={"shareUrl":urlAddress,"shareTitleName":"QQ空间"};
		return YT.JsonToStr(json);
	},
	
	couponAlert : function(cfg){
		var alertHtml = "";
		if(cfg.ok_btn=="true"){
			//双按钮
			alertHtml += '<div class="opa_num"></div>';
			alertHtml += '<div class="alertDiv2">';
			alertHtml += '	<div class="doubleDiv2">';
			alertHtml += '		<div class="alertTitle2"><span class="titleSpan2">'+cfg.title+'</span></div>';
			alertHtml += '		<div class="alertCont2"><span class="contSpan2">'+cfg.msg+'</span></div>';
			alertHtml += '		<div class="alertBt2">';
			alertHtml += '			<div class="alertBt_left2" onclick="'+cfg.cancle_func+'"><span class="btSpan">'+cfg.cancle_text+'</span></div>';
			alertHtml += '			<div class="alertBt_right2" onclick="'+cfg.ok_func+'"><span class="btSpan">'+cfg.ok_text+'</span></div>';
			alertHtml += '		</div>';
			alertHtml += '	</div>';
			alertHtml += '</div>';
		}else{
			//单按钮
			alertHtml += '<div class="opa_num"></div>';
			alertHtml += '<div class="alertDiv2">';
			alertHtml += '	<div class="singleDiv2">';
			alertHtml += '		<div class="alertTitle2"><span class="titleSpan2">'+cfg.title+'</span></div>';
			alertHtml += '		<div class="alertCont2"><span class="contSpan2">'+cfg.msg+'</span></div>';
			alertHtml += '		<div class="alertBt2" onclick="'+cfg.cancle_func+'">';
			alertHtml += '			<span class="btSpan">'+cfg.cancle_text+'</span>';
			alertHtml += '		</div>';
			alertHtml += '	</div>';
			alertHtml += '</div>';
		}
		$("#alert_bg").html(alertHtml);
		$("#alert_bg").css("display","inline-block");
		document.getElementById("alert_bg").addEventListener('touchmove', App.handler,false);
	},
	/*防止滑动函数*/
	handler : function(event){
		event.preventDefault();
	},
	//弹框确定
	ok : function(){
		$("#alert_bg").css("display","none");
		document.getElementById("alert_bg").removeEventListener('touchmove', App.handler,false);
	},

};
Fw.onReady(App);