/*
+--------------------------------------------------------------------
| Version	Date		Comment
| 3.01		2005/05/22	initial version
|
| Copyright (c) 2004 Rosman (http://www.rosman.co.at)
+--------------------------------------------------------------------
| Purpose
| implement print function
+--------------------------------------------------------------------
| Usage
+--------------------------------------------------------------------
| Appl. Dependencies:  -
+--------------------------------------------------------------------
| Author(s): Johan Rosman <johan@rosman.co.at>
+--------------------------------------------------------------------

+--------------------------------------------------------------------
| Version History:
+--------------------------------------------------------------------
| Version	Date		Comment
+--------------------------------------------------------------------
| 3.01		2005/05/22	initial version
+--------------------------------------------------------------------
*/

if ( !window._dhtml_js ) {
	alert ( 'Error in '+self.location.pathname+': print.js needs dhtml.js' );
} else if ( !_print_js ) {
	// variable to enable dependency / multiple calls check
	var _print_js = true;

	var _location = null;
	var _kap_location = null;

	/* open print preview in a new window */
	function openwin() {
		if ( this.id == 'print' ) {
			_print = _location;
		} else {
			_print = _kap_location;
		}
		if ( _print ) {
			window.open(	_print,
					"",
					"width=" + Math.ceil ( screen.availWidth * 0.8 ) + ",height=" + Math.ceil ( screen.availHeight * 0.9 ) +
					",top=0,left=0,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no");
		}
	}

	function print_init() {
		if ( _print_onload ) { _print_onload(); }
		if ( document.body.className != 'print' ) {
			var _pr = new getobj("print");
			if ( _pr.obj ) {
				var _a = _pr.obj.getElementsByTagName ( 'a' );
				if ( _a.length == 1 ) {
					_location = _a[0].href;
					_a[0].href='#';
					_a[0].target='';
					_pr.obj.onclick = openwin;
				}
			}
			var _pr = new getobj("kapprint");
			if ( _pr.obj ) {
				var _a = _pr.obj.getElementsByTagName ( 'a' );
				if ( _a.length == 1 ) {
					_kap_location = _a[0].href;
					_a[0].href='#';
					_a[0].target='';
					_pr.obj.onclick = openwin;
				}
			}
		} else {
			var _pr = new getobj("features");
			_pr.style.visibility = 'visible';
			if ( _pr.obj.lang == 'de' ) {
				if ( window.print ) { // IE on Mac doesnt support window.print !!!
					_pr.obj.innerHTML='<button id="print" onClick="window.print()">Drucken</button> <button id="close" onClick="window.close()">Schließen</button>';
				} else {
					_pr.obj.innerHTML='<button id="close" onClick="window.close()">Schließen</button>';
				}
			} else {
				if ( window.print ) { // IE on Mac doesnt support window.print !!!
					_pr.obj.innerHTML='<button id="print" onClick="window.print()">Print</button> <button id="close" onClick="window.close()">Close</button>';
				} else {
					_pr.obj.innerHTML='<button id="close" onClick="window.close()">Close</button>';
				}
			}
		}
	}

	/* cascade onload */
	if ( window.onload ) {
		var _print_onload = window.onload;
	}
	window.onload = print_init;
}
