// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/menu.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.

var g_PopupIFrame;

function at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- DropDown Control ------------------------------------------------------

var at_timeout = 100;

// ----- Show Aux -----

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p.className        = "active";

  if (c.offsetWidth <= 0)
  {
    c.style.position   = "absolute";
    c.style.visibility = "visible";
    c.style.display    = "block";
  }

  var direction = undefined;
  if (p.parentNode && p.parentNode["at_position"] == "x")
    direction = p.parentNode["at_direction"];

  var top   = (c["at_position"] == "y") ?  p.offsetHeight-2 : 0;
  var left1 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;
  var left2 = (c["at_position"] == "x") ? -c.offsetWidth -2 : 0;
  var left3 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    if (p.style.position != 'absolute')
    {
      left1 += p.offsetLeft;
      left2 += p.offsetLeft;
      top   += p.offsetTop;
    }
    left3 += p.offsetLeft;
  }

  if (direction)
  {
    left = (direction == 'right') ? left1 : left2;
    c['at_direction'] = direction;
  }
  else
  {
    left = (left3+c.offsetWidth < document.body.offsetWidth) ? left1 : left2;
    c['at_direction'] = (left3+c.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }

  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display    = "block";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.zIndex   =2;
}

// ----- Hide Aux -----

function at_hide_aux(parent, child)
{
  document.getElementById(parent).className        = "parent";
  document.getElementById(child ).style.visibility = "hidden";
  document.getElementById(child ).style.display    = "block";
}

// ----- Show -----

function at_show(evt)
{
var e = evt? evt : window.event;
if(!e) return;
var key = 0;
if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
else if (typeof(e.which)!= 'undefined') { key = e.which; } 
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
    p.className        = "active";
  var check = c.getElementsByTagName("a");	
			  // alert(check.length);
			   if(check.length !=0){
  
	  at_show_aux(p.id, c.id);
	 if(key=='40'){
	   var links = c.getElementsByTagName("a");
	   if(links[0] != null)
			links[0].focus();	
			
	   //c.getElementsByTagName("A").focus();
	 }
	 
	  
	  clearTimeout(c["at_timeout"]);
	  
	  // added by P for showing <div> on top of <select>
	  if (IsIE())
	  {
		  if(g_PopupIFrame==null)
			ShowPopupDiv(c.id);
	  }
    }
}

function at_show2(evt)
{
var e = evt? evt : window.event;
if(!e) return;
var key = 0;
if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
else if (typeof(e.which)!= 'undefined') { key = e.which; } 
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child"]);

   var links = p.parentNode.parentNode.parentNode.getElementsByTagName("a");	
		if(key=='39'){		 		
		   for (i = 0; i <links.length; i++) {
				if(links[i].id == this["at_parent"]){					
					if (i >=links.length){
						links[0].focus();	
					}
					else{					
						links[i+1].focus();										
					}
						
				}			
			}   
		 }
		  else if(key=='37'){		 

		   for (i = links.length-1; i >=0; i--) {
				if(links[i].id == this["at_parent"]){
					if (i-1>=0)			
						links[i-1].focus();	
					else
						links[i].focus();							 
					
				}
				
			}   
		 }else  {
		
			 
			   var check = c.getElementsByTagName("a");	
			  // alert(check.length);
			   if(check.length !=0){
			      clearTimeout(c["at_timeout"]);
			  	  at_show_aux(p.id, c.id);
    			  	  
			     if(key=='40'){
			       links = c.getElementsByTagName("a");
			       if(links[0] != null)
					    links[0].focus();	
    					
			       //c.getElementsByTagName("A").focus();
			     }
			      // added by P for showing <div> on top of <select>
			      if (IsIE())
			      {
				      if(g_PopupIFrame==null)
					    ShowPopupDiv(c.id);
			      }
			  }
			  
		}
}

// ----- Hide -----

function at_hide()
{
	
		  var c = document.getElementById(this["at_child"]);

		  c["at_timeout"] = setTimeout("at_hide_aux('"+this["at_parent"]+"', '"+this["at_child" ]+"')", at_timeout);
		  
		  // added by P for showing <div> on top of <select>
		  if (IsIE())
		  {
			if(g_PopupIFrame != null){
				document.body.removeChild(g_PopupIFrame);
				g_PopupIFrame=null;
			}
		  }
	 
}
function at_hide2(evt)
{
var e = evt? evt : window.event;
if(!e) return;
var key = 0;
if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
else if (typeof(e.which)!= 'undefined') { key = e.which; } 
	if(key!='40' && key!='38'  ){
		  var c = document.getElementById(this["at_child"]);
		  var p = document.getElementById(this["at_parent"]);
		  at_hide_aux(this["at_parent"], this["at_child" ]);
		  
		
		
		  // added by P for showing <div> on top of <select>
		  if (IsIE())
		  {
			if(g_PopupIFrame != null){
				document.body.removeChild(g_PopupIFrame);
				g_PopupIFrame=null;
			}
		  }
		  
		/*  if(key=='39'){
		   var links = p.parentNode.getElementsByTagName("a");

		   for (i = 0; i <links.length; i++) {
				if(links[i].id == this["at_parent"]){
					if (i+1<links.length)							
						links[i+1].focus();	
					else
						links[0].focus();	
					
				}			
			}   
		 }
		  else if(key=='37'){
		   var links = p.parentNode.getElementsByTagName("a");

		   for (i = links.length-1; i >=0; i--) {
				if(links[i].id == this["at_parent"]){
					if (i-1>=0)			
						links[i-1].focus();	
					else
						links[i].focus();	
						 
					
				}
				
			}   
		 }*/
	 }else {return false;}
}

// ----- Attach -----

function at_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child );

  p["at_child"]    = c.id;
  c["at_child"]    = c.id;
  p["at_parent"]   = p.id;
  c["at_parent"]   = p.id;
  c["at_position"] = position;

  p.onmouseover = at_show;
  p.onmouseout  = at_hide;
   p.onkeydown= at_hide2;
    p.onkeyup= at_show2;
	 c.onkeydown= at_hide2;
  c.onmouseover = at_show;
  c.onmouseout  = at_hide;
  var temp =c.getElementsByTagName("a");
  var sPath = window.location.pathname;

  var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
 

if (sPage =="comp_business_hk.aspx" ||sPage =="comp_business_china.aspx" ||sPage =="comp_business_hotel.aspx" ||sPage =="comp_infra.aspx" ||sPage =="comp_store.aspx" ||sPage =="comp_others_direct.aspx" ||sPage =="comp_others_other.aspx")
 sPage ="comp_business.aspx";
 if (sPage =="property_sale_cn.aspx")  
  sPage ="property_sale.aspx";
   if (sPage =="property_lease_cn.aspx")  
  sPage ="property_lease.aspx";
    if(sPage !=""){
      for (i=0;i<temp.length;i++){        
        if(temp[i].href.match(sPage)){    
      
          p.parentNode.parentNode.className="Headmenu";
          /*  var img=p.getElementsByTagName("img")[0].src;
            if(!img.match("x.gif"))
            p.getElementsByTagName("img")[0].src= img.substring(0,img.length-4)+"x"+img.substring(img.length-4,img.length);*/
        }
      }
     }
}

// ----- DropDown Menu ---------------------------------------------------------

// ----- Build Aux -----

function dhtmlmenu_build_aux(parent, child, position)
{
  document.getElementById(parent).className = "parent";
  var width =160;
  var brCounter=1;
  if(parent=="menu_col08")
  width =103;
  for (var i in child)
  {    
	if (child[i] == 'br')
    {
       brCounter+=1;
      continue;
    }
  }
  width=width*brCounter;
  if(parent!="menu_col08")
  document.write('<div class="vert_menu" id="'+parent+'_child" ><table width='+width+' border="0" cellpadding="0" cellspacing="0"><tr><td width="2%" height="8"><img src="html/eng/images/submenu_lc.png" width="7" height="8" /></td><td width="45%" background="html/eng/images/submenu_top.png"><img src="html/eng/images/submenu_top.png" width="152" height="8" /></td><td width="53%"><img src="html/eng/images/submenu_rc.png" width="9" height="8" /></td></tr><tr><td height="69" background="html/eng/images/submenu_l.png"></td><td valign="top" bgcolor="#FBFAFA"><table height="100%" cellspacing="0" cellpadding="0" border="0" style="background-color:#fbfafa"><tr><td>');
  else
  document.write('<div class="vert_menu2" id="'+parent+'_child" ><table width='+width+' border="0" cellpadding="0" cellspacing="0"><tr><td height="8" width="2%"><img src="html/eng/images/submenu_lc.png" width="7" height="8" /></td><td background="html/eng/images/submenu_top.png" width="45%"><img src="html/eng/images/submenu_top.png" width="88" height="8"  /></td><td width="53%"><img src="html/eng/images/submenu_rc.png" width="9" height="8" /></td></tr><tr><td height="69" background="html/eng/images/submenu_l.png"></td><td bgColor="#fbfafa" vAlign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>');
  var n = 0;
  var nextFunction='';
  for (var i in child)
  {
    if (i == '-')
    {
      document.getElementById(parent).href = child[i];      
      continue;
    }
	if (child[i] == 'br')
    {
       document.write('</td><td style="vertical-align: top;" height="100%">');
      continue;
    }
	if (child[i] == 'small')
    {
       nextFunction="small";
      continue;
    }
	if(nextFunction != ''){
		switch(nextFunction)
		{
		case "small":
			  if (typeof child[i] == "object")
			{
			  document.write('<a class="SubHeadmenu" id="'+parent+'_'+n+'"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)"  title="'+i+'" ><IMG border=0 src="html/eng/images/trans.gif" width=10 height=5><IMG border=0 hspace=10 src="html/eng/images/submenuBt.jpg" width=5 height=5>'+i+'</a>');
			  dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
			}
			else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'" class="SubHeadmenu"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)" title="'+i+'" ><IMG border=0 src="html/eng/images/trans.gif" width=10 height=5><IMG border=0 hspace=10 src="html/eng/images/submenuBt.jpg" width=5 height=5>'+i+'</a>');
			
		  break;		
		default:
			 if (typeof child[i] == "object")
				{
				  document.write('<a class="parent" id="'+parent+'_'+n+'"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)"  title="'+i+'" ><IMG border=0 src="html/eng/images/menu_point.jpg" width="5" height="5" hspace="5" alt="" />'+i+'</a>');
				  dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
				}
			else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)" title="'+i+'" ><IMG border=0 src="html/eng/images/menu_point.jpg" width="5" height="5" hspace="5" alt="" />'+i+'</a>');
			
		}
		n++;
		nextFunction='';
	}else{
		if (typeof child[i] == "object")
		{
		  document.write('<a class="parent" id="'+parent+'_'+n+'"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)"  title="'+i+'" ><IMG border=0 src="html/eng/images/menu_point.jpg" width="5" height="5" hspace="5" alt="" />'+i+'</a>');
		  dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
		}
		else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'"  onkeydown="keyarrow(\''+parent+'_'+n+'\',event)" title="'+i+'" ><IMG border=0 src="html/eng/images/menu_point.jpg" width="5" height="5" hspace="5" alt="" />'+i+'</a>');
		n++;
	}
  }
if(parent!="menu_col08")
  document.write('</td></tr></table></td><td background="html/eng/images/submenu_r.png">&nbsp;</td></tr><tr><td height="9"><img src="html/eng/images/submenu_lb.png" width="7" height="9" /></td><td background="html/eng/images/submenu_b.png"><img src="html/eng/images/submenu_b.png" width="152" height="9" border="0" /></td><td><img src="html/eng/images/submenu_rb.png" width="9" height="9" /></td></tr></table></div>');
  else
  document.write('</td></tr></table></td><td background="html/eng/images/submenu_r.png">&nbsp;</td></tr><tr><td height="9"><IMG src="html/eng/images/submenu_lb.png" width="7" height="9" /></td><td background="html/eng/images/submenu_b.png"><img border="0" src="html/eng/images/submenu_b.png" width="88" height="9" /></td><td><img src="html/eng/images/submenu_rb.png" width=9 height=9></td></tr></table></div>');
  var sPath = window.location.pathname;
  var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
  var c = document.getElementById(parent);
  if (sPage =="citizen_dedicate.aspx" ||sPage =="citizen_facilitate.aspx" ||sPage =="citizen_protect.aspx" ||sPage =="citizen_support.aspx"||sPage =="citizen_dedicate_music.aspx"||sPage =="citizen_dedicate_goal.aspx"||sPage =="citizen_facilitate_china.aspx")
 sPage ="citizen_commit.aspx";
 if (sPage =="comp_business_hk.aspx" ||sPage =="comp_business_hk1.aspx" ||sPage =="comp_business_hk2.aspx" ||sPage =="comp_business_china.aspx"||sPage =="comp_business_hotel.aspx"||sPage =="comp_infra.aspx"||sPage =="comp_store.aspx"||sPage =="comp_others_direct.aspx"||sPage =="comp_others_other.aspx")
 sPage ="comp_info.aspx";
    if(sPage !=""){  
      if(c.href.match(sPage)){
        c.parentNode.parentNode.className="Headmenu";
           /* var img=c.getElementsByTagName("img")[0].src;
            c.getElementsByTagName("img")[0].src= img.substring(0,img.length-4)+"x"+img.substring(img.length-4,img.length);*/
        }
     }
    
  
  at_attach(parent, parent+"_child", position);
}

function keyarrow(parent,evt){

var e = evt? evt : window.event;
if(!e) return;

var key = 0;
if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
else if (typeof(e.which)!= 'undefined') { key = e.which; } 
var hyper=document.getElementById(parent);

if(key=='13'){
window.location=hyper.href;
}
 if(key=='40'){
   var links = hyper.parentNode.parentNode.parentNode.getElementsByTagName("a");
   for (i = 0; i <links.length; i++) {
		if(links[i].id == hyper.id){
			if (i+1<links.length)			
				links[i+1].focus();	
			else
				links[0].focus();	
//				alert(links[i].id);
		}
		
	}
   	return false;
 }
 if(key=='38'){
   var links = hyper.parentNode.parentNode.parentNode.getElementsByTagName("a");
    for (i = links.length-1; i >=0; i--) {
		if(links[i].id == hyper.id){
			if (i-1>=0)			
				links[i-1].focus();	
			else
				links[links.length-1].focus();	
	//			alert(hyper.id);
		}
		
	}
   	return false;
 }
  if(key=='9'){
   var links = hyper.parentNode.getElementsByTagName("a");

   for (i = 0; i <links.length; i++) {
		if(links[i].id == hyper.parentNode["at_parent"]){
			if (i+1<links.length)	{		
				links[i+1].focus();				
			}				
			else{
				inks = hyper.parentNode.parentNode.getElementsByTagName("a");
				i=0;
			   for (i = 0; i <links.length; i++) {
					if(links[i].id == hyper.parentNode["at_parent"]){
						if (i+1<links.length)			
							links[i+1].focus();	
						else
							links[0].focus();	
						
					}
					
				}   
			}
		}
		
	}   
	return false;
 }
 if(key=='39'){
   var links = hyper.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("a");
  
   for (i = 0; i <links.length; i++) {
		if(links[i].id == hyper.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode["at_parent"]){
		/*	if (i+1<links.length)			
				links[i+1].focus();	
			else
				links[0].focus();	*/
				links[i].focus();	
			
		}
		
	}   
 }
  if(key=='37'){
   var links = hyper.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("a");
  
   for (i = links.length-1; i >=0; i--) {
		if(links[i].id == hyper.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode["at_parent"]){
		/*	if (i-1>=0)			
				links[i-1].focus();	
			else*/
				links[i].focus();				
		}
		
	}   
 }
 
}
// ----- Build -----

function dhtmlmenu_build(menu)
{
  for (var i in menu) {
    dhtmlmenu_build_aux(i, menu[i], "y");
  }
}

/*
 * Written by  : P
 * Date        : Jan 14, 2008
 *
 * Description : The codes below are used to make the pull-down <div> on top
 *               of the <select>. Actually, it is a bug found in IE 6 or
 *               below (Other browsers function properly.)
 */
function IsIE()
{
	return ( navigator.appName=="Microsoft Internet Explorer" );
}


function ShowPopupDiv(divID)
{
	var divPopup=document.getElementById(divID);

	//Increase default zIndex of div by 1, so that DIV appears before IFrame
	divPopup.style.zIndex=divPopup.style.zIndex+1;

	/*var iFrame = document.createElement("IFRAME");
	iFrame.setAttribute("src", "");

	//Match IFrame position with divPopup
	iFrame.style.position="absolute";
	iFrame.style.left =divPopup.offsetLeft + 'px';
	iFrame.style.top =divPopup.offsetTop + 'px';
	iFrame.style.width =divPopup.offsetWidth + 'px';
	iFrame.style.height =divPopup.offsetHeight + 'px';

	document.body.appendChild(iFrame);

	//Store iFrame in global variable, so it can get removed when divPopup is hidden
	g_PopupIFrame=iFrame;*/
}
