/**
* JavaScript functions for cookiehandling
*
* @package    StWD
* @access	  public
* @author	  Dominique Stender <dstender@st-webdevelopment.de?>
* @copyright  2004 (Dominique Stender); All rights reserved
* @version    1.0.0
*/

  /**
  * Sets a cookie
  *
  * @param string name Name of the cookie
  * @param string value Value of the cookie
  * @param string expired Time when the cookie will expire
  * @param string path path for which the cookie is valid
  * @param string domain domain for which the cookie is valid
  * @param string secure flag weather the cookie is SSL enabled or not
  * @return void
  */
  function cookie_set(name, value, expires, path, domain, secure) {
    var cur_cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = cur_cookie;
  } // end: function  cookie_set()



  /**
  * retrieves the contents of a cookie
  *
  * @param string name Name of the cookie
  * @return mixed string containing the cookies value, NULL if the cookie does not exist
  */
  function cookie_get(name) {
    var dc      = document.cookie;
    var prefix  = name + "=";
    var begin   = dc.indexOf("; " + prefix);

    if (begin == -1) {
      begin = dc.indexOf(prefix);

      if (begin != 0) {
        return null;
      } // end: if
    } else {
      begin += 2;
    } // end: if
    var end = document.cookie.indexOf(";", begin);

    if (end == -1) {
      end = dc.length;
    } // end: if

    return unescape(dc.substring(begin + prefix.length, end));
  } // end: function cookie_get()


  /**
  * removes a cookie
  *
  * @param string name Name of the cookie
  * @param path path for which the cookie is valid
  * @param string domain domain for which the cookie is valid
  * @return void
  */
  function cookie_delete(name, path, domain) {
    if (get_cookie(name)) {
      document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    } // end: if
  } // end: function cookie_delete()



  /**
  * Minor fixes for dates
  *
  * @param date an instance of the Date object
  * @return void
  */
  function fix_date(date) {
    var base = new Date(0);
    var skew = base.getTime();

    if (skew > 0) {
      date.setTime(date.getTime() - skew);
    } // end: if
  } // end: function fix_date()

	/**
	* Trigger "needs cookie" warning in layer.
	*
	* @access public
	* @return void
	*/
	function cookieWarning(cookieName, getName, warnText) {
		var cookieSessionId = cookie_get(cookieName);
		var myDiv 			= false;

		if (typeof document.getElementById('mb3HeaderWarnings') == 'object') {
			myDiv = document.getElementById('mb3HeaderWarnings');

			if (!cookieSessionId
				&& document.location.href.indexOf(getName + '=') == -1) {

				myDiv.innerHTML 			= warnText;
				myDiv.style['visibility']	= 'visible';
				myDiv.style['display']		= 'block';
			} // end: if
		}
	}

	/**
	* Redirects the user if no session cookie is set and URL-based sessionIds are
	* allowed within the system.
	*
	* @access public
	* @return void
	*/
	function noCookieRedirect(cookieName, getName, sessionId) {
		var cookieSessionId = cookie_get(cookieName);
		var paramAppend		= '&';
		var redirectString	= getName + '=' + sessionId;

		if (cookieSessionId == null) {
			// no cookie set in browser

			// fix appender-char if no params exist
			if (document.location.href.indexOf('?') == -1) {
				// [8.11.07 vh] append also a & because typo3 has a small bug. if there is no id= in the query
				// it thinks that ftu=... is the id
				paramAppend = '?&';
			}

			// redirect to self with url-param
			document.location.href = document.location.href + paramAppend + redirectString;
		} // end: if
	}

	var dmcOnloadFuncs = new Array();
	/**
	* calls specified functions for the body onLoad Event
	* the function which wants to be called, adds itself to an array and than it gets called
	* current function calls:
	* __utmSetTrans() - send the Google Analytics Form @ the basket checkout (wk step6) - according global variable: utmTrans
	* __initZoom() - initiate the zoom-layer-script - according global variable: initZoom
	* __foofoo() - sample for further function calls  - according global variable: foofoo
	*
	* @access	public
	* @return	void
	*/
	function dmcOnLoad() {

		for(var i=0; i<dmcOnloadFuncs.length; i++) {

			if (typeof dmcOnloadFuncs[i] == 'function') {
				dmcOnloadFuncs[i]();
			}
		}

	}

	function addOnloadFunction(func) {
		if (typeof func == 'function') {
			dmcOnloadFuncs.push(func);
		}
	}

	function openWindow(url, name, parameter) {
		// Wenn ein Parameter uebergeben wird --> diesen uebernehmen
		if (parameter) {
			size = parameter;
		}

		var popuphandler = window.open(url,name,size);
		popuphandler.window.focus();

		return popuphandler;
	}


/**
* return a string with the coordinate center of Browser
*
* @access	public
* @return	string
*/
function popupCoordinate(CoordinateWidth, CoordinateHeight) {
	var x = (screen.width-CoordinateWidth)/2;
	var y = (screen.height-CoordinateHeight)/2;
	return	'top='+y+',left='+x;
}
/**
* open a popup window with the given position and size
*
* @access	public
* @return	string
*/
function openWindowCenter(url, name, parameter,CoordinateWidth,CoordinateHeight) {
	// Wenn ein Parameter uebergeben wird --> diesen uebernehmen
	if (parameter) {
		popupCoordin = popupCoordinate(CoordinateWidth,CoordinateHeight);
		size		=  parameter+','+popupCoordin;
	}

	var popuphandler = window.open(url,name,size);
	popuphandler.window.focus();

	return popuphandler;
}

/**
* Change the value of the object with the given id
*
* @access	public
* @return	boolean		result of the change
*/
function changeFormElementvalue(id, newValue) {
	var returnValue		= false;
	var formElement		= document.getElementById(id);

	if (formElement) {
		formElement.value = newValue;
		returnValue = true;
	}

	return returnValue;
}
// open popup window
function openNewWindow(url) {
	var width			= 600;
	var height			= 540;
	var windowParams	= '';
	var leftPosition	= (screen.width) ? (screen.width-width)/2 : 0;
	var topPosition	= (screen.height) ? (screen.height-height)/2 : 0;
	windowParams = 	'width='+ width +',height='+ height +',top=' + topPosition +
					',left=' + leftPosition + ',scrollbars=no,resizable=yes,toolbar=no'+
					',status=no,directories=no,menubar=no,location=no';
	vHWin = window.open(url, 'FEopenLink', windowParams);
	vHWin.focus();
}
function submitWithGrantAddressExemption_catalogueOrder (ctype, uid) {
	var form = document.getElementById(ctype + '[' + uid + ']' + '[form]');
	var action = document.getElementById(ctype + '[' + uid + ']' + '[action][grantAddressExemption_catalogueOrder]');

	if(action && form) {
		action.value = 'grantAddressExemption_catalogueOrder';
		form.submit();
	}
}
	var dmc_mb3_product_pi1mediaActive	= '';
	var dmc_mb3_product_pi1mediaIndex	= 0;
	var flagOutletProduct				= false;
	var insideOfChangeArticlePopup 		= false;

	var submitAddArticle				= true;

	var dmc_mb3_product_pi1onestopshopping	= 0;
	var oneStopProductsCount = 0;

	function productToggle(uid, id, imageNum, state) {
		dmc_mb3_product_pi1mediaIndex = imageNum;

		/* gather necessary objects */
		var mainImage	= document.getElementById('dmc_mb3_product_pi1' + uid + 'MainImage');
		var toggleImage	= document.getElementById('dmc_mb3_product_pi1' + uid + 'Product' + id + 'Opener');
		var productBody	= document.getElementById('dmc_mb3_product_pi1' + uid + 'Product' + id + 'Body');

		/* if state is 1 or 0, transform it to the other
			(user supplies target state, switch statement checks for current state */
		if (state == 1 || state == 0) {
			state = (state + 1) % 2;

		} else if (productConf[uid][id]) {
			state = productConf[uid][id]['state'];
		} /* end: if */

		if (mainImage) {
			switch (state) {
				case 0:

					if (productConf[uid][id]['large'][imageNum]) {
						mainImage.src					= productConf[uid][id]['large'][imageNum];

						/* handle grey activity indicator below thumbnails */
						var oldActive	= false;
						var newActive	= document.getElementById('dmc_mb3_product_pi1' + uid + id + imageNum + 'mediaActive');

						if (dmc_mb3_product_pi1mediaActive != '') {
							oldActive	= document.getElementById(dmc_mb3_product_pi1mediaActive);
						} /* end: if */

						if (oldActive) {
							gfxToggle(oldActive, 'clear.gif', 'but_detail_thumb_on.gif');
						} /* end: if */

						if (newActive) {
							gfxToggle(newActive, 'clear.gif', 'but_detail_thumb_on.gif');
							dmc_mb3_product_pi1mediaActive = 'dmc_mb3_product_pi1' + uid + id + imageNum + 'mediaActive';
						} /* end: if */

					} else if (productConf[uid][id]['large']['default']) {
						mainImage.src	= productConf[uid][id]['large']['default'];
					} /* end: if */

					if (toggleImage) {
						toggleImage.src					= dmc_mb3_product_pi1ToggleImageOff;
					} /* end: if */

					if (productBody) {
						productBody.className			= 'productBodyVisible';
					} /* end: if */

					if (typeof productConf[uid][id]['state'] != undefined) {
						productConf[uid][id]['state']	= 1;
					} /* end: if */
					break;

				case 1:
					if (toggleImage) {
						toggleImage.src				 		= dmc_mb3_product_pi1ToggleImageOn;
					} /* end: if */

					if (productBody) {
						productBody.className				= 'productBodyInvisible';
					} /* end: if */

					if (typeof productConf[uid][id]['state'] != undefined) {
						productConf[uid][id]['state']	= 0;
					} /* end: if */
					break;

				default:
			} /* end: switch */
		} /* end: if */
	}

	function initProduct(uid, id, multiArticle) {
		/* gather necessary objects */
		var variation		= '';
		var size			= '';
		var color			= '';
		var productBody		= document.getElementById('dmc_mb3_product_pi1' + uid + 'Product' + id + 'Body');
		var toggleImage		= document.getElementById('dmc_mb3_product_pi1' + uid + 'Product' + id + 'Opener');
		var state			= productConf[uid][id]['state'];
		var numOfArticle	= 0;
		var numSoldOutArticles 	= 0;

		/* check whether a single article is preselected */ /* and sold out */
		for (var tmpVariation in productConf[uid][id]['articles']) {

			for (var tmpSize in productConf[uid][id]['articles'][tmpVariation]) {

				for (var tmpColor in productConf[uid][id]['articles'][tmpVariation][tmpSize]) {

					if (productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['selected'] == '1') {
						variation	= tmpVariation;
						size		= tmpSize;
						color		= tmpColor;
					} /* end: if */


					/* start: checks if at least one article is sold out*/
					numOfArticle++;
					if(productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['stockTypeCode'] == '3') {
						numSoldOutArticles++;
						if(productConf[uid][id]['soldout'] == false) {
							productConf[uid][id]['soldout'] = true;
						}
					}
					/* stop: checks if at least one article is sold out*/

				} /* end: for */
			} /* end: for */
		} /* end: for */

		fillVariationForm(uid, id, variation, color, size);

		variation	= currentVariation(uid, id);
		size		= currentSize(uid, id, variation);
		color		= currentColor(uid, id, variation, size);

		setSoldOutErrorText(uid, id, variation, size, color);

		displayArtNumber(uid, id, variation, size, color);
		displayPrice(uid, id, variation, size, color);
		displayAvailability(uid, id, variation, size, color);

		if (toggleImage
			&& productBody) {
			switch (state) {
				case 1:
					productBody.className	= 'productBodyVisible';
					toggleImage.src			= dmc_mb3_product_pi1ToggleImageOff;
					break;

				case 0:
					productBody.className	= 'productBodyInvisible';
					toggleImage.src			= dmc_mb3_product_pi1ToggleImageOn;
					break;

				default:
			} /* end: switch */
		} /* end: if */

		if (multiArticle) {

		} else {
			addSoldOutText(uid, id);
		}

		var colorForm = document.getElementById('cross_select'+uid);

		if (colorForm && colorForm.options) {
			if(numOfArticle == numSoldOutArticles) {
				if(colorForm.options[0].text != '') {
					colorForm.options[0].text = colorForm.options[0].text + txtSeparator + txtSoldOut;
				} else {
					colorForm.options[0].text = txtSoldOut;
				}
			} else {
				if(colorForm.options[0].text != '') {
					colorForm.options[0].text = colorForm.options[0].text + txtSeparator + productConf[uid][id]['txtColorAndNumer'];
				} else {
					colorForm.options[0].text = productConf[uid][id]['txtColorAndNumer'];
				}
			}

			// if there is only only color in the selecbox
			// change the selectbox to make it look like an inputfield
			if (colorForm.length == 1) {
				colorForm.size = 1;
				colorForm.multiple = true;
				colorForm.selectedIndex = -1
			}
		}
	}


	function addSoldOutText(uid, id){
		/* start: add text to size select box if at least one article is sold out */
		if(productConf[uid][id]['soldout'] == true) {
			if(flagOutletProduct == false) {
				var sizeForm = document.getElementById('productSizeForm_' + uid + '_' + id);
				if(sizeForm) {
					if(sizeForm.length == 1) {
						sizeForm.size = sizeForm.length + 3;
						sizeForm.style.height = 'auto';
					}
					sizeForm.options[sizeForm.length]	= new Option(soldOutText_1, '0', false, false);
					sizeForm.options[sizeForm.length-1].className = 'clr21';
					sizeForm.options[sizeForm.length]	= new Option(soldOutText_2, '0', false, false);
					sizeForm.options[sizeForm.length-1].className = 'clr21';
					sizeForm.options[sizeForm.length]	= new Option(soldOutText_3, '0', false, false);
					sizeForm.options[sizeForm.length-1].className = 'clr21';
				}
			}
		}
		/* stop: add text to size select box if at least one article is sold out */
	}

	function changeProduct(uid, id, startFrom, noSoldoutRedirect) {

		/* gather necessary objects */
		var variationForm	= document.getElementById('productVariationForm_' 	+ uid + '_' + id);
		var sizeForm		= document.getElementById('productSizeForm_' 		+ uid + '_' + id);
		var colorForm		= document.getElementById('productColorForm_' 		+ uid + '_' + id);

		var productForm			= document.getElementById('productForm_' + uid);

		var variation		= currentVariation(uid, id);
		var size			= currentSize(uid, id, variation);
		var color			= currentColor(uid, id, variation, size);

		switch (startFrom) {
			case 'variation':
				fillSizeForm(uid, id, variation);
				break;

			case 'size':
				fillColorForm(uid, id, variation, size);
				break;

			case 'color':
				setGravure(uid, id, variation, size, color);
				break;

			default:
		} /* end: switch */

		variation		= currentVariation(uid, id);
		size			= currentSize(uid, id, variation);
		color			= currentColor(uid, id, variation, size);

		displayArtNumber(uid, id, variation, size, color);
		displayPrice(uid, id, variation, size, color);
		displayAvailability(uid, id, variation, size, color);

		/* start: redirection if article is sold out */
		if(window.redirectSoldOutArticle && noSoldoutRedirect!=true) {
			var variation		= currentVariation(uid, id);
			var size			= currentSize(uid, id, variation);
			var color			= currentColor(uid, id, variation, size);
			var articlePk		= 0;

			if(sizeForm.value != 0) {
				var stockTypeCode	= productConf[uid][id]['articles'][variation][size][color]['stockTypeCode'];
			}

			if(stockTypeCode == '3') {
				articlePk	= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
				redirectSoldOutArticle(articlePk);
			}

		}
		/* end: redirection if article is sold out */

		/* start: hide hint if a size was selected */
		//if(sizeForm.value != 0) {
			if (window.document.getElementById('error_header'+uid)) {
				errorcontainer = document.getElementById('error_header'+uid);
				errorcontainer.className = 'dmc_mb3_product_error_header_off';
				errorpic = document.getElementById('dmc_mb3_product_error_pic'+uid);
				errorpic.className = 'dmc_mb3_product_error_pic_off';
			}
		//}

		setSoldOutErrorText(uid, id, variation, size, color);

		/* stop: hide hint if a size was selected */
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function setSoldOutErrorText(uid, id, variation, size, color){

		var errorsoldoutcontainer = document.getElementById('errorsoldoutcontainer'+uid);
		var errorpic = document.getElementById('dmc_mb3_product_error_pic'+uid);

		if (errorsoldoutcontainer) {
			if (productConf[uid][id]['articles'][variation]
				&& productConf[uid][id]['articles'][variation][size]
				&& productConf[uid][id]['articles'][variation][size][color]
				&& productConf[uid][id]['articles'][variation][size][color]['stockTypeCode'] == 3) {

				errorsoldoutcontainer.className = 'dmc_mb3_product_error_header_on';


				errorpic.className = 'dmc_mb3_product_error_pic_on';
			} else {

				errorsoldoutcontainer.className = 'dmc_mb3_product_error_header_off';
			}

		}
	}


	function addToBasket(uid, id) {

		var form			= document.getElementById('productForm_' + uid);
		var amountForm		= document.getElementById('productAmountForm_' + uid + '_' + id);
		var pkForm			= document.getElementById('productBasketPk_' + uid);
		var productPkForm	= document.getElementById('productBasketProductPk_' + uid);
		var variation		= currentVariation(uid, id);
		var size			= currentSize(uid, id, variation);
		var color			= currentColor(uid, id, variation, size);
		var amount			= 0;
		var sizeFormValue	= '';
		var sizeForm		= document.getElementById('productSizeForm_' 		+ uid + '_' + id);

		/* start: checks if a size is selected  */
		if(sizeForm) {
			if(sizeForm.nodeName == 'SELECT') {
				if (sizeForm.length == 1) {
					sizeFormValue = sizeForm.options[0].value;
				} else {
					sizeFormValue = sizeForm.options[sizeForm.selectedIndex].value;
				}
			} else if (sizeForm.nodeName == 'INPUT'
				&& (sizeForm.type == 'text'
					|| sizeForm.type == 'hidden')) {
				sizeFormValue = sizeForm.value;
			}

			if(sizeFormValue == 0) {
				errorcontainer = document.getElementById('error_header'+uid);
				errorcontainer.className = 'dmc_mb3_product_error_header_on';
				errorpic = document.getElementById('dmc_mb3_product_error_pic'+uid);
				errorpic.className = 'dmc_mb3_product_error_pic_on';
				return 0;
			}
		}
		/* stop: checks if a size is selected  */

		if (amountForm) {
			if(amountForm.nodeName == 'SELECT') {
				amount = amountForm.options[amountForm.selectedIndex].value;
			} else if (amountForm.nodeName == 'INPUT'
				&& (amountForm.type == 'text'
					|| amountForm.type == 'hidden')) {
				amount = amountForm.value;
			}
		}

		if (form && pkForm && productPkForm && amount > 0) {
			pkForm.value		= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
			productPkForm.value = id;





			form.submit();
		}
		return 1;
	}

	function addToBasketSubmit(uid, id, target, popup, url, popupParams) {
		if (popup) {
			var form			= document.getElementById('productForm_' + uid);
			form.action 		= url;

			// do NOT load page from 'url' variable here! race condition w/ 2 Apache threads!
			window.open('/clear.gif', target, popupParams);
		}

	//	if(firstClick) {
	//		firstClick = false;
		if(submitAddArticle){
			addToBasket(uid, id);
		}

	//	}
	}

	function addToNotepad(uid, id, url) {
		/*
		var form			= document.getElementById('productForm_' + uid);
		var amountForm		= document.getElementById('productAmountForm_' + uid + '_' + id);
		var pkForm			= document.getElementById('productBasketPk_' + uid);
		var productPkForm	= document.getElementById('productBasketProductPk_' + uid);
		var variation		= currentVariation(uid, id);
		var size			= currentSize(uid, id, variation);
		var color			= currentColor(uid, id, variation, size);
		var amount			= 0;

		if (amountForm) {
			amount = amountForm.options[amountForm.selectedIndex].value;
		}

		if (form && pkForm && productPkForm && amount > 0) {
			pkForm.value		= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
			productPkForm.value = id;
			form.action = url;
			form.target = target;
			form.submit();
		}
		*/

		var artNumber 		= '';
		var variation		= '';
		var size			= '';
		var color			= '';

		// find currently selected article number
		variation	= currentVariation(uid, id);
		size		= currentSize(uid, id, variation);
		color		= currentColor(uid, id, variation, size);

		artNumber	= productConf[uid][id]['articles'][variation][size][color]['artNumber'];

		// change document.location
		document.location.href = url.replace('%s', artNumber);
	}

	function changeItemInBasket(uid, id) {
		var form			= document.getElementById('productForm_' + uid);
		var amountForm		= document.getElementById('productAmountForm_' + uid + '_' + id);
		var pkForm			= document.getElementById('productBasketPk_' + uid);
		var productPkForm	= document.getElementById('productBasketProductPk_' + uid);
		var variation		= currentVariation(uid, id);
		var size			= currentSize(uid, id, variation);
		var color			= currentColor(uid, id, variation, size);
		var amount			= 0;

		if (amountForm) {
			if(amountForm.nodeName == 'SELECT') {
				amount = amountForm.options[amountForm.selectedIndex].value;
			} else if (amountForm.nodeName == 'INPUT'
				&& (amountForm.type == 'text'
					|| amountForm.type == 'hidden')) {
				amount = amountForm.value;
			}
		}

		if (form && pkForm && productPkForm && amount > 0) {
			pkForm.value		= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
			productPkForm.value = id;
			form.submit();
			window.close();
		}

		return false;
	}

	function displayArtNumber(uid, id, variation, size, color) {
		var artNumberDiv	= document.getElementById('productArtNumber_' 		+ uid + '_' + id);

		if (artNumberDiv) {
			artNumberDiv.innerHTML	= productConf[uid][id]['articles'][variation][size][color]['artNumber'];
// CCC [dst] 21.12.2005 - compatible to CH only!
//									+ ' '
//									+ productConf[uid][id]['articles'][variation][size][color]['adCode'];
		} /* end: if */
	}

	function displayPrice(uid, id, variation, size, color) {
		var priceDiv		= document.getElementById('productPrice_' 		+ uid + '_' + id);
		var oldPriceDiv		= document.getElementById('productOldPrice_'	+ uid + '_' + id);
		var oldPriceWrap	= document.getElementById('productOldPrice_'	+ uid + '_' + id + '_wrap');

		if (priceDiv) {
			priceDiv.innerHTML	= productConf[uid][id]['articles'][variation][size][color]['price'];
		} /* end: if */

		if (oldPriceDiv && oldPriceWrap) {
			var oldPrice 	= productConf[uid][id]['articles'][variation][size][color]['oldPrice'];
			oldPrice 		= parseFloat(oldPrice.replace(/,/g, '.'));

			if (oldPrice > 0) {
				oldPriceDiv.innerHTML			= productConf[uid][id]['articles'][variation][size][color]['oldPrice'];
				oldPriceWrap.style.visibility	= 'visible';
				oldPriceWrap.style.display		= 'inline';

			} else {
				oldPriceWrap.style.visibility	= 'hidden';
				oldPriceWrap.style.display		= 'none';
			}
		}

	}

	function displayAvailability(uid, id, variation, size, color) {
		var availDiv	= document.getElementById('productAvail_' 		+ uid + '_' + id);

		if (availDiv) {
			availDiv.innerHTML	= productConf[uid][id]['articles'][variation][size][color]['stockType'];
			availDiv.className	= productConf[uid][id]['articles'][variation][size][color]['stockTypeClass'];
		} /* end: if */
	}

	function setVariation(uid, id, variation) {
		var variationForm	= document.getElementById('productVariationForm_' 	+ uid + '_' + id);
		var index			= 0;

		if (variationForm) {
			if(variationForm.nodeName == 'SELECT') {
				for (var tmpVariation in productConf[uid][id]['articles']) {

					if (tmpVariation == variation) {
						variationForm.selectedIndex = index;
					} /* end: if */

					index++;
				} /* end: for */
			} else if (variationForm.nodeName == 'INPUT'
				&& (variationForm.type == 'text'
					|| variationForm.type == 'hidden')
				) {

				variationForm.value = variation;
			}/* end: if*/
		} /* end: if */
	}

	function firstVariation(uid, id) {
		/* find first variation */
		for (var returnValue in productConf[uid][id]['articles']) {
			break;
		} /* end: for */

		return returnValue;
	}

	function currentVariation(uid, id) {
		var returnValue		= '';
		var variationForm	= document.getElementById('productVariationForm_' 	+ uid + '_' + id);

		if (variationForm) {
			if(variationForm.nodeName == 'SELECT' && variationForm.selectedIndex != -1) {
				returnValue = variationForm.options[variationForm.selectedIndex].value;
			} else if (variationForm.nodeName == 'INPUT'
				&& (variationForm.type == 'text'
					|| variationForm.type == 'hidden')
				) {

				returnValue = variationForm.value;
			}/* end: if*/
		} else {
			returnValue = firstVariation(uid, id);
		} /* end: if */

		return returnValue;
	}

	function fillVariationForm(uid, id, variation, color, size) {
		var variationForm	= document.getElementById('productVariationForm_' 	+ uid + '_' + id);
		var tmpVariation	= false;
		var index			= 0;

		if (variationForm) {
			if(variationForm.nodeName == 'SELECT') {
				/* clear all options */
				for (var j = variationForm.length; j >= 0; j--) {
					variationForm.options[j] = null;
				} /* end: for */

				/* fill with new variations */
				for (tmpVariation in productConf[uid][id]['articles']) {

					if (tmpVariation == variation) {
						variationForm.options[variationForm.length]	= new Option(tmpVariation, tmpVariation, false, true);
						variationForm.selectedIndex					= index;

					} else {
						variationForm.options[variationForm.length]	= new Option(tmpVariation, tmpVariation, false, false);
					} /* end: if */

					index++;
				} /* end: for */

				/* set selected */
				if (variationForm.selectedIndex == -1) {
					variationForm.selectedIndex = 0;
				} /* end: if */
			} else if (variationForm.nodeName == 'INPUT'
				&& (variationForm.type == 'text'
					|| variationForm.type == 'hidden')
				) {

				variationForm.value = variation;
			}/* end: if*/
		} /* end: if */

		/* fill size form */
		fillSizeForm(uid, id, currentVariation(uid, id), size, color);
	}

	function setSize(uid, id, variation, size) {
		var sizeForm	= document.getElementById('productSizeForm_' 	+ uid + '_' + id);
		var index		= 0;

		if (sizeForm) {
			if(sizeForm.nodeName == 'SELECT') {
				for (var tmpSize in productConf[uid][id]['articles'][variation]) {

					if (tmpSize == size) {
						sizeForm.selectedIndex = index;
					} /* end: if */

					index++;
				} /* end: for */
			} else if (sizeForm.nodeName == 'INPUT'
				&& (sizeForm.type == 'text'
					|| sizeForm.type == 'hidden')
				) {

				sizeForm.value = size;
			}/* end: if*/
		} /* end: if */
	}

	function firstSize(uid, id, variation) {
		/* find first size */
		for (var returnValue in productConf[uid][id]['articles'][variation]) {
			break;
		} /* end: for */

		return returnValue;
	}

	function currentSize(uid, id, variation) {
		var returnValue		= '';
		var sizeForm		= document.getElementById('productSizeForm_' 	+ uid + '_' + id);

		if (sizeForm) {
			if (sizeForm.nodeName == 'SELECT' && sizeForm.selectedIndex != -1) {
				returnValue = sizeForm.options[sizeForm.selectedIndex].value;
			} else if (sizeForm.nodeName == 'SELECT' && sizeForm.length == 1) {
				returnValue = sizeForm.options[0].value;
			} else if (sizeForm.nodeName == 'INPUT'
				&& (sizeForm.type == 'text'
					|| sizeForm.type == 'hidden')
				) {

				returnValue = sizeForm.value;
			}/* end: if*/
		} else {
			returnValue = firstSize(uid, id, variation);
		} /* end: if */

		return returnValue;
	}

	function fillSizeForm(uid, id, variation, size, color) {
		var sizeForm	= document.getElementById('productSizeForm_' 	+ uid + '_' + id);
		var tmpSize		= false;
		var sizeOld		= false;
		var sizeOldName	= false;
		var index		= 0;

		if (sizeForm) {
			if(sizeForm.nodeName == 'SELECT') {
				/* remember old state */
				sizeOld = sizeForm.selectedIndex;

				if (sizeOld != -1) {
					sizeOldName = sizeForm.options[sizeOld].value;
				} /* end: if */

				/* fill with new sizes */
				for (tmpSize in productConf[uid][id]['articles'][variation]) {
					// change tmpSize_show and add the 2 values
					tmpSize_show = tmpSize;
					// read first color from size
					for (tmpColor in productConf[uid][id]['articles'][variation][tmpSize]) {

						// get price and availability from first colorelement
						price = productConf[uid][id]['articles'][variation][tmpSize][tmpColor]['price'];
						stockType = productConf[uid][id]['articles'][variation][tmpSize][tmpColor]['stockType'];

						// change tmpSize_show and add the 2 values
						tmpSize_show = tmpSize + ' - ' + stockType + ' - ' + price;
					}

					if (tmpSize == size
						|| tmpSize == sizeOldName) {

						sizeForm.options[sizeForm.length]	= new Option(tmpSize_show, tmpSize, false, true);
						sizeForm.selectedIndex				= index;

					} else {
						sizeForm.options[sizeForm.length]	= new Option(tmpSize_show, tmpSize, false, false);
					} /* end: if */

					index++;
				} /* end: for */

				// if there is only 1 option to select (index 0 is the "please choose text)
				// change the selectbox to make it look like an inputfield
				// But: inside of the ChangeArticle popup there is no "please choose" text
				if (insideOfChangeArticlePopup == false) {
					numberOfOptions = 2;
				} else {
					numberOfOptions = 1;
				}

				if (sizeForm.length == numberOfOptions) {
					sizeForm.options[0] = null;
					sizeForm.size = 1;
					sizeForm.multiple = true;
					sizeForm.selectedIndex = -1
				}

			} else if (sizeForm.nodeName == 'INPUT'
				&& (sizeForm.type == 'text'
					|| sizeForm.type == 'hidden')
				) {

				sizeForm.value = size;
			}/* end: if*/
		} /* end: if */

		/* fill color form */
		fillColorForm(uid, id, variation, currentSize(uid, id, variation), color);
	}

	function setColor(uid, id, variation, size, color) {
		var colorForm	= document.getElementById('productColorForm_' 	+ uid + '_' + id);
		var index		= 0;

		if (colorForm) {
			if(colorForm.nodeName == 'SELECT') {
				for (var tmpColor in productConf[uid][id]['articles'][variation][size]) {

					if (tmpColor == color) {
						colorForm.selectedIndex = index;
					} /* end: if */

					index++;
				} /* end: for */
			} else if (colorForm.nodeName == 'INPUT'
				&& (colorForm.type == 'text'
					|| colorForm.type == 'hidden')
				) {

				colorForm.value = color;
			}/* end: if*/
		} /* end: if */
	}

	function firstColor(uid, id, variation, size) {
		/* find first color */
		for (var returnValue in productConf[uid][id]['articles'][variation][size]) {
			break;
		} /* end: for */

		return returnValue;
	}

	function currentColor(uid, id, variation, size) {
		var returnValue		= '';
		var colorForm		= document.getElementById('productColorForm_' 	+ uid + '_' + id);

		if (colorForm) {
			if (colorForm.nodeName == 'SELECT' && colorForm.selectedIndex != -1) {
				returnValue = colorForm.options[colorForm.selectedIndex].value;
			} else if (colorForm.nodeName == 'INPUT'
				&& (colorForm.type == 'text'
					|| colorForm.type == 'hidden')
				) {

				returnValue = firstColor(uid, id, variation, size);//colorForm.value;
			}/* end: if*/
		} else {
			returnValue = firstColor(uid, id, variation, size);
		} /* end: if */

		return returnValue;
	}

	function fillColorForm(uid, id, variation, size, color) {
		var colorForm		= document.getElementById('productColorForm_' 	+ uid + '_' + id);
		var tmpColor		= false;
		var colorOld		= false;
		var colorOldName	= false;
		var index			= 0;

		if (colorForm) {
			if(colorForm.nodeName == 'SELECT') {
				/* remember old state */
				colorOld = colorForm.selectedIndex;

				if (colorOld != -1) {
					colorOldName = colorForm.options[colorOld].value;
				} /* end: if */

				/* clear all options */
				for (var j = colorForm.length; j >= 0; j--) {
					colorForm.options[j] = null;
				} /* end: for */

				/* fill with new colors */
				for (tmpColor in productConf[uid][id]['articles'][variation][size]) {

					if (tmpColor == color
						|| tmpColor == colorOldName) {

						colorForm.options[colorForm.length]	= new Option(tmpColor, tmpColor, false, true);
						colorForm.selectedIndex = index;

					} else {
						colorForm.options[colorForm.length]	= new Option(tmpColor, tmpColor, false, false);
					} /* end: if */

					index++;
				} /* end: for */
			} else if (colorForm.nodeName == 'INPUT'
				&& (colorForm.type == 'text'
					|| colorForm.type == 'hidden')
				) {

				colorForm.value = color;
			}/* end: if*/
		} /* end: if */

		/* set gravure */
		setGravure(uid, id, variation, size, currentColor(uid, id, variation, size));
	}

	function setGravure(uid, id, variation, size, color) {
		var gravureForm		= document.getElementById('productGravureForm_' + uid + '_' + id);
		var gravureTitle	= document.getElementById('productGravureTitle_' + uid + '_' + id);
		var gravureText		= document.getElementById('productGravureText_' + uid + '_' + id);

		if (gravureForm && gravureTitle && gravureText) {
			/* set current state */
			gravureForm.maxLength = productConf[uid][id]['articles'][variation][size][color]['gravureLength'];
			gravureText.innerHTML = productConf[uid][id]['articles'][variation][size][color]['gravureText'];

			if (gravureForm.maxLength == 0) {
				gravureForm.style.visibility	= 'hidden';
				gravureTitle.style.visibility	= 'hidden';
				gravureText.style.visibility	= 'hidden';
				gravureForm.style.display		= 'none';
				gravureTitle.style.display		= 'none';
				gravureText.style.display		= 'none';

			} else {
				gravureForm.style.visibility	= 'visible';
				gravureTitle.style.visibility	= 'visible';
				gravureText.style.visibility	= 'visible';
				gravureForm.style.display		= 'inline';
				gravureTitle.style.display		= 'block';
				gravureText.style.display		= 'block';
			} /* end: if */
		} /* end: if */
	}

	if (!productConf) {
		var productConf = new Array();
	}


	function openPopUp(url) {
		var width			= 500;
		var height			= 320;
		var windowParams	= '';

		var leftPosition	= (screen.width) ? (screen.width-width)/2 : 0;
		var topPosition	= (screen.height) ? (screen.height-height)/2 : 0;

		windowParams = 	'width='+ width +',height='+ height +',top=' + topPosition +
						',left=' + leftPosition + ',scrollbars=yes,resizable=no,toolbar=no'+
						',status=no,directories=no,menubar=no,location=no';

		vHWin = window.open(url, 'FEopenLink', windowParams);
		vHWin.focus();
	}


	function openSizeGuidancePopUp(uid, id, url, tab) {
		var artNumber 		= '';
		var variation		= '';
		var size			= '';
		var color			= '';

		var width			= 700;
		var height			= 475;
		var windowParams	= '';

		var leftPosition	= (screen.width) ? (screen.width-width)/2 : 0;
		var topPosition	= (screen.height) ? (screen.height-height)/2 : 0;

		windowParams = 	'width='+ width +',height='+ height +',top=' + topPosition +
						',left=' + leftPosition + ',scrollbars=yes,resizable=yes,toolbar=no'+
						',status=no,directories=no,menubar=no,location=no';

		// find currently selected article number
		variation	= currentVariation(uid, id);
		size		= currentSize(uid, id, variation);
		color		= currentColor(uid, id, variation, size);


		/* START: BAP specific modification */
		// Selects the first value of the array if no size is selected
		var sizeForm = document.getElementById('productSizeForm_' + uid + '_' + id);
		if(!sizeForm || sizeForm.value == 0)
		{
			size	= firstSize(uid, id, variation);
			color	= firstColor(uid, id, variation, size);
		}
		/* END: BAP specific modification */

		artNumber	= productConf[uid][id]['articles'][variation][size][color]['artNumber'];

		url = url.replace('%s', artNumber);

		// open popup
		vHWin = window.open(url, 'FEopenLink', windowParams);
		vHWin.focus();
		return false;
	}


	function showOutletCare(){

		if (document.getElementById('article_careOutlet').className != 'article_careOutlet_visible') {
			document.getElementById('article_careOutlet').className ='article_careOutlet_visible';
			return false;
		}else{
			document.getElementById('article_careOutlet').className ='article_careOutlet_hidden';
			return false;
		}

	}

	/**
	 * Opens popup window for outlet product information
	 *
	 * @access public
	 * @return boolean
	 **/
	function openOutletInfoPopUp(url, windowParams){
		// open popup
		vHWin = window.open(url, 'FEopenLink', windowParams);
		vHWin.focus();
		return false;
	}

	/**
	 * Depending on the tab value in the url, it sets the related div in/visible
	 *
	 * @access public
	 * @return boolean
	 **/
	function init_sizeguidance_popup() {
		// checks preselection of tabs
		var path = window.location.pathname;
		var pos = path.indexOf("/tab/");

		tab = path.substr(pos+5, 1);

		if(tab == 2) {
			showHideObject('view2', true);
			showHideObject('view1', false);

			if(document.getElementById('tab2')) {
				document.getElementById('tab2').className='clrBg13 fCopyB';
			}
			if(document.getElementById('tab1')) {
				document.getElementById('tab1').className='';
			}
		}
	}


	function init_productinfo_popup() {
		if(document.getElementById('tab1')) {
			document.getElementById('tab1').className='clrBg13 fCopyB';
			showHideObject('view1', true);
		} else {
			if(document.getElementById('tab2')) {
				document.getElementById('tab2').className='clrBg13 fCopyB';
				showHideObject('view2', true);
			} else {
				if(document.getElementById('tab3')) {
					document.getElementById('tab3').className='clrBg13 fCopyB';
					showHideObject('view3', true);
				} else {
					if(document.getElementById('tab4')) {
						document.getElementById('tab4').className='clrBg13 fCopyB';
						showHideObject('view4', true);
					}
				}
			}
		}
	}


	function setBackgroundForTab(elementId) {
		if(document.getElementById(elementId)) {
			document.getElementById(elementId).className = 'clrBg13 fCopyB';
		}
	}

	function removeBackgroundForTab(elementId) {
		if(document.getElementById(elementId)) {
			document.getElementById(elementId).className = '';
		}
	}

	// main function processing call and get results from webservice
	function doIncrementalProductupdate(data, uid, id, multiArticle) {
		xajax_getIncrementalAvailability(data, uid, id, multiArticle);
	} // end: function

	function handleProductupdate(uid, id, incrementaldata, multiArticle) {
		var newAllSoldOut = false;

		// start updating availability if the response (incrementalList) is set
		if (incrementaldata.length > 0) {
			// parse the response and build an array with
			// the articlepk as key and availabilitystatus as values
			var incrementalStockType = new Array();
			var incrementalList = incrementaldata.split('||');

			for (var i = 0; i < incrementalList.length; i++) {

				var incrementalValues = incrementalList[i].split('###');
				incrementalStockType[incrementalValues[0]] = incrementalValues[1];
			} // end: for

			var uniqueVariation = '';
			var uniqueColor = '';
			var newSoldOutArticles = false;


			// change the avaiability of all articles of the current product
			for (var tmpVariation in productConf[uid][id]['articles']) {
				uniqueVariation = tmpVariation;
				for (var tmpSize in productConf[uid][id]['articles'][tmpVariation]) {
					for (var tmpColor in productConf[uid][id]['articles'][tmpVariation][tmpSize]) {
						uniqueColor = tmpColor;
						var articlePk = productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['articlePk'];
						// change status only if we have got data for this pk
						if (incrementalStockType[articlePk]) {
							productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['stockTypeCode'] = incrementalStockType[articlePk];
							productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['stockType'] = stockTypeText[incrementalStockType[articlePk]];
							if (incrementalStockType[articlePk] == 3) {
								newSoldOutArticles = true;
							}
						}
					} // end: for
				} // end: for
			} // end: for

			// update the availability status text in the size selectbox
			var sizeForm	= document.getElementById('productSizeForm_' 	+ uid + '_' + id);

			newAllSoldOut = true;
			for (var i = 0; i < sizeForm.length; i++) {
				var optionSize = sizeForm.options[i].value;
				// as there are also "please select" and other texts in the selectbox
				// we have to check if there is a related article to option value
				if (productConf[uid][id]['articles'][uniqueVariation][optionSize]) {
					price 		= productConf[uid][id]['articles'][uniqueVariation][optionSize][uniqueColor]['price'];
					stockType 	= productConf[uid][id]['articles'][uniqueVariation][optionSize][uniqueColor]['stockType'];
					sizeForm.options[i].text = 	optionSize + ' - ' + stockType + ' - ' + price;

					if (productConf[uid][id]['articles'][uniqueVariation][optionSize][uniqueColor]['stockTypeCode'] != 3) {
						newAllSoldOut = false;
					}

				} // end: if
			} // end: for
		} // end: if

		// if there was no soldout text before the ajax request
		// but there is a soldout article in the ajax response, add the soldout text
		if (productConf[uid][id]['soldout'] == false && newSoldOutArticles == true) {
			productConf[uid][id]['soldout'] = true;

			if (multiArticle) {

			} else {
				addSoldOutText(uid, id);
			}
		} // end: if

		var colorForm = document.getElementById('cross_select'+uid);

		if (colorForm && colorForm.options) {
			if(newAllSoldOut == true) {
				if(colorForm.options[0].text != '') {
					colorForm.options[0].text = productConf[uid][id]['txtColor'] + txtSeparator + txtSoldOut;
				} else {
					colorForm.options[0].text = txtSoldOut;
				}
			} else {
				if(colorForm.options[0].text != '') {
					colorForm.options[0].text = productConf[uid][id]['txtColor'] + txtSeparator + productConf[uid][id]['txtColorAndNumer'];
				} else {
					colorForm.options[0].text = productConf[uid][id]['txtColorAndNumer'];
				}
			}
		}
	} // end: function

	var productMultiActive 	= new Array();
	var activatedLayer		= false;


	function addToBasketMultiSubmit(mainuid) {

		var dosubmit 		= true;
		var firstErrorUid	= false;
		var form			= document.getElementById('productFormMulti_' + mainuid);

		for (var uid in productMultiActive) {

			var id = productMultiActive[uid];

			var enabledForm		= document.getElementById('productEnabledForm_' + uid);
			if (enabledForm.value == 1) {
				var articlePkForm			= document.getElementById('productBasketPk_' + uid);
				var productPkForm			= document.getElementById('productBasketProductPk_' + uid);
				var amountForm				= document.getElementById('productAmountForm_' + uid + '_' + id);
				var stocktypecodeForm		= document.getElementById('stocktypecodeForm_' + uid);
				var productSizeForm			= document.getElementById('productSizeForm_' + uid);

				var variation		= currentVariation(uid, id);
				var size			= currentSize(uid, id, variation);

				if(size == 0) {
					errorcontainer = document.getElementById('error_header'+uid);
					errorcontainer.className = 'dmc_mb3_product_error_header_on';
					errorpic = document.getElementById('dmc_mb3_product_error_pic'+uid);
					errorpic.className = 'dmc_mb3_product_error_pic_on';
					if (dosubmit) {
						firstErrorUid = uid;
					}

					dosubmit = false;
				} else {

					var color			= currentColor(uid, id, variation, size);
					var amount			= amountForm.value;

					if (articlePkForm && productPkForm && color) {
						articlePkForm.value			= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
						stocktypecodeForm.value 	= productConf[uid][id]['articles'][variation][size][color]['stockTypeCode'];
						productSizeForm.value 		= productConf[uid][id]['articles'][variation][size][color]['artSize'];
						productPkForm.value 		= id;
					}
				}
			}
		}

		if (dosubmit && form) {

			form.submit();
		} else {

			if (firstErrorUid) {
				window.location.href=('#product'+firstErrorUid);
			}
		}
	}

	function disableProduct(uid) {

		var enabledForm				= document.getElementById('productEnabledForm_' + uid);
		var enabledContent 			= document.getElementById('productEnabledContent_' + uid);
		var noProductsLeftContent	= document.getElementById('noProductsLeft');
		var addToBasketMultiButton	= document.getElementById('addToBasketMultiSubmit');

		enabledForm.value = 0;
		enabledContent.style.display = "none";

		oneStopProductsCount--;

		if (oneStopProductsCount < 1) {
			noProductsLeftContent.style.display = "inline";
			addToBasketMultiButton.style.display = "none";
			noproductscountdown(5);
		}
	}

	function noproductscountdown(countdown){

		var noProductsLeftContent	= document.getElementById('noProductsLeft');
        noProductsLeftContent.innerHTML = allproductsremovedtext.replace("###countdown###", countdown);

        if(countdown>0){
			setTimeout("noproductscountdown("+(countdown-1)+");",1000);
        } else {
	        tb_remove();
        }
    }


	/**
	 *
	 * @access public
	 * @return void
	 **/
	function enableAllMultiProducts(){
		oneStopProductsCount = 0;
		for (var uid in productConf) {

			var enabledForm				= document.getElementById('productEnabledForm_' + uid);
			var enabledContent 			= document.getElementById('productEnabledContent_' + uid);
			var noProductsLeftContent	= document.getElementById('noProductsLeft');
			var addToBasketMultiButton	= document.getElementById('addToBasketMultiSubmit');

			if (noProductsLeftContent) {
				noProductsLeftContent.style.display = "none";
			}

			if (addToBasketMultiButton) {
				addToBasketMultiButton.style.display = "";
			}

			if (enabledForm) {
				enabledForm.value = 1;
				oneStopProductsCount ++;
			}
			if (enabledContent) {
				enabledContent.style.display = "";
			}
		}
	}

//This script detects the following:
//Flash
//Windows Media Player
//Java
//Shockwave
//RealPlayer
//QuickTime
//Acrobat Reader
//SVG Viewer


var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var opera = (agt.indexOf("opera") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win)
{
	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader");
}

if (opera)
{
	pluginlist = detectFlashInOpera();
}


if (ns || !win)
{
		nse = "";
		for (var i=0;i<navigator.mimeTypes.length;i++)
		{
			nse += navigator.mimeTypes[i].type.toLowerCase();
		}
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name)
{
	result = false;
	document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n');
	if (result)
		return name+',';
	else return '';
}

function detectNS(ClassID,name)
{
	n = "";
	if (nse.indexOf(ClassID) != -1)
		if (navigator.mimeTypes[ClassID].enabledPlugin != null)
			n = name+",";
	return n;
}

function detectFlashInOpera()
{
	n = "";
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object')
		{
			n = "Flash in opera";
		}
	}
	return n;
}



pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")
// this function works in combination with product extension
// it uses the productConf array created by the product extension
// so it may not work anywhere else than productdetail pages...
function articleRecommendLink(uid, id, url) {
	var artNumber 		= '';
	var variation		= '';
	var size			= '';
	var color			= '';

	var width			= 580;
	var height			= 550;
	var windowParams	= '';

	var leftPosition	= (screen.width) ? (screen.width-width)/2 : 0;
	var topPosition	= (screen.height) ? (screen.height-height)/2 : 0;

	windowParams = 	'width='+ width +',height='+ height +',top=' + topPosition +
					',left=' + leftPosition + ',scrollbars=yes,resizable=yes,toolbar=no'+
					',status=no,directories=no,menubar=no,location=no';

	// find currently selected article number
	variation	= currentVariation(uid, id);
	size		= currentSize(uid, id, variation);
	color		= currentColor(uid, id, variation, size);

	/* START: BAP specific modification */
	// Selects the first value of the array if no size is selected
	var sizeForm = document.getElementById('productSizeForm_' + uid + '_' + id);
	if(sizeForm.value == 0)
	{
		size	= firstSize(uid, id, variation);
		color	= firstColor(uid, id, variation, size);
	}
	/* END: BAP specific modification */


	artNumber	= productConf[uid][id]['articles'][variation][size][color]['artNumber'];
//'width=500,height=560,scrollbars=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,location=no'
	// open popup
	vHWin = window.open(url.replace('%s', artNumber), 'FEopenLinkArticleRecommend', windowParams);
	vHWin.focus();
	return false;
}
var mouseX 			= 0;
var mouseY 			= 0;
var tooltip 		= null;

function getMouseXY(e) {

	if (document.all) {
		mouseX = window.event.x + document.body.scrollLeft;
		mouseY = window.event.y + document.body.scrollTop;

	} else {
		var Element = e.target;

		var CalculatedTotalOffsetLeft 	= 0;
		var CalculatedTotalOffsetTop 	= 0;
		while (Element.offsetParent)
		{
			CalculatedTotalOffsetLeft = Element.offsetLeft;
			CalculatedTotalOffsetTop = Element.offsetTop;
			Element = Element.offsetParent;
		} ;

		mouseX = e.pageX - CalculatedTotalOffsetLeft;
		mouseY = e.pageY - CalculatedTotalOffsetTop;
	}
	
}

function updateTooltip(x, y) {
	if (tooltip != null) {
		tooltip.style.left	= (x + 10) + 'px';
		tooltip.style.top 	= (y + 10) + 'px';
	}
}

function showTooltip(id) {
	tooltip = document.getElementById(id);

	if (tooltip.innerHTML != '') {
		tooltip.style.display 		= 'block';
		tooltip.style.visibility	= 'visible';
	}
}

function hideTooltip() {
	tooltip.style.display 		= 'none';
	tooltip.style.visibility	= 'hidden';

	tooltip = null;
}


	function intoBasket(id) {
			
		var form = document.getElementById("orderlineForm_"+id); /* uid hinzufuegen */
		form.submit();
	}
	
var shoppingbasketFormDoubleSubmit = false;

function shoppingbasketFormSubmit(ctype, uid, nextstepValue) {
	var form			= document.getElementById(ctype + '[' + uid + ']' + '[form]');
	var nextstep		= document.getElementById(ctype + '[' + uid + ']' + '[nextstep]');
	if (shoppingbasketFormDoubleSubmit == false) {
		if (form && nextstep && nextstepValue > 0) {
			shoppingbasketFormDoubleSubmit = true;
			nextstep.value 	= nextstepValue;
			form.submit();
		}

	}
}

function shoppingbasketFormChangeAction(ctype, uid, oldAction, newAction) {
	var form			= document.getElementById(ctype + '[' + uid + ']' + '[form]');
	var action			= document.getElementById(ctype + '[' + uid + ']' + '[action][' + oldAction + ']');

	if (action) {
		action.value = newAction;
	}
}

function togglePaymentDiv(obj, divName, divId) {
	var allPaymenttypeDetailDivs = document.getElementsByName(divName);
	if (allPaymenttypeDetailDivs.length > 0) {
		var size = allPaymenttypeDetailDivs.length;
		for (var i = 0; i < size; i++) {
			allPaymenttypeDetailDivs[i].style.display = 'none';
		}
	}

	var divObject		= document.getElementById(divId);
	if(divObject) {
		divObject.style.display = 'block';
	}
}

function toggleDeliveryAddress(ctype, uid) {
	// check whether browser is DOM capable
	if (!document.getElementById) {
		return;
	}

	var elem1 = document.getElementById('deliveryAddressCheckBox');
	var elem2 = document.getElementById('deliveryAddressArea');

	if (!elem1 || !elem2) {
		return;
	}

	if (elem1.checked) {
		elem2.style.display = 'block';
		shoppingbasketFormChangeAction(ctype, uid, 'deliveryAddress', 'deliveryAddress');
	}
	else {
		elem2.style.display = 'none';
		shoppingbasketFormChangeAction(ctype, uid);
		shoppingbasketFormChangeAction(ctype, uid, 'deliveryAddress', 'unsetDeliveryAddress');
	}
}

function checkBillingCountry(ctype, uid, state) {
		var alternativeDelivery 	= document.getElementById('alternativeDelivery');

/*
		var greenlandAddressInfobox = document.getElementById('greenlandAddressInfobox');
		var faroeAddressInfobox 	= document.getElementById('faroeAddressInfobox');

		if (greenlandAddressInfobox) {
			if(state == 'GRL'){
				document.getElementById('greenlandAddressInfobox').className = ctype+'_visible_section';
			} else {
				document.getElementById('greenlandAddressInfobox').className = ctype+'_invisible_section';
			}
		}

		if (faroeAddressInfobox) {
			if(state == 'FRO'){
				document.getElementById('faroeAddressInfobox').className = ctype+'_visible_section';
			} else {
				document.getElementById('faroeAddressInfobox').className = ctype+'_invisible_section';
			}
		}
*/
		if (alternativeDelivery) {
			if (state == 'DNK') {
				document.getElementById('alternativeDelivery').className = ctype+'_visible_section';
				shoppingbasketFormChangeAction(ctype, uid);
				shoppingbasketFormChangeAction(ctype, uid, 'deliveryAddress', 'unsetDeliveryAddress');
			} else {
				document.getElementById('alternativeDelivery').className = ctype+'_invisible_section';
				shoppingbasketFormChangeAction(ctype, uid, 'deliveryAddress', 'unsetDeliveryAddress');
			}
		}
}


function displayCreditcardInfo(moduleName) {
	var moduleNameAddition = '[creditcard]';
	var creditcardRadioBtn = document.getElementById(moduleName + moduleNameAddition);
	var creditcardInfoDiv = document.getElementById('creditcardInfo');
	
	if (creditcardRadioBtn.checked == true) {
		creditcardInfoDiv.style.display = 'block';
	} else {
		creditcardInfoDiv.style.display = 'none';
	}
}

// this function works in combination with product extension
// it uses the productConf array created by the product extension
// so it may not work anywhere else than productdetail pages...
function articleRankingLink(uid, id, url) {
	var artNumber 		= '';
	var variation		= '';
	var size			= '';
	var color			= '';

	// find currently selected article number
	variation	= currentVariation(uid, id);
	size		= currentSize(uid, id, variation);
	color		= currentColor(uid, id, variation, size);


	/* START: BAP specific modification */
	// Selects the first value of the array if no size is selected
	var sizeForm = document.getElementById('productSizeForm_' + uid + '_' + id);

	if(sizeForm){
		if(sizeForm.value == 0)
		{
			size	= firstSize(uid, id, variation);
			color	= firstColor(uid, id, variation, size);
		}
	}
	/* END: BAP specific modification */

	artNumber	= productConf[uid][id]['articles'][variation][size][color]['artNumber'];

	// change document.location
	document.location.href = url.replace('%s', artNumber);
}

function autoBirthdateJump(field, targetName, idx) {
	// check whether browser is DOM capable
	if (!document.getElementsByName) {
		return;
	}

	idx = (idx === undefined ? 0 : idx);
	var len = field.value.length;

	if (len >= field.maxLength) {
		var elems = document.getElementsByName(targetName);

		if (elems.length > idx) {
			elems[idx].focus();
		}
	}
}

function submitWithGrantAddressExemption_changeAddress (ctype, uid) {
	var form = document.getElementById(ctype + '[' + uid + ']' + '[form]');
	var action = document.getElementById(ctype + '[' + uid + ']' + '[action][grantAddressExemption_changeAddress]');

	if(action && form) {
		action.value = 'grantAddressExemption_changeAddress';
		form.submit();
	}
}
/**
* This is used for the extension specific functions
*
* @package		mb3p
* @subpackage	shoppingbasketcached
* @access		public
* @author	    Boris Azar
* @version		1.0.0
*/
var dmc_mb3_shoppingbasketcached = {

	// public method for url decoding
	decode : function (data) {
		var lsRegExp = /\+/g;
		// Return the decoded string
		return unescape(String(data).replace(lsRegExp, " "));
	}

}

/**
* Shoppingbasketcached function
*
* @package		mb3p
* @subpackage	shoppingbasketcached
* @access		public
* @author	    Boris Azar
* @version		1.0.0
*/

	/**
	* Sets a cookie
	*
	* @param string 	basketAmountContainerId			id of the basketAmountContainer
	* @param string 	articlesAmountContainerId		id of the articlesAmountContainer
	* @return void
	*/
	function fillShoppingBasketWithData(basketAmountContainerId, articlesAmountContainerId, basketValuesContainer, emptyArticlesTotalamount) {
		var articlesAmountContainer = document.getElementById(articlesAmountContainerId);
		var basketAmountContainer 	= document.getElementById(basketAmountContainerId);
		var basketValuesContainer  	= document.getElementById(basketValuesContainer);
		var emptyBasketContainer  	= document.getElementById('emptyBasketContainer');

		var articlesAmountContainerValue = 0;
		var basketAmountContainerValue = emptyArticlesTotalamount;

		var cookieData = cookie_get('mb3p');
		if (cookieData && typeof cookieData != 'undefined') {
			var data = eval('(' + cookieData + ')'); //cookieData.parseJSON();
			if (data) {
				// get the articlesAmountContainer object and set data in it
				if (articlesAmountContainer
					&& typeof data.shoppingbasket.articlesAmount != 'undefined') {

					// do not forget to decode the data (+ signs are converted back to spaces)
					articlesAmountContainerValue = dmc_mb3_shoppingbasketcached.decode(data.shoppingbasket.articlesAmount);
				} // end: if

				// get the basketAmountContainer object and set data in it
				if (basketAmountContainer
					&& typeof data.shoppingbasket.basketAmount != 'undefined') {

					// do not forget to decode the data (+ signs are converted back to spaces)
					basketAmountContainerValue = dmc_mb3_shoppingbasketcached.decode(data.shoppingbasket.basketAmount);
				} // end: if
			} // end: if
		} // end: if

		// get the articlesAmountContainer object and set data in it
		if (articlesAmountContainer) {
			// do not forget to decode the data (+ signs are converted back to spaces)
			articlesAmountContainer.innerHTML = articlesAmountContainerValue;
		} // end: if

		// get the basketAmountContainer object and set data in it
		if (basketAmountContainer) {
			// do not forget to decode the data (+ signs are converted back to spaces)
			basketAmountContainer.innerHTML = basketAmountContainerValue;
		} // end: if

		// hide row with basket infos if basket empty
		if( articlesAmountContainerValue==0 && parseInt(basketAmountContainerValue) ==0 ){
			basketValuesContainer.style.display = 'none';
			if (emptyBasketContainer) {
				emptyBasketContainer.style.display = 'block';
			}
		}

	} // end: function

function orderFormChangeAction(ctype, uid, actionName, actionValue, additionalParam) {
	var form			= document.getElementById(ctype + '[' + uid + ']' + '[form]');
	var action			= document.getElementById(ctype + '[' + uid + ']' + '[action]');

	if(additionalParam != null) {
		additionalParam	= '[' + additionalParam + ']';
	}else{
		additionalParam	= '';
	}

	if (action) {
		action.name		= ctype + '[' + uid + '][action][' + actionName + ']' + additionalParam;
		action.value	= actionValue;
	}

	form.submit();
}

function setDivVisible(field) {
	if (document.getElementById('selectbox_' + field).length > 0) {
		document.getElementById('selectdiv_' +field).style.margin = "0px";
	}
}


function setDivInvisible(field){
	document.getElementById('selectdiv_' +field).style.margin = "-1000px";
}


function setupFields() {

	for (var lineNumber=0; lineNumber < numberOfOrderlines; lineNumber++) {
		updateSize(lineNumber);
	}
}


function updateSize(lineNumber) {
	// find size text field and clear it
	var inputSize = document.getElementById('text_size_' + lineNumber);
	var alreadyUpdated = inputSize.alreadyUpdated;
	var oldSize = '';
	var oldSizeStillAvailable = false;

	if (!alreadyUpdated) {
		inputSize.alreadyUpdated = true;
	} else {
		inputSize.className = inputSize.className.replace('formError', 'noError');
		oldSize = inputSize.value;
		inputSize.value = '';
	}

	// removes all options from the selectbox
	var selectboxSize = document.getElementById('selectbox_size_'+lineNumber);
	for (var i=selectboxSize.length; i > 0; i--) {
		selectboxSize.options[i-1] = null;
	}

	// adds available options from the array to the selectbox
	var artnumber = document.getElementById('text_artnumber_'+lineNumber).value;
	if (artnumber) {
		if (articleData[artnumber]) {

			for (var size in articleData[artnumber]) {
				if (typeof(articleData[artnumber][size]) == 'object') {
					if (oldSize !== '' && size == oldSize) {
						oldSizeStillAvailable = true;
					}

					newoption = new Option(size);
	 				selectboxSize.options[selectboxSize.length] = newoption;
	 			}
			}
		}
	}
	if (oldSizeStillAvailable) {
		inputSize.value = oldSize;
	} else {
		//preset the first option if there is only one or invalid option
		if (selectboxSize.length == 1 ||
			(selectboxSize.length > 0 && (!inputSize.value))) {
			inputSize.value = selectboxSize.options[0].text;
		}
	}


	updateColor(lineNumber);
}

function updateColor(lineNumber) {

	// find color text field and clear it
	var inputColor = document.getElementById('text_color_' + lineNumber);
	var alreadyUpdated = inputColor.alreadyUpdated;
	var oldColor = '';
	var oldColorStillAvailable = false;

	if (!alreadyUpdated) {
		inputColor.alreadyUpdated = true;
	} else {
		inputColor.className = inputColor.className.replace('formError', 'noError')
		oldColor = inputColor.value;
		inputColor.value = '';
	}

	// removes all options from the selectbox
	var selectboxColor = document.getElementById('selectbox_color_'+lineNumber);
	for (var i=selectboxColor.length; i > 0; i--) {
		selectboxColor.options[i-1] = null;
	}

	// adds available options from the array to the selectbox
	var artnumber = document.getElementById('text_artnumber_'+lineNumber).value;
	var size 	  = document.getElementById('text_size_'+lineNumber).value;
	if (size) {
		size = size.toUpperCase();
		document.getElementById('text_size_'+lineNumber).value = size;
	}
	var displayAmount = false;

	if (artnumber && size) {
		if (articleData[artnumber]) {
			for (var color in articleData[artnumber][size]) {
				if (typeof(articleData[artnumber][size][color]) == 'object') {
					if (oldColor !== '' && color === oldColor) {
						oldColorStillAvailable = true;
					}

					newoption = new Option(color);
					selectboxColor.options[selectboxColor.length] = newoption;
					displayAmount = true;
				}
			}
		}
	}

	if (oldColorStillAvailable) {
		inputColor.value = oldColor;
	} else {
  	//preset the first option if there is only one or invalid option
		if (selectboxColor.length == 1 ||
  			(selectboxColor.length > 0 && (!inputColor.value))) {
			inputColor.value = selectboxColor.options[0].text;
		}
	}
	updateAmount(lineNumber, displayAmount);
	//updateStaticFields(lineNumber);
}

function updateAmount(lineNumber, displayAmount) {
	// find amount text field and clear it
	var inputAmount = document.getElementById('text_amount_' + lineNumber);
	if (!displayAmount) {
		inputAmount.value = '';
	}

	var selectboxAmount = document.getElementById('selectbox_amount_'+lineNumber);

	for (var i=1; i<10; i++) {
		newoption = new Option(i);
		selectboxAmount.options[i-1] = newoption;
	}

  	//preset the first option if there is only one or invalid option
	if (inputAmount.value>10) {
		inputAmount.value = selectboxAmount.options[0].text;
	}

	updateStaticFields(lineNumber);
}

function updateStaticFields(lineNumber) {

	// sets static fields depending on the selection of the fields
	// 'artnumber', 'variation', 'size', 'color' and 'amount'
	var artnumber = document.getElementById('text_artnumber_'+lineNumber).value;
	var size 	  = document.getElementById('text_size_'+lineNumber).value;
	var color 	  = document.getElementById('text_color_'+lineNumber).value;
	var amountField = document.getElementById('text_amount_'+lineNumber);
	// default settings
	var amountNum = '';
	var description = '';
	//var imageURL	= clearGif;
	//var imageHeight = 1;
	var productlink = '#';
	var singlePrice = '';
	//var	totalPrice 	= '';
	var	stocktype	= '';

	// field that depend on articlenumber only
	if (artnumber && articleData[artnumber]) {

		// if set it could display the producttext even before size and color is chosen.
		description = articleData[artnumber]['text'];
		//imageURL	= articleData[artnumber]['imageURL'];
		//imageHeight = 40;
		productlink = 'product/' + articleData[artnumber]['productPk'] + '/group/' + articleData[artnumber]['groupPk'] + productURL;
	}

	// fields that depend on all attributes
	if (artnumber && articleData[artnumber]
		&& articleData[artnumber][size] && articleData[artnumber][size][color]) {

		if (articleData[artnumber][size][color]['variation'] > 0) {
			description = description+'<BR />'+articleData[artnumber][size][color]['variation'];
		}
		singlePriceNum 	= (parseFloat(articleData[artnumber][size][color]['price'])).toFixed(2);
		amountNum 		= parseInt(amountField.value);

		if (isNaN(amountNum) || amountNum <= 0) {
			amountNum = 1;
		} else if (amountNum > 9) {
			amountNum = 9;
		}

		amountField.className = amountField.className.replace('formError', 'noError');

		if (isNaN(singlePriceNum))  {
			singlePrice = '';
		} else {
			singlePrice = singlePriceNum+' '+currency;
		}
		/*if (isNaN(singlePriceNum))  {
			totalPrice = '';
		} else {
			totalPrice = (singlePriceNum * amountNum).toFixed(2)+' '+currency;
		}*/
		//description = articleData[artnumber][size][color]['text'];
		description = description + ',<br/>' +  color;
		stocktype	= stockTypeCodes[articleData[artnumber][size][color]['stocktype']];
	}

	document.getElementById('text_amount_'+lineNumber).value = amountNum;
	document.getElementById('label_singleprice_'+lineNumber).innerHTML = singlePrice;
	//document.getElementById('label_totalprice_'+lineNumber).innerHTML = totalPrice;
	document.getElementById('label_description_'+lineNumber).innerHTML = description;
	document.getElementById('label_stocktype_'+lineNumber).innerHTML = stocktype;

	//document.getElementById('label_image_'+lineNumber).src = imageURL;
	//document.getElementById('label_image_'+lineNumber).width = imageHeight;
	//document.getElementById('productlink_'+lineNumber).value = productlink;

	if (javaErrorcheck) {
		errorCheck( lineNumber );
		//stockTypeCodeCheck( articleData[artnumber][size][color]['stocktype']);
	}

	// initialize empty fields with fake formular element
	if( !description || description=='') {
		document.getElementById('label_description_'+lineNumber).innerHTML = '<input type="text" value="" class="w90" readonly="readonly"/>';
	}
}


function errorCheck(lineNumber) {
	var error = false;
	var errorLabel = "";
	var artnumber  = document.getElementById('text_artnumber_'+lineNumber).value;
	var size 	   = document.getElementById('text_size_'+lineNumber).value;
	var color 	   = document.getElementById('text_color_'+lineNumber).value;
	var classname  = "";

	var soldOut = false;

	if (artnumber.length > 0) {
		if(articleData[artnumber]) {
			classname = document.getElementById('text_artnumber_' +lineNumber).className.replace("formError", "noError");
			document.getElementById('text_artnumber_' +lineNumber).className = classname;
			if (size.length > 0) {
				if (articleData[artnumber][size]) {
					classname = document.getElementById('text_size_' +lineNumber).className.replace("formError", "noError");
					document.getElementById('text_size_' +lineNumber).className = classname;
					if (color.length > 0) {
						if (articleData[artnumber][size][color]) {
							classname = document.getElementById('text_color_' +lineNumber).className.replace("formError", "noError");
							document.getElementById('text_color_' +lineNumber).className = classname;
						} else {
							errorLabel = 'color';
						}
					}
				} else {
					errorLabel = 'size';
				}
			}
		} else {
			errorLabel = 'artnumber';
		}
	} else {
		classname = document.getElementById('text_artnumber_' +lineNumber).className.replace("formError", "noError");
		document.getElementById('text_artnumber_' +lineNumber).className = classname;
	}

	if (errorLabel.length > 0) {
		//classname = document.getElementById('text_'+errorLabel+'_'+lineNumber).className.replace("noError", "formError");
		//document.getElementById('text_'+errorLabel+'_'+lineNumber).className = classname;
		setFormElementErrorClass( errorLabel, lineNumber);
		document.getElementById('error_'+lineNumber).innerHTML = errorTexts[errorLabel];
		document.getElementById('errorbox_' +lineNumber).className = ' errorVisible';
	} else {

		document.getElementById('errorbox_' +lineNumber).className = ' errorHidden';

		if(articleData[artnumber]) {
			if(articleData[artnumber][size]) {
				if(articleData[artnumber][size][color]) {
					if(articleData[artnumber][size][color]['stocktype'] == MB3_STOCK_SOLD_OUT){
						document.getElementById('error_'+lineNumber).innerHTML = stockTypeErrorText[MB3_STOCK_SOLD_OUT];
						setFormElementErrorClass( "artnumber", lineNumber);
						setFormElementErrorClass( "size", lineNumber);
						setFormElementErrorClass( "color", lineNumber);
						setFormElementErrorClass( "amount", lineNumber);
						document.getElementById('errorbox_' +lineNumber).className = ' errorVisible';
					}
				}
			}
		}
	}

}


/**
 *
 * @access public
 * @return void
 **/
function setFormElementErrorClass( errorLabel, lineNumber){
		classname = document.getElementById('text_'+errorLabel+'_'+lineNumber).className.replace("noError", "formError");
		document.getElementById('text_'+errorLabel+'_'+lineNumber).className = classname;
}

function fieldOnFocus(field, lineNumber) {
	//document.getElementById('selectbox_'+field+'_'+lineNumber).selectedIndex = -1;

	var selectbox 	= document.getElementById('selectbox_'+field+'_'+lineNumber);
	var text 	  	= document.getElementById('text_'+field+'_'+lineNumber).value;
	var selectedIdx = -1;
	for (var i=selectbox.length; i > 0; i--) {
		if (text == selectbox.options[i-1].text) {
			selectedIdx = i-1;
		}
	}
	selectbox.selectedIndex = selectedIdx;
	setDivVisible(field+'_'+lineNumber);
}

function fieldOnBlur(field, lineNumber) {

	setDivInvisible(field+'_'+lineNumber);
}

function fieldOnClick(field, lineNumber, nextFocus) {
	fieldOnBlur(field, lineNumber);
	var nextField = document.getElementById(nextFocus);
	if (nextField) {
		nextField.focus();
	}
}


function fieldOnChange(field, self, lineNumber) {
	var index = self.selectedIndex;
	if(index >= 0) {
		document.getElementById('text_'+field+'_'+lineNumber).value = self.options[index].text;
	};
}

function addOrderline(lineNumber) {
	var numberOfOrderlines = parseInt(document.getElementById('numberOfOrderlines').value);
	// if actual lineNumer is the last line of the orderform
	//actually not in use as not necessary and makes problems with table layout...
	/*
	if ((numberOfOrderlines-1) == parseInt(lineNumber)) {
		template = document.getElementById('orderlineTemplate').innerHTML;
		template = template.replace(/JSMARKERNUM/g, numberOfOrderlines);
		template = template.replace(/JSMARKERPLUS/g, (numberOfOrderlines + 1));
		template = template.replace(/JSMARKERMOD2/g, (numberOfOrderlines % 2));
		document.getElementById('addOrderline_'+numberOfOrderlines).innerHTML = template;
		document.getElementById('numberOfOrderlines').value = numberOfOrderlines + 1;
	}*/
}

function retrieveArticleData(lineNumber) {

	var artnumber = document.getElementById('text_artnumber_'+lineNumber).value;
	ajaxCall = false;

	if (artnumber.length > 0) {
		if (typeof(articleData[artnumber]) == 'object') {
			//article data already exists
		} else {
			ajaxCall = useAjax;
		}
	}

	if (ajaxCall) {

		cp.call('typo3conf/ext/dmc_mb3_orderform_core/ajaxGetArticleData.php',
						'getArticleData',
						response,
						'x'+artnumber,
						clientPk,
						languagePk,
						lineNumber);

	} else {
		updateSize(lineNumber);
		document.getElementById('text_size_'+lineNumber).focus();
		fieldOnFocus('size',lineNumber);
	}
}

function response(result) {

	var artnumber = result['data']['artnumber'];
	var lineNumber = result['data']['lineNumber'];
	if (result['data']['status'] == 'found') {
		articleData[artnumber] = result['data']['properties'];
	}
	document.getElementById('text_artnumber_'+lineNumber).value = artnumber;
	updateSize(lineNumber);
	document.getElementById('text_size_'+lineNumber).focus();
	fieldOnFocus('size',lineNumber);
}

function productInfoPopup(productlinkId) {

	var popupurl = document.getElementById(productlinkId).value;
	var popupProductInfo = window.open(popupurl, 'popup_productRecommend', 'width=705,height=510,scrollbars=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,location=no');
	popupProductInfo.focus();

}

function checkArtNumberField (lineNumber, artNumber, artNumberField) {
	if (artNumber.length == 6) {
		addOrderline(lineNumber)
		retrieveArticleData(lineNumber)
	}
}

