
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

//0 means disabled; 1 means enabled;
var jpopupStatus = 0;

//loading popup

function jpopupLoad(jpopupTitle, noIeBackground, altClass, altWidth)
{
	var jpopupTitle;
	var noIeBackground;
	var altClass;

	if(jpopupStatus==0)
	{
		$j(".jpopup-header-title").html(jpopupTitle);
		if(noIeBackground == 1)
		{
			jQuery.each(jQuery.browser, function(i) {
				if(!$j.browser.msie){
					$j(".jpopup-background").fadeIn(200);
				}
			});
		}
		else
		{
			$j(".jpopup-background").fadeIn(200);
		}
		$j(".jpopup").fadeIn(200);

		if(altClass != '')
		{
			$j(".jpopup").addClass(altClass);
		}

		// 20100420 mb: neu für nfcvideo
		var altWidth;
		if(altWidth != '')
		{
			$j(".jpopup").css('width',altWidth);
		}

		jpopupStatus = 1;
	}
}

//disabling popup
function jpopupDisable()
{
	// 20100420 mb: neu für nfcvideo
	$j(".jpopup video").remove();
	$j(".jpopup audio").remove();

	if(jpopupStatus==1)
	{
		$j(".jpopup-background").fadeOut(200);
		$j(".jpopup").fadeOut(200);
		jpopupStatus = 0;
	}
}

//centering popup
function jpopupCenter(pWidth)
{
	var pWidth;
	//request data for centering
	var windowWidth = $j(window).width();
	var windowHeight = $j(window).height();
	var popupHeight = $j(".jpopup").height();
	var popupWidth = $j(".jpopup").width();
	var scrollTop = $j(window).scrollTop();

	if(pWidth > 0) { popupWidth = pWidth; }

	//centering
	$j(".jpopup").css
	(
		{
			"position": "absolute",
			"top": (scrollTop+50),
			"left": windowWidth/2-popupWidth/2
		}
	);
	//only need force for IE
	$j.each
	(
		$j.browser, function(i,val)
		{
			if( i == 'msie' && val == true && $j.browser.version.substr(0,1) <= 8)
			{
				$j(".jpopup-background").css
				(
					{
						"height": windowHeight + scrollTop,
						"display": "none"
					}
				);
			}
		}
	);
}

	/*** selectVariations ***/
	/**
 * simulate a dropdown select box
 */
function selectVariations()
{
	$j('.product-view-variations-list li').click
			(
			function()
			{
				$j("[input[name='products_variations_id']").val($j(this).attr("class"));
				$j('.product-view-variations .newListSelected').html($j(this).html());
				$j(this).parent().hide();
				return false;
			}
	);
}

function jpopupAddProduct(pageId, productsId, variations_id)
{
	var pageId;
	var productsId;
	var bol_productVariation;
	var productsVariationsId;

	if(variations_id >= 0){
		productsVariationsId = variations_id;
	}

	jpopupCenter(880);
	jpopupLoad('', 1);
	jpopupLoading();

	if(productsId > 0)
	{
		var productsIdGet = "&tx_nfcshop_pi1[products_id]="+productsId;
		var productsVariationsIdGet = productsVariationsId > 0 ? "&tx_nfcshop_pi1[products_variations_id]="+productsVariationsId : "";
		$j.ajax
		(
			{
				type: "POST",
				//timeout: 7000,
				data: {},
				url: "index.php?id="+pageId+"&type=576&tx_nfcshop_pi1[action]=AJAX_ADD_CART"+productsIdGet+productsVariationsIdGet,
				success: function(result)
				{
					$j(".jpopup-content").html(result);
					selectVariations();
				},
				error:function (xhr, ajaxOptions, thrownError)
				{
					console.log(xhr.status);
					console.log(ajaxOptions);
					console.log(thrownError);
				}
			}
		);
	}
	return false;
}


/**
 * Comment
 */

function jpopupRecommendationForm(pageId, area, shopId, productsId, productName, productImage)
{
	var pageId;
	var area;
	var shopId;
	var productsId;
	var productImage;
	var productName;
	var action = 'AJAX_MAIL_RECOMMENDATION';
	var type = '576';

	jpopupCenter();
	jpopupLoad('', 1);
	jpopupLoading();

	jpopupStatus = 1;

	$j.ajax
	(
		{
			type: 'POST',
			url: "index.php?id="+pageId,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data:
			{
				productsId: productsId,
				shopId: shopId,
				area: area,
				productImage: productImage,
				productName: productName,
				'tx_nfcshop_pi1[action]': action,
				type: type
			},
			success:
				function (outputText, textStatus)
				{
					if(outputText)
					{
						$j(".jpopup-content").html(outputText);
					}
				}
		}
	);
}

function sendRecommendation(shopId, area, productId, obj)
{
	var shopId;
	var area;
	var productId;
	var inputFields;
	var formValues = new Array();
	var obj_php = "";
	var total = 0;

	$j('.error').remove();

	for(i=0; i <obj.childNodes.length; i++)
	{
		if(obj.childNodes[i].tagName == "INPUT")
		{
			if(obj.childNodes[i].type == "text")
			{
				++ total;
				obj_php = obj_php + "s:" +
				String(obj.childNodes[i].name).length + ":\"" + String(obj.childNodes[i].name) + "\";s:" +
				String(obj.childNodes[i].value).length + ":\"" + String(obj.childNodes[i].value) + "\";";
			}
		}
	}
	obj_php = "a:" + total + ":{" + obj_php + "}";

	$j.ajax
	(
		{
			type: 'POST',
			url: 'index.php?eID=tx_nfcshop_recommendation_send',
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data:
			{
				shopId: shopId,
				area: area,
				productId: productId,
				obj_php: obj_php
			},
			success:
				function (outputText, textStatus)
				{
					if(outputText)
					{
						var output = outputText.split('|');
						var counter = 0;
						for(var i = 0; i < output.length; i++)
						{
							var failure_pos = output[i].search(/_failure/);
							if(failure_pos >= 0)
							{
								var formtag = output[i].substr(0, failure_pos);
								$j('.recommendation_'+formtag+'_input').after('<span class="error">X</span>');
								++ counter;
							}
						}

						if(counter == 0)
						{
							//console.log(outputText);
							$j(".jpopup-content").html('<div class="recommendation_success">'+outputText+'</div>');
							setTimeout("jpopupDisable()", 2000);
						}
						else
						{
							console.log('ERROR');
						}
					}
				}
		}
	);
}

function jpopupPriceAlertForm(pageId, area, shopId, productsId, productName, productImage)
{
	var pageId;
	var area;
	var shopId;
	var productsId;
	var productImage;
	var productName;
	var action = 'AJAX_MAIL_PRICEALERT';
	var type = '576';

	jpopupCenter();
	jpopupLoad('', 1);
	jpopupLoading();

	jpopupStatus = 1;

	$j.ajax
	(
		{
			type: 'POST',
			url: "index.php?id="+pageId,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data:
			{
				productsId: productsId,
				shopId: shopId,
				area: area,
				productImage: productImage,
				productName: productName,
				'tx_nfcshop_pi1[action]': action,
				type: type
			},
			success:
				function (outputText, textStatus)
				{
					if(outputText)
					{
						$j(".jpopup-content").html(outputText);
					}
				}
		}
	);
}

function sendPriceAlert(shopId, area, productId, obj)
{
	var shopId;
	var area;
	var productId;
	var inputFields;
	var formValues = new Array();
	var obj_php = "";
	var total = 0;
	var value = '';
	var text = ''

	$j('.error').remove();

	for(i=0; i <obj.childNodes.length; i++)
	{
		jQuery.parseJSON()
		value = '';
		if(obj.childNodes[i].tagName == "INPUT")
		{
			if(obj.childNodes[i].type == "text")
			{
				text = obj.childNodes[i].value;
				text = text.replace(/\u20ac/g, '&euro;');
				++ total;
				obj_php = obj_php + "s:" +
				String(obj.childNodes[i].name).length + ":\"" + String(obj.childNodes[i].name) + "\";s:" +
				String(text).length + ":\"" + String(text) + "\";";
			}
			else if(obj.childNodes[i].type == "checkbox")
			{
				++ total;
				if(obj.childNodes[i].checked)
				{
					value = 'Ja';
				}
				obj_php = obj_php + "s:" +
				String(obj.childNodes[i].name).length + ":\"" + String(obj.childNodes[i].name) + "\";s:" +
				String(value).length + ":\"" + String(value) + "\";";
			}
		}
		else if(obj.childNodes[i].tagName == "TEXTAREA")
		{
			++ total;
			obj_php = obj_php + "s:" +
			String(obj.childNodes[i].name).length + ":\"" + String(obj.childNodes[i].name) + "\";s:" +
			String(obj.childNodes[i].value).length + ":\"" + String(obj.childNodes[i].value) + "\";";
		}
		else if(obj.childNodes[i].tagName == "SELECT")
		{
			++ total;
			if(obj.childNodes[i].value != '')
			{
				value = obj.childNodes[i].value;
			}
			obj_php = obj_php + "s:" +
			String(obj.childNodes[i].name).length + ":\"" + String(obj.childNodes[i].name) + "\";s:" +
			String(value).length + ":\"" + String(value) + "\";";
		}
	}
	obj_php = "a:" + total + ":{" + obj_php + "}";

	$j.ajax
	(
		{
			type: 'POST',
			url: 'index.php?eID=tx_nfcshop_price_alert_send',
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data:
			{
				shopId: shopId,
				area: area,
				productId: productId,
				obj_php: obj_php
			},
			success:
				function (outputText, textStatus)
				{
					try
					{
						var counter = 0; // pre-initialization

						if( outputText )
						{
							if(outputText.search('_') > 0) {
								var output = outputText.split('|');
								for(var i = 0; i < output.length; i++)
								{
									var failure_pos = output[i].search(/_failure/);
									if(failure_pos >= 0)
									{
										var formtag = output[i].substr(0, failure_pos);
										$j('.priceAlert_'+formtag+'_input').after('<span class="error">X</span>');
										++ counter;
									}
								}
							}
							else if (outputText.search('<b>') > 0)
							{
								$j('.priceAlert_my_email').css('color', 'red');
								$j('.priceAlert_my_email_input').after('<br /><span class="error" style="padding-left:0px">'+outputText+'</span><br />');
								++ counter;
							}

						}

						if(counter == 0) // if no errors occured, show user success message
						{
							$j( '.jpopup-content' ).html('<div class="priceAlert_success">' + $j( '.successMessage' ).text() + '</div>');
							setTimeout("jpopupDisable()", 5000);
							$j( '.alarm' ).hide( 100 ); // hide button for price alert!
						}

					}
					catch( e )
					{
						// console.log( 'error: ' + e );
					}
				}
		}
	);
}

function priceAlertAGB(){
//	jQuery('#agb').slideToggle(300);
//	return false;
}


function jpopupLoading()
{
	$j(".jpopup-content").html('<div style="text-align: center"><img src="fileadmin/_global/graphics/icons/loading.gif" /></div>');
}


function jpopupLoadingText(text)
{
	$j(".jpopup-content").html('<div style="text-align: center"><img src="fileadmin/_global/graphics/icons/loading.gif" /></div><div style="text-align: center">'+text+'</div>');
}




/*** TOOLTIP ***/
//0 means disabled; 1 means enabled;
var jtooltipStatus = 0;

function jtooltipLoad(jtooltipTitle)
{
	var jtooltipTitle;

	if(jtooltipStatus==0)
	{
		$j("#jtooltip-content").html(jtooltipTitle);
		$j("#jtooltip").show();
		jtooltipStatus = 1;
	}
}


function jtooltipPosition(relativeX, relativeY)
{
	$j("#jtooltip").css
	(
		{
			"position": "absolute",
			"top": (relativeY),
			"left": relativeX,
			"z-index": 9999
		}
	);
}

//disabling tooltip
function jtooltipDisable()
{
	if(jtooltipStatus==1)
	{
		$j("#jtooltip").hide();
		jtooltipStatus = 0;
	}
}




var openLinkStatus = 0;

function openLink(domPath, addParams)
{
	var addParams = addParams ? addParams : '';
	var url = $j(domPath).attr("href") + addParams;
	if(openLinkStatus == 0)
	{
		openLinkStatus = 1;
		//console.log(url);
		window.location = url;
	}
}

function openLinkUrl(linkUrl)
{
	if(openLinkStatus == 0)
	{
		openLinkStatus = 1;
		//console.log(linkUrl);
		window.location = linkUrl;
	}
}

function openLinkUrlNewWindow(linkUrl){
	window.open(linkUrl, "_blank");
}

function jSwitchLayerVariations(value)
{
	if ($j(value).is(':hidden') )
	{
		$j(value).show();
	}
	else
	{
		$j(value).hide();
	}
}

function jSwitchLayer(value)
{
	if ($j(value).is(':hidden') )
	{
		$j(value).show();
	}
	else
	{
		$j(value).hide();
	}
}


/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};


/**
 * @comment			changed 20100312 by Markus Brunner -> extension access for new classes
 * @param int id 		layer id number
 * @param int elements	number of elements
 * @param string extension	extension css-class prefix e.g. 'nfc-shippingpages-'
 */
function LayerOff(id, elements, extension)
{
	for(i=1; i<=elements; i++)
	{
		if(id != i)
		{
			if(document.getElementById(extension+'layer-'+i))
			{
				document.getElementById(extension+'layer-'+i).style.display = 'none';
				document.getElementById(extension+'tab-'+i).className = extension+'tab';
			}
		}
		else
		{
			document.getElementById(extension+'layer-'+id).style.display = 'block';
			document.getElementById(extension+'tab-'+id).className = extension+'tab-active';
		}
	}
}


function array_key_exists ( key, search )
{
	// Checks if the given key or index exists in the array
	// version: 909.322
	// discuss at: http://phpjs.org/functions/array_key_exists
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
	if (!search || (search.constructor !== Array && search.constructor !== Object))
	{
			return false;
	}
	return key in search;
}

// mb: flyouttree-additional-columns BEGIN
var flyoutTreeAdditionalColumns = jClass.extend({
	appName:'flyoutTreeAdditionalColumns',
	elements: null,
	options: {
		leftDistance: 236,
		colWidth: 193
	},
	init: function(elements, options) {
		var options = $j.extend(true,this.options,options);
		this.options = options;
		var nextLevelElements = $j(elements).find('ul.flyouttree-additional-columns');
		var nextLevelElementsCount = nextLevelElements.length;
		if(nextLevelElementsCount > 0) {
			var maximumColHeight = 0;
			nextLevelElements.each($j.shove(function(index,elem){
				var newLeftPosition = this.options.leftDistance + (parseInt(index) * this.options.colWidth);
				$j(elem).css({'left':newLeftPosition+'px','width':this.options.colWidth+'px'});
				var currentColHeight = $j(elem).outerHeight();
				if(currentColHeight > maximumColHeight) maximumColHeight = currentColHeight;
			}, this));
			if (maximumColHeight > 0) { nextLevelElements.css('height',maximumColHeight); }
		}
	}
});
// mb: flyouttree-additional-columns END

$j(document).ready(function()
{

	$j(".jquery-button").click
	(
		function()
		{
			jpopupCenter();
			return false;
		}
	);

	$j(".jpopup-close").click
	(
		function()
		{
			jpopupDisable();
			return false;
		}
	);

	$j(".jpopup-background").click
	(
		function()
		{
			jpopupDisable();
			return false;
		}
	);

	//Press Escape event!
	$j(document).keypress
	(
		function(e)
		{
			if(e.keyCode==27 && jpopupStatus==1)
			{
				jpopupDisable();
			}
		}
	);


	/*** TOOLTIP ***/
	$j(".jtooltip").mousemove
	(
		function(e)
		{
			var relativeX = e.pageX + 25;
			var relativeY = e.pageY + 5;

			var tooltipText = this.title;
			$j(this).removeAttr("title");

			jtooltipPosition(relativeX, relativeY);
			jtooltipLoad(tooltipText);

		}
	)

	$j(".jtooltip").mouseout
	(
		function()
		{
			this.title = $j("#jtooltip-content").html();
			jtooltipDisable();
		}
	)

	/*** ****/
	selectVariations();
	/*** flyout navigation PRODUKTE begin***/
	$j(".flyouttree li").hover(
		function () {
			$j(this).children("ul").show();
			/*
			 * separate columns initialization in eacht navigation_flyouts template:
			 * new flyoutTreeAdditionalColumns($j(this),{leftDistance: 236,colWidth: 193});
			 */
			var fl = $j(this).parents('.level_2').find('.item_2_childs');
			fl.removeClass();
			fl.addClass("flyout_level_2_highlight");
		},
		function(){
			$j(this).children("ul").hide();
			var fl = $j(this).parents('.level_2').find('.flyout_level_2_highlight');
			fl.removeClass();
			fl.addClass("item_2_childs");
		}
	);
	/*** flyout navigation PRODUKTE end***/



	/*** flyout navigation PRODUKTE ***/
	$j(".navitree li").hover(
		function () {
			$j(this).children("ul.flyouttree-children").show();
			// mb: flyouttree-additional-columns BEGIN
			var leftDistance = 236;
			var colWidth = 250;
			var nextLevelElements = $j(this).find('ul.flyouttree-additional-columns');
			var nextLevelElementsCount = nextLevelElements.length;
			if(nextLevelElementsCount > 0) {
				var maximumColHeight = 0;
				nextLevelElements.each(function(index){
					var newLeftPosition = leftDistance + (parseInt(index) * colWidth);
					$j(this).css('left',newLeftPosition+'px');
					$j(this).css('width',colWidth+'px');
					var currentColHeight = $j(this).outerHeight();
					if(currentColHeight > maximumColHeight) maximumColHeight = currentColHeight;
				});
				if (maximumColHeight > 0) {nextLevelElements.css('height',maximumColHeight);}
			}
			// mb: flyouttree-additional-columns END
			var fl = $j(this).parents('.level_1').find('.item_1_childs');
			fl.removeClass();
			fl.addClass("flyout_level_1_highlight");
		},
		function(){
			$j(this).children("ul.flyouttree-children").hide();
			var fl = $j(this).parents('.level_1').find('.flyout_level_1_highlight');
			fl.removeClass();
			fl.addClass("item_1_childs");
		}
	);


	/*** flyout navigation mainnavigation begin ***/
	$j(".mainnavi li").hover(
		function (e) {
			/*** switch to flyout the navigation to the left site ***/
			var posEvent = e.pageX;
			if(posEvent > 950) $j(this).children("ul").addClass("flyout_left");
			if((posEvent < 950) && $j(this).children("ul").hasClass("flyout_left")) $j(this).children("ul").removeClass("flyout_left");
			/***/
			$j(this).children("div.flyout_level_1").addClass("hover");
			$j(this).children("div.flyout_level_1").children("div.a_level_1").children("a").addClass("hover_color_font");
			setRootline($j(this), $j(this).css('z-index'));

			return true;
		},
		function(){
			/*** remove style if flyout opens to the left site ***/
			if($j(this).children("ul").hasClass("flyout_left")) $j(this).children("ul").removeClass("flyout_left");
			/***/
			$j(this).children("div.flyout_level_1").removeClass("hover");
			$j(this).children("div.flyout_level_1").children("div.a_level_1").children("a").removeClass("hover_color_font");
			unsetRootline($j(this), $j(this).css('z-index'));

			return true;
		}
	);

	$j('.click_level_1').click(function() {
		$j("li.manu_level_1").children("ul").hide();
		alert('Handler for .click() called.');
	});

	function setRootline(e, zIndex) {
	var fl;

		if(zIndex >= 1502){
			fl = e.parents('.level_'+(zIndex-1)).find('.'+(zIndex-1));
			fl.removeClass();
			fl.addClass("flyout_highlight");

			setRootline(zIndex-1);
		}

		if(zIndex == 15){
			fl = e.parents('.level_1').find('.showArrow');
			fl.removeClass();
			fl.addClass("flyout_highlight");
		}

		return true;
	}

	function unsetRootline(e, zIndex) {
	var fl;

		if(zIndex >= 1502){
			fl = e.parents('.level_'+(zIndex-1)).find('.flyout_highlight');
			fl.removeClass();
			fl.addClass("showArrow "+(zIndex-1));

			unsetRootline(zIndex-1);
		}

		if(zIndex == 15){
			fl = e.parents('.level_1').find('.flyout_highlight');
			fl.removeClass();
			fl.addClass("showArrow");
		}

		return true;
	}
	/*** flyout navigation mainnavigation end ***/

	$j('.hideSellingPoints').hide();

	$j('.moreSellingPoints').click(
		function()
		{
			$j('.hideSellingPoints').toggle();
			$j('.moreSellingPoints').toggle();
			return false;
		}
	);

	$j('span.hideSellingPoints').click(
		function()
		{
			$j('.hideSellingPoints').toggle();
			$j('.moreSellingPoints').toggle();
			return false;
		}
	);

	/* Ajax Load */
	var ajaxUrl = $j('#ajaxFrame').attr('class');
	$j('#ajaxFrame').load(ajaxUrl,function(response, status, xhr) {
		if(status != 'error')
		{
			if($j('#accordionCrossRatings div').length != 0)
			{
				$j('.jQueryNoRatingsAvailable').remove();
				$j('#accordionRatings').accordion({
					icons:icons,
					autoHeight: false,
					collapsible:true
				});
				$j('#accordionCrossRatings').accordion({
					icons:icons,
					autoHeight: false,
					collapsible:true
				});
			}
			else
			{
				$j('#accordionRatings').accordion({
					icons:icons,
					autoHeight: false,
					collapsible:true
				});
			}

			var lenDivs = $j('#accordionCrossRatings .ratings-title').length;
			var icons = {
				header: "openArrow",
				headerSelected: "closeArrow"
			};
			for(var i = 0;i<=lenDivs;i++)
			{
				$j('#accordionCrossRatings .ratings-title').eq(i).appendTo($j('#accordionRatings'));
				$j('#accordionCrossRatings .ratings-content').eq(i).appendTo($j('#accordionRatings'));
			}
		}
	});

	// Star-Rating-System
	try {
            $j("input.star").rating('select');
        } catch(e) {
            
        }

	// Slider-Rating-System
	var countSliders = $j('.ratings_SLIDERS').length;
	for(var i = 1;i<= countSliders;i++)
	{
		$j('.ratingsSlidersID'+i+' .slider_rating').slider({
			value: 50,
			min: 1,
			max: 100
		});
	}
});

/**
 * function for slideable login header
 * @date 		20100324
 * @author 	Markus Brunner
 */
function displaySlidableLogin(initialHeight,closedButtonPath,openButtonPath,closedButtonTop,openButtonTop,layerOpacity) {
	if(initialHeight == '') { initialHeight = '-83px'; }
	if(closedButtonTop == '') { closedButtonTop = '-1px'; }
	if(openButtonTop == '') { openButtonTop = '-1px'; }
	if(layerOpacity == '') { layerOpacity = '1.0'; }

	/* initial positioning */
	$j('#top-login-div-wrapper').show().css({'top':initialHeight});
	$j('#login-togglebutton').attr('src',closedButtonPath);
	$j('#open-login-div').css('top',closedButtonTop);

	/* initial opcity: opacity:0.9;filter:alpha(opacity=90); */
	$j("#top-login-div").show().css({'opacity':layerOpacity});

	/* click-action for open-button */
	$j("#open-login-div").click(
		function(){
			/* std: $j('#top-login-div').slideToggle("slow");*/
			if($j('#top-login-div-wrapper').css('top') == initialHeight) {
				$j('#login-togglebutton').attr('src',openButtonPath);
				$j('#open-login-div').css('top',openButtonTop);
				$j('#top-login-div-wrapper').animate(
					{top: '0px'},500,'swing'
				);
			} else {
				$j('#login-togglebutton').attr('src',closedButtonPath);
				$j('#open-login-div').css('top',closedButtonTop);
				$j('#top-login-div-wrapper').animate(
					{top: initialHeight},500,'swing'
				);
			}
		}
	);

	/* click-action for close-button */
	$j("#close-login-div").click(
		function(){
			/* std: $j('#top-login-div').slideUp("slow");*/
			$j('#login-togglebutton').attr('src',closedButtonPath);
			$j('#open-login-div').css('top',closedButtonTop);
			$j('#top-login-div-wrapper').animate(
				{top: initialHeight},500,'swing'
			);
		}
	);
}

function changeProductsPerPage(int_productsPerPage)
{
	var query = window.location.search.substring(1);

	if(query.length == 0)
	{
		self.location.href = window.location.href + '?ppp=' + int_productsPerPage;
	}
	else
	{
		var vars = query.split("&");
		var newquery = "";
		var isppp = false;
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == "ppp") {
				pair[1] = int_productsPerPage;
				isppp = true;
			}
			if (newquery.length > 0)
			{
				newquery += "&";
			}
			newquery += pair[0] + "=" + pair[1];
		}
		if (isppp == false)
		{
			newquery = "ppp=" + int_productsPerPage + "&" + newquery;
		}

		self.location.href = window.location.href.substring(0, window.location.href.indexOf('?')+1) + newquery;
	}
}

function changeDeliveryAddress(id_address, id_current)
{
	var id_address;
	var id_current;

	if(id_address == 0)
	{
		return false;
	}

	$j('.checkout-shipping-address-col1').html('<div style="text-align: center; margin-top:30px"><img src="fileadmin/_global/graphics/icons/loading.gif" /></div>');

	$j.ajax
	(
		{
			type: 'POST',
			url: 'index.php?eID=tx_nfcshop_change_delivery_address',
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data:
			{
				id_address: id_address,
				id_current: id_current
			},
			success:
				function (outputText, textStatus)
				{
					$j('.checkout-shipping-address-col1').html(outputText);
				}
		}
	);
}

/**
 * Setzt die Anzahl der Produkt je Seite in ein Cookie
 */
function setProductsPerPage(ppp, href) {
	$j.cookie("ProductsPerPage", ppp, { path: "/", expires: 0 });
	document.location.href=href;
}

/**
 * Setzt die Sortieunrg der Produktliste in ein Cookie
 */
function setProductslistSorting(sorting, href) {
	$j.cookie("ProductslistSorting", sorting, { path: "/", expires: 0 });
	document.location.href=href.replace(/page=[0-9][0-9]?[0-9]?/g,'page=0');
}

/**
 * Setzt den ViewType fÃ¼r die Darstellung der Produktliste in ein Cookie
 */
function setProductslistViewType(viewType, href) {
	$j.cookie("ProductslistViewType", viewType, { path: "/", expires: 0 });
	document.location.href=href;
}



/**
 * Ajax Login fÃ¼r den Proxy
 */
function ajaxLogin(pid, redirect) {
	jQuery.ajax({
		type: "POST",
		dataType: 'json',
		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		data: {
			ajax: 1,
			user: jQuery('#tx-newloginbox-pi1-user').val(),
			pass: jQuery('#password').val(),
			logintype: 'login',
			pid: pid,
			redirect_url: redirect,
			submit: jQuery('#tx-newloginbox-pi1-login_submit').val()

		},
		url: "index.php?eID=felogin_ajax",
		success: function(result) {
			if(result != null && result.data.error == 1) {
				ajaxLoginError(result);
			}
			else if(result != null) {
				ajaxLoginOutputData(result);
				ajaxCallShoppingCart();
			}
		},
		error: function (e) {
//			console.log('error: ' + e.message);
		}
	});
}

function ajaxLoginOutputData(datas) {
	$j('errormsg').hide();
	$j('.tx-felogin-pi1').html(datas.data.html);
	$j('#top-login-div-wrapper').css({
		'display': 'block',
		'top': '0px'
	});
	$j('#top-login-div').css({
		'display': 'block',
		'opacity': 1
	});
	displaySlidableLogin(datas.data.ajaxJS.initialHeight,datas.data.ajaxJS.closedButtonPath,datas.data.ajaxJS.openButtonPath,datas.data.ajaxJS.closedButtonTop,datas.data.ajaxJS.openButtonTop,datas.data.ajaxJS.layerOpacity)
	$j('#top-login-div-wrapper').css({'top':'0px'});
	$j('#login-togglebutton').attr('src', datas.data.ajaxJS.openButtonPath);
}

function ajaxLoginError(e) {
	// Hier wird die Fehlermeldung ausgegeben
	$j('.errormsg').show();
}
