/* Script by: www.jtricks.com
 * Version: 20060325
 * Latest version:
 * www.jtricks.com/javascript/blocks/ordering.html
 */
function getAbsoluteDivs()
{
    var arr = new Array();
    var all_divs = document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
			
            arr[j] = all_divs.item(i);
			
            j++;
        }

    return arr;
}
function checkMenu(id2)
{
 var obj= document.getElementById(id2);
	 if(obj.style.display=='block'){
		  setTimeout(function(){hideMenu(id2)},1000);

 return false;
	 }
	 else{
	setTimeout(function(){showMenu(id2)},100);	//this v short timeout prevents menu flash

    return true;
}
}

function hideMenu(id2){
	
	 var obj= document.getElementById(id2);
	 
	obj.style.display='none';
}

function showMenu(id2){
	
	 var obj= document.getElementById(id2);
	 
	obj.style.display='block';
}

function bringToFront(id,id2)
{
    if (!document.getElementById ||
        !document.getElementsByTagName)
        return;
if(checkMenu(id2)){
    var obj = document.getElementById(id);
    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;

    // Compute the maximal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}
}

function sendToBack(id)
{
    if (!document.getElementById ||
        !document.getElementsByTagName)
        return;

    var obj = document.getElementById(id);
    var divs = getAbsoluteDivs();
    var min_index = 999999;
    var cur_index;

    if (divs.length < 2)
        return;

    // Compute the minimal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj)
            continue;

        if (item.style.zIndex == '')
        {
            min_index = 0;
            break;
        }

        cur_index = parseInt(item.style.zIndex);
        if (min_index > cur_index)
        {
            min_index = cur_index;
        }

    }

    if (min_index > parseInt(obj.style.zIndex))
    {
        return;
    }

    obj.style.zIndex = 1;

    if (min_index > 1)
        return;

    var add = min_index == 0 ? 2 : 1;

    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj)
            continue;

        item.style.zIndex += add;
    }
}
