//this function  (openWindow) is used by commercial Directory//

 
function MenuItem(id,group){
this.ChildGroup = null;
this.ID = id;

this.ParentGroup = group;
this.Container = document.getElementById(id);
this.Selected = (this.Container.getAttribute("selected")=="True");
this.CustomID = this.Container.getAttribute("CustomID");
//alert(this.CustomID);
//alert(this.Selected);
if(this.Selected) {
	//alert("1");
	var pItem;
for(pItem=this.ParentGroup.ParentItem;pItem!=null;pItem=pItem.ParentGroup.ParentItem){ 
		//alert("2");
		pItem.Selected = true;
		pItem.Highlight();
	} 
  }
}

MenuItem.prototype.Show = function(){ 
this.style.visibility = 'visible';
this.style.display = 'block';
this.Visible = true;
}
 
MenuItem.prototype.Hide = function(){
this.style.visibility = 'hidden';
this.style.display = 'none';
}
MenuItem.prototype.Highlight = function(){ 
//alert(this.Container.getAttribute("cssOver"));
this.Container.className = this.Container.getAttribute("cssOver");

}
MenuItem.prototype.UnHighlight = function(){ 
if(!this.Selected){ 
this.Container.className = this.Container.getAttribute("css");
}
//alert(this.Container.getAttribute("css"));
//if(this.Container.id=="CategoryMenu1_item_1099")
//alert(this.Container.css); 
}
 
MenuItem.prototype.DoSelect = function(){
//document.forms[0].m.value += "calling DoSelect on " + this.ID +"\n";
//this.PassOverState = false;
	if(this.ChildGroup != null)
		 if(this.ChildGroup.HideTID){ 
			 //document.forms[0].m.value += " clearing " + this.ChildGroup.ID + "\n";
			clearTimeout(this.ChildGroup.HideTID);
			this.ChildGroup.HideTID = 0;
		}
	 
	if(this.ParentGroup.HideTID){ 
		//document.forms[0].m.value += " clearing " + this.ParentGroup.ID + "\n";
		clearTimeout(this.ParentGroup.HideTID);
		this.ParentGroup.HideTID = 0;	
	}
	
	if (this.ParentGroup.ParentItem != null)
	{
		var parentGroup = this.ParentGroup.ParentItem.ParentGroup;
		if (parentGroup.HideTID)
		{
			clearTimeout(parentGroup.HideTID);
			parentGroup.HideTID = 0;
			
		}
		this.ParentGroup.ParentItem.Highlight();
		//this.ParentGroup.ParentItem.Container.className = "MenuItemOver";

	}
	this.ParentGroup.HideChildGroups();
	for(i=0;i<this.ParentGroup.Items.length;i++)
	{
	 if(this.ParentGroup.Items[i]!=this)
	 this.ParentGroup.Items[i].UnHighlight();//.Container.className = "MenuItem";
	
	
	}
	
	/*if (!this.Selected)// && (!this.Disabled))
	{
		
		this.Selected = true;
		//if (this.ParentGroup.ParentMenu.LastSelectedItem != null)
			//if (this.ParentGroup.ParentMenu.LastSelectedItem != this)
			//	this.ParentGroup.ParentMenu.LastSelectedItem.UnSelectUnconditional();
		//this.Highlight();		
		this.ParentGroup.ParentMenu.LastSelectedItem = this;		
	}*/



} 
function MenuGroup(id){
this.Items = new Array();
this.ID = id;
this.Container = document.getElementById(id);
this.ParentItem = null;
this.ParentMenu = null;
this.Visible = false;
this.HideTID =0;
this.ExpandDirection = "Right";
}
MenuGroup.prototype.getx = function(obj){  
 var curleft =0; 
  if (obj.offsetParent){  
  	while (obj.offsetParent){ 
  		//alert(obj.tagName + " " + obj.id + " " + curleft);
  		//if(obj.id=="table2")
  		//alert("obj.offsetLeft================"+obj.offsetLeft);
  		curleft += obj.offsetLeft;
  		//alert(obj.tagName + " " + obj.id + " " + curleft);
  	 	obj = obj.offsetParent;
  	 } 
  	 //alert(obj.tagName + " " + obj.id + " " + curleft);
  }	
  else if (obj.x)
  {
  
  curleft += obj.x;
  }
  	return curleft;
  }
MenuGroup.prototype.gety = function(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) {	curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; }

MenuGroup.prototype.Show = function(container)
{

//alert(container.id);
//alert(this.Container.id);
if(!this.Visible)
{

//document.forms[0].m.value += "calling Show on " + this.ID +" \n";
//clearTimeout(this.HideTID);
this.Container.style.visibility = 'visible';
if(this.ExpandDirection=="Right")
{
//alert("r");

this.Container.style.left =  this.getx(container)+container.offsetWidth;//this.GroupById.ParentItem.Container.style.left+this.GroupById.ParentItem.Container.clientWidth;
this.Container.style.top = this.gety(container);

}
else
{
//alert(document.body.scrollWidth);
//alert(this.getx(container));
//alert(this.Container.offsetLeft);
//alert((this.getx(container)-this.Container.offsetWidth));
if(this.ParentMenu.Browser=="IE")
{this.Container.style.left = (this.getx(container)-this.Container.offsetWidth);// + 'px';//this.GroupById.ParentItem.Container.style.left+this.GroupById.ParentItem.Container.clientWidth;
}
else
{
	if(this.ParentMenu.Browser=="NS")
	{
		this.Container.style.right = document.body.clientWidth-this.getx(container);
	}
	else 
	{
		this.Container.style.left = this.getx(container)-this.Container.offsetWidth;
	}
//alert(this.getx(container));
//alert(this.Container.offsetWidth);
//alert(this.getx(container)-(this.Container.offsetWidth-this.getx(container)));
//alert(this.getx(container));
//netscape this.Container.style.right = document.body.clientWidth-this.getx(container);
//this works for firefox==>this.Container.style.left = this.getx(container)-this.Container.offsetWidth;
//last used (this.Container.offsetWidth-this.getx(container));
//-this.Container.offsetWidth);//(this.getx(container)-(this.Container.offsetWidth-this.getx(container)));
}
this.Container.style.top = this.gety(container);// + 'px';

}
this.Container.style.visibility = 'visible';
//if(this.ParentMenu.IsOverLaying)
if(this.ParentMenu.Browser=="IE")
{
				if (!document.getElementById(this.ID+'_overlay'))
				{
				document.forms[0].insertAdjacentHTML("beforeEnd","<iframe id='" +this.ID+'_overlay'+ "' src='about:blank' + style='position:absolute;left:0px;top:0x;z-index:500;display:none' scrolling='no' frameborder='0'></iframe>");
				}
				var  overlayFrame = document.getElementById(this.ID+'_overlay');
				overlayFrame.style.top = this.Container.style.top;
				overlayFrame.style.left = this.Container.style.left;
				overlayFrame.style.width = this.Container.offsetWidth;
				overlayFrame.style.height = this.Container.offsetHeight;
				overlayFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
				overlayFrame.style.display = 'block';
				
}
this.ParentMenu.LastSelected = this;
this.Visible = true;
}
//alert(this.Container.getElementsByTagName("table")(1).style.left);
}
MenuGroup.prototype.Hide = function()
{


//document.forms[0].m.value += "trying to call Hide on " + this.ID +" \n";
//clearTimeout(this.ParentItem.HideTID);

eval("currentTid_"+this.ID+" = this;");
this.HideTID = setTimeout("currentTid_"+this.ID+".HideAfterTimeout(true)", this.ParentMenu.GroupDelay);

//}
//else
//{
////document.forms[0].m.value += this.ID +" is invisible \n";
//}
}
MenuGroup.prototype.HideAfterTimeout = function(hideParent)
{
if(this.Visible)
{ 
if(this.ParentMenu.Browser=="IE")
{
//document.forms[0].m.value += "calling Hide on " + this.ID +" \n";this.ID+'_overlay'
var  overlayFrame = document.getElementById(this.ID+'_overlay');
//var  overlayFrame = document.getElementById(this.ParentMenu.RootGroup.ID+'_overlay');
overlayFrame.style.display = 'none';
}
this.Container.style.visibility = 'hidden';
this.Visible = false;
//this.Selected = false;
if(hideParent)
		 this.HideParentGroup();
		 this.HideChildGroups();
}	 

/*if(this.ParentMenu.LastSelectedItem!=null)
   
    //moving from parent item
	if(this.ParentMenu.LastUnSelectedItem.ID==this.ParentItem.ID)
	{   //moving from parent item to group
		if(this.ParentMenu.LastSelectedItem.ParentGroup.ID==this.ID)
		{
		
		}// moving from parent item to outside
		else
		{
		 //document.forms[0].m.value += this.ID +" is visible andto be hidden \n";
		 this.Container.style.visibility = 'hidden';
		 if(this.ParentMenu.LastSelectedItem.ParentGroup.ID!=this.ParentItem.ParentGroup.ID)
		 if(hideParent)
		 this.HideParentGroup();
		 this.HideChildGroups();
		}
		
	}
	//moving from child group to parent item or out side
	else if(this.ParentMenu.LastUnSelectedItem.ParentGroup.ID==this.ID)
	{
			if(this.ParentMenu.LastSelectedItem.ID==this.ParentItem.ID)
			{
				
			}
			else
			{
				//document.forms[0].m.value += this.ID +" is visible andto be hidden \n";
				this.Container.style.visibility = 'hidden';
				if(hideParent)
				this.HideParentGroup();
				this.HideChildGroups();
			}
	}*/

	
}

//this.Container.style.left = this.getx(this.ParentItem.Container)+this.ParentItem.Container.offsetWidth;//this.GroupById.ParentItem.Container.style.left+this.GroupById.ParentItem.Container.clientWidth;
//this.Container.style.top = this.gety(this.ParentItem.Container);

MenuGroup.prototype.HideChildGroups = function()
{
 var i;
 for(i=0;i<this.Items.length;i++)
 {
  if(this.Items[i].ChildGroup!=null)
   this.Items[i].ChildGroup.HideAfterTimeout(false);
 
 }
}
MenuGroup.prototype.HideParentGroup = function()
{
 if(this.ParentItem!=null)
 {
 eval("currentTid_"+this.ID+" = this;");
 this.ParentItem.UnHighlight();
 this.ParentItem.ParentGroup.HideTID = setTimeout("currentTid_"+this.ID+".ParentItem.ParentGroup.HideAfterTimeout(true)", this.ParentMenu.GroupDelay);
}
	//this.ParentItem.ParentGroup.HideTimeoutId = window.setTimeout(this.ID + "_callBack.ParentItem.ParentGroup.HideTimeout(true);", this.ParentMenu.GroupHideDelay);
	/*var i;
 for(i=0;i<this.ParentMenu.Groups.length;i++)
 {
  if(this.IsParentGroup(this.ParentMenu.Groups[i]))
   this.ParentMenu.Groups[i].HideAfterTimeout(true);
 
 }*/
}
/*MenuGroup.prototype.IsChildGroup = function(group)
{
 var childGroup = this;
 while(childGroup.ParentItem!=null)
 {
  childGroup = childGroup.ParentItem.ParentGroup;
  if(parentGroup.ID==group.ID)
  return true;
 }
 return false;
}*/
MenuGroup.prototype.IsParentGroup = function(group)
{
 var parentGroup = this;
 while(parentGroup.ParentItem!=null)
 {
  parentGroup = parentGroup.ParentItem.ParentGroup;
  if(parentGroup.ID==group.ID)
  return true;
 }
 return false;
}
function Menu(rootGroupId)
{

this.Groups = new Array();
this.Items = new Array();
this.RootGroup = new MenuGroup(rootGroupId);
this.RootGroup.ParentMenu = this;
this.RootGroup.ExpandDirection = this.RootGroup.Container.getAttribute("expandDirection");
this.Scrollable = this.RootGroup.Container.getAttribute("scrollable")=="true" ? true : false;
//alert(this.RootGroup.Container.getAttribute("scrollable"));
this.BuildGroups(this.RootGroup);
//alert(this.Groups.length);
//alert(this.RootGroup.Items[3].ChildGroup.ID);
//alert(this.Groups[0].Items[0].ID);
//alert(this.Groups[0].Items[1].ID);
this.GroupDelay = parseInt(this.RootGroup.Container.getAttribute("groupDelay"));
this.GroupById = null;
this.ItemById = null;
this.ItemById = null;
this.LastSelected = null;
this.LastUnSelectedItem =null;
if(this.RootGroup.Container.getAttribute("isOverLaying")=="true")
this.IsOverLaying = true;
else
this.IsOverLaying = false;
this.Browser = "Gecko";
if (navigator.appName == "Microsoft Internet Explorer")
{
	//if (navigator.appVersion.indexOf("MSIE 5.5") > 0 || navigator.appVersion.indexOf("MSIE 6") > 0)
			this.Browser = "IE";//"IE6"
}
else if (navigator.appName.indexOf("Netscape")>=0)
{
	//if (navigator.appVersion.indexOf("MSIE 5.5") > 0 || navigator.appVersion.indexOf("MSIE 6") > 0)
			this.Browser = "NS";//"IE6"
}

}

Menu.prototype.DoScroll= function(group,dir)
{
this.GetGroup(this.RootGroup,group);
this.GroupById.DoScroll(dir);
}

MenuGroup.prototype.DoScroll= function(dir)
{
	if(this.ParentItem.ParentGroup!=null)
	{
		if(this.ParentItem.ParentGroup.HideTID)
			clearTimeout(this.ParentItem.ParentGroup.HideTID);
		if(this.HideTID)
			clearTimeout(this.HideTID);
			this.HideTID = 0;
	}
			
eval("currentScrlID_"+this.ID+" = this;");
this.ScrlID = setTimeout("currentScrlID_"+this.ID+".DoScrollTimeout('" + dir + "')", 53);
}

MenuGroup.prototype.DoScrollTimeout = function(dir)
{	
	var scrli = document.getElementById(this.ID + "scrli");
	var scrlitop = parseInt(scrli.style.top.replace("px",""));
	if(dir=="u")
	{
		if(scrlitop<0)
			scrlitop++;
		else
		this.StopScroll();
		
	}
	if(dir=="d")
	{ 
		if((scrlitop+20)<scrli.offsetHeight)
			scrlitop--;
		else
		this.StopScroll();
	}
	scrli.style.top = scrlitop +"px"; 
	eval("currentScrlID_"+this.ID+" = this;");
	this.ScrlID = setTimeout("currentScrlID_"+this.ID+".DoScrollTimeout('" + dir + "')", 23); 
	
}

MenuGroup.prototype.StopScroll = function()
{	
	clearTimeout(this.ScrlID);
	this.ScrlID= 0;
}
Menu.prototype.StopScroll = function(group)
{	
	this.GetGroup(this.RootGroup,group);
	this.GroupById.StopScroll();
}

Menu.prototype.BuildGroups = function(group)
{
//alert("group.ID=" + group.ID);
var items = document.getElementById(group.ID).getElementsByTagName("table");
var i;
var i_;
var n;
if(group==this.RootGroup)
	{
		i_= 1;
		n=items.length;
	}
	else
	{
		
		if(this.Scrollable)
		{ 
				i_=2;
				n=items.length-1;
		}
		else
		{
				i_ = 1;
				n=items.length;
		}
	}
var newGroup;

for(i=i_;i<n;i++)
{
	//if(group!=this.RootGroup)
	//alert("start "+items[i].id);
var newItem = new MenuItem(items[i].id,group);
	
	if(items[i].getAttribute("childGroup") != null && items[i].getAttribute("childGroup")!="")
		{
		
		 //alert("items[" + i +"].id=" + items[i].id);
		 newGroup  = new MenuGroup(items[i].getAttribute("childGroup"));
		 newGroup.ParentItem = newItem;
		 newGroup.ParentMenu = this;
		 newGroup.ExpandDirection = newGroup.Container.getAttribute("expandDirection");
		 //alert(newItem.ID + " is the parent item of the group " + newGroup.ID + " ");
		 this.Groups[this.Groups.length] = newGroup;
		 //alert("newGroup.ID="+ newGroup.ID);
		 this.BuildGroups(newGroup);
		 newItem.ChildGroup = newGroup;
		 
		}
	//if(group!=this.RootGroup)
	//	alert("end "+items[i].id);
	group.Items[group.Items.length] = newItem;
	
}
//alert(this);
}


Menu.prototype.Click = function(item,e)
{
//this.GetItem(this.RootGroup,item.id);
if(item.getAttribute("clickHref")!="")
{
//if(item.getAttribute("clickHref").indexOf("?")>=0)
window.location = item.getAttribute("clickHref");// + "&menuItemId="+this.ItemById.CustomID;
//else
//window.location = item.getAttribute("clickHref");//+ "?menuItemId="+this.ItemById.CustomID;
}
}
Menu.prototype.Over = function(object)
{
//object.className = "MenuItemOver";
//if(object.id!='Menu1_i3')
////document.forms[0].m.value += event.srcElement.tagName + " is over";
//window.status = "over";
this.GetItem(this.RootGroup,object.id);
//this.GetGroup(this.RootGroup,object.id);
//if(!this.ItemById.Selected)
//{
//this.ItemById.Selected = true;
this.LastSelectedItem = this.ItemById;
this.LastSelectedGroup = this.ItemById.ParentGroup;
//}
//alert(this.ItemById.ID);
//alert(this.ItemById.ChildGroup.ID);
//alert(this.RootGroup==this.ItemById.ParentGroup);
//eval("current_select"+this.ItemById.ID+" = this.ItemById;");
//this.tid = setTimeout("current_select"+this.ItemById.ID+".DoSelect()", 10);
this.ItemById.Highlight();
this.ItemById.DoSelect();
}
Menu.prototype.Out = function(object)
{
//document.forms[0].m.value += "Out on " + object.id +"\n";
//object.className = "MenuItem";
///if(object.id=='Menu1_1_i0')
//document.forms[0].m.value += event.toElement.tagName + " is out \n";
////document.forms[0].m.value = object.id;
//window.status = "out";
this.GetItem(this.RootGroup,object.id);
//this.ItemById.Selected = false;
this.LastUnSelectedItem = this.ItemById;
this.ItemById.UnHighlight();
//}
//this.GetGroup(this.RootGroup,object.id);

//this.LastSelectedGroup = this.ItemById.ParentGroup;
}
Menu.prototype.ShowGroup = function(container,id)
{
//clearTimeout(this.tid);
//window.status = "ShowGroup";
this.GetGroup(this.RootGroup,id);
//eval("currentTid_"+this.ID+" = this;");
//eval("currentTid_cont_"+this.ID+" = container;");
//this.GroupById.HideTID = setTimeout("currentTid_"+this.ID+".GroupById.Show("currentTid_cont_"+this.ID+")", this.GroupDelay);
this.GroupById.Show(container);
////document.forms[0].m.value = //document.forms[0].m.value + id + "=again ";

if(id=='Menu1_1')
	{
		//alert("="+this.GroupById.ID);
		//alert("="+this.GroupById.Container.id);
	
	}
}
Menu.prototype.HideGroup = function(group,id)
{
this.GetGroup(this.RootGroup,id);
this.GroupById.Hide();
//this.GetGroup(this.RootGroup,id);
//this.GroupById.Container.style.visibility = 'visible';
}
Menu.prototype.GetItem = function(group,id)
{
 var i;
 //if(item.ID=id)
 //this.ItemById = item;
for(i=0;i<group.Items.length;i++)
{
 if(group.Items[i].ID==id)
 {
 this.ItemById = group.Items[i];
 //alert(id + "="+ i + "=" + group.Items[i].ID + " " + group.Items[i].ParentGroup.ID);
 }
 if(group.Items[i].ChildGroup != null)
 {
 //alert("yes");
 this.GetItem(group.Items[i].ChildGroup,id);
 }
}




}

Menu.prototype.GetGroup = function(group,id)
{
var i;
if (group.ID == id) 
{
this.GroupById = group;
////document.forms[0].m.value = //document.forms[0].m.value + group.ID  +"="+id;
}
for (i=0;i<group.Items.length; i++)
{
	////document.forms[0].m.value = //document.forms[0].m.value + group.Items[i].ID;
	if (group.Items[i].ChildGroup != null)
	{
		////document.forms[0].m.value = //document.forms[0].m.value + group.Items[i].ChildGroup.ID;
		this.GetGroup(group.Items[i].ChildGroup,id);
	}
}
}
Menu.prototype.Show = function()
{

alert("show");
}
function KeyPress()
{
 //document.forms[0].m.value = "";

}
