/**
 * [OEmarry] (C)2010-2099 OEMARRY.COM Inc.
 * Email: service@phpcoo.com, phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2016-04-22 by OEdev $
*/

$(function(){ 
	
	//搜索商家------------------Begin 
	$("[f='index_serkey']").bind("click", function(){
		if ($(this).val() == "搜商家…") {
			$(this).val("");
		}
	});
	$("[f='index_serkey']").bind("blur", function(){
		if ($(this).val() == "") {
			$(this).val("搜商家…");
		}
	});
	
	$("[f='index_btn_search']").bind("click", function(){ //搜索
		$serkey = $("[f='index_serkey']").val();
		if ($serkey.length > 0 && $serkey != "搜商家…") {
			$("#s_serkey").val($serkey);
			$("#index_serch_form").submit();
		}
	});
	//搜索商家------------------End

	//改变tr错综样式代码 页面底部加载 table增加样式名 table_cs
	$oe_table_obj = $(".table_cs tr");
	$oe_tr_len = $oe_table_obj.length;
	if ($oe_tr_len > 0) {
		for (i=0; i<$oe_tr_len; i++){
			if (i > 0) {
				if (i%2 == 0) {
					$($oe_table_obj).eq(i).addClass("tr_b");
				}
			}
		}
	}

	//浏览内容
	$("[f='detail']").live("click", function(){
		$_mod = $(this).attr("data-mod");
		$_id = $(this).attr("data-id");
		$_url = _ROOT_PATH+"index.php?c="+$_mod+"&a=detail&id="+$_id;
		window.open($_url);
	});

	//通用 单个删除(url 方式) 
	$("[f='onedel']").live("click", function(){
		$_url = $(this).attr("data-url");
		$_text = $(this).attr("data-text");
		if (typeof($_text) == "undefined") {
			$_text = "确定要删除吗？";
		}
		oePopConfirm($_text, $_url, "url");
	});

	//通用 批量删除(form 提交方式)
	$("[f='multidel']").live("click", function(){
		$_id_name = $(this).attr("data-idname");
		$_a = $(this).attr("data-a");
		$_form = $(this).attr("data-form");

		$_value = document.getElementsByName($_id_name);;
		$_valueArr = $_value.length;
		$_str = "";
		$_num = 0;
		for ($_i=0; $_i<$_valueArr; $_i++) {
			if($_value[$_i].checked == true) {
				$_str += $_value[$_i].value+",";
				$_num++;
		   }
		}
		if ($_num < 1) {
			ToastShow("请选择要删除的信息");
			return false;
		}
		if ($_a != "") {
			$("#a").val($_a);
		}
		$("#oeform").val($_form);
		oePopConfirm("确定要删除吗？", "oemarryUcCallBackDelForm");
	});
	

	//通用 单个确认操作 2016.04.23
	$("[f='oneconfirm']").live("click", function(){
		$_url = $(this).attr("data-url");
		$_text = $(this).attr("data-text");
		if (typeof($_text) == "undefined") {
			$_text = "确定要执行该操作吗？";
		}
		oePopConfirm($_text, $_url, "url");
	});

	//预览图片(通用)
	$("[f='viewimg']").live("click", function(){
		$img_url = $(this).attr("src");
		if ($img_url.length > 0) {
			if ($img_url.substr(0, 1) == "/") {
			
			}
			else {
				$img_url = _ROOT_PATH+$img_url;
			}
			window.open($img_url);
		}
	});

	//阅读站内消息
	$("[f='readmsg']").live("click", function(){
		$tag_value = $(this).attr("data-value");
		
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?m=user",
			cache: false,
			data: {c:"msg", a:"read", id:$tag_value, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					$("#msg_status_"+$tag_value).html("<font color='green'>已读</font>");
					$("#msg_btn_"+$tag_value).html("~~");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("操作失败");
					}
					
				}

			},
			error: function() {
				ToastShow("操作失败，请检查网络！");
			}
		});

	});
	

	$("[f='adddianpingto']").live("click", function(){ //添加店铺追评
		$commid = $(this).attr("data-id");
		oe_varpop_uc_shopaddto($commid);
	});
	$("[f='editdianpingto']").live("click", function(){ //编辑店铺追评
		$replyid = $(this).attr("data-id");
		oe_varpop_uc_shopeditto($replyid);
	});
	$("[f='deldianpingto']").live("click", function(){ //删除店铺追评
		$replyid = $(this).attr("data-id");
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?m=user",
			cache: false,
			data: {c:"shopcomment", a:"delto", id:$replyid, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("删除失败");
					setTimeout(function(){
						window.location.reload();
					}, 800);
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("删除失败");
					}
					
				}

			},
			error: function() {
				ToastShow("删除失败，请检查网络！");
			}
		});
	});

	$("[f='editwords']").live("click", function(){ //编辑店铺追评
		$wordid = $(this).attr("data-id");
		oe_varpop_uc_editwords($wordid);
	});


});


//全选/反选
function oemarrySelectAll(obj, cls) {
	if (typeof(cls) == "undefined") {
		cls = "selall";
	}
	//alert($(obj).attr("class").indexOf("icon-checkbox-unchecked"));
	if ($(obj).hasClass("icon-checkbox-unchecked")) { //执行全选
		$(obj).removeClass("icon-checkbox-unchecked");
		$(obj).addClass("icon-checkbox-checked");
		$("."+cls+":checkbox").attr("checked", true);

	}
	else { //执行反选
		$(obj).removeClass("icon-checkbox-checked");
		$(obj).addClass("icon-checkbox-unchecked");
		$("."+cls+":checkbox").attr("checked", false);
	}
}

//弹出确认框回调删除信息函数结合f=multidel使用
function oemarryUcCallBackDelForm() {
	eval($("#oeform").val()).submit();
}


/**
 * 弹出添加追加店铺点评页面
 * @param:: int $commid 店铺ID
 * @param:: int $width 页面宽
 * @param:: int $height iframe高
 * @return:: null
*/
function oe_varpop_uc_shopaddto($commid, $width, $height) {
	if (typeof($width) == "undefined") {$width = 600;}
	if (typeof($height) == "undefined") {$height = 300;}
	$_url = _ROOT_PATH+"index.php?m=user&c=shopcomment&a=addto&id="+$commid;
	oePopDialog("oe_js_pop_shop_addto", "点评追加", $_url, "ajax", $width, $height);
}
/**
 * 弹出编辑追加店铺点评页面
 * @param:: int $replyid 回复ID
 * @param:: int $width 页面宽
 * @param:: int $height iframe高
 * @return:: null
*/
function oe_varpop_uc_shopeditto($replyid, $width, $height) {
	if (typeof($width) == "undefined") {$width = 600;}
	if (typeof($height) == "undefined") {$height = 300;}
	$_url = _ROOT_PATH+"index.php?m=user&c=shopcomment&a=editto&id="+$replyid;
	oePopDialog("oe_js_pop_shop_editto", "编辑追加", $_url, "ajax", $width, $height);
}


/**
 * 弹出编辑留言页面
 * @param:: int $wordsid 留言ID
 * @param:: int $width 页面宽
 * @param:: int $height iframe高
 * @return:: null
*/
function oe_varpop_uc_editwords($wordsid, $width, $height) {
	if (typeof($width) == "undefined") {$width = 600;}
	if (typeof($height) == "undefined") {$height = 300;}
	$_url = _ROOT_PATH+"index.php?m=user&c=shopwords&a=edit&id="+$wordsid;
	oePopDialog("oe_js_pop_uc_editwords", "编辑留言", $_url, "ajax", $width, $height);
}