var myShopFavoritesRefresh = false;
var myShopBoughtArticlesRefresh = true;
var myShopOrdersRefresh = true;

var quickorder_row = 3;
/**
 * calls shop action in a ajax request to add products to cart
 * 
 * @param productId
 * @param quantity
 * @return
 */
function addProductToCart(productId, linkObj, fieldPrefix)
{
	var fieldPrefix = fieldPrefix ? fieldPrefix + '_' : '';
		
	var quantity = document.getElementById(fieldPrefix + 'quantity_' + productId).value;
	if (quantity == '')
	{
		document.getElementById(fieldPrefix + 'quantity_'+productId).value = 1;
		quantity = 1;
	}

	// make some nice flubbel here
	document.getElementById(fieldPrefix + 'quantity_' + productId).disabled = 'disabled';
	Element.addClassName(linkObj, 'articletable_basket_loader');
	
	var params = 'shop.cart['+productId+'][artlink]='+productId+'&shop.cart['+productId+'][artcount]='+quantity;
	var postUrl = absCorrect+'shop/components/ajax_addToCart.html';

	var req = new Ajax.Request(postUrl, {
		method: 'post',
		parameters: params,
		onComplete: function(transport)
	 	{
			res = eval(transport.responseText);
			document.getElementById('shop_basket_positions').getElementsByTagName('span')[0].innerHTML = res.totalcount;
			document.getElementById('shop_basket_price').getElementsByTagName('span')[0].innerHTML = res.totalincl;
			
			// remove the nice added flubbel here...
			document.getElementById(fieldPrefix + 'quantity_'+productId).disabled = '';
			Element.removeClassName(linkObj, 'articletable_basket_loader');
		}
	});

	return false;
}

/**
 * calls shop action in a ajax request to add products to cart and calls order page
 * 
 * @param productId
 * @param quantity
 * @return
 */
function addProductToCartFreetext(linkObj)
{
	var quantity = document.getElementById('shop.cart[ZETX][artcount]').value;
	if (quantity == '')
	{
		document.getElementById('shop.cart[ZETX][artcount]').value = 1;
		quantity = 1;
	}
	
	// make some nice flubbel here	
	Element.addClassName(linkObj, 'articletable_basket_loader');
	
	var form = Element.up(linkObj, 'FORM');
	var params = Form.serialize(form);
	var postUrl = absCorrect+'shop/components/ajax_addToCart.html';
	
	Form.disable(form);
	
	var req = new Ajax.Request(postUrl, {
		method: 'post',
		parameters: params,
		onSuccess: function(transport)
	 	{			
			window.location.href = absCorrect+'shop/cart.html';
		}
	});
	
	return false;
}

/**
 * calls shop action in a ajax request to add products to cart and calls order page
 * 
 * @param productId
 * @param quantity
 * @return
 */
function addProductToCartQuickOrder(nr, linkObj, fieldPrefix)
{
	var fieldPrefix = fieldPrefix ? fieldPrefix + '_' : 'quick_order_';
		
	var quantity = document.getElementById(fieldPrefix + 'quantity_' + nr).value;
	if (quantity == '')
	{
		document.getElementById(fieldPrefix + 'quantity_'+nr).value = 1;
		quantity = 1;
	}
	
	// make some nice flubbel here
	document.getElementById(fieldPrefix + 'quantity_' + nr).disabled = 'disabled';
	Element.addClassName(linkObj, 'articletable_basket_loader');
	
	productId = document.getElementById(fieldPrefix + 'id_' + nr).value;
	
	var params = 'shop.cart['+productId+'][artlink]='+productId+'&shop.cart['+productId+'][artcount]='+quantity;
	var postUrl = absCorrect+'shop/components/ajax_addToCartBySAP.html';
	
	var req = new Ajax.Request(postUrl, {
		method: 'post',
		parameters: params,
		onComplete: function(transport)
	 	{			
			res = eval(transport.responseText);
			if(res.error_nr)
			{
				document.getElementById(fieldPrefix + 'id_' + nr).value = "";
				alert("Produkt mit SAP Nummer " + res.error_nr + " wurde nicht gefunden!");
			}
			else
			{
				document.getElementById('shop_basket_positions').getElementsByTagName('span')[0].innerHTML = res.totalcount;
				document.getElementById('shop_basket_price').getElementsByTagName('span')[0].innerHTML = res.totalincl;
			}
			// remove the nice added flubbel here...
			document.getElementById(fieldPrefix + 'quantity_'+nr).disabled = '';
			Element.removeClassName(linkObj, 'articletable_basket_loader');
		}
	});
	
	return false;
}

function quickOrderAll()
{
	for(i=1;i<=quickorder_row;i++)
	{
		addProductToCartQuickOrder(i,document.getElementById("quick_order_button_"+i));
	}
}

function checkboxAlert(chkbox, msg)
{
	if (chkbox.checked != true)
	{
		alert(msg);
		return false;
	}
	
	return true;
}

function getPosition(el) {
	var r = { top:0, left:0, width:0, height:0 };
	if(!el) return r;
	else if(typeof el == 'string' ) el = $(el);
	if(typeof el != 'object' ) return r;
	if(typeof el.offsetTop != 'undefined') {
		r.height = el.offsetHeight;
		r.width = el.offsetWidth;
		r.left = r.top = 0;
		while (el && el.tagName != 'BODY')         {
			r.top  += parseInt( el.offsetTop );
			r.left += parseInt( el.offsetLeft );
			el = el.offsetParent;
		}
	}
	return r;
}

function checkForRelativePositionedElements(el) {
	var browserName = navigator.appName;
	var browserVersion = parseInt(navigator.appVersion);
	if (browserName == "Microsoft Internet Explorer" && browserVersion == 4 && navigator.appVersion.indexOf("MSIE 7.0") != -1 || navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var rels = $('shop_container').select('.articletable_info','.articletable_store','#tab_positioner');
		if(rels.length > 0) {
			var objLayer = getPosition(el);
			for(x=0;x<rels.length;x++) {
				var objRel = getPosition(rels[x]);
				if((objRel.left > objLayer.left && (objRel.left < (objLayer.left + objLayer.width))) && (objRel.top > objLayer.top && (objRel.top < (objLayer.top + objLayer.height)))) {
					rels[x].hide();
				}
				else
				{
					rels[x].show();
				}
			}
		}
	}
}

function restoreRelativePositionedElements() {
	var browserName = navigator.appName;
	var browserVersion = parseInt(navigator.appVersion);
	if (browserName == "Microsoft Internet Explorer" && browserVersion == 4 && navigator.appVersion.indexOf("MSIE 7.0") != -1 || navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var rels = $('shop_container').select('.articletable_info','.articletable_store','#tab_positioner');
		for(x=0;x<rels.length;x++) {
			if(rels[x].style.display == 'none') {
				rels[x].show();
			}
		}
	}
}

function showExpertSearch(element) {
	if($('shop_quickorder_loggedin').style.display!='none') {
		restoreRelativePositionedElements();
		new Effect.BlindUp('shop_quickorder_loggedin',{duration: 0.5,afterFinish: function(){
			new Effect.BlindDown('shop_expertsearch_loggedin',{duration: 0.5,afterFinish: function(){
				checkForRelativePositionedElements('shop_expertsearch_loggedin');
			}});
			element.className = 'shop_toggle_button_active';
		}});
		$('shop_quickorder_button').className = 'shop_toggle_button';
	}	else if($('shop_visited_pages').style.display!='none') {
			new Effect.BlindUp('shop_visited_pages',{duration: 0.5,afterFinish: function(){
				restoreRelativePositionedElements();
				new Effect.BlindDown('shop_expertsearch_loggedin',{duration: 0.5,afterFinish: function(){
					checkForRelativePositionedElements('shop_expertsearch_loggedin');
				}});
				element.className = 'shop_toggle_button_active';
		}});
		$('shop_lastviewed_button').className = 'shop_toggle_button';
	}	else if($('shop_expertsearch_loggedin').style.display=='none') {
		new Effect.BlindDown('shop_expertsearch_loggedin',{duration: 0.5,afterFinish: function(){
			checkForRelativePositionedElements('shop_expertsearch_loggedin');
		}});
		element.className = 'shop_toggle_button_active';
	} else {
		new Effect.BlindUp('shop_expertsearch_loggedin',{duration: 0.5});
		restoreRelativePositionedElements();
		element.className = 'shop_toggle_button';
	}
}
function hideExpertSearch() {
	$('shop_expertsearch_button').className = 'shop_toggle_button';
	new Effect.BlindUp('shop_expertsearch_loggedin',{duration: 0.5});
	restoreRelativePositionedElements();
}
function showQuickOrder(element) {
	if($('shop_expertsearch_loggedin').style.display!='none') {
		restoreRelativePositionedElements();
		new Effect.BlindUp('shop_expertsearch_loggedin',{duration: 0.5,afterFinish: function(){
				new Effect.BlindDown('shop_quickorder_loggedin',{duration: 0.5, afterFinish: function(){
					checkForRelativePositionedElements('shop_quickorder_loggedin');
				}});
				element.className = 'shop_toggle_button_active';
		}});
		$('shop_expertsearch_button').className = 'shop_toggle_button';
	}	else if($('shop_visited_pages').style.display!='none') {
		new Effect.BlindUp('shop_visited_pages',{duration: 0.5,afterFinish: function(){
				restoreRelativePositionedElements();
				new Effect.BlindDown('shop_quickorder_loggedin',{duration: 0.5, afterFinish: function(){
					checkForRelativePositionedElements('shop_quickorder_loggedin');
				}});
				element.className = 'shop_toggle_button_active';
		}});
		$('shop_lastviewed_button').className = 'shop_toggle_button';
	}	else if($('shop_quickorder_loggedin').style.display=='none') {
		new Effect.BlindDown('shop_quickorder_loggedin',{duration: 0.5, afterFinish: function(){
			checkForRelativePositionedElements('shop_quickorder_loggedin');
		}});
		element.className = 'shop_toggle_button_active';
	} else {
		new Effect.BlindUp('shop_quickorder_loggedin',{duration: 0.5});
		restoreRelativePositionedElements();
		element.className = 'shop_toggle_button';
	}
}
function hideQuickOrder() {
	$('shop_quickorder_button').className = 'shop_toggle_button';
	new Effect.BlindUp('shop_quickorder_loggedin',{duration: 0.5});
	restoreRelativePositionedElements();
}
function addQuickOrderRow() {
	newrow = "<tr id='quickorder_row_"+(quickorder_row+1)+"'><td><input type='text' id='quick_order_id_"+(quickorder_row+1)+"' class='textinput' style='width: 220px;' /></td><td><input type='text' id='quick_order_quantity_"+(quickorder_row+1)+"' class='textinput' style='width: 35px;' /></td><td><a id='quick_order_button_"+(quickorder_row+1)+"' class='articletable_basket_qo' href='#' onClick='return addProductToCartQuickOrder("+(quickorder_row+1)+", this)'></a></td></tr>";
	new Insertion.After($('quickorder_row_'+quickorder_row), newrow);
	quickorder_row++;
	checkForRelativePositionedElements('shop_quickorder_loggedin');
}
function showVisitedPages(element)
{
	if($('shop_expertsearch_loggedin').style.display!='none') {
		restoreRelativePositionedElements();
		new Effect.BlindUp('shop_expertsearch_loggedin',{duration: 0.5,afterFinish: function(){
				new Effect.BlindDown('shop_visited_pages',{duration: 0.5, afterFinish: function(){
					checkForRelativePositionedElements('shop_visited_pages');
				}});
				element.className = 'shop_toggle_button_active';
		}});
		$('shop_expertsearch_button').className = 'shop_toggle_button';
	} else if($('shop_quickorder_loggedin').style.display!='none') {
		restoreRelativePositionedElements();
		new Effect.BlindUp('shop_quickorder_loggedin',{duration: 0.5,afterFinish: function(){
				new Effect.BlindDown('shop_visited_pages',{duration: 0.5, afterFinish: function(){
					checkForRelativePositionedElements('shop_visited_pages');
				}});
				element.className = 'shop_toggle_button_active';
		}});
	$('shop_quickorder_button').className = 'shop_toggle_button';
	}	else if($('shop_visited_pages').style.display=='none') {
		new Effect.BlindDown('shop_visited_pages',{duration: 0.5, afterFinish: function(){
			checkForRelativePositionedElements('shop_visited_pages');
		}});
		element.className = 'shop_toggle_button_active';
	} else {
		new Effect.BlindUp('shop_visited_pages',{duration: 0.5});
		restoreRelativePositionedElements();
		element.className = 'shop_toggle_button';
	}
}
function hideVisitedPages()
{
	$('shop_lastviewed_button').className = 'shop_toggle_button';
	new Effect.BlindUp('shop_visited_pages',{duration: 0.5});
	restoreRelativePositionedElements();
}
function showTechnology() {
	if($('technology').style.display=='none') {
		$('technology').style.display='block';
		$('link_technology').style.display='block';
		$('btn_technology').className = 'shop_toggle_button_active';
		checkForRelativePositionedElements('shop_expertsearch_loggedin');
	} else {
		$('technology').style.display='none';
		$('link_technology').style.display='none';
		$('btn_technology').className = 'shop_toggle_button';
		checkForRelativePositionedElements('shop_expertsearch_loggedin');
	}
}
function showManufacturer() {
	if($('manufacturer').style.display=='none') {
		$('manufacturer').style.display='block';
		$('link_manufacturer').style.display='block';
		$('btn_manufacturer').className = 'shop_toggle_button_active';
		checkForRelativePositionedElements('shop_expertsearch_loggedin');
	} else {
		$('manufacturer').style.display='none';
		$('link_manufacturer').style.display='none';
		$('btn_manufacturer').className = 'shop_toggle_button';
		checkForRelativePositionedElements('shop_expertsearch_loggedin');
	}
}
function expandArticleTable(element) {
	if($('expander_label').innerHTML.indexOf('mehr')>-1) {
		$('expander_label').innerHTML = 'weniger';
		$('expander').className = 'expander_active';
		var tds = $('articletable').select('.invisible');
		var len = tds.length;
		for(x=0;x<len;x++) {
			tds[x].style.display = '';
		}
		new Ajax.Request(absCorrect+'shop/components/ajax_requests.html?pim.sess_productTableExpanded=1');
	} else {
		$('expander_label').innerHTML = 'mehr';
		$('expander').className = '';
		var tds = $('articletable').select('.invisible');
		var len = tds.length;
		for(x=0;x<len;x++) {
			tds[x].style.display = 'none';
		}
		new Ajax.Request(absCorrect+'shop/components/ajax_requests.html?pim.sess_productTableExpanded=0');
	}
}
function hideRows() {
	var trs = document.getElementsByClassName('byebye');
	for(x=0;x<trs.length;x++) {
		trs[x].style.display='none';
	}
}
function showStoreInfo(article,startup,showIn,available)
{
	if(showIn == 'productDetail')
	{
		if(available) var stock = 1;
		if(!available) var stock = 0;
		var amount = 1;
	}
	else
	{
		var stock = parseInt($('lagerstand_'+article).value);
		var amount = parseInt($('shop.cart['+article+'][artcount]').value);
	}

	if(stock < 1)
	{
		$('store_sign_'+article).setAttribute("class", "articletable_info");
		$('store_sign_'+article).setAttribute("className", "articletable_info");
		$('storeinfo_'+article).innerHTML = 'Liefertermin wird abgekl&auml;rt und schnellstm&ouml;glich mitgeteilt.';
	}
	else if(stock < amount)
	{
		$('store_sign_'+article).setAttribute("class", "articletable_info");
		$('store_sign_'+article).setAttribute("className", "articletable_info");
		$('storeinfo_'+article).innerHTML = 'Derzeit ist nicht die gesamte gew&uuml;nschte Menge verf&uuml;gbar. Wir nehmen schnellstm&ouml;glich mit Ihnen Kontakt auf.';
	}
	else
	{
		$('store_sign_'+article).setAttribute("class", "articletable_store");
		$('store_sign_'+article).setAttribute("className", "articletable_store");
		$('storeinfo_'+article).innerHTML = 'Bestellung bis 16:30 Uhr: Versand erfolgt heute.<br/>Zwischenverkauf vorbehalten.';
	}
	if(!startup) $('storeinfo_'+article).show();
}
function hideStoreInfo(article)
{
	$('storeinfo_'+article).hide();
}
// executes a link per ajax to the given target
function linkWrapper(linkObj,target,page)
{
	var targetpage = linkObj.href;
	if(page !== '')
	{
		targetpage = page;
	}
	
	new Ajax.Updater(target,targetpage,{ evalScripts: true });
	return false;
}
function formWrapper(formObj,target,page)
{
	var targetpage = formObj.action;
	if(page !== '')
	{
		targetpage = page;
	}
	
	new Ajax.Updater(target,targetpage,{evalScripts: true, method: 'post', postBody: Form.serialize(formObj) });
	return false;
}

/* scripts from the html prototype */
function toggleTab(active) {
	// get parent ul
	obj = active;
	while(obj.nodeName != 'UL') {
		obj = obj.parentNode;
	}
	// get all lis from ul
	listitems = obj.getElementsByTagName('li');
	// set all inactiv
	for(var i=0;i<listitems.length;i++) {
		document.getElementById(listitems[i].id+'_content').style.display = 'none';
		listitems[i].className = '';
	}
	// set active
	active.className = 'active';
	document.getElementById(active.id+'_content').style.display = 'block';
	return false;
}
function showLayer(theheading,thelink) {
	element = $(theheading);
	if(element.style.display=='none') {
		element.style.display='block';
		thelink.className='sidebox_21 max';
	} else if(element.style.display=='block') {
		element.style.display='none';
		thelink.className='sidebox_21 min';
	}
}
function showAlert() {
	return confirm('Wollen Sie diesen myShop-Eintrag wirklich entfernen?');
}

function saveAsFavorite(obj, uId, pId, action)
{
	if (typeof action == 'undefined')
	{
		action = 'add';
	}
	
	Element.addClassName(obj, 'articletable_basket_loader');
	
	if (action == 'add')	var url = absCorrect + 'shop/ajax_save_favorites.html';
	else					var url = absCorrect + 'shop/ajax_remove_favorites.html';
	new Ajax.Request(url, {
		method: 'post',
		parameters: { 'pim.userid': uId, 'pim.productid': pId },
		onComplete: function(transport)
		{
			if (action == 'add')
			{
				Element.removeClassName(obj, 'articletable_basket_loader');
				Element.addClassName(obj, 'articletable_favorite');
				
				$('fav_el_a'+pId).style.display = '';
				$('fav_el_b'+pId).style.display = 'none';
			}
			else
			{
				Element.removeClassName(obj, 'articletable_basket_loader');
				Element.addClassName(obj, 'articletable_isfavorite');
				$('fav_el_a'+pId).style.display = 'none';
				$('fav_el_b'+pId).style.display = '';
			}
		}
	});
	myShopFavoritesRefresh = true;
	return false;
}

function saveAllAsFavorites(uId, pIds)
{
	var url = absCorrect + 'shop/ajax_save_favorites.html';
	var products = pIds.split(',');
	
	for(var i = 0; i < products.length; i++)
	{		
		var pId = products[i];
		if(pId.length > 0)
		{
			new Ajax.Request(url, {
				method: 'post',
				parameters: { 'pim.userid': uId, 'pim.productid': pId }
			});
		}
	}
	return false;
}

function saveAllAsFavoritesBoughtArticles(button, selector)
{
	var favorites = Element.select(Element.up(button, 'table'), selector);
	for(var i = 0; i < favorites.length; i++)
	{
		// Execute onClick handler of each favorites button;
		favorites[i].onclick(favorites[i]);
	}
	return false;
}

function removeMyShopFavorite(updateId, uId, pId, removeAll)
{
	if (typeof removeAll == 'undefined') removeAll = false;
	
	if ((removeAll && confirm('Wollen Sie diesen myShop-Eintrag wirklich entfernen?')) ||
		(!removeAll && confirm('Wollen Sie alle Favoriten entfernen?')))
	{
		myShopFavoritesRefresh = true;
		myShopBoughtArticlesRefresh = true;
		
		var url = absCorrect + 'shop/ajax_remove_favorites.html';
		new Ajax.Request(url, {
				method: 'post',
				parameters: { 'pim.userid': uId, 'pim.productid': pId },
				onComplete: function(transport)
				{
					refreshMyShopFavorites(updateId);
				}
			});
	}
	return false;
}

function refreshMyShopFavorites(updateId)
{
	if(!myShopFavoritesRefresh)
		return;
	
	if($('refreshMyShopFavorites'))
		$('refreshMyShopFavorites').show();
	
	var url = absCorrect + 'shop/components/myShop_favorites.html';
	new Ajax.Updater(updateId, url, {
		evalScripts: true,
		onComplete: function(transport)
		{
			if($('refreshMyShopFavorites'))
				$('refreshMyShopFavorites').hide();
		}
	});
	myShopFavoritesRefresh = false;
}

function refreshMyShopOrders(updateId)
{
	if(!myShopOrdersRefresh)
		return;
	
	if($('refreshMyShopOrders'))
		$('refreshMyShopOrders').show();
	
	var url = absCorrect + 'shop/components/myShop_orders.html';
	new Ajax.Updater(updateId, url, {
		evalScripts: true,
		evalJS: true,
		onComplete: function(transport)
		{
			if($('refreshMyShopOrders'))
				$('refreshMyShopOrders').hide();
		}
	});
	myShopOrdersRefresh = false;
}

var boughtProducts = new Array();
function addProductsToCart(products, link, loader) {
	
	link.style.display = 'none';
	loader.style.display = '';

	var postUrl = absCorrect+'shop/components/ajax_addArToCart.html';
	var req = new Ajax.Request(postUrl, {
		method: 'post',
		parameters: products,
		onComplete: function(transport) {
			link.style.display = '';
			loader.style.display = 'none';
			res = eval(transport.responseText);
			document.getElementById('shop_basket_positions').getElementsByTagName('span')[0].innerHTML = res.totalcount;
			document.getElementById('shop_basket_price').getElementsByTagName('span')[0].innerHTML = res.totalincl;
		}
	});
}

function refreshMyShopBoughtArticles(updateId)
{
	if(!myShopBoughtArticlesRefresh)
		return;
	
	if($('refreshMyShopBoughtArticles'))
		$('refreshMyShopBoughtArticles').show();
	
	var url = absCorrect + 'shop/components/myShop_bought_articles.html';
	new Ajax.Updater(updateId, url, {
		evalScripts: true,
		onComplete: function(transport)
		{
			if($('refreshMyShopBoughtArticles'))
				$('refreshMyShopBoughtArticles').hide();
		}
	});
	myShopBoughtArticlesRefresh = false;
}

function filterMyShopBoughtArticles(select, updateId)
{
	if($('refreshMyShopBoughtArticles'))
		$('refreshMyShopBoughtArticles').show();
	
	var url = absCorrect + 'shop/components/myShop_bought_articles.html?shop.sess_filter_bought_articles=' + select.value;
	new Ajax.Updater(updateId, url, {
		evalScripts: true,
		onComplete: function(transport)
		{
			if($('refreshMyShopBoughtArticles'))				
				$('refreshMyShopBoughtArticles').hide();
		}
	});

	myShopBoughtArticlesRefresh = false;
}

function filterMyShopOrders(select, updateId)
{	
	if($('refreshMyShopOrders'))
		$('refreshMyShopOrders').show();
	
	var url = absCorrect + 'shop/components/myShop_orders.html?shop.sess_filter_orders=' + select.value;
	new Ajax.Updater(updateId, url, {
		evalScripts: true,
		onComplete: function(transport)
		{
			if($('refreshMyShopOrders'))
				$('refreshMyShopOrders').hide();
		}
	});

	myShopOrdersRefresh = false;
}

function expertSearchSupplierCheckboxClick(clickedElement)
{
	showExpertSearchSearchIndicator();
	var image = Element.down(clickedElement, 'img');
	if(Element.hasClassName(image, 'expertSearchCheckboxChecked'))
	{		
		expertSearchSetChecked(image, 'expertSearchCheckboxNotChecked', 'expertSearchCheckboxChecked', false);
	}
	else
	{		
		expertSearchSetChecked(image, 'expertSearchCheckboxChecked', 'expertSearchCheckboxNotChecked', true);
	}

	var form = Element.up(clickedElement, 'form');		
	refreshExpertSearchCategories(form);	
}

function expertSearchCategoryCheckboxClick(clickedElement)
{
	showExpertSearchSearchIndicator();
	var image = Element.down(clickedElement, 'img');
	if(Element.hasClassName(image, 'expertSearchCheckboxChecked'))
	{		
		expertSearchSetChecked(image, 'expertSearchCheckboxNotChecked', 'expertSearchCheckboxChecked', false);
	}
	else
	{		
		expertSearchSetChecked(image, 'expertSearchCheckboxChecked', 'expertSearchCheckboxNotChecked', true);
	}

	var form = Element.up(clickedElement, 'form');	
	refreshExpertSearchSuppliers(form);	
}

function expertSearchSetChecked(image, addClass, removeClass, state)
{
	var listElement = Element.up(image, 'li');
	var checkbox = Element.down(listElement, 'input');
		
	Element.addClassName(image, addClass);
	Element.removeClassName(image, removeClass);
	Element.removeClassName(image, 'expertSearchCheckboxPartialChecked');
	
	var subList = Element.down(listElement, 'ul');
	if(subList)
	{
		if(state)
		{
			Element.show(subList);
		}
		else
		{
			Element.hide(subList);
		}
		var subElements = Element.select(subList, 'img');
		for(var i = 0; i < subElements.length; i++)
		{
			if(Element.hasClassName(subElements[i], removeClass))
			{
				Element.addClassName(subElements[i], addClass);
				Element.removeClassName(subElements[i], removeClass);
			}			
			Element.down(Element.up(subElements[i],'li'), 'input').checked = state;
		}		
	}
	else
	{
		checkbox.checked = state;
		var parentListElement = Element.up(listElement, 'li');
		if(parentListElement)
		{
			var siblingElements = Element.select(Element.up(listElement, 'ul'), 'img');
			var checkedSiblingElements = Element.select(Element.up(listElement, 'ul'), 'img.expertSearchCheckboxChecked');
			
			if(checkedSiblingElements.length == 0)
			{
				expertSearchSetChecked(Element.down(parentListElement, 'img'), 'expertSearchCheckboxNotChecked', 'expertSearchCheckboxChecked', false);
				return;
			}
			
			if(checkedSiblingElements.length < siblingElements.length)
			{
				parentListElement.down('img').addClassName('expertSearchCheckboxPartialChecked');
				parentListElement.down('img').removeClassName('expertSearchCheckboxChecked');
				parentListElement.down('img').removeClassName('expertSearchCheckboxNotChecked');
			}
			else
			{
				parentListElement.down('img').addClassName('expertSearchCheckboxChecked');
				parentListElement.down('img').removeClassName('expertSearchCheckboxNotChecked');
				parentListElement.down('img').removeClassName('expertSearchCheckboxPartialChecked');				
			}
		}
	}
}

function refreshExpertSearchResultCount(form)
{
	showExpertSearchSearchIndicator();
	var params = Form.serialize(form, true);
	new Ajax.Updater('expertSearchResultCount', absCorrect + 'shop/components/ajax_search_result_count.html', {
		parameters: params,
		onComplete: function(transport) {
			hideExpertSearchSearchIndicator();
		}
	});	
}

function refreshExpertSearchCategories(form)
{
	showExpertSearchSearchIndicator();
	$('technology').setOpacity(0.2);
	var params = Form.serialize(form, true);	
	new Ajax.Updater('technology', absCorrect + 'shop/components/ajax_search_categories.html', {
		parameters: params,
		onSuccess: function(transport)
		{			
			refreshExpertSearchResultCount(form);
		},
		onComplete: function(transport)
		{
			$('technology').setOpacity(1);
		}
	});
	
}

function refreshExpertSearchSuppliers(form)
{
	showExpertSearchSearchIndicator();
	$('manufacturer').setOpacity(0.2);
	var params = Form.serialize(form, true);	
	new Ajax.Updater('manufacturer', absCorrect + 'shop/components/ajax_search_suppliers.html', {
		parameters: params,
		onSuccess: function(transport)
		{
			refreshExpertSearchResultCount(form);
		},
		onComplete: function(transport)
		{
			$('manufacturer').setOpacity(1);
		}
	});	
}

function resetExpertSearchCategories(form)
{
	showExpertSearchSearchIndicator();
	if(firstlevelCategories = Element.childElements(Element.down(form, '#technology ul')))
	{
		for(var i = 0; i < firstlevelCategories.length; i++)
		{
			if(Element.hasClassName(firstlevelCategories[i], 'inactive'))
				continue;
			
			if(img = Element.down(firstlevelCategories[i], 'img'))
			{				
				expertSearchSetChecked(img, 'expertSearchCheckboxNotChecked', 'expertSearchCheckboxChecked', false);
			}
		}
	}
	refreshExpertSearchSuppliers(form);
}

function resetExpertSearchSuppliers(form)
{
	showExpertSearchSearchIndicator();
	if(suppliers = Element.select(form, '#manufacturer img'))
	{		
		for(var i = 0; i < suppliers.length; i++)
		{
			if(Element.hasClassName(Element.up(suppliers[i], 'li'), 'inactive'))
				continue;
			
			expertSearchSetChecked(suppliers[i], 'expertSearchCheckboxNotChecked', 'expertSearchCheckboxChecked', false);
		}
	}
	refreshExpertSearchCategories(form);
}

function showExpertSearchSearchIndicator()
{
	$('expertSearchSearchIndicator').show();
}

function hideExpertSearchSearchIndicator()
{
	$('expertSearchSearchIndicator').hide();
}

function toggleDetail(href,oid)
{
	// show selected order detail table
	var tr = $('detail_' + oid);
	if(tr.style.display == 'none')
	{
		tr.show();
	}
	else
	{
		tr.hide();
	}
	
	//toggle link
	if(Element.hasClassName(href, 'toggleDetail'))
	{
		Element.toggleClassName(href, 'toggleDetailOpen');
	}
	else
	{
		Element.toggleClassName(href, 'toggleDetail');
	}
}

function toggleLoginForms()
{
	if($('loginform').style.display!='none')
	{
		$('loginform').hide();
		$('passwordform').show();
	}
	else
	{
		$('loginform').show();
		$('passwordform').hide();
	}
}

function toggleSidebarDownloads(btn)
{
	var downloads = Element.up(btn, '.sidebox').select('.toggleDownloads');
	if(downloads[0].style.display == 'none')
	{
		for(x=0;x<downloads.length;x++)
		{
			downloads[x].show();
		}
		Element.down(btn, '.less').show();
		Element.down(btn, '.more').hide();
	}
	else
	{
		for(x=0;x<downloads.length;x++)
		{
			downloads[x].hide();
		}
		Element.down(btn, '.more').show();
		Element.down(btn, '.less').hide();
	} 
}
function toggleDeliveryAddress()
{
	if($('select_delivery_address').style.display == '')
	{
		$('select_delivery_address').hide();
		$('add_delivery_address').show();
	}
	else
	{
		$('add_delivery_address').hide();
		$('select_delivery_address').show();
	}
}