//////////////////////////////////////////////////
// Functions for Modal Dialogs
//////////////////////////////////////////////////
function openEditModalDialog(modalDialogPath, fileForOpen, dialogTitle, dialogWidth, dialogHeight, postBackScript, Resize)
{
  var sEdge='raised'; // raised sunken;
	var bCenter= 'No';
	var bHelp= 'No';
	var bResize= 'No';
	if (Resize!=null)
	    bResize= Resize;
	var bStatus= 'No';
	var bUnadorned = 'Yes';
	var bScroll = 'No';
	
  var parentWidth = document.body.clientWidth;  
  var parentHeight = document.body.clientHeight;  
  var parentTop = window.screenTop;  
  var parentLeft = window.screenLeft;  

	var	iTop='';
	var	iLeft=''; 

  //if (dialogHeight != '' && dialogWidth != '' )
  //{
	  //iTop=Math.round((parentHeight - dialogHeight) / 2) + parentTop;
	  //iLeft=Math.round((parentWidth - dialogWidth) / 2) + parentLeft; 
	//}
	//else
  //{
    bCenter= 'Yes';
  //}

	var sFeatures="dialogHeight: " + dialogHeight + "px; dialogWidth: " + dialogWidth + "px; dialogTop: " + iTop + "px; dialogLeft: " + iLeft + "px; edge: " + sEdge + "; center: " + bCenter + "; help: " + bHelp + "; resizable: " + bResize + "; status: " + bStatus + "; unadorned: " + bUnadorned + "; scroll: " + bScroll + ";";  
    
  var result = false;
  result = window.showModalDialog(modalDialogPath, new Array( fileForOpen, dialogTitle, parentWidth, parentHeight, parentTop, parentLeft ) , sFeatures )
  // Если вернули true и задан параметр postback, то надо выполнить постбек на сервер
  if ( typeof(result)=="boolean" && result) 
  {
      if((postBackScript) && (postBackScript.length>0))
      {
        eval(postBackScript); 
        // click already handled by postback. So it is returned false to prevent repeated postback. 
        return false;
      }
      else
      {
        // simply reload current window
        window.location.reload(true);
      }
  }
  // Если вернули строку, то это URL
  if ( typeof(result)=="string")
  {
      window.navigate(result);
      return false;
  }
  return result;
}

function ExitOKModalDialog() { if (top.RetOk) top.RetOk();}
function ExitCancelModalDialog() { if (top.RetCancel) top.RetCancel();  }
function ExitRedirectModalDialog(loc) { if (top.RetRedirect) top.RetRedirect(loc);  }
function OnKeypressEscModalDialog() { if (window.event.keyCode == 27) ExitCancelModalDialog(); }


function ResizeDialogWindowToFill() 
{
  var myForm = document.forms[0];
  if (myForm && document.body)
  {
    var dw = document.body.scrollWidth  - document.body.clientWidth;
    var dh = document.body.scrollHeight - document.body.clientHeight;
    if ((dw<0)&&(dw>-20))
      dw=0;
    if (dw > 0 && dh > 0)
      dh-=17;
    if (dw==0 && dh==0) return;
    if (top.ChangeDialogSize)
    {
      top.ChangeDialogSize(dw, dh);
      // top.CenterWindow(null,null);
    }
  }
}


