//JavaScript code for functions

//***********************
//	REVISION HISTORY
//	Date
//	04.22.99		code inception
//					This file is put together to provide standardized JavaScript functionality
//					it is based on functions already inplace and in use in applications
//					and will be expanded as necessary
//
//	06.09.99		video_on_top functions added
//					premise:  A pop-up window is useful for course structure
//					thus far it has been impossible to make sure that the
//					window had focus due to a bug in Browser 4.0 and the
//					<EMBED> tag.  This is the work-around. 
//				
//	06.28.99		The various open window functions have been added.  Also the 
//					winVideo function has been modified to work like the other
//					functions produced.
//
//	11.01.99		Rearranged masterWindowOpen so it moves window to specified
//					location first, then loads the necessary page.  Added 'var' 
//					statement as potential bug fix for erratic behavior in courses.
//
//	11.05.99		bug fix to ClosePopUp -- added top. for multi-frame pop-ups.
//
//	FUNCTION LIST
//	Date		Function Name				Brief Summary
//	
//	04.22.99	preloadImages				loads roll-overs into memory as a page loads
//	04.22.99	switchImg					switches images for roll-overs
//											modified 08.12.99 
//	06.10.99	myPlayVideo(modified)		plays video in a pop-up window
//	06.10.99	myFocusVideo				controls focus of pop-up window
//	06.10.99	vidCleanUp					defensive coding for closing vid window (very necessary)
//											modified 08.12.99 
//	06.10.99	mainCleanUp					defensive coding for closing main window (very necessary)
//  06.28.99    winVideo					modified, used to be myPlayVideo	
//  06.28.99    winNoScroll					opens a window with no scroll bars
//  06.28.99    winScroll					opens a window with scroll bars
//  06.28.99    winCenterScroll				opens a window centered on the screen with scroll bars
//  06.28.99    winCenterNoScroll			opens a window centered on the screen with no scroll bars
//  06.28.99    masterWindowOpen			main function to open a window
//	08.10.99	winScrollTB					opens a window with scroll bars and toolbar
//	11.05.99	ClosePopUp 					closes a pop-up window and focuses the opener
//	02.15.00	cleanUp 					closes a pop-up window and relocates the opener
//***********************


//******************************************************************************
//* Name:  preloadImages
//* Parameters:  any comma-delimited string of image names
//* Returns:
//* Notes:  loads the specified graphics into the cache
//*Usage: <body onLoad="preloadImages('image1.gif, image2.gif, ...')">
//******************************************************************************
 
function preloadImages() {
 		// make sure the document has images
	if (document.images) {
   		
		// inititialize the preLoad Object
		if (typeof document.preLoad == 'undefined'){
     			document.preLoad = new Object();
	   		}
		
		document.preLoad.loadedImages = new Array();    // make an Array to stick the loadedImages into
		var argLength = preloadImages.arguments.length; // length of the passed in arguments
   		
		// loop through the array
		for(arg=0; arg < argLength; arg++) {
			// make a new Image
     			document.preLoad.loadedImages[arg] = new Image();
     			// load the image into memory
			document.preLoad.loadedImages[arg].src = preloadImages.arguments[arg];
		}
	}
}// end preloadImages


//******************************************************************************
//* Name:  switchImg
//* Parameters:	imageName = the image name in the <IMG> tag
//				imgageSrc = an image file with complete path
//* Returns:
//* Notes: assigns the image to the document object
//* Usage: eg. onMouseOver="switchImg('imageName', 'images/image.gif')"
//******************************************************************************

function switchImg(imageName, imageSrc) {
	if (document.images) {
    	document.images[imageName].src = imageSrc;
	}
}// end switchImg


//******************************************************************************
//* Name:  winVideo
//* Parameters: videoSrc -- an html file with the embeded video content
//* Returns:  nothing
//* Notes:  must be used with myFocusVideo() script to keep the video window on top
//*			the variable myVidWin must be declared null outside myPlayVideo, 
//*			as it is also used by myFocusVideo().
//*			If no (X,Y) location is specified, the window is centered.
//* Usage:  <A HREF="javascript:myPlayVideo('videopage.htm')"> link text </A>
//******************************************************************************

var myVidWin = null;
 
//function winVideo(winUrl, winName, winWidth, winHeight, winX, winY) {
function winVideo(winUrl, winName, winWidth, winHeight, winX, winY) {
	
	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=no";
	
	if (arguments.length == 4) {
		//do math to center window
	 	var screenH = screen.availHeight;
	 	var screenW = screen.availWidth;
	 	
	 	var moveX = (screenW - winWidth)/2;
	 	var moveY = (screenH - winHeight)/2;
		
		myVidWin = masterWindowOpen(winUrl, winName, winFeatures, moveX, moveY);
	}
	else {
		myVidWin = masterWindowOpen(winUrl, winName, winFeatures, winX, winY);
	}
}
//end winVideo

//******************************************************************************
//* Name:  myFocusVideo
//* Parameters:  videoWin
//* Returns:  nothing
//* Notes:  this script makes a pop-up video window never loose focus.
//*			the pop-up window must have myCleanUp() script.
//* Usage:  <BODY onFocus="myFocusVideo(myVidWin)">
//******************************************************************************
function myFocusVideo(myVid) {
	if (!myVid || myVid.closed){
		window.focus();
	}
	else if (!myVid.closed) {
			myVid.focus();
	}
}
//end myFocusVideo

//******************************************************************************
//* Name:  vidCleanUp
//* Parameters:  none
//* Returns:  nothing
//* Notes:  Sets parent window variable to null so myFocusVideo will work in IE
//*			The appName check is necessary bcs Netscape can actually switch videos
//*				without closing the window.
//*			This function is NOT on the close function so that the clean-up will still occur if 
//*				the window is closesd with the X box in the upper right
//*			There should be no reference to visclnt.js in the <SCRIPT> tag.
//*				all functions need to be local or referenced to the parent document.
//* Usage:	<BODY onBlur="self.focus()" onUnload="window.opener.vidCleanUp()">
//*			If the HTML page is the second or more page to load in a pop-up window, the body needs:
//*			<BODY onBlur="self.focus()" onLoad="window.opener.myVidWin=window"
//*			onUnload="window.opener.vidCleanUp()">
//******************************************************************************

function vidCleanUp() {
	if (navigator.appName == "Microsoft Internet Explorer") {
			myVidWin = null;
	}	
}
//end vidCleanUp

//******************************************************************************
//* Name:  mainCleanUp
//* Parameters: videoWin
//* Returns:  nothing
//* Notes:  Closes vidWin if it is open on unload of main page
//* Usage:	<BODY onUnload="mainCleanUp(myVidWin)">
//******************************************************************************

function mainCleanUp(myVid) {
	if (typeof myVid == "undefined") {
		return;
		}
	if (!myVid || myVid.closed){
		return;
		}
	else if (!myVid.closed) {
			myVid.close();
		}
}
//end mainCleanUp

//******************************************************************************
//* Name: winNoScroll
//* Parameters: winUrl the URL, winName name of the Window, winWidth width of the window,
//* 			 winHeight width of the window
//* Returns: nothing
//* Notes: builds the "features" string and passes it to masterWindowOpen
//* Usage: call from an HTML document to open a window with no scroll bars
//******************************************************************************
function winNoScroll(winUrl, winName, winWidth, winHeight, winX, winY) {
	
	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=no";
	
	if (arguments.length == 4) {
		masterWindowOpen(winUrl, winName, winFeatures, 0, 0);
	}
	else {
		masterWindowOpen(winUrl, winName, winFeatures, winX, winY);
	}
}
//end winNoScroll

//******************************************************************************
//* Name: winScroll
//* Parameters: winUrl the URL, winName name of the Window, winWidth width of the window,
//* 			 winHeight width of the window
//* Returns: nothing
//* Notes: builds the "features" string and passes it to masterWindowOpen
//* Usage: call from an HTML document to open a window with scroll bars
//******************************************************************************
function winScroll(winUrl, winName, winWidth, winHeight, winX, winY) {

	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes";
	
	if (arguments.length == 4) {
		masterWindowOpen(winUrl, winName, winFeatures, 0, 0);
	}
	else {
		masterWindowOpen(winUrl, winName, winFeatures, winX, winY);
	}
}
//end winScroll


//******************************************************************************
//* Name: winScrollTB
//* Parameters: winUrl the URL, winName name of the Window, winWidth width of the window,
//* 			 winHeight width of the window
//* Returns: nothing
//* Notes: builds the "features" string and passes it to masterWindowOpen
//* Usage: call from an HTML document to open a window with scroll bars and toolbar
//******************************************************************************
function winScrollTB(winUrl, winName, winWidth, winHeight, winX, winY) {
	
	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",toolbar=yes,scrollbars=yes";
	
	if (arguments.length == 4) {
		masterWindowOpen(winUrl, winName, winFeatures, 0, 0);
	}
	else {
		masterWindowOpen(winUrl, winName, winFeatures, winX, winY);
	}
}
//end winScrollTB


//******************************************************************************
//* Name: winCenterScroll
//* Parameters: winUrl the URL, winName name of the Window, winWidth width of the window,
//* 			 winHeight width of the window
//* Returns: nothing
//* Notes: builds the "features" string and passes it to masterWindowOpen
//* Usage: call from an HTML document to open a window centered on the screen
//* with scroll bars
//******************************************************************************
function winCenterScroll(winUrl, winName, winWidth, winHeight) {
	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes";
	
 	//do math to center window
 	var screenH = screen.availHeight;
 	var screenW = screen.availWidth;
 	
 	var moveX = (screenW - winWidth)/2;
 	var moveY = (screenH - winHeight)/2;
	masterWindowOpen(winUrl, winName, winFeatures, moveX, moveY);
}
//end winCenterScroll

//******************************************************************************
//* Name: winCenterNoScroll
//* Parameters: winUrl the URL, winName name of the Window, winWidth width of the window,
//* 			 winHeight width of the window
//* Returns: nothing
//* Notes: builds the "features" string and passes it to masterWindowOpen
//* Usage: call from an HTML document to open a window centered on the screen
//* with no scroll bars
//******************************************************************************
function winCenterNoScroll(winUrl, winName, winWidth, winHeight) {
	var winFeatures = "width=" + winWidth + ",height=" + winHeight + ",scrollbars=no";
	
 	//do math to center window
 	var screenH = screen.availHeight;
 	var screenW = screen.availWidth;
 	
 	var moveX = (screenW - winWidth)/2;
 	var moveY = (screenH - winHeight)/2;
	masterWindowOpen(winUrl, winName, winFeatures, moveX, moveY);
}
//end winCenterNoScroll

//******************************************************************************
//* Name: masterWindowOpen
//* Parameters: mstUrl the URL, mstName Name of the Window, 
//*				mstFeatures features for the window, mstX x-screen position, 
//*				mstY y-Screen position
//* Returns: nothing
//* Notes:  This function opens the window brings it to the front if it is already
//*			open and moves it to a specified (x, y) position
//* Usage: Only call this function from the other functions within this document 
//******************************************************************************
function masterWindowOpen(mstURL, mstName, mstFeatures, mstX, mstY) {
	var openWindow = window.open("", mstName, mstFeatures);
	openWindow.moveTo(mstX, mstY);
	openWindow.location.href = mstURL;
	openWindow.self.focus();
	openWindow.onblur="self.focus()"
	return openWindow;
}
//end masterWindowOpen

//******************************************************************************
//* Name: ClosePopUp
//* Parameters: none
//* Returns: nothing
//* Notes:  Closes a pop-up window and focuses the window that opened it.
//******************************************************************************

function ClosePopUp()  {
	top.window.opener.focus();
	top.window.self.close();
}
//end ClosePopUp

//******************************************************************************
//* Name: cleanUp
//* Parameters: myString the url
//* Returns: nothing
//* Notes:  Closes a pop-up window and relocates the page that opened it.
//******************************************************************************

function cleanUp(myString) {
	myWin = self.opener;
	myWin.top.frames[1].location = myString;	
	ClosePopUp()
	}
//end cleanUp

//******************************************************************************
//* Name: sendEmail
//* Parameters: none
//* Returns: nothing
//* Notes:  Sends an email to the mailto recipient address.
//******************************************************************************
function sendEmail() {

            window.location.href = "mailto:almasuppliers@gmail.com";

}
//end sendEmail
