﻿////////////////////////////////////////
// SSL 인증 
var locationProtocol = document.location.protocol + "//";
////////////////////////////////////////

function CImpressionCafe() {}
CImpressionCafe.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;
}

CImpressionCafe.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)));
}

CImpressionCafe.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")
		CImpressionCafe.setGlobalCookie("pcid", now.getTime(), expires, "/", ".auction.co.kr");
	else
		CImpressionCafe.setGlobalCookie("pcid", now.getTime(), expires, "/", null);
}

CImpressionCafe.getArgs = function() {
	var args = new Object();
	// Get Query String
	var query = location.search.substring(1); 
	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 
		// if not found, skip to next
		if (pos == -1) continue; 
		// Extract the name
		var argname = pairs[i].substring(0,pos); 
		alert(argname);
		// Extract the value
		var value = pairs[i].substring(pos+1); 
		// Store as a property
		args[argname] = unescape(value); 
	}
	return args; // Return the Object
}

CImpressionCafe.getArgsIncludeFrm = function() {
    var frm = "";
	var args = new Object();
	// Get Query String
	var query = location.search.substring(1); 
	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('='); 
		if (pos == -1) continue; 
		var argname = pairs[i].substring(0,pos); 
		if (argname == "frm")
		var value = pairs[i].substring(pos+1); 
		frm = value;
	}
	return frm;
}

CImpressionCafe.getReferer = function(referer, loc) {
    // frm 파라미터를 가지고 올 경우 모든 referer 에 우선한다.
    var frm = CImpressionCafe.getArgsIncludeFrm();
    
    if (frm != "" && frm != null)
        referer = frm + ".auction.co.kr";
    else { // frm 파라미터가 없을 경우 referer 정보를 정재한다.
        var rHost = referer.split("/");
        referer = rHost[2];
    }
    
    // frm 파라미터가 없고, referer 정보도 없을 경우 직접 입력으로 처리한다.
    if (referer == null || referer == "")
        referer = "review.auction.co.kr";
    
	return referer;
}

CImpressionCafe.getFileUri = function(loc) {
    return loc.replace(location.search,"");
}

CImpressionCafe.sendWebLog = function() {
	if ((CImpressionCafe.getCookie("pcid") == null) || (CImpressionCafe.getCookie("pcid").substring(0, 3) == "AAP") || (CImpressionCafe.getCookie("pcid").length > 15)) CImpressionCafe.setPCID();
	//웹로그 분석 용: setPCID() 먼저 Call 필수
	
	var referer = document.referrer;
	var thisLocation = location.href;
	referrer = CImpressionCafe.getReferer(referer,thisLocation);
	var fileUri = CImpressionCafe.getFileUri(thisLocation);
	// 여기서 호출
    document.write("<img src='/Common/WebLog.aspx?pcid=" + CImpressionCafe.getCookie("pcid") +"&referer=" + referrer + "&cu=" + escape(fileUri)  + "'  width=0 height=0 border=0>");
    //document.write("<iframe src='/Common/WebLog.aspx?pcid=" + CImpressionCafe.getCookie("pcid") +"&referer=" + referrer + "&cu=" + escape(fileUri)  + "'  width=100% height=100 border=0></iframe>");
}

CImpressionCafe.sendWebLog();