/**
* 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()

/*
 * function.js
 *
 * The content of this file is (c) 2003 - 2007 dmc
 * digital media center GmbH
 * All rights reserved
 *
 * This software is the confidential and proprietary
 * information of dmc digital media center GmbH.
 *
 */


/**
 * global functions used by many extensions
 *
 * $Id: functions.js 8952 2008-11-03 10:42:29Z in-sms $
 */

	/**
	* flag to prevent double submits by doubleclicks on buttons
	*/
	var doubleclickFormSubmitFlag = false;

	/**
	* performs a form submit of the form defined by ctype and uid
	* and prevents a double click form submit
	*
	* @access public
	* @param  ctype    the name of the extension
	* @param  uid      the uid of the pageelement
	* @return void
	*/
	function doubleclickCheckFormSubmit(ctype, uid) {
		var form			= document.getElementById(ctype + '[' + uid + ']' + '[form]');

		if (doubleclickFormSubmitFlag == false) {
			if (form) {
				doubleclickFormSubmitFlag = true;
				form.submit();
			} // end: if
		} // end: if
	} // end: function

	/**
	* Change the value of the object with the given id
	*
	* @access	public
	* @param  	id    		the id of the form element to get changed
	* @param  	newValue    the new value for the form element to get changed
	* @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;
		} // end: if

		return returnValue;
	} // end: if

	/**
	* 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
		}
	} // end: function

	/**
	* 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) {
				// appended & because typo3 has a small bug
				// if there is no 'id=' in the query typo3 thinks that ftu=... is the id
				paramAppend = '?&';
			}

			// redirect to self with url-param
			document.location.href = document.location.href + paramAppend + redirectString;
		} // end: if
	} // end: function

	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]();
			}
		}
	} // end: function

	/**
	*
	* @access public
	* @param  func
	* @return void
	*/
	function addOnloadFunction(func) {
		if (typeof func == 'function') {
			dmcOnloadFuncs.push(func);
		}
	} // end: function

	/**
	*
	* @access public
	* @param  url
	* @param  name
	* @param  parameter
	* @return popuphandler
	*/
	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;
	} // end: function

	/**
	*
	* @access public
	* @param  url
	* @param  name
	* @param  parameter
	*/
	function openJQueryPopupWindow(url, name, parameter) {
				
		name	 = '<span style="font-size:17px;font-weight:bold">'+name+'</span>';
		popupurl = url+"?TB_iframe=true&";
		
		// Wenn ein Parameter uebergeben wird --> diesen uebernehmen
		if (parameter) {
			size = parameter.replace(/\,/g, "&");
			popupurl = url+"?TB_iframe=true&"+size;
		}

		tb_show(name, popupurl, false);

	} // end: function


	/*
	Copyright (c) 2005 JSON.org

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The Software shall be used for Good, not Evil.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
	*/

	var JSON = {
		org: 'http://www.JSON.org',
		copyright: '(c)2005 JSON.org',
		license: 'http://www.crockford.com/JSON/license.html',

		stringify: function (arg) {
	    	var c, i, l, s = '', v;
	    	var numeric = true;

	    	switch (typeof arg) {
	    		case 'object':
	      			if (arg) {
	        			if(Array.prototype.isPrototypeOf(arg)){
	          			// do a test whether all array keys are numeric
	          				for (i in arg) {
	            				if (isNaN(i) || !isFinite(i)) {
	              					numeric = false;
	              					break;
	            				} // end: if
	          				} // end: for

	          				if (numeric == true) {
	            				for (i = 0; i < arg.length; ++i) {
	              					if (typeof arg[i] != 'undefined') {
	                					v = this.stringify(arg[i]);
	                					if (s) {
	                  						s += ',';
	                					} // end: if
	                					s += v;
	              					} else {
	                					s += ',null';
	              					} // end: if
	            				} // end: for
	            				return '[' + s + ']';
	          				} else {
	            				for (i in arg) {
	                				v = arg[i];
	                				if (typeof v != 'undefined' && typeof v != 'function') {
	                  					v = this.stringify(v);
	                  					if (s) {
	                    					s += ',';
	                  					}
	                  					s += this.stringify(i) + ':' + v;
	                				} // end: if
	            				} // end: for
	            				// return as object
	            				return '{' + s + '}';
	          				} // end: if
	        			} else if (typeof arg.toString != 'undefined') {
	          				for (i in arg) {
	            				v = arg[i];
	            				if (typeof v != 'undefined' && typeof v != 'function') {
	              					v = this.stringify(v);
	              					if (s) {
	                					s += ',';
	              					} // end: if
	              					s += this.stringify(i) + ':' + v;
	            				} // end: if
	          				} // end: for
	          				return '{' + s + '}';
	        			} // end: if
	      			} // end: if
	      			return 'null';

				case 'number':
	      			return isFinite(arg) ? String(arg) : 'null';

				case 'string':
			      	l = arg.length;
					s = '"';
	      			for (i = 0; i < l; i += 1) {
	        			c = arg.charAt(i);
	        			if (c >= ' ') {
	          				if (c == '\\' || c == '"') {
	            				s += '\\';
	          				} // end: if
	          				s += c;
			        	} else {
	          				switch (c) {
	            				case '\b':
	              					s += '\\b';
	              					break;
	            				case '\f':
	              					s += '\\f';
	              					break;
	            				case '\n':
	              					s += '\\n';
	              					break;
	            				case '\r':
	              					s += '\\r';
	              					break;
	            				case '\t':
	              					s += '\\t';
	              					break;
	            				default:
	              					c = c.charCodeAt();
	              					s += '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
	          				} // end: if
	        			} // end: if
	      			} // end: for
	      			return s + '"';

				case 'boolean':
	      			return String(arg);

	   			default:
	      			return 'null';
	    	} // end: switch
	  	},

		parse: function (text) {
	    	var at = 0;
	    	var ch = ' ';

	    	function error(m) {
	      		throw {
	        		name: 'JSONError',
	        		message: m,
	        		at: at - 1,
	        		text: text
	      		};
	    	} // end: function

	    	function next() {
	      		ch = text.charAt(at);
	      		at += 1;
	      		return ch;
	    	} // end: function

	    	function white() {
	      		while (ch != '' && ch <= ' ') {
	        		next();
	      		} // end: while
	    	} // end: function

	    	function str() {
	      		var i, s = '', t, u;

	      		if (ch == '"') {
					outer:      while (next()) {
	          			if (ch == '"') {
	            			next();
	            			return s;
	          			} else if (ch == '\\') {
	            			switch (next()) {
	            				case 'b':
	              					s += '\b';
	              					break;
	            				case 'f':
	              					s += '\f';
	              					break;
	            				case 'n':
	              					s += '\n';
	              					break;
	            				case 'r':
	              					s += '\r';
	              					break;
	            				case 't':
	              					s += '\t';
	              					break;
	            				case 'u':
	              					u = 0;
	              					for (i = 0; i < 4; i += 1) {
	                					t = parseInt(next(), 16);
	                					if (!isFinite(t)) {
	                  						break outer;
	                					} // end: if
	                					u = u * 16 + t;
	              					} // end: for
	              					s += String.fromCharCode(u);
	              					break;
	            				default:
	              					s += ch;
	            			} // end: switch
	          			} else {
	            			s += ch;
	          			} // end: if
	        		} // end: while
	      		} // end: if
	      		error("Bad string");
	    	} // end: function

	    	function arr() {
	      		var a = [];

	      		if (ch == '[') {
	        		next();
	        		white();
	        		if (ch == ']') {
	          			next();
	          			return a;
	        		} // end: if
	        		while (ch) {
	          			a.push(val());
	          			white();
	          			if (ch == ']') {
	            			next();
	            			return a;
	          			} else if (ch != ',') {
	            			break;
	          			} // end: if
	          			next();
	          			white();
	        		} // end: while
	      		} // end: if
	      		error("Bad array");
	    	} // end: function

	    	function obj() {
	      		var k, o = {};

	      		if (ch == '{') {
	        		next();
	        		white();
	        		if (ch == '}') {
	          			next();
	          			return o;
	        		} // end: if
	        		while (ch) {
	          			k = str();
	          			white();
	          			if (ch != ':') {
	            			break;
	          			}
	          			next();
	          			o[k] = val();
	          			white();
	          			if (ch == '}') {
	            			next();
	            			return o;
	          			} else if (ch != ',') {
	            			break;
	          			} // end: if
	          			next();
	          			white();
	        		} // end: while
	      		} // end: if
	      		error("Bad object");
	    	} // end: function

	    	function assoc() {
	      		var k, a = [];

	      		if (ch == '<') {
	        		next();
	        		white();
	        		if (ch == '>') {
	          			next();
	          			return a;
	        		}
	        		while (ch) {
	          			k = str();
	          			white();
	          			if (ch != ':') {
	            			break;
	          			} // end: if
	          			next();
	          			a[k] = val();
	          			white();
	          			if (ch == '>') {
	            			next();
	            			return a;
	          			} else if (ch != ',') {
	            			break;
	          			} // end: if
	          			next();
	          			white();
	        		} // end: while
	      		} // end: if
	      		error("Bad associative array");
	    	} // end: function

	    	function num() {
	      		var n = '', v;

		  		if (ch == '-') {
	        		n = '-';
	        		next();
	      		} // end: if
	      		while (ch >= '0' && ch <= '9') {
	        		n += ch;
	        		next();
	      		} // end: while
	      		if (ch == '.') {
	        		n += '.';
	        		while (next() && ch >= '0' && ch <= '9') {
	          			n += ch;
	        		} // end: while
	      		} // end: if
	      		if (ch == 'e' || ch == 'E') {
	        		n += 'e';
	        		next();
	        		if (ch == '-' || ch == '+') {
	          			n += ch;
	          			next();
	        		} // end: if
	        		while (ch >= '0' && ch <= '9') {
	          			n += ch;
	          			next();
	        		} // end: while
	      		} // end: if
	      		v = +n;
	      		if (!isFinite(v)) {
	        		error("Bad number");
	      		} else {
	        		return v;
	      		} // end: if
	    	} // end: function

	    	function word() {

			  	switch (ch) {
	        		case 't':
	          			if (next() == 'r' && next() == 'u' && next() == 'e') {
	            			next();
	            			return true;
	          			} // end: if
	          			break;
	        		case 'f':
	          			if (next() == 'a' && next() == 'l' && next() == 's' &&
	              			next() == 'e') {
	            			next();
	            			return false;
	          			} // end: if
	          			break;
	        		case 'n':
	          			if (next() == 'u' && next() == 'l' && next() == 'l') {
	            			next();
	            			return null;
	          			} // end: if
	          			break;
	      		} // end: switch
	      		error("Syntax error");
	    	} // end: function

	    	function val() {

		  		white();
	      		switch (ch) {
	        		case '{':
	          			return obj();
	        		case '[':
	          			return arr();
	        		case '<':
	          			return assoc();
	        		case '"':
	          			return str();
	        		case '-':
	          			return num();
	        		default:
	          			return ch >= '0' && ch <= '9' ? num() : word();
	      		} // end: switch
	    	} // end: function

	    	return val();
	  	}
	};




	var dmc_mb3_product_pi1mediaActive	= '';
	var dmc_mb3_product_pi1mediaIndex	= 0;
	var dmc_mb3_product_pi1amountError	= '';

	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) {

		if(typeof productConf[uid][id] == 'undefined') return;

		/* 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'];

		/* check whether a single article is preselected */
		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 */
				} /* 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);

		displayArtNumber(uid, id, variation, size, color);
		displayPrice(uid, id, variation, size, color);
		displayAvailability(uid, id, variation, size, color);
		displayDynamicBasePrice(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 */
	}

	function changeProduct(uid, id, startFrom) {
		/* 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 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);
		displayDynamicBasePrice(uid, id, variation, size, color);

		showCurrentMainImage(uid, id, variation, size, color);
	}

	function showCurrentMainImage(uid, id, variation, size, color){
		var artNumber	= getCurrentArtNumber(uid, id, variation, size, color);
		var mainImage	= document.getElementById('dmc_mb3_product_pi1' + uid + 'MainImage');
		var imageSize = 'large';
		var imageArray	= productConf[uid]['main'][imageSize];

		/* set default */
		dmc_mb3_product_pi1mediaIndex = 'default';
		mainImage.src = productConf[uid]['main'][imageSize][0];
		/* serach right image */
		for (var i = 0; i < imageArray.length; ++i) {

			var matches = /([0-9]*)\.jpg$/.exec(imageArray[i]);
			if (matches) {
				if(matches[1] == artNumber){
					mainImage.src = imageArray[i];
					dmc_mb3_product_pi1mediaIndex = i;
					break;
				}
			} /* end: if */
		}

	} /* end: function */

	function getCurrentArtNumber(uid, id, variation, size, color) {
		return productConf[uid][id]['articles'][variation][size][color]['artNumber'];
	}

	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);

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

	function addToBasketSubmit(uid, id, target, popup, url, popupParams) {
		var amount			= 0;
		var amountForm		= document.getElementById('productAmountForm_' + uid + '_' + id);

		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 (amount > 0) {

				if (popup) {

					var form			= document.getElementById('productForm_' + uid);
					form.action = url;

					var variation		= currentVariation(uid, id);
					var size			= currentSize(uid, id, variation);
					var color			= currentColor(uid, id, variation, size);
					var articlePk		= productConf[uid][id]['articles'][variation][size][color]['articlePk'];

					if (url.search(new RegExp(window.location.host)) != -1) {
							var pattern = new RegExp(window.location.host+'\/');
							var replace = window.location.host+'/article/'+articlePk+'/';
					} else {
							var pattern = new RegExp('\/');
							var replace = '/article/'+articlePk+'/';
					}
					url = url.replace(pattern, replace);

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

				addToBasket(uid, id);
			} else {
				alert(dmc_mb3_product_pi1amountError);
			}
		}
	}


	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 (amount > 0) {
			if (form && pkForm && productPkForm) {
				pkForm.value		= productConf[uid][id]['articles'][variation][size][color]['articlePk'];
				productPkForm.value = id;
				form.submit();
				window.close();
			}
		} else {
			alert(dmc_mb3_product_pi1amountError);
		}

		return false;
	}

	function displayArtNumber(uid, id, variation, size, color) {
		var artNumberDiv			= document.getElementById('productArtNumber_' 			+ uid + '_' + id);
		var articleOrderNumberDiv	= document.getElementById('productArticleOrderNumber_' + 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 */

		if (articleOrderNumberDiv) {
			articleOrderNumberDiv.innerHTML = productConf[uid][id]['articles'][variation][size][color]['articleOrderNumber'];
		} /* 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 displayDynamicBasePrice(uid, id, variation, size, color) {
		var availDiv	= document.getElementById('dynamicbasepricelabel_' 		+ uid + '_' + id);

		if (availDiv) {
			availDiv.innerHTML	= productConf[uid][id]['articles'][variation][size][color]['dynamicbasepricelabel'];
		} /* 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 == '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 */

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

			/* fill with new sizes */
			for (tmpSize in productConf[uid][id]['articles'][variation]) {

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

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

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

					index++;
				} /* end: for */
			} 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 openerUrl(url){
		if (opener == null || typeof(opener.name) == "unknown" || typeof(opener.name) == "undefined" ) {
			var handler = window.open(url,'','');
			handler.focus();
			self.close();
		} else {
			opener.location.href = url;
			opener.focus();
			self.close();
		}
	}



	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 shoppingbasketCheckPaymentType(ctype, uid, installment){
	var installmentCheckBox = document.getElementById(ctype + '[' + uid + ']' + '[installment][checkbox]');

	var mode	= installmentCheckBox.checked;
    if(installment == '1') {
		installmentCheckBox.disabled = false;
	} else {
		installmentCheckBox.checked	= false;
		installmentCheckBox.disabled = true;
	}
}


basketDisplayList = function () {

	this.headObj = new Object();
	this.listObj = new Object();
	this.bottomObj = new Object();

	this.data = new Array();
	this.fwdLinkHTML = '';
	this.errorHTML = '';
	this.numberPerPage = 3;
	this.startIndex = 0;
	this.onLastPage = 0;

	this.init = function (prefix, headId, listId, bottomId) {
		this.headObj = document.getElementById(prefix+headId);
		this.listObj = document.getElementById(prefix+listId);
		this.bottomObj = document.getElementById(prefix+bottomId);
		this.renderList();
	}

	this.renderList = function () {
		var content = '';

		if (this.data.length == 0) {

			this.headObj.innerHTML = '';
			this.bottomObj.innerHTML = '';

			this.listObj.innerHTML = this.errorHTML;

		} else {

			var lastIndex = this.data.length - 1;
			var endIndex  = this.startIndex + this.numberPerPage;

			for (i in this.data) {
				if (i >= this.startIndex && i < endIndex) {
					content += this.data[i];
					if (i == lastIndex) {
						this.onLastPage = 1;
					}
				}
			}

			if (this.data.length > this.numberPerPage) {
				content += this.fwdLinkHTML;
			}

			this.listObj.innerHTML = content;
		}
	}

	this.fwd = function () {

		if (this.onLastPage == 1) {
			this.onLastPage = 0;
			this.startIndex = 0;
		} else {
			this.startIndex += this.numberPerPage;
		}

		this.renderList();
	}
}

/*
 * function.js
 *
 * The content of this file is (c) 2003 - 2007 dmc
 * digital media center GmbH
 * All rights reserved
 *
 * This software is the confidential and proprietary
 * information of dmc digital media center GmbH.
 *
 */


/**
 * tooltip methods for the newsletter extension
 *
 * $Id: functions.js 52 2008-07-11 14:44:26Z sbe $
 */

var mouseX 			= 0;
var mouseY 			= 0;
var tooltip 		= null;

/**
*
* @access public
* @param  e
* @return void
*/
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;
	} // end: if
} // end: function

/**
*
* @access public
* @param  x
* @param  y
* @return void
*/
function updateTooltip(x, y) {

	if (tooltip != null) {
		tooltip.style.left	= (x + 10) + 'px';
		tooltip.style.top 	= (y + 10) + 'px';
	} // end: if
} // end: function

/**
*
* @access public
* @param  id
* @return void
*/
function showTooltip(id) {
	tooltip = document.getElementById(id);

	if (tooltip.innerHTML != '') {
		tooltip.style.display 		= 'block';
		tooltip.style.visibility	= 'visible';
	} // end: if
} // end: function

/**
*
* @access public
* @return void
*/
function hideTooltip() {
	tooltip.style.display 		= 'none';
	tooltip.style.visibility	= 'hidden';

	tooltip = null;
} // 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 + ']';
	}

	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).className = 'fieldVisible'
	}
}

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 (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;
				}
			}
		}
	}

	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;
		}
	}

	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.
		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 > 100) {
			amountNum = 100;
		}

		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'];
		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);
	}

}

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  = "";

	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';
		}
	}

	if (errorLabel.length > 0) {
		classname = document.getElementById('text_'+errorLabel+'_'+lineNumber).className.replace("noError", "formError");
		document.getElementById('text_'+errorLabel+'_'+lineNumber).className = classname;
		document.getElementById('error_'+lineNumber).innerHTML = errorTexts[errorLabel];
		document.getElementById('errorbox_' +lineNumber).className = ' errorVisible';
	} else {
		document.getElementById('errorbox_' +lineNumber).className = ' errorHidden';
	}
}

function fieldOnFocus(field, lineNumber) {
	document.getElementById('selectbox_'+field+'_'+lineNumber).selectedIndex = -1;
	setDivVisible(field+'_'+lineNumber);
}

function fieldOnBlur(field, lineNumber) {
	document.getElementById('selectdiv_'+field+'_'+lineNumber).className = 'fieldHidden';
}

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
	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) {

		var url		= '/typo3conf/ext/dmc_mb3_orderform/ajaxGetArticleData.php';
		var data	= 'artnumber='+artnumber+'&clientPk='+clientPk+'&languagePk='+languagePk+'&lineNumber='+lineNumber;

		 $.ajax({
			 type		: 'POST',
			 url		: url,
			 data		: data,
			 dataType	: 'json',
			 success	: function(result){
				response(result);
			 }
		 });

	} else {

		updateSize(lineNumber);
	}
}

function response(result) {

	var artnumber = result['artnumber'];
	var lineNumber = result['lineNumber'];
	if (result['status'] == 'found') {
		articleData[artnumber] = result['properties'];
	}
	document.getElementById('text_artnumber_'+lineNumber).value = artnumber;
	updateSize(lineNumber);
	document.getElementById('text_size_'+lineNumber).focus();
	fieldOnFocus('size',lineNumber);
}

function productInfoPopup(productlinkId,titleId) {

	var popupurl = document.getElementById(productlinkId).value;
	var title = document.getElementById(titleId);
	if (title) {
		title = title.textContent;
	} else {
		title = '';
	}
	openJQueryPopupWindow(popupurl,title,'width=705,height=510,scrollbars=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,location=no')

}



var SearchBoxManager = function () {

	this.searchType = 0;
	this.searchType_default = 0;
	this.searchWord = '';
	this.searchForm = new Object();
	this.searchDefaultText = '';
	this.errorNoSearchWord = '';
	
	this.searchTargets = {
		'mb3': {
			'inputName': 'dmc_mb3_search_pi1[searchstring]',
			'action': ''
		},
		'typo3': {
			'inputName': 'tx_indexedsearch[sword]',
			'action': ''
		}
	}	
	
	this.init = function () {
		imagePreload_start();

		/* if init set should be typo3, ... */
		if (this.searchType == 1 ) {
			if(this.searchType_default != 1){
				this.toggleSelector('Shop', 'Website');
			}
			this.setFormValues('typo3');
		}
	}
	
	this.switchTarget = function (target) {

		/* website : typo3 */
		if (target == 'typo3') {
			this.toggleSelector('Shop', 'Website');
			this.setFormValues('typo3');

		/* shop : mb3 */
		} else if (target == 'mb3') {
			this.toggleSelector('Website', 'Shop');
			this.setFormValues('mb3');
		}
	}
	
	this.setFormValues = function(target) {

		/* website : typo3 */
		if (target == 'typo3') {
			document.getElementById('searchField').name = this.searchTargets.typo3.inputName;
			document.getElementById('searchType').value = 1;
			this.searchType = 1;
			this.searchForm.action = this.searchTargets.typo3.action;

		/* shop : mb3 */
		} else if (target == 'mb3') {
			document.getElementById('searchField').name = this.searchTargets.mb3.inputName;
			document.getElementById('searchType').value = 0;		
			this.searchType = 0;
			this.searchForm.action = this.searchTargets.mb3.action;
		}
	}
	
	this.toggleSelector = function (from, to) {
		document.getElementById('search'+from).style.display = 'none';
		document.getElementById('search'+from+'Layer').style.display = 'none';
		document.getElementById('search'+to).style.display = 'block';

		document.getElementById('search'+from+'Layer').style.visibility = 'hidden';
		document.getElementById('search'+to+'Layer').style.visibility = 'visible';
	}

	this.toggleLayer = function (layer) {
		var layerObj = document.getElementById('search'+layer+'Layer')

		layerObj.style.display = ( layerObj.style.display == 'none' ) ? "block" : "none";
	}
	
	this.checkInput = function () {
		var returnValue = false;

		if (document.getElementById('searchField').value != this.searchDefaultText) {
			returnValue = true;
		} else {
			alert(this.errorNoSearchWord);
		}

		return returnValue;
	}
	
	this.submit = function () {
		var check = this.checkInput();
		
		if (check) {
			this.searchForm.submit();
		}
	}
}


// function to load images
var pos_array = 0;
function imagePreload() {
	var new_image = new Image();
	new_image.src = preload_images[pos_array];
	pos_array++;
	if(pos_array < preload_images.length) {
		setTimeout('imagePreload()', 1);
	}
}
// start of load function
function imagePreload_start() {
	// images available?
	if(preload_images.length == 0) {
		return;
	} else {
		setTimeout('imagePreload()', 1);
	}
}



/**
* Function to position the address in header next to logo
*
* @param	element			html code to positioning
* @param	nextToArea		target area
* @access	public
* @return	void
*
*/
function positionEshopInHeader(element, nextToArea) {

	var selectedElement;
	var targetArea;
	
	selectedElement = document.getElementById(element);
	targetArea = document.getElementById(nextToArea);
	targetArea.appendChild(selectedElement);
}

jx={http:false,format:'text',callback:function(data){},handler:false,error:false,opt:new Object(),
getHTTPObject:function(){var http=false;if(typeof ActiveXObject !='undefined'){try{http=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){
try{http=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){http=false;}}
}else if(XMLHttpRequest){try{http=new XMLHttpRequest();}catch(e){http=false;}}return http;},
load:function(url,callback,format,method){this.init();if(!this.http||!url)return;
//if(this.http.overrideMimeType)this.http.overrideMimeType('text/xml');
this.callback=callback;
if(!method)var method="GET";if(!format)var format="text";this.format=format.toLowerCase();
method=method.toUpperCase();var ths=this;var now="cuid="+new Date().getTime();url+=(url.indexOf("?")+1)?"&":"?";
url+=now;var parameters=null;if(method=="POST"){var parts=url.split("\?");url=parts[0];parameters=parts[1];}
this.http.open(method,url,true);if(method=="POST"){
this.http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
this.http.setRequestHeader("Content-length",parameters.length);this.http.setRequestHeader("Connection","close");
}if(this.handler){this.http.onreadystatechange=this.handler;}else{this.http.onreadystatechange=function(){
if(!ths)return;var http=ths.http;if(http.readyState==4){if(http.status==200){var result="";
if(http.responseText)result=http.responseText;if(ths.format.charAt(0)=="j"){result=result.replace(/[\n\r]/g,"");
result=eval('('+result+')');}else if(ths.format.charAt(0)=="x"){result=http.responseXML;}
if(ths.callback)ths.callback(result);}else{
if(ths.opt.loadingIndicator)document.getElementsByTagName("body")[0].removeChild(ths.opt.loadingIndicator);
if(ths.opt.loading)document.getElementById(ths.opt.loading).style.display="none";
if(ths.error)ths.error(http.status);}}}}this.http.send(parameters);},
bind : function(user_options) {var opt = {'url':'','onSuccess':false,'onError':false,'format':"text",
'method':"GET",'update':"",'loading':"",'loadingIndicator':""}
for(var key in opt) {if(user_options[key]) {opt[key] = user_options[key];}}
this.opt = opt;if(!opt.url) return;if(opt.onError) this.error = opt.onError;var div = false;
if(opt.loadingIndicator) {div = document.createElement("div");
div.setAttribute("style","position:absolute;top:0px;left:0px;");div.setAttribute("class","loading-indicator");
div.innerHTML = opt.loadingIndicator;document.getElementsByTagName("body")[0].appendChild(div);
this.opt.loadingIndicator=div;}if(opt.loading) document.getElementById(opt.loading).style.display="block";
this.load(opt.url,function(data){if(opt.onSuccess) opt.onSuccess(data);
if(opt.update) document.getElementById(opt.update).innerHTML = data;
if(div) document.getElementsByTagName("body")[0].removeChild(div);
if(opt.loading) document.getElementById(opt.loading).style.display="none";
},opt.format,opt.method);},init : function() {this.http = this.getHTTPObject();}}


// Merge Objects: @see http://www.prototypejs.org/api/object/extend
Object.extend = function(destination, source) {
	for (var property in source)
		destination[property] = source[property];
	return destination;
};

ifcRedirect = function(data) {
	// bind function calls a callback function with data from ajax call
	// i did not see a possibility to pass over redirectUrl, it is stored in the global object IFC though
	window.location.href = IFC.conf.redirectUrl;
}

var InstituteFinderConnector = function () {

	this.conf = {
		pageId:'',
		uid:'',
		form:'',
		tmpl:'',
		ll:'',
		updateId:'',
		loading:'',
		ext:'dmc_institutefinder',
		ctype:'dmc_institutefinder_pi1',
		redirectUrl:''
	}
	
	this.formPrefix = '';
	this.formObj = {};
	this.savedParams = {};
	this.params = [];
	
	this.init = function () {

		this.formPrefix = this.conf.ctype+'['+this.conf.uid+']';
		this.formObj = document.getElementById(this.conf.form);
		this.setInitParams();
	}
	
	this.setConfig = function (conf) {
		Object.extend(this.conf, conf || { });
	}

	this.handleStep = function (obj, step, context, addargs) {
	
		switch (context) {
			case 'filterState':
			case 'filterCity':
				if (obj.value != '') {
					this.resetFormFields([obj.name]);
					this.setInitParams();
					this.setFormParams();
					if (document.getElementById(this.formPrefix+'[filter][country]').value == 'LUX') {
						this.setResultStep();
					} else {
						this.setReloadContentAndResultStep();
					}
					this.getStep(step);
				}				
				break;

			case 'filterZipsearch':
				this.resetFormFields([this.formPrefix+'[filter][zipsearch]']);
				this.setInitParams();
				this.setFormParams();
				this.setReloadContentAndResultStep();
				this.getStep(step);				
				break;

			case 'filterMap':
				document.getElementById(this.formPrefix+'[filter][zipsearch]').value = addargs;
				this.resetFormFields([this.formPrefix+'[filter][zipsearch]']);
				this.setInitParams();
				this.setFormParams();
				this.setResultStep();
				this.getStep(step);
				break;
			
			case 'filterRegion':
				if (obj.value != '') {
					var redirectCountries = ['DEU', 'CHE', 'NLD', 'BEL', 'AUT', 'LUX'];
					var redirectToCountyStep = false;
	
				    for (var i=0; i < redirectCountries.length; i++) {
						if (obj.value == redirectCountries[i]) {
							redirectToCountyStep = true;
							break;
						}
				    }
	
					document.getElementById(this.formPrefix+'[filter][country]').value = obj.value;
	
					this.resetFormFields([obj.name]);
					this.setInitParams();
					this.setFormParams();
	
				    if (redirectToCountyStep == true) {
						this.conf.updateId = 'updateContainer';
						this.getStep('country');
				    } else {
				    	this.setResultStep();
						this.getStep(step);
					}
				}
				break;
				
			case 'filterBar':
				if (obj.value == '') {
					obj.value = 1;
				} else {
					obj.value = '';
				}

				this.setInitParams();
				this.setFormParams();
				this.setResultStep();
				
				this.getStep(step);
				break;

			case 'nextResults':
				document.getElementById(this.formPrefix+'[next]').value = addargs;
				this.setInitParams();
				this.setFormParams();
				this.setResultStep();
				this.getStep(step);
				break;
			
							
			default:
				this.setInitParams();
				this.setFormParams();
				this.getStep(step);
				
				break;
		}
	}

	this.setInitParams = function () {
		this.params = [];
		this.params.push({key:'eID', value:this.conf.ext});
		this.params.push({key:'id', value:this.conf.pageId});
		this.params.push({key:'uid', value:this.conf.uid});
		this.params.push({key:'ctype', value:this.conf.ctype});
		this.params.push({key:'tmpl', value:this.conf.tmpl});
		this.params.push({key:'ll', value:this.conf.ll});
	}

	this.setResultStep = function () {
		this.params.push({key:this.formPrefix+'[substep]', value:'result'});
		this.conf.updateId = 'subUpdateContainer';
	}

	this.setReloadContentAndResultStep = function () {
		this.params.push({key:this.formPrefix+'[substep]', value:'result'});
		this.params.push({key:this.formPrefix+'[reloadcontent]', value:'1'});
		this.conf.updateId = 'updateContainer';
	}

	this.resetFormFields = function (excludeFields) {

	    for (var i=0; i < this.formObj.elements.length; i++) {
			var element = this.formObj.elements[i];
	
			if (typeof excludeFields != 'undefined') {
				for (var j=0; j < excludeFields.length; j++) {
					if (element.name.indexOf(excludeFields[j]) < 0) {
						switch (element.type) {
							case 'select-one':
								element.selectedIndex = 0;
								break;
								
							case 'text':
								element.value = '';
								break;
						}
					}
			    }
			} else {
				switch (element.type) {
					case 'select-one':
						element.selectedIndex = 0;
						break;
						
					case 'text':
						element.value = '';
						break;
				}
			}
	    }
	}

	this.setFormParams = function (allowedFields) {

	    for (var i=0; i < this.formObj.elements.length; i++) {
			var element = this.formObj.elements[i];
	
			if (typeof allowedFields != 'undefined') {
			    for (var i=0; i < allowedFields.length; i++) {
					if (element.name.indexOf(allowedFields[i]) > 0) {
						this.params.push({key:element.name, value:element.value});					
					}
			    }
			} else {
				this.params.push({key:element.name, value:element.value});				
			}
	    }
	}
	
	this.getStep = function (step) {
	    var url = '/index.php?';
	
		this.params.push({key:this.formPrefix+'[step]', value:step});
		
	    for (var i=0; i < this.params.length; i++) {
	    	url += '&' + this.params[i].key +'='+ this.params[i].value;
	    }
		
		var JXConf = {
			'url':url,
			'update':this.conf.updateId,
			'method':'post',
			'onSuccess':false
		};

		if ( this.conf.redirectUrl != '' ) {
			redirectUrl		= this.conf.redirectUrl;
			JXConf.onSuccess= ifcRedirect;
			JXConf.update	= "";
		} 
		
		if (this.conf.loading != '') {
			JXConf.loading = this.conf.loading;
		} 

		// bind data to jx ajax object    
		jx.bind(JXConf);
	}
	
	this.de = function () {
		console.dir(this);
	}
}
