var VRTContorller = {

	options : {

		numberingApiPath : "http://www.scroll-shop.com/plaza/apl/js/seq.jsp",

 hosts : ["www.scroll-shop.com", "www.rapty.com", "www.micosuper.com", "www.m-kirei.com", "www.marble-m.com", "www.romapri.com", "www.seikatsuzacca.com", "www.kutuya928.com", "www.raprier.com", "www.koa-st.com"],

		seqCookieName : "Vs",

		visitCookieName : "Vv",

		cookieExpires : 90,

		cookieHTMLPath : "/cookie.html",

		seqParamName : "seq"

	},



	getOption : function(key) {

		return this.options[key];

	},



	setOption : function(key, param) {

		this.options[key] = param;

	},



	loadingID : null,



	scriptElement : {},



	timeout : 10000, 



	getCookie : function(name) {

		if (document.cookie) {

			var cookies = document.cookie.split("; ");

			

			for (var i = 0; i < cookies.length; i++) {

				var param = cookies[i].split("=");



				if (param[0] == name) {

					return param[1];

				}

			}

		}

		return null;

	},



	setCookieSeq : function(seq) {

		var expires = new Date(new Date().getTime() + (60 * 60 * 24 * 1000 * this.getOption('cookieExpires')));



		document.cookie = this.getOption('seqCookieName') + "=" + escape(seq) + "; expires=" + expires.toGMTString() + "; path=/";

		document.cookie = this.getOption('visitCookieName') + "=; path=/";

	},



	getJSONP : function(){

		var script = this.scriptElement = document.createElement('script');



		script.setAttribute("type", "text/javascript");

		script.setAttribute("charset", "utf-8");

		script.setAttribute("src", this.getOption('numberingApiPath') + '?nocache=' + (new Date()).getTime());



		document.body.appendChild(script);

	},



	getJSONPOnError : function() {

		this.deleteScript(this.scriptElement);

		this.scriptElement = null;

		

		return false;

	},



	deleteScript : function(scriptElement) {

		if (scriptElement != null) {

			document.body.removeChild(scriptElement);

		}

	},



	makeXSCookie : function() {

		if (this.loadingID != null) return false;



		if ((navigator.cookieEnabled == true) && (this.getCookie(this.getOption('visitCookieName')) == null)) {

			var seq = this.getCookie(this.getOption('seqCookieName'));



			if (seq != null) {

				var data = new Object();

				data['seq'] = seq;

				this.updateXSCookie(data);

			} else {

				this.loadingID = setTimeout(function() { this.getJSONPOnError(); }, this.timeout);



				this.getJSONP();

			}

		}

	},



	updateXSCookie : function(data) {

		if (!data || (data['seq'].length <= 0)) {

			this.getJSONPOnError();



			return false;

		}



		this.setCookieSeq(data['seq']);



		var hosts = this.getOption('hosts');

		var cookieHTMLPath = this.getOption('cookieHTMLPath');

		var seqParamName = this.getOption('seqParamName');



		for (var i = 0; i < hosts.length; i++) {

			if (hosts[i] != window.location.hostname) {

				var iframe = document.createElement('iframe');



				iframe.setAttribute("src", 'http://' + hosts[i] + cookieHTMLPath + '?=' + seqParamName + '=' + escape(data['seq']));

				iframe.setAttribute("height", 0);

				iframe.setAttribute("width", 0);

				iframe.setAttribute("marginheight", 0);

				iframe.setAttribute("marginwidth", 0);

				iframe.setAttribute("border", 0);

				iframe.setAttribute("frameborder", 0);

				iframe.setAttribute("scrolling", 'no');

				document.body.appendChild(iframe);

			}

		}

	},



	getQuerySeq : function() {

		if (location.search.length > 1) {

			var m_Array = location.search.substr(1).split("&");

			var seqParamName = this.getOption('seqParamName');

			for (var idx = 0; idx < m_Array.length; idx++) {

				var param = m_Array[idx].split("=");



				if (param[1] == seqParamName) {

					return param[2];

				}

			}

		}



		return null;

	},



	createXSCookie : function(data) {

		this.deleteScript(this.scriptElement);

		this.scriptElement = null;



		clearTimeout(this.loadingID);

		this.loadingID = null;



		var hosts = this.getOption('hosts');

		var numberingApiPath = this.getOption('numberingApiPath');



		for (var i = hosts.length - 1; i >= 0; i--) {

			if (numberingApiPath.search(new RegExp(hosts[i])) != -1) {

				hosts.splice(i, 1);

			}

		}



		this.setOption('hosts', hosts);



		this.updateXSCookie(data);

	}

};



var VRTMakeXSCookie = function() {

	VRTContorller.makeXSCookie();

};



var VRTCallback = function(data) {

	VRTContorller.createXSCookie(data);

};
