// client side pop-in style window support
function WindowClosed(){
  //Override this function to capture window events
}

//pop-in style window
//height & width ignored if maximized is true
function WindowOpen(url, title, width, height, OnClientClose, maximized){
  var errMsg = '';
  if(url==null){errMsg='A \'url\' must be provided to the \'WindowOpen\' call.';}
  //show any errors
  if(errMsg.length > 0){
    alert(errMsg);
    return;
  }
  //set defaults
  if(title==null){title=url;}
  if(width==null){width=400;}
  if(height==null){height=600;}
  if(OnClientClose==''){OnClientClose=null;}
  if(maximized==null){maximized=false;}
  
  //Get window object, set properties and open
  var winMngr = GetRadWindowManager();
  var win = winMngr.GetWindowByName('winMain');
  
  if(win != null){
    
    //make sure we are in the browser
    var brow = new MaxWindowSize(width, height);

    //set window properties  
    win.SetUrl(url); 
    win.SetTitle(title);
    win.SetSize(brow.Width, brow.Height);
    win.OnClientClose = OnClientClose;
    win.Show();
    if(maximized){
      win.Maximize();
    }
  }else{
    alert('Unable to find window object \'winMain\'.');
  }
}

function GetRadWindow(){    
  var oWindow = null;    
  if (window.radWindow) oWindow = window.RadWindow; //Will work in Moz in all cases, including clasic dialog    
  else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)    
  return oWindow;              
}    


function Close(){
  var win = GetRadWindow();
  win.Close();
}  

//return parent window
function ParentWindow(){
  var win = GetRadWindow();
  return win.BrowserWindow;
}

//refresh with post back
function RepostParent(){
  ParentWindow().location.reload(true);
}

//re-load url (no postback)
function RefreshParent(){
  ParentWindow().location.href=ParentWindow().location.href;
}

function RefreshParentAndClose(){
  RefreshParent();
  Close();
}

function RepostParentAndClose(){
  RepostParent();
  Close();
}

/*----------------------------
  Local Window Methods
----------------------------*/
function Repost(){
  document.location.reload(true);
}
//
function Refresh(){
  document.location.href=document.location.href;
}

