var MenuCurrentPoint;
var MenuCurrentButton;
var MenuTimeout=null;
var MenuLang;
var currentSubMenu;

function AttachEvent(element, name, observer, useCapture) {
    if (element.addEventListener) {
      element.addEventListener(name, observer, useCapture);
    } else if (element.attachEvent) {
      element.attachEvent('on' + name, observer);
    }
}

function DetachEvent(element, name, observer, useCapture) {
    useCapture = useCapture || false;
    if (name == 'keypress' &&
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || element.detachEvent))
      name = 'keydown';

    if (element.removeEventListener) {
      element.removeEventListener(name, observer, useCapture);
    } else if (element.detachEvent) {
      try {
        element.detachEvent('on' + name, observer);
      } catch (e) {}
    }
 }


function MenuPointMouseOver(sender,lang){
    
	if (MenuTimeout) clearTimeout(MenuTimeout);
	if (MenuCurrentButton&&MenuCurrentButton.id==sender.id){
	 	return;
	}
	CurrentPointNoHide=0;
	HideCurrentPoint(0);

	if(('ctl00_'+sender.id+'_submenu')!=currentSubMenu){
	    ShowCurrentSubMenu(false);
	}
	
	if (MenuCurrentPoint=document.getElementById('ctl00_'+sender.id+'_submenu')){		

        td=document.getElementById(sender.id+'_td');
        
        
        if(sender.id=='reg')
            td.className='specactive';
        else
            td.className='active';
		
		MenuCurrentPoint.style.display='block';
		MenuAlign(MenuCurrentPoint, sender);
		
		if (!MenuCurrentPoint.onmouseover){
			AttachEvent(MenuCurrentPoint, 'mouseover', StopHideCurrentPoint);
			AttachEvent(MenuCurrentPoint, 'mouseout', MenuPointMouseOut);
		}
	}
    MenuLang=lang;
	HighligntButton(sender);
	MenuCurrentButton=sender;
}

function HighligntButton(sender){
	//sender.firstChild.style.background='transparent url(images/'+MenuLang+sender.id+'_on.gif) no-repeat scroll center center';		
	AttachEvent(sender, 'mouseout', MenuPointMouseOut);
}

function MenuPointMouseOut(){
	if (MenuTimeout){
		clearTimeout(MenuTimeout);
	}

	MenuTimeout=setTimeout('HideCurrentPoint()', 150);
}

function HideCurrentPoint(sended){
    //alert(currentSubMenu);
    if (MenuCurrentPoint){
        if(MenuCurrentPoint.id==currentSubMenu){
            return;
        }
    }

    if (MenuCurrentPoint){
        var id=String(MenuCurrentPoint.id).substr(6);    
        id=id.substr(0,id.indexOf('_submenu'));	
        td=document.getElementById(id+'_td');
        if(id=='reg')
            td.className='spec';
        else
            td.className='button';
    }
    
	if (MenuCurrentPoint) MenuCurrentPoint.style.display='none';
	if (MenuCurrentButton){
	 //MenuCurrentButton.firstChild.style.background='transparent url(images/'+MenuLang+MenuCurrentButton.id+'.gif) no-repeat scroll center center';	 
	}
	
	MenuCurrentPoint=null;
	MenuCurrentButton=null;	
	ShowCurrentSubMenu(true);

}

function StopHideCurrentPoint(){
	if (MenuTimeout){
	 clearTimeout(MenuTimeout);
	 MenuTimeout=null;
	}
}

function MenuAlign(point, sender){
	
	//alert(sender.offsetLeft + " " + point.offsetWidth + " " + point.parentNode.offsetWidth);
	
	if((sender.offsetLeft+point.offsetWidth)>point.parentNode.offsetWidth){
	    point.style.left=(point.parentNode.offsetWidth-point.offsetWidth) +"px";
	    
	}else{
	    point.style.left=sender.offsetLeft+"px";
	    //alter(point.style.left);
	}
	
	//alert(point.firstChild.nextSibling.firstChild.offsetWidth);	
	//alert(point.style.display);
}

function ShowCurrentSubMenu(visible){
    var o;
    var id=String(currentSubMenu).substr(6);    
    id=id.substr(0,id.indexOf('_submenu'));
    
    td=document.getElementById(id+'_td');
    //alert('zz');
    if(td)
    {   
        if(visible)
        {
            //alert(td.className);
            if(id=='reg')
                 td.className='specactive';
            else
                 td.className='active';
            //alert(td.className);
        }
        else
        {
            if(id=='reg')
                td.className='spec';
            else
                td.className='button';        
        }
    }
                

    
    
    if (o=document.getElementById(currentSubMenu))   
    {        
        if(visible){
            btn=document.getElementById(id);
            if(btn){
                td=document.getElementById(id+'_td');
                
                
                
                o.style.left="-1000px";
                o.style.display='block';
                if((btn.offsetLeft+o.offsetWidth)>o.parentNode.offsetWidth){
                    o.style.left=(o.parentNode.offsetWidth-o.offsetWidth) +"px";
                }else{
                    o.style.left=btn.offsetLeft+"px";
                }
            }
            
            
            
        }
        else {

            o.style.display='none';
        }
    }
}


//--------------------------------------------------------------------------------------------------------
//----- Other stuff
function rollon(obj)
{
obj.className ='rollon'
}
function rolloff(obj)
{
obj.className ='rolloff'
}
function rollclick(obj)
{
obj.className ='rollclick'
}

//---- for big button
function rollon_big(obj)
{
obj.className ='rollon_big'
}
function rolloff_big(obj)
{
obj.className ='rolloff_big'
}
function rollclick_big(obj)
{
obj.className ='rollclick_big'
}

function openUserChat(){
    pWidth=463;
    pHeight=315;
    if(screen != null) {
        posX = Math.round((screen.width - pWidth) / 2);
        posY = Math.round((screen.height - pHeight) / 2);
        posCode = (document.layers)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
    }
    else posCode = "";
    window.open("/guest_livechat.aspx", "_blank", "width="+pWidth+",height="+pHeight+","+posCode);
}

var mainMenu = [

    ["about", "about_company"],
    ["our_team", "about_company"],
    ["philosophy", "about_company"],
    ["management_strategies", "about_company"],
    ["our_advantages", "about_company"],
    ["services", "about_company"],
    ["contact", "about_company"],
    
    ["products", "products"],
    ["process", "products"],
    ["calculator", "products"],
    ["commettee", "products"],
    ["safe", "products"],
    ["test_drive", "products"],
    ["banking", "products"],
    ["secure_id", "products"],
    
    ["prereg", "investing_account"],   
    ["register", "reg"],//investing_account
    ["termsofuse", "investing_account"],
    ["importanttoread", "investing_account"],
    ["accountagreement", "investing_account"],
    ["privacy_policy", "investing_account"],
    
    ["learntoinvest", "news"],
    ["propertyinvestment", "news"],    
    ["realestateinvesting", "news"],    
    ["capitalmgm", "news"],    
    ["moneymgm", "news"],    
    
    ["register", "reg"]
      
];


function dourl(id){
    
    for(i=0;i<mainMenu.length;i++)
    {
        if(mainMenu[i][0]==id){            
            var f = document.myform;
            f.sub_menu_id.value="sub_"+id;
            f.main_menu_id.value=mainMenu[i][1];
            f.action= '/'+id+'.aspx';
            //alert( f.main_menu_id.value);    
            f.submit();
            return true;
        }
    }
}

function dolocale(lc){
    //var f = document.myform;
    //f.action="/default.aspx";
    //f.mylc.value=lc;
    //alert(f.mylc.value);
    //f.submit();
    //__doPostBack('', '');
     return false;
}

function dohtmlurl(lc)
{
    //alert(lc);
    document.location="/"+lc;
    return false;
}