// Server Properties
var DIG_Server = "clamo.macpert.com";
var DIG_Page = "/CLAMO_WINGLISH.do";

// Site Prop.
var DIG_SiteID = "20";

//var DIG_InfoKind = "DIG AD";
var DIG_InfoKind = "ALL";

// AD Prop.
//var DIG_AD = false;
var DIG_AD_DELI = "macpert_ad_id";
//var DIG_AD_DELI2 = "channel_name=keyword";

// Page Prop.
var DIG_isData = false;
 
// Cookie Name
var DIG_VisitorCookie = "DIG_" + DIG_SiteID + "_VISITOR";
var DIG_VisitCookie = "DIG_" + DIG_SiteID + "_VISIT";
var DIG_PreAdcodeCookie = "DIG_" + DIG_SiteID + "_PreAdcode";

// Cookie
var DIG_Cookie_Expire = 30;

// get Unique Number
function DIG_getUniqNum() {
	var currentTime = DIG_getCurrentTime() + "";
	var randNum = Math.floor(Math.random() * 100000) + "";
	if (randNum.length == 1) {
		randNum = "0000" + randNum;
	} else {
		if (randNum.length == 2) {
			randNum = "000" + randNum;
		} else {
			if (randNum.length == 3) {
				randNum = "00" + randNum;
			} else {
				if (randNum.length == 4) {
					randNum = "0" + randNum;
				}
			}
		}
	}
	return currentTime + "" + randNum;
}

// get Current Time
function DIG_getCurrentTime() {
	var today = new Date();
	var year = today.getFullYear() + "";
	var month = (today.getMonth() + 1) + "";
	var day = today.getDate() + "";
	var hour = today.getHours() + "";
	var min = today.getMinutes() + "";
	var second = today.getSeconds() + "";
	var millisecond = today.getMilliseconds() + "";
	if (month.length == 1) {
		month = "0" + month;
	}
	if (day.length == 1) {
		day = "0" + day;
	}
	if (hour.length == 1) {
		hour = "0" + hour;
	}
	if (min.length == 1) {
		min = "0" + min;
	}
	if (second.length == 1) {
		second = "0" + second;
	}
	if (millisecond.length == 1) {
		millisecond = "00" + millisecond;
	} else {
		if (millisecond.length == 2) {
			millisecond == "0" + millisecond;
		}
	}
	
	return year + month + day + hour + min + second + millisecond + "";
}

// set Cookie
function DIG_setCookie(name, value, expire) {
	var today = new Date();
	today.setDate(today.getDate() + parseInt(expire));
	if (expire == 0) {
		document.cookie = name + "=" + escape(value) + ";path=/;";
	} else {
		document.cookie = name + "=" + escape(value) + ";path=/;expires=" + today.toGMTString() + ";";
	}
}

// get Cookie
function DIG_getCookie(name) {
	var cookieName = name + "=";
	var x = 0;
	while (x <= document.cookie.length) {
		var y = (x + cookieName.length);
		if (document.cookie.substring(x, y) == cookieName) {
			if ((endOfCookie = document.cookie.indexOf(";", y)) == -1) {
				endOfCookie = document.cookie.length;
			}
			return unescape(document.cookie.substring(y, endOfCookie));
		}
		x = document.cookie.indexOf(" ", x) + 1;
		if (x == 0) {
			break;
		}
	}
	return "";
}
function DIG_getParameter(name) {
	var paraName = name + "=";
	var URL = "" + self.document.location.search;
	var tURL = "";
	eval("try{ tURL=top.document.location.search; }catch(_e){}");
	URL = URL + "&" + tURL;
	if (URL.indexOf(paraName) != -1) {
		var x = URL.indexOf(paraName) + paraName.length;
		var y = URL.substr(x).indexOf("&");
		if (y != -1) {
			return URL.substring(x, x + y);
		} else {
			return URL.substr(x);
		}
	}
	return "";
}

function DIG_escapeStr(_str) {
	var str, ch;
	var bEncURI = "N";
	eval("try{bEncURI=encodeURI('O');}catch(_e){ }");
	if (bEncURI == "O") {
		str = encodeURI(_str);
	} else {
		str = escape(_str);
	}
	str = str.split("+").join("%2B");
	str = str.split("/").join("%2F");
	str = str.split("&").join("%26");
	str = str.split("?").join("%3F");
	str = str.split(":").join("%3A");
	str = str.split("#").join("%23");
	return str;
}


function DIG_makeURL() {
	var rp = self.document.referrer;		// 
	var trp = "";
	eval("try{trp = top.document.referrer;}catch(e){}");
	var tcp = "";
	eval("try{tcp = top.document.location.href;}catch(e){}");
	var bFrm = false;
	if (rp == tcp) {
		rp = trp;
		bFrm = true;
	}
	if (rp == "undefined") {
		rp = "";
	}
	var cp = self.document.location.href;
	if (cp.substr(0, 4) == "file") {
		return "";
	}
	var DIG_VISITOR = DIG_getCookie(DIG_VisitorCookie);
	if (DIG_VISITOR == "undefined" || DIG_VISITOR == "" || DIG_VISITOR == null) {
		DIG_VISITOR = DIG_getCookie(DIG_VisitorCookie);
	}
	var DIG_VISIT = DIG_getCookie(DIG_VisitCookie);
	if (DIG_VISIT == "undefined" || DIG_VISIT == "" || DIG_VISIT == null) {
		DIG_VISIT = DIG_getCookie(DIG_VisitCookie);
	}
	
	//°¡ÀåÃÖ±Ù±¤°íÄÚµå
	var DIG_PREADCODE = DIG_getCookie(DIG_PreAdcodeCookie);
	if (DIG_PREADCODE == "undefined" || DIG_PREADCODE == "" || DIG_PREADCODE == null) {
		DIG_PREADCODE = DIG_getCookie(DIG_PreAdcodeCookie);
	}
	if (DIG_PREADCODE == "undefined" || DIG_PREADCODE == "" || DIG_PREADCODE == null) {
		DIG_PREADCODE = "";
	}
	

	// ÇöÀçÀ¯ÀÔ±¤°íÄÚµå
	var DIG_ADCODE = DIG_getParameter(DIG_AD_DELI);
	if (DIG_ADCODE == null || DIG_ADCODE == "undefined") {
		DIG_ADCODE = "";
	}
	if (DIG_InfoKind == "DIG AD") {
		if (cp.toLowerCase().indexOf(DIG_AD_DELI) > 0) {		// case same session
			DIG_isData = true;
			if (DIG_VISITOR == "undefined" || DIG_VISITOR == "" || DIG_VISITOR == null) {			// not exist VisitorID
				DIG_VISITOR = DIG_getUniqNum();
				DIG_VISIT = DIG_VISITOR;
				DIG_setCookie(DIG_VisitorCookie, DIG_VISITOR, DIG_Cookie_Expire);
				DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);
				
				// ÃÖ±Ù ±¤°í °ªÀ» ÄíÅ°¿¡ ÀúÀå
				// ÃÖÃÊ ¹æ¹® & cp¿¡¼­ °ªÀ» ¶â¾î¼­ ÀúÀå
				DIG_setCookie(DIG_PreAdcodeCookie, DIG_ADCODE, DIG_Cookie_Expire);
			} else {			// exist VisitorID
				DIG_setCookie(DIG_VisitorCookie, DIG_VISITOR, DIG_Cookie_Expire);
				/*
				if (DIG_VISIT == "undefined" || DIG_VISIT == "" || DIG_VISIT == null ) {			// not exist VisitID
					DIG_VISIT = DIG_getUniqNum();
					DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);
				}
				*/
				DIG_VISIT = DIG_getUniqNum();
				DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);


				// ÃÖ±Ù ±¤°í °ªÀ» ÄíÅ°¿¡ ÀúÀå(°»½Å)
				DIG_setCookie(DIG_PreAdcodeCookie, DIG_ADCODE, DIG_Cookie_Expire);
			}
		} else {				// not same session
			if (DIG_VISITOR == "undefined" || DIG_VISITOR == "" || DIG_VISITOR == null) {			// not exist VisitorID
				DIG_isData = false;
				return "";
			} else {			// exist VisitorID
				if (DIG_VISIT == "undefined" || DIG_VISIT == "" || DIG_VISIT == null) {
					DIG_setCookie(DIG_VisitorCookie, DIG_VISITOR, DIG_Cookie_Expire);
					DIG_VISIT = DIG_getUniqNum();
					DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);

					// ÄíÅ°¿¡¼­ ÀÐÀº ÃÖ±Ù±¤°í °ªÀ» °»½ÅÇÑ´Ù
					DIG_setCookie(DIG_PreAdcodeCookie, DIG_PREADCODE, DIG_Cookie_Expire);
					DIG_isData = true;
				}
			}
		}
	} else {			// not 'DIG AD' but 'ALL'
		if (DIG_VISIT == "undefined" || DIG_VISIT == "" || DIG_VISIT == null) {			// not exist VisitID
			DIG_isData = true;
			if (DIG_VISITOR == "undefined" || DIG_VISITOR == "" || DIG_VISITOR == null) {			// not exist VisitorID
				DIG_VISITOR = DIG_getUniqNum();
				DIG_VISIT = DIG_VISITOR;
				DIG_setCookie(DIG_VisitorCookie, DIG_VISITOR, DIG_Cookie_Expire);
				DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);

				// Ã³À½¹æ¹®ÀÏ °æ¿ì ÇöÀç±¤°í ÄÚµå°ªÀ» ÃÖ±ÙÄÚµåÄíÅ°°ª¿¡ ÀúÀå
				DIG_setCookie(DIG_PreAdcodeCookie, DIG_ADCODE, DIG_Cookie_Expire);
			} else {			// exist VisitorID
				DIG_setCookie(DIG_VisitorCookie, DIG_VISITOR, DIG_Cookie_Expire);
				if (DIG_VISIT == "undefined" || DIG_VISIT == "" || DIG_VISIT == null) {				// not exist VisitID
					DIG_VISIT = DIG_getUniqNum();
					DIG_setCookie(DIG_VisitCookie, DIG_VISIT, 0);

					// ±¤°íÀ¯ÀÔÀÏ °æ¿ì´Â ÇöÀç ±¤°íÄÚµå¸¦ °»½Å
					if (cp.toLowerCase().indexOf(DIG_AD_DELI) > 0) {
						DIG_setCookie(DIG_PreAdcodeCookie, DIG_ADCODE, DIG_Cookie_Expire);						
					// ±¤°íÀ¯ÀÔÀÌ ¾Æ´Ò°æ¿ì ÀÌÀü±¤°íÄíÅ°¿¡¼­ °ªÀ» ÀúÀå
					} else {
						DIG_setCookie(DIG_PreAdcodeCookie, DIG_PREADCODE, DIG_Cookie_Expire);
					}
				}
			}
		}
	}
	if (!rp) {
		rp = "";
	}
	if (!cp) {
		cp = "";
	}
	var t_url = "";
	var prtc = document.location.protocol.indexOf("https") != -1 ? "https://" : "http://";
	t_url = t_url + prtc + DIG_Server + DIG_Page;
	t_url = t_url + "?siteid=" + DIG_SiteID;					// ??? ID
	t_url = t_url + "&visitorid=" + DIG_VISITOR;
	t_url = t_url + "&visitid=" + DIG_VISIT;
	t_url = t_url + "&adcodeid=" + DIG_ADCODE;
	t_url = t_url + "&preadcodeid=" + DIG_PREADCODE;
	t_url = t_url + "&referrerpage=" + DIG_escapeStr(rp);			// 
	t_url = t_url + "&currentpage=" + DIG_escapeStr(cp);			//  
	if ((typeof TP) != "undefined" && TP.length != 0) {
//		t_url = t_url + "&targetpage=" + DIG_escapeStr(TP);			// 
		t_url = t_url + "&targetpage=" + TP;			// 
		DIG_isData = true;
	}
	if ((typeof SX) != "undefined" && SX.length != 0) {
		t_url = t_url + "&gender=" + SX;
		DIG_isData = true;
	}
	if ((typeof AG) != "undefined" && AG.length != 0) {
		t_url = t_url + "&age=" + AG;
		DIG_isData = true;
	}
	if ((typeof RG) != "undefined" && RG.length != 0) {
		t_url = t_url + "&region=" + RG;
		DIG_isData = true;
	}
	if ((typeof PN) != "undefined" && PN.length != 0) {
		t_url = t_url + "&pagename=" + PN;
		DIG_isData = true;
	}
	if ((typeof IK) != "undefined" && IK.length != 0) {
		t_url = t_url + "&innerkeyword=" + IK;
		DIG_isData = true;
	}
	if ((typeof EP) != "undefined" && EP.length != 0) {
		t_url = t_url + "&exposureproduct=" + EP;
		DIG_isData = true;
	}
	if ((typeof PP) != "undefined" && PP.length != 0) {
		t_url = t_url + "&productname=" + PP;
		if ((typeof OK) != "undefined" && OK.length != 0) {
			if ((typeof OA) != "undefined" && OA.length != 0) {
				DIG_isData = true;
			}
		}
	}
	if ((typeof PE) != "undefined" && PE.length != 0) {
		t_url = t_url + "&productea=" + PE;
		DIG_isData = true;
	}
	if ((typeof PC) != "undefined" && PC.length != 0) {
		t_url = t_url + "&productcost=" + PC;
		if ((typeof PP) != "undefined" && PP.length != 0) {
			if ((typeof OK) != "undefined" && OK.length != 0) {
				if ((typeof OA) != "undefined" && OA.length != 0) {
					DIG_isData = true;
				}
			}
		}
	}
	if ((typeof OK) != "undefined" && OK.length != 0) {			// OrderKey
		t_url = t_url + "&orderkey=" + OK;
		if ((typeof PP) != "undefined" && PP.length != 0) {
			if ((typeof OA) != "undefined" && OA.length != 0) {
				DIG_isData = true;
			}
		}
	}
	if ((typeof PA) != "undefined" && PA.length != 0) {
		t_url = t_url + "&productcategory=" + PA;
		if ((typeof PP) != "undefined" && PP.length != 0) {
			if ((typeof OK) != "undefined" && OK.length != 0) {
				if ((typeof OA) != "undefined" && OA.length != 0) {
					DIG_isData = true;
				}
			}
		}
	}
	if ((typeof MU) != "undefined" && MU.length != 0) {
		t_url = t_url + "&menu=" + MU;
		DIG_isData = true;
	}
	if ((typeof OA) != "undefined" && OA.length != 0) {
		t_url = t_url + "&orderamount=" + OA;
		if ((typeof PP) != "undefined" && PP.length != 0) {
			if ((typeof OK) != "undefined" && OK.length != 0) {
				DIG_isData = true;
			}
		}
	}
	if ((typeof PK) != "undefined" && PK.length != 0) {
		t_url = t_url + "&productdiv=" + PK;
		if ((typeof PP) != "undefined" && PP.length != 0) {
			if ((typeof OK) != "undefined" && OK.length != 0) {
				if ((typeof OA) != "undefined" && OA.length != 0) {
					DIG_isData = true;
				}
			}
		}
	}
	return t_url;
}
var url_base = DIG_makeURL();
var DIG_img = new Image();
var Brws_isMSIE = (document.all) ? true : false;
var Brws_isJS12 = (window.screen) ? true : false;
if (DIG_InfoKind == "DIG AD") {
	if (DIG_isData) {
		if (Brws_isJS12 == true) {
			if (Brws_isMSIE) {
				DIG_img.src = url_base;
			} else {
				setTimeout("DIG_img.src = url_base;", 0);
			}
		} else {
			if (DIG_isMSIE) {
				document.write("<div style=\"display: none\">");
			}
			document.write("<img src=\"" + url_base + "\" height=\"0\" width=\"0\">");
			if (DIG_isMSIE) {
				document.write("</div>");
			}
		}
	}
} else {
	if (DIG_isData) {
		if (Brws_isJS12 == true) {
			if (Brws_isMSIE) {
				DIG_img.src = url_base;
			} else {
				setTimeout("DIG_img.src = url_base;", 0);
			}
		} else {
			if (DIG_isMSIE) {
				document.write("<div style=\"display: none\">");
			}
			document.write("<img src=\"" + url_base + "\" height=\"0\" width=\"0\">");
			if (DIG_isMSIE) {
				document.write("</div>");
			}
		}
	}
}