//===============================================================================
// Name:     xwin
// Purpose:  Collection of functions of window events.
// Version:  1.3.1
// Date:     2005-06-20
// Author:   X. Jian
// Usage:
//    <script language='JavaScript' src='scripts/xwin.js'></script>
//===============================================================================
var winTmp = null;
var winInfo = null
function openInfoWin(url, strWinName, width, height, blnNewWin, intMSec) {
   var strOpts = "location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes";
   if (strWinName) {
      strWinName = strWinName.replace(/\s/,'')
   }
   else {
      strWinName = "xinfo"
   }

   if (isNaN(width)) {
      width= 550
   }
   if (isNaN(height)) {
      height = 750
   }
   strOpts += ",width="+width+",height="+height;

   if (url.search(/http:/i) < 0) {
      url = baseHREF() + url;
   }
   if (blnNewWin) {
      var winNew = window.open(url, strWinName, strOpts);
      winNew.focus();
   }
   else {
      if (winInfo && !winInfo.closed) {
         winInfo.location.href=url
      }
      else {
        closeWin(winInfo);
        winInfo = window.open(url, strWinName, strOpts);
      }
		if (intMSec) {
			setTimeout("winInfo.focus()", intMSec)
		}
		else {
      	winInfo.focus();
		}
   }
}
openWin.opt = '';
function openWin(url, strWinName, intWidth, intHeight, blnNewWin, blnAdjustURLByBase, intMoveToX, intMoveToY) {
	intMoveToX = (intMoveToX)? intMoveToX : 0;
	intMoveToY = (intMoveToY)? intMoveToY : 0;
   var strOpts = "location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
   if (typeof(adjustByBase) == "undefined") {
      adjustByBase = 1
   }
   if (strWinName) {
      strWinName = strWinName.replace(/\s/,'')
   }
   if (intWidth && !isNaN(intWidth)) {
      strOpts += ",width="+intWidth;
   }
   if (intHeight && !isNaN(intHeight)) {
      strOpts += ",height="+intHeight;
   }
   var blnOpenNewWin = (openWin.opt != strOpts)? 1 : 0;
   if (intMoveToX || intMoveToY) {
	   var x, y;
		var w = (intWidth)? intWidth : screen.availWidth
		var h = (intHeight)? intHeight : screen.availHeight;
		  if (isNaN(intMoveToX)) {
		     if (intMoveToX == 'right') {
				  x  = screen.availWidth - w
			  }
			  else if (intMoveToX.match(/^mid/i)) {
				  x = 0.5 * (screen.availWidth - w)
			  }
			  else {
				  x = 0
			  }
		  }   
		  else { x = (intMoveToX)? intMoveToX : 0}
	  strOpts += ",left="+x
	     if (isNaN(intMoveToY)) {
		     if (intMoveToY == 'bottom') {
				  y  = screen.availHeight - h
			  }
			  else if (intMoveToY.match(/^mid/i)) {
				  y = 0.5 * (screen.availHeight - h)
			  }
			  else {
				  y = 0
			  }
		  }   
		  else { y = (intMoveToY)? intMoveToY : 0}
		  
	  strOpts += ",top="+y
	}
   openWin.opt = strOpts;
   if (strWinName == null) {
      strWinName = "XWindow";
   }
   if (url.search(/http:/i) < 0) {
      url = ((blnAdjustURLByBase)? baseHREF() : docHREF()) +  url;
   }
   if (blnNewWin) {
      var winNew = window.open(url, strWinName, strOpts); 
      winNew.focus();
   }
   else {
     if (!blnOpenNewWin &&  winTmp && !winTmp.closed && winTmp.location) { 
        winTmp.location.href = url
     }
     else {
       closeWin(winTmp);
       winTmp = window.open(url, strWinName, strOpts);
     }

     winTmp.focus();
   }
}
function closeWin(winToClose) {
   if (winToClose == null) {
      winToClose = winTmp;
   }
   if (winToClose && !winToClose.closed) {
      winToClose.close()
   }
}
