// JavaScript Document
var int = 0;
var ii = 0;
var jj = 0;
var kk = 0;
var mm = 0;
var div_id = 1200;
var menu = "";
var menu_arr = new Array ();
var padding = 15;

function heading(uid, type, data) {
	this.uid = uid;
	this.type = type;
	this.heading = data+"<div class='side_menu_underline'></div>";
}
function add_s_menu(curr_item) 
{
	curr_item.s_arr =  new Array ();
}

function menu_item(uid, indent, type, string, menu_link, parent)
{	
	this.indent = indent;
	this.uid = uid;
	this.menu_link = menu_link;
	this.string = string;
	this.type = type;
	this.parent = parent;
	this.opened = false;
	this.indent = indent;
	this.container_div = this.uid+"_div";
	this.underline_div = this.uid+"_un_div"
	this.selected = false;
	if (this.uid == page_id)
	{
		this.selected = true;
		if (this.type == "drop_down")
		{
			this.opened = true;
		}		
		var p = this.parent;
		while (p != null)
		{
			p.opened = true;
			p = p.parent;
		}
	}		
	
	this.menu_item = "<div id='"+this.uid+"_div' class='menu_item_div'><h6><a id='"+uid+"' class='menu_link' onmouseover=\"menu_item_rollover(\'"+this.container_div+"\', "+this.selected+")\" onmouseout=\"menu_item_rolloff(\'"+this.container_div+"\', "+this.selected+")\" href='"+menu_link+"'>"+string+"</a></h6></div><div id=\""+this.underline_div+"\" class=\"side_menu_underline\"></div>";	
}

////BUILD MENU
function build_menu(menu_arr)
{
	var i;
	for ( i = 0; i < menu_arr.length; i++)
	{
		var divtag = "<div id='"+div_id+"'>";
		menu_arr[i].div_id = div_id;
		div_id++;
		
		if (menu_arr[i].heading != undefined)
		{
			menu=menu+menu_arr[i].heading;
		}
		else if (menu_arr[i].s_arr != undefined)
		{
			menu=menu+divtag+menu_arr[i].menu_item+"</div>";
			build_menu(menu_arr[i].s_arr);
		}
		else 
		{
			menu=menu+divtag+menu_arr[i].menu_item+"</div>";
		}
	}
}

///EXPAND SELECTED
/// After the menu has been instantiated
function init_expand(menu_arr)
{
	var i;
	for (i=0 ; i < menu_arr.length; i++)
	{
		if (menu_arr[i].s_arr != undefined)	
		{
			if (menu_arr[i].opened == true)
			{	
				var x;
				for (x = 0; x < menu_arr[i].s_arr.length; x++)
				{
					document.getElementById(menu_arr[i].s_arr[x].div_id).className="visible";		
					document.getElementById(menu_arr[i].s_arr[x].container_div).style.marginLeft = (padding*menu_arr[i].s_arr[x].indent)+"px";	
					document.getElementById(menu_arr[i].s_arr[x].underline_div).style.marginLeft = (padding*menu_arr[i].s_arr[x].indent)+"px";					 
				}			
			}
			else
			{
				var x;
				for (x = 0; x < menu_arr[i].s_arr.length; x++)
				{
					 document.getElementById(menu_arr[i].s_arr[x].div_id).className="invisible";					 
				}			
			}
			init_expand(menu_arr[i].s_arr);
		}
	}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	var j;
	var i;
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
///////////////////////-----------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\
///// There are 3 types of items that can be produced from this menu creator. Headings, menu items, and sub menu items. You would use a heading for a custom image or anything that has unique code. 
// Menu items and sub menu items are what make the menu work, you cannot have a submenu without first having a menu item and adding a submenu to it. 
//EXAMPLE//////   menu_arr[ii] = new menu_item("UID", "TYPE", "NAME", "URL");
// the uid is a unique number or string that should be set at the beginning of any page that has a menu, as in "var init = "WhateverYouWant" 
/// TYPe is only relevent if there is a submenu attached to a menu item, That parent menu_arr[ii] should be set to drop_down, in all other cases it is just for reference
//// NAME is the actual text as it will appear on the page.
/////URL is where it will link to, in this case since this can and will be attached to files in different levels of the site, it will be a good idea to always use an absolute path
///////////////////////-----------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\
//// THE ELEMENTS TO CREATE GO HERE


function initialize_menu()
{
menu_arr[ii++] = new heading("0", "header", "<div align='center'><p><a href='http://www.formz.com/products/formz.html'><img src='http://www.formz.com/images/formzSM.png' width='130' height='41' border='0' /></a></p></div>");

menu_arr[ii++] = new menu_item("features", 0,"menu_item", "Features", "http://www.formz.com/products/formz/formzFeatures.php", null);

menu_arr[ii] = new menu_item("documentation", 0,"menu_item", "Documentation", "http://www.formz.com/products/formz/formzDocumentation.html", null);
	add_s_menu(menu_arr[ii]);
	/////////SUBMENU ITEMS
	menu_arr[ii].s_arr[jj++] = new menu_item("english", 1,"menu_item", "English", "http://www.formz.com/products/formz/formzDocumentation.html", menu_arr[ii]);
	menu_arr[ii].s_arr[jj++] = new menu_item("deutsch", 1,"menu_item", "Deutsch", "http://www.formz.com/products/formz/formzDocumentation_Deutsch.html", menu_arr[ii]);
ii++;
jj=0;

menu_arr[ii++] = new menu_item("trial", 0, "menu_item", "Demo Version", "http://www.formz.com/products/formz/formzTrial.html", null);
menu_arr[ii++] = new menu_item("training", 0,"menu_item", "Training", "http://www.formz.com/products/formz/formzTraining.html", null);
menu_arr[ii++] = new menu_item("purchase", 0,"menu_item", "Purchase", "http://www.formz.com/products/formz/formzSales.html", null);
menu_arr[ii] = new menu_item("videos", 0,"menu_item", "Videos", "http://www.formz.com/products/formz/formzVideo_320.php?startMovie=formZ_intro_p1", null);
	add_s_menu(menu_arr[ii]);
	menu_arr[ii].s_arr[jj++] = new menu_item("video_small", 1,"menu_item", "Small", "http://www.formz.com/products/formz/formzVideo_320.php?startMovie=formZ_intro_p1", menu_arr[ii]);
	menu_arr[ii].s_arr[jj++] = new menu_item("video_large", 1,"menu_item", "Large", "http://www.formz.com/products/formz/formzVideo_640.php?startMovie=formZ_intro_p1", menu_arr[ii]);
ii++;
jj=0;

menu_arr[ii++] = new menu_item("virtual_arm", 0,"menu_item", "Virtual Arm Videos", "http://www.formz.com/products/formz/formzVirtualArm_640.php?startMovie=00_intro", null);

menu_arr[ii++] = new menu_item("requirements", 0,"menu_item", "System Requirements", "http://www.formz.com/products/formz/formzSystem.html", null);
menu_arr[ii++] = new menu_item("version_history", 0,"menu_item", "Version History", "http://www.formz.com/products/formz/versionHistory/fz_History.html", null);
menu_arr[ii++] = new menu_item("registration", 0,"menu_item", "Product Registration", "http://www.formz.com/products/formz/formzProductRegistration.html", null);
}

initialize_menu();
build_menu(menu_arr);
menu= menu+"<div id=\"google_translate_element\"></div>";
document.getElementById('mainContent_Menu').innerHTML=menu;
init_expand(menu_arr);



///_______________________________________________________________________\\\
//ADD GOOGLE TRANSLATE
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
 }, 'google_translate_element');
}

document.write ('<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></sc'+'ript>');
///_______________________________________________________________________\\\
/*
function submitChange() 
{

	var google_options = getElementsByClass("goog-te-combo");
	var selected_index = google_options[0].options.selectedIndex;
	langName = google_options[0].options[selected_index].value;
	//googleTranslateElementInit();
	var element = document.getElementById("content_div").innerHTML;
    google.language.translate(element, langName, function(result) 
	{
						alert (element + langName);

		if (!result.error) 
		{
				alert (element + langName);

			element.innerHTML = result.translation;
		}
	});
}
*/

///_______________________________________________________________________\\\
///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\\\


/*function submitChange() 
{
	alert(document.getElementById(':1.targetLanguage').option[1].value);
     //var value = document.getElementById(':1').value;
	// alert(value);
     //var value = document.getElementById('source').value;
 //    google.language.detect(value, detectResult);
     return false;
}*/

function highllght_menu_item(page_id, menu_arr)
{
	var i = 0;
	for ( i = 0; i < menu_arr.length; i ++)
	{
		if (menu_arr[i].uid == page_id)
		{
			document.getElementById(menu_arr[i].uid).className="side_menu_highlight";
			return;
		}
		else if (menu_arr[i].s_arr != undefined)
		{
			for (x = 0; x < menu_arr[i].s_arr.length; x++)
			{
				if (menu_arr[i].s_arr[x].uid == page_id && menu_arr[i].s_arr[x] != undefined)	
				{
					document.getElementById(menu_arr[i].s_arr[x].uid).className="side_menu_highlight";
					return;
				}
			}
			highllght_menu_item(page_id, menu_arr[i].s_arr);
		}
	}
}
highllght_menu_item(page_id, menu_arr);


function menu_item_rollover(div_id, selected)
{
	var id = div_id;
	if (selected == false)
	{
		document.getElementById(id).style.backgroundColor = "#617c9a";
	}
}
function menu_item_rolloff(div_id, selected)
{
	var id = div_id;
	if (selected == false)
	{
		document.getElementById(id).style.backgroundColor = "transparent";
	}
}
/*
+++++++++++++++++++++++++++EXAMPLE+++++++++++++++++ ++++++++

function initialize_menu()
{
menu_arr[ii++] = new heading("0", "header", "<div align='center'><p><a href='http://www.formz.com'><img src='http://www.formz.com/images/renderzoneSM.png' width='130' height='28' border='0' /></a></p></div>");
//alert (menu_arr.length);
///////MENU ITEM
menu_arr[ii++] = new menu_item("1231", 0,"menu_item", "Top1", "http://www.formz.com", null);

//// MENU ITEM WITH SUBMENU 
menu_arr[ii] = new menu_item("1233", 0,"drop_down", "Top2", "http://www.formz.com", null);
	add_s_menu(menu_arr[ii]);
	/////////SUBMENU ITEMS
	menu_arr[ii].s_arr[jj++] = new menu_item("12340", 1,"menu_item", "T2L1_1", "http://www.formz.com", menu_arr[ii]);
	menu_arr[ii].s_arr[jj++] = new menu_item("12355", 1,"menu_item", "T2L1_2", "http://www.formz.com", menu_arr[ii]);
	menu_arr[ii].s_arr[jj++] = new menu_item("123452", 1,"menu_item", "T2L1_3", "http://www.formz.com", menu_arr[ii]);
ii++;
jj=0;

menu_arr[ii] = new menu_item("1213456", 0, "drop_down", "Top3", "http://www.formz.com", null);
	add_s_menu(menu_arr[ii]);
	/////////SUBMENU ITEMS
	menu_arr[ii].s_arr[jj] = new menu_item("3241234", 1,"drop_down", "T3L1_1", "http://www.formz.com", menu_arr[ii]);
		kk = 0;
		add_s_menu(menu_arr[ii].s_arr[jj]);
		menu_arr[ii].s_arr[jj].s_arr[kk++] = new menu_item("44445w", 2,"menu_item", "T3L2_1", "http://www.formz.com", menu_arr[ii].s_arr[jj]);
		menu_arr[ii].s_arr[jj].s_arr[kk++] = new menu_item("4", 2,"menu_item", "T3L2_2", "http://www.formz.com", menu_arr[ii].s_arr[jj]);
		menu_arr[ii].s_arr[jj].s_arr[kk++] = new menu_item("3", 2,"menu_item", "T3L2_3", "http://www.formz.com", menu_arr[ii].s_arr[jj]);
	jj++;
	menu_arr[ii].s_arr[jj++] = new menu_item("33", 1,"menu_item", "T3L1_2", "http://www.formz.com", menu_arr[ii]);
	menu_arr[ii].s_arr[jj] = new menu_item("0435", 1,"drop_down", "T3L1_3", "http://www.formz.com", menu_arr[ii]);
		kk = 0;
		add_s_menu(menu_arr[ii].s_arr[jj]);
		menu_arr[ii].s_arr[jj].s_arr[kk++] = new menu_item("2", 2,"menu_item", "T3L2_4", "http://www.formz.com", menu_arr[ii].s_arr[jj]);
		menu_arr[ii].s_arr[jj].s_arr[kk++] = new menu_item("165346465", 2,"menu_item", "T3L2_5", "http://www.formz.com", menu_arr[ii].s_arr[jj]);	
	jj++;
ii++;
jj=0;
menu_arr[ii++] = new menu_item("2234234", 0,"menu_item", "Top4", "http://www.formz.com", null);
}*/

/// HIGHLIGHTS THE INITIAL SELECTED menu item

