/**
* 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 5850 2007-11-22 09:40:02Z toegerol $
 */

	/**
	* 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

	/*
	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();
	  	}
	};




/*
 * 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.
 *
 */


/**
 * functions to set pco actions
 *
 * $Id: functions.js 173 2008-08-26 12:05:52Z jri $
 */


	/**
	* set a pco action to a defined action form field
	*
	* @access public
	* @param  ctype       the name of the extension
	* @param  uid         the uid of the pageelement
	* @param  newAction   the name of the pco action
	* @return void
	*/
	function pcoFormSetAction(ctype, uid, newAction) {

		var action			= document.getElementById(ctype + '[' + uid + ']' + '[pcoAction]');

		if (action) {
			action.value = newAction;
		} // end: if
	} // end: function


/*
 * 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 173 2008-08-26 12:05:52Z jri $
 */

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

	var dmc_mb3_product_pi1mediaActive	= '';
	var dmc_mb3_product_pi1mediaIndex	= 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) {
		/* 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 searchTerm		= document.getElementById('product_searchstring');
		var state			= productConf[uid][id]['state'];
		var articlenumber	= '';
		var isMatched		= false;

		/* 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]) {

					// To search for the article number with all articles, if it matches, the search term has to be the article number with the given adcode
					articlenumber = productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['articleOrderNumber'];
					if (searchTerm != null && articlenumber.substr(0, 6) == searchTerm.value.substr(0, 6) && isMatched != true) {
						productConf[uid][id]['articles'][tmpVariation][tmpSize][tmpColor]['selected'] = '1';
						isMatched = true;
					} /* end: if */
					
					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);

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

	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;

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

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

		addToBasket(uid, id);
	}


	function changeItemInBasket(uid, id, actionValue) {

		if(uid.indexOf('_') != -1) {
			arrUID = uid.split ('_');
			shoppingUid = arrUID[0];
		} else {
			shoppingUid = uid;
		}
		var strFomrId		= 'dmc_mb3_shoppingbasket_pi1['+ shoppingUid + '][form]';
 		var form			= document.getElementById(strFomrId);
		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.action = actionValue;
			form.submit();
			// window.close();
		}

		return false;
	}

	function displayArtNumber(uid, id, variation, size, color) {
		var artNumberDiv			= document.getElementById('productArtNumber_' 			+ uid + '_' + id);
		var articleOrderNumberDiv	= document.getElementById('productArticleOrderNumber_' + uid + '_' + id);
		var searchTerm				= document.getElementById('product_searchstring');
		var articlenumber			= '';
		var isMatched				= false;
		
		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 search is made and search term is found in the article number, then search term has to be displayed
		if(size != undefined && variation != undefined){
			articlenumber = productConf[uid][id]['articles'][variation][size][color]['articleOrderNumber'];
		}
		if (searchTerm != null && articlenumber.substr(0, 6) == searchTerm.value.substr(0, 6)) {
			isMatched = true;
		} /* end: if */

		if (articleOrderNumberDiv && articlenumber != '') {
			// If the article number is valid and found in the article list, replace the articlenumber with search term
			if(isMatched == true) {
				articleOrderNumberDiv.innerHTML = searchTerm.value;
			} else {
				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');
		oldPriceWrap.style.visibility	= 'hidden';
		oldPriceWrap.style.display		= 'none';
		if (oldPriceDiv && oldPriceWrap && size) {
			var oldPrice 	= productConf[uid][id]['articles'][variation][size][color]['oldPrice'];
			var oldPriceNumericRegex = oldPrice.match(/(\d)/);
			if (oldPriceNumericRegex.length > 0 && oldPriceNumericRegex[0] > 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';
			}
		}
		if (priceDiv && size) {
			priceDiv.innerHTML	= productConf[uid][id]['articles'][variation][size][color]['price'];
			if(oldPrice > 0) {
				priceDiv.style.color = 'red';
			}
		} /* end: if */

	}

	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 */
	}

	//chk if an object is an array or not.
	function isArray(obj) {
		//returns true is it is an array
		if (obj.constructor.toString().indexOf('Array') == -1)
			return false;
		else
			return true;
	}

	function firstVariation(uid, id) {

		/* find first variation */
		var returnValue

		for (returnValue in productConf[uid][id]['articles']) {
			// workaround for
			// To ignore '______array' value in array
			if(returnValue != '______array') {
				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']) {

					// workaround for
					// To ignore '______array' value in array
					if(tmpVariation != '______array') {
						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]) {
			// workaround for
			// To ignore '______array' value in array
			if(returnValue != '______array') {
				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]) {

				// workaround for
				// To ignore '______array' value in array
				if(tmpSize != '______array') {
					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: if

			} /* 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 */
		var returnValue = false;
		if(size != undefined && variation != undefined){
			for (var returnValue in productConf[uid][id]['articles'][variation][size]) {
				// workaround for
				// To ignore '______array' value in array
				if(returnValue != '______array') {
					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]) {

					// workaround for
					// To ignore '______array' value in array
					if(tmpColor != '______array') {
						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: if
				} /* 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 */
	}

	function doShowTooltip(uid, id, ev, show)
	{
	    ev = ev || window.event;
		if(ev.pageX || ev.pageY)
		{
		    x = ev.pageX;
		    y = ev.pageY;
		}else{
			x = ev.clientX + document.body.scrollLeft - document.body.clientLeft;
			y = ev.clientY + document.body.scrollTop  - document.body.clientTop;
		}

	    var oToolTip = document.getElementById('basketTooltip');
		if (show)
		{
		    if (!checkAllSelected(uid, id)) {
				oToolTip.style.left = x-20;
				oToolTip.style.top = y-105;
				oToolTip.style.display='block';
			}
		} else {
			oToolTip.style.display='none';
		}
	}

	function checkAllSelected(uid, id) {
		if(!isEmptyForm(uid, id, 'productVariationForm_') && !isEmptyForm(uid, id, 'productSizeForm_') &&
			!isEmptyForm(uid, id, 'productColorForm_')) {
				document.getElementById('linkAddButtonId').className = 'submit_on floatRight';
				document.getElementById('linkAddButtonId').src="/typo3conf/ext/dmc_mb3_product/images/1/de/ags/basket_on.gif"
				return true;
		} else {
			document.getElementById('linkAddButtonId').className = 'submit_off floatRight';
			document.getElementById('linkAddButtonId').src="/typo3conf/ext/dmc_mb3_product/images/1/de/ags/basket_off.gif"
			return false;
		}
	}

	function isEmptyForm(uid, id, formFieldName) {
		var returnValue		= false;
		var formField		= document.getElementById(formFieldName	+ uid + '_' + id);

		if (formField) {
			if (formField.nodeName == 'SELECT' && formField.selectedIndex != -1) {
				returnValue = formField.options[formField.selectedIndex].value;
				returnValue = false;
			} else if (formField.nodeName == 'INPUT' &&
				(formField.type == 'text' || formField.type == 'hidden')) {
					returnValue = false;
			} else {
				returnValue = true;
			} /* end: if*/
		} else {
			returnValue = false;
		}/* end: if */

		return returnValue;
	}


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



	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;
	}
}

/**
* 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 this.decodeUtf8(unescape(String(data).replace(lsRegExp, " ")));
	},

	/**
	* decodes a string in utf8
	*
	* @param string 	utftext							string to be decoded
	* @return void
	*/
	decodeUtf8: function (utftext) {
		var plaintext = "";
		var i=0;
		var c=0;
		var c1=0;
		var c2=0;

		// while-Schleife, weil einige Zeichen uebersprungen werden
		while(i<utftext.length) {
			c = utftext.charCodeAt(i);
			if (c<128) {
				plaintext += String.fromCharCode(c);
				i++;
			} else if((c>191) && (c<224)) {
				c2 = utftext.charCodeAt(i+1);
				plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
				i+=2;
			} else {
				c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
				plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
				i+=3;
			}
		}

		return plaintext;
	 } // end: function

}

/**
* 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) {
		var articlesAmountContainer = document.getElementById(articlesAmountContainerId);
		var basketAmountContainer = document.getElementById(basketAmountContainerId);

		var cookieData = cookie_get('mb3pc');
		if (cookieData && typeof cookieData != 'undefined') {

			var data = JSON.parse(cookieData);
			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);

					// 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

				} // 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);

					// 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
				} // end: if
			} // end: if
		} // end: if
	} // 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'
		// Only for IE 7 
		if(navigator.userAgent.indexOf('MSIE 7.0') != -1) {
			document.getElementById('selectbox_' + field).focus();
		}
	}
}

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	= '';
	var currency	= '&euro;';

	// 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 > 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);
	// NOT for IE 6
	if(navigator.userAgent.indexOf('MSIE 6.') == -1) {
		document.getElementById('selectbox_'+field+'_'+lineNumber).focus();
	}
}

function fieldOnBlur(field, lineNumber) {
	document.getElementById('selectdiv_'+field+'_'+lineNumber).className = 'fieldHidden';
	fieldOnChange(field, self, lineNumber);
}

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) {

		cp.call('/typo3conf/ext/dmc_mb3_orderform/ajaxGetArticleData.php',
						'getArticleData',
						response,
						artnumber,
						clientPk,
						languagePk,
						lineNumber);

	} else {

		updateSize(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();

}
