/**
 * Benoetigter Code fuer die Klasse "Heatmap"
 * Zur Weitergabe der Daten an die erforderliche Schnittstelle
 * 
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2010 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/?GUI[0]=license     New BSD License
 * 
 * */


function Heatmap (siteName, urlPath)
{
	this.IE = '';
	var newthis = this;

	
	/**
	 * Anmeldung an MouseDown um Klicks zu speichern
	 * */
	this.register = function ()
	{
		newthis.IE = document.all ? true : false;
		if (!newthis.IE) {
			document.captureEvents(Event.MOUSEMOVE);
		}

		document.onmousedown = newthis.save;
	};

	
	/**
	* Ermittelt die Informationen und gibt die Daten an Ajax zur Speicherung weiter
	* @param event e	: Event
	* @return bool
	*/
	this.save = function (e)
	{
		if (!e) { // Event-Variable holen falls nötig
			e = window.event;
		}

		if (newthis.IE) {
			if (typeof(e.button) != 'undefined' && e.button == 2) { // Rechtsklick verhindern
				return false;
	        }
	        
			clickX = e.clientX + document.body.scrollLeft;
			clickY = e.clientY + document.body.scrollTop;
		} else {
			if (typeof(e.which) != 'undefined' && e.which == 3) { // Rechtsklick verhindern
				return false;
	        }
	        
			clickX = e.pageX;
			clickY = e.pageY;
		}


		if (e.target) {
			target = e.target;
		} else if (e.srcElement) {
			target = e.srcElement;
		}
		if (target.nodeType == 3) // defeat Safari bug
			target = target.parentNode;

		tagName = target;

		// Gesammelte Daten an Schnittstelle senden
		var url = urlPath + '?x=' + clickX + '&y=' + clickY + '&siteName=' + siteName + '&tagName=' + tagName;
		newthis.sendRequest(url);
		return true;
	};
	
	
	/**
	* Sendet die gesammelten Informationen an die entspr. Url
	* @param string url	: Url der Schnittstelle, welche die Daten abspeichert
	* @return bool
	*/
	this.sendRequest = function (url)
	{
		var ajaxRequest;

		if (typeof(window.ActiveXObject) == 'undefined') {
			ajaxRequest = new XMLHttpRequest();
		} else {
			ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
		}
		
		// Request senden
		ajaxRequest.open('GET', url, true);
		ajaxRequest.send(null);
		
		return true;
	};

	
}




