﻿/* 전체지역보기 */
var entireAreaToday;
var strToday;
function onViewEntireAreaTodayMaking(backFoward) {
	if (entireAreaToday == null) {
		entireAreaToday = new Date();
	}
	entireAreaToday.setDate(entireAreaToday.getDate() + backFoward);

	if (entireAreaToday >= new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())) {
		$("#aViewEntireNext").attr("href", "#");
		$("#aViewEntireNext > img").attr("src", "/images/common/mMonth_next.gif").attr("alt", "다음달");
	}
	else {
		$("#aViewEntireNext").attr("href", "javascript:onViewEntireAreaTodayMaking(1);");
		$("#aViewEntireNext > img").attr("src", "/images/common/mMonth_next_on.gif").attr("alt", "다음달");
	}
	
	strToday = (entireAreaToday.getFullYear() + "").padLeft(4, "0")
				+ (entireAreaToday.getMonth() + 1 + "").padLeft(2, "0")
				+ (entireAreaToday.getDate() + "").padLeft(2, "0");
	//alert(strToday);

	$("#imgEntire1").attr("src", "/images/common/mYear_" + strToday.substr(0, 1) + ".gif").attr("alt", strToday.substr(0, 1));
	$("#imgEntire2").attr("src", "/images/common/mYear_" + strToday.substr(1, 1) + ".gif").attr("alt", strToday.substr(1, 1));
	$("#imgEntire3").attr("src", "/images/common/mYear_" + strToday.substr(2, 1) + ".gif").attr("alt", strToday.substr(2, 1));
	$("#imgEntire4").attr("src", "/images/common/mYear_" + strToday.substr(3, 1) + ".gif").attr("alt", strToday.substr(3, 1));
	$("#imgEntire5").attr("src", "/images/common/mMonth_" + strToday.substr(4, 1) + ".gif").attr("alt", strToday.substr(4, 1));
	$("#imgEntire6").attr("src", "/images/common/mMonth_" + strToday.substr(5, 1) + ".gif").attr("alt", strToday.substr(5, 1));
	$("#imgEntire7").attr("src", "/images/common/mMonth_" + strToday.substr(6, 1) + ".gif").attr("alt", strToday.substr(6, 1));
	$("#imgEntire8").attr("src", "/images/common/mMonth_" + strToday.substr(7, 1) + ".gif").attr("alt", strToday.substr(7, 1));

	WJPRON.Web.WS.CommonService.GetEntireAreaTodayMakingJsonData(strToday,
																onGetEntireAreaTodayCompleted,
																onGetEntireAreaTodayFailed);
}

function getJsonObject(json) {
	var jsonObj = $.parseJSON(json);
	return jsonObj;
}

function onGetEntireAreaTodayCompleted(result) {
	if (result != null) {
		
		var isToday = true;
		var tempDate1 = new Date();
		if (strToday != (tempDate1.getFullYear() + "").padLeft(4, "0")
						+ (tempDate1.getMonth() + 1 + "").padLeft(2, "0")
						+ (tempDate1.getDate() + "").padLeft(2, "0")) {
			isToday = false;
		}

		var jsonObj = getJsonObject(result);
		var queryString;
	
		for (var i=1; i <= jsonObj.Rows.length; i++) {
			if (i == 1) {
				if (jsonObj.Rows[i - 1].FAMILYDAY_YN == "N")
					$("#spanFamilyDay").hide();
				else
					$("#spanFamilyDay").show();
			}


			if (isToday) {
			    queryString = "/Index.aspx?AreaSeqNo=" + jsonObj.Rows[i - 1].AREA_SEQ_NO;
			    
			} else {
			    queryString = "/Index.aspx?PdtSeqNo=" + jsonObj.Rows[i - 1].PDT_SEQ_NO;
			}
				
			$("#liEntireArea" + i).removeClass("comming");
			$("#liEntireArea" + i).html("<div class='placeList'><p class='tle'></p><p class='pic'></p><div class='gPrice'></div></div><p class='placeName'></p>");
			$("#liEntireArea" + i + " > div.placeList > p.tle")
				.html("[" + jsonObj.Rows[i - 1].AREA_NM + "] <strong>" + cutOffString(jsonObj.Rows[i - 1].PRD_NM, 23, false) + "</strong>");
			$("#liEntireArea" + i + " > div.placeList > p.pic")
				.html("<a href='" + queryString + "'><img src='/Upload/Product/" + jsonObj.Rows[i - 1].THUMBNAIL_ULD_FILE_NM + "' alt='" + jsonObj.Rows[i - 1].PRD_MAIN_COPY + "' /></a>");
			$("#liEntireArea" + i + " > div.placeList > div.gPrice")
				.html("<span class='sale'>" + jsonObj.Rows[i - 1].DC_RT + "% 할인</span> <span class='pri'><strike>" + convertCurrencyType(jsonObj.Rows[i - 1].ORG_AMT) + "</strike><br />" + convertCurrencyType(jsonObj.Rows[i - 1].SALE_AMT) + "</span>");
			$("#liEntireArea" + i + " > p.placeName")
				.html("<a href='" + queryString + "'><img src='/Upload/Misc/" + jsonObj.Rows[i - 1].AREA_IMG_FILE_NM + "' class='png24' alt='" + jsonObj.Rows[i - 1].AREA_NM + "' /></a>");
		}
		
		for (j = i; j <= 5; j++) {
			$("#liEntireArea" + j).addClass("comming");
			$("#liEntireArea" + j).html("<img src='/images/common/comingSoon.png' class='png24' alt='common soon' />");
		}
	}
}

function onGetEntireAreaTodayFailed(result) {
	alert("오류로 인해 처리하지 못했습니다.\n오류내용 : " + result.get_message());
}
