/* Custom-made functions */

// To open image viewer.
function selectImage(aFile, aWidth, aHeight) {
  openDialog("../gallery/viewer.jsp?FILE="+aFile+"&HEIGHT="+aHeight+"&WIDTH="+aWidth,aWidth,aHeight,null,null,false,false,"");
}
 
// To open video viewer. 
function selectVideo(aFile, aWidth, aHeight) {
  openDialog("../files/vid_viewer.jsp?FILE="+aFile+"&HEIGHT="+aHeight+"&WIDTH="+aWidth,aWidth,aHeight,null,null,false,false,"");
}

/* For pages in need of dialog window */

/*Constants for window position*/
wpLEFT_TOP = 0;
wpCENTER_TOP=1;
wpRIGHT_TOP = 2;
wpLEFT_CENTER = 3;
wpCENTER = 4;
wpRIGHT_CENTER=5;
wpLEFT_BOTTOM=6;
wpCENTER_BOTTOM=7;
wpRIGHT_BOTTOM=8;
wpDEFAULT=wpCENTER;
childWin=null;

/**
* url - the url to open
* width  - width of the window
* height - heigth of the window
* returnFunc - function to be call when dialogresult is OK. the function is declared on the parent page.
* dialogName - name of the dialog window to open. the default constant "_dialog_win" is used if not passed.
*/
function openDialog(url, width, height, returnFunc,  windowPos, dialogName, scroll, resizable, anOption) {
  var wp=wpDEFAULT;
	var left= (screen.width - width) / 2;
  var top = (screen.height - height) / 2;
  if (windowPos!=null) wp=windowPos;
  switch (wp) {
		 case wpLEFT_TOP : left=0;top=0;break;
		 case wpCENTER_TOP : top=0;break;
		 case wpRIGHT_TOP : left=screen.width-width;top=0;break;
		 case wpLEFT_CENTER : left=0;break;
		 case wpRIGHT_CENTER : left=screen.width-width;break;
		 case wpLEFT_BOTTOM : left=0;top=screen.height-height;break;
		 case wpCENTER_BOTTOM : top=screen.height-height;break;
		 case wpRIGHT_BOTTOM : left=screen.width-width;top=screen.height-height;break;
	}
	scroll = scroll ? "yes" : "no";
  resizable = resizable ? "yes" : "no";
	var attr = "left=" + left + ",top=" + top
	  + ",scrollbars="+scroll+",resizable="+resizable+",menubar=no,dependent=yes,width=" + width +
         ",height=" + height + anOption;
	var winName = "_dialog_win";
	if (dialogName!=null && dialogName!="") winName=dialogName;
  var dialogWin = window.open(url, winName, attr);
	window.MODAL_RESULT=0;
	window.EXEC_RESULT=null;
	window.returnFunc = returnFunc;
	childWin=dialogWin;
	dialogWin.focus();
	return dialogWin;
}
