/*
 * Created on 2009-07-31
 *
 * To change the template for this generated file go to
 * this project is base on LCP system power by LICHENG (lichengdongdong@hotmail.com)
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
$( function() {
	$("#shopList #btnDelShop").click(
			function() {
				$("form#formShopList").attr("action", "?name=Shop&handle=del")
						.submit();
			})
	//
	// $("#shopEdit #showstatus0").hide();

	/*
	 * 迷你店铺宝贝设置
	 */
	if ($("#itemsSet").size() != 0) {
		$("#itemsSet .itemsset").draggable( {
			stop : function(event, ui) {
				$(this).find(".x").val(ui.position.left);
				$(this).find(".y").val(ui.position.top);
			}
		});
	}

	// 调用时间控件
	if ($('#deadlineEdit').size() != 0) {
		$('.dateedit').calendar();
	}
	
	if($('#shopEdit').size()!=0){
		minishop_swapCopy('direct');
		//minishop_showHelp();
	}
	//
	if($("#shopIndex").size()!=0){
	   minishop_getindexshop();
	}
})

/**
 * 
 * @param id
 * @return
 */
function minishop_delProd(id) {
	var url = '/index.php?name=minishop&handle=prod&deal=del&id=' + id + '&ajax=1';
	$.getJSON(url, function(data) {
		if (data.className == "success") {
			$("#item" + id).remove();
			alert(data.message);
			return;
		}
		//
			alert(data.message);
		});
}

/**
 * 
 */
function minishop_select_module(v,em) {
	$(".function"+v).each(function(){		
		
		if($(this).attr("name")!=$(em).attr("name")){
			$(this).attr("checked","");
		}
	})
	
	
	
	// 获得合计
	var needmoney = 0;
	$(".moduleselect:checked").each(function(){
		var mmoney=parseInt($(this).val());
		needmoney+=mmoney;
	})
	
	
	


	$("#needmoney").val(needmoney);
}

/**
 * 
 * @return
 */
function minishop_open_submit() {
	var needmoney = parseInt($("#needmoney").val());
	var existmoney = parseInt($("#existmoney").val());
	if (existmoney < needmoney) {
		alert("你目前的拥有的迪币不够");
		return false;
	}
	return true;
}

/**
 * 
 * @param index
 * @return
 */
function minishop_swap_showstatus(index) {
	$("#showstatus0,#showstatus1").hide();
	$("#link_swap_showstatus0,#link_swap_showstatus1").removeClass("select");

	$("#showstatus" + index).show();
	$("#link_swap_showstatus" + index).addClass("select");

}

/**
 * 
 * @return
 */
function minishop_havereferlink(em) {
	var referuiddiv = $("#havereferuiddiv");
	// alert((em).checked);
	if ((em).checked) {
		referuiddiv.html($("#referlinktmp").html());
	} else {
		referuiddiv.html('');
	}
}

/**
 * 
 * @param em
 * @return
 */
function minishop_changelink(em) {

	var minishoplink = $(em).val();
	var minishopreallink = $(em).attr("realurl");
	var element = $("#istaobao").get(0);
	//
	if (element.checked == true) {
		$("a.minishoplink").attr("href", minishopreallink);
	} else {
		$("a.minishoplink").attr("href", minishoplink);
	}

}

/**
 * 
 * @param id
 * @return
 */
function minishop_item_save(id) {

	var title = $("li#item" + id).find("#title").val();
	var url = '/index.php?name=taoke&handle=editTaokeItem&id=' + id + '&ajax=1';
	$.ajax( {
		url :url,
		data : {
			title :title,
			click :1
		},
		dateType :'json',
		type :'post',
		success : function(da) {
			alert("成功保存");
		}
	})
}

/**
 * 
 * @return
 */
function minishop_refresh() {
	$.ajax( {
		url :'/index.php?name=minishop&handle=refresh&ajax=1',
		data : {
			click :1
		},
		dataType :'json',
		type :'post',
		success : function(data) {
			if (!data.message) {
				alert("出错");
				return;
			}
			location.reload();
	     }
	})
}

/**
 * 
 * @param type
 * @return
 */
function minishop_swapCopy(type){
	$("a#link_directCopy,a#link_codeCopy").removeClass('select');
	$("div#directCopy,div#codeCopy").hide();
	//
	$("a#link_"+type+"Copy").addClass("select");
	$("div#"+type+"Copy").show();
}


/**
 * 
 * @return
 */
function minishop_updateShop() {
	var url = "/index.php?name=shop&handle=edit";
	window.b = new Boxy(
			'<iframe src="' + url + '&single=1&backjs=parent.b.hide();parent.minishop_refresh();" height="600" width="700" frameborder="0" scrolling="auto">正在加载...</iframe>',
			{
				title :"修改店铺信息",
				modal :true
			});
}

/**
 * 
 * @return
 */
function minishop_open_module(url, title) {
	window.b = new Boxy(
			'<iframe src="' + url + '&single=1&backjs=parent.b.hide();parent.minishop_refresh();" height="600" width="700" frameborder="0" scrolling="auto">正在加载...</iframe>',
			{
				title :title,
				modal :true
			});
}




/**
 * 
 * @return
 */
function minishop_setfilterallow(){
	var isopenfilterallow=$('input[@name=isopenfilterallow][@checked]').val();
	var url='/index.php?name=minishop&handle=setfilterallow&ajax=1&isopenfilterallow='+isopenfilterallow;
    
	$.getJSON(url,function(data){
		if(data.message){
		  alert(data.message);
		}
	})	
}

/**
 * 
 * @return
 */
function  minishop_getindexshop(type){
	
	var sid=parseInt($("#sid").val());
	if(sid!=0){
	  if(type=='next'){
		 sid=sid-1;  
	  }
	  if(type=='forward'){
	     sid=sid+1;
	  }
	}	
    var url='/index.php?name=minishop&handle=detail&ajax=1&sid='+sid;
    
	$.getJSON(url,function(data){
		if(data.message){
			$("#minishopdiv").html(data.message);
		}
	});
}

/**
 * 
 * @param em
 * @return
 */
function minishop_settype(em){
	var picurl=$(em).val();
	$("#minishopimg").attr("src",picurl);
}


/**
 * 
 */
function minishop_getmoney(){
	var money=$("#needmoney").val();
	var url="/index.php?name=money&money="+money+"#charge";
	window.location.href=url;
}


/**
 * 
 * @return
 */
function minishop_showHelp(){
	var url = "/index.php?name=minishop&handle=help";
	window.b = new Boxy(
			'<iframe src="' + url + '&single=1" height="600" width="700" frameborder="0" scrolling="auto">正在加载...</iframe>',
			{
				title :"帮助信息",
				modal :true
			});
}
