/**
 * 添加活动范围值
 */
function addRang(val){
	var rang = $("#"+val).val();
	var lists  = document.getElementById("act_range_ext");
	var rang_val = document.forms['myform'].elements[val];
	if (rang > 0){
		rangId = rang;
		rangName = rang_val.options[rang_val.selectedIndex].text;
	}else{
		return;
	}
	//检查是否已经存在
	exists = false;
	for (i = 0; i < document.forms['myform'].elements.length; i++){
	  if (document.forms['myform'].elements[i].type=="checkbox"){
		if (document.forms['myform'].elements[i].value == rangId){
		  exists = true;
			  $.showConfirm('选定的选项已经存在','','hc')
		}
	  }
	}
	// 创建checkbox
	var is_pt = $('#is_pt').val();
	if (!exists){
		if(is_pt == 1){
			lists.innerHTML = "<label class='checkbox-inline'><input type='checkbox' name='act_rang_ext[]' value='" + rangId + "' checked='true' /> " + rangName + "</label>&nbsp;&nbsp;";
		}else{
	  		lists.innerHTML += "<label class='checkbox-inline'><input type='checkbox' name='act_rang_ext[]' value='" + rangId + "' checked='true' /> " + rangName + "</label>&nbsp;&nbsp;";
	  	}
	}
}
/**
 * 搜索商品
 */
function searchgoods(){
	var query= new Object();
	query.keyword =$('#keyword').val();
	query.is_pt =$('#is_pt').val();
	$.ajax({
		type: "GET",
		url: APP+"Shop/Promot/ajaxgetgoods.html",
		data: query,
		success: function(data){
			$("#goods_id").html(data.list);
		}
	});
}
/**
 * 添加活动
 */
function add_promot(){
	var query= new Object();
	query = $("form[name='myform']").serialize();
	$.ajax({
		type: "post",
		url: APP+"Shop/Promot/insert_promot.html",
		data: query,
		success: function(data){
			if(data.status==1){
				$.showSuccess(data.info,0,'hc');
				window.location.href=data.url;
			}else{
				$.showErr(data.info,0,'hc');
			}
		}
	});
}
/**
 * 修改活动
 */
function edit_promot(){
	var query= new Object();
	query = $("form[name='myform']").serialize();
	$.ajax({
		type: "post",
		url: APP+"Shop/Promot/update_promot.html",
		data: query,
		success: function(data){
			if(data.status==1){
				$.showSuccess(data.info,0,'hc');
				window.location.href=data.url;
			}else{
				$.showErr(data.info,0,'hc');
			}
		}
	});
}
/*添加拼团活动*/
function add_fight_group(){
	var act_name = $('#act_name').val();
	if(act_name == 0){
		$.showErr('请输入活动名称',0,'hc');
		return false;
	}
	var act_range_ext = $('#act_range_ext').html();
	if(act_range_ext == ''){
		$.showErr('请选择商品',0,'hc');
		return false;
	}
	var group_number = $('#group_number').val();
	if(group_number == 0){
		$.showErr('请输入拼团人数',0,'hc');
		return false;
	}
	if(group_number < 2){
		$.showErr('拼团人数最少为2人',0,'hc');
		return false;
	}
	var group_time_limit = $('#group_time_limit').val();
	if(group_time_limit == 0){
		$.showErr('请输入有效时间',0,'hc');
		return false;
	}
	if(group_time_limit < 1){
		$.showErr('最短时间为1小时',0,'hc');
		return false;
	}
	var start_time = $('#start_time').val();
	var end_time = $('#end_time').val();
	if(start_time == '' || end_time == ''){
		$.showErr('请选择拼团时间',0,'hc');
		return false;
	}
	var query= new Object();
	query = $("form[name='myform']").serialize();
	$.ajax({
		type: "post",
		url: APP+"Shop/Promot/add_fight_group.html",
		data: query,
		success: function(data){
			if(data.status==1){
				$.showSuccess(data.info,0,'hc');
				window.location.href=data.url;
			}else{
				$.showErr(data.info,0,'hc');
			}
		}
	});
}
function edit_fight_group(){
	var act_name = $('#act_name').val();
	if(act_name == 0){
		$.showErr('请输入活动名称',0,'hc');
		return false;
	}
	var act_range_ext = $('#act_range_ext').html();
	if(act_range_ext == ''){
		$.showErr('请选择商品',0,'hc');
		return false;
	}
	var group_number = $('#group_number').val();
	if(group_number == 0){
		$.showErr('请输入拼团人数',0,'hc');
		return false;
	}
	if(group_number < 2){
		$.showErr('拼团人数最少为2人',0,'hc');
		return false;
	}
	var group_time_limit = $('#group_time_limit').val();
	if(group_time_limit == 0){
		$.showErr('请输入成团时间',0,'hc');
		return false;
	}
	if(group_time_limit < 1){
		$.showErr('最短成团时间为1小时',0,'hc');
		return false;
	}
	var start_time = $('#start_time').val();
	var end_time = $('#end_time').val();
	if(start_time == '' || end_time == ''){
		$.showErr('请选择拼团时间',0,'hc');
		return false;
	}
	
	var query= new Object();
	query = $("form[name='myform']").serialize();
	$.ajax({
		type: "post",
		url: APP+"Shop/Promot/edit_fight_group.html",
		data: query,
		success: function(data){
			if(data.status==1){
				$.showSuccess(data.info,0,'hc');
				window.location.href=data.url;
			}else{
				$.showErr(data.info,0,'hc');
			}
		}
	});
}


