var productName;
var productCount;

function setProductName(name) {
	productName = name;
}

function setProductCount(count) {
	productCount = count;
}

/**
 * Ändert den Wert von nextStep, damit auch 
 * zurück geblättert werden kann während des 
 * Bestellvorgangs.
 * @param step
 */
function backTo(step) {
	var element = document.getElementById('nextStep');
	element.value = step;
}

/**
 * Übergibt an hidden-Input, wie viel nach dem Submit wieder
 * runter gescrollt werden muss.
 * @author Radoslaw Rudnicki
 * @version 1.0
 */
function initScroll() {
	var elements = document.getElementsByName('scroll');
	for (index = 0; index < elements.length; index++) {
		var element = elements[index];
		if (document.documentElement.scrollTop) {
			element.value = document.documentElement.scrollTop;
		} else {
			element.value = window.scrollY;
		}
	}
}

/**
 * Scroll die Seite nach unten um den Wert scrollY.
 * @author Radoslaw Rudnicki
 * @version 1.0
 * @param Integer scrollY
 * @param Boolean doSatinEffect
 */
function scrollDown(scrollY, doSatinEffect) {
	window.scroll(0, scrollY);
	if (doSatinEffect) {
		satinBackground(true);
	}
}

/**
 * Wird benutzt um vom Dialog zur Kasse zu kommen.
 * Dabei wird das Dialogfenster geschlossen und der Schleier ausgefadet.
 * @author Radosalw Rudnicki
 * @version 1.0
 */
function linkToCart() {
	fadeOut('satin', 0, 0.1, 40, 'warenkorb');
}

/**
 * Dunkelt den Hintergrund ab/auf.
 * @param enable
 */
function satinBackground(enable) {
	if (enable) {
		fadeIn('satin', 0.5, 0.1, 40);
	} else {
		fadeOut('satin', 0, 0.1, 40);
	}
}

var fadeInStatus = 'stop';
var fadeOutStatus = 'stop';
var opacity = 0;

/**
 * Fadet ein Element ein.
 * @author Radoslaw Rudnicki
 * @param String elementId
 * @param Double maxOpacity
 * @param Double stepOpacity
 * @param Integer timeout
 */
function fadeIn(elementId, maxOpacity, stepOpacity, timeout, dialogText) {
	var element = document.getElementById(elementId);
	
	if ('stop' == fadeInStatus && 'stop' == fadeOutStatus) {
		fadeInStatus = 'start';
		
		element.style.width = '100%';
		element.style.height = '100%';
		
		opacity = 0;
		
		element.style.opacity = opacity;
		element.style.filter="Alpha(opacity="+(opacity * 100)+")";
		
		setTimeout("fadeIn('"+elementId+"', "+maxOpacity+", "+stepOpacity+", "+timeout+")", timeout);
	} else if ('start' == fadeInStatus) {
		
		if (opacity < maxOpacity) {
			opacity = opacity + stepOpacity;
			
			if (opacity > maxOpacity) {
				opacity = maxOpacity;
			}
			
			element.style.opacity = opacity;
			element.style.filter="Alpha(opacity="+(opacity * 100)+")";
			
			setTimeout("fadeIn('"+elementId+"', "+maxOpacity+", "+stepOpacity+", "+timeout+")", timeout);
		} else {
			fadeInStatus = 'stop';
			
			// Projektspezifisch, Dialog öffnen, nach FadeIn.
			openDialog('dialog');
			ajax('php/ajaxDialogInfoCart.php?name='+productName+'&count='+productCount, 'dialog', 'images/ajaxLoading.gif', 50);
		}
	}
}

/**
 * Fadet ein Element aus.
 * @author Radoslaw Rudnicki
 * @version 1.0
 * @param String elementId
 * @param Double minOpacity
 * @param Double stepOpacity
 * @param Integer timeout
 */
function fadeOut(elementId, minOpacity, stepOpacity, timeout, link) {
	var element = document.getElementById(elementId);
	
	if ('stop' == fadeOutStatus && 'stop' == fadeInStatus) {
		// Projektspezifisch, Dialog schließen, wenn FadeOut.
		closeDialog('dialog');
		
		fadeOutStatus = 'start';
		opacity = element.style.opacity;
		
		element.style.opacity = opacity;
		element.style.filter="Alpha(opacity="+(opacity * 100)+")";
		
		setTimeout("fadeOut('"+elementId+"', "+minOpacity+", "+stepOpacity+", "+timeout+", '"+link+"')", timeout);
	} else if ('start' == fadeOutStatus) {
		if (opacity > minOpacity) {
			opacity = opacity - stepOpacity;
			
			if (opacity < minOpacity) {
				opacity = minOpacity;
			}
			
			element.style.opacity = opacity;
			element.style.filter="Alpha(opacity="+(opacity * 100)+")";
			
			setTimeout("fadeOut('"+elementId+"', "+minOpacity+", "+stepOpacity+", "+timeout+", '"+link+"')", timeout);
		} else {
			fadeOutStatus = 'stop';
			
			element.style.width = '0px';
			element.style.height = '0px';
			
			if ('undefined' != link && link) {
				self.location.href = link;
			}
		}
	}
}

