/* main Navigation */
function mainmenu()
{
	$("#mainNavigation ul").css(
		{
			display: "none"
		}
	);
	$("#mainNavigation li").hover(
		function()
		{
			$(this).find('ul:first').slideDown(100);
		},
		function()
		{
			$(this).find('ul:first').slideUp(100);
		}
	);
}

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};

/* encrypted email for each class "encryptedEmailLink" */
(function($) {
$.fn.yasp = function () {
	$(this).each(function () {
		var textAsASCII = '&#'+$(this).text().replace(/[,]+/g, ";&#")+';';
		if (this.href=='mailto:') 
			$(this).replaceWith('<a href="mailto:'+textAsASCII+'">'+textAsASCII+'</a>');
		else
			$(this).replaceWith(textAsASCII);
	});	
};
})(jQuery);

$(document).ready(function() { 

	// hauptnavigation
	mainmenu();

	// emails verschluesselt ausgeben
	$('.encryptedEmailLink').yasp();

	// footer image mouseover
	$(".bookmark_image").hover(function(){this.src = this.src.replace("_off.","_on.");}, function(){this.src = this.src.replace("_on.","_off.");});
	
	// hide errorbox on click
	$(".errorbox").click(function(e){
		$(this).hide();
	});

	// Blink Errorbox
	$(".errorbox").each(function () {
		var style = ""; if ($(this).attr("style")) style = $(this).attr("style");
		var display = ""; if ($(this).css("display")) display = $(this).css("display");
		if (
			$(this).is(':visible') && 
			display != "none" && 
			!style.indexOf("display: none")>-1 &&
			!style.indexOf("display:none")>-1
		) 
		{
			$(this).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
		}
	});
	
	// hide selectboxes and cluetip on body click
	$('body').click(function() {
		$('#cluetip').hide();
	});

	// Bonusprogramm Login
	$('#login_submit').click(function(e){
		e.preventDefault();
		var email = $("#login_email").attr('value');
		var password = $("#login_password").attr('value');
		$.ajax({
			type: "POST",
			timeout: 7000,
			data: {email: email, password: password},
			url: "inc_loadAjaxContent.php?expressLogin",
			success: function(result) {
				if(result == "false") {
					$("#login_messages2").html('<div class="errorbox" onclick="this.style.display=\'none\'"><p>Diese E-Mail/Passwort Kombination gibt es nicht in der STARCAR Datenbank, oder Sie haben Ihre E-Mail-Adresse noch nicht bestätigt. Sie können sich <a href="bonusprogramm_passwort_vergessen.php"><u>hier</u></a> Ihr aktuelles Passwort zuschicken lassen.</p><p class="right"><u><a href="" onclick="return false">schliessen</a></u></p><div class="clear"></div></div>');
				}
				else {
					$("#login_form_container").hide();
					$("#logout_ok_container").hide();
					$("#login_ok_container").show();
					$("#login_messages").html(result);
				}
			}
		})
	});

	// Express Logout
	$('#logout_submit').click(function(e){
		e.preventDefault();
		$.ajax({
			type: "POST",
			timeout: 7000,
			url: "inc_loadAjaxContent.php?expressLogout",
			success: function(result) {
				if(result === "true") {
					$("#login_ok_container").hide();
					$("#logout_ok_container").show();
					$("#login_form_container").show();
				}
			}
		})
	});
	
	
});

function goto (url) 
{
	document.location.href = url;
	return false;
}

function openWin(url, title, width, height) {
	var openWin = window.open(url, title, 'width='+width+', height='+height+', location=0, directories=0, status=0, toolbar=0, scrollbars=0, resizable=0, screenX='+this.screenX+',  screenY='+this.screenY+', scrolling=no');
	openWin.focus();
}

function openWinResize(url, title, width, height) {
	var openWin = window.open(url, title, 'width='+width+', height='+height+', location=0, directories=0, status=0, toolbar=0, scrollbars=1, resizable=1, screenX='+this.screenX+',  screenY='+this.screenY+', scrolling=no');
	openWin.focus();
}

function openAgb(url, title, width, height) {
	var openWin = window.open(url, title, 'width='+width+', height='+height+', location=0, directories=0, status=0, toolbar=0, scrollbars=yes, screenX='+this.screenX+',  screenY='+this.screenY);
	openWin.focus();
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	//if(cents=='00') cents='-';
	return (((sign)?'':'-') + '&euro; ' + num + ',' + cents);
}

function addToGermanDate(strDatum, anzahlTage) 
{
	// strDatum = 10.10.09
	arrDatum = strDatum.split('.');
	jahr = 1*arrDatum[2]; if (jahr < 999) jahr += 1900;

	startdatum = new Date(jahr, (1*arrDatum[1])-1, 1*arrDatum[0]);
	datum = new Date(startdatum.getTime() + (24 * 60 * 60 * 1000));

	jahr = datum.getYear(); if (jahr<10) jahr = '0'+jahr;
	monat = datum.getMonth()+1; if (monat<10) monat = '0'+monat;
	tag = datum.getDate(); if (tag<10) tag = '0'+tag;

	return (tag + '.' + monat + '.' + jahr);
}