/**************************************************************************************************
*
*    /mypage/wishlist.asp
*
**************************************************************************************************/

var wishListInit = function () {
	/* ORDER CART LIST CHECKBOX */
	var masterBox = wishForm.masterBox,
		checkBox = wishForm.wishIdx;
	if (masterBox && checkBox) {
		masterBox.onclick = masterBox.onchange = function () {
			if (checkBox.length) {
				for (var i = 0; i < checkBox.length; i++)
					checkBox[i].checked = this.checked;
			} else {
				checkBox.checked = this.checked;
			}
		};
	}

	if (checkBox) {
		if (checkBox.length) {
			for (var i = 0; i < checkBox.length; i++) {
				checkBox[i].onclick = checkBox[i].onchange = function () {
					if (this.checked)
						addClass(this.parentNode.parentNode, "trSelect");
					else
						removeClass(this.parentNode.parentNode, "trSelect");

					for (var i = 0, count = 0, length = checkBox.length; i < length; i++)
						if (checkBox[i].checked)
							count ++;
					masterBox.checked = (checkBox.length != count) ? false : true;
				};
				addEvent(checkBox[i], "focus", linkBlur);
			}
		} else {
			checkBox.onclick = checkBox.onchange = function () {
				masterBox.checked = checkBox.checked;
			};
			addEvent(checkBox, "focus", linkBlur);
		}
	}

	/* ORDER CART LIST DELETE */	
	var wishList = document.getElementById("mypage_wishList"),
		a = wishList.getElementsByTagName("A");
	if (a && a.length > 0) {
		for (i = 0; i < a.length; i++) {
			if (i > 0 && !((i + 1) % 3)) {
				a[i].onclick = function () {
					var productName = this.parentNode.parentNode.getElementsByTagName("A")[1].innerHTML;
					if (!confirm("\"" + productName.replace(/<[^>]+>/g, "") + "\" »óÇ°À» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?      "))
						return false;
					loading("mypage_wishList");
					Async.send("/common/async/mypage_wish_delete.asp", function (send_) {
						setTimeout(function () {
							insertNodes("mypage_wishList", send_.responseText, wishListInit);
						}, random(300, 500));
					}, getQueryString(this.href));
					return false;
				};
			}
			addEvent(a[i], "focus", linkBlur);
		}
	}

	var paging = document.getElementById("wish_paging");
	if (paging) {
		a = paging.getElementsByTagName("A");
		for (i = 0; i < a.length; i++) {
			a[i].onclick = function () {
				loading("mypage_wishList");
				Async.send("/common/async/mypage_wishlist.asp", function (send_) {
					setTimeout(function () {
						insertNodes("mypage_wishList", send_.responseText, wishListInit);
					}, random(300, 500));
				}, getQueryString(this.href))
				return false;
			};
		}
	}

	sideRefresh();
};

var wishForm = document.getElementById("wishForm");
if (wishForm) {
	wishForm.onsubmit = function () {
		var checkBox = this.wishIdx,
			count = 0;
		if (!checkBox) {
			alert("ÀÌµ¿ÇÒ ¸ñ·ÏÀÌ ¾ø½À´Ï´Ù.      ");
			return false;
		}
		if (checkBox.length) {
			for (var i = 0; i < checkBox.length; i++)
				if (checkBox[i].checked)
					count ++;
		} else if (checkBox.checked) {
				count ++;
		}
		if (!count) {
			alert("Àå¹Ù±¸´Ï·Î ÀÌµ¿ÇÒ ¸ñ·ÏÀ» ¼±ÅÃ ÇØÁÖ¼¼¿ä!!      ");
			this.masterBox.focus();
			return false;
		}
		location.hash = "#cartFocus";
		loading("order_cartList");
		Async.send("/common/async/mypage_wish_to_cart.asp", function (send_) {
			setTimeout(function () {
				insertNodes("order_cartList", send_.responseText, cartListInit);
			}, random(300, 500));
		}, formQueryString(this));
		return false;
	};
	wishListInit();
}

var a = document.getElementById("wishDelete");

if (a) {
	a = a.getElementsByTagName("A")

	a[0].onclick = function () {
		var checkBox = wishForm.wishIdx,
			queryString = "";
		if (!checkBox) {
			alert("»èÁ¦ÇÒ ¸ñ·ÏÀÌ ¾ø½À´Ï´Ù.      ");
			return false;
		}
		if (checkBox.length) {
			for (var i = 0; i < checkBox.length; i++)
				if (checkBox[i].checked)
					queryString += ", " + checkBox[i].value;
		} else {
			queryString = ", " + checkBox.value;
		}
		if (!queryString) {
			alert("»èÁ¦ÇÒ ¸ñ·ÏÀ» ¼±ÅÃ ÇØÁÖ¼¼¿ä!      ");
			checkBox[0].focus();
			return false;
		}
		queryString = "wishIdx=" + escape(queryString.substr(2));
		var conf = confirm("¼±ÅÃ ÇÏ½Å ¸ñ·ÏÀ» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?      ");
		if (conf) {
			loading("mypage_wishList");
			Async.send("/common/async/mypage_wish_delete.asp", function (send_) {
				setTimeout(function () {
					insertNodes("mypage_wishList", send_.responseText, wishListInit);
				}, random(300, 500));
			}, queryString);
		}
		return false;
	};

	a[1].onclick = function () {
		var checkBox = wishForm.wishIdx,
			checked = false;
		if (!checkBox) {
			alert("»èÁ¦ÇÒ ¸ñ·ÏÀÌ ¾ø½À´Ï´Ù.      ");
			return false;
		}
		checked = wishForm.masterBox.checked = wishForm.masterBox.checked ? false : true;
		if (checkBox.length) {
			for (var i = 0; i < checkBox.length; i++)
				checkBox[i].checked = checked;
		} else {
			checkBox.checked = checked;
		}
		return false;
	};

	a[2].onclick = function () {
		checkBox = wishForm.wishIdx;
		if (!checkBox) {
			alert("»èÁ¦ÇÒ ¸ñ·ÏÀÌ ¾ø½À´Ï´Ù.      ");
			return false;
		}
		if (checkBox.length) {
			for (var i = 0, queryString = ""; i < checkBox.length; i++)
					queryString += ", " + checkBox[i].value;
		} else {
			queryString = ", " + checkBox.value;
		}
		queryString = "wishIdx=" + escape(queryString.substr(2));
		var conf = confirm("ÀüÃ¼ ¸ñ·ÏÀ» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?      ");
		if (conf) {
			loading("mypage_wishList");
			Async.send("/common/async/mypage_wish_delete.asp", function (send_) {
				setTimeout(function () {
					insertNodes("mypage_wishList", send_.responseText, wishListInit);
				}, random(300, 500));
			}, queryString);
		}
		return false;
	};
}

/*******************************************************************************************************/