// global states
var isIE = false, cssError = false, debug = false;
var req = new Array();
var cssLoaded, cssUris;
var firstCall = true;
var switchDesignTimeouts = new Array();

// inits designeditor and later inits the design
function initEditor(regen,design,variant,switchd)
{
	// show a wait layer
	showBackLayer(layerFrame,layerContent,layerStop);

	// switch design or reset design
	if(regen == true)
	{
		// reset
		window.setTimeout(function ()
		{
			sendForm(deResetForm);
		}, 250);
	}
	else
	{
		// init users design
		initDesign(design,variant,switchd);
		// hides the initial wait layer
		window.setTimeout(function ()
		{
			hideLoadLayer(layerFrame,layerContent);
		}, 1200);
	}
}

// init functions for design page
function initDesign(selectedDesign,selectedVariant,restoreFlag)
{
	// fill hidden form fields with request values if restoreFlag is set
	if(restoreFlag)
	{
		// get invert strings from request and write to js session
		var invertStrings = getObject('invertStrings');
		if(invertStrings)
		{
		  var string = invertStrings.value;
		  if(string != '')
		  {
			  var strings = string.split(",");
			  for(var i=0;i<strings.length;i++)
			  {
			  	setInvertStateOfOption(selectedVariant,selectedDesign,getIndexOfInvertOption(strings[i]),true);
			  }
		  }
		}

		// apply design and config view
		if(selectedDesign && selectedVariant)
		{
			switchDesign(selectedVariant,selectedDesign,true);
		}
		else
		{
			if(wscDesign)
			{
				if(wscDesign.length > 0)
				{
					if(wscDesign[0].variant)
					{
						if(wscDesign[0].variant.length > 0)
						{
							if(wscDesign[0].variant[0].name)
							  switchDesign(wscSelectedVariant=wscDesign[0].variant[0].name,wscSelectedDesign=wscDesign[0].name,true);
						}
					}
				}
			}
		}

	}

	// adjust layer
	adjustHideLayer('wscHideLyr','wscHideLyr','wscHideRef');

	// changes header and background position
	changeHeaderPosByDesign(prvTpl,selectedDesign);
	changeBackgroundPosByRef('wscPrvBldCtr');

	// match columns
	matchColumns('colArea',null);
	matchColumns('hdrCols',null);
}

// special form implementation of wsc needs an action switcher  								   
function submitBack(formName,actionAddress)
{
  	var formObj = getObject(formName);
  	if(formObj)
  	{
  	  formObj.action = actionAddress;
  	  sendForm(formObj);
  	}
}

// initializes the colorpicker in the popup with data of parent view
function getParentColor()
{
	// reads from field in parent window and writes to local field
	var color = '';
	var parent = window.opener;
	if(parent && parent.closed != true)
	{
		var source = getOpenerObject(deColorField);
		if(source)
		  color = source.value;
	}
	return color;
}

// writes a value of the colorpicker in the popup to data of parent view
function saveParentColor()
{
	// reads from field in parent window and writes to local field
	var parent = window.opener;
	if(parent && parent.closed != true)
	{
		var dest = getOpenerObject(deColorField);
		var source = getObject(deColorSource);
		if(source && dest)
		{
		  // if changed
		  if(dest.value.toLowerCase() != source.value.toLowerCase())
		  {
			// copy color to parent
			dest.value = source.value;
			// fire action and show a layer in parent
			var formObj = getOpenerObject(deColorForm);
			var el0 = getOpenerObject(layerFrame);
			var el1 = getOpenerObject(layerContent);
			var el2 = getOpenerObject(layerStop);
			setWindow(parent);
			parent.focus();
			processForm(formObj,el0,el1,el2);
			setWindow(self);
		  }
		  else
		  {
		  	self.close();
		  }
		}
	}
	// close
	window.setTimeout(function ()
	{
		self.close();
	}, 750);
}

// xml connection
function initXMLRequest(index)
{
	if(index >= 0 && typeof(index) == "number")
	{
		var uri = cssUris[index];
	    if (window.XMLHttpRequest)
	    {
			req[index] = new XMLHttpRequest();
		    req[index].onreadystatechange = new Function('func', 'callBackAction("'+index+'")');
		    req[index].open("GET", uri, true);
		    req[index].send(null);
	    }
	    else if (window.ActiveXObject)
	    {
	        isIE = true;
	        req[index] = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req[index])
	        {
	            req[index].onreadystatechange = new Function('func', 'callBackAction("'+index+'")');
	            req[index].open("GET", uri, true);
	            req[index].send();
	        }
	    }
	}
}

// xml request
function callBackAction(index)
{
    if (req[index].readyState == 4)
    {
        if (req[index].status == 200)
        {	
        	cssLoaded[index] = true;
        }
        else
        {
        	if(debug)
              alert("Error "+req[index].status+": "+req[index].statusText);
            cssError = true;
        }
    }
}

// changes the view of configurator and design by switching between variants
function switchDesign(variantName,designName,callToggleTabVisibility)
{
	// get global data
	var designs = wscDesign;

	// set defaults
	var done = false;

	if(variantName && designName && designs && cssLinks)
	{
		// show a user feedback layer
		if(!firstCall)
		  showBackLayer(layerFrame,layerContent,layerStop);

		// change style of selected tab
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							getObject("design_tab_"+designs[i].name+variants[j].name).className = "";
						}
					}
				}
			} 
		}
		getObject("design_tab_"+designName+variantName).className = "selected";

		// change style of forward revert tabs
		changeRunTabStyle(variantName,designName);

		// change style of shown design
		if(cssLinks.length > 0 && !firstCall)
		{
			// defaults
			var realCssObj, object, hiddenCssObj;
			var uriString;
			var inputString = '';

			// get a komma separated list of invert options
			var inverts = getInvertSelectsOfVariant(variantName,designName);
			
			// prepare the added strings
			// get string of uri with one parameter and his value
			uriString = "&design="+designName+"&variant="+variantName;
			
			// add invert options as komma separated list if invert options are set
			var m=0;
			if(inverts)
			{
				if(inverts.length > 0)
				{
				  	for(var k=0;k<inverts.length;k++)
				  	{
				  		if(getInvertStateOfOption(variantName,designName,inverts[k]))
				  		{
				  			if(m==0)
				  			{
								uriString = uriString + "&invert=";
							}
					  		if(m!=0)
					  		{
					  			uriString = uriString + ",";
					  			inputString = inputString + ",";
					  		}
					  		inputString = inputString + getNameOfInvertOption(inverts[k]);
					  		uriString = uriString + getNameOfInvertOption(inverts[k]);
					  		m++;
					  	}
				  	}
			  	}
			}

			// fill global css uri array for usage in this function and xml request caller
			// clear global var
			cssUris = new Array();
			cssLoaded = new Array();
			// operate for all elements referenced by array
			for(var i=0;i<cssLinks.length;i++)
			{
				// specify new uris of css link references
				object = getObject(cssLinks[i]);
				if(object && uriString)
				{
					// get string of uri with one parameter and his value
					cssUris[i] = getUriWithoutParameter(object.href) + "?cusID=" + getUriParameterValue(object.href,"cusID") + uriString;
					// initialize load states array
					cssLoaded[i] = false;
					// call xml request to load css files
					initXMLRequest(i);
				}
				// we need this because of conditional comments a last css
				// file will only be loaded in internet explorer
				else if (uriString)
				{
					// initialize load states array
					cssLoaded[i] = true;
				}
			}

			// wait till xml request pulled the new css files
			// -- 
			// reset state
			var timeoutCount = 0;
			// check if files are loaded else wait
			function waitOnLoad()
			{
				if(cssError == false)
				{
					// wait a little bit
					window.setTimeout(function ()
					{
						// determine if css is loaded
						allCssLoaded = true;
						for(var k=0;k<cssLoaded.length;k++)
						{
							if(cssLoaded[k] == false)
							  allCssLoaded = false;
						}
						// if css is loaded switch link references in html
						if(allCssLoaded)
						{
							// clear timeouts which were registered by previous calls of switchDesign
							for(var i=0;i<switchDesignTimeouts.length;i++)
							{
								window.clearTimeout(switchDesignTimeouts[i]);
							}
							switchDesignTimeouts = new Array();

							// begin to apply the new css
							var newLink;
							var tmpUri;
							for(var i=0;i<cssLinks.length;i++)
							{
								// change dummy used css link references to prevent
								// view flipping behaviours of browser
								// -- create a dummy link element, deactivate it
								//    and give him the css as reference
								// -- only create if not already exists
								if(cssUris[i])
								{
									if(hiddenCssObj = getObject("css_hidden_"+i))
									{
										hiddenCssObj.href = cssUris[i];
									}
									else
									{
										newLink = document.createElement("link");
										newLink.setAttribute("rel", "stylesheet");
										newLink.setAttribute("type", "text/css");
										newLink.setAttribute("href", cssUris[i]);
										newLink.setAttribute("disabled", "disabled");
										newLink.setAttribute("id", "css_hidden_"+i);
										document.getElementsByTagName("head")[0].appendChild(newLink);
									}
								}
							}
							window.setTimeout(function ()
							{
								// change real css references
								for(var i=0;i<cssLinks.length;i++)
								{
									// operate if element exists
									realCssObj = getObject(cssLinks[i]);
									if(realCssObj)
									{
										// set uri to html link css references
										// -- wait a little bit before do this
										realCssObj.href = cssUris[i];
									}
								}

								// set done for hide layer routine
								done = true;

								// match column heights because font sizes etc could be changed
								window.setTimeout(function ()
								{
									resetColHeights('colArea');
									resetColHeights('hdrCols');
								}, 150);
								window.setTimeout(function ()
								{
								    matchColumns('colArea',null);
								    matchColumns('hdrCols',null);
								}, 200);
								window.setTimeout(function ()
								{
									adjustHideLayer('wscHideLyr','wscHideLyr','wscHideRef');
								}, 250);

							}, 150);
						}
						// else wait a litte bit more
						else
						{
							// if timeout count (250 seconds) not exceeded
							if(timeoutCount < 251)
							  waitOnLoad();
							else
							{
							  // set done for hide layer routine
							  done = true;
							  // info for user
							  alert('The connection to 1-2-3-LIVE timed out. Our service is busy. Please try again later.');
							}
							// increment timeout counter
							timeoutCount++;
						}
					}, 1000);
				}
				else
				{
					// set done for hide layer routine
					done = true;
					// info for user
					alert('Lost connection to 1-2-3-LIVE service. Please try again later.');
				}
			}
			waitOnLoad();
		}

		// wait for finish loading
		if(!firstCall)
		{
 			var timeoutCount2 = 0;
			function waitOnDone()
			{
				// wait a little bit
				window.setTimeout(function ()
				{
					if(done)
					{
						// readjust header and content column heights because of internet
						// explorer 7 render behaviour for tcp congestion situations
						//
						// hint: this function(s) are just running while load layer is already
						//       hidden. in this case, the user can switch the design. then
						//       this function will be called for another design an overlaps
						//       the previous process of this function(s). to avoid the
						//       overlapping, we had to register and compare the requests.
						//
						var stopCountA = 0;
						var stopCountB = 0;
						function readjustColumnsA()
						{
							switchDesignTimeouts[switchDesignTimeouts.length] = window.setTimeout(function ()
							{
								if(stopCountA<16)
								{
									stopCountA++;
									matchColumnsByMaster(prvColMasterHdr,'hdrCols',null);
									readjustColumnsA();
								}
								// if circle and waiting for readjust columns is finished,
								// adjust the hide layer anew
								else
								{
									adjustHideLayer('wscHideLyr','wscHideLyr','wscHideRef');
								}
							}, 650);
						}
						function readjustColumnsB()
						{
							switchDesignTimeouts[switchDesignTimeouts.length] = window.setTimeout(function ()
							{
								if(stopCountB<56)
								{
									stopCountB++;
									matchColumnsByMaster(prvColMasterCnt,'colArea',null);
									readjustColumnsB();
								}
								// if circle and waiting for readjust columns is finished,
								// adjust the hide layer anew
								else
								{
									adjustHideLayer('wscHideLyr','wscHideLyr','wscHideRef');
								}
							}, 950);
						}
						readjustColumnsA();
						readjustColumnsB();
						// call design content switcher on design (not variant) change
						changeHeaderPosByDesign(prvTpl,designName);
						//changeImgUrisByDesign(prvTpl,designName);
						// refresh config view
						refreshConfigView(variantName,designName);
						// hide or unhide tabs to show only an amount of 20
						if(callToggleTabVisibility)
						  toggleTabVisiblity(variantName,designName);
						// set form values to selected design
						getObject('design').value = designName;
						getObject('variant').value = variantName;
						// new input string
						var newInputString = '';
						if(inputString != '')
						  newInputString = inputString;
						// set designeditor specific form values
						var devf = getObject(deVariantField);
						var dedf = getObject(deDesignField);
						var deisf = getObject(deInvertStringField);
						if(devf && dedf && deisf)
						{
							dedf.value = designName;
							devf.value = variantName;
							deisf.value = newInputString;
						}
						// set form values to selected options
						getObject('invertStrings').value = newInputString;
						// hides the feedback layer
						hideLoadLayer(layerFrame,layerContent);
					}
					else
					{
						// if timeout count (30 seconds) not exceeded
						if(timeoutCount2 < 60)
						  waitOnDone();
						else
						{
						  hideLoadLayer(layerFrame,layerContent);
						  alert('The connection to 1-2-3-LIVE timed out. Our service is busy. Please try again later.');
						}
						// increment timeout counter
						timeoutCount2++;
					}

				}, 500);
			}
			waitOnDone();
		}
		else
		{
			// refresh config view
			refreshConfigView(variantName,designName);
	
			// hide or unhide tabs to show only an amount of 20
			if(callToggleTabVisibility)
			  toggleTabVisiblity(variantName,designName);
			  
			// unhide inline wait layer at end of loading when first call
			var ilObj = getObject(inlineLayer);
			if(ilObj)
			  ilObj.style.display = 'none';
		}

		// set first call to false
		firstCall = false;
	}
}

// changes the active state of forward and revert tabs
function changeRunTabStyle(variantName,designName)
{
	// change style of forward revert tabs
	var varCount = getAmountOfVariants();
	var filter = wscFilterFavorits;
	var last, first = false;
	if(filter)
	{
		if(getSelectIndexOfVariant(variantName,designName) == getFirstFavoritIndex()) first = true;
		if(getSelectIndexOfVariant(variantName,designName) == getLastFavoritIndex()) last = true;
	}
	else
	{
		if(getSelectIndexOfVariant(variantName,designName) == 0) first = true;
		if(getSelectIndexOfVariant(variantName,designName) == varCount-1) last = true;
	}
	if(first)
	  getObject("design_tab_rev").style.visibility = "hidden";
	else
	  getObject("design_tab_rev").style.visibility = "visible";
	if(last)
	  getObject("design_tab_fwd").style.visibility = "hidden";
	else
	  getObject("design_tab_fwd").style.visibility = "visible";
}

// changes all uris of a parent node where design string
// is responsible for the new uri
function changeImgUrisByDesign(parentNodeId,design)
{
	// default and init
	var parentNodeObj = getObject(parentNodeId); 

	// change urls of images by a defined scheme
	if(parentNodeObj)
	{
		var imgArray = parentNodeObj.getElementsByTagName("img");
		if(imgArray)
		{
			var imgCount = imgArray.length;
			if(imgCount > 0)
			{
				var imgUri;
				for(var i=0;i<imgCount;i++)
				{
					imgUri = imgArray[i].src;
					// search in image src if this is an image
					// where we should change the src
					if(imgUri.search(/_design.*/) != -1)
					{
						imgArray[i].src = imgUri.match(/.+_design/) + design + imgUri.match(/\.jpg|\.jpeg|\.gif|\.png/);
					}
				}
			}
		}
	}
}

// change the vertical position of a body background image by top left position of reference
function changeBackgroundPosByRef(refEl)
{
	var refObj = getObject(refEl);
	if(refObj)
	{
		document.body.style.backgroundPosition = "0 "+refObj.offsetTop+"px";
	}
}

// change the header position for design tokio
function changeHeaderPosByDesign(parentNodeId,design)
{
	// init and default 
	var relDesign = '003';
	var mnvId = 'mnvArea';
	var hdrId = 'hdrArea';
	var tmpNode;
	var mnvNode = getObject(mnvId);
	var hdrNode = getObject(hdrId);
	// select a child after real parent because of template background
	var parNode = getObject(parentNodeId);
	if(parNode)
	{
		// get next child because of template background
		for(var i=0;i<parNode.childNodes.length;i++)
		{
			if(parNode.childNodes[i].nodeType == '1')
			{
			  parNode = parNode.childNodes[i];
			  i=parNode.childNodes.length;
			}  
		}
	}
	// find first element child node not text child (empty spaces) nodes
	var fstNode;
	if(parNode)
	{
		for(var i=0;i<parNode.childNodes.length;i++)
		{
			if(parNode.childNodes[i].nodeType == '1')
			{
			  fstNode = parNode.childNodes[i];
			  i=parNode.childNodes.length;
			}  
		}
	}

	if(fstNode && parNode)
	{
		// decide what to do
		if(fstNode.getAttribute('id') == hdrId && design == relDesign)
		{
			// we will show a preview of relDesign, we want to have the mnvId
			// the first element to show, but hdrId is the first element at
			// the moment, so lets switch
			tmpNode = parNode.removeChild(mnvNode);
			parNode.insertBefore(tmpNode, hdrNode);
		}
		else if(fstNode.getAttribute('id') != hdrId && design != relDesign)
		{
			// we will show a preview of !relDesign, we want to have the hdrId
			// the first element to show, but mnvId is the first element at
			// the moment, so lets switch
			tmpNode = parNode.removeChild(hdrNode);
			parNode.insertBefore(tmpNode, mnvNode);
		}
	}
}


// get a value of a url parameter
function getUriParameterValue(uri,parameter)
{
	// prepare searched parameter
	parameter = parameter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	
	// set search and execute
	var regex = new RegExp("[\\?&]"+parameter+"=([^&#]*)");
	var results = regex.exec(uri);
	
	// return found string
	if(results == null)
	  return "";
 	else
	  return results[1];
}

// get a value of a url parameter
function getUriWithoutParameter(uri)
{
	// defaults
	var result;
	var strings;
	
	// split uri at questionmark
	if(uri)
	{
		strings = uri.split("?");
	
		// get uri part before the questionmark
		if(strings)
		{
			if(strings.length == 2)
			  result = strings[0];
		}
	}
	
	// return found string
	return result;
}

// refreshes the config options pane
function refreshConfigView(variantName,designName)
{
	// get global data
	var invertOptions = wscInvertOptions;
	var designs = wscDesign;
	
	if(invertOptions && designs && variantName && designName)
	{
		// get hint text object
		hintObj = getObject('wscInvertHint');
		
		// first hide all invert options and uncheck all
		for(var i=0;i<invertOptions.length;i++)
		{
			if (getObject(invertOptions[i]+"_ctr")){
				getObject(invertOptions[i]+"_ctr").style.display = 'none';
			}
			if (getObject(invertOptions[i])) {
				getObject(invertOptions[i]).checked = false;
			}
		}
		if(hintObj)
		  hintObj.style.display = 'none';

		// unhide all invert option checkboxes for the current variant and design
		var invertSelects = getInvertSelectsOfVariant(variantName,designName);
		if(invertSelects)
		{
			// show a hint if no invert options are available for the selected design
			if(invertSelects.length == 0)
			{
				if(hintObj)
				  hintObj.style.display = 'inline';
			}
			// else unhide the checkboxes
			else
			{
				for(var i=0;i<invertSelects.length;i++)
				{
					var invertOptionName = getNameOfInvertOption(invertSelects[i]);
					tmpObj = getObject(invertOptionName+"_ctr");
					tmpBox = getObject(invertOptionName);
					if(tmpObj && tmpBox)
					{
						// unhide
						tmpObj.style.display = 'block';
						
						// set checkbox states of invert options
						if(getInvertStateOfOption(variantName,designName,invertSelects[i]))
						  tmpBox.checked = true;
					}
				}
			}
		}

		// hide or unhide favorit selection links
		if(getFavoritState(variantName,designName))
		{
			getObject('favorit_link_on').style.display='inline';
			getObject('favorit_link_off').style.display='none';
		}
		else
		{
			if (getObject('favorit_link_on')) {getObject('favorit_link_on').style.display='none';}
			if (getObject('favorit_link_off')){getObject('favorit_link_off').style.display='inline';}
		}

		// hide or unhide favorit piktograms above tabs
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(variants[j].favorit)
							{
								getObject("design_fav_"+designs[i].name+variants[j].name).style.visibility = 'visible';
							}
							else
							{
								if (getObject("design_fav_"+designs[i].name+variants[j].name)) {getObject("design_fav_"+designs[i].name+variants[j].name).style.visibility = 'hidden';}
							}
						}
					}
				}
			} 
		}

		// if favorits are set toggle the filter buttons
		toggleFilterLinks();
	}
}

// hide or unhide tabs to show only an amount of 20
function toggleTabVisiblity(variantName,designName)
{
	// default and init
	var m = 0;
	var maxTabs = wscMaxTabs;
	var lastShownPos, firstShownPos;
	var currentSelectedPos=getSelectIndexOfVariant(variantName,designName);
	var currentFavoritPos=getFavoritIndexOfVariant(variantName,designName);
	var designs = wscDesign;
	var filter = wscFilterFavorits;

	// specify current position on tab pane
	if(filter)
	  currentShownPos = currentFavoritPos;
	else
	  currentShownPos = currentSelectedPos;

	// compute while recognizing favorits
	if(variantName && designName && designs && maxTabs)
	{
		// compute last shown tab
		// -- determine last shown pos by set to default
		if(currentShownPos < maxTabs-1)
		{
			// current selected position is in the range of maximum tab amount
			// leave the shown tabs the same
			lastShownPos = maxTabs-1;
			firstShownPos = 0;
		}
		// else if at the end of the max amount of tabs or later
		// -- take current shown pos to determine last shown pos
		else
		{
			// slide the last tab position to one position later
			if(currentShownPos < getAmountOfVisibleDesigns()-1)
			  lastShownPos = currentShownPos+1;
			// hold current selected position if at the end of the tab amount or list
			else
			  lastShownPos = currentShownPos;
			// i do not know why this behaviour but we had to shown one more
			// position earlier if favorit filter is on and position is after max tabs
			if(filter)
			  lastShownPos = lastShownPos+1;
			// determine first shown pos
			// compute the first pos specially if favorit filter is activated
			if(filter)
			{
			  firstShownPos = getEarlierFavoritTrueIndex(lastShownPos,maxTabs-1);
			  // i do not know why this behaviour but we had to shown one more
			  // position earlier if favorit filter is on and position is after max tabs
			  if(currentShownPos < maxTabs)
				firstShownPos = firstShownPos-1;
			}	  
			// subtract max tab amount for deactivated favorit filter
			else
			  firstShownPos = lastShownPos-(maxTabs-1);
		}

		// hide and unhide
		var styleString;
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							// first hide it
							styleString = 'none';
							// count dependent on favorit or not
							if(filter)
							{
								if(getFavoritState(variants[j].name,designs[i].name))
								{
									if(m >= firstShownPos && m <= lastShownPos)
									{
										styleString = 'block';
									}
									// increment to count already shown tabs to compare with maximum of shown tabs
									m++;
								}
							}
							else
							{
								if(m >= firstShownPos && m <= lastShownPos)
								{
									styleString = 'block';
								}
								// increment to count already shown tabs to compare with maximum of shown tabs
								m++;
							}
							// write hide or unhide factor
							getObject("design_num_"+designs[i].name+variants[j].name).style.display = styleString;
						}
					}
				}
			}
		}
	}
}

// find an index reverse in a virtual favorit true only array by giving
// start index and amount of max search indexes earlier
function getEarlierFavoritTrueIndex(startIndex,amount)
{
	// defaults and init
	var favorits = getArrayOfFavoritSelects();
	var stopIndex = startIndex-1;

	if(favorits)
	{
		// initialize
		var foundCount = 0;
		var favoritIndex = getSelectIndexByFavoritTrueIndex(startIndex);

		// if lesser favorits than startIndex
		if(!favoritIndex)
		  favoritIndex = getLastFavoritTrueIndex();

		// the index range of startIndex can be larger than
		// the index range of virtual favorit true only array 
		if(favoritIndex)
		{
			// process if start index is within the range of accessed array
			if(favoritIndex <= favorits.length)
			{
				for(var i=favoritIndex;i>=0;i--)
				{						
					// compute first position of tab which should be visible
					// if queried favorit has true state and we want only
					// search a definied amount of indexes
					if(favorits[i] && foundCount < amount)
					{
						stopIndex = i;
						foundCount++;
					}
				}
			}
		}
	}
	
	// return the found index
	return stopIndex;
}

// hide or unhide favorit filter links
function toggleFilterLinks()
{
	// toggle the filter buttons if favorits are set
	var favorits = getArrayOfFavoritSelects();
	if(favorits)
	{
		if(!wscFilterFavorits)
		{
			var favoritCount = 0;
			for(var k=0;k<favorits.length;k++)
			{
				if(favorits[k] == true)
				  favoritCount++;
			}
			if(favoritCount > 0)
			{
				getObject("design_filter_fav").style.visibility = 'visible';
				getObject("design_filter_dsn").style.visibility = 'hidden';
			}
			else
			{
				if(getObject("design_filter_fav")){getObject("design_filter_fav").style.visibility = 'hidden';}
			}
			if(getObject("design_filter_dsn")){getObject("design_filter_dsn").style.visibility = 'hidden';}
		}
		else
		{
			getObject("design_filter_dsn").style.visibility = 'visible';
		}
	}
}

// only show favorits on tabs
function filterFavorits(variant,design)
{
	// default
	favorits = getArrayOfFavoritSelects();
	designs = wscDesign;

	// get global data
	if(favorits && designs)
	{		
		// set global filter switch for other functions
		wscFilterFavorits = true;

		// set value of hidden form field for session handling
		getObject("favoritFilter").value = 'true';

		// switch to first favorit design if there is no favorit design selected by user
		var switchNeeded = true;
		if(getFavoritState(variant,design))
		  switchNeeded = false;
		if(switchNeeded)
		{
			// get index of first favorit
			var newPos = getFirstFavoritIndex();

			// switch design and variant
			switchDesign(wscSelectedVariant=getVariantBySelectIndex(newPos),wscSelectedDesign=getDesignBySelectIndex(newPos),callToggleTabVisibility=false);
		}
		else
		{
			// change style of forward revert tabs
			changeRunTabStyle(variant,design);
		}

		// toggle button visibility and link activity
		getObject("design_filter_fav").style.visibility = 'hidden';
		getObject("design_filter_dsn").style.visibility = 'visible';
		getObject("design_filter_fav_ctr").className = getObject("design_filter_fav_ctr").className+" selected";

		// hide or unhide tabs to show only an amount of 20
		toggleTabVisiblity(wscSelectedVariant,wscSelectedDesign);
	}
}

// reset favorits filter
function clearFavoritsFilter()
{
	// get global data
	var designs = wscDesign;
	if(designs)
	{
		// set global filter switch for other functions
		wscFilterFavorits = false;

		// change visibility of tabs
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							getObject("design_num_"+designs[i].name+variants[j].name).style.display = 'block';
						}
					}
				}
			} 
		}

		// set value of hidden form field for session handling
		getObject("favoritFilter").value = 'false';

		// hide or unhide tabs to show only an amount of 20
		toggleTabVisiblity(wscSelectedVariant,wscSelectedDesign);

		// toggle button visibility and link activity
		getObject("design_filter_fav_ctr").className = getObject("design_filter_fav_ctr").className.replace(/\bselected\b/, '');
		toggleFilterLinks();
	}
}

// switches design one step forward or back
function runDesign(direction)
{
	if(wscSelectedVariant && wscSelectedDesign)
	{
		// position of selected design and amount of shown designs
		var newPos;
		var oldPos = getSelectIndexOfVariant(wscSelectedVariant,wscSelectedDesign);
		var posAmount = getAmountOfVariants();

		// compute new position
		if(direction)
		{
			var favorits = getArrayOfFavoritSelects();
			if(direction == '-')
			{
				// if favorits are filtered
				if(wscFilterFavorits)
				{
					// stop if already at the beginning
					if(oldPos != getFirstFavoritIndex())
					{
						var foundCount = 0;
						for(var k=oldPos-1;k>=0;k--)
						{
							if(favorits[k] == true && foundCount == 0)
							{
								newPos = k;
								foundCount++;
							}
						}
					}
					else
					{
						newPos = oldPos;
					}
				}
				// else normal mode
				else
				{
					// stop if already at the beginning else subtract a step
					if(oldPos > 0)
					  newPos = oldPos-1;
					else
					  newPos = oldPos
				}
			}
			else if(direction == '+')
			{
				// if favorits are filtered
				if(wscFilterFavorits)
				{
					// stop if already at the end
					if(oldPos != getLastFavoritIndex())
					{
						var foundCount = 0;
						for(var k=oldPos+1;k<favorits.length;k++)
						{
							if(favorits[k] == true && foundCount == 0)
							{
								newPos = k;
								foundCount++;
							}
						}
					}
					else
					{
						newPos = oldPos;
					}
				}
				// else normal mode
				else
				{
					// stop if already at the end else add a step
					if(oldPos < posAmount-1)
					  newPos = oldPos+1;
					else
					  newPos = oldPos;
				}
			}
		}
		
		// switch the design
		switchDesign(wscSelectedVariant=getVariantBySelectIndex(newPos),wscSelectedDesign=getDesignBySelectIndex(newPos),callToggleTabVisibility=true);
	}
}

// switches the state and view of a favorit selection
function switchFavoritSelection(variant,design)
{
	// default
	var favorits = getArrayOfFavoritSelects();

	if(variant && design && favorits)
	{	
		// changes to data of states array
		// get local state
		var state = favorits[getSelectIndexOfVariant(variant,design)];

		// activate or deactivate this design and variant as favorit
		if(state)
		  setFavoritState(variant,design,false);
		else
		  setFavoritState(variant,design,true);
		
		// reset favorit state if there are no more favorits
		favorits = getArrayOfFavoritSelects();
		var favoritCount = 0;
		for(var k=0;k<favorits.length;k++)
		{
			if(favorits[k] == true)
			  favoritCount++;
		}
		if(favoritCount == 0)
		{
			// clear all favorits filter settings and special views
			clearFavoritsFilter();
		}

		// call function to handle session
		prepareFavoritsForSession();
		
		// switch the shown design if the actual selected design was removed from favorits
		if(state && wscFilterFavorits)
		{
			var newPos = getFirstFavoritIndex();
			switchDesign(wscSelectedVariant=getVariantBySelectIndex(newPos),wscSelectedDesign=getDesignBySelectIndex(newPos),callToggleTabVisibility=true);
		}
		else
		{
			// refresh config view if no design change is needed (while a design is changed the config view will be refreshed, too)
			refreshConfigView(variant,design);
		}
	}
}

// write all favorit selections to a hidden form field for session handling
function prepareFavoritsForSession()
{
	// default
	var designs = wscDesign;
	var variants;
	var string = '';
	var count = 0;

	// go through the multi-dimensional design array, find
	// the variant and write all state to a string
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				if(variants = designs[i].variant)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name && variants[j].favorit != null)
						{
							if(variants[j].favorit)
							{
								if(count > 0)
								  string = string + ',';
								string = string + designs[i].name + "_" + variants[j].name;
								count++;
							}
						}
					}
				}
			} 
		}
	}

	// write the string to a form field value
	getObject('favoritSelects').value = string;
}

// write all invert selections to a hidden form field for session handling
function prepareInvertSelectsForSession()
{
	// default
	var designs = wscDesign;
	var variants;
	var inverts;
	var string = '';
	var count = 0;

	// go through the multi-dimensional design array, find
	// the variant and write all state to a string
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				if(variants = designs[i].variant)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(inverts = variants[j].invert)
							{
								for(var k=0;k<inverts.length;k++)
								{
									if(inverts[k].option >= 0 && inverts[k].selected != null)
									{
										if(inverts[k].selected)
										{
											if(count > 0)
											  string = string + ',';
											string = string + designs[i].name + "_" + variants[j].name + "_" + getNameOfInvertOption(inverts[k].option);
											count++;
										}
									}
								}
							}
						}
					}
				}
			} 
		}
	}

	// write the string to a form field value
	getObject('invertSelects').value = string;
}

// switches only the favorit state of a variant
function setFavoritState(variantName,designName,state)
{
	// default
	var designs = wscDesign;
	var variants;

	// go through the multi-dimensional design array, find
	// the variant and write the new state
	if(designs && variantName && designName)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name == designName)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name == variantName)
						  wscDesign[i].variant[j].favorit = state;
					}
				}
			} 
		}
	}
}

// finds the favorit state of a variant
function getFavoritState(variantName,designName)
{
	// default
	var designs = wscDesign;
	var variants;
	var state = false;

	// go through the multi-dimensional design array, find
	// the variant and get the new state
	if(designs && variantName && designName)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name == designName)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name == variantName)
						  state = wscDesign[i].variant[j].favorit;
					}
				}
			} 
		}
	}
	
	// returns the state
	return state;
}

// switches the local state of a invert option checkbox
function switchInvertOption(checkbox,variant,design)
{
	// wscInvertOptions[i]
	var object = getObject(checkbox);
	var invertOption = getIndexOfInvertOption(checkbox);

	// change checkbox selection state
	if(object && invertOption >= 0)
	{
		if(object.checked)
		{
			setInvertStateOfOption(variant,design,invertOption,true)
		}
		else
		{
			setInvertStateOfOption(variant,design,invertOption,false)		
		}
	}

	// call a function to handle session
	prepareInvertSelectsForSession();

	// switch the shown design
	switchDesign(variant,design,callToggleTabVisibility=true);
}

// changes the visiblity and initial content of the example layer in design selection dialog
function showExampleLayer(state,design,element,content,hide)
{
	if(design && element && state >= 0)
	{
		// changes the shown content within the example layer
		if(state == 1)
		  changeExampleLayer(design,0);

		// call common layer visibility function
		changeLayerVisibility(state,element);

		// re-position layer and contents
		adjustContentLayer(content);
		adjustHideLayer(element,null,hide);
	}
}

// changes the content of the example layer in design selection dialog
function changeExampleLayer(design,template)
{
	// default
	designs = getArrayOfDesigns();
	var pos;

	// process
	if(design && wscExampleImages && wscExampleRoot && template >= 0 && designs && wscExampleCaptions)
	{
		pos = getIndexOfArrayValue(designs,design);
		if(template < wscExampleImages[pos].length)
		{
			// change preview image
			var exampleImages = wscExampleImages[pos];
			getObject('example_image').src = wscExampleRoot + "/" + exampleImages[template];

			// change header text and subtitle
			getObject('example_header').innerHTML = getObject('example_link_'+template).innerHTML;
			getObject('example_subtitle').innerHTML = getObject('example_link_'+template).innerHTML;
			
			// change image caption
			if(template < wscExampleCaptions[pos].length)
			{
				var exampleCaptions = wscExampleCaptions[pos];
				getObject('example_caption').innerHTML = exampleCaptions[template];
			}
			
			// change link state
			for(var i=0;i<wscExampleImages[pos].length;i++)
			{
				if(i == template)
				{
					getObject('example_ctr_'+i).className = 'selected';
				}
				else
				{
					getObject('example_ctr_'+i).className = '';
				}
			}
		}		
	}
}

// returns the first index of favorits array with true value
function getFirstFavoritIndex()
{
	// default
	var pos;
	var foundCount = 0;
	var favorits = getArrayOfFavoritSelects();

	// compute
	if(favorits)
	{
		for(var k=0;k<favorits.length;k++)
		{
			if(favorits[k] == true && foundCount == 0)
			{
				pos = k;
				foundCount++;
			}
		}
	}

	// return
	return pos;
}

// returns the last index of favorits array with true value
function getLastFavoritIndex()
{
	// default
	var pos;
	var favorits = getArrayOfFavoritSelects();

	// compute
	if(favorits)
	{
		for(var k=0;k<favorits.length;k++)
		{
			if(favorits[k] == true)
			{
				pos = k;
			}
		}
	}

	// return
	return pos;
}

// hide or unhide fields depending on a radio selection
function changeFormPayment()
{
	// object references to get and set values
	var objSelBank = getObject('customer_payment_bank');
	var objSelInquiry = getObject('customer_payment_inquiry');
	var objCtrBank = getObject('customer_bank');
	var objCtrInquiry = getObject('customer_inquiry');

	if(objSelBank && objSelInquiry && objCtrBank && objCtrInquiry)
	{
		// check the two possible values or states
		if(objSelBank.checked == true)
		{
			// and hide a container and unhide the other
			objCtrBank.style.display = 'block';
			objCtrInquiry.style.display = 'none';
		}
		else if(objSelInquiry.checked == true)
		{
			// and hide a container and unhide the other
			objCtrBank.style.display = 'none';
			objCtrInquiry.style.display = 'block';
		}
	}
}

// hide or unhide fields depending on a radio selection
function changeFormCustomer()
{
	// object references to get and set values
	var objSelBiz = getObject('customer_type_business');
	var objSelPriv = getObject('customer_type_private');
	var objCtrBiz1 = getObject('customer_business');
	var objCtrBiz2 = getObject('customer_business2');
	var objCtrBiz3 = getObject('customer_business3');
	var objCtrPriv = getObject('customer_private');
	var objForm = getObject('register_customer');

	if(objSelBiz && objSelPriv && objCtrBiz1 && objCtrBiz2 && objCtrBiz3 && objCtrPriv && objForm)
	{
		// check the two possible values or states
		if(objSelPriv.checked == true)
		{
			// and hide a container and unhide the other
			objCtrBiz1.style.display = 'none';
			objCtrBiz2.style.display = 'none';
			objCtrBiz3.style.display = 'none';
			objCtrPriv.style.display = 'block';
			objForm.action = '/123live-website-gen/actions/register_private.action';
		}
		else if(objSelBiz.checked == true)
		{
			// and hide a container and unhide the other
			objCtrBiz1.style.display = 'block';
			objCtrBiz2.style.display = 'block';
			objCtrBiz3.style.display = 'block';
			objCtrPriv.style.display = 'none';
			objForm.action = '/123live-website-gen/actions/register_business.action';
		}
	}
}

// returns an array of all selected invert options of a design and variant
function getInvertSelectsOfVariant(variantName,designName)
{
	// defaults
	var designs = wscDesign;
	var options = new Array();
	var variants;
	var inverts;

	// get invert options by query the designs
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				if(designs[i].name == designName)
				{
					variants = designs[i].variant;
					if(variants)
					{
						for(var j=0;j<variants.length;j++)
						{
							if(variants[j].name)
							{
								if(variants[j].name == variantName)
								{
									if(inverts = variants[j].invert)
									{
										for(var k=0;k<inverts.length;k++)
										{
											options.push(inverts[k].option);
										} 
									}
								}
							}
						}
					}
				}
			}
		} 
	}
	
	// returns the array
	return options;
}

// finds the index of a variant in the temporary select array
function getSelectIndexOfVariant(variantName,designName)
{
	// default
	var designs = wscDesign;
	var variants;
	var index = 0;
	var k = 0;

	// go through the multi-dimensional design array, count
	// over all variants and stop if the name is the same
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(variants[j].name == variantName && designs[i].name == designName)
							{
								index = k;
							}
							k++;
						}
					}
				}
			}
		} 
	}

	// return the name
	return index;
}

// finds the index of a variant in a temporary favorit only list
function getFavoritIndexOfVariant(variantName,designName)
{
	// default
	var designs = wscDesign;
	var variants;
	var index;
	var k = 0;

	// go through the multi-dimensional design array, count
	// over all variants and stop if the name is the same
	if(designs && variantName && designName)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(variants[j].favorit)
							{
								if(variants[j].name == variantName && designs[i].name == designName && index == null)
								{
									index = k;
								}
								k++;
							}
						}
					}
				}
			}
		} 
	}

	// return the name
	return index;
}

// finds the design name by the index of the temporary select array
function getDesignBySelectIndex(index)
{
	// default
	var designName;
	var designs = wscDesign;
	var variants;
	var k = 0;

	// go through the multi-dimensional design array, count
	// over all designs and stop if the count is same as index
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(k == index)
							{
								designName = designs[i].name;
							}
							k++;
						}
					}
				}
			}
		} 
	}

	// return the name
	return designName;
}

// finds the variant name by the index of the temporary select array
function getVariantBySelectIndex(index)
{
	// default
	var variantName;
	var designs = wscDesign;
	var variants;
	var k = 0;

	// go through the multi-dimensional design array, count
	// over all designs and stop if the count is same as index
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						{
							if(k == index)
							{
								variantName = variants[j].name;
							}
							k++;
						}
					}
				}
			}
		} 
	}

	// return the name
	return variantName;
}

// returns the index of a array value
function getIndexOfArrayValue(array,value)
{
	var j;
	if(array && value)
	{
		for(var i=0;i<array.length;i++)
		{
			if(array[i] == value)
			{
				j=i;
			}
		}
	}
	return j;
}

// creates an one-dimensional array of favorit selects states from all variants
function getArrayOfFavoritSelects()
{
	// default
	var array = new Array();
	var designs = wscDesign;
	var variants;

	// go through the multi-dimensional design array, get
	// the favorit states and write them to an own array
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						  array.push(variants[j].favorit);
					}
				}
			}
		} 
	}

	// return the array
	return array;
}

// returns the index in an select array of an favorit array with states true only
function getSelectIndexByFavoritTrueIndex(favIndex)
{
	// default
	var selIndex;
	var count = -1;
	var favorits = getArrayOfFavoritSelects();

	// find
	if(favorits)
	{
		for(var i=0;i<favorits.length;i++)
		{
			if(favorits[i])
			  count++;
			
			if(count == favIndex)
			  selIndex = i;
		}
	}

	// return
	return selIndex;
}

// return the last index of an temporary favorit true only array
function getLastFavoritTrueIndex()
{
	// default
	var count = -1;
	var favorits = getArrayOfFavoritSelects();

	// find
	if(favorits)
	{
		for(var i=0;i<favorits.length;i++)
		{
			if(favorits[i])
			{
				count++;
			}
		}
	}

	// return
	return count;
}

// counts the amount of favorit selections
function getAmountOfFavorits()
{
	// default
	var amount = 0;
	var favoritList = getArrayOfFavoritSelects();

	// count
	if(favoritList)
	{
		for(var i=0;i<favoritList.length;i++)
		{
			if(favoritList[i])
			  amount++;
		}
	}

	// return count
	return amount;
	
}

// counts the amount of all designs configured
function getAmountOfDesigns()
{
	// default
	var amount = 0;
	var designs = getArrayOfDesigns();

	// count the amount
	if(designs)
	  amount = designs.length;

	// return the amount
	return amount;
}

// counts the amount of visible variants dependent on favorits filter
function getAmountOfVisibleDesigns()
{
	// default
	var filter = wscFilterFavorits;
	var designs = wscDesign;
	var count = 0;

	// compute
	if(filter != null && designs)
	{
		if(filter)
		{
		  count = getAmountOfFavorits();
		}
		else
		  count = getAmountOfVariants();
	}

	// return computed value
	return count;
}

// counts the amount of all variants configured
function getAmountOfVariants()
{
	// default
	var amount = 0;
	var variants = getArrayOfVariants();

	// count the amount
	if(variants)
	  amount = variants.length;

	// return the amount
	return amount;
}

// creates an array of all designs configured
function getArrayOfDesigns()
{
	// default
	var array = new Array();
	var designs = wscDesign;

	// go through the multi-dimensional design array and
	// push to the new array if a design was found
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			  array.push(designs[i].name);
		} 
	}

	// return the array
	return array;
}

// creates an array if all variants configured
function getArrayOfVariants()
{
	// default
	var list = new Array;
	var designs = wscDesign;
	var variants;

	// go through the multi-dimensional design array and
	// push to the new array if a variant was found
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				variants = designs[i].variant;
				if(variants)
				{
					for(var j=0;j<variants.length;j++)
					{
						if(variants[j].name)
						  list.push(variants[j].name);
					}
				}
			}
		} 
	}

	// return the array
	return list;
}

// returns the internal name of an invert option
function getNameOfInvertOption(index)
{
	var options = wscInvertOptions;
	var name;
	if(options)
	{
		if(index < options.length)
		  name = options[index];
	}
	return name;
}

// finds the index of an invert option by name
function getIndexOfInvertOption(name)
{
	var options = wscInvertOptions;
	var index;
	if(name)
	{
		for(var i=0;i<options.length;i++)
		{
			if(options[i] == name)
			{
				index = i;
			}
		}
	}
	return index;
}

// returns the state of an variant invert option
function getInvertStateOfOption(variantName,designName,invertOption)
{
	// default
	var state = false;
	var designs = wscDesign;
	var invertOptions = wscInvertOptions;
	var variants;
	var inverts;

	// go through the multi-dimensional design array and
	// find the invert state of an option if a variant was found
	if(designs && invertOptions)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				if(designs[i].name == designName)
				{
					variants = designs[i].variant;
					if(variants)
					{
						for(var j=0;j<variants.length;j++)
						{
							if(variants[j].name)
							{
								if(variants[j].name == variantName)
								{
									inverts = variants[j].invert;
									if(inverts)
									{
										if(invertOption < invertOptions.length)
										{
											for(var k=0;k<inverts.length;k++)
											{
												if(inverts[k].selected != null && inverts[k].option >= 0)
												{
													if(inverts[k].option == invertOption)
													  state = inverts[k].selected;
												}
											}
										} 
									}
								}
							}
						}
					}
				}
			}
		} 
	}

	// return the state
	return state;
}

// sets the state of an variant invert option
function setInvertStateOfOption(variantName,designName,invertOption,state)
{
	// default
	var designs = wscDesign;
	var variants;
	var inverts;

	// go through the multi-dimensional design array and
	// find the invert state of an option if a variant was found
	if(designs)
	{
		for(var i=0;i<designs.length;i++)
		{
			if(designs[i].name)
			{
				if(designs[i].name == designName)
				{
					variants = designs[i].variant;
					if(variants)
					{
						for(var j=0;j<variants.length;j++)
						{
							if(variants[j].name)
							{
								if(variants[j].name == variantName)
								{
									inverts = variants[j].invert;
									if(inverts)
									{
										for(var k=0;k<inverts.length;k++)
										{
											if(inverts[k].option == invertOption)
											{
												if(inverts[k].selected != null)
												  wscDesign[i].variant[j].invert[k].selected = state;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		} 
	}

	// return the state
	return state;
}

// get state of a form element and return
function getFormState(element)
{
	var state = 0;
	if(getObject(element))
	{
		if(getObject(element).value == 'true')
		{
			state = 1;
		}
	}
	return state;
}

// shows a feedback and adjusts it layer if user must wait
function showBackLayer(layerFrame,layerContent,layerStop)
{
	// activates the layer
	changeLayerVisibility(1,layerFrame);

	// adjust layer to fit screen
	adjustContentLayer(layerContent);
	adjustHideLayer(layerFrame,null,layerStop);
}

// hides the feedback layer
function hideLoadLayer(layerFrame,layerContent)
{
	// activates the layer
	changeLayerVisibility(0,layerFrame);
}

// shows a user feedback layer and sends a form
function processForm(form,layerFrame,layerContent,layerStop)
{
	// shows a layer and adjusts it to the screen
	showBackLayer(layerFrame,layerContent,layerStop);

	// send form
	window.setTimeout(function ()
	{
		sendForm(form);
	}, 500);
}

// change visibility of form areas by selected list item
function changeFormBySelectList(listElementId,selectedValue,showElementId,hideElementId)
{
	// default and init
	listElementObj = getObject(listElementId);
	showElementObj = getObject(showElementId);
	hideElementObj = getObject(hideElementId);
	
	// show and hide
	if(listElementObj && showElementObj && hideElementObj && selectedValue)
	{
		if(listElementObj.options[listElementObj.selectedIndex].value == selectedValue)
		{
			showElementObj.style.display = 'block';
			hideElementObj.style.display = 'none';
		}
		else
		{
			showElementObj.style.display = 'none';
			hideElementObj.style.display = 'block';
		}
	}
	
}

// copy pastes a form value to another
function copyFormValue(fromFieldName,toFieldName)
{
	getObject(toFieldName).value=getObject(fromFieldName).value;
}

// switch the state of a layer visibility variable
function switchLayerState(oldState)
{
	var newState = 1;
	if (oldState == 1 || oldState == null)
	{
		newState = 0;
	}
	return newState;
}

// EOF
