//theuntitled JavaScript Document

document.observe("dom:loaded", function() {
	if ($$('div.kategoriebox_Januar')) {
		$$('div.glossar_B, div.glossar_C, div.glossar_D, div.glossar_E, div.glossar_F, div.glossar_G, div.glossar_H, div.glossar_I, div.glossar_J, div.glossar_K, div.glossar_L, div.glossar_M, div.glossar_N, div.glossar_O, div.glossar_P, div.glossar_Q, div.glossar_R, div.glossar_S, div.glossar_T, div.glossar_U, div.glossar_V, div.glossar_W, div.glossar_X, div.glossar_Y, div.glossar_Z, div.glossar_misc').each(function(element) {
			element.hide();
		});
	}
	FormValues = new FormValues();
	/* Send a Friend */
	if ($("send-a-friend-status")) {
		sendAFriend();
	}
	updateTextbox();
	$('Message').observe('keydown', function() {
		updateTextbox();
	});
	$('Message').observe('keyup', function() {
		updateTextbox();
	});
});

var FormValues = function() {}

FormValues.prototype = {
	run: function() {
		that = this;
		$$('form').each(function(element) {
			element.getInputs('text').each(function(element) {
				that.observer(element, element.value);
			});
		});
	},
	observer: function(element, value) {
		Event.observe(element, 'focus', function() {
			if (value == element.value) {
				element.value = '';
			}
		});
		Event.observe(element, 'blur', function() {
			if (element.value == '') {
				element.value = value;
			}
		});
	},
	add: function(element, value) {
		this.observer(element, value);
	}
}

function loginCheck() {
	var fehler = new Array();
	if (!$F('Login')) {
		$('Login').setStyle({
			border: '1px solid #f00'
		});
		$('Login').value = 'Benutzername';
		FormValues.add($('Login'), 'Benutzername');
		fehler.push('Name');
	}
	if (!$F('Password')) {
		$('Password').setStyle({
			border: '1px solid #f00'
		});
		$('Password').value = 'Password';
		FormValues.add($('Password'), 'Password');
		fehler.push('Passwort');
	}
	if (fehler.length) {
		return false;
	} else {
		return true;
	}
}

function sendAFriend() {
	if ($("send-a-friend").getStyle("display") == "none") {
		Effect.BlindDown('send-a-friend', {
			duration: 0.5
		});
	} else {
		Effect.BlindUp('send-a-friend', {
			duration: 0.5
		});
	}
	setTimeout(function() {
		Effect.ScrollTo($("footer_container"));
	}, 600);
}

function newSendAFriend(reopen) {
	Effect.BlindUp("send-a-friend", {
		duration: 0.5,
		queue: {
			position: "end",
			scope: "sendafriend"
		},
		afterFinish: function() {
			$("send-a-friend-success").hide();
			$("send-a-friend-form").show();
		}
	});
	if (reopen) {
		Effect.BlindDown("send-a-friend", {
			duration: 0.5,
			queue: {
				position: "end",
				scope: "sendafriend"
			}
		});
	}
	setTimeout(function() {
		Effect.ScrollTo("footer_container", {
			afterFinish: function() {
				$("Recipient").value = "";
				$("Recipient").focus();
			}
		});
	}, (reopen) ? 1100 : 600);
	
}

function updateTextbox() {
	var maxLength = parseInt($("send-a-friend-maxlength").innerHTML);
	if ($("Message").value.length > maxLength) {
		$("Message").value = $('Message').value.substring(0, maxLength)
	}
	$('send-a-friend-messagelength').update('(' + $('Message').value.length + ' von ' + maxLength + ' Zeichen)');	
}

function toggleDealerSearchSelection() {
	var button = $("haendlersuche_auswahl_button");
	var overlay = $("haendlersuche_auswahl_layer");
	
	if (overlay.getStyle("display") == "none") {
		overlay.show();
		button.addClassName("btn_haendler_offen");
	} else {
		overlay.hide();
		button.removeClassName("btn_haendler_offen");
	}
	return false;
}