function expand(l)
{
   var obj = findObj(l);
   if( obj!=null )
   {
      if(obj.style){
         obj = obj.style;
         obj.display = "block";
      }
   }
}
function collapse(l)
{
   var obj = findObj(l);
   if( obj != null )
   {
      if(obj.style){
         obj = obj.style;
         obj.display = "none";
      }
   }   
}
function findObj(n, d) 
{
   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
   if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function showHideLayers() { //
   var i,p,v,obj,args=arguments;
   for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
   if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
   obj.visibility=v; }
}
function showHide(l)
{
   var obj = findObj(l);
   if(obj.style)
   {
      obj = obj.style;
      obj.display = (obj.display=="block") ? "none" : "block";
   }
}
function showHideLayer( id )
{
   var div = document.getElementById( id );
   if( div.style.display == 'block' )
   {
      collapse( id );
      showHideLayers( id, '', 'hide' );
   }
   else
   {
      expand( id );
      showHideLayers( id, '', 'show' );
   }
   return;
}
function hideLayer( id )
{
   var div = document.getElementById( id );
   collapse( id );
   showHideLayers( id, '', 'hide' );
   return;
}
function showLayer( id )
{
   var div = document.getElementById( id );
   expand( id );
   showHideLayers( id, '', 'show' );
   return;
}
function sizeTo(obj,w,h,cb,divisor)
{
   var o = findObj(obj);
   var currentHeight = parseInt(o.style.height);
   var currentWidth = parseInt(o.style.width);
   o.style.width = currentWidth + (w - currentWidth)/divisor + 'px';
   o.style.height = currentHeight + (h - currentHeight)/divisor+ 'px';
   if(Math.abs(w - currentWidth) <= 1 && Math.abs(h - currentHeight) <= 1)
   {
	   o.style.width = w + 'px';
	   o.style.height = h + 'px';
	   eval(cb);
   }
}
function getActualPos(eElement)
{
   var nTopPos = eElement.offsetTop;
	 var nLeftPos = eElement.offsetLeft;            // initialize var to store calculations
   var eParElement = eElement.offsetParent;     // identify first offset parent element
   while (eParElement != null)
   {                                            // move up through element hierarchy
      nTopPos += eParElement.offsetTop;
			nLeftPos += eParElement.offsetLeft;        // appending top offset of each parent
      eParElement = eParElement.offsetParent;  // until no more offset parents exist
   }
   return { x:nLeftPos, y:nTopPos };                              // return the number calculated
}
//for getting the value etc. of those pesky form elements with numbers as names - bsh
function getFormElementByName( n, f )
{
   var el;
   for(var i=0, l=f.elements.length;i<l; i++)
   {
      if( f[i].name == n )
      {
         el = f[i];
         break;
      }
   }
   return el;
}
function open_window(path, w, h, scrollbar)
{
	var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var topPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height='+h+', width='+w+', top='+topPosition+',left='+leftPosition+',scrollbars=' + scrollbar;
	var title='ServiceMagic';

   newWin = 'newWin = win' + 'dow' + '.' + 'open("' + path + '","' + title + '","' + settings + '");';
   eval(newWin);
   newWin.focus();
}