/**
 * NameRobot JavaScript
 *
 * Copyright NameRobot
 */

if (typeof _nr == 'undefined') {
	var _nr = {};
};

_nr.load = function()
{
	if ($('loginlink')) {
		$('loginlink').href = "javascript: _nr.login.show();";
	};

	_nr._createlogin();

	_ptools.onError = function(Exception, onclick, nohide)
	{
		if (Exception.getCode() == 400)
		{
			// Prüfen ob der benutzer eingeloggt ist
			_Ajax.asyncPost('ajax_is_auth', function(result, Ajax)
			{
				if (TOOLS && (result == 0 || !result))
				{
					User = false;

					_nr.loader.stop(true);
					_nr.login.show();

					return;
				};

				_ptools.onError(
					new _ptools.Exception('Internal Server Error'),
					function () { _nr.hideError(); },
					false
				);
			}, {
				project : _Project.name
			});

			return;
		};

		document.body.focus();

		if (typeof onclick != 'function')
		{
			onclick = function() {
				_nr.hideError();
			};
		};


		// Login schließen falls es auf ist
		if (typeof nohide == 'undefined' && !nohide) {
			_nr.login.hide();
		};

		_nr.loader.stop(true);

		if (!$('ExceptionMsg'))
		{
			var oMsg  = document.createElement('div');
			var style = null;
			var wpo   = _ptools._System.getScrollXY()[1];

			oMsg.id = 'ExceptionMsg';

			document.body.appendChild( oMsg );
		};

		var oMsg = $('ExceptionMsg');

		oMsg.innerHTML = '<img src="'+ URL_BIN_DIR +'32x32/messagebox_warning.png" style="margin: 20px 10px 10px 30px; float: left;" />' +
			'<div style="margin: 20px;float: left; width: 380px">'+ Exception.getMessage() +'</div>' +
			'<div id="ExceptionButton" style="width: 100px; margin: 0 auto; text-align: center"></div>';

		style = oMsg.style;
		style.top    = '150px';
		style.left   = '50%';
		style.border = '2px solid #551C1C';
		style.height = '150px';
		style.width  = '500px';
		style.color  = '#000';
		style.zIndex = 9999;
		style.marginLeft      = '-250px';
		style.position        = 'fixed';
		style.backgroundColor = '#FFBFBF';

		_nr.background.show();

		$('ExceptionButton').appendChild(
			new _ptools.Button({
				text    : 'OK',
				onclick : onclick,
				width   : 100
			}).create()
		);
	};

	if (TOOLS && typeof _nr.user != 'undefined') {
		_nr.user.load();
	};

	if (typeof _nr.user != 'undefined')
	{
		// Prüfen ob offene Rechnungen vorhanden sind
		_nr.user.checkBill();
	};

	if ($('registration') && User == false)
	{
		$('registration').onclick = function()
		{
			window.location = $('register_link').href;
		};

		$('registration').onmouseover = function()
		{
			_nr.Bubble.show('<br />Jetzt bei NameRobot anmelden und mit Ihrer Namensfindung starten.', this);
		};

		$('registration').onmouseout = function()
		{
			_nr.Bubble.hide();
		};
	};

	_pcsg.Basket.load();

	_nr.Twitter();
	//_nr.Footer.load();

	if (window.location.toString().match('#contact'))
	{
		_nr.Feedback.open();
	};
};

_nr.hideError = function()
{
	if (!$('ExceptionMsg')) {
		return;
	};

	new Fx.Morph($('ExceptionMsg'), {
		duration   : 500,
		transition : Fx.Transitions.Quad.easeOut,
		onComplete : function()
		{
			$('ExceptionMsg').parentNode.removeChild(
				$('ExceptionMsg')
			);

			_nr.background.hide();
		}
	}).start({
		opacity : 0
	});
};

_nr._createlogin = function()
{
	$('form-login').innerHTML = '<div class="header">Einloggen</div>' +

		'<fieldset class="username">' +
	 		'<label for="username">Benutzername / E-Mail</label>' +
	 		'<input name="username" ' +
	 			'type="text" ' +
	 			'value="" ' +
	 			'onfocus="this.className = \'active\'" ' +
	 			'onblur="this.className = \'\'" ' +
	 		'/>' +
	 	'</fieldset>' +

		'<fieldset class="password">' +
	 		'<label for="password">Passwort</label>' +
	 		'<input name="password" ' +
	 			'type="password" ' +
	 			'value="" ' +
	 			'onfocus="this.className = \'active\'" ' +
	 			'onblur="this.className = \'\'" ' +
	 		'/>' +
	 	'</fieldset>' +

	 	'<p style="margin: 5px 0 5px 10px"><input type="checkbox" name="ssl" style="width: 15px; padding-left: 0px; border: none;" /> Übertragung mit SSL verschlüsseln</p>' +

	 	'<div id="btn_login"></div>' +
	 	'<input type="submit" name="submit" value="Login!" style="display: none" />' +

	 	'<div class="login-register">' +
	 		'<p>Ich bin noch nicht registriert und möchte mich neu anmelden</p>' +
	 		'<div id="login-register-btn"></div>' +
	 	'</div>';


	// Login Submit Button
	if (!$('btn_login')) {
		return;
	};

	var f = document.forms['form-login'];

	f.elements['username'].onkeydown = function(e)
	{
		e = e || window.event;

		if (e.keyCode == 13)
		{
			var f = document.forms['form-login'];

			if (f.elements['username'].value == '' ||
				f.elements['password'].value == '')
			{
				return false;
			};

			_nr.login.login();
			 return false;
        };
    };

    f.elements['password'].onkeydown = function(e)
	{
		e = e || window.event;

		if (e.keyCode == 13)
		{
			var f = document.forms['form-login'];

			if (f.elements['username'].value == '' ||
				f.elements['password'].value == '')
			{
				return false;
			};

			_nr.login.login();
			 return false;
        };
    };

	$('login-register-btn').appendChild(
		new _ptools.Button({
			text    : 'Jetzt kostenlos anmelden',
			width   : 200,
			onclick : function() {
				window.location = '/neu-anmelden.html';
			}
		}).create()
	);

	$('btn_login').appendChild(
		new _ptools.Button({
			text    : 'Passwort vergessen',
			width   : 150,
			onclick : function() {
				_nr.login.forgetPassword();
			}
		}).create()
	);

	$('btn_login').appendChild(
		new _ptools.Button({
			text    : 'Abbrechen',
			width   : 100,
			onclick : function() {
				_nr.login.hide()
			}
		}).create()
	);

	$('btn_login').appendChild(
		new _ptools.Button({
			text    : 'Login!',
			width   : 100,
			onclick : function() {
				_nr.login.login();
			}
		}).create()
	);
};

_nr.Footer =
{
	height : 700,

	load : function()
	{
		if (Cookie.read('nrfooter') == 'close')
		{
			$('footer').style.height = '18px';
			this.close();
		} else
		{
			$('footer').style.height = _nr.Footer.height +'px';
		};
	},

	open : function()
	{
		if (!$('footer')) {
			return;
		};

		new Fx.Morph($('footer'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				Cookie.write('nrfooter', 'open');
				$('footeropenerline').innerHTML = '<span class="bottom">F u ß z e i l e - a u s b l e n d e n</span>';

				new Fx.Scroll(window).toBottom();
			}
		}).start({
			height : _nr.Footer.height
		});
	},

	setFooterHeight : function(height)
	{
		_nr.Footer.height = height;

		new Fx.Morph($('footer'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				new Fx.Scroll(window).toBottom();
			}
		}).start({
			height : _nr.Footer.height
		});
	},

	close : function()
	{
		if (!$('footer')) {
			return;
		};

		new Fx.Scroll(window, {
	    	onComplete : function()
	    	{
				new Fx.Morph($('footer'), {
					duration   : 500,
					transition : Fx.Transitions.Quad.easeOut,
					onComplete : function()
					{
						Cookie.write('nrfooter', 'close');
						$('footeropenerline').innerHTML = '<span class="top">F u ß z e i l e - e i n b l e n d e n</span>';
					}
				}).start({
					height : 18
				});
	    	}
	    }).toTop();
	},

	change : function()
	{
		if (!$('footer')) {
			return;
		};

		if ($('footer').style.height == (_nr.Footer.height +'px'))
		{
			_nr.Footer.close();
			return;
		};

		_nr.Footer.open();
	},

	openComment : function(id, height, elm)
	{
		var id = 'nr_comment_'+ id;

		if (!$(id)) {
			return;
		};

		if ($(id).style.height == height+'px')
		{
			_nr.Footer.setFooterHeight( _nr.Footer.height-height );

			// schließen
			new Fx.Morph($(id), {
				duration   : 500,
				transition : Fx.Transitions.Quad.easeOut,
				onComplete : function()
				{
					elm.innerHTML = 'ganzen Kommentar lesen';
				}
			}).start({
				height : 60
			});

			return;
		};

		_nr.Footer.setFooterHeight( _nr.Footer.height+height );

		new Fx.Morph($(id), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				elm.innerHTML = 'Kommentar schließen';
			}
		}).start({
			height : height
		});
	}
};

_nr.HeaderSlider =
{
	start : true,

	step1 : 0,
	step2 : -980,
	step3 : -1960,

	load : function()
	{
		(function()
		{
			_nr.HeaderSlider.left()
		}).delay( 8000 );
	},

	left : function()
	{
		if (!$('header-slider')) {
			return;
		};

		if (this.start == false) {
			return;
		};

		if ($('header-slider').offsetLeft == 0)
		{
			this.step( 2 );
		} else if ($('header-slider').offsetLeft == this.step2)
		{
			this.step( 3 );
		} else
		{
			this.step( 1 );
		};
	},

	move : function(step)
	{
		new Fx.Morph($('header-slider'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_nr.HeaderSlider.load();
			}
		}).start({
			left : step
		});
	},

	play : function()
	{
		var lis = $('headernumbers').getElementsByTagName('li');

		lis[3].className = 'play-active';
		lis[4].className = 'stop';

		this.start = true;
		this.left();
	},

	stop : function()
	{
		var lis = $('headernumbers').getElementsByTagName('li');

		lis[3].className = 'play';
		lis[4].className = 'stop-active';

		this.start = false;
	},

	step : function(no)
	{
		var lis = $('headernumbers').getElementsByTagName('li');

		lis[0].className = 'play-info';
		lis[1].className = 'play-blog';
		lis[2].className = 'play-go';

		switch (no)
		{
			case 1:
				lis[0].className = 'play-info-active';

				this.move( this.step1 );
			break;

			case 2:
				lis[1].className = 'play-blog-active';

				this.move( this.step2 );
			break;

			case 3:
				lis[2].className = 'play-go-active';

				this.move( this.step3 );
			break;
		};
	},

	click : function(no)
	{
		this.stop();
		this.step( no );
	}
};

_nr.BoxLink = function(elm)
{
	window.location = elm.getElementsByTagName('a')[0].getAttribute('href');
};

/*
_nr.Video = function()
{
	var Video = new Element('div');

	Video.id = 'nrVideo';
	Video.set('opacity', 0);

	Video.className = 'nrVideo radius';
	Video.innerHTML = '' +
		'<div id="nrVideoTitle">NameRobot Video</div>' +
		'<div id="nrVideoContent"></div>' +
		'<div id="nrVideoClose"></div>';

	document.body.appendChild( Video );

	$('nrVideoClose').onclick = function()
	{
		$('nrVideo').innerHTML = '';

		new Fx.Morph($('nrVideo'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				$('nrVideo').parentNode.removeChild(
					$('nrVideo')
				);

				_nr.background.hide();
			}
		}).start({
			opacity : 0
		});
	};

	_nr.background.show();

	new Fx.Morph($('nrVideo'), {
		duration   : 500,
		transition : Fx.Transitions.Quad.easeOut,
		onComplete : function()
		{
			_Ajax.asyncPost('ajax_get_help_video', function(result)
			{
				if (!$('nrVideoContent')) {
					return;
				};

				$('nrVideoContent').innerHTML = result;
			}, {
				project : _Project.name
			});
		}
	}).start({
		opacity : 1
	});
};
*/
_nr.Info =
{
	show : function(txt)
	{
		$('infobox').set('opacity', 0);
		$('infobox').style.display = '';

		if (typeof txt != 'undefined') {
			$('infobox-content').innerHTML = txt;
		};

		new Fx.Morph($('infobox'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut
		}).start({
			opacity : 1,
			bottom  : 40
		});
	},

	hide : function()
	{
		new Fx.Morph($('infobox'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut
		}).start({
			opacity : 0,
			bottom  : 20
		});
	}
};

_nr.Facebook =
{
	open : function()
	{
		if ($('social_facebook')) {
			return;
		};

		var oDiv = new Element('div');

		oDiv.setStyles({
			position   : 'absolute',
			top        : '100px',
			background : '#fff',
			left       : '100px',
			width      : '490px',
			border     : '1px solid #E3E3E3',
			zIndex     : 100,
			shadow     : '0px 5px 20px #5f5f5f'
		});

		oDiv.addClass('shadow');
		oDiv.addClass('radius10');

		oDiv.innerHTML = '' +
			'<div style="margin: 10px;">' +
				'<img src="'+ PROJECT_BIN_URL +'images/16x16/helpinfo_close.png" onclick="_nr.Facebook.close();" style="position: absolute; right: 3px; top: 3px; cursor: pointer;" />' +
				'<iframe src="http://www.facebook.com/plugins/likebox.php?id=10150115484340417&amp;width=470&amp;connections=16&amp;stream=true&amp;header=true&amp;height=587" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:470px; height:587px;" allowTransparency="true"></iframe>' +
				'<div id="facebook_close_btn" style="clear: both; width: 100px; height: 20px; margin: 5px auto;"></div>' +
			'</div>';

		oDiv.id = 'social_facebook';

		document.body.appendChild( oDiv );

		$('facebook_close_btn').appendChild(
			new _ptools.Button({
				width   : 100,
				text    : 'schließen',
				onclick : function()
				{
					_nr.Facebook.close();
				}
			}).create()
		);

		new Fx.Scroll(document, {
		    duration : 500
		}).start(0, 0);

	},

	close : function()
	{
		if (!$('social_facebook')) {
			return;
		};

		$('social_facebook').parentNode.removeChild( $('social_facebook') );
	}
};

_nr.MessageBox =
{
	show : function(txt)
	{
		_nr.background.show();

		$('messagebox').set('opacity', 0);
		$('messagebox').style.display = '';

		if (typeof txt != 'undefined') {
			$('messagebox-text').innerHTML = txt;
		};

		$('messagebox-btn').innerHTML = '';
		$('messagebox-btn').appendChild(
			new _ptools.Button({
				name    : 'close-messagebox',
				text    : 'schließen',
				width   : 120,
				onclick : function(Btn)
				{
					_nr.MessageBox.hide();
				}
			}).create()
		);


		new Fx.Morph($('messagebox'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut
		}).start({
			opacity : 1,
			bottom  : 40
		});
	},

	hide : function()
	{
		new Fx.Morph($('messagebox'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_nr.background.hide();
			}
		}).start({
			opacity : 0,
			bottom  : 20
		});
	}
};

_nr.Twitter = function()
{
	if (!$('tweetcontent')) {
		return;
	};

	$('tweetcontent').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center';

	_Ajax.asyncPost('ajax_get_tweet', function(result, Ajax)
	{
		if (!$('tweetcontent')) {
			return;
		};

		(function()
		{
			// chrom fix O_o
			$('tweetcontent').set('styles', {
				background : ''
			});

			$('tweetcontent').set('html', result);
		}).delay(200);
	}, {
		project : _Project.name
	});
};

_nr.SitePopup =
{
	open : function(type)
	{
		// Login schließen falls es auf ist
		_nr.login.hide();

		var oBG  = document.createElement('div');
		var oMsg = oBG.cloneNode(true);

		var scrollWidth  = document.documentElement.scrollWidth;
		var scrollHeight = document.documentElement.scrollHeight;

		var style  = null;
		var wpo    = _ptools._System.getScrollXY()[1];
		var height = _ptools._System.getMaxHeight();

		if (screen.height) {
			height = screen.height;
		};

		oBG.id  = 'ReportBG';
		oMsg.id = 'ReportMsg';
		oMsg.innerHTML = '';

		style = oBG.style;
		style.backgroundColor = '#000';
		style.width    = scrollWidth +'px';
		style.height   = scrollHeight +'px';
		style.position = 'absolute';
		style.top      = '0';
		style.left     = '0';
		style.zIndex   = 1000;
		style.opacity    = '0.6';
		style.MozOpacity = '0.6';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';

		style = oMsg.style;
		style.backgroundColor = '#EAFDE6';
		style.position   = 'fixed';
		style.marginLeft = '-410px';
		style.marginTop  = '-280px';
		style.top    = '50%';
		style.left   = '50%';
		style.border = '2px solid #519548';
		style.height = '420px';
		style.width  = '820px';
		style.color  = '#000';
		style.zIndex = 1001;

		style.opacity    = '0';
		style.MozOpacity = '0';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';

		document.body.appendChild( oMsg );
		document.body.appendChild( oBG );

		if (oMsg.offsetTop < 10) {
			oMsg.style.top = '300px';
		};

		$('ReportMsg').set('opacity', 0);
		$('ReportMsg').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center #EAFDE6';

		new Fx.Morph($(oMsg), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_Ajax.asyncPost('ajax_namerobot_sites', function(result, Ajax)
				{
					var tplresult = Ajax.getAttribute('tplresult');

					if (!$('ReportMsg')) {
						return;
					};

					$('ReportMsg').style.background = '#EAFDE6';
					$('ReportMsg').innerHTML  = result.html;

					// pdf
					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'PDF',
							link    : result.printlink,
							onclick : function(Btn)
							{
								var tplresult = Btn.getAttribute('tplresult');

								if (!$('dlframe'))
								{
									var oFrame = document.createElement('iframe');
									oFrame.id = 'dlframe';

									oFrame.style.position = 'absolute';
									oFrame.style.top      = '-100px';
									oFrame.style.left     = '-100px';

									document.body.appendChild( oFrame );
								};

								$('dlframe').src = Btn.getAttribute('link').replace('.print', '.pdf');

								/*
								switch (tplresult)
								{
									default:
									case 'agb':
										$('dlframe').src = 'http://www.namerobot.de/agb.pdf';
									break;

									case 'privacy':
										$('dlframe').src = 'http://www.namerobot.de/datenschutzerklärung.pdf';
									break;

									case 'revocation':
										$('dlframe').src = 'http://www.namerobot.de/widerrufserklärung.pdf';
									break;
								};
								*/
							},
							width     : 100,
							tplresult : tplresult
						}).create()
					);

					// drucken
					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'drucken',
							onclick : function(Btn)
							{
								window.open(Btn.getAttribute('link'), '_blank');
							},
							width     : 100,
							tplresult : tplresult,
							link      : result.printlink
						}).create()
					);


					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'schließen',
							onclick : function() {
								_nr.SitePopup.close();
							},
							width : 100
						}).create()
					);


				}, {
					project : _Project.name,
					tpltype : type
				});
			}
		}).start({
			opacity : 1
		});

		return false;
	},

	close : function()
	{
		new Fx.Morph($('ReportMsg'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
			 	$('ReportMsg').parentNode.removeChild(
			 		$('ReportMsg')
			 	);

				$('ReportBG').parentNode.removeChild(
					$('ReportBG')
				);
			}
		}).start({
			opacity : 0
		});
	}
};

_nr.Feedback =
{
	open : function()
	{
		// Login schließen falls es auf ist
		_nr.login.hide();

		var oBG  = document.createElement('div');
		var oMsg = oBG.cloneNode(true);

		var scrollWidth  = document.documentElement.scrollWidth;
		var scrollHeight = document.documentElement.scrollHeight;

		var style  = null;
		var wpo    = _ptools._System.getScrollXY()[1];
		var height = _ptools._System.getMaxHeight();

		if (screen.height) {
			height = screen.height;
		};

		oBG.id  = 'ReportBG';
		oMsg.id = 'ReportMsg';
		oMsg.innerHTML = '';

		style = oBG.style;
		style.backgroundColor = '#000';
		style.width    = scrollWidth +'px';
		style.height   = scrollHeight +'px';
		style.position = 'absolute';
		style.top      = '0';
		style.left     = '0';
		style.zIndex   = 1000;
		style.opacity    = '0.6';
		style.MozOpacity = '0.6';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';

		style = oMsg.style;
		style.backgroundColor = '#EAFDE6';
		style.position   = 'fixed';
		style.marginLeft = '-410px';
		style.marginTop  = '-280px';
		style.top    = '50%';
		style.left   = '50%';
		style.border = '2px solid #519548';
		style.height = '420px';
		style.width  = '820px';
		style.color  = '#000';
		style.zIndex = 1001;

		style.opacity    = '0';
		style.MozOpacity = '0';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';

		document.body.appendChild( oMsg );
		document.body.appendChild( oBG );

		$('ReportMsg').set('opacity', 0);
		$('ReportMsg').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center #EAFDE6';

		new Fx.Morph($(oMsg), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_Ajax.asyncPost('ajax_contact_tpl', function(result)
				{
					if (!$('ReportMsg')) {
						return;
					};

					$('ReportMsg').style.background = '#EAFDE6';
					$('ReportMsg').innerHTML  = result;

					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'senden',
							onclick : function() {
								_nr.Feedback.send();
							},
							width   : 100
						}).create()
					);

					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'abbrechen',
							onclick : function() {
								_nr.Feedback.close();
							},
							width : 100
						}).create()
					);

					document.forms['contact'].elements['text'].focus();

					if (User && User.email) {
						document.forms['contact'].elements['email'].value = User.email;
					};

				}, {
					project : _Project.name
				});
			}
		}).start({
			opacity : 1
		});

		return false;
	 },

	 close : function()
	 {
	 	new Fx.Morph($('ReportMsg'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
			 	$('ReportMsg').parentNode.removeChild(
			 		$('ReportMsg')
			 	);

				$('ReportBG').parentNode.removeChild(
					$('ReportBG')
				);
			}
		}).start({
			opacity : 0
		});
	 },

	 send : function()
	 {
	 	var f = document.forms['contact'];

	 	var params = {
	 		text    : f.elements['text'].value,
	 		email   : f.elements['email'].value,
	 		browser : _ptools._Browser.get(),
	 		depth   : screen.colorDepth,
	 		width   : screen.width,
			height  : screen.height,

			availHeight : screen.availHeight,
			availWidth  : screen.availWidth
	 	};

		$('ReportMsg').innerHTML = '';
		$('ReportMsg').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center #FFBFBF';

	 	_Ajax.asyncPost('ajax_contact_send', function(result)
	 	{
 			$('ReportMsg').style.background = '#FFBFBF';
 			$('ReportMsg').innerHTML = '<div align="center" style="margin: 50px 20px 20px;">'+ result +'</div>';

 			var o = document.createElement('div');
 			o.style.margin = '0 auto';
 			o.style.width  = '100px';

 			o.appendChild(
 				new _ptools.Button({
 					text    : 'schließen',
 					onclick : function() {
 						_nr.Feedback.close();
 					}
 				}).create()
 			);

 			$('ReportMsg').appendChild(o);
	 	}, {
			project : _Project.name,
			params  : JSON.stringify( params )
		});
	 }
};

_nr.Guarantee =
{
	open : function(notextarea)
	{
		// Login schließen falls es auf ist
		_nr.login.hide();

		new Fx.Scroll(document, {
		    duration : 500
		}).start(0, 0);

		var oBG  = document.createElement('div');
		var oMsg = oBG.cloneNode(true);

		var scrollWidth  = document.documentElement.scrollWidth;
		var scrollHeight = document.documentElement.scrollHeight;

		var style  = null;
		var wpo    = _ptools._System.getScrollXY()[1];
		var height = _ptools._System.getMaxHeight();

		if (screen.height) {
			height = screen.height;
		};

		oBG.id  = 'ReportBG';
		oMsg.id = 'ReportMsg';
		oMsg.innerHTML = '';

		style = oBG.style;
		style.backgroundColor = '#000';
		style.width    = scrollWidth +'px';
		style.height   = scrollHeight +'px';
		style.position = 'absolute';
		style.top      = '0';
		style.left     = '0';
		style.zIndex   = 1000;
		style.opacity    = '0.6';
		style.MozOpacity = '0.6';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';

		style = oMsg.style;
		style.backgroundColor = '#EAFDE6';
		style.position   = 'absolute';
		style.marginLeft = '-410px';
		style.top    = '30px';
		style.left   = '50%';
		style.border = '2px solid #519548';
		style.height = typeof notextarea != 'undefined' ? '500px' : '720px';
		style.width  = '820px';
		style.color  = '#000';
		style.zIndex = 1001;

		style.opacity    = '0';
		style.MozOpacity = '0';
		style.filter     = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';

		document.body.appendChild( oMsg );
		document.body.appendChild( oBG );

		$('ReportMsg').set('opacity', 0);
		$('ReportMsg').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center #EAFDE6';

		new Fx.Morph($(oMsg), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				_Ajax.asyncPost('ajax_guarantee_tpl', function(result, Ajax)
				{
					$('ReportMsg').style.background = '#EAFDE6';
					$('ReportMsg').innerHTML  = result;

					if (Ajax.getAttribute('notextarea'))
					{
						var elm = document.forms['contact'].elements['text'];

						elm.parentNode.removeChild( elm );

						$('ReportButton').style.width = '100px';
					} else
					{
						$('ReportButton').appendChild(
							new _ptools.Button({
								text    : 'senden',
								onclick : function() {
									_nr.Guarantee.send();
								},
								width   : 100
							}).create()
						);
					};

					$('ReportButton').appendChild(
						new _ptools.Button({
							text    : 'schließen',
							onclick : function() {
								_nr.Guarantee.close();
							},
							width : 100
						}).create()
					);

					if (document.forms['contact'].elements['text']) {
						document.forms['contact'].elements['text'].focus();
					};

					if (!User && User.email) {
						document.forms['contact'].elements['email'].value = User.email;
					};

				}, {
					project    : _Project.name,
					notextarea : typeof notextarea != 'undefined' ? notextarea : false
				});
			}
		}).start({
			opacity : 1
		});

		return false;
	 },

	 close : function()
	 {
	 	new Fx.Morph($('ReportMsg'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
			 	$('ReportMsg').parentNode.removeChild(
			 		$('ReportMsg')
			 	);

				$('ReportBG').parentNode.removeChild(
					$('ReportBG')
				);
			}
		}).start({
			opacity : 0
		});
	 },

	 send : function()
	 {
	 	var f = document.forms['contact'];

	 	var params = {
	 		text    : f.elements['text'].value,
	 		browser : _ptools._Browser.get()
	 	};

		$('ReportMsg').innerHTML = '';
		$('ReportMsg').style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center #FFBFBF';

	 	_Ajax.asyncPost('ajax_guarantee_send', function(result)
	 	{
 			$('ReportMsg').style.background = '#FFBFBF';
 			$('ReportMsg').innerHTML = '<div align="center" style="margin: 50px 20px 20px;">'+ result +'</div>';

 			var o = document.createElement('div');
 			o.style.margin = '0 auto';
 			o.style.width  = '100px';

 			o.appendChild(
 				new _ptools.Button({
 					text    : 'schließen',
 					onclick : function() {
 						_nr.Guarantee.close();
 					}
 				}).create()
 			);

 			$('ReportMsg').appendChild(o);
	 	}, {
			project : _Project.name,
			params  : JSON.stringify( params ),
			onError : function(Exception)
			{
				_nr.Guarantee.close();

				_ptools.onError(Exception);
			}
		});
	 }
};

_nr.unload = function()
{
	if (typeof _nr.user != 'undefined') {
		_nr.user.unload();
	};
};

_nr.login =
{
	url : '',

	show : function(url)
	{
		if (User) {
			return;
		};

		// Prüfen ob Cookies aktiviert sind
		Cookie.write('nrtest', 1);

		if (!Cookie.read('nrtest'))
		{
			_nr.MessageBox.show('Ihr Browser akzeptiert leider keine Cookies. Bitte aktivieren Sie Cookies in Ihrem Browser.');
			return;
		};


		if (!$('login-container')) {
			return;
		};

		_nr.login.url = 'http://'+ window.location.host +'/tools/';

		if (typeof url != 'undefined') {
			_nr.login.url = url;
		};

		_nr.background.show();

		$('login-container').set('opacity', '0');
		$('login-container').style.display = '';

		new Fx.Morph($('login-container'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function() {
				document.forms['form-login'].elements['username'].focus();
			}
		}).start({
			opacity : 1
		});
	},

	hide : function(onComplete)
	{
		var onComplete = onComplete || function() {
			_nr.background.hide();
		};

		new Fx.Morph($('login-container'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : onComplete
		}).start({
			opacity : 0
		});
	},

	forgetPassword : function()
	{
		var form = document.forms['form-login'];

		if (form.elements['username'].value == '')
		{
			form.elements['username'].style.border = '1px solid red';
			form.elements['username'].value = 'Bitte ausfüllen';

			form.elements['username'].onfocus = function()
			{
				if (form.elements['username'].value == 'Bitte ausfüllen') {
					form.elements['username'].value = '';
				};
			};

			return;
		};

		_nr.loader.start();

		_Ajax.asyncPost('ajax_plugins_intranet_forget_pass', function(result)
		{
			$('form-login').innerHTML = '<div class="header">Passwort vergessen</div>' +
				'<div style="margin: 10px; text-align: center;">Ihnen wurde eine E-Mail mit weiteren Anweisungen gesendet</div>' +
				'<div id="btn_new_pw" style="width: 120px; margin-left: 125px; margin-top: 30px;"></div>';

			$('btn_new_pw').appendChild(
				new _ptools.Button({
					name    : 'btn_new_pw',
					text    : 'schließen',
					width   : 120,
					onclick : function(Btn)
					{
						_nr.login.hide();
						_nr._createlogin();
					}
				}).create()
			);

			_nr.loader.stop();
			_nr.background.show();

		}, {
			project  : _Project.name,
			plugin   : 'intranet',
			user     : form.elements['username'].value
		});
	},

	login : function()
	{
		_nr.loader.start();

		var form = document.forms['form-login'];

		if (form.elements['ssl'].checked)
		{
			var oForm = new Element('form');

			oForm.action = _nr.login.url.replace('http://', 'https://');
			oForm.method = 'POST';

			oForm.innerHTML = '' +
				'<input type="hidden" name="username" value="'+ form.elements['username'].value  +'" />' +
				'<input type="hidden" name="password" value="'+ form.elements['password'].value  +'" />' +
				'<input type="hidden" name="login" value="1" />' +
				'<input type="submit" name="senden" value="senden" />';

			document.body.appendChild( oForm );

			oForm.submit();
			return;
		};

		_Ajax.asyncPost('ajax_login', function(result)
		{
			window.location = _nr.login.url;
		}, {
			ssl      : true,
			project  : _Project.name,
			username : form.elements['username'].value,
			password : form.elements['password'].value,
			onError  : function(Exception, Ajax)
			{
				_nr.login.hide(function(){});

				if (Exception.getCode() == 401)
				{
					// Falls Benutzer deaktiviert ist, fragen ob Aktivierungslink gesendet werden soll
					_nr.loader.stop(true);
					_nr.login.activasionPopup(
						Ajax.getAttribute('username')
					);

					return false;
				};

				_ptools.onError(Exception, function()
				{
					new Fx.Morph($('ExceptionMsg'), {
						duration   : 500,
						transition : Fx.Transitions.Quad.easeOut,
						onComplete : function()
						{
							$('ExceptionMsg').parentNode.removeChild(
								$('ExceptionMsg')
							);

							_nr.login.show();
						}
					}).start({
						opacity : 0
					});
				}, false);

				return false;
			}
		});

		return false;
	},

	activasionPopup : function(username)
	{
		_nr.drop.clear();
		_nr.drop.show(function()
		{
			var o = document.createElement('div');
			o.id = 'new-activasion-content';
			o.style.margin = '20px 0pt 0pt 20px';


			o.innerHTML = '<h1>Konto nicht aktiviert</h1>' +
				'<span style="color: red;">' +
					'Ihr Konto ist leider nicht aktiviert, bitte aktivieren Sie Ihr Konto.' +
				'</span>';

			_nr.drop.appendContent(o);
		});

		$('drop-container-buttons').innerHTML = '';

		_nr.drop.appendButton(
			new _ptools.Button({
				name     : 'new-activasion',
				text     : 'neuen Aktivierungslink senden',
				width    : 200,
				username : username,
				onclick  : function(Btn)
				{
					_Ajax.asyncPost('ajax_plugins_intranet_new_activasion_code', function(result, Ajax)
					{
						_nr.drop.clear();

						$('drop-container-buttons').innerHTML = '';
						$('drop-container-content').innerHTML = '<div style="margin: 20px 0pt 0pt 20px">' +
							'<p>Ihnen wurde ein neuer Aktivierungslink zugesendet.</p>' +
							'<p>Bitte prüfen Sie Ihren Posteingang und ggf. den Spam-Ordner.</p>' +
						'</div>';

						_nr.drop.appendButton(
							new _ptools.Button({
								name    : 'back',
								text    : 'zurück zum Login',
								width   : 200,
								onclick : function()
								{
									_nr.drop.close(true);
									_nr.login.show();
								}
							})
						);

						$('drop-container-buttons').style.marginLeft = '-100px';

					}, {
						plugin   : 'intranet',
						project  : _Project.name,
						username : Btn.getAttribute('username')
					});
				}
			})
		);

		_nr.drop.appendButton(
			new _ptools.Button({
				name    : 'back',
				text    : 'zurück zum Login',
				width   : 200,
				onclick : function()
				{
					_nr.drop.close(true);
					_nr.login.show();
				}
			})
		);

		$('drop-container-buttons').style.marginLeft = '-200px';
	}
};

_nr.loader =
{
	start : function(text)
	{
		_nr.background.show();

		if (!$('loader')) {
			return
		};

		if (typeof text == 'undefined') {
			text = '<div style="margin-top: 50px; text-align: center;">Bitte warten ...</div>';
		};

		$('loader').style.display = '';
		$('loader').innerHTML     = text;
	},

	stop : function(nohide)
	{
		if ($('loader'))
		{
			$('loader').style.display = 'none';
			$('loader').innerHTML     = '';
		};

		if (typeof nohide != 'undefined' && nohide == true) {
			return;
		};

		_nr.background.hide();
	}
};

_nr.background =
{
	show : function()
	{
		if (!$('BackgroundWindow'))
		{
			var oBG = document.createElement('div');

			var scrollWidth  = document.documentElement.scrollWidth;
			var scrollHeight = document.documentElement.scrollHeight;

			oBG.id  = 'BackgroundWindow';

			var style = oBG.style;
			style.backgroundColor = '#000';
			style.position   = 'fixed';
			style.MozOpacity = '0.6';
			style.width   = '100%';
			style.height  = '100%';
			style.top     = '0';
			style.left    = '0';
			style.zIndex  = 1000;
			style.opacity = '0.6';
			style.filter  = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';

			document.body.appendChild(oBG);
		};

		$('BackgroundWindow').display = '';
	},

	hide : function()
	{
		if ($('BackgroundWindow')) {
			$('BackgroundWindow').parentNode.removeChild( $('BackgroundWindow') );
		};
	}
};

_nr.drop =
{
	show : function(onComplete, onCancel)
	{
		if (!$('drop-container')) {
			return;
		};

		if ($('drop-container').style.top == '200px')
		{
			onComplete();
			return;
		};

		_nr.background.show();

		//$('drop-container').style.top = '130px';
		$('drop-container').set('opacity', '0');
		$('drop-container').style.display = '';

		$('drop-container-buttons').innerHTML = '';

		this.appendButton(
			new _ptools.Button({
				text     : 'abbrechen',
				oncancel : onCancel,
				onclick  : function(Btn)
				{
					if (Btn.getAttribute('oncancel')) {
						Btn.getAttribute('oncancel')();
					};

					_nr.drop.close();
				}
			})
		);

		new Fx.Morph($('drop-container'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : onComplete
		}).start({
			opacity : 1
		});
	},

	close : function(nohide)
	{
		new Fx.Morph($('drop-container'), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function()
			{
				$('drop-container-content').innerHTML = '';

				$('drop-container-buttons').innerHTML   = '';
				$('drop-container-buttons').style.width = '';

				if (typeof nohide && nohide == true) {
					return;
				};

				_nr.background.hide();
			}
		}).start({
			opacity : 0
		});
	},

	setStyle : function(property, value)
	{
		switch (property)
		{
			case 'height':
			case 'width':
			break;

			default:
				return;
			break;
		};

		$('drop-container').setStyle(property, value);
	},

	clear : function()
	{
		$('drop-container-content').innerHTML = '';

		$('drop-container').setStyle('height', '');
		$('drop-container').setStyle('width', '');
	},

	appendButton : function(_Button)
	{
		var _width = $('drop-container-buttons').offsetWidth;

		$('drop-container-buttons').appendChild(
			_Button.create()
		);

		$('drop-container-buttons').style.width      = (_width + _Button.obj.offsetWidth) + 5 +'px';
		$('drop-container-buttons').style.marginLeft = '-'+ Math.round(($('drop-container-buttons').offsetWidth / 2)) +'px';
	},

	appendContent : function(obj)
	{
		$('drop-container-content').appendChild( obj );
	}
};

_nr.switchToolsSubMenu = function(elm)
{
	var uls = elm.parentNode.getElementsByTagName('ul');

	if (!uls[0]) {
		return false;
	};

	if (uls[0].style.display == 'none')
	{
		uls[0].style.display = '';
		elm.className = 'minus';

		return false;
	};

	uls[0].style.display = 'none';
	elm.className = 'plus';

	return false;
};

_nr.Bubble =
{
	o  : null,
	fx : null,

	active : null,

	show : function(text, elm)
	{
		if (this.active == elm) {
			return;
		};

		this.active = elm;

		if (!this.o)
		{
			var o = new Element('div');

			o.set('opacity', 0);

			o.className      = 'ToolTip';
			o.style.position = 'absolute';

			document.body.appendChild( o );

			this.o  = o;
			this.fx = new Fx.Morph($(this.o), {
				duration   : 500,
				transition : Fx.Transitions.Sine.easeOut
			});
		};

		var pos = _ptools._System.getElmPos(elm);

		this.fx.cancel();

		this.o.set('opacity', 0);
		this.o.innerHTML = text;

		this.o.style.top  = (pos.y-160) +'px';
		this.o.style.left = pos.x-40 +'px';

		this.fx.start({
		    opacity : 1,
		    top     : (pos.y-110)
		});

		var event = window.event;

		if (typeof event == 'undefined') {
			return false;
		};

		// Event Cancel
		if (typeof event.preventDefault == 'function')
		{
			event.preventDefault();
			event.stopPropagation();
		} else
		{
			event.returnValue = false;
		};


		return false;
	},

	hide : function()
	{
		this.active = null;

		if (!this.fx) {
			return;
		};

		this.fx.cancel();
		this.fx.start({
		    opacity : 0,
		    top     : parseInt(this.o.style.top)-30
		});
	}
};



/**
 * Seiten Funktionen
 */
function nrScrollTo(elm)
{
	if (elm.href.match('#top'))
	{
		new Fx.Scroll(document, {
		    duration : 500
		}).start(0, 0);

		return false;
	};

	$('startbox1').className = 'startbtnbox';
	$('startbox2').className = 'startbtnbox';
	$('startbox3').className = 'startbtnbox';


	var _FX = new Fx.Scroll(document, {
	    duration : 500
	});

	if (elm.href.match('#namerobot'))
	{
		_FX.start(0, 300);

		ActiveScroll = $('startbox1');

		// gelber kasten auf NR scrollen
		_nr.HeaderSlider.click( 1 );

	} else if (elm.href.match('#wie'))
	{
		_FX.start(0, 660);

		ActiveScroll = $('startbox2');


	} else if(elm.href.match('#genial'))
	{
		_FX.start(0, 960);

		ActiveScroll = $('startbox3');
	};

	ActiveScroll.className = 'startbtnbox active_btnbox';

	return false;
};

var genial =
{
	slide  : true,
	fx     : null,
	active : null,
	click  : false,

	next : function()
	{
		var lis  = $('genialnumbers').getElementsByTagName('li');
		var no   = parseInt( this.active.innerHTML );
		var next = lis[0];

		if (lis[no]) {
			next = lis[no]
		};

		this.scrollTo( next );
	},

	load : function()
	{
		var ul = $('genialtext').getElementsByTagName('ul')[0];
		var li = $('genialnumbers').getElementsByTagName('li')[0];

		this.fx = new Fx.Morph(ul, {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut
		});

		this.scrollTo( li );
	},

	onclick : function(elm)
	{
		this.click = true;
		this.scrollTo( elm );
	},

	scrollTo : function(elm)
	{
		if (this.active) {
			this.active.className = '';
		};

		var no = parseInt( elm.innerHTML );
		var ul = $('genialtext').getElementsByTagName('ul')[0];

		switch (no)
		{
			default:
			case 1:
				this.fx.start({top : 0});
			break;

			case 2:
				this.fx.start({top : -110});
			break;

			case 3:
				this.fx.start({top : -210});
			break;

			case 4:
				this.fx.start({top : -310});
			break;

			case 5:
				this.fx.start({top : -410});
			break;

			case 6:
				this.fx.start({top : -510});
			break;

			case 7:
				this.fx.start({top : -610});
			break;

			case 8:
				this.fx.start({top : -710});
			break;

			case 9:
				this.fx.start({top : -810});
			break;
		};

		this.active = elm;
		this.active.className = 'active';

		if (this.click == false)
		{
			function slideNext(e, add){
				genial.next();
			};

			slideNext.delay(4000);
		};
	}
};

function _nrload()
{
	if (typeof _nr != 'undefined') {
		_nr.load();
	};

	if (NR_LOGIN) {
		_nr.login.show();
	};

	if (typeof _nr.HeaderSlider != 'undefined') {
		_nr.HeaderSlider.load();
	};

    // NR Tracker
    if (typeof piwikTracker != 'undefined') {

      if(!User){
          piwikTracker.setCustomVariable(1,"NRUserType","Gast" );
      } else {
          piwikTracker.setCustomVariable(1,"NRUserType","User" );
          piwikTracker.setCustomVariable(3,"KNR",User.id);
      };
      piwikTracker.trackPageView();
    };


	zoom_image_loader();
};

function _nrunload()
{
	if (typeof _nr != 'undefined') {
		_nr.unload()
	};
};

