var selectAreHidden = 0;

function help( url,main )
{
	if( main == "main" )
	{
		hlp=window.open(url,"up","toolbar=no,scrollbars=yes,resizable=yes,width=640,height=480,left=200,top=170");
	}
	else
	{
		hlp=window.open(url,"up","toolbar=no,scrollbars=no,resizable=yes,width=320,height=60,left=200,top=170");
	}
	hlp.focus();
}

function InvoiceWindow( url )
{
    msgWindow=open(url,'Invoice','toolbarno,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=760,height=500');  
    if (msgWindow.opener == null) msgWindow.opener = self;
}


var select_tab = false;


function hideSelect( detail )
{
    if( selectAreHidden == 1 )
    {
        return 0;
    }

    selectAreHidden = 1;
    
    x1 = detail.offsetLeft;
    y1 = detail.offsetTop;
    x2 = x1 + detail.offsetWidth;
    y2 = y1 + detail.offsetHeight;

    if(isNaN(x1)) x1 = 0;
    if(isNaN(x2)) x2 = 10000;
    if(isNaN(y1)) y1 = 0;
    if(isNaN(y2)) y2 = 10000;
        

    if (!select_tab) {
        select_tab = getElementsToHide();
    }
	

    for( i = 0; i < select_tab.length && i < 50; i++ )
	{
        obj = select_tab[i];
		if( !obj )
            continue;
         
		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
        objParent = obj.offsetParent;
         		
		while (objParent.tagName.toUpperCase() != "BODY")
		{
            objLeft  += objParent.offsetLeft;
            objTop   += objParent.offsetTop;
            objParent = objParent.offsetParent;
		}

        objRight  = objLeft + obj.offsetWidth;
        objBottom = objTop  + obj.offsetHeight;

 		if( ( (objTop  > y1 && objTop  < y2) || (objBottom > y1 && objBottom < y2) ) &&
            ( (objLeft > x1 && objLeft < x2) || 
              (objRight > x1 && objRight < x2) ||
              (objLeft < x1 && objRight > x2) ) 
            )
        {
            if (obj.style.visibility != "hidden") {
                obj.style.visibility = "hidden";
            }
        }

        if( objTop > y2 )
        {
            return;
        }
    }
}
         

function showSelect()
{
    if( selectAreHidden == 1 )
    {
        if (select_tab == null) {
            select_tab = getElementsToShow();
        }

        for( i = 0; i < select_tab.length && i < 50; i++ )
        {
            obj = select_tab[i];
            if (! obj || ! obj.offsetParent)
                continue;
    
    		if (obj.style.visibility != "")
            {
                obj.style.visibility = "";
            }
    	}
        selectAreHidden = 0;
    }
}

    
first_init_text = new Array ();
second_init_text = new Array ();
select_init_text = new Array();
first_init_value = new Array ();
second_init_value = new Array ();
select_init_value = new Array ();
var first_init_length;
var second_init_length;
var select_init_length;

// That function saves two select options in two arrays
function store_select(select1,select2)
{
   first_init_length = select1.length;
   second_init_length = select2.length;

   for (i=0; i< first_init_length; i++) {
       first_init_value[i] = select1.options[i].value;
       first_init_text[i] = select1.options[i].text;
   }
   
   for (i=0; i< second_init_length; i++) {
       second_init_value[i] = select2.options[i].value;
       second_init_text[i] = select2.options[i].text;
   }
}

// That function saves a select options in an array
function store_1select(select1)
{
   select_init_length = select1.length;
   
   for (i=0; i< select_init_length;i++)
   {
       select_init_value[i] = select1.options[i].value;
       select_init_text[i] = select1.options[i].text;
   }
}

// Restores initial options saved by store_select()
function reset_display(select1,select2)
{
   var len_first = select1.length;   
   var len_second = select2.length;

   for( i = 0; i <len_first ; i++ )
   {
       select1.options[0] = null;
   } 
   for( i = 0; i < first_init_length ; i++ )
   {
       select1[i] = new Option (first_init_text[i],first_init_value[i]);
   }
   for( i = 0; i < len_second ; i++ )
   {
       select2.options[0] = null;
   } 
   for( i = 0; i < second_init_length ; i++ )
   {
       select2[i] = new Option (second_init_text[i],second_init_value[i]);
   }
}

// Restores initial options saved by store_select()
function reset_1display(select1)
{
   var len_select = select1.length;   
   
   for( i = 0; i <len_select ; i++ )
   {
       select1.options[0] = null;
   } 
   for( i = 0; i < select_init_length ; i++ )
   {
       select1[i] = new Option (first_init_text[i],first_init_value[i]);
   }
}


