function loadDateList(){
	$.ajax({
 		url: "../ajax/commonAjaxAction!serverDate.action",
		type: 'post',
		dataType: 'json',
		timeout: 200000,
		data:{
		},
		error: function(){},
		success: getDateSuccess
	});
}

function showDiv()
{
	closeCity();
	var flag = document.getElementById("mydiv").style.display;
	if(flag=='none'){
		openDiv();
	}else{
		closeDiv();
	}
}

function closeDiv()
{
	$("#mydiv").fadeOut("slow",function(){
		clearDate();
	});
}

function openDiv()
{
	loadDateList();
	$("#mydiv").fadeIn("slow",function(){
		
	});	
}

function clearDate(){
	$("#mydiv").html("");
}

function getDateSuccess(json)
{
	var dateList = json.dateMap;
	var op  = "<div id='top'><div class='month'>最近配送日期</div><div class='btn'><a onclick='closeDiv()'><img src='../imagesnew/city/del.gif' width='16' height='16' /></a></div></div>";
	op  += "<ul>";
	i = 1;
	for(var k in dateList)
	{
     		// 使用w3c标准语法为select添加option
     		var date = formatStr(dateList[k]);
     		if(dateList[k].indexOf('/')!=-1)
         	{
     			op +=  "<li><a href='javascript:addLaraessDate(\""+date+"\")' class='show'>"+dateList[k]+"</a></li>";
     		}else
         	{
				op +=  "<li><a href='javascript:addLaraessDate(\""+date+"\")' >"+dateList[k]+"</a></li>";
         	}
			if(i%4 == 0)
			{
				op+="<br/>"
			}
			i++;
	} 
	op  += "<li><a class='day' href='javascript:addLaraessDate(\"\")' >不限礼品配送日期</a></li>";
	op  += "</ul>";
	op  += "<div class=‘mymore’><a style='font-weight:bold;' href='javascript:monthDateList(null,null,null)'>更多配送日期</a></div>";
	op  += "<div class=‘cc’></div>";
	$("#mydiv").html(op);
}

function monthDateList(type,month,year)
{
	$.ajax({
 		url: "../ajax/commonAjaxAction!serverMonthDate.action",
		type: 'post',
		dataType: 'json',
		timeout: 200000,
		data:{
			type:type,
			year:year,
			month:month
		},
		error: function(){alert(1111);},
		success: getMonthDateSuccess
		});
}

function getMonthDateSuccess(json)
{
	var dateList = json.dateMap;
	var month = json.month;
	var year = json.year;
	$("#mydiv").html("");
	var op  = "<div id='top'><div class='month'><a href='javascript:monthDateList(\"up\",\""+month+"\",\""+year+"\")'> << 上一月 </a><a href='javascript:monthDateList(\"down\",\""+month+"\",\""+year+"\")'> 下一月 >> </a></div><div class='btn'><a onclick='closeDiv()'><img src='../images/del.gif' width='16' height='16' /></a></div></div>";
	op  += "<ul>";
	i = 1;
	for(var k in dateList)
	{
   		// 使用w3c标准语法为select添加option
   		var date = formatStr(dateList[k]);
   		if(dateList[k].indexOf('/')!=-1)
       	{
   			op +=  "<li><a href='javascript:addLaraessDate(\""+date+"\")' class='show'>"+dateList[k]+"</a></li>";
   		}else
       	{
   			op +=  "<li><a href='javascript:addLaraessDate(\""+date+"\")'>"+dateList[k]+"</a></li>";
       	}
		if(i%4 == 0)
		{
			op+="<br/>"
		}
		i++;
	} 
	alert(op);
	op  += "</ul>";
	op  += "<div class=‘mymore’><a style='font-weight:bold;' href='javascript:loadDateList()'>返回最近配送日期</a></div>";
	op  += "<div class=‘cc’></div>";
	$("#mydiv").html(op);
}


function addLaraessDate(value)
{
	var valuedate = formatStr2(value);
	// 使用AJAX处理区域session
	$.ajax({
 		url: "../ajax/locationAjaxAction!addSessionLargessDate.action",
		type: 'post',
		dataType: 'json',
		timeout: 20000,
		data:{
		largessDate:valuedate
		},
		error: function(){},
		success: addLaraessDateSuccess
	});
}

function addLaraessDateSuccess(json){
	//alert("susscee");
	var largessDate = json.largessDate;
	if(largessDate==''){
		$("#show_date").html("不限礼品配送日期");
	}else{
		$("#show_date").html(largessDate);
	}	
	closeDiv();
	
	// 根据 执行的方法，来判断，进入 哪个查询
	var methodFlag = $("#methodFlag").val();
	//alert(methodFlag);
	if(methodFlag=='queryProduct')
	{
		//alert("进入queryProduct");
		searchByType('','','','');
	}
	else if(methodFlag =='queryProductByAllType')
	{
		//alert("进入queryProductByAllType");
		queryProductByAllType();
	}
	else
	searchByType('','','','');
}

function formatStr(str)
{ 
	str=str.replace("年","&"); 
	str=str.replace("月","#"); 
	str=str.replace("日","@"); 
	return str; 
}
function formatStr1(str)
{ 
	if(str == ""|| str == null)
	{
		return "不限礼品配送日期";
	}
	str=str.replace("&","年"); 
	str=str.replace("#","月"); 
	str=str.replace("@","日"); 
	return str; 
}

function formatStr2(str)
{ 
	if(str == "")
	{
		return str;
	}
	str=str.replace("&","-"); 
	str=str.replace("#","-"); 
	str=str.replace("@",""); 
	return str; 
}
