

///////////
var active = "no match";
var aTemp = new Array();

function writeAllDivsLM(mylg) {
	var out = '';
	for(var i=0; i<b_sort_arr.length; i++) {
		out += getTableMainLM(b[b_sort_arr[i]][3]);
	}	
	document.write(getdivmainlm(out,mylg));
}

function getdivmainlm(outTable,divlg) {
	var out = '';
	var nlpic = 'anm';
	var nlurl = '';
	var facebookde = 'http://www.facebook.com/bettybossi';
	var facebookfr = 'http://www.facebook.com/bettybossienfrancais';
	var twitter = 'http://www.twitter.com/bettybossi';
	var youtube = 'http://www.youtube.com/bettybossichannel';
	
	if(hasNLprofile==1){
		nlpic = 'profil';
		nlurl = '_profil';
	}
	out += '<div id="mainMenu" class="divmainlm">';
	out += '<table border="0" cellpadding="0" cellspacing="0" width="179">';
	out += '<tr><td height="1" class="mainmenuout" style="cursor:pointer;cursor:hand;"><img src="/images/menu_dottedline.gif" width="179" height="1" alt="" border="0"></td></tr>';
	out += outTable
    out += '<tr><td height="50" valign="bottom" align="center"><br><a href="/'+divlg+'/forum/forum_news'+nlurl+'.aspx"><img name="nlbut" src="/images/but_newsletter3_'+nlpic+'_'+divlg+'.gif" alt="" border="0"></a>';
	//Adding social media features
    out += '<br>';
    if(divlg=='de'){
		out += '<a href="'+facebookde+'" target="_blank"><img name="facebookbut" src="/images/facebook.png" alt="" border="0"></a>&nbsp;';
		out += '<a href="'+twitter+'" target="_blank"><img name="twitterbut" src="/images/twitter.png" alt="" border="0"></a>&nbsp;';
		out += '<a href="'+youtube+'" target="_blank"><img name="youtubebut" src="/images/youtube.png" alt="" border="0"></a>&nbsp;';
	}
	else{
		out += '<a href="'+facebookfr+'" target="_blank"><img name="facebookbut" src="/images/facebook.png" alt="" border="0"></a>';
	}
    out += '</td></tr>';
	//out += '<tr><td height="50" valign="bottom" align="center"><br><a href="/'+divlg+'/shop/iwb_shop_abo_list.aspx"><img name="nlbut" src="/images/but_zeitung_'+divlg+'.gif" alt="" border="0"></a></td></tr>';
	out += '</table></div>';
	return out;
}

function checkForActiveLM(arr)
	{	
		var aarr = arr;
		var tarr = 't' + aarr;


		// check for a sub entry that has an active value
		if(a[tarr])
		{
			for(var i=0;i<a[tarr][6].length;i++)
				{
					for(var j=0;j<a[tarr][6][i][5].length;j++)
					 	{
							if((a[tarr][6][i][5][j] == activeEntry) || ((a[tarr][6][i][4]) == parseInt(activeEntry.slice(1,activeEntry.length))))
								{
									return true;
								}
							else if ((a[a[tarr][6][i][5][j]]) && (a[tarr][6][i][5][j] != aarr) && (!isNaN(parseInt(a[tarr][6][i][5][j].slice(1,a[tarr][6][i][5][j].length)))))
								{
									// temporarily exit routine if a submenue is found. after that, return
									if (parseInt(a[tarr][6][i][5][j].slice(1,a[tarr][6][i][5][j].length)) > aarr)
										{
											if(checkForActiveLM(parseInt(a[tarr][6][i][5][j].slice(1,a[tarr][6][i][5][j].length)))) return true;
										}
								}
						}
				}
		}
	}
	
function getTableMainLM(arr)
	{
		var out = '', t;
		var tarr= 't' + arr;
		var tableMainSubContent = '';

				if(debug) {
					t=b[tarr][3] + ' ' + b[tarr][0];
				}
				else {
					t=b[tarr][0];
				}

			// looking for submenu / creating submenu
			if((active != "matched") && (b[tarr][2]!=1))
			 	{
					// checking for any active entries in the menu and if found start writing and getting the entries
					if(checkForActiveLM(arr))
						{
							var tableMainSubContent = getTableMainSubLM(arr,0)
							active = "matched";
						}
				} 
			else if(active == "matched")
				{
					//do nothing
				}
			else
				{
					// its a main page and therefor we only have to write second level links
					var tableMainSubContent = getTableMainSubLM(arr,1)
					active = "matched";
				}

			
			// creating a main menu entry
			maintableheight+=mheight1;
			if(b[tarr][2]==1)
				{
					// active
					out += '<tr><td id="tabt'+b[tarr][3]+'" align="left" valign="middle" height="20" class="mainmenuover" style="cursor:pointer;cursor:hand;"'
					out += ' onMouseOver="showLayers(' + ca(b[tarr][4]) + ');clearPath(true);writePath(' + b[tarr][3] + ',1,' + b[tarr][3] + ',1);" onMouseOut="hideLayers(' + ca(b[tarr][4]) + ')" onClick="document.location.href=\''+b[tarr][1]+'\';"'
					out += '><img src="/images/spacer.gif" width="15" height="1" alt="" border="0">'
					out += t
					out += '</td></tr>';

					out += '<tr><td height="1" id="tabta'+b[tarr][3]+'" class="mainmenuout" style="cursor:pointer;cursor:hand;" '
					out += 'onMouseOver="clearPath(true);writePath(' + b[tarr][3] + ',1,' + b[tarr][3] + ',1);" onClick="document.location.href=\''+b[tarr][1]+'\';"'
					out += '>'
					out += '<img src="/images/menu_dottedline.gif" width="179" height="1" alt="" border="0">'
					out += '</td></tr>';
				}
				// next step does show the path to the whole page
				// with a different colour than the active page
				/*else if(tableMainSubContent.length>0)
				{
					// active subentry
					out += '<tr><td id="tabt'+b[tarr][3]+'" align="left" valign="middle" height="20" class="mainmenusel" style="cursor:pointer;cursor:hand;"'
					out += ' onMouseOver="showLayers(' + ca(b[tarr][4]) + ');clearPath(true);writePath(' + b[tarr][3] + ',1,' + b[tarr][3] + ',1);" onMouseOut="hideLayers(' + ca(b[tarr][4]) + ')" onClick="document.location.href=\''+b[tarr][1]+'\';"'
					out += '><img src="/images/spacer.gif" width="15" height="1" alt="" border="0">'
					out += t
					out += '</td></tr>';
				}*/
			else
				{
					// inactive
					out += '<tr><td id="tabt'+b[tarr][3]+'" align="left" valign="middle" height="20" class="mainmenuout" style="cursor:pointer;cursor:hand;"'
					out += 'onMouseOver="showLayers(' + ca(b[tarr][4]) + ');clearPath(true);writePath(' + b[tarr][3] + ',1,' + b[tarr][3] + ',1);this.className=\'mainmenuover\'" onMouseOut="hideLayers(' + ca(b[tarr][4]) + ')" onClick="document.location.href=\''+b[tarr][1]+'\';this.className=\'mainmenuout\';"'
					out += '><img src="/images/spacer.gif" width="15" height="1" alt="" border="0">'
					out += t
					out += '</td></tr>';

					out += '<tr><td height="1" class="mainmenuout" style="cursor:pointer;cursor:hand;">'
					out += '<img src="/images/menu_dottedline.gif" width="179" height="1" alt="" border="0">'
					out += '</td></tr>';
				}

			
			if(tableMainSubContent.length>0)
				{
					out += '<tr>';
						out += '<td colspan="3" class="mediumsize">';
							out += '<table border="0" cellpadding="0" cellspacing="0" width="179"><tr><td class="mediumsize">';
								out += tableMainSubContent;
							out += '</td></tr></table>';
						out += '</td>';
					out += '</tr>';
					out += '<tr><td height="1" class="mainmenuout" style="cursor:pointer;cursor:hand;"><a href="javascript:void(0)"><img src="/images/menu_dottedline.gif" width="179" height="1" alt="" border="0"></a></td></tr>';
				}
				
		return out;
	}
	

// function for writing the menues under the main link 
function getTableMainSubLM(arr,action)
	{
		var out = '';
		var levelSubstractor = 15;
		var tarr = 't' + arr;
		var tempArr = tarr;
		if(action==0)
			{
				// writeing the sub menu under the main entry with levels until active entry level
				for(var elem in a) {
					{
						for(var j = 0; j<a[elem][6].length; j++)
							{
								if(a[elem][6][j][4] == parseInt(activeEntry.slice(1,activeEntry.length)))
									{
										createTableMainSubTempArrLM(a[elem][6][j][8],a[elem][0])
										var maxLevel = a[elem][6][j][8]
									}
							}
						}
					}
				
				for(var i=0;i<aTemp.length;i++)
					{
						if(aTemp[i][2] == 1)
							{
								tarr = 't' + aTemp[i][0]
								if(a[tarr])
									{
										for(var k=0;k<a[tarr][6].length;k++)
											{
												aTemp[aTemp.length] = new Array(a[tarr][6][k][4],a[tarr][6][k][8],a[tarr][6][k][2],a[tarr][6][k][0],a[tarr][6][k][1],a[tarr][6][k][3]);
											}
									}
							}
					}
			}
		else if(action==1)
			{
				// writeing a sub menu under the main entry if main entry is active page
				if(a[tarr])
					{	
						for(var i=0;i<a[tarr][6].length;i++)
							{
								aTemp[aTemp.length] = new Array(a[tarr][6][i][4],a[tarr][6][i][8],a[tarr][6][i][2],a[tarr][6][i][0],a[tarr][6][i][1],a[tarr][6][i][3]);
							}
					}
			}
		
		aTemp.sort(sortNumericLM);
		
		
		
		/*var alertMsg = ''
		for(i=0;i<aTemp.length;i++)
			{
				alertMsg += aTemp[i][0] + " - " + aTemp[i][1] + " - " + aTemp[i][2] + " - " + aTemp[i][3] + " - " + aTemp[i][4] + " - " + aTemp[i][5] + "\n";
			}
		alert(alertMsg);*/
		
		// creating the submenu entries for the table


		for(var k=0;k<aTemp.length;k++)
			{
				maintableheight+=mheight2;
				// checking wether having to write a sub menu under the active entry (if there is any)
				// and setting sub entries path to active. also decomment path steps in
				// menuwriting functions...
				/*if((k+1) < aTemp.length)
					{
						if((aTemp[(k+1)][1]>aTemp[k][1]) && (aTemp[k][1] < maxLevel))
							 {
							 	aTemp[k][2] = 1;									
									for(var elem in a) {
										{
											for(var l = 0; l<a[elem][6].length; l++)
												{
													if(a[elem][6][l][4] == aTemp[k][0])
														{
															a[elem][6][l][2] = 1;
														}
												}
											}
										}
							 }
					}*/
				 
				if(aTemp[k][2]==0)
					{
						// inactive
						var actionTR = '<tr class="submenudownout" style="cursor:pointer;cursor:hand;" onClick="document.location.href=\'' + aTemp[k][4] + '\';"';
						if (aTemp[k][5]==1)
						 	{
								actionTR += ' onMouseOver="changeArrowDown(\''+aTemp[k][0]+'\',1);this.className=\'submenudownover\';" onMouseOut="changeArrowDown(\''+aTemp[k][0]+'\',0);this.className=\'submenudownout\';"'
							}
						else
							{
								actionTR += ' onMouseOver="this.className=\'submenudownover\';" onMouseOut="this.className=\'submenudownout\';"'
							}
						actionTR += '>'
						var sclass="LMKinactive"
						var imageType = "Out"
					}
				// next step does show the path to the whole page
				// with a different colour than the active page
				/*else if((aTemp[k][2]==1) && (aTemp[k][1]<maxLevel))
					{
						// active
						var actionTR = '<tr class="submenudownsel" style="cursor:pointer;cursor:hand;" onClick="document.location.href=\'' + aTemp[k][4] + '\';">';
					}*/			
				else
					{
						// active
						var actionTR = '<tr class="submenudownover" style="cursor:pointer;cursor:hand;" onClick="document.location.href=\'' + aTemp[k][4] + '\';">';
						var sclass="LMKactive";
						var imageType = "Over"
					}
					
					if (aTemp[k][5]==1)
						{
							out += '<table cellspacing="0" cellpadding="0" width="179" border="0">'+ actionTR +'<td width="' + (20+((aTemp[k][1]-2)*levelSubstractor)) + '"><img src="/images/spacer.gif" height="1" width="' + (20+((aTemp[k][1]-2)*levelSubstractor)) + '"></td><td class="mediumsize" align="left" valign="top" width="' + (172 - (aTemp[k][1]*levelSubstractor)) + '">'
							out += aTemp[k][3]
							out += '</td><td class="mediumsize" width="10" align="left" valign="top"><img src="' + navImgPath + '/submenu_arrow' + imageType + '_down2.gif" width="7" height="15" alt="" border="0" name="mi'+aTemp[k][0]+'"></td></tr>';
							out += '<tr><td colspan="3" height="1"><img src="/images/spacer.gif" width="10" height="1" alt="" border="0"></td></tr></table>';
						}
					else
						{
							out += '<table cellspacing="0" cellpadding="0" width="179" border="0">'+ actionTR +'<td width="' + (20+((aTemp[k][1]-2)*levelSubstractor)) + '"><img src="/images/spacer.gif" height="1" width="' + (20+((aTemp[k][1]-2)*levelSubstractor)) + '"></td><td class="mediumsize" align="left" valign="top" height="15" width="' + (172 - (aTemp[k][1]*levelSubstractor)) + '">'
							out += aTemp[k][3]
							out += '</td><td class="mediumsize" width="10" align="left" valign="top"><img src="/images/spacer.gif" width="7" height="15" alt="" border="0"></td></tr>';
							out += '<tr><td colspan="3" height="1"><img src="/images/spacer.gif" width="10" height="1" alt="" border="0"></td></tr></table>';
						}
			}
		return out;
	}

// filling the temp array with entries for sub menu
function createTableMainSubTempArrLM(maxLevel,arrId)
	{
		var tarr = arrId;
		
		
		for(var i=0;i<a[tarr][6].length;i++)
			{
				aTemp[aTemp.length] = new Array(a[tarr][6][i][4],a[tarr][6][i][8],a[tarr][6][i][2],a[tarr][6][i][0],a[tarr][6][i][1],a[tarr][6][i][3]);
			}
		
		if(maxLevel>2)
			{	
				// starting from top-most level counting down until level 2
				getEntriesLM(maxLevel,arrId)
			} 
		else
			{
				return aTemp
			}
	}
	
// getting the entries
function getEntriesLM(maxLevel,arrId)
	{
		for(var elem in a)
			{
				for(var i = 0; i<a[elem][6].length; i++)
					{
						for(var j = 0; j<a[elem][6][i][5].length; j++)
							{
								if((a[elem][6][i][5][j] == arrId) && (a[elem][6][i][8] == maxLevel-1))
									{
										createTableMainSubTempArrLM(a[elem][6][i][8],a[elem][0])
									}
							}
					}
			}
	}
	
// sorting the temporary array by the order ids of the entry
function sortNumericLM(a,b)
	{
		a = a[0]
		b = b[0]
		
		if (a > b)
			{
			return 1;
			}
		else if (a < b)
			{
			return -1;
			}
		else
			{
			return 0;
			}
	}
	

