//  -------------------------------------------------------------------------------
//  eMCAT_UI.js
//	Script contains commmon functions used by the eMCAT Web Module User Interface
//  Copyright 2006 BASE77
//  -------------------------------------------------------------------------------

function OpenWindow(sWinName, sURL, nWidth, nHeight, bModal,bFullScreen)
{
	var nMacBugW , nMacBugH ;

	if(is_mac && ! is_safari)
	{
		nMacBugW = 0;
		nMacBugH = 0;
	}
	else
	{
		nMacBugW = 6;
		nMacBugH = 26;
	}

	if (window.showModalDialog && bModal)	
	{		
		var hWin = window.showModalDialog(sURL, "returnValue",'dialogWidth:' + (nWidth + nMacBugW) +'px;dialogHeight:' + (nHeight+ nMacBugH) +'px; help:no; center:yes; resizable:no; status:no; scroll:no; center:yes');	
		//eval("var " + sWinName + " = window.showModalDialog(FlashcardsURL, null,'dialogWidth:526px;dialogHeight:406px; help:no; resizable:no; status:no; scroll:no; center:yes');";)
		if(hWin)	document.location = hWin;
	}
	else if (window.showModelessDialog && bModal)	
	{
		
		var hWin = window.showModelessDialog(sURL, null,'dialogWidth:' + (nWidth + nMacBugW) +'px;dialogHeight:' + (nHeight+ nMacBugH) +'px; help:no;center:yes; resizable:no; status:no; scroll:no; center:yes');
		//eval("var " + sWinName + " = window.showModelessDialog(FlashcardsURL, null,'dialogWidth:526px;dialogHeight:406px; help:no; resizable:no; status:no; scroll:no; center:yes');";)
		hWin.focus();
		
		if(hWin != null)
        {
            if(hWin.opener == null) 
            {
                hWin.opener = self;
            }
        }
		else
		{
			HandleError(3);
		}
	}
	else
	{	
		var strWinProp = " toolbar=no" ;        //Back, Forward, etc...
		strWinProp += ",location=no" ;     //URL field
		strWinProp += ",directories=no";   //"What's New", etc...
		strWinProp += ",status=no" ;      //Status Bar at bottom of window.
		strWinProp += ",menubar=no";  //Menubar at top of window.

		if(bFullScreen)
		{
			strWinProp +=" ,fullscreen=yes";
		}
		else
		{
			strWinProp +=" ,fullscreen=no";
		}

		strWinProp += ",resizable=no" ;   //Allow resizing by dragging. 
		strWinProp += ",scrollbars=no" ;  //Displays scrollbars is document is larger than window.
		strWinProp += ",titlebar=no" ;    //Enable/Disable titlebar resize capability.
		strWinProp += ",width=" + nWidth   ; //Standard 640,800/788, 800/788
		strWinProp += ",height=" + nHeight ; //Standard 480,600/541, 600/566               
		strWinProp += ",top=" + ((screen.height - nHeight) /2)  ;            //Offset of windows top edge from screen.
		strWinProp += ",left=" + ((screen.width - nWidth) /2)  ;            //Offset of windows left edge from screen.
		strWinProp += ",maximize=no" ;            //Offset of windows left edge from screen.
		strWinProp += "";  
		
		var hWin = window.open(sURL, sWinName, strWinProp);

		if(!(is_safari || is_firefox ))
		{
			//hWin.resizeTo(nWidth, nHeight)
		}
		
		/// resize fullscreen windows on FF
		if(is_firefox && nWidth == screen.width)
		{
			hWin.resizeTo(nWidth, nHeight)
		}
		

		hWin.focus();

		if(hWin != null)
        {
            if(hWin.opener == null) 
            {
                hWin.opener = self;
            }
         }
		else
		{
			HandleError(4);
		}
	}

	return hWin;
}

function OpenFlashcardsWindow()
{
	OpenWindow("FCWin", "./Flashcards.htm", 520, 380, true,false)
}


function LaunchTest()
{
	if((is_firefox || is_safari) || (is_ie5up))
	{
		if(is_mac && is_ie)
		{	
			OpenWindow("TestingScreen", "./TestingScreen.htm", screen.width, screen.height, false,true)
		}
		else if(is_safari)
		{
			OpenWindow("TestingScreen", "./TestingScreen.htm", screen.availWidth , screen.availHeight, false,true)
		}
		else
		{
			OpenWindow("TestingScreen", "./TestingScreen.htm", screen.width , screen.height, false,true)
		}
	}
	else
	{
		HandleError(1);
		return false;
	}
}


function popWin() {
	var url_page, x, y, window_width, window_height;

	if(arguments.length == 1) {
		url_page = arguments[0];
		window_width = window.screen.width * 0.7;
		window_height = window.screen.height * 0.6;
	} else if(arguments.length == 3) {
		url_page = arguments[0];
		window_width = arguments[1];
		window_height = arguments[2];		
	} else {
		HandleError(5);
		return;
	}	
	x = (window.screen.width - window_width) / 2 
	y = (window.screen.height - window_height) / 2;			
	var pWin = window.open(url_page, null, 'toolbar=0,location=0,fullscreen=yes,directories=0,menubar=0,scrollbars=0,resizable=0,width=' + window_width + ',height=' + window_height + ',top=' + y + ',left=' + x);
	if(window.navigator.userAgent.indexOf('Mac') != -1) pWin.resizeTo(window_width, window_height);
}



