var CompanyPageTracker = function(trackerUrl, spCd){
	this.trackerUrl = trackerUrl;
	this.spCd = spCd;
	this.mobKb = 0;
	this.saleNo = new Array();
	this.orderNo = new Array();
	
	this.setMobKb = function(mobKb){
		this.mobKb = mobKb;
	}
	this.setCustomerId = function(cstId){
		this.cstId = cstId;
	}
	this.setPageUrl = function(url){
		this.pageUrl = url;
	}
	this.setPageTitle = function(title){
		this.pageTitle = title;
	}
	this.addSaleNo = function(sn){
		this.saleNo.push(sn);
	}
	this.addOrderNo = function(orderNo){
		this.orderNo.push(orderNo);
	}
	
	this.sendAccessData = function(async){
		if(! this.spCd || !this.trackerUrl){
			return;
		}
		var url = trackerUrl; 
		url += "?spCd="+this.spCd;
		if(this.mobKb != 0){
			url += "&mobKb="+this.mobKb;
		}
		url += "&resolution="+screen.width+"x"+screen.height;
		if(this.pageTitle){
			url += "&title=" + this.pageTitle.replace(/&/g, "%26").replace(/\?/g,"%3F");
		} else if(document.title){
			var t = document.title;
			url += "&title=" + t.replace(/&/g, "%26").replace(/\?/g,"%3F");
		}
		if(document.referrer){
			var r = document.referrer;
			r = r.replace(/&/g, "%26").replace(/\?/g,"%3F");
			url += "&referer=" + r;
		}
		if(this.cstId){
			url += "&cstId=" + this.cstId;
		}
		for(var i=0; i<this.orderNo.length; i++){
			url += "&orderNo="+this.orderNo[i];
		}
		for(var j=0; j<this.saleNo.length; j++){
			url += "&saleNo="+this.saleNo[j];
		}
		
		if(!this.pageUrl){
			this.pageUrl = document.location.href;
		}
		url += "&url="+this.pageUrl.replace(/&/g, "%26").replace(/\?/g,"%3F");
		
		if(async){
			var xhr = this.createXhr();
			xhr.open("POST",encodeURI(url));
			xhr.send();
		} else {
			var img = new Image();
			img.src = encodeURI(url);
		}
	}
	
	this.createXhr = function(){
		var xhr = null;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else {
			try {
				xhr = new ActiveXObject('MSXML2.XMLHTTP.6.0');
			} catch (e) {
				try {
					xhr = new ActiveXObject('MSXML2.XMLHTTP.3.0');
				} catch (e) {
					try {
						xhr = new ActiveXObject('MSXML2.XMLHTTP');
					} catch (e) {
					}
				}
			}
		}
		return xhr;
	}

}

