﻿/*
script name : cpc_script.js
script definition : site check & analysis include
script version : V5
script register : 2009.10.20
script writer : sky (mini0557@nate.com)
*/


if(typeof cpcguard == 'undefined'){

	var cpcguard = new Object();

	cpcguard.complete = /complete|loaded/i;
	cpcguard.binder = {isReady : false, readyList : [], ready : function(log){try{if(!this.isReady){this.isReady = true; if(this.readyList){for(var i =0; i < this.readyList.length; i++){this.readyList[i].call();}this.readyList = null;}}}catch(e){}}}
	cpcguard.loader = {bind : function(binder){try{if(document.addEventListener){ /* Mozilla Firefox || Google Crom || Opera || Safari currently support this event */ document.addEventListener('DOMContentLoaded', function(){binder.ready('DOMContentLoaded'); document.removeEventListener( 'DOMContentLoaded', arguments.callee, false );}, false );}else if(document.attachEvent){/* IE */ document.attachEvent('onreadystatechange', function(){if(cpcguard.complete.test(document.readyState)){document.detachEvent('onreadystatechange', arguments.callee); binder.ready('onreadystatechange');}}); if(window.attachEvent){window.attachEvent('onload', function(){if(cpcguard.complete.test(document.readyState)){document.detachEvent('onload', arguments.callee); binder.ready('onload');}});} if(document.readyState){if(cpcguard.complete.test(document.readyState)){binder.ready('cpcguard.complete ie');}}} (function(){if(!arguments.callee.done && cpcguard.complete.test(document.readyState)){arguments.callee.done = true; binder.ready('cpcguard.complete all');}else{window.setTimeout(arguments.callee, 500);}})();}catch(e){(function(){if(!arguments.callee.done && cpcguard.complete.test(document.readyState)){arguments.callee.done = true; binder.ready('cpcguard.complete error');}else{window.setTimeout(arguments.callee, 500);}})();}}}
	cpcguard.includer = {exist : function(id){try{return document.getElementById(id);}catch(e){return null;}}, include: function(type,url,id,isCacheID,charset,method,time){try{if(this.exist(id)){return true;}(function(){var _head = document.getElementsByTagName('head')[0] || document.documentElement; if(_head){var _script; if(isCacheID){url = (url.indexOf('?') > -1) ? url + '&noCacheIE=' + (new Date()).getTime() :  url + '?noCacheIE=' + (new Date()).getTime();} if(type == 'style'){_script = document.createElement('link'); _script.type='text/css'; _script.rel='stylesheet'; _script.charset= charset || 'utf-8'; _script.href = url; _script.media='screen'; _script.id=id; _script.async = true;}else if(type == 'javascript'){_script = document.createElement('script'); _script.type='text/javascript'; _script.language='javascript'; _script.charset= charset || 'utf-8'; _script.src= url; _script.id=id; _script.async = true;} _script.onload = _script.onreadystatechange = function(){if(!arguments.callee.done && (!this.readyState || cpcguard.complete.test(this.readyState))){arguments.callee.done=true; this.onload = this.onreadystatechange = null; if(method){if(time){window.setTimeout(method,time);}else{window.setTimeout(method,10);}}}}; _head.appendChild(_script);}else{window.setTimeout(arguments.callee, 10);}})(); return true;}catch(e){return false;}}, readystate : function(object,method,time){try{if(object.readyState){object.onreadystatechange = function(){if(!arguments.callee.done && (!this.readyState || cpcguard.complete.test(this.readyState))){arguments.callee.done=true; this.onload = this.onreadystatechange = null; if(method){if(time){window.setTimeout(method,time);}else{method();}}}}}else{object.onload = function(){if(method){if(time){window.setTimeout(method,time);}else{method();}}}}}catch(e){object.onload = function(){if(method){if(time){window.setTimeout(method,time);}else{method();}}}}}}
	cpcguard.ajax = {dynamicQuery: function(url,isCacheID,charset){try{(function(){var _head = document.getElementsByTagName('head')[0] || document.documentElement; if(_head){if(isCacheID){url = (url.indexOf('?') > -1) ? url + '&noCacheIE=' + (new Date()).getTime() :  url + '?noCacheIE=' + (new Date()).getTime();} var _script = document.createElement('script'); _script.type='text/javascript'; _script.charset= charset || 'utf-8'; _script.async = true; _script.src = url; _script.onload = _script.onreadystatechange = function(){if(!arguments.callee.done && (!this.readyState || cpcguard.complete.test(this.readyState))){arguments.callee.done=true; this.onload = this.onreadystatechange = null; _head.removeChild(this);}}; _head.appendChild(_script);}else{window.setTimeout(arguments.callee, 10);}})();}catch(e){}}}
	cpcguard.domain = function(){try{var _domain_list = new Array('.AC.KR', '.ES.KR', '.GO.KR', '.HS.KR', '.KG.KR', '.MS.KR', '.NE.KR', '.NA.TO', '.OR.KR', '.PE.KR', '.SC.KR', '.CO.IN', '.CO.KR', '.CO.CM', '.CO.NZ', '.CO.UK', '.COM.AG', '.COM.CM', '.COM.CN', '.COM.HN', '.COM.KI', '.COM.LC', '.COM.MU', '.COM.MX', '.COM.NF', '.COM.PH', '.COM.PK', '.COM.PL', '.COM.SB', '.COM.SC', '.COM.TW', '.COM.VC', '.COM.VN', '.ORG.CN', '.ORG.HN', '.ORG.IN', '.ORG.KI', '.ORG.LC', '.ORG.LI', '.ORG.MU', '.ORG.NZ', '.ORG.UK', '.NET.AG', '.NET.CN', '.NET.CM', '.NET.HN', '.NET.IN', '.NET.KI', '.NET.LC', '.NET.MU', '.NET.NF', '.NET.NZ', '.NET.PH', '.NET.PK', '.NET.PL', '.NET.SB', '.NET.SC', '.NET.VC', '.FIRM.IN', '.GEN.IN', '.IND.IN', '.ME.UK', '.BIZ.PL', '.INFO.PL', '.ORG.PH', '.ORG.PK', '.ORG.PL', '.ORG.SB', '.ORG.SG', '.ORG.SC', '.ORG.TW', '.ORG.VC', '.CLUB.TW', '.EBIZ.TW', '.GAME.TW', '.IDV.TW', '.COM', '.NET', '.KR', '.MOBI', '.JOBS', '.TRAVEL', '.ORG', '.BIZ', '.INFO', '.TEL', '.ME', '.CN', '.ASIA', '.NAME', '.TV', '.CC', '.JP', '.IN', '.US', '.FR', '.HK', '.EU', '.DE', '.AC', '.AG', '.AM', '.AT', '.BE', '.BZ', '.CH', '.CX', '.CZ', '.ES', '.FM', '.GD', '.GS', '.HN', '.IM', '.IO', '.KI', '.LA', '.LC', '.LU', '.MD', '.MN', '.MS', '.MU', '.NF', '.NU', '.PH', '.PK', '.PL', '.SC', '.SG', '.SH', '.TC', '.TK', '.TM', '.TL', '.TW', '.VC', '.VG', '.WS'); var _domain = document.domain; for(var i = 0; i < _domain_list.length; i++){var _index = _domain.toUpperCase().indexOf(_domain_list[i]); if(_index > 0){var _split = _domain.split('.'); var _length = _split.length; var _domainlength = (_domain_list[i].split('.')).length; if(_domainlength == 3){if(_length > 2){return _split[_length-3] + '.' + _split[_length-2] + '.' +_split[_length-1];}}else if(_domainlength==2){if(_length > 1){return _split[_length-2] + '.' +_split[_length-1];}}}} return _domain;}catch(e){return document.domain;}}
	cpcguard.cookie = {setCookie: function(name,value,domain,expires,path,secure){try{document.cookie = name + '=' +  escape(value) + ((expires == null) ? '' : ('; expires=' + expires.toGMTString())) + ((path == null) ? '; path=/' : ('; path=' + path)) +  ((domain == null) ? '' : ('; domain=' + domain)) + ((secure == true) ? '; secure' : '');}catch(e){}}, getCookie: function(name,defaultValue){try{var _cookies = document.cookie.split('; '); for(var i=0; i < _cookies.length; i++){var args = _cookies[i].split('='); if(name == args[0]){if(args.length==1){return '';}else{return unescape(args[1]);}}} return defaultValue == null ? null : defaultValue;}catch(e){return null;}}, makeCookie : function(info){try{if(info){var cookie = "{"; for(var i in info){if(typeof(info[i]) == 'function'){continue;}if(info[i] == null || typeof(info[i]) == 'undefined'){cookie += '"' + i + '":null,';}else if(typeof(info[i])  == 'number'){cookie += '"' + i + '":' + info[i] + ',';}else{cookie += '"' + i + '":"' + info[i] + '",';}} return cookie.substring(0,cookie.length-1) + "}";} return "";}catch(e){return "";}}, getUserCookie : function(name){try{var _cookie =  this.getCookie('CPC_' + name); if(_cookie){return  eval('('+ _cookie+')');}else{return null;}}catch(e){return null;}}, setUserCookie : function(type,name,object,domain){try{if(type == 'global'){var _expires = new Date(); _expires.setDate(_expires.getDate() + 365); this.setCookie('CPC_' + name, this.makeCookie(object), domain,_expires);}else{this.setCookie('CPC_' + name, this.makeCookie(object), domain);}}catch(e){return null;}}, deleteCookie : function(name,object,domain){try{var _expires = new Date(); _expires.setDate( _expires.getDate() - 1 ); this.setCookie('CPC_' + name, object, domain,_expires);}catch(e){return null;}}}

	var cpc_service = {analysis:'1',conversion:'1',son:'0',spopup:'0',clickpoint:'0'}; var cpc_siteid = '', cpc_domain = '', cpc_userip = '', cpc_timeset = '', cpc_command = ""; var cpc_protocol = document.location.protocol || 'http:';
	window.onerror = function(){return true;}
	//if(!document.body){document.write('<body></body>');};
	if(document.URL.indexOf('cpcguard_Login=Y') < 0){cpc_domain = cpcguard.domain(); cpcguard.includer.include('javascript', cpc_protocol + '//img.cpcguard.com/siteInfo/'+document.domain+'.js','include_cpc_service', true, 'utf-8');}
	function cpc_analysis_service(){if(cpc_site){if(cpc_site.serviceYN == 'Y'){cpc_siteid = cpc_site.siteID; cpc_service.analysis = cpc_site.script.charAt(0); cpc_service.conversion = cpc_site.script.charAt(1);cpc_service.son = cpc_site.script.charAt(2); cpc_service.spopup = cpc_site.script.charAt(3); cpc_service.clickpoint = cpc_site.script.charAt(4); try{if(cpc_site.remain && parseInt(cpc_site.remain) < 0){cpc_service.son = '0'; cpc_service.spopup = '0'; cpc_service.clickpoint = '0';}}catch(e){} cpcguard.ajax.dynamicQuery(cpc_protocol + '//sc1.cpcguard.com/v6/getCode_1.aspx',true,'utf-8');}}}
	function cpc_analysis_bind(receiveData){try{cpc_userip = receiveData.ip; cpc_timeset = receiveData.timeset; cpcguard.includer.include('javascript',cpc_protocol + '//sc1.cpcguard.com/v6/customer/kisa/cpc_analysis.js','include_cpc_analysis', false,'utf-8');}catch(e){}}
}