var userType = "";
var isDrp = "";
mui.ready(function(){
	console.log("页面加载完毕")
	document.querySelector('.loading-bg').style.display='none';
	mui.previewImage();
	userType = getQueryString("userType");
	/* isDrp = getQueryString("isDrp");
	if(userType == '2' && isDrp == 'true'){
		$('.mui-bar-tab').hide();
f		isDrp = 'false';
	}else{
		userType = 1;
	} */
});
function countChoices(obj) {
	max = 3;
	box1 = obj.form.box1.checked;
	box2 = obj.form.box2.checked;
	box3 = obj.form.box3.checked;
	box4 = obj.form.box4.checked;
	box5 = obj.form.box5.checked;
	box6 = obj.form.box6.checked;
	box7 = obj.form.box7.checked;
	box8 = obj.form.box8.checked;
	/* box9 = obj.form.box9.checked; */
	count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0)+ (box4 ? 1 : 0)+ (box5 ? 1 : 0)+ (box6 ? 1 : 0)+ (box7 ? 1 : 0)+ (box8 ? 1 : 0);
	checkall();
	if (count > max) {
		mui.alert('',"您只能选择" + max + "张图片!");
		obj.checked = false;
	}
}
$("#my-up-arrow .my-arrow").on("click",function(){
	var child=$(this).children();
	if(child.hasClass('mui-icon-arrowup')){
		child.removeClass('mui-icon-arrowup').addClass('mui-icon-arrowdown')
		$('#my-up-arrow').removeClass('my-up-arrow');
		$('#my-img-view .hide').hide();
		$('.my-hide').show();
	}else{
		child.removeClass('mui-icon-arrowdown').addClass('mui-icon-arrowup')
		$('#my-up-arrow').addClass('my-up-arrow');
		$('#my-img-view .hide').css('display','inline-block');
		$('.my-hide').hide();
	}
});
$(".content-more").on("click",function(){
	var lb=$(this).prev().children();
	if(lb.hasClass('line-clamp-2')){
		lb.removeClass('line-clamp-2')
		$(this).text('收起');
	}else{
		lb.addClass('line-clamp-2')
		$(this).text('更多');
	}
});
$('#btn-share').on("click",function(){
	console.log($("input[name='radio1']:checked"));
		var msg=$.trim($('#textarea').val()),imgstr="",contentid=$("input[name='radio1']:checked").val();
		$("#my-img-view input[type=checkbox]:checked").each(function(index){
			if($("#my-img-view input[type=checkbox]:checked").length==(index+1)){
				imgstr+=$(this).val();
			}else{
				imgstr+=$(this).val()+"|";
			}
		});
		console.log(imgstr+msg);
		var parameter= {
				message:msg,
				imgUrl:imgstr,
				contentId:contentid
	        };
		var desc=msg;
		console.log(desc+"hhe")
		if(desc==''){
			desc=$("input[name='radio1']:checked").prev().text();
			console.log($("input[name='radio1']:checked").prev().text())
		}
		$.ajax({
			"type":"post",
            "url":"/iamberry/wechat/share/add",
            "data" :parameter,
            "success" : function(res) {
            	var openid = '',shareId = '';
            	console.log(res)
                if(res.status){
                	console.log(res.message);
                	// 注册分享功能
					window.repleFlag = false;
					window.hiddenAllWechatMenu = false;//window.wxFriend window.repleWxData 
					var linkUrl=encodeURI("http://"+window.location.host+"/iamberry/wechat/sharePage/toSharePage?shareId="+res.data.shareId+"&openid="+res.data.openid + "&userType=" + userType);
					window.wxFriend = {
						    "appId": "",
						    "link":linkUrl,
						    "desc":desc,
						    "title":"8秒冲好一瓶奶!",
						    "imgUrl":"http://"+window.location.host+"/iamberry/common/shop/shareImages/"+$("input[type=checkbox]:checked").val(),
						    "netError":"您的网络异常，请刷新重试!如多次刷新无效，请向我们反应 ~",
						    "shareTimeSuccess":"分享成功",					//这里是分享朋友圈后调用的文字
						    "shareTimeCancel":"已取消分享",				//这里是取消分享给朋友圈后调用的文字
						    "shareAppSuccess":"分享成功",		    //这里是分享好友后调用的文字
						    "shareAppCancel":"已取消分享"			//这里是取消分享给好友后调用的文字
					};
					getConfig();
					setTimeout(mask.show(),500); //显示遮罩
                }else{
                	mui.toast(res.message);
                }
            }
		}); 
});
mui.os.ios ? listener_ipt() : keyup_fn();
function keyup_fn() {
	$('body').on('keyup', '#textarea', function(e) {
		var currKey = 0,
			e = e || event;
		currKey = e.keyCode || e.which || e.charCode;
		var keyName = String.fromCharCode(currKey);
		if (currKey == "13") {
			checkall();
		}
	});
}
function listener_ipt() {
	document.getElementById('textarea').onblur = function() {
		checkall();
	}
}
function reg_share_title(){
	var str=$.trim($('#textarea').val());
	var pattern = /最高|最低价|0元购|天猫|最佳|奢侈|文化大革命|极致|出厂价|零元购|京东|最先进|金牌|蛮夷|国家级|批发价|全场通用|淘宝|最大|名牌|日本鬼子|世界级|极品价|零利|当当|最强|最赚|战斗民族|顶级|一降到底|倾销|聚美优品|最极致|超赚|印度阿三|国家领导人|特价|最终解释权|1号店|最棒|之王|佛祖|国家主席|惊爆价|亏本|聚划算|最新|之最|上帝|习大大|清仓|击破一折|阿里巴巴|最低|填补国内空白|真主|周总理|跳楼价|击破二折|taobao|最长|著名品牌|绿茶婊|周恩来|跳水价|击破三折|TMALL|最宽|质量免检|权势狗|毛泽东|神价|击破四折|tianmao|最窄|质量无须检测|最薄|毛主席|一省到底|击破五折|Alibaba|最坚固|国家领导人推荐|最美|第一|底价|击破六折|alibaba|最小巧|国家机关推荐|顶尖|最新科学|极品价|击破七折|dangdang|最灵敏|国家机关专供|巅峰|最新技术|全场低至|击破1折|亚马逊|最完美|国家机关特供|极品|最先进加工工艺|价格最低|击破2折|amazon|最高级|屌炸天|百分百|一流|最实惠|击破3折|Amazon|绝佳|屌丝|国宝级|最小|最优惠|击破4折|jd|极佳|撕逼|宇宙级|TMD|tmd|SB|sb|SM|sm|傻逼|傻b|中国猪|台湾猪|我操|贱人|装b|煞笔|傻比|婊子|我日|我干|日你|我草|卧艹|卧槽|爆你|艹你|cao你|他妈|别他吗|草你|操你|你娘|你丫|干你|干死|杂种|狗日|妈逼|日逼|妈了个逼|狗娘养|不得好死|全家死光|死全家|贱比|贱b|下贱|全家死绝|白痴|无耻|妈的|贱货|人渣|混蛋|精子|射精|诱奸|强奸|做爱|被操|被插|被干|逼奸|仓井空|操逼|骚逼|死逼|操死|插阴|潮吹|潮喷|成人|春药|推油|性虐|一夜情|阴道|阴茎|淫糜|李克强|邓小平|肛交|龟头|黄片|奸情|叫床|妓女|口交|乳交|乱伦|内射|颜射|手淫|奶子|炮友|色情|性爱|屌|屄|a片|三级片|咪咪|呻吟|高潮|裸露|脱光|六合彩|法轮|轮法功|法轮功|李洪志|退党|台独|国民党|藏独|圣战组织|伊斯兰|温家宝|胡锦涛|共产党|共匪|反共|杀人|谋杀|自杀|海洛因|杜冷丁|鸦片|麻古|k粉|冰毒|大麻|吗啡|摇头丸|迷药|麻醉药|乖乖粉|三唑仑|毒品|贷款|发票|枪|炸弹|手榴弹|雷管|手雷|违禁品|匕首|电棍|\*|\'|\\/;
	if(str==''){
		return false;
	}
	if(pattern.test(str)){
		mui.alert('您好，评价内容被检测到有敏感字词，请更换！',function(){
			$('#textarea').val(str.replace(pattern, "**"));
		});
		$('#btn-share').removeClass('my-btn-red').addClass('my-btn-gray').attr('disabled','disabled');
		return false;
	}else{
		$("input[name=radio1]").prop('checked',false);
		$('.line-clamp-2').css('color','#999');
		return true;
	}
};
$('input[name=radio1]').on("click",function(){
	$('#textarea').val('');
	$('input[name=radio1]').prop('checked',false);
	$(this).prop('checked',true);
	checkall();
	if($(this).is(':checked')){
		console.log('1')
		$('.line-clamp-2').css('color','#999');
		$(this).prev().css('color','#333');
	}
})
function checkall(){
	if($("#my-img-view input[type='checkbox']:checked").length>0 && (reg_share_title() || $("input[name='radio1']:checked").length>0)){
			$('#btn-share').removeClass('my-btn-gray').addClass('my-btn-red').removeAttr('disabled');
		}else{
			$('#btn-share').removeClass('my-btn-red').addClass('my-btn-gray').attr('disabled','disabled');
		}
}
var mask = mui.createMask(function() {
}); //callback为用户点击蒙版时自动执行的回调；
function getQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return "";
}