////////////////////////////////////////
// SSL ÀÎÁõ 
var locationProtocol = document.location.protocol + "//";
////////////////////////////////////////

function CImpression() {}
CImpression.setGlobalCookie = function(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	if( (name + "=" + escape(value)).length <= 4000 )
		document.cookie = curCookie;
	else if(confirm("Cookie exceeds 4KB and will be cut!"))
		document.cookie = curCookie;
}

CImpression.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)));
}

CImpression.setPCID = function() {
	var now = new Date();
	var expires = new Date();
	expires.setUTCFullYear( expires.getUTCFullYear() + 10 );

	if (location.hostname.substring((location.hostname.length > 13) ? (location.hostname.length - 14) : 0, location.hostname.length) == ".auction.co.kr")
		CImpression.setGlobalCookie("pcid", now.getTime(), expires, "/", ".auction.co.kr");
	else
		CImpression.setGlobalCookie("pcid", now.getTime(), expires, "/", null);
}

CImpression.chkNaturalSearch = function() {
	var referrer = document.referrer;

	if (referrer.length > 0) {
		if (referrer.indexOf("://") > 0) {
			referrer = referrer.substring(referrer.length, referrer.indexOf("://") + 3);
		}
		else {
			referrer = referrer;
		}
		referrer = referrer.substring(referrer.indexOf("/"), 0);
		if ((referrer != "www.auction.co.kr") && (referrer != "auction.co.kr"))
			return referrer;
		else return "";
	}
	return "";
}

CImpression.sendWebLog = function() {
	if ((CImpression.getCookie("pcid") == null) || (CImpression.getCookie("pcid").substring(0, 3) == "AAP") || (CImpression.getCookie("pcid").length > 15)) CImpression.setPCID();
	//À¥·Î±× ºÐ¼® ¿ë: setPCID() ¸ÕÀú Call ÇÊ¼ö
	
	//À¥·Î±× ¼­¹ö http ¿äÃ»Àº implog3 https ¿äÃ»Àº implog1À¸·Î º¯°æÇÔ.
	var strText = "";
	if (locationProtocol == "http://") { 		
	  strText = "<table cellpadding=0 cellspacing=0 style='display:none;'><tr><td><img src=\"" + locationProtocol + "implog3.auction.co.kr/common/weblog.asp?cu=" + encodeURI(location.href)  + "&referrer=" + CImpression.chkNaturalSearch() + "\"  width=0 height=0 border=0></td></tr></table>";	  
//		document.write("<table cellpadding=0 cellspacing=0 style='display:none;'><tr><td><img src='" + locationProtocol + "implog3.auction.co.kr/common/weblog.asp?cu=" + encodeURI(location.href)  + "&referrer=" + CImpression.chkNaturalSearch() + "'  width=0 height=0 border=0></td></tr></table>");
	} else {
	  strText = "<table cellpadding=0 cellspacing=0 style='display:none;'><tr><td><img src=\"" + locationProtocol + "implog1.auction.co.kr/common/weblog.asp?cu=" + encodeURI(location.href)  + "&referrer=" + CImpression.chkNaturalSearch() + "\"  width=0 height=0 border=0></td></tr></table>";
//		document.write("<table cellpadding=0 cellspacing=0 style='display:none;'><tr><td><img src='" + locationProtocol + "implog1.auction.co.kr/common/weblog.asp?cu=" + encodeURI(location.href)  + "&referrer=" + CImpression.chkNaturalSearch() + "'  width=0 height=0 border=0></td></tr></table>");
	}
	document.write(strText);
}

CImpression.sendWebLog();