
function jopen( url, attr, nm )
{
  var dattr="scrollbars,resizable,width=600";
  var dname="_blank";
  if( attr ) dattr=attr;
  if( nm ) dname=nm;
  var win = window.open( "", dname, dattr );
  if ( win && typeof(win.focus) != "undefined" )
  {
    scrnX = screen.availWidth;
    scrnY = screen.availHeight;
    winX = window.innerWidth?win.outerWidth:document.body.clientWidth;
    winY = window.innerWidth?win.outerHeight:document.body.clientHeight;
    win.moveTo(Math.round( (scrnX-winX)/2 ), Math.round( (scrnY-winY)/2 ) );
    win.location.href=url;
    win.focus();

  }
}

function focusFirstControl( formID )
{
  var frm = document.forms[formID];
  if( frm )
  {
    // iterate throuugh form controls, find the first usable one to focus.
    for(i in frm.elements)
    { 
      if( frm.elements[i] &&  frm.elements[i].tagName )
      { 
        var tagName = frm.elements[i].tagName;        
        if( tagName == "INPUT" && frm.elements[i].type == "text" || tagName == "TEXTAREA" )
        {   
          if( tagName == "INPUT" && frm.elements[i].readOnly )// check readonly property
            continue;               
          if( frm.elements[i].disabled ) // is it disabled
            continue;
          if( frm.elements[i].offsetWidth == 0 ) // best visibility indicator I could find
            continue;         
          frm.elements[i].focus();          
          break;           
        }      
      }      
    }  
  } 
} 
function doExit()
{
  myDom.setCookie( "mode","s" );
  var form;
  if( window.opener.document.forms.length )
  { 
    form = window.opener.document.forms[0];
  }
  if( form )
  {  
    if( form.xmldirections )
    {
      form.xmldirections.value="<mode>s</mode>";    
    }  
  }    
  myDom.setCookie( "mode","s" );
  var uri = window.opener.location;
  
  if( window.opener.location.search.length == 0 )
  {
    if( form.elements["id"] ) uri += "?id=" + form.elements["id"].value;
    else if( form.elements["Id"] ) uri += "?Id=" + form.elements["Id"].value;
  }
  
  window.opener.location = uri;
  window.close();
}

