
//***************************************
//functions for index_models.shtml
//*************************************


//constructor for image objects of model module
function createModelHilite(whichBGImg,whichImg,lowsrc){
	//erzeugen der mouseover-Images
	if(!whichImg.counter){
		whichImg.counter = 1;
		whichImg.hilitetoggle = 1;
		whichImg.bgimg = "url(" + whichBGImg + ")";		
		whichImg.offimg = new Image();
		whichImg.offimg.src = lowsrc;
		//creating  hilite images 
		if(arguments.length > 3){
			whichImg.addImages = new Array();
			for(i=0;i<arguments.length-3;i++){
				whichImg.addImages[i] = new Image();
				whichImg.addImages[i].src = arguments[i+3];
			}
		}	
		}
	}


//mouseover function for model image
function showModelHilite(whichDiv,whichImgObj,whichDataDiv){
	try {
		if(whichImgObj.hilitetoggle == 1) whichImgObj.src = whichImgObj.addImages[0].src;
		if(whichDataDiv.className == "cl_data_multiple"){
			whichDataDiv.className = "cl_data_visible";
		}
		else{
			whichDataDiv.className = "cl_data_fixed_visible";
		}
		//check out for td as correct parentNode	
		var td_as_parent = whichDiv.parentNode;
		while (td_as_parent) {
  			if(td_as_parent.className == "onecol" || td_as_parent.className == "onecol_to_line"){
			var correctParent = td_as_parent;
			break;
			}
			else{
  			td_as_parent = td_as_parent.parentNode;
			}
		}		
		correctParent.style.background = "url(" + td_bgimage + ")";
		whichDiv.style.background = "#F0F0F5";	
		changeModelsClass(whichDataDiv);
	}
	catch (ex) {
		// ignore
	}
}

//mouseout function for model image
function resetModelHilite(whichDiv,whichImgObj,whichDataDiv){
	try {
		whichImgObj.src = whichImgObj.offimg.src;
		if(whichDataDiv.className == "cl_data_visible"){
			whichDataDiv.className = "cl_data_multiple";
		}
		else{
			whichDataDiv.className = "cl_data";
		}	
		var td_as_parent = whichDiv.parentNode;
		while (td_as_parent) {
  			if(td_as_parent.className == "onecol" || td_as_parent.className == "onecol_to_line"){
			var correctParent = td_as_parent;
			break;
			}
			else{
  			td_as_parent = td_as_parent.parentNode;
			}
		}		
		correctParent.style.background = "url()";
		whichDiv.style.background = "#ffffff";
		changeModelsClass(whichDataDiv);
	}
	catch (ex) {
		// ignore
	}
}

//mouseover function for price display
function showPrice(whichDataDiv){
	try {
		whichDataDiv.className = "cl_price";
		whichDataDiv.parentNode.style.backgroundImage = whichDataDiv.parentNode.parentNode.parentNode.childNodes[0].bgimg;
		myNum = checkmyNodeNum(whichDataDiv);
		changeModelImage(whichDataDiv,myNum);
	}
	catch (e) {
	  // ignore errors
	}
}

//check div num
function checkmyNodeNum(which){
 i = which.parentNode.parentNode.childNodes.length;
 for(x=0;x<i;x++){
  if(which.parentNode.parentNode.childNodes[x].childNodes[1].className == "cl_price"){
  return(x+1);
  }
 }
}

//change model image (if more than one model)
function changeModelImage(whichDiv, whichNum){
	whichDiv.parentNode.parentNode.parentNode.childNodes[0].hilitetoggle = 0;
	whichDiv.parentNode.parentNode.parentNode.childNodes[0].src = 
whichDiv.parentNode.parentNode.parentNode.childNodes[0].addImages[whichNum].src;

}

//mouseout function for price display
function resetPrice(whichDataDiv){
	whichDataDiv.parentNode.parentNode.parentNode.childNodes[0].hilitetoggle = 1;
	whichDataDiv.className = "cl_price_hidden";
	whichDataDiv.parentNode.style.background = "url()";
}

//check model divs
function changeModelsClass(which){
 i = which.childNodes.length;
 for(x=0;x<i;x++){
 	var a = which.childNodes[x].childNodes.length;
	for(b=0;b<a;b++){
  		if(which.childNodes[x].childNodes[b].className == "cl_model"){
  			which.childNodes[x].childNodes[b].className = "cl_model_vis";
  		}
		else if(which.childNodes[x].childNodes[b].className == "cl_model_vis"){
  			which.childNodes[x].childNodes[b].className = "cl_model";
  		}		
 	}
	}	
}

//================================================================
//Scripts for Newslist Scroller
//===============================================================

//creating Newslist
function createNewslist(whichID,whichMenu){
	scrollTimer = 0;
	this.id = whichID;
	//props for positionierung of menu
	this.imgPosChecked = 0;
	this.menuPos = 0;
	this.menuTop = 0;
	this.imgHeight = 0;
	this.menuWidth = 0;
	//reading arrays
	this.activeMenu = eval(whichMenu);
	this.subMenuItemsList = '';
	if(this.activeMenu != 0) {
		for(var i = 0; i < this.activeMenu.length-2; i++) {
			this.subMenuItemsList += '<div class="news_entry">'
			  + '<img src="' + newslistbutton + '" width="10" height="8" alt="" class="arrow_news">'
			  + (this.activeMenu[i+2]!=null ? this.activeMenu[i+2] : "")
			  + '<span class="date_news">' + this.activeMenu[i] + ':</span>'
			  + ' ' + this.activeMenu[i+1]
			  + (this.activeMenu[i+2]!=null ? this.activeMenu[i+2] : "</a>")
			  + '</div>';
			i = i + 2;
		}	
	}	
}


//writing newsscroller start html
function initNewsScroller(whichMenu){
if(whichMenu.activeMenu != 0) {
		document.getElementById("nscr_news").innerHTML = whichMenu.subMenuItemsList;
		document.getElementById("nscr_maindiv_nolink").style.visibility = "visible";
		document.getElementById("nscr_maindiv_nolink").style.display = "block";				
		document.getElementById("nscr_news").style.top= 0 + "px";		
	}		
}

function scroll_up(){
	var divTop = document.getElementById("nscr_news").offsetTop;
	var maxTop = document.getElementById("nscr_news").offsetHeight;
	maxTop = maxTop - 98;
	//alert(maxTop);
	divTop = divTop - 1;
	if(divTop + maxTop <= 0 ) divTop= -maxTop;
	document.getElementById("nscr_news").style.top = divTop + "px";
	//if(navigator.appVersion.indexOf("MSIE 5") != -1 && isMac) document.getElementById("nscr_news").style.left = 20 + "px";
	scrollTimer = setTimeout("scroll_up()",10);

}

function scroll_down(){
	var divTop = document.getElementById("nscr_news").offsetTop;
	var maxTop = document.getElementById("nscr_news").offsetHeight;
	divTop = divTop + 1;
	if(divTop >= 0) divTop = 0;
	document.getElementById("nscr_news").style.top = divTop + "px";
	//if(navigator.appVersion.indexOf("MSIE 5") != -1 && isMac) document.getElementById("nscr_news").style.left = 20 + "px";
	scrollTimer = setTimeout("scroll_down()",10);

}

function scroll_stop(){
	if (scrollTimer) clearTimeout(scrollTimer);
}


//=========================================
// Calendar-functions
//=========================================

// active month in calendar control
var activeMonth = 0;

function makeCalendar(){
	//reading arrays
	this.months = new Array;
	for(var i = 0; i < arguments.length; i++){
		this.months[i] = arguments[i];
		this.months[i].name = this.months[i][0][0];
		this.months[i].daysum = this.months[i][0][1];
		this.months[i].start = this.months[i][0][2];
		var startCount = this.months[i].start * 23;
		/*var startCount = 0;
		switch (this.months[i].start) {
			case 'mo':
			startCount = 0;
			break;
			case 'di':
			startCount = 1*23;
			break;
			case 'mi':
			startCount = 2*23;
			break;
			case 'do':
			startCount = 3*23;
			break;
			case 'fr':
			startCount = 4*23;
			break;
			case 'sa':
			startCount = 5*23;
			break;
			case 'so':
			startCount = 6*23;
			break;
			}	*/
		this.months[i].completeDayList = new Array;
		for(var x = 1; x < this.months[i].length; x++){
			var day = this.months[i][x][0];
			var href = this.months[i][x][1];
			var title = this.months[i][x][2];
			var description = this.months[i][x][3];
			var completeDescription = '';
			completeDescription += '<span class="eventTitle">' + title + '</span><span class="eventDesc">' + description + '</span>';
			//if there are more than one event per day...
			if(this.months[i].completeDayList[day]){
				var addDescription = '<span class="eventDesc">' + description + '</span>';
				var addCompleteDescription = this.months[i].completeDayList[day][2];
				addCompleteDescription += addDescription;
				this.months[i].completeDayList[day][2] = addCompleteDescription;
			}
			else{
				this.months[i].completeDayList[day] = [day,href,completeDescription];
			}
			}
		this.months[i].divHTML = '';
		this.months[i].divHTML += '<span style="width:' + startCount + 'px;height:15px;display:block;float:left;"></span>';			
		for(var y = 1; y < this.months[i].daysum + 1; y++){
			if(y < 10){
					var numToString = "0" + y;
					}
				else{
					var numToString = y;
					}				
			if(!this.months[i].completeDayList[y]){				
				this.months[i].divHTML += '<span class="number">' + numToString + '</span>';
			}
			else{
				var tempHTML = '<span class="number_hi"><a class="numberlink" onmouseover="showEventDescription(calendar.months[' + i + '].completeDayList[' + y + '][2])" onmouseout="hideEventDescription()" href="' + this.months[i].completeDayList[y][1] + '">' + numToString + '</a></span>';
			 	this.months[i].divHTML += tempHTML;
			}
		
			}	
		//alert(this.months[i].html);
	}
}

/**
 * @param pIncludePassedEvents <Boolean> if true passed events shall be included
 */
function initCalendar(pIncludePassedEvents){
	var actualDate = new Date()
	var month = actualDate.getMonth() + 1;
	var year = actualDate.getFullYear();
	var checkDate = "m" + parseInt(month) + parseInt(year);
	for(var i = 0; i < calendar.months.length; i++){
		if(checkDate == calendar.months[i].name){
			activeMonth = i;
			break;
		}
	}
	if(pIncludePassedEvents == true && activeMonth==0) {
		activeMonth  =  calendar.months.length -1;
	}
	
	var startHTML = calendar.months[activeMonth].divHTML;
	var startDate = getFullDateName(calendar.months[activeMonth].name);
	document.getElementById("calendarcontent").innerHTML = startHTML;
	if(navigator.appVersion.indexOf("MSIE 5") != -1 && isMac){
		document.getElementById("chosenDate").style.width = 110 + "px";
	}
	document.getElementById("chosenDate").innerHTML = startDate;
	document.getElementById("calendarcontent").style.width = 163 + "px";
	document.getElementById("calendarcontent").style.display = "block";
	document.getElementById("calendarcontent").style.visibility = "visible";
}

function showEventDescription(whichEvent){
	document.getElementById("eventdescription").innerHTML = whichEvent;
	document.getElementById("descriptioncontainer").style.display = "block";
	document.getElementById("descriptioncontainer").style.visibility = "visible";
}
	
function hideEventDescription(){
	document.getElementById("eventdescription").innerHTML = '';
	document.getElementById("descriptioncontainer").style.display = "none";
	document.getElementById("descriptioncontainer").style.visibility = "hidden";
}

function switchMonthForward(pRequestPrefix){
	activeMonth = activeMonth + 1;
	if(activeMonth >= calendar.months.length) activeMonth = calendar.months.length -1;
	var newMonthName = calendar.months[activeMonth].name;
	newMonthName = getFullDateName(newMonthName);
	if(navigator.appVersion.indexOf("MSIE 5") != -1 && isMac){
		document.getElementById("chosenDate").innerHTML = '';
	}
	document.getElementById("chosenDate").innerHTML = newMonthName;
	document.getElementById("calendarcontent").innerHTML = calendar.months[activeMonth].divHTML;	

	updateEvents(pRequestPrefix, calendar.months[activeMonth].name);
}

function switchMonthBack(pRequestPrefix){
	activeMonth = activeMonth - 1;
	if(activeMonth <= 0) activeMonth = 0;
	var newMonthName = calendar.months[activeMonth].name;
	newMonthName = getFullDateName(newMonthName);
	if(navigator.appVersion.indexOf("MSIE 5") != -1 && isMac){
		document.getElementById("chosenDate").innerHTML = '';
	}
	document.getElementById("chosenDate").innerHTML = newMonthName;
	document.getElementById("calendarcontent").innerHTML = calendar.months[activeMonth].divHTML;	
	
	updateEvents(pRequestPrefix, calendar.months[activeMonth].name);
}

/**
 * @param pRequestPrefix
 * @param pActiveMonth
 */
function updateEvents(pRequestPrefix, pActiveMonth) {
	var ajaxRequestUrl = pRequestPrefix + pActiveMonth + '.xml';
	ajaxEngine.registerRequest(ajaxRequestUrl, ajaxRequestUrl);	
	// update content 
	ajaxEngine.sendRequest(ajaxRequestUrl);	
	rewriteEventsPrintLink(printlink, pActiveMonth);
}

//get complete year and month out of array-name
function getFullDateName(chosenMonth){
	var dateString = chosenMonth;
	dateString = dateString.substr(1,dateString.length);
	var yearString = dateString.substr(dateString.length - 4,dateString.length);
	var monthString = dateString.substr(0,dateString.length - 4);
	var monthInt = parseInt(monthString) -1;
	monthString = monthFullnames[monthInt];
	var fullName = monthString + " " + yearString;
	return(fullName);	
}

function rewriteEventsPrintLink(pPrintLink, pCurrentSelection) {
	pPrintLink = pPrintLink.replace('PLACEHOLDER',pCurrentSelection);
	var linkAnchor = document.getElementById('content_functions_print_link');
	if (linkAnchor!=null) {
		linkAnchor.href = 'javascript:'+pPrintLink;
	}
	var iconAnchor = document.getElementById('content_functions_print_icon');
	if (iconAnchor!=null) {
   iconAnchor.href = 'javascript:'+pPrintLink;
  }
}
//----- glossary functions ------


/* Sets/ Resets the text of input field
 */
function setInputText(input, defaultText)
{
	if(input.value == defaultText)
	{
		input.value="";
	}
	else if(input.value == "")
	{
		input.value = defaultText;
	}
}

// holds the most recently selected letter
var previuoslySelected;

/* highlights index entry and abc-nav-element of selected letter
 * letter: selected letter
 * clearSelected: clear/ de-highlight most recent selection
 */
function highlightLetter(letter, clearSelected) 
{
	letter = letter.toUpperCase();
	// assign highlighting css-styles
	document.getElementById('glossary_letter_headline_'+letter).className = "glossary_letter_headline_hi";
	document.getElementById('glossary_letter_contents_'+letter).className = "glossary_letter_contents_hi";
	document.getElementById('glossary_letter_head_'+letter).className = "glossary_letter_head_hi";	
	document.getElementById('glossary_abc_letter_'+letter).className = "glossary_abc_letter_hi";	
	document.getElementById('glossary_abc_link_'+letter).className = "glossary_abc_link_hi";
	
	
	// undo highlighting of previously selected entry
	if(previuoslySelected&&clearSelected&&previuoslySelected!=letter)
	{
		dehighlightLetter(previuoslySelected);
	}
	if(clearSelected)
	{
		previuoslySelected = letter;
	}
}

/* de-highlights index entry and abc-nav-element of selected letter
 */
function dehighlightLetter(letter)
{	
	letter = letter.toUpperCase();
	// assign non-highlighted css-styles
	document.getElementById('glossary_letter_headline_'+letter).className = "glossary_letter_headline";
	document.getElementById('glossary_letter_contents_'+letter).className = "glossary_letter_contents";
	document.getElementById('glossary_letter_head_'+letter).className = "glossary_letter_head";
	document.getElementById('glossary_abc_letter_'+letter).className = "glossary_abc_letter";
	document.getElementById('glossary_abc_link_'+letter).className = "glossary_abc_link";
}

/* limit displayed select entries according to input
 */
function limitEntries(selectForm, currentInput){
	var limitedEntries;
	var option;
	var title;
	var match;
	var lengthLimited;

	lengthLimited = 0;
	
	// compute length of limited Array	
	for(i = 0; i < entries.length; i++)
	{
		title = entries[i][0];
		match = title.toLowerCase().search(new RegExp(currentInput.toLowerCase()));	
		if(match != -1)
		{
			lengthLimited++;						
		}		
	}
	
	limitedEntries = new Array(lengthLimited);	
	

	// fill limited array
	for(i = 0; i < entries.length; i++)
	{
		title = entries[i][0];
		match = title.toLowerCase().search(new RegExp(currentInput.toLowerCase()));
				
		if(match != -1)
		{			
			limitedEntries.push(entries[i]);			
		}		
	}		
			
	// fill select box with options out of limitedEntries
	
	clearSelect(selectForm);		
	for(i = 0; i < limitedEntries.length; i++)
	{
		if(limitedEntries[i] != null)
		{
			option = new Option(limitedEntries[i][0], limitedEntries[i][1], false, false);
			selectForm.options[selectForm.options.length] = option;	
		}
	}
}

// switches window.location to currently selected select-option
function switchTo(currentSel){	
	window.location.href = currentSel.options[currentSel.selectedIndex].value;
}

// Clears the selectbox
function clearSelect(selectForm) {  
   var length;
   //length = document.glossaryForm.glossarySearchSelect.options.length;
   length = selectForm.options.length;
   if(length>0)
   {
	   for (i = length; i >= 0; i--) {	   
	      document.glossaryForm.glossarySearchSelect.options[i] = null;
	   }
   }
     
}

//--------------END glossary functions------------------

/*--------------sitemap functions----------------------*/

function toggleSitemapCategory(theId, activate) {

	var styleClass;	

			
	if(activate){
		styleClass = 'sitemap_col_header_hi';
	}else{
		styleClass = 'sitemap_col_header';
	}

	// apply
	if (document.all && document.all[theId].style.getAttribute) {
		document.all[theId].className = styleClass;
	} else if (document.getElementById) {
		document.getElementById(theId).className = styleClass;
	}
}

/**
 * toggles image of sitemap category headline.
 * @param theId
 * @param theUrl  
 */
function toggleSitemapCategoryImage(theId, theUrl) {
	// apply
	if (document.all && document.all[theId].style.getAttribute) {
		document.all[theId].src = theUrl;
	} else if (document.getElementById) {
		document.getElementById(theId).src = theUrl;
	}
}
/*--------------END sitemap functions------------------*/

/* function for displaying / hiding optional back-button
 *
 * checks history, if not empty, display HTML-element with id theId 
 * @param theId id of HTML element to display / hide
 */

function displayBackButton(theId) {
	if(history.length > 1) {
		if (document.all && document.all[theId].style.getAttribute) {
			document.all[theId].style.display = 'block';
		} else if (document.getElementById) {
			document.getElementById(theId).style.display = 'block';
		}
	}
}
/* END function for optional back-button */

/*dialog center functions */

/**
 * moves option from one select imput to another
 * @param pFromSelect select box from where to remove item
 * @param pToSelect select box where to add item
 */
function moveItem(pFromSelect, pToSelect) {
	var fromSelect = document.getElementById(pFromSelect);
	var toSelect = document.getElementById(pToSelect);
	var notSelectedItems = new Array();
	var amountUnselected = 0;
	if(fromSelect && toSelect) {
		// detect and copy selected options
		for(i = 0; i < fromSelect.options.length; i++) {
		 var newOpt = new Option(fromSelect.options[i].text, fromSelect.options[i].value, false, false);
			if(fromSelect.options[i].selected == true) {				
				toSelect.options[toSelect.options.length] = newOpt;
			} else {
				notSelectedItems[amountUnselected++] = newOpt	;
			}
		}		
		// clear from-select box
		for(i = fromSelect.options.length -1; i >= 0; i--) {
			fromSelect.options[i] = null;
		}
		
		// refill from select box
		for(i = 0; i < notSelectedItems.length; i++) {
			fromSelect.options[i] = notSelectedItems[i];
		}		
	}
	
}

/**
 * submits form to given url
 * Switches location to that URL. 
 * @param pForm form to be submitted
 * @param pSel select to get values of
 * @param pUrl url to post form to
 * @param pMaxBrochures maximum number of brochures allowed to be ordered at once
 */
function submitBrochureForm(pForm, pSel, pUrl, pMaxBrochures) {
	var theSel = document.getElementById(pSel);
	var theForm = document.getElementById(pForm);
	if(theSel && theForm) {
		// if show downloads, check if a selection was made
		if(pUrl.indexOf('show_downloads')>-1 && !validateBrochureSelect(pSel, null, pMaxBrochures)) {
			return;
		}
			
		theForm.action = pUrl;
		theForm.submit();
	}
}

/**
 * Validate controls of the given form against their validation rules.
 * @param pForm Form to validate
 */
function validateForm(pForm) {
	var messageBox = document.getElementById("message_box");
	if (!messageBox) return;
	var isValidated = true;	
	var errorFieldCount = 0;
	for(var i = 0; i < form_array.length; i+=6) {	
		var name        = form_array[i];
		var caption     = form_array[i+1];
		var validation  = form_array[i+2];
		var errorMsg    = form_array[i+3];
		var isMandatory = form_array[i+4];
		var maxLength   = form_array[i+5];
		var isMultiple  = (typeof name != "string");
		var message = null;
		// if custom / multiple
		if (isMultiple) {
			var formElements = new Array();
			for(var j = 0; j < name.length; j++ ){
				formElements[j] = pForm.elements[name[j]]; 
			}			
			message = getMessageMultiple(formElements, validation, isMandatory);
		} else {
			var formElement = pForm.elements[name];				
			message = getMessage(formElement, validation, isMandatory, maxLength);
		}		

		// output
		var cssClass = "form_label_dialog";

		if (message) {
			if (errorMsg) {
				message = errorMsg;
			} else {
				message = message.replace(/\{0\}/, caption); 
				message = message.replace(/\{1\}/, maxLength); 
			}
      message = "<div>" + message + "</div>"; 
			if (isValidated) {
				messageBox.innerHTML = message;
			} else {
				messageBox.innerHTML += message;
			}
			isValidated = false;
			cssClass += "_error";
			errorFieldCount++;
		}

		if (isMultiple) {
			name = name[0];
		}

		var controlBox = document.getElementById(name + "_box");
		if (controlBox) {
			controlBox.className = cssClass;
		}
	}
	if (!isValidated) {
    messageBox.innerHTML = "<div style=\"MARGIN-BOTTOM: 12px;\">" + messageBox.innerHTML + "</div>";
    
    // send custom user tracking event with error count fields
    if (typeof cms_UserTracking_sendCustomEvent == "function"
        && typeof usertracking_pageurl_default == "string"
        && typeof usertracking_pagetitle_default == "string") {
      cms_UserTracking_sendCustomEvent("FormValidationErrors", usertracking_pageurl_default, usertracking_pagetitle_default,
        null, null, {errorFieldCount:errorFieldCount});
    }
    
	}
	return isValidated;
}

/**
 *  Return the value of the given form element.
 *  @param pElement Element to get the value of
 */
function getValue(pElement) {
	if(!pElement){
		return null;		
	}
	var value = "";
	if (pElement.length) {
		for (var x = 0; x < pElement.length; x++) {
			if (pElement[x].checked || pElement[x].selected) {
				value += (value ? "," : "") + pElement[x].value;
				break;
			}
		}
	} else {
		value = pElement.value;
	}
	return value;
}



var JS_IDENTIFIER = "javascript:";

/**
 *  Get the validation message for the given form element.
 *  @param pElement Form element to get the message for
 *  @param pValidation Validation expression
 *  @param pIsMandatory Whether the element is mandatory
 *  @param pMaxLength Max length of the element
 */
function getMessage(pElement, pValidation, pIsMandatory, pMaxLength) {
	if(!pElement) {
		return null;
	}
	var message = null;
	var value = getValue(pElement);
	if (pIsMandatory && (!value || value.length == 0)) {
		if (pElement.options) {
			message = lang['submit_error_selection_missing'];
		} else {
			message = lang['submit_error_field_missing'];
		}
	}
	else if (pValidation.length > 0) {
		var indexJs = pValidation.indexOf(JS_IDENTIFIER);
		if (indexJs == 0) { 
			var jsMethodName = pValidation.substring(indexJs + JS_IDENTIFIER.length);		 	
			var values = new Array(value);
			eval("message = " + jsMethodName + "(values)");
		} else {
			var regExp = new RegExp(pValidation);			
			if (!regExp.test(value)) {
				message = lang['submit_error_field_invalid'];
			}
		}
	} else if (pMaxLength > 0 && value.length > pMaxLength) {
		message = lang['submit_error_field_too_long'];
	}
	return message;
}

/**
 *  Get the validation message for the given form elements.
 *  @param pElement Form elements to get the message for
 *  @param pValidation Validation expression
 *  @param pIsMandatory Whether the elements are mandatory
 */
function getMessageMultiple(pElements, pValidation, pIsMandatory) {
	if(!pElements) {
		return null;
	}
	var message = null;
	var values = new Array();
	var emptyVal = false;
	for (var k = 0; k < pElements.length; k++) {
		values[k] = getValue(pElements[k]);	
		if(!values[k] || values[k].length == 0)	{
			emptyVal = true;
		}
	}

	var jsMethodName;
	var paramCount = 0;
	if (pValidation.length > 0) {
		// Check whether validation expression contains javascript
		var indexJs = pValidation.indexOf(JS_IDENTIFIER);
		if(indexJs > -1) { 
			jsMethodName = pValidation.substring(indexJs + JS_IDENTIFIER.length);
			paramCount = eval(jsMethodName + ".length");
		}
	}

	// If the custom validation method accepts a second parameter it implements a custom mandatory validation
	var customMandatory = (paramCount > 1);
	if (!customMandatory && pIsMandatory && emptyVal) {
		message = lang['submit_error_field_missing'];
	}
	else if (jsMethodName && (!emptyVal || customMandatory)) {
		// Evalutate custom validation method
		message = eval(jsMethodName + "(values, pIsMandatory)");
	}
	return message;
}

/**
 * TODO: comment
 */
function fillTravelSelects(pProgramSelect, pDestSelect, pIntervalSelect, pParicipantsSelect, pLevel, pStore){
	var programSelect = document.getElementById(pProgramSelect);
	var destSelect = document.getElementById(pDestSelect);
	var intervalSelect = document.getElementById(pIntervalSelect);
	var participantsSelect = document.getElementById(pParicipantsSelect);
	var store = document.getElementById(pStore);
	
	if(programSelect && destSelect && intervalSelect && participantsSelect) {	
		
		//var controls = new Array(programSelect, destSelect, intervalSelect, participantsSelect);
				
		var prgIndex = programSelect.selectedIndex -1;
		var dstIndex = destSelect.selectedIndex -1;
		var itvIndex = intervalSelect.selectedIndex -1;
		var pcpIndex = participantsSelect.selectedIndex -1;
		
		
		if(pLevel == 0) {
			destSelect.selectedIndex = 0;
			intervalSelect.selectedIndex = 0;	
			participantsSelect.selectedIndex = 0;			
			if(prgIndex < 0) {
				destSelect.disabled = true;				
				intervalSelect.disabled = true;
				participantsSelect.disabled = true;				
			} else {
				fillSelect(destSelect, programs[prgIndex][1]);	
				destSelect.disabled = false;
			}
			return;
		} 
				
		if(pLevel == 1) {
			intervalSelect.selectedIndex = 0;	
			participantsSelect.selectedIndex = 0;
			if(dstIndex < 0) {				
				intervalSelect.disabled = true;				
				participantsSelect.disabled = true;
			}	else {	
				fillSelect(intervalSelect, programs[prgIndex][1][dstIndex][1]);
				intervalSelect.disabled = false;
			}
			return;
		}

		if(pLevel == 2) {
			participantsSelect.selectedIndex = 0;
			if(itvIndex < 0) {			
				participantsSelect.disabled = true;
		}	else {		
			  var maxVal = programs[prgIndex][1][dstIndex][1][itvIndex][1];
				fillParticipantsSelect(participantsSelect, maxVal);
				participantsSelect.disabled = false;
			}
			
		}			
	}
	
	// fill value store
	if(programSelect.selectedIndex > -1 && destSelect.selectedIndex > -1 && intervalSelect.selectedIndex > -1 && participantsSelect.selectedIndex > -1) {
		store.value = programSelect.options[programSelect.selectedIndex].value + ", " 
								+ destSelect.options[destSelect.selectedIndex].value + ", " 
								+ intervalSelect.options[intervalSelect.selectedIndex].value + ", "
								+ participantsSelect.options[participantsSelect.selectedIndex].value;
	}						
}


/**
 * fills select box with options from 2d array values (value=text). Leaves first option unchanged.
 * @param pSelect select box to be filled
 * @param pValues 2d array of values
 */
function fillSelect(pSelect, pValues) {
		
		// clear select box
		for(i = pSelect.options.length -1; i > 0; i--) {
			pSelect.options[i] = null;
		}
		// refill select box
		for(i = 0; i < pValues.length; i++) {
			pSelect.options[i+1] = new Option(pValues[i][0], pValues[i][0], false, false);
		}	
}

/**
 * fills select box with options from 2d array values (value=text). Leaves first option unchanged.
 * @param pSelect select box to be filled
 * @param pValues 2d array of values
 */
function fillParticipantsSelect(pSelect, pMaxVal) {
		
		// clear select box
		for(i = pSelect.options.length -1; i > 0; i--) {
			pSelect.options[i] = null;
		}
		// refill select box
		for(i = 1; i <= pMaxVal; i++) {
			pSelect.options[i] = new Option(i, i, false, false);
		}	
}


/**
 * validates travel event inputs
 * @param pParticipSelName name/id of input for participants, which must have selection > 0 (=default 'please choose' option)
 * @param pErrorMsg i18n error message
 */
function validateTravelEvent(pParticipSelName) {
	var errorMsgBox = document.getElementById('errorMsgBox');
	if (!errorMsgBox) {
		return false;
	}
	var participantsSelect = document.getElementById(pParticipSelName);
	if(participantsSelect && participantsSelect.selectedIndex > -1) {		
		errorMsgBox.style.display = 'none';
		return true;
	}
	errorMsgBox.style.display = 'block';
	errorMsgBox.className = 'dialog_error_txt';
	var errMsg = "Please select an event!";
	if(TRAVEL_EVENT_ERROR_MESSAGE) {
		errMsg = TRAVEL_EVENT_ERROR_MESSAGE
	}
	errorMsgBox.innerHTML = "<div>" + errMsg + "</div>";
	return false;			
}

/**
 * validates brochure select input.
 * @param pSelectSelectedName name/id of input with selected brochures 
 * @param pSelectNotSelectedName name/id of input with not selected brochures
 * @param pMaxBrochures maximum number of brochures allowed to be ordered at once
 * @param pIsOnClick true if validation is invoked on click, false if on submit
 */
function validateBrochureSelect(pSelectSelectedName, pSelectNotSelectedName, pMaxBrochures, pIsOnClick) {
	var errorMsgBox = document.getElementById('errorMsgBox');
	if (!errorMsgBox || !pMaxBrochures) {		
		return false;
	}
	var theSelected = document.getElementById(pSelectSelectedName);	
	
	// split up if-clause to increase readability
		
	// on click validation
	if(pIsOnClick) { 
		var theNotSelected = document.getElementById(pSelectNotSelectedName);
		if(theSelected && theNotSelected && pMaxBrochures && getValidSelectOptions(theSelected, false) +  getValidSelectOptions(theNotSelected, true) <= pMaxBrochures) {
			errorMsgBox.style.display = 'none';
			return true;
		}
	}else { // on submit validation
		if(theSelected && pMaxBrochures && getValidSelectOptions(theSelected, false)	 > 0 && getValidSelectOptions(theSelected, false) <= pMaxBrochures) {
			errorMsgBox.style.display = 'none';
			return true;
		}	
	}
	
	errorMsgBox.style.display = 'block';
	var errMsg = "Please select a brochure!";
	if(BROCHURE_ERROR_MESSAGE) {
		errMsg = BROCHURE_ERROR_MESSAGE;
	}
	errorMsgBox.innerHTML = "<div>" + errMsg + "</div>";
	return false;	
}

/**
 * @param pSelect select object to be checked
 * @param pCheckSelection true if if only selected options shall be counted, false if not
 * @return # of options being not null
 */
function getValidSelectOptions(pSelect, pCheckSelection) {
	var countOptions = 0;
	if(pSelect) {	
		for(i=0;i<pSelect.options.length;i++) {
			if(typeof(pSelect.options[i] != "object")){
				if(!pCheckSelection || pSelect.options[i].selected) {
					countOptions++;	
				}
			}
		}
	}
	return countOptions
}


/**
 * 
 *
 */
function getSelectedOptions(pSelectName) {
	var theSelect = document.getElementById(pSelectName);
	var countOptions = 0 ;
	if(theSelect) {		
		for(i = 0; i < theSelect.options.length; i++) {
			if(theSelect.options[i].selected) {
				countOptions++;
			}
		}
	}
	return countOptions;
}

/** constant regexp matching numeric expressions*/
var PATTERN_NUMERIC = /\d+/;

/**
 * custom validation of date fields
 * @param pValues array of values to check
 */
function validateDate(pValues){
	var message = null;
	var day = pValues[0];
	var month = pValues[1];
	var year = pValues[2];	
	var regExp = new RegExp(PATTERN_NUMERIC);		
			
	if (!regExp.test(day) || !regExp.test(month) || !regExp.test(year)) {
		message = lang['submit_error_field_invalid'];
	}
	return message;
}

/**
 * custom validation of date zip-and-city fields
 * @param pValues array of values to check
 */
function validateZipAndCity(pValues){
	var message = null;
	var zip = pValues[0];
	var regExp = new RegExp(PATTERN_NUMERIC);			
	if (!regExp.test(zip)) {
		message = lang['submit_error_field_invalid'];
	}
	return message;
}

/**
 * custom validation of phone fields
 * @param pValues array of values to check
 */
function validatePhone(pValues){
	var message = null;
	var prefix = pValues[0];
	var number = pValues[1];
	var regExp = new RegExp(PATTERN_NUMERIC);			
	if (!regExp.test(prefix) || !regExp.test(number)) {
		message = lang['submit_error_field_invalid'];
	}
	return message;
}

/**
 * custom validation of email fields
 * @param pValues array of values to check
 */
function validateEmail(pValues){
	var message = null;
	var value = pValues[0];
	var regExp=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i			
	if (!regExp.test(value)) {
		message = lang['submit_error_field_invalid'];
	}
	return message;
}

/** 
 * Validate salutation control.
 * @param pValues Value Array (0:Salutation 1:Title)
 * @param pIsMandatory Whether the Salutation field is mandatory
 */
function validateSalutation(pValues, pIsMandatory){
	var message = null;
	var value = pValues[0];
	if (pIsMandatory && (!value || value.length == 0)) {
		message = lang['submit_error_field_missing'];
	}
	return message;
}

/**
 * Builds comma separated list of selected carlines in given input.
 * @param pSelect select to retrieve values from
 * @param pHiddenKeyStore input to store names in
 */
function updateCarlines(pSelect, pHiddenKeyStore) {
	var select = document.getElementById(pSelect);
	var store = document.getElementById(pHiddenKeyStore);
	if(select && store) {
		store.value = "";
		for(var i = 0; i < select.options.length; i++) {
			if(store.value.length != 0){
				store.value += ";" ;
			}			
			store.value += select.options[i].value;		
		}
	}
}

/**
 * Updates the hidden control containing the selected option text
 * @param pSelect Select gourp form element
 */
function selectGroupChanged(pSelect) {
  if(!pSelect) return;
  var frm = pSelect.form;
  var controlName = pSelect.name + "txt";
  
  if(frm.elements[controlName]) {
    var selectedLabel = "";
    if (pSelect.selectedIndex > -1) {
      var selectedOption = pSelect.options[pSelect.selectedIndex];
      selectedLabel = selectedOption.text;
    }
    frm.elements[controlName].value = selectedLabel;
  }
}

/*END dialog center functions */

/* Fullsize Popup Functions*/

/**
 * checks for url param doResize. If not existent or set to 1, window is resized to fullscreen.
 * Resizing is disabled, when doResize is set to 0.
 */
function resizeFullsizePopup() {
	var doResize=true;
	var urlParams = location.search;
	urlParams = urlParams.substring(urlParams.indexOf('doResize'));
	if(urlParams.indexOf('&')>-1) {
		urlParams = urlParams.substring(0,urlParams.indexOf('&'));
	}		
	if(urlParams.indexOf('doResize=0')>-1){
		doResize = false;	
	} else if(urlParams.indexOf('doResize=1')>-1) {
		doResize = true;
	}	
	if(doResize){
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth,screen.availHeight);
	}
}

/**
 * Opens link in opener if existent, otherwise opens in same window
 * @param pUrl url to link to
 */
function openInOpener(pUrl) {	
	if(pUrl) {
		var prefix = '';
		if(window.opener) {
			prefix = 'window.opener.';
			window.opener.focus();
		} 			
		eval(prefix + pUrl);
	}
}

/* END Fullsize Popup Functions*/

/* meta nav login */

/**
 * contains eprofile login state and links according to current state
 * @param pTitle title attribut
 * @param pHref href of link
 */
function LoginLink(pTitle, pHref){
	this.title = pTitle;
	this.href = pHref;
}

/**
 * writes uncached login links in metanav
 * @param pLoginLinks array of LoginLink-objects containing title, href
 * @param pLoggedInText message text in logged-in state
 */
function writeLogin(pLoginLinks, pLoggedInText) {
	if(pLoginLinks && pLoggedInText) {
		document.write("<span style=\"PADDING-LEFT: 23px;\">");
		if(eprofile_currentuser_info!=null) {
			document.write("<span style=\"COLOR: #000000;PADDING-RIGHT: 8px;\">"+pLoggedInText+"</span>");
			document.write("<a href=\""+pLoginLinks[1].href+"\">"+pLoginLinks[1].title+"</a>");
			document.write("<span class=\"foothead_vertical_separator\">I</span>");
			document.write("<a href=\""+pLoginLinks[2].href+"\">"+pLoginLinks[2].title+"</a>");
		} else {
			document.write("<a href=\""+pLoginLinks[0].href+"\">"+pLoginLinks[0].title+"</a>");
		}
	  document.write("</span>");
  }
}


/* END meta nav login */

/* FPS functions */

/**
 * fills select box with id pSelectName with model options depending on modelgroup selection indicated pSelectedValue
 * @param pSelectedValue name of selected modelgroup
 * @param pModels array of modelgroups / models
 * @param pSelectName name/id of select box to be (re-)filled
 * @param pSelectedOption (pre-)selected option   
 */
function toggleFpsTechdataSelect(pSelectedValue, pModels, pSelectName, pSelectedOption) {
	var sel = document.getElementById(pSelectName);
	if(sel && pModels) {
		var modelOptions = pModels[pSelectedValue];
		var selectedModelLabel = null;
		
		// clear options and leave first option 
		for(var i = sel.options.length-1; i > 0; i--) {
			sel.options[i] = null;
		}
		var modelOptionsSize=0;
		if(modelOptions){
			modelOptionsSize=modelOptions.length;
		}
		// refill options
		for(var i =  1; i <= modelOptionsSize; i++) {
			sel.options[i] = modelOptions[i-1];
			// check option if matches pre-select
			if(pSelectedOption && pSelectedOption.indexOf(sel.options[i].value)>=0) {
				sel.options[i].selected = true;
				selectedModelLabel = sel.options[i].text; 
			}
		}		

		// generate custom user tracking page title
		if (typeof usertracking_pagetitle_default == "string") {
		  var pageTitle = usertracking_pagetitle_default;
		  
		  if (selectedModelLabel) {
		    pageTitle += " - " + selectedModelLabel;
		  }
		  
		  usertracking_pagetitle_customized = pageTitle;
		}
	}
}

/**
 * contains tab category data
 * @param pTitle title attribut
 * @param pData array of subcategories
 */
function Category(pLabel, pTitle, pData) {
	this.label = pLabel
	this.title = pTitle;
	this.data = pData;
}

/**
 * registers and sends ajax request and toggles tan navigation display according to selection given.
 * 
 * @param pCategories array of available categories and super categories
 * @param pPageHandle handle of page to be queried
 * @param pPageExtension extension of page to be queried
 * @param pSelectedCategory selected category
 * @param pSelectedSuperCategory selected super category   
 * @param pVariation selected varation
 * @param pIsPrintView true if is invoked in print view
 */
function switchTab(pCategories, pPageHandle, pPageExtension, pSelectedCategory, pSelectedSuperCategory, pVariation, pIsPrintView) {
	var label;
	var elem;
	var subEntries;
	var categories;
	var ajaxRequestId;
	var ajaxRequestUrl;
	var isTopLevel = pSelectedSuperCategory == null;
	var hasTwoLevels = pCategories.length > 1;
	var subCategory = null;
	var variation = '';
	
	// generate ajax request id and url, constants 'AJAX_GLOB','CATEGORY', 'SUPER_CATEGORY' set in context of calling page
	
	if(!isTopLevel) {	// in case of 'being'	a category tab

		ajaxRequestId = 'switchFpsTab_' + SUPER_CATEGORY + pSelectedSuperCategory + '_' + CATEGORY + pSelectedCategory;		
		ajaxRequestUrl = pPageHandle + "." + AJAX_GLOB +  "." + SUPER_CATEGORY + pSelectedSuperCategory + "." + CATEGORY + pSelectedCategory;
	
		// find  matching sub category array	
		categories = new Array();
		for(var i = 0; i < pCategories.length; i++) {
			if(pCategories[i].label == pSelectedSuperCategory) {
				categories = pCategories[i].data;
				break;
			}	 
		}
		
		// highlight parent
		var parentTab = document.getElementById(pSelectedSuperCategory);
		if(parentTab) {
			parentTab.className = STYLE_TOPLEVEL_SELECTED;
		}
		
		
	} else { // in case of 'being' a super category tab
		categories = pCategories;	
					
		// get first sub entry of (super) category
		for (var i = 0; i < categories.length; i++) {
			if(categories[i].label == pSelectedCategory){				
				subCategory = categories[i].data[0].label;
				break;
			}
		}		
		
		ajaxRequestId = 'switchFpsTab_' + SUPER_CATEGORY + pSelectedCategory + '_' + CATEGORY + subCategory;						
		ajaxRequestUrl = pPageHandle + "." + AJAX_GLOB +  "." + SUPER_CATEGORY + pSelectedCategory + "." + CATEGORY + subCategory;
	}
	
	
	// add variation
	if(pVariation){ //&& pVariation.length > 0) {
			ajaxRequestId += "_" + pVariation;
			ajaxRequestUrl += "." + pVariation;
	}
	
	// set styles
	var styleSelected; 
	var styleNotSelected;
	if(isTopLevel || !hasTwoLevels) {
		//constants STYLE_TOPLEVEL, STYLE_TOPLEVEL_SELECTED, STYLE_2ND_LEVEL, STYLE_2ND_LEVEL_SELECTED set in context of calling page
		styleSelected = STYLE_TOPLEVEL_SELECTED; 
		styleNotSelected = STYLE_TOPLEVEL;
	} else {
		styleSelected = STYLE_2ND_LEVEL_SELECTED; 
		styleNotSelected = STYLE_2ND_LEVEL;
	}
	
	// toggle nav styles and display
	var subItemLabel;
	var subItem;
	
	for(var i = 0; i < categories.length; i++) {

		label = categories[i].label;		
		var elems = document.getElementsByName(label);
		for(var h = 0; h < elems.length; h++) {
			elem = elems[h];
			if(elem) {
				subEntries = document.getElementById(label + '_items');
				if(label == pSelectedCategory) {
					elem.className = styleSelected;								
					if(subEntries) {
						subEntries.style.display = 'block';
						// set sub item tab label styles
						for(var j = 0; j < categories[i].data.length; j++) {
							subItemLabel = categories[i].data[j].label;
							var subItems = document.getElementsByName(subItemLabel);
							for(var k = 0; k < subItems.length; k++) {
								subItem = subItems[k];
								if(subItem) {
									if(j==0) {
										subItem.className = STYLE_2ND_LEVEL_SELECTED;
									} else {
										subItem.className = STYLE_2ND_LEVEL;							
									}
								}
							}
						}					
					}			
				} else {
					elem.className = styleNotSelected;
					if(subEntries) {
						subEntries.style.display = 'none';
					}	
				}
			}
		}
	}
	
	if(!pIsPrintView) {
		// register ajax request	
		ajaxEngine.registerRequest(ajaxRequestId, ajaxRequestUrl + pPageExtension);
		
		// update content 
		ajaxEngine.sendRequest(ajaxRequestId);	
	}
	
	// update category vars	
	if(isTopLevel) {
		currentSuperCategory = pSelectedCategory;
		currentCategory = subCategory;
	} else {	
		currentCategory = pSelectedCategory;
		currentSuperCategory = pSelectedSuperCategory;
	}
	//DEBUG: alert(ajaxRequestUrl + pPageExtension);
	
	// simulate on load user tracking (not for toplevel to avoid double logging)
	if (!isTopLevel) {
		if (typeof cms_UserTracking_sendOnLoadEvent == "function"
		    && typeof usertracking_pagetitle_default == "string") {
		  var pageTitle = usertracking_pagetitle_default;
		  // check for tabnavselector box (strip of strings after ",", i.e. headline image)
		  var fpsTabNavSelector = document.getElementById("fpsTabNavSelector");
		  if (fpsTabNavSelector) {
		    var tabNavSelectorValue = fpsTabNavSelector.value;
		    var stripOffPos = tabNavSelectorValue.indexOf(",");
		    if (stripOffPos>=0) {
			    tabNavSelectorValue = tabNavSelectorValue.substring(0,stripOffPos);
		    }
		    pageTitle += " - " + tabNavSelectorValue;
		  }
		  
		  // append super category and category titles
		  currentSuperCategoryTitle = null;
		  currentCategoryTitle = null;
		  try{
		  	for(var i = 0; i < pCategories.length; i++) {
					var superCategory = pCategories[i];
					if(superCategory.label==currentSuperCategory) {
						currentSuperCategoryTitle = superCategory.title;
						for(var j = 0; j <superCategory.data.length; j++) {
							var category = superCategory.data[j];
							if(category.label==currentCategory) {
								currentCategoryTitle = category.title;
								break;		
							}
						}
						break; 
					}
				}
		  } catch(e){
			  //ignore
		  }
		  
		  if (currentSuperCategoryTitle!=null && currentSuperCategoryTitle!="default" && currentSuperCategoryTitle!="1") {		  				
		    pageTitle += " - " + currentSuperCategoryTitle;
		  }
		  if (currentCategoryTitle!=null) {		  	
		    pageTitle += " - " + currentCategoryTitle;
		  }
		  
		  // keep customized page title
		  usertracking_pagetitle_customized = pageTitle;
		 	if(!pIsPrintView) { 
		  	cms_UserTracking_sendOnLoadEvent(null, pageTitle, usertracking_onload_config);
		  }
		}
	}
} 

/**
 * Sets colors and specs variation selector value according to selected checkboxes.
 * @param pFormName id of form containing checkboxes.
 */
function setVariantSelector(pFormName) {
	var frm = document.forms[pFormName];
	
	var variants = '';
	
  if (frm!=null){
		for (var i=0; i < frm.elements.length; i++) {
			if (frm.elements[i].id.indexOf(checkboxPattern) != -1) {
				if(frm.elements[i].checked == true) {
					if (variants.length > 0) {
						variants += '_';
					}
					variants += frm.elements[i].value;
				}
			}
		}
	}
	
	if (variants.length > 0) {
		currentVariation = VARIATION + SELECTED_MODELVARIANTS + getSelectedModelVariant() + '_' + variants;
	} else {
		currentVariation = VARIATION + SELECTED_MODELVARIANTS + getSelectedModelVariant();
	}
}

function getSelectedModelVariant() {
	var selectedModelVariant = 'sel0';
	if(currentVariation) {
		// strip prefix
		currentVariation = currentVariation.substr(currentVariation.lastIndexOf('-')+1);
		var modelVariants = currentVariation.split('_');
		for(var i = 0; i < modelVariants.length; i++) {
			if(modelVariants[i].indexOf('sel') !=-1) {
				selectedModelVariant = modelVariants[i];
				break;
			} 
		}
	}
	return selectedModelVariant;
}

/**
 * TODO: might/should be replacable by existing js function.
 * Opens popup with external url 
 * @param pUrl url to be opened in popup
 */
function externalImagePopup(pUrl) {
	var windowFeatures = "toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=no, width=300, height=300";
	var win = window.open(pUrl,'external_image_popup',windowFeatures);
}


/**
 * Toggles (grouped) nav entries depending on given id in given nav
 * @param pName id of entry/group of entries to be activated
 * @param pNavId id of nav to be toggled
 */
function toggleScrollNavEntries(pName, pNavId) {
  var entryBlockTitle = eval('entryBlockTitle' + pNavId);
  var entries = eval('entries' + pNavId);
  var titles = eval('entryTitles' + pNavId);
	for (var i = 0; i < entries.length; i++) {
		var groupedEntries = document.getElementsByName(entries[i]);
		var navLink = document.getElementById(entries[i]+'_NAVLINK');
		if (groupedEntries && navLink) {
			for (var j = 0; j < groupedEntries.length; j++) {
				var entry = groupedEntries[j];
				if (entries[i]==pName) {
					entry.style.display = 'block';
					eval('previousNavEntry' + pNavId + 	'= entries[Math.max(i-1,0)]');
					eval('nextNavEntry' + pNavId + '=  entries[Math.min(i+1,entries.length-1)]');
					navLink.style.color = '#000000';
					
					// fire custom on load event
					if (typeof cms_UserTracking_sendOnLoadEvent == "function"
	    				&& typeof usertracking_pagetitle_customized == "string") {
						var title = usertracking_pagetitle_customized + " - " + entryBlockTitle + ": " + titles[i];
						cms_UserTracking_sendOnLoadEvent(null, title, usertracking_onload_config);
	    		}
					
				} else {
					entry.style.display = 'none';
					navLink.style.color = '#3C5F8C';
				}				
			}
		}		
	}
}

/**
 *  toggles images in sample config module
 * @param pImageId id of image div to be displayed
 * @param pAltImageId id of image div to be hidden
 */
function toogleSampleConfigImages(pImageId, pAltImageId) {
	var imgDiv = document.getElementById(pImageId);
	var altImgDiv = document.getElementById(pAltImageId);
	if(imgDiv && altImgDiv) {
		imgDiv.style.display = 'block';
		altImgDiv.style.display = 'none';
	}
}

/**
 * Updates both flash object and/or embed element assigned with given name by setting variable 'variation' to given pValue
 * @param pFlashName name of flash object and embed element
 * @param pValue value to be set
 */
function updateFlash(pFlashName, pValue) {
	var flashes = document.getElementsByName(pFlashName);
	if(flashes) {
		// iterate on all possible elements (shoud be both 'object' and 'embed') and ignore possible errors to have function work cross browser
		for(var i = 0; i < flashes.length; i++) {
			var flash = flashes[i];
			try {
				splitValues = pValue.split(',');
				flash.SetVariable('variation', splitValues[0]);
			} catch(ex) {
				// ignore
			}
			
		}
	}
}

var INFOBOX_ORIENTATION_LEFT = 0;
var INFOBOX_ORIENTATION_RIGHT = 1;

/**
 * @param pId id of layer to be shown
 */
function showInfoLayer(pId, pReferenceObjId, pOrientation, pArrowSymbol, pIsPublishMode, pStageOffset) {
	var layer = document.getElementById(pId);
	var reference = document.getElementById(pReferenceObjId);
	var orientation = pOrientation;
	if(orientation==null || (orientation != INFOBOX_ORIENTATION_RIGHT && orientation != INFOBOX_ORIENTATION_LEFT)) {
		orientation = INFOBOX_ORIENTATION_RIGHT;
	}
	if(layer && reference) {
		layer.style.display = 'block';
		var referencePos =  findPos(reference);//Position.get(reference);			
		
		arrangeInfoLayer(layer,referencePos,orientation,pArrowSymbol);
	}
}

/**
 * Because of different browser interpretations of style.top and style.left the variation has to be calculated and adjusted  
 * @param pLayer Layer to arrange
 * @param pReferencePosition y-coordinate of chosen icon
 * @param pOrientation on right or left site of chosen icon 
 * @param pArrowSymbol
 */
function arrangeInfoLayer(pLayer, pReferencePosition, pOrientation,pArrowSymbol){
	var arrow = document.getElementById(pArrowSymbol);
	if(!pLayer || !pReferencePosition){
		return;
	}
	pLayer.style.top='0px';
	pLayer.style.left='0px';	
	var layerPosition = findPos(pLayer);
	if(pOrientation == INFOBOX_ORIENTATION_LEFT) {
		var offsetLeft=pReferencePosition[0]-pLayer.offsetWidth-layerPosition[0]-1;
		pLayer.style.left=offsetLeft+'px';
		if(arrow) {
			arrow.style.left=(pLayer.offsetWidth-6)+'px';
		}
	}
	else{
		var offsetLeft=pReferencePosition[0]-layerPosition[0]+16;
		pLayer.style.left=offsetLeft+'px';
	}
	var differenceTop=pReferencePosition[1]-layerPosition[1]-17;
	pLayer.style.top=differenceTop+'px';
}

/**
 * @param pId id of layer to be hidden
 */
function hideInfoLayer(pId) {
	var layer = document.getElementById(pId);
	var icon = document.getElementById(pId+"_icon");
	if(layer&&icon) {
		var layerPos = findPos(layer);	
		var iconPos = findPos(icon);
		if(!(mousePosX>=layerPos[0] && mousePosX<=layerPos[0]+layer.offsetWidth &&  mousePosY>=layerPos[1] && mousePosY<=layerPos[1]+layer.offsetHeight)
		&& !(mousePosX>=iconPos[0] && mousePosX<=iconPos[0]+icon.offsetWidth && mousePosY>=iconPos[1] && mousePosY<=iconPos[1]+icon.offsetHeight)) {
			layer.style.display = 'none';		
		} 
	}
}


/**
	POSITIONING, POSITION RETRIEVAL
**/
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {		
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function mouseX(evt) {
	if (evt.pageX) {
		return evt.pageX;
	} else if (evt.clientX) {
  	return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  } else {
	  return null;
  }
}
function mouseY(evt) {
	if (evt.pageY) {
		return evt.pageY;
	} else if (evt.clientY) {
	  return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :	document.body.scrollTop);
	} else {
		return null;
	}
}

var mousePosX;
var mousePosY;

function getmouseposition(evt) {
  try {
		if(!evt) evt = window.event; // IE compatibility
		mousePosX = mouseX(evt);
		mousePosY = mouseY(evt);
  }
  catch (ex) {
    // ignore errors
  }
}

document.onmousemove = getmouseposition;


function toggleFinancialServicesData(pTableOn,pTableOff,pToggleDivOn,pToggleDivOff){
	try {
		document.getElementById(pTableOn).style.display = 'block';
		document.getElementById(pTableOff).style.display = 'none';
		document.getElementById(pToggleDivOn).style.display = 'block';
		document.getElementById(pToggleDivOff).style.display = 'none';		
	} catch(ex)	{
		// ignore
	}
}

function updateContentHeadline(pImageId, pValue) {
	img = document.getElementById(pImageId);
	if (img) {
		try {
			splitValues = pValue.split(',');
			if(splitValues.length>1) {
				img.src = splitValues[1];	
			}
		} catch(ex) {
			// ignore		
		}
	}
}


	
function fpsControlCheckBoxes(obj, pFormName) 
{
	var minAnzahlCheckboxActivatedFps = 0;
	var maxAnzahlCheckboxActivatedFps = 3;
	var checkboxPattern ="checkbox";  
	var frm;
	if(pFormName) {
		frm = document.getElementById(pFormName);
	} else {
		frm = document.forms["ausstattungsform"];
	}
	var countActiveCheckBoxes = 0;
	for (var i=0; i < frm.elements.length; i++) {
		if (frm.elements[i].id.indexOf(checkboxPattern) != -1) 		{
			//if (frm.elements[i].id == obj.id)	{
				if (frm.elements[i].checked == true) {
	       	countActiveCheckBoxes++;
        }                         
        /* less than min */
        if (countActiveCheckBoxes < minAnzahlCheckboxActivatedFps) {
           countActiveCheckBoxes=minAnzahlCheckboxActivatedFps;
           obj.checked = true;
        }
        /* more than max */
        if (countActiveCheckBoxes > maxAnzahlCheckboxActivatedFps) {
		        countActiveCheckBoxes=maxAnzahlCheckboxActivatedFps;
            obj.checked = false;
        }
      //}
    }
  } 
}

/* END FPS functions */

/* Fullsize Template functions */
function adjustBackground() {
	var width = '101.5%';
	try {
		if (document.getElementById('row_stage_flex_bg') && navigator.appName.indexOf("Microsoft")==-1) {
			width = window.innerWidth-16;			 
		 } else {
				width = document.body.clientWidth;
		 }
		 document.getElementById('row_stage_flex_bg').style.width = width+"px";
	 } catch(e) {
	 	// ignore
	 }
}
		
window.onresize=adjustBackground;

/* END Fullsize Template functions */

function allItemsUnchecked(pName) {
 var elems = document.getElementsByName(pName);
 var allUnchecked = true;
 if(elems) {
 	for(var i = 0; i < elems.length; i++) { 	
 		if(elems[i].checked) {
 			allUnchecked = false;
 			break;
 		}
 	}
 }
 //alert(allUnchecked); 
 return allUnchecked;
}