var menuLevel2Height = 23;
var menuLeve13Height = 23;
var MenuType=1;
var lastChildDivHeight;
var lastParentDivID;
var lastChildDivID;
var Child3ID=-1;
var Parent3ID; 
var SubParent3ID;
var SubNum3;
var expandMove11;
var Level1ID;
var Level1SubNum;
var ThirdLevelIsOpen=false;
var ShowSub3= false
var Ar = new Array() 
var ArParent = new Array() 
var	CurrentLevelAllClose=false
var ArrayIndex =0 
var Current =0
var FromLevel1 = true
var FromLevel2 = false
var ClosePreviousMenuOnOpen = false
var flag=false

function PageSelected()
{
	try
	{
		var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
		var url = location.href.substring(dir.length,location.href.length+1);
		
		if (url.toLowerCase().indexOf("ar_") != -1 || url.toLowerCase().indexOf("fr_") != -1 || url.toLowerCase().indexOf("gr_") != -1 || url.toLowerCase().indexOf("sp_") != -1)
   	        var PageName = url.substring(3,url.lastIndexOf('.'));
		else
		    var PageName = url.substring(0,url.lastIndexOf('.'));
		
		PageName=PageName.toLowerCase();
		document.getElementById("a_"+PageName).className="wpm_menu_level1_select"	
		//document.getElementById("a"+PageName).className="wpm_menu_level1_Select"
		document.getElementById(PageName).className="wpm_menu_level1_over"	
	}
	catch(ex)
	{}
}

function ChangeHieght(ID, Sign, SubNum)
{
	try
	{
		var tempHeight = document.getElementById("div" + ID).style.height.substring(0, document.getElementById("div" + ID).style.height.length - 2);
		if(Sign == '+')
		{
			tempHeight = tempHeight * 1 + 6 * 1;
			document.getElementById("div" + ID).style.height = tempHeight + "px";
			if(tempHeight * 1 < menuLevel2Height * SubNum)
			{
				expandMove = window.setTimeout("ChangeHieght('" + ID + "', '+', " + SubNum + ");", 0.00000000000000000000000000000000000000000000000000000000000000000000000001);
			}
			else
			{
				document.getElementById("div" + ID).style.display = "block";
				if (MenuType==4)
				{
				    document.getElementById("img" + ID).src = "images/wpm_menu_negative2.gif";
				}
				else
				{
				    document.getElementById("img" + ID).src = "images/wpm_menu_negative1.gif";
				}
				
				if(ShowSub3==true)
				{
				    ExpandMenu2(Child3ID, SubNum3,  Parent3ID, SubParent3ID)
				    ShowSub3= false
				}
			 }
		}
		else
		{  
			tempHeight = tempHeight * 1 - 6 * 1;
			document.getElementById("div" + ID).style.height = tempHeight + "px";
			if(tempHeight * 1 > 1)
			{
				expandMove1 = window.setTimeout("ChangeHieght('" + ID + "', '-', " + SubNum + ");", 0.00000000000000000000000000000000000000000000000000000000000000000000000001);	
			}
			else
			{ 
			  document.getElementById("div" + ID).style.display = "none";
			  if (MenuType==4)
				{
				    document.getElementById("img" + ID).src = "images/wpm_menu_positive2.gif";
				}
				else
				{
				    document.getElementById("img" + ID).src = "images/wpm_menu_positive1.gif";
				}
			}
		}
	}
	catch(ex)
	{}
}


function ExpandMenu(ID, SubNum)
{ Level1ID = ID
  Level1SubNum = SubNum
  ThirdLevelIsOpen=false
  FromLevel1=true
  //alert(document.getElementById("div" + ID).style.display)
	try
	{ 
		if(lastChildDivHeight != null && lastChildDivHeight != 0)
		{ if (ClosePreviousMenuOnOpen==true)
		  {
			ExpandMenu2(lastChildDivID.substring(3), lastChildDivHeight / menuLevel2Height,  ID, SubNum)
		  }
			lastChildDivHeight = 0;
			ExpandMenu(ID, SubNum);
		}
		else
		{
			if(lastParentDivID != null && lastParentDivID != "div" + ID)
			{
				if (ClosePreviousMenuOnOpen==true)
				{
					if (document.getElementById(lastParentDivID).style.display == "block")
					{
					    ChangeHieght(lastParentDivID.substring(3), '-', SubNum);
					}
				}
			}
			lastParentDivID = "div" + ID;
			if (document.getElementById("div" + ID).style.display == "block")
			{ 
				if (Child3ID != -1)
				{  
			    	ThirdLevelIsOpen=true;
				    for (i=0;i<Ar.length;i++)
				    { 
				        if (ArParent[i] == ID)
				        {  	
				            FromLevel1 =false
				      	    ChangeHieght2(Ar[i], '-', SubNum3, ID, SubParent3ID)
    			        	for (j=0;j<ArParent.length;j++)
			        	    {
							    if(ArParent[j] != -1) 
							    {
							        ThirdLevelIsOpen =true
							        break;
							    }
						    }
			            }		       
				    } 
			   	}

			  	if (FromLevel1==true)
				{ 
					ChangeHieght(ID, '-', SubNum);
				}
			}
			
			else
			{ 
			    FromLevel1=true
				ChangeHieght(ID, '+', SubNum);
				document.getElementById("div" + ID).style.display = "block";
			}
		}
	}
	
	catch(ex)
	{}
}

function ChangeHieght2(ID, Sign, SubNum, parentID, SubParent)
{
    try
	{ 
		var tempHeight = document.getElementById("div" + ID).style.height.substring(0, document.getElementById("div" + ID).style.height.length - 2);
		var tempParentHeight = document.getElementById("div" + parentID).style.height.substring(0, document.getElementById("div" + parentID).style.height.length - 2);
		if(Sign == '+')
		{  
		    FromLevel1 = false
			tempHeight = tempHeight * 1 + 6 * 1;
			tempParentHeight = tempParentHeight * 1 + 6 * 1
			document.getElementById("div" + ID).style.height = tempHeight + "px";
			document.getElementById("div" + parentID).style.height = tempParentHeight + "px";
			if(tempHeight * 1 < menuLeve13Height * SubNum)
			{
				expandMove21 = window.setTimeout("ChangeHieght2('" + ID + "', '+', " + SubNum + ", '" + parentID + "', '" + SubParent + "');", 0.00000000000000000000000000000000000000000000000000000000000000000000000001);	
			}
			else
			{ 
    			Child3ID = ID
				if (Ar.length>0)
				{  
				    ChildExist=false;
					for (i=0;i<Ar.length;i++)
					{
						if (Ar[i]==Child3ID)
						{
						    Ar[i]=Child3ID
						    ArParent[i]=parentID
						    ChildExist=true
						}
					}
					if (ChildExist==false)
					{
					    Ar[ArrayIndex]=Child3ID
					    ArParent[ArrayIndex]=parentID
					    ArrayIndex =ArrayIndex + 1;
					}
			 }
			 else
			 {
			  Ar[ArrayIndex]=Child3ID
			  ArParent[ArrayIndex]=parentID
			  ArrayIndex =ArrayIndex + 1;
			}
			
			
			
			Parent3ID = parentID
			SubParent3ID = SubParent
		    SubNum3 =SubNum;
			document.getElementById("div" + ID).style.display = "block";
			document.getElementById("img" + ID).src = "images/wpm_menu_negative2.gif";
			}
			lastChildDivHeight = tempHeight;
		}
		else
		{
			tempHeight = tempHeight * 1 - 6 * 1;
			document.getElementById("div" + ID).style.height = tempHeight + "px";
			
			if(tempParentHeight * 1 - 6 * 1 > 2)
			{
				document.getElementById("div" + parentID).style.height = tempParentHeight * 1 - 6 * 1 + "px";
			}
			
			if(tempHeight * 1 > 0)
			{  
			
				expandMove22 = window.setTimeout("ChangeHieght2('" + ID + "', '-', '" + SubNum + "', '" + parentID + "', '" + SubParent + "');",0.00000000000000000000000000000000000000000000000000000000000000000000000001);
				
			}
			else
			{ 
			
		
			
			if (ThirdLevelIsOpen ==true)
			{ 
			
			 Child3ID =ID
			 }
			 else
			 {
			 
			 ThirdLevelIsOpen=false
			Child3ID = -1
			}
			
		   for (i=0;i<Ar.length;i++)
			{
			  if (Ar[i]==ID)
			  {
			  
			  ArParent[i]=-1
			  }
			
			}
			Current=0
			Remind =0
			for (i=0;i<Ar.length;i++)
					{
					
						if (ArParent[i] == Level1ID)
						{
						
						CurrentLevelAllClose=false
						}
						else if (ArParent[i] ==-1)
							{Current += 1
							CurrentLevelAllClose=true
						
							}
						
						else
						{
						Remind +=1
						
						}
					}
			
				  if (CurrentLevelAllClose==true && Current== Ar.length-Remind )
					{ 
					
					  if (FromLevel2==true)
					  {
					  ChangeHieght2(ID, '-', SubNum);
					  FromLevel2=false
					  }
					  else
					  {
					 
					   if (FromLevel1 == false)
					  {
					  FromLevel1==true
					  ChangeHieght(Level1ID, '-', Level1SubNum);
					  
					  }
					 }
					 }
				
						
			  document.getElementById("div" + ID).style.display = "none";
			  document.getElementById("img" + ID).src = "images/wpm_menu_positive2.gif";
				
			}
			
			lastChildDivHeight = 0;
		}
	}
	catch(ex)
	{
	}
}

function ExpandMenu2(ID, SubNum, parentID, SubParent)
{
	try
	{
		if(lastChildDivID != null && lastChildDivID != "div" + ID)
		{if (ClosePreviousMenuOnOpen==true)
		  {
			if (document.getElementById(lastChildDivID).style.display == "block")
			{ 
				ChangeHieght2(lastChildDivID.substring(3), '-', SubNum, parentID, SubParent);
			}
		 }
		}
		lastChildDivID = "div" + ID;

		if (document.getElementById("div" + ID).style.display == "block")
		{  
		    FromLevel2=true
			ChangeHieght2(ID, '-', SubNum, parentID, SubParent);
		}
		else
		{
		 
			ChangeHieght2(ID, '+', SubNum, parentID, SubParent);
			
			document.getElementById("div" + ID).style.display = "block";
		}
		lastChildDivHeight = document.getElementById(lastChildDivID).style.height.substring(0, document.getElementById(lastChildDivID).style.height.length - 2);
		
	}
	catch(ex)
	{
	}
}



function ChangeBGColor(objTD, objIMG)
{ 
	try
	{
	if (objTD.className.indexOf("_over")==-1)
	    {
		    objTD.className += "_over";
		}
	}
	catch(ex)
	{} 
}

function RestoreColor(objTD, objIMG)
{
	try
	{
	   if (objTD.className.indexOf('_over')>0)
	   {
		objTD.className = objTD.className.substring(0, objTD.className.length - 5);
		}
	}
	catch(ex)
	{
	}
}
function ChangeBGColorExpand(objTD, objIMG)
{   document.getElementById(objTD).className += "_over"; 
	try
	{
//	 if (document.getElementById(objTD).className.indexOf('_over')==-1)
//	   {
	   document.getElementById("a_"+ objIMG).className += "_select";
	   //alert(document.getElementById("a_"+objIMG).className);
//	 alert( document.getElementById("a_"+ objIMG).className); 
	 
	document.getElementById(objIMG).className += "_over";
	   
		document.getElementById("TD"+ objIMG).className += "_over";
		document.getElementById("tdsub"+ objIMG).className += "_over";
		  	
		}
//	}
	catch(ex)
	{
	//alert(ex.message)
	} 
	
//  document.getElementById(objTD).className += "_over";
//  //alert(document.getElementById("tdsub"+ objIMG))
//	try
//	{	document.getElementById(objIMG).className += "_over";
//		document.getElementById("TD"+ objIMG).className += "_over";
//		document.getElementById("tdsub"+ objIMG).className += "_over";
//	}
//	catch(ex)
//	{
//	//alert("catch")
//	} 
	
}

function RestoreColorExpand(objTD, objIMG)
{ 
	try
	{
	   if (document.getElementById(objTD).className.indexOf('_over')>0 || document.getElementById("a_"+ objIMG).className.indexOf('_select')>0 )
	   {
		document.getElementById(objTD).className = document.getElementById(objTD).className.substring(0, document.getElementById(objTD).className.length - 5);
		document.getElementById("a_"+ objIMG).className = document.getElementById("a_"+ objIMG).className.substring(0, document.getElementById("a_"+ objIMG).className.length - 7);
		document.getElementById(objIMG).className = document.getElementById(objIMG).className.substring(0, document.getElementById(objIMG).className.length - 5);
		//alert(document.getElementById("a_"+ objIMG).className);
			try
			{
			document.getElementById("TD" + objIMG).className = document.getElementById("TD" + objIMG).className.substring(0, document.getElementById("TD" + objIMG).className.length - 5);
			//document.getElementById("a_" + objIMG).className = document.getElementById("a_" + objIMG).className.substring(0, document.getElementById("a_" + objIMG).className.length - 7);
			document.getElementById("tdsub" + objIMG).className = document.getElementById("tdsub" + objIMG).className.substring(0, document.getElementById("tdsub" + objIMG).className.length - 5);
			}
			catch(ex1)
			{}
		}
	}
	catch(ex)
	{ 
	}
	
	
	
}
function hideMenu(tdID)
{

	document.getElementById(tdID).style.display='none';
}

function showMenu(tdID)
{
	document.getElementById(tdID).style.display='block';
}

function OpenWindow(strFileName, intWidth, intHeight)
{
	window.open(strFileName, '','width=' + intWidth + ', height=' + intHeight + ', scrollbars=no')
}


/****************** ShowSubs *********************************/
	function ShowSubs(parentdivid,parentitemcount,childdivid,childitemcount,tdid)
	{
		try
		{
			if (childdivid=="")
			{
			ExpandMenu(parentdivid,parentitemcount)
		
			}
			else
			{
						
			Child3ID = childdivid
			Parent3ID = parentdivid
			SubParent3ID = parentitemcount
		    SubNum3 =childitemcount;
		    ShowSub3= true
			ExpandMenu(parentdivid,parentitemcount)
						
			}
			
		ChangeBGColorExpand(tdid,tdid.substring(3,tdid.length))
		document.getElementById(tdid).onmouseover="ChangeBGColorExpand(tdid,tdid.substring(3,tdid.length))"
		document.getElementById(tdid).onmouseout="javascript:"
			
		}
		catch(e)
		{}
	
		
}
