function AdLog() {}

AdLog.SetAdCookie = function(value) {
	var name = "adCode";
	var cookieValue = AdLog.GetCookie("AGP");
	var arr = "";
	var rtnSetCookieValue = "";
	if(cookieValue != null) { 
		arr = cookieValue.split("&");
	} 
	for(var i = 0; i < arr.length; i++) { 
		subArr = arr[i].split("=");
		if(subArr.length > 0) { 
			if(subArr[0] != name) { 
				rtnSetCookieValue += subArr[0] + "=" + ((subArr[1] != null) ? escape(subArr[1]) : "") + "&";
			} 
		} 
	} 
	rtnSetCookieValue = rtnSetCookieValue + name + "=" + escape(value);
	AdLog.SetGlobalCookie("AGP", rtnSetCookieValue, "", "/", ".auction.co.kr", "");
	return 1;
}

AdLog.GetCookie = function(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
		return (null);
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
	return (unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)));
}

AdLog.SetGlobalCookie = function(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + value + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	if( (name + "=" + value).length <= 4000 )
		document.cookie = curCookie;
	else if(confirm("Cookie exceeds 4KB and will be cut!"))
		document.cookie = curCookie;
}

function adLog(loggingUrl, adSeqnoForCookie) {
	if (loggingUrl == null || loggingUrl == "") return false;

	var iframeControl = document.getElementById("iframeAdLogDynamic");

	if (adSeqnoForCookie != null && adSeqnoForCookie > 0) AdLog.SetAdCookie(adSeqnoForCookie);

	try {
		if (iframeControl == null) {
			iframeControl = document.createElement("iframe");

			iframeControl.setAttribute("id", "iframeAdLogDynamic");
			iframeControl.setAttribute("width", "0");
			iframeControl.setAttribute("height", "0");
			iframeControl.setAttribute("hspace", "0");
			iframeControl.setAttribute("vspace", "0");
			iframeControl.setAttribute("marginwidth", "0");
			iframeControl.setAttribute("marginheight", "0");
			iframeControl.setAttribute("scrolling", "no");
			iframeControl.setAttribute("frameborder", "0");

			document.body.appendChild(iframeControl);
		}

		iframeControl.setAttribute("src", loggingUrl);
		return true;
	} catch (ex) { return false; }
}
