﻿var imageRoot = "http://image.serakorea.com/Renewal/";

// 좌측 검색어 입력 상자에 이벤트를 적용.
function AddScriptToSearchTextBox()
{
	var leftSearchArea = document.getElementsByName("MK_Search")[0];
	var tbLeftSearch = leftSearchArea.getElementsByTagName("input")[0];
	var btnLeftSearch = leftSearchArea.getElementsByTagName("img")[0];
	
	if (tbLeftSearch)
	{
		tbLeftSearch.onfocus = function()
		{
			this.value = "";
		}
		
		tbLeftSearch.onblur = function()
		{
			if (this.value == "")
			{
				this.value = "검색어를 입력하세요~";
			}
		}
	}
	
	if (btnLeftSearch)
	{
		btnLeftSearch.onclick = function()
		{
			CheckSearchTextBox();
		}
	}
}

// 검색어 입력 상자를 검사.
function CheckSearchTextBox()
{
	var leftSearchArea = document.getElementsByName("MK_Search")[0];
	var tbLeftSearch = leftSearchArea.getElementsByTagName("input")[0];

	if (tbLeftSearch.value == "" || tbLeftSearch.value == "검색어를 입력하세요~")
	{
			alert("검색어를 입력하지 않았습니다.");
	}
	else
	{
		document.forms[0].action = "/Market/ProductList.aspx";
		document.forms[0].submit();
	}
}

// 추천 키워드를 검색어로 입력.
function InputKeywordIntoTextbox(args)
{
	var leftSearchArea = document.getElementsByName("MK_Search")[0];
	var tbLeftSearch = leftSearchArea.getElementsByTagName("input")[0];
	
	if (tbLeftSearch)
	{
		tbLeftSearch.value = args.firstChild.nodeValue;
		CheckSearchTextBox();
	}
}

// 장바구니에서 구매 팝업을 연다.
function buyFromCart(cartId)
{
	openBuyWindow(0, cartId);
}

// 장바구니 외부에서 구매 팝업을 연다.
function buyFromOthers(productId)
{
	openBuyWindow(productId, 0);
}

// 구매 팝업을 연다.
function openBuyWindow(productId, cartId)
{
	window.open("/PopUp/Market/buyitem01.aspx?pid=" + productId + "&cid=" + cartId, "BuyWindow", "width=470, height=560");
}

// 세라 캐시 설명 팝업을 연다.
function openCashHelpWindow()
{
	window.open("/SupportsDoc/about/about_seracash.aspx", "CashHelpWindow", "width=455, height=300");
}

// 세라 쿠폰 설명 팝업을 연다.
function openCouponHelpWindow()
{
	window.open("http://security.serakorea.com/MyFolder/Help/popup_coupon02.aspx", "CouponHelpWindow", "width=450, height=400");
}

addLoadEvent(AddScriptToSearchTextBox);