/*global de*/
de = this.de || {};
de.datev = de.datev || {};
de.datev.portal = de.datev.portal || {};
de.datev.portal.statisticsevent = function () {
    var thisNamespace = de.datev.portal.statisticsevent || {};


////////////////////////////////////////////////
/////////// Senden von Statistik-Events ////////
////////////////////////////////////////////////

//(2) Download-Button mit Statistic-Event versehen
var init = function () {

	var downloadLink = document.getElementById("serviceDownload");
	if(downloadLink) {

		de.datev.events.addEvent(downloadLink, "click", function(evt) {

			var titleWithUnderscores = JS_GLOBAL_VAR_RessourceTitel ? JS_GLOBAL_VAR_RessourceTitel.replace(/\s/, "-") : "KEIN-TITEL";

			var url_statisticsevent = "http://www.datev.de/statistik/sas.event.css?" +
							          "anw=dado" +
			                		  "&#38;req=Seite" +
					                  "&#38;zg=" + (JS_GLOBAL_VAR_Zielgruppe ? JS_GLOBAL_VAR_Zielgruppe : "n") +
							          "&#38;bez=Download-gestartet"+
						              "&#38;pfad=Downloads_" + titleWithUnderscores;

			sendEvent(url_statisticsevent);
		});

	}/*end - downloadLink*/
};/*end - init*/



//(3) Belegdaten mit jedem Buttonklick ziehen
var sendEvent = function (url_event) {
	var request = null;

	//Firefox bzw. IE7
	try {
		request = new XMLHttpRequest();
		request.open("GET", url_event, true);
		request.onreadystatechange = function(){};
        request.send(null);
	}
	catch(e){
		//IE 5 bzw. 6
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
			request.open("GET", url_event, true);
			request.onreadystatechange = function(){};
        	request.send(null);
		}
		catch(e){
			request = new ActiveXObject("Microsoft.XMLHTTP");
			request.open("GET", url_event, true);
			request.onreadystatechange = function(){};
    		request.send(null);

		}/*end - ActiveXObject("Msxml2.XMLHTTP");*/
	}/*end - XMLHttpRequest*/
};/*end - sendEvent*/


//////////////////////////////////////////////////////
// PUBLIC
//////////////////////////////////////////////////////
thisNamespace.init = init;

return thisNamespace;
}(); // de.datev.portal.statisticsevent


////////////////////////////////////////////////////////////////
// (1) Ausfuehrung
////////////////////////////////////////////////////////////////
de.datev.events.addEvent(window, "load", de.datev.portal.statisticsevent.init);

