$(document).ready(function(){
	let CommPicArr=[];
	var cukey=$("#id-cukey").val();
	var prevPage=parseInt($.cookie('propage'));
	if($(".pro-desc").length == 0) {
	    $.cookie('propage', '', {expires:30});	
	}
	if($(".pb2-pm").length == 0) {
	    $.cookie('propage-det', '', {expires:30});
	}
	var showSel=0;
	Ini();
	function Ini(){
		if($("[sub=topc]").length<=1){
			$("#id-re-readmore").hide();
		}
		if($("[ael=al-re-s]").length<=1){
			$("#id-rev-sel-show-f2").hide();
		}
	}
	selbtn();
	function selbtn(){
		$("#id-rev-sel-show").unbind('click');
	    $("#id-rev-sel-show").bind('click',function(){
		    if(showSel==0){
			    $("#id-rev-sel-all").show();
			    showSel=1;
		    }else{
			    $("#id-rev-sel-all").hide();
			    showSel=0;
		    }
	    });
	}
	$("#id-rev-sel-all").click(function(){
		var rtype=$(this).attr('retype');
		var seltxt=$(this).html();
		var nowtxt=$('#id-rev-sel-show').html();
		$('#id-rev-sel-show').html(seltxt);
		$(this).html(nowtxt);
		if(rtype=='top'){
			$(this).attr('retype','most');
			$("[ael=al-re-s]").each(function(){
				var st=$(this).attr('stick');
				if(st!='Yes'){
					$(this).fadeOut(100);
				}else{
					$(this).show();
				}
			});
		}
		if(rtype=='most'){
			$("[ael=al-re-s]").each(function(){
				$(this).fadeIn(500);
			});
			$(this).attr('retype','top');
		}
		$(this).hide();
		selbtn();
		showSel=0;
	});
	var i=1;
	var max=parseInt($("#re-tmax").val());
	var totail=$("#retotail").html();
	$("#id-re-readmore").click(function(){
		var nownum=parseInt($("#re-shownum").html());
		i++;
		$("#rev-t_"+i).toggle(300);
		if(i>=max){
			$(this).hide();
			$("#re-shownum").html(totail);
		}else{
			var sn=nownum+6;
			$("#re-shownum").html(sn.toString());
		}
	});
	$("[ael=al-rev-star]").hover(function (){
		var th=parseInt($(this).attr("th"));
		$("[ael=al-rev-star]").each(function(){
			$(this).removeClass('heart');
			$(this).addClass('emptyheart');
		});
		var i=1;
		$("[ael=al-rev-star]").each(function(){
			if(i<=th){
				$(this).removeClass('emptyheart');
				$(this).addClass('heart');
			}
			i++;
		});
	},function(){
        var th=parseInt($("#send-star").val());
        $("[ael=al-rev-star]").each(function(){
			$(this).removeClass('heart');
			$(this).addClass('emptyheart');
		});
		var i=1;
		$("[ael=al-rev-star]").each(function(){
			if(i<=th){
				$(this).removeClass('emptyheart');
				$(this).addClass('heart');
			}
			i++;
		});
    });
	$("[ael=al-rev-star]").click(function(){
		var th=parseInt($(this).attr("th"));
		$("[ael=al-rev-star]").each(function(){
			$(this).removeClass('heart');
			$(this).addClass('emptyheart');
		});
		var i=1;
		$("[ael=al-rev-star]").each(function(){
			if(i<=th){
				$(this).removeClass('emptyheart');
				$(this).addClass('heart');
			}
			i++;
		});
		$("#send-star").val(th);
	});
	$("#send-re-name").keyup(function(){
		$("#name-tip").hide();
	});
	$("#send-re-email").keyup(function(){
		$("#email-tip").hide();
	});
	$("#id-r-s-but").click(function () {
        var contip=$("#re-send-cont-tip").val();
        var contip2=$("#re-send-cont-tip2").val();	
		var contip3=$("#re-send-cont-tip3").val();
		if($('#id-r-s-i-s-cont').val()==''){
			swal({   
	     		title: contip,   
	     		text: contip2,   
	     		timer: 2000,  
	     		type: "error",
	     		showConfirmButton: false 
	     	});
		    return false;
		}
		if($('#send-re-name').val()==''){
			$("#name-tip").show();
			return false;
		}
		if($('#send-re-email').val()==''){
			$("#email-tip").show();
			return false;
		}
	    var can={
	     	"Content":$('#id-r-s-i-s-cont').val(),
			"Name":$('#send-re-name').val(),
			"Email":$('#send-re-email').val(),
			"ProID":$('#ProID').val(),
			"Star":$('#send-star').val(),
			"PicArr":CommPicArr,
			"CuKey":cukey
	    };
		var t = $(this);
		var sending = $('#Email_Sending').val();
		var yuan = t.html();
		var mibaofs = new JQAjax("/comm/ajax.php?sub=PoseReview");
		mibaofs.OnStart(function () {
			t.html(sending);
		});
		mibaofs.OnStop(function () {
			t.html(yuan);
		});
		mibaofs.OnSuccess(function (C) {
			if (C.d.Code == 0) {
				var laste = '';
				$("[sub=topc]").each(function () {
					var show = $(this).css("display");
					if (show != 'none') {
						laste = $(this);
					}
				});
				var code = '';
				var starNum = parseInt($('#send-star').val());
				var EnTime = GetReviewTime();
				code += '<div class="review-s" ael="al-re-s" stick="" style="display:none">';
				code += '<div class="rev-s-top1">';
				code += '<img class="rev-flag" src="/new/templates/Web/en/images/f-user.png">';
				code += '<div class="rev-name-c">' + $('#send-re-name').val() + '</div>';
				code += '</div>';
				code += '<div class="rev-s-top2">';
				code += '<div class="rev-star-f">';
				for (var i = 1; i <= starNum; i++) {
					code += '<div class="rev-star-s"></div>';
				}
				code += '</div>';
				code += '</div>';
				code += '<div class="rev-s-top3">' + EnTime + '</div>';
				code += '<div class="rev-content">';
				code += '<span class="rev-pass-tip">' + contip3 + '</span><br/>';
				code += $('#id-r-s-i-s-cont').val();
				code += '</div>';
				code += '<div class="rev-s-picf">';
                $.each(CommPicArr,function(i,val){
					code += '<a class="revs-p-s fancybox" fancy-isrc="'+val+'">'; 
					code += '<img src="'+val+'"/>';
					code += '</a>';
				});

				code += '</div>';
				code += '</div>';
				code += '</div>';
				if (laste == '') {
					$(".review-f").append('<div class="review-t" id="rev-t_1" sub="topc" style="display:block;"></div>');
					$("[sub=topc]").each(function () {
						var show = $(this).css("display");
						if (show != 'none') {
							laste = $(this);
						}
					});
				}
				laste.append(code);
				laste.children(".review-s:last-child").fadeIn(1000);
				$("#id-r-s-i-s-cont").val('');
				$("#send-re-name").val('');
				$("#send-re-email").val('');
                CommPicArr=[];
				$(".r-s-i-img-show").html("");
				if ($(".fancybox").length) {
					$(".fancybox").fancybox();
				}
			}
		});
		mibaofs.OnSend($.toJSON(can), "json", true);
	});
	GetReviewTime();
	function GetReviewTime() {
		var myDate = new Date();
		var Year = myDate.getFullYear();
		var Da = myDate.getDate();
		var Mon = myDate.getMonth();
		var enMon = MonTurnEn(Mon);
		return enMon + ' ' + Da + '.' + Year;
	}
	function MonTurnEn(tmp_mon) {
		if (tmp_mon == '1') {
			return 'Jan';
		}
		if (tmp_mon == '2') {
			return 'Feb';
		}
		if (tmp_mon == '3') {
			return 'Mar';
		}
		if (tmp_mon == '4') {
			return 'Apr';
		}
		if (tmp_mon == '5') {
			return 'May';
		}
		if (tmp_mon == '6') {
			return 'Jun';
		}
		if (tmp_mon == '7') {
			return 'Jul';
		}
		if (tmp_mon == '8') {
			return 'Aug';
		}
		if (tmp_mon == '9') {
			return 'Sep';
		}
		if (tmp_mon == '10') {
			return 'Oct';
		}
		if (tmp_mon == '11') {
			return 'Nov';
		}
		if (tmp_mon == '12') {
			return 'Dec';
		}
	}
	var unix=0;
	var up = $("#rev-uppic-btn").Huploadify({
		auto:true,
		fileTypeExts:'*.jpg;*.png;*.bmp;*.gif',
		multi:true,
		fileSizeLimit:200,
		breakPoints:true,
		buttonText:'Upload Image',
		saveInfoLocal:true,
		showUploadedPercent:true,//鏄惁瀹炴椂鏄剧ず涓婁紶鐨勭櫨鍒嗘瘮锛屽20%
		showUploadedSize:true,
		removeTimeout:9999999,
		uploader:'/comm/upload.php?cukey='+cukey,
		onUploadStart:function(){
			if(unix==0){
				unix = Date.parse(new Date());
			}
			up.Huploadify('settings','formData', {PostUnix:'1111',bb:'2222'});
		},
		onUploadSuccess:function(file){
		},
		onUploadComplete:function(file,data,response){
			unix=0;
			var timestamp = Date.parse(new Date());
			var obj = eval('(' + data + ')');
			var PicUrl='/uploads/'+obj.file;
			CommPicArr.push(PicUrl);
			let c='';
			c+='<div class="rsiimg-s">';
			c+='<img class="rsisimg" src="'+PicUrl+'" />';
			c+='<div class="rsisclose">x</div>';
			c+='</div>';
			$(".r-s-i-img-show").append(c);
			$(".rsisclose").unbind("click");
			$(".rsisclose").bind("click",function(){
                let f=$(this).parents(".rsiimg-s");
				let src=f.find(".rsisimg").attr("src");
				$.each(CommPicArr,function(i,val){
                    if(val==src){
						CommPicArr.splice(i,1);
					}
				});
				f.remove();
			});
		},	
	});
});