(function (){
	window.errors_occured = false;
	window.basic_error_handling = true;
	function report( msg, url, line) {
		
		error_id = msg; 
		if( !window.basic_error_handling ||  window.errors_occured || error_rate_limited() ) { return; }
		var reporting_url = 'https://cst-client-monitoring.viomassl.com/error.php'
		var img = new Image();
		var error_type = "error-basic";
		if( navigator.userAgent.indexOf('MSIE') != -1 ){
			 error_type = "error-basic-ie";
		}
		var website_url = window.location.href;
		var error_file = website_url;
		if( typeof url != 'undefined' ) {
			error_file = url;
		}
		img.src = '$$1?type=$$6&url=$$2&referrer=$$4&error_str=$$3&error_line=$$5'
			.replace('$$1',reporting_url)
			.replace('$$2',encodeURIComponent(error_file))
			.replace('$$3',msg)
			.replace('$$4',encodeURIComponent(website_url))
			.replace('$$5',encodeURIComponent(line))
			.replace('$$6',error_type);
		window.errors_occured = 1;
		error_rate_limit();
	}
	
	function error_rate_limited() {
		return document.cookie.indexOf('cmsehandler') != -1;
	}

	function error_rate_limit() {
		var expiry = new Date(new Date().getTime() +1000*60*60*24*1).toGMTString();
		document.cookie = 'cmsehandler=1; expires='+ expiry + '; path=/';
	}	
	
	// sonst hat man im ie keine line und file
	window.onerror = report;	
//	if( window.addEventListener) {
//		window.addEventListener ("error", report);	
//	} else if ( window.attachEvent ) {
//		window.attachEvent ("onerror", report);
//	}
})()


