var tmr;

function CreateMenu(){
	var mnuParent = document.getElementById("tdMainMenu");
	var mnuItm;	
	
	for(var i = 0; i < mnuItms.length; i++){
		mnuItm = document.createElement("div");
		mnuItm.id = "mnuItm" + i;
		if(mnuItms[i][1].length == 0){
			mnuItm.innerHTML = "<img src='images/MenuBorder.jpg' border=0/><br><div onclick='MenuClicked(this);' class='MenuSpan'>" + mnuItms[i][0] + "</div>";
		}
		else{
			var img = "";
			if(document.dir == "rtl"){
				img = "ar";
			}
			mnuItm.innerHTML = "<img src='images/MenuBorder.jpg' border=0/><br><div onclick='MenuClicked(this);' class='MenuSpan'>" + mnuItms[i][0] + "</div>";
		}
		
		if(mnuItms[i][1].length == 0){
			mnuItm.childNodes[2].onclick = function(){
				var indx = event.srcElement.parentElement.id.replace("mnuItm", "");
				window.location = mnuItms[indx][2];
			}
		}
		mnuParent.appendChild(mnuItm);
	}	
}

function MenuClicked(obj){
	if(obj.parentElement.id.search("mnuItm") == -1){ //Clicked right object
		return;
	}
	if(obj.parentElement.children.length == 3){ //Not Shown
		HideSubMnu(obj);   //Hide all menus
		ShowSubMnu(obj);   //Show Clicked menu
	}
	else{
		HideSubMnu(obj);
	}
}

function ShowSubMnu(obj){
	if(obj.parentElement.id.search("mnuItm") == -1){
		return;
	}
	
	var indx = obj.parentElement.id.replace("mnuItm", "");
	if(mnuItms[indx][1].length == 0){
		return;
	}
	
	var subParent = document.createElement("div");
	var subItm;
	var subItmLnk;
	
	subParent.id = "dvSubMnu";
	subParent.style.width = "100%";
	subParent.style.backgroundColor = "#000000";
	subParent.style.border = "0";
	
	for(var i = 0; i < mnuItms[indx][1].length; i++){
		subItm = document.createElement("div");
		subItm.style.height = "25px";
		subItm.style.paddingTop = "6px";
		subItm.style.backgroundColor = "#000000";
		if(document.dir == "ltr"){
		subItm.style.textAlign="left";
		}
		if(document.dir == "rtl"){
		subItm.style.textAlign="right";
		}
		subItm.style.paddingLeft = "5px";
		
		subItmLnk = document.createElement("a");
		subItmLnk.style.fontFamily = "Tahoma";
		subItmLnk.style.fontWeight = "normal";
		subItmLnk.style.fontSize = "11px";
		subItmLnk.style.backgroundColor = "#000000";
		subItmLnk.style.color = "#ffffff";
		subItmLnk.className="Link";
		subItmLnk.href = mnuItms[indx][2][i];
		subItmLnk.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + mnuItms[indx][1][i];
		subItm.appendChild(subItmLnk);
		subParent.appendChild(subItm);
	}
	
	if(obj.childNodes.length > 1){
		obj.childNodes[0].src = "images/MenuBorder.jpg";
	}
	
	obj.parentElement.appendChild(subParent);
}

function HideSubMnu(obj){
	if(obj.parentElement.id.search("mnuItm") == -1){
		return;
	}
	
	if(obj.parentNode.parentElement.children.length > 1){
		var img = "";
		if(document.dir == "rtl"){
			img = "ar";
		}
		obj.parentNode.parentElement.children[0].src = "images/MenuBorder.jpg";
	}
	
	var divSubMnu = document.getElementById("dvSubMnu");
	if(divSubMnu != null){	
		document.getElementById('dvSubMnu').removeNode(true);
	}
}


function popup(popupcompanyfile, winheight, winwidth, Type, Scrollable)
{
		if (winheight==0)
				winheight = screen.availHeight - 100;
		if (winwidth==0)
				winwidth = screen.availWidth - 50;
		var myTop
		var myWidth
		myTop = ((screen.availHeight - winheight)/2) - 25;
		myLeft = (screen.availWidth - winwidth)/2;
		if (Scrollable == 0)
			window.open(popupcompanyfile, Type, "resizable=no,status=no,height=" + winheight + ",width=" + winwidth + ",scrollbars=no, location=no, menubar=no, left=" + myLeft + ", top=" + myTop);
		else
			window.open(popupcompanyfile, Type, "resizable=no,status=no,height=" + winheight + ",width=" + winwidth + ",scrollbars=yes, location=no, menubar=no, left=" + myLeft + ", top=" + myTop);
}
