// JavaScript Document
function BIsChildOfA(B, A)
{
	elem = B;
	while(elem)
	{
		if (elem.parentNode == A)
		{
			return true;	
		}
		elem = elem.parentNode;
	}
	return false;
}

function nextSiblingIgnorBlank(obj)
{
	elem = obj.nextSibling;
	while(elem)
	{
		if (!elem.nodeName.match(/text/ig))
			return elem;
			
		elem = elem.nextSibling;
	}
}

function firstChildIgnorBlank(obj)
{
	elem = obj.firstChild;
	while(elem)
	{
		if (!elem.nodeName.match(/text/ig))
			return elem;
			
		elem = elem.nextSibling;
	}
}

function hideMenu(evt, obj)
{
	evt = evt || window.event;
	
	toElement = evt.toElement || evt.relatedTarget;

	if (BIsChildOfA(toElement, obj))
		return ;
	else
	{
		child = firstChildIgnorBlank(obj);
		hideObj(nextSiblingIgnorBlank(child));	
	}
	if (obj.innerHTML.match(/btn_search_instrument/ig))
	{	
		obj.firstChild.style.width = "280px";
		document.getElementById("div_instrument_search_result").style.width = "280px";
		document.getElementById("ipt_instrument_search").style.width = "280px";
	}
}

var nav_text_color;
var separator_color;
var separator_width;
function hideObj(obj)
{
    if ("2px" == obj.style.borderRightWidth){ //if obj clicked, the div border changed.
        obj.parentNode.getElementsByTagName("div")[0].style.visibility = "hidden";
        obj.style.border = "0px";        
        obj.style.borderRightStyle = "solid";
        obj.style.borderRightWidth = separator_color;
        obj.style.borderRightWidth = separator_width;
        obj.style.backgroundColor = ""; 
        if (undefined != nav_text_color) obj.style.color = nav_text_color;
        
        var ipt_instrument_search = document.getElementById("ipt_instrument_search");
        if (null != ipt_instrument_search)
            ipt_instrument_search.value = "";
        var div_instrument_search_result = document.getElementById("div_instrument_search_result");
        if (null != div_instrument_search_result){
            while(null != div_instrument_search_result.firstChild){
                div_instrument_search_result.removeChild(div_instrument_search_result.firstChild);
            }
            div_instrument_search_result.style.height = "0px";
        }  
    }
}
function showObj(obj)
{
    obj.parentNode.getElementsByTagName("div")[0].style.visibility = "visible";
    separator_color = obj.style.borderRightColor;
    separator_width = obj.style.borderRightWidth;
    obj.style.border = "2px solid #ccc";
    obj.style.borderBottom = "none";
    nav_text_color = obj.style.color;
    obj.style.color = "#006ab1";
    obj.style.backgroundColor = "white";
    aObjs = obj.parentNode.getElementsByTagName("a");
    for (i=0; i<aObjs.length; i++)
    {
        aObjs[i].style.color = "#006ab1";
    }
}

function showMenu(obj)
{		
	if (obj.parentNode.getElementsByTagName("div")[0].style.visibility != "visible")
	{
		aObjs = obj.parentNode.parentNode.getElementsByTagName("div");
		for (i=0; i<aObjs.length; i++)
		{
				aDivs = aObjs[i].getElementsByTagName("div");
				for (j=0; j<aDivs.length; j++) 
				{
					if (aDivs[j].className == "navi_tab_title" && obj != aDivs[j])
					{
						hideObj(aDivs[j]);
					}
				}
		}
		showObj(obj);
	}
	else
	{
		hideObj(obj);
	}
	obj.parentNode.getElementsByTagName("div")[0].style.left = obj.offsetLeft + "px";
	obj.parentNode.getElementsByTagName("div")[0].style.top = (obj.offsetTop + obj.offsetHeight -2 ) + "px";	
	
	if (obj.innerHTML.match(/btn_search_instrument/ig))
	{
		obj.parentNode.getElementsByTagName("div")[0].style.width = "400px";
		document.getElementById("div_instrument_search_result").style.width = "400px";
		document.getElementById("ipt_instrument_search").style.width = "400px";
	}
	if (obj.innerHTML.match(/Account/ig))
	{
		obj.parentNode.getElementsByTagName("div")[0].style.width = "110px";
	}
	if (obj.innerHTML.match(/current_language/ig))
	{
		obj.parentNode.getElementsByTagName("div")[0].style.width = "50px";
	}
}

function on_upgrade() {
     var fm = document.getElementById("navigation_form");
     if(null != fm){
         fm.action = "https://pro.carryquote.com/enroll/payment_update/introduction.asp";
         fm.submit();
     }
}
function menu_open_page(url) {
    location.href = url;
}

