////////////////////////////////////////////////////////////

//	Images

////////////////////////////////////////////////////////////



function js_preloadImages() 

{ //v1.2

  if (document.images) 

  {

    var imgFiles = js_preloadImages.arguments;

    var preloadArray = new Array();

    for (var i=0; i<imgFiles.length; i++) {

      preloadArray[i] = new Image;

      preloadArray[i].src = imgFiles[i];

    }

  }

}



// swap one image list for another

function js_swapImage() 

{

  var i, theObj, j=0, swapArray=new Array, oldArray=document.js_swapImgData;

  for (i=0; i < (js_swapImage.arguments.length-2); i+=3) 

  {

    theObj = eval(js_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1])

    if (theObj != null) 

    {

      // Save the current image source

      swapArray[j++] = theObj;

      swapArray[j++] = (oldArray==null || oldArray[j-1]!=theObj) ? theObj.src : oldArray[j];



      // Swap in the new image source

      theObj.src = js_swapImage.arguments[i+2];

    } 

  }

  document.js_swapImgData = swapArray; //used for restore

}



// restore to saved state

function js_swapImgRestore()

{

  js_swapImgRestoreTo(document.js_swapImgData);

}



// restore to specified state

function js_swapImgRestoreTo(restoreData)

{

  var restoreArray = restoreData;

  if (restoreArray != null)

    for (var i=0; i<(restoreArray.length-1); i+=2)

      restoreArray[i].src = restoreArray[i+1];

}



// clear saved state

function js_swapImgClear()

{

	var restoreArray = document.js_swapImgData;

	document.js_swapImgData = null;

	return restoreArray;

}





////////////////////////////////////////////////////////////

//	Windows

////////////////////////////////////////////////////////////



// nCorner <0-TopLeft, 1-BottomLeft, 2-TopRight, 3-BottomRight(default)>

function js_popUpWindow(url, winName, W, H, nCorner, bPrintable) 

{

  var popWindow = "";

  var restoreArray = document.js_popupWindowData;

  if (restoreArray == null)

    restoreArray = new Array;



  // default to bottom right

  if ( nCorner == null || nCorner < 0 || nCorner > 3 )

  	nCorner = 3;



  var X = 0;

  var Y = 0;

  

  switch(nCorner)

  {

     case 0:	// TopLeft

     {

        X = 0;

        Y = 0;

        break;

     }

     case 1:	// BottomLeft

     {

        X = 0;

        Y = screen.availheight-H-10;

        break;

     }

     case 2:	// TopRight

     {

        X = screen.availWidth-W-10;

        Y = 0;

        break;

     }

     case 3:	// Botttom Right

     {

        X = screen.availWidth-W-10;

        Y = screen.availheight-H-10;

        break;

     }

  }



  // Close any open popup windows first, to allow the new window to open at the specified size

  // Only do this for the PC since the Mac browsers have problems recycling windows after they are closed

  if ( !(navigator.appVersion.indexOf("Mac") != -1) ) // not Mac

	js_closePopUpWindows();



  // Open the window at the specified size

  if ( bPrintable == null || bPrintable == 0 )

    popWindow=window.open(url,winName,'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable,width='+W+',height='+H);

  else

    popWindow=window.open(url,winName,'menubar=yes,toolbar=yes,location=no,directories=no,status=no,scrollbars=no,resizable,width='+ W +',height=' + H);



  // Position the window and give it focus

  popWindow.moveTo(X, Y);

  popWindow.focus();



  // Update the restore array

  restoreArray[restoreArray.length] = popWindow;



  // Save the restore array

  document.js_popupWindowData = restoreArray;

}



function js_closePopUpWindows()

{

  var restoreArray = document.js_popupWindowData;



  if (document.js_popupWindowData != null)

  {

    var i = 0;

    for ( i = 0; i < document.js_popupWindowData.length; i++)

    {

      // Close the window if it is still open

      if (document.js_popupWindowData[i] != "" && document.js_popupWindowData[i].closed != true) // JS 1.1

         document.js_popupWindowData[i].close();

    }



    document.js_popupWindowData = null;

  }

}





////////////////////////////////////////////////////////////

//	goToURL

////////////////////////////////////////////////////////////



function js_goToURL(url) 

{

  if (url != "") { self.location=url; }

}





////////////////////////////////////////////////////////////

//	Layers

////////////////////////////////////////////////////////////



function js_showHideLayers() 

{

  var i, visStr, args;

  args = js_showHideLayers.arguments;

  for (i=0; i < (args.length-2); i+=3) 

  { 

    //with arg triples (objNS,objIE,visStr)

    visStr   = args[i+2];



    if (navigator.appName == 'Netscape') 

    {

      if (document.layers != null) eval(args[i]+".visibility = '"+visStr+"'");

    } 

    else //IE

    { 

      if (visStr == 'show') visStr = 'visible'; //convert vals

      if (visStr == 'hide') visStr = 'hidden';

      if (document.all != null) eval(args[i+1]+".style.visibility = '"+visStr+"'");

    } 

  }

}



////////////////////////////////////////////////////////////

//	Localization

////////////////////////////////////////////////////////////

// Cached global variable to store language choice (must be initialized by calling HTML page as below)

// parent.m_idLanguage = js_getLanguage("SiteCookieName");



// Set the selected language for the site

// Note: Need cookies.js to be included to call this

function js_setLanguage(idLanguage, siteCookieName)

{

	var expdate = new Date();

	js_fixCookieDate(expdate); // correct Mac date bug

	expdate.setTime (expdate.getTime() + (4368 * 60 * 60 * 1000)); // 6 months (24*463) hrs from now 

	

	// Create a sub cookie called "PreferredLanguage" to save this setting

	js_setSubcookie(siteCookieName,"PreferredLanguage",idLanguage,expdate,"/");



	// Update globally cached variable

	parent.m_idLanguage = idLanguage;

}



// Return the setting from the PreferredLanguage cookie

// Returns null if no language cookie found

// Note: Need cookies.js to be included to call this

function js_getLanguage(siteCookieName)

{

	var idLanguage = js_getSubcookie(siteCookieName,"PreferredLanguage");

	return ( idLanguage == "" ) ? null : idLanguage;

}







////////////////////////////////////////////////////////////

//	Playing media files

////////////////////////////////////////////////////////////



function js_canPlayEmbeddedMP3()

{

  	// No known Mac browsers support embedded MP3's yet

  	if ( navigator.appVersion.indexOf("Mac") != -1 ) // Mac browser

	{

		return false;

	}

	else if (navigator.appName == "Netscape")

	{

		// All current versions of Netscape are unable to play embedded MP3's

		return false;

//		var mimeType = navigator.mimeTypes["audio/x-mpeg"];

//		if  ( mimeType == null || mimeType.enabledPlugin == null )

//			return false;

	}

	else

	{

		// check if IE can handle mp3

	}

	return true;

}



function js_canPlayEmbeddedWAV()

{

	if (navigator.appName == "Netscape")

	{

		// All current versions of Netscape are unable to play embedded WAV's

		return false;

//		var mimeType = navigator.mimeTypes["audio/x-wav"];

//		if  ( mimeType == null || mimeType.enabledPlugin == null )

//			return false;

	}

	else

	{

		// check if IE can handle embedded WAV

	}

	return true;

}



// Cached global variable to enable/disable sounds (must be initialized by calling HTML page as below)

// parent.m_bEnableSounds = js_isSoundEnabled("SiteCookieName");





// Note: Need cookies.js to be included to call this

function js_enableSound(bEnable, siteCookieName)

{

	var expdate = new Date();

	js_fixCookieDate(expdate); // correct Mac date bug

	expdate.setTime (expdate.getTime() + (4368 * 60 * 60 * 1000)); // 6 months (24*463) hrs from now 

	

	// Create a sub cookie called "EnableSoundEffects" to save this setting

	js_setSubcookie(siteCookieName,"EnableSoundEffects",bEnable,expdate,"/");



	// Update globally cached variable

	parent.m_bEnableSounds = bEnable;

}



// Return the setting from the EnableSoundEffects cookie

// Note: Need cookies.js to be included to call this

function js_isSoundEnabled(siteCookieName)

{

	var bEnableSounds = js_getSubcookie(siteCookieName,"EnableSoundEffects");

	if ( bEnableSounds == "" )

	{

		// No cookie yet, write one out

		js_enableSound(js_canPlayEmbeddedMP3(), siteCookieName);

		bEnableSounds = js_getSubcookie(siteCookieName,"EnableSoundEffects");

	}	

	return bEnableSounds == "true" ? true : false;

}



function js_playSound(theSound)

{

	if (parent.m_bEnableSounds == true)

	{

		if (navigator.appName == "Netscape")

		{

			if ( document[theSound] != null )

			{

				document[theSound].play(false);

				return true;

			}

		}

		else

		{

			if ( document.embeds[theSound] != null )

			{

				document.embeds[theSound].play();

			//	document.embeds[theSound].Run();

				return true;

			}

		}

	}

	return false;

}



////////////////////////////////////////////////////////////

//	Get URL parameters

////////////////////////////////////////////////////////////

function js_getParamValue(name, win) 

{ 

	if (!(win)) 

		win = window;

	name += "="; 

	var nPos1 = win.location.href.indexOf(name); 

	if (nPos1 < 0) 

		return ""; 

	var nPos2 = win.location.href.indexOf("&", nPos1); 

	return unescape( nPos2 >= nPos1  ? win.location.href.substring(nPos1 + name.length, nPos2) 

					 : win.location.href.substring(nPos1 + name.length) );

} 



////////////////////////////////////////////////////////////

//	Randomization 

////////////////////////////////////////////////////////////

function js_getRandomNum(lbound, ubound) 

{

	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);

}



function js_getRandomChar(number, lower, upper, other, extra) 

{

	var numberChars = "0123456789";

	var lowerChars = "abcdefghijklmnopqrstuvwxyz";

	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";

	var charSet = extra;

	if (number == true)

	charSet += numberChars;

	if (lower == true)

	charSet += lowerChars;

	if (upper == true)

	charSet += upperChars;

	if (other == true)

	charSet += otherChars;

	return charSet.charAt(js_getRandomNum(0, charSet.length));

}



function addBookmark( bookmarkurl, bookmarktitle )

{

	if (document.all)

	{

		window.external.AddFavorite(bookmarkurl, bookmarktitle);

	}

}





function js_getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,

		latterNumber, latterLower, latterUpper, latterOther) 

{

	var rc = "";

	if (length > 0)

	rc = rc + js_getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);

	for (var idx = 1; idx < length; ++idx) 

	{

		rc = rc + js_getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);

	}

	return rc;

}



/*

function CallFunc(exp, wait) 

{ 

	wait = (wait == null) ? 1 : wait; setTimeout(exp, wait); 

} 

*/

