 var fullPath = "http://www.virtualunison.org.uk/http";
 var visagePath = "http://www.virtualunison.org.uk";
 /*Full path used in conjunction with checkUrl to remove erroneous urls.*/
 
 
 function printTopMenu() {
    var location = document.getElementById('minorlinksbox');
	
	var data = eval( "(" + menuJSON + ")" );
	var faqsForCategory = data.menuList['MENU'];
	var html = "";

	/* Arrays are 1-based as a blank element must be added to the Atwone section to ensure there isn't a trailing ',' */
     for (var x=1; x < faqsForCategory.length; x++){
        var categoryurl = faqsForCategory[x].url;
		var categoryurl = checkUrl(categoryurl,23);
		
		html += "<a class='minorlinks' href=\"" + visagePath + "/session=" + theSession + "/" + categoryurl + "\">" + faqsForCategory[x].title + "</a><span class='pipe'> | </span>";
    }            
	html += "</ul>";
	location.innerHTML = html;
 }
 
   function printFooterMenu() {
    var location = document.getElementById('mlbfooter');
	
	var data = eval( "(" + bottommenuJSON + ")" );
	var faqsForCategory = data.bottommenuList['BOTTOMMENU'];
	var html = "";

    /* Arrays are 1-based as a blank element must be added to the Atwone section to ensure there isn't a trailing ',' */
    for (var x=1; x < faqsForCategory.length; x++){
        var categoryurl = faqsForCategory[x].url;
		var categoryurl = checkUrl(categoryurl,23);
		
		html += "<a class='minorlinks' href=\"" + visagePath + "/session=" + theSession + "/" + categoryurl + "\">" + faqsForCategory[x].title + "</a><span class='pipe'> | </span>";
    }
    location.innerHTML = html;
 }
 

 
 function checkUrl(theUrl,theSlice) {
 /*Removes full path from links so it is not added twice*/
	if(theUrl.match(fullPath)){
		theUrl = theUrl.slice(theSlice);
	}
	return theUrl;
 }
 
   function checkDirectories(html, theUrl, theTitle, prevUrl) {
	/*For the left hand menu, formats the links and adds them to the html variable.*/
	if (prevUrl) {
		if (prevUrl.match(":void")){
			html += "</div>";
		}
	}	
	categorytitle = theTitle;
	categoryurl = theUrl;		
	var categoryurl = checkUrl(categoryurl,38);
	if(categoryurl.match(":void")) {
		html += "<a href=\""  + categoryurl + "\">" + categorytitle + "</a>";
		html += "<div>";
	}else{
		html += "<a href=\"" + visagePath + "/session=" + theSession + "/" + categoryurl + "\">" + categorytitle + "</a>";
	}	
    return html;
  }

 function printLeftMenu() {
    var location = document.getElementById('qm0');	
	var data = eval( "(" + leftmenuJSON + ")" );
	var faqsForCategory = data.leftmenuList['LEFTMENU'];
	var html = "";
    for (var x=1; x < faqsForCategory.length; x++){
		if (faqsForCategory[x].url) {
			if(faqsForCategory[x-1].suburl5){
				html += "</div></div></div>";
				if (faqsForCategory[x-1].suburl5.match(":void")){
					html += "&nbsp;</div>";
				}
			}else if(faqsForCategory[x-1].suburl4) {
				html += "</div></div>";
				if (faqsForCategory[x-1].suburl4.match(":void")){
					html += "&nbsp;</div>";
				}
			}else if (faqsForCategory[x-1].suburl3) {
				html += "</div>";
				if (faqsForCategory[x-1].suburl3.match(":void")){
					html += "&nbsp;</div>";
				}
			}
			var html = checkDirectories(html, faqsForCategory[x].url, faqsForCategory[x].title, faqsForCategory[x-1].url);
		}else if (faqsForCategory[x].suburl3){
			if(faqsForCategory[x-1].suburl5){
				html += "</div></div>";
			}else if(faqsForCategory[x-1].suburl4) {
				html += "</div>";
			}
		var html = checkDirectories(html, faqsForCategory[x].suburl3, faqsForCategory[x].subtitle3, faqsForCategory[x-1].suburl3);
		}else if (faqsForCategory[x].suburl4){		
			if(faqsForCategory[x-1].suburl5){
				html += "</div>";
			}
		var html = checkDirectories(html, faqsForCategory[x].suburl4, faqsForCategory[x].subtitle4, faqsForCategory[x-1].suburl4);
		}else if (faqsForCategory[x].suburl5){
			var html = checkDirectories(html, faqsForCategory[x].suburl5, faqsForCategory[x].subtitle5, faqsForCategory[x-1].suburl5);
		}else{
			categorytitle = faqsForCategory[x].subtitle;
			categoryurl = faqsForCategory[x].suburl;
			html += "<a href=\"" + categoryurl + "\">" + categorytitle + "</a>"; 
			if(categoryurl.match(":void")) {
				html += "<div>";
			}
		}
	}
    location.innerHTML = html + "</div>";
  }

