if (typeof SixChat == "undefined")
	var SixChat = {};

SixChat.Stats = {
	NewHitForWm : function(localProjectId, localWmId, country) {

		this.d = document;
		this.dl = document.location;
		this.dd = document.domain;
		this.dc = document.cookie;

		if (!localProjectId) {
			this._showError("NewHitForWm: missing parameter 'localProjectId'");
			return;
		}
		if (!localWmId) {
			this._showError("NewHitForWm: missing parameter 'localWmId'");
			return;
		}

		// var url = 'http://us.6-chats.com/stats/i/i.gif';
		var url = '/stats/i/i.php';
		url += "?datetime=" + this._getDatetime();
		url += "&lprid=" + localProjectId;
		url += "&lwmid=" + localWmId;
		url += "&lang=de";
		url += "&dRef=" + this._getDocReferrer();
		url += "&dLoc=" + this._getDocFullLocation();
		url += "&dCook=" + this._getDocFullCookie();
		url += "&country=" + country;
		var i = new Image();
		//alert(url);
		i.src = url;
	},
	_getDatetime : function() {
		var today = new Date();
		var y = today.getFullYear();
		var m = today.getMonth()+1; 
		var m = String("0" + m).slice(-2);
		var d = String("0" + today.getDate()).slice(-2);
		var h = String("0" + today.getHours()).slice(-2);
		var n = String("0" + today.getMinutes()).slice(-2);
		var s = String("0" + today.getSeconds()).slice(-2);
		return this.URL_Encode(y + '-' + m + '-' + d + ' ' + h + ':' + n + ':'
				+ s);
	},
	_getDocFullLocation : function() {
		return this.URL_Encode(this.dl);
	},
	_getDocFullCookie : function() {
		if (!this.dc)
			return '0';
		return this.URL_Encode(this.dc);
	},
	_getDocDomain : function() {
		return this.URL_Encode(this.dd);
	},
	_getDocPage : function() {
		var pg = this.dl.pathname + this.dl.search;
		pg = this.URL_Encode(pg);
		return pg;
	},
	_getDocReferrer : function() {
		var ref = this.d.referrer;
		if (!ref || ref == "") {
			ref = "0";
			return ref;
		}
		var dom = this.dd;
		page = ref.indexOf(dom);
		if ((page >= 0) && (page <= 8)) {
			ref = "0";
		} else if (ref.indexOf("[") == 0
				&& ref.lastIndexOf("]") == (ref.length - 1)) {
			ref = "0";
		}

		ref = this.URL_Encode(ref);
		return ref;
	},
	_getCurrentPageUrl : function() {
		var val = new String(window.location);
		val = val.substring(0, 255);
		return val;
	},
	_showError : function(msg) {
		var err = "SixChat Javascript ERROR\n";
		err += "Class: SixChat.Stats\n";
		err += "Error message follows:\n----------------------\n";
		err += msg;
		alert(err);
	},
	// public method for url encoding
	URL_Encode : function(string) {
		return escape(this._URL_utf8_encode(string));
	},
	// private method for UTF-8 decoding
	_URL_utf8_encode : function(string) {
		var string = new String(string);
		string = string.replace(/\r\n/g, "\n");
		var utftext = "";

		for ( var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if ((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	}

};
