//' Software by DavidRegier.com. Unauthorized use of this code is prohibited

/*
function checkDim
function checkImgName
function DeleteCookie
function directX
function dissolveDirectX
function DynamicIndex
function DynamicWindow
function fadeIn
function fadeInDirectX
function FileWriter
function GetCookie
function getCookieDomain
function getCookieVal
function getEmailLink
function getOpacity
function getRGB
function getTransition
function getVal
function initImagesArr
function largePic
function PopUp
function PreLoader
function randompick
function recordToCookie
function reportError
function SetCookie
function SlideShow
function startFade
function trim
*/

//--------------------------------------------------------------------------------------

// 11/6/2007
IE = false, AOL = false, SF = false, MZ = false;

if( navigator.appName == "Microsoft Internet Explorer" ) {
	IE = true;
	if( navigator.userAgent.indexOf( "AOL" ) >= 0 ) AOL = true;
}
else if( navigator.userAgent.indexOf( "Safari" ) >= 0 )
	SF = true;
else if( navigator.appName == "Netscape" )
	MZ = true;

winOS = ( navigator.platform.substring( 0, 3 ) == "Win" );
winIE = ( winOS && IE );
macOS = ( navigator.platform.substring( 0, 3 ) == "Mac" );
macIE = ( macOS && IE );

theHost = document.location.hostname;
theHostLC = theHost.toLowerCase();

local = ( theHostLC.length == 0 || theHostLC == "127.0.0.1" || theHostLC == "localhost" ), live = !local;

qStr = unescape( document.location.search ).substring( 1 );

homePage = "default.aspx"
path = document.location.pathname;
delimeter = ( path.indexOf( "\\" ) >= 0 ) ? "\\" : "/";
if( path.charAt( path.length - 1 ) == delimeter ) path += homePage;
Path = path.split( delimeter );
fileName = Path[ Path.length - 1 ];

// Re-assemble e-mail addresses
if( typeof window.DB == "object" ) {

	if( typeof window.DB.Administrators == "object" ) {

		for( var key in DB.Administrators ) {

			eMailOut = "";
			eMailIn = DB.Administrators[ key ].replace( /\s{2}/g, "." );
			eMailIn = eMailIn.replace( /\s{1}/g, "@" );
			for (i = 0; i <= eMailIn.length; i++)
				eMailOut = eMailIn.charAt(i) + eMailOut;

			DB.Administrators[ key ] = eMailOut;
		}

	}

	if( typeof window.DB.Contact == "object" ) {

		eMailOut = "";
		eMailIn = DB.Contact.Email.replace( /\s{2}/g, "." );
		eMailIn = eMailIn.replace( /\s{1}/g, "@" );
		for (i = 0; i <= eMailIn.length; i++)
			eMailOut = eMailIn.charAt(i) + eMailOut;

		DB.Contact.Email = eMailOut;

	}

	if( typeof window.DB.ReportErrorsTo == "string" ) {

		eMailOut = "";
		eMailIn = DB.ReportErrorsTo.replace( /\s{2}/g, "." );
		eMailIn = eMailIn.replace( /\s{1}/g, "@" );
		for (i = 0; i <= eMailIn.length; i++)
			eMailOut = eMailIn.charAt(i) + eMailOut;

		DB.ReportErrorsTo = eMailOut;
	}
}

// Re-assemble e-mail addresses
if( window.rapw ) {
	var rapwOut = "";
	rapw = rapw.replace( /^kRe7lbAh/, "" ).replace( /uNqp1l7a$/, "" );
	for( var i = 0; i <= rapw.length; i++ )
		rapwOut = rapw.charAt(i) + rapwOut;
	rapw = rapwOut;
}

InstructionsHomePage =

"This HTML text box contains your homepage slide-show data and you are free to add/remove and or move their positions, with the exception of the first one called \"ssHome_ma_0001.jpg\". Slide show plays from top down in a loop and ALL these images must be sized to exactly 420 x 280 pixels - the border is part of the image. Makana Akua and the text is part of the image file \"homePageBkg.jpg\". If you need to change this text you will need to create a new \"homePageBkg.jpg\" with your new or edited text embedded onto it." +

"<ol style='margin-top:4px; margin-bottom:4px;'>" +

	"<li>Right-click a photo to get image-properties & pause the slide-show.</li>" +

	"<li><a href='javascript:PopUp.openWin( \"uploader.aspx\", 650, 350, 2, 0, 0, 0, 0, 0, 0 );' title='Upload files to the server' class='fw'>Click here</a> to upload new photos.</li>" +

	"<li>Hold Shift & click photo to pause it, repeat this action to re-start it.</li>" +

	"<li>Hold Ctrl & click photo to run it at hi-speed, repeat this action to revert to normal speed. This is useful for quickly checking that it's working correctly.</li>" +
"</ol>";

window.onunload = function() { if( window.DW ) DW.removeWin(); }


var Msg = new Array();
Msg.about = "Learn more about the home & area";
Msg.cal = "Check our booking calendar for availability";
Msg.contact = "Contact us via phone, e-mail or mail";
Msg.homePage = "Back to our homepage";
Msg.rates = "Get our Rental rates";
Msg.SS = "View photos via our automated slide-show";
Msg.enlarge = "Click to enlarge";


// 11/6/2007
//////////////////////////////// Start PreLoader: PL ////////////////////////////////

function PreLoader() {

	this.Files = [

	"images/header.jpg",

	"calendar.aspx",
		"calendar.js",
		"cal-data.js",
		"HaenaBeachHalePF.css",

	"about.aspx",
		"images/HOP_323_lgTN.jpg",
		"images/HOP_7103_lgTN.jpg",
		"images/HOP_6261_lgTN.jpg",
		"images/HOP_7022_lgTN.jpg",
		"images/HOP_3570_lgTN.jpg",

	"rates.aspx",
		"images/HOP_aerial_lgTN.jpg",
		"images/HOP_001_lgTN.jpg",
		"images/HOP_7049_lgTN.jpg",
		"images/HOP_4872_lgTN.jpg",

	"ss.aspx?db=images.js",
		"images.js",
		"images/HOP_house_lg.jpg",

	"default.aspx",
		"images-homepage.js",
		"images/homePageBkg.jpg",
		"images/ssHome_HOP_001.jpg",

	"uploader.aspx",


	null ];

	this.debug = 0;
	try {
		if( top.qStr && top.qStr.indexOf( "preloader=show" ) != -1 )
			this.debug = 1;
	}
	catch( Err ) { }

	if( this.debug )
		DeleteCookie( "nFilesCached" );

	this.Request = null;
	this.timer = 0;
	this.nFilesCachedCookie = GetCookie( "nFilesCached" );
	this.nFilesCached = ( this.nFilesCachedCookie ) ? parseInt( this.nFilesCachedCookie ) : 0;
	this.run = run;
	if( this.debug ) top.document.title = "File preloader started...";

	//------------------------------------- Method PL -------------------------------------

	function run() {

		// W3C
		if( window.XMLHttpRequest ) {
			try { this.Request = new XMLHttpRequest(); }
			catch( Err ) { this.Request = null; }
		}

		// IE 6-
		else if( window.ActiveXObject ) {
			try { this.Request = new ActiveXObject( "Msxml2.XMLHTTP" ); }
			catch( Err ) {
				try { this.Request = new ActiveXObject( "Microsoft.XMLHTTP" ); }
				catch( Err ) { this.Request = null; }
			}
		}

		clearTimeout( PL.timer );

		if( this.Request ) {

			if( this.nFilesCached < this.Files.length - 1 ) {

				this.Request.onreadystatechange = function() {
					try {
						if( PL.Request.readyState == 4 ) {
							if( PL.Request.status == 200 ) {
								if( PL.debug )
									top.document.title = PL.Files[ PL.nFilesCached ] + " preloaded; #" + ( ( PL.nFilesCached + 1 ) + " of " + ( PL.Files.length - 1 ) );
							}
							else {
								if( PL.debug )
									alert( "File preloader encountered an error retrieving: \n " + PL.Files[ PL.nFilesCached ] + "\n Status: " + PL.Request.status + "\n StatusText: " + PL.Request.statusText + "\n Number " + ( ( PL.nFilesCached + 1 ) + " of " + ( PL.Files.length - 1 ) ) );
							}

							PL.nFilesCached++;
							SetCookie( "nFilesCached", PL.nFilesCached );
							PL.timer = setTimeout( "if( window.PL ) PL.run();", 100 );

						}
					}
					catch( Err ) {
						var eMsg = "Exception at PL.run()\n\n";
						for( var i in Err ) eMsg += i + ": " + Err[ i ] + "\n";
						try{ if( PL.debug ) alert( eMsg ); } catch( Err ) { self.status = eMsg.replace( /\n/g, " " ); }
					}
				}

				this.Request.open( "GET", this.Files[ this.nFilesCached ], true );
				this.Request.send( null );

			}
		}

		// Browser cannot make http request (AOL/SF crash) so get images only
		else if( PL.debug )
			top.document.title = "Browser does not support the HttpRequest Request Protocol";
	}

}

PL = new PreLoader();

//////////////////////////////// End PreLoader: PL ////////////////////////////////

// 11/6/2007
//----------------------------------- String Prototype -----------------------------------
// If key is found in strToSearch then returns its value, otherwise returns null
function getVal( key ) {

	var value = null;
	var strToSearch = this.toString();

	var KeyVals = strToSearch.split( "&" );

	for( member in KeyVals ) {
		var ThisPair = KeyVals[ member ].split( "=" );
		if( key == ThisPair[ 0 ] ) { value = ThisPair[ 1 ]; break; }
	}
	if( typeof value == "undefined" ) value = "";
	return value;
}
String.prototype.getVal = getVal;

// 12/14/2007
//----------------------------------- String Prototype -----------------------------------
// Trims white space (which includes line breaks) off both ends
function trim() {
	var str = this.toString();
	return str.replace( /^\s*|\s*$/g, "" );
}
String.prototype.trim = trim;


//--------------------------------------------------------------------------------------

function reportError( sub, msg ) {

	var Now = new Date();

	var diagnostics = " \nURL: " + document.location.href;

	try{ var topURL = top.document.location.href; }
	catch( e ){ var topURL = "Exception thrown while reading top URL"; }

	try{ var ref = document.referrer; }
	catch( e ){ var ref = "Exception thrown while reading Referrer"; }

	diagnostics += " \nTop URL: " + topURL;
	diagnostics += " \nTime: " + Now.toLocaleString() + " (client's time)";
	diagnostics += " \nPrior Page: " + ref;
	diagnostics += " \nGMT Offset: " + Now.getTimezoneOffset() / 60 + " hours";
	diagnostics += " \nMonitor: " + screen.width + "x" + screen.height + "x" + screen.colorDepth;
	diagnostics += " \nJava Enabled: " + navigator.javaEnabled();
	for( i in navigator ) { if( typeof navigator[ i ] != "object" ) diagnostics += " \n" + i + ": " + navigator[ i ]; }

	if( confirm ( sub + "\n\n" + msg + "\n\n==> Help us improve our site, click OK to report this problem to our Web Site Administrator..." ) )
		document.location.href = "mailto:" + DB.ReportErrorsTo + "?subject=" + escape( theHost + "; " + sub ) + "&body=" + escape( msg + " \n\nDIAGNOSTICS: This info may be used to help us troubleshoot technical problems" + diagnostics );
}

// 1/18/2008
///////////////////////////// START IMAGE LIBRARY FUNCTIONS /////////////////////////////
// ACCESSOR VARS: winIE, MZ, SF, local

//--------------- Image Library ---------------
function randompick() {
  return randompick.arguments[ Math.floor( Math.random()*randompick.arguments.length ) ];
}

function getTransition( transNum, duration ) {

	var trans = "";
	if( winIE ) {
		var d = duration;
		if( parseFloat( navigator.userAgent.split( "MSIE" )[ 1 ] ) >= 5.5 ) { //IE 5.5+

			var thisTrans = ( transNum == 1 ) ? Math.floor( Math.random() * 17 ) + 2 : transNum;

			switch ( thisTrans ) {
				case 2: trans="Fade(duration="+d+",overlap=1)"; break;
				case 3: trans="Blinds(duration="+d+",bands="+randompick(2,4,6,8)+",direction="+randompick('up','down','right','left')+")"; break;
				case 4: trans="CheckerBoard(duration="+d+",squaresX="+randompick(2,4,8,12)+",squaresY="+randompick(2,4,8,12)+",direction="+randompick('up','down','right','left')+")"; break;
				case 5: trans="Barn(duration="+d+",motion="+randompick('in','out')+",orientation=",randompick('horizontal','vertical')+")"; break;
				case 6: trans="GradientWipe(duration="+d+",gradientSize="+randompick(0,0.1,0.3,0.5,0.7,0.9,1)+",wipeStyle="+randompick(0,1)+",motion="+randompick('forward','reverse')+")"; break;
				case 7: trans="Inset(duration="+d+")"; break;
				case 8: trans="Iris(duration="+d+",irisStyle="+randompick('DIAMOND','CIRCLE','CROSS','PLUS','SQUARE','STAR')+",motion="+randompick('in','out')+")"; break;
				case 9: trans="RadialWipe(duration="+d+",wipeStyle="+randompick('CLOCK','WEDGE','RADIAL')+")"; break;
				case 10: trans="RandomBars(duration="+d+",orientation="+randompick('horizontal','vertical')+")"; break;
				case 11: trans="RandomBars(duration="+d+")"; break;
				case 12: trans="Slide(duration="+d+",pushStyle="+randompick('HIDE','PUSH','SWAP')+",bands="+randompick(1,2,3,4,5,6,7)+")"; break;
				case 13: trans="Spiral(duration="+d+",gridSizeX="+randompick(8,16,32,64)+",gridSizeY="+randompick(8,16,32,64)+")"; break;
				case 14: trans="Stretch(duration="+d+",stretchStyle="+randompick('HIDE','PUSH','SPIN')+")"; break;
				case 15: trans="Strips(duration="+d+",motion="+randompick('leftdown','leftup','rightdown','rightup')+")"; break;
				case 16: trans="Wheel(duration="+d+",spokes="+randompick(2,4,10,16,20)+")"; break;
				case 17: trans="Zigzag(duration="+d+",gridSizeX="+randompick(8,16,32,64)+",gridSizeY="+randompick(8,16,32,64)+")"; break;
				case 18: trans="RandomDissolve(duration="+d+")"; break;
        //case 19: trans="Pixelate(duration="+d+",maxSquare="+randompick(5,10,20,30,40,50)+")"; break;
				default: alert( "SWITCH/CASE ERROR: Case caught by default handler in \"getTransition\"" );
			}
			trans = "progid:DXImageTransform.Microsoft." + trans;
		}
		else { // Old IE 5 Browsers

			switch ( transNum ) {
				case 2: trans="blendTrans(duration="+d+")"; break;
				default: trans="revealTrans(duration="+d+",transition=" + Math.floor(Math.random()*23) + ")";
			}
		}
	}
	return trans;
}
//--------------- Image Library ---------------
function getRGB( abbrev ) {
	var rgb = abbrev;
	switch( abbrev ) {
		case "b": rgb = "0,0,0"; break;
		case "w": rgb = "255,255,255"; break;
	}
	var reRGB = /^\d{1,3},\d{1,3},\d{1,3}$/, badRGB = false;
	if( !reRGB.test( rgb ) ) badRGB = true;
	else {
		var Channels = rgb.split( "," );
		for( var i = 0; i < 3; i++ )
			if( parseInt( Channels[ i ] ) > 255 ) badRGB = true;
	}
	if( badRGB ) {
		reportError( "Errant Data", "Bad RGB value \"" + rgb + "\"" );
		rgb = "255,255,255";
	}
	return rgb;
}
//--------------- Image Library ---------------
function getOpacity( dissolveSF, dissolveMZ ) {
	var opac = "";
	if ( winIE ) opac = "visibility:hidden;";
	else if( MZ && dissolveMZ ) opac = "opacity:0;"
	else if ( SF && dissolveSF ) opac = "opacity:0;"
	return opac;
}
//--------------- Image Library ---------------
function startFade( FadeInPhoto, transNum, transDur, transDelay, dissolveSF, dissolveMZ ) {
	window.FadeInPhoto = FadeInPhoto;
	window.transNum = transNum;
	window.transDur = transDur;
	window.transDelay = transDelay;
	if( winIE ) setTimeout( "fadeInDirectX()", transDelay );
	else if( ( MZ && dissolveMZ ) || ( SF && dissolveSF ) ) {
		FadeInPhoto.onload = function() { /*cancel photo onload function*/ };
		( transDelay ) ? setTimeout( "fadeIn( FadeInPhoto )", transDelay ) : fadeIn( FadeInPhoto );
	}
	else {
		if( SF ) FadeInPhoto.style.opacity = 1.0;
		else FadeInPhoto.style.visibility = "visible";
	}
}
//--------------- Image Library ---------------
// call from startFade only, never call directly
function fadeInDirectX() {
	try {
		FadeInPhoto.style.filter = getTransition( transNum, transDur );
		FadeInPhoto.filters(0).apply();
		FadeInPhoto.style.visibility = "visible";
		FadeInPhoto.filters(0).play();
	}
	catch( Err ) {
		if( local ) {
			var eMsg = "Exception Caught in fadeInDirectX function:\n\n";
			for( var i in Err ) eMsg += i + ": " + Err[ i ] + "\n";
			alert( eMsg );
		}
		FadeInPhoto.style.visibility = "visible";
	}
}
//--------------- Image Library ---------------
// SF & MZ: Uses recursion, but if fadeDuration is longer that 1.5 sec (1500 ms) stop dissolving

GuiObj = null, fadeOpacity = 0, fadeOpacityTimer = 0, fadeStartTime = 0, dissolveOff = 0, opacityStep = .05;

function fadeIn( GuiObj ) {

	if( fadeStartTime == 0 && !dissolveOff ) {
		fadeStartTime = new Date().getTime();
		if( window.Settings && Settings.transDur )
			opacityStep = 1 / ( Settings.transDur / .04 );
	}

	if( dissolveOff ) fadeOpacity = .9999;

	if( MZ ) GuiObj.style.opacity = fadeOpacity;
	else GuiObj.style.opacity = fadeOpacity;

	if( !dissolveOff ) {
		this.fadeOpacity += opacityStep;
		if( fadeOpacity < 1 ) {
			window.GuiObj = GuiObj;
			fadeOpacityTimer = setTimeout( "fadeIn( GuiObj )", 40 );
		}
		else {
			if( MZ ) GuiObj.style.opacity = 0.9999;
			else GuiObj.style.opacity = 0.9999;
			clearTimeout( fadeOpacityTimer );
			GuiObj = null;
			fadeOpacity = 0;
			fadeOpacityTimer = 0;
			var fadeEndTime = new Date().getTime();
			var fadeDuration = fadeEndTime - fadeStartTime;
			if( fadeDuration > 1500 ) dissolveOff = 1;
			fadeStartTime = 0;
			//document.title = fadeDuration;
		}
	}
}

//--------------- Image Library ---------------
function dissolveDirectX( OldPhoto, newPhotoSrc, borderWid, borderCol, transNum, transDur ) {

	try {
		OldPhoto.style.filter = getTransition( transNum, transDur );
		OldPhoto.filters(0).apply();
		OldPhoto.src = newPhotoSrc;
		if( borderWid ) OldPhoto.style.borderColor = "rgb( " + getRGB( borderCol ) + " )";
		OldPhoto.filters(0).play();
	}
	catch( Err ) {
		if( local ) {
			var eMsg = "Exception Caught in dissolveDirectX function:\n\n";
			for( var i in Err ) eMsg += i + ": " + Err[ i ] + "\n";
			alert( eMsg );
		}
		OldPhoto.src = newPhotoSrc;
		if( borderWid ) OldPhoto.style.borderColor = "rgb( " + getRGB( borderCol ) + " )";
	}
}

//--------------- Image Library ---------------
function directX( OldPhoto, newPhotoSrc, borderWid, borderCol, transNum, transDur ) {

	try {
		OldPhoto.parentNode.style.filter = getTransition( transNum, transDur );
		OldPhoto.parentNode.filters(0).apply();
		OldPhoto.src = newPhotoSrc;
		if( borderWid ) OldPhoto.style.borderColor = "rgb( " + getRGB( borderCol ) + " )";
		OldPhoto.parentNode.filters(0).play();
	}
	catch( Err ) {
		if( local ) {
			var eMsg = "Exception Caught in directX function:\n\n";
			for( var i in Err ) eMsg += i + ": " + Err[ i ] + "\n";
			alert( eMsg );
		}
		OldPhoto.src = newPhotoSrc;
		if( borderWid ) OldPhoto.style.borderColor = "rgb( " + getRGB( borderCol ) + " )";
	}
}

//--------------- Image Library ---------------
function initImagesArr() {
	try { Images.length = Images.length - 1; }
	catch( Err ) {
		reportError( "Image Data Error", "ERROR: Images array cannot be initialized because:\n 1) Data file \"" + window.dataFile + "\" is non-existent; OR\n 2) The data it contains is malformed (bad syntax)" );
	}
}

//--------------- Image Library ---------------
fileNameErr = false;
function checkImgName( fileName ) {

	var rePattern = /\s+/g;

	if( !fileNameErr && rePattern.test( fileName ) ) {
		fileNameErr = true;
		reportError( "Image File Name Error", "ERROR: An image file name \"" + fileName + "\" contains forbidden white-space characters." );
	}
}

//--------------- Image Library ---------------
ImgReal = null; checkDimTimer = 0;
function checkDim( imgRealSrc, widDB, hgtDB ) {

	// Animated gifs can erroneously report widDB & hgtDB of 0 which causes false errors
	if( widDB > 0 && hgtDB > 0 ) {

		if( ImgReal == null ) {
			ImgReal = new Image();
			ImgReal.src = imgRealSrc;
		}
		if( ImgReal.complete ) {
			clearTimeout( checkDimTimer );
			var realWid = ImgReal.width, realHgt = ImgReal.height;
			if( realWid > 1 && realHgt > 1 && ( realWid != widDB || realHgt != hgtDB ) ) {
				var FileComponents = ImgReal.src.split( "/" );
				var fileName = FileComponents[ FileComponents.length - 1 ];
				var eMsg = "\"" + fileName + "\" has incorrect dimensions: \n  1) " + widDB + " x " + hgtDB + " are the errant values \n  2) " + realWid + " x " + realHgt + " are the true values";
				reportError( "Image Dimension Error", eMsg );
			}
			ImgReal = null;
		}
		else {
			clearTimeout( checkDimTimer );
			eval( "checkDimTimer = setTimeout( 'checkDim( \"" + imgRealSrc + "\", " + widDB + ", " + hgtDB + " )', 250 );" );
		}
	}

}

/////////////////////////////// END IMAGE LIBRARY FUNCTIONS ///////////////////////////////

// 1/18/2008
//////////////////////////////////////// START SLIDE SHOW: SS ////////////////////////////////////////

/*
VAR: qStr, local, winIE, MZ, SF
FUN: Image Library Functions
OBJ: DW
CLS: .ss*

NOTE: If images re-positions itself as SS plays in IE, try adjusting the pages table width's, table borders, and set css align to left. Seems to happen when setting border old way, ie: <table border="1"...
*/

//--------------------------------- OBJECT CONSTRUCTOR ---------------------------------

function SlideShow( popUp ) {

	initImagesArr();

	if( popUp ) {
		if( !AOL ) {
			window.moveTo( 0, 0 );
			window.resizeTo( screen.availWidth, screen.availHeight );
		}
	}

	this.userIsAdministrator = GetCookie( "userWithWritePrivileges" );
//this.userIsAdministrator = 1;
	this.popUp = popUp;
	this.slideNum = ( Settings.SS.randomStart && !this.userIsAdministrator ) ? Math.floor( Math.random() * Images.length ) : 0;
	this.nFirstSlide = this.slideNum;
	this.speedActual = Settings.SS.speed * 1000;
	this.automated = ( this.speedActual < 86400000 ); // 86400000 ms = 1 day
	this.SPEED_FAST = 500;
	this.preLoadTimer = 0;
	this.NextImage = null;
	this.slideDelay = 0;
	this.running = true;
	this.forward = true;
	this.buttons = false;
	this.dissolve = true;
	this.maxDissolveMZ = 1000 * 1000;
	this.maxImgWid = 0;
	this.maxImgHgt = 0;

	// Methods...
	this.changeSpeed = changeSpeed;
	this.init = init;
	this.start = start;
	this.showSlide = showSlide;
	this.skipErrantSlide = skipErrantSlide;
	this.preLoadNext = preLoadNext;
	this.imgClickHandler = imgClickHandler;
	this.back = back;
	this.next = next;
	this.showMsg = showMsg;
	this.getCoordinates = getCoordinates;
	this.repositionElements = repositionElements;
	this.pauseSS = pauseSS;
	this.getControls = getControls;
	this.getGUI = getGUI;
	window.onresize = this.repositionElements;
	this.rightClick = rightClick;
	this.setControlVisibility = setControlVisibility;

	this.msg = new Array();
	this.msg.ssRunning = "Slide Show Running...";
	this.msg.downloadingImg = "Preparing next slide...";
	this.msg.pleaseWait = "Downloading image, please wait...";
	this.msg.ssPaused = "Slide Show Paused, re-click \"Pause\" to continue...";
	this.msg.ssPausedSF = "Slide Show Paused, click \"Run\" to continue...";
	this.msg.next = ( this.automated ) ? "Jump forward" : "Next";
	this.msg.back = ( this.automated ) ? "Go back" : "Back";
	this.msg.ssExit = ( this.automated ) ? "Close this slide-show window" : "Close this pop-up window";
	//------------------------------------ METHOD: SS ------------------------------------
	// Called by body onMouseover/out (if any) in pop-up slide-show. Hides controls when mouse moved off-screen
	// Does not work in IE standards compliant mode

	function setControlVisibility( on ) {

		var SSButtons = document.getElementById( "SSButtons" );
		if( SSButtons )
			SSButtons.style.visibility = ( on ) ? "visible" : "hidden";

		var SSExitPopUp = document.getElementById( "SSExitPopUp" );
		if( SSExitPopUp )
			SSExitPopUp.style.visibility = ( on ) ? "visible" : "hidden";

	}

	//------------------------------------ METHOD: SS ------------------------------------
	// Called once on page load

	function start() {

		// While console is still hidden, place each photo-caption in it & read and set the height to the tallest one
		// Purpose is to keep content below SS from moving up/down as photo height changes
		if( Settings.SS.console ) {
			var Console = document.getElementById( "ssConsole" );
			var maxConsoleHgt = 0;
			for( var i = 0; i < Images.length; i++ ) {
				Console.innerHTML = ( Images[ i ][ 3 ] ) ? Images[ i ][ 3 ] : "X";
				var consoleHgt = Console.offsetHeight;
				if( consoleHgt > maxConsoleHgt )
					maxConsoleHgt = consoleHgt;
			}
			Console.style.height = maxConsoleHgt + "px";
		}

		this.repositionElements();

		this.showMsg();

		if( Settings.SS.console )
			Console.style.visibility = "visible";

		this.preLoadNext();
	}

	//------------------------------------ METHOD: SS ------------------------------------

	function getCoordinates( TheImage ) {

		// Get on screen position of overlay so we can lay new one on top
		var x = 0; var y = 0;
		TheElement = TheImage;
		var parPosAbs = false;
		while( TheElement ) {
			if( SF ) {
				if( !parPosAbs ) parPosAbs = ( TheElement.style.position == "absolute" );
				if( parPosAbs && TheElement == document.body ) break;
			}
			y += TheElement.offsetTop;
			x += TheElement.offsetLeft;
			TheElement = TheElement.offsetParent;
		}
		return[ x, y ];

	}
	//------------------------------------ METHOD: SS ------------------------------------

	function repositionElements() {

		// SS running as a pop-up, so programatically center SS-GUI horizontially & vertically
		if( SS.popUp ) {

			var IeBody = ( IE && document.compatMode == "CSS1Compat" ) ? document.documentElement : document.body;

			var bodyHgt = ( IE ) ? IeBody.clientHeight : window.innerHeight;
			var bodyWid = ( IE ) ? IeBody.clientWidth : window.innerWidth;

			var SsGui = document.getElementById( "SsGui" );
			var ssGuiHgt = SsGui.offsetHeight;
			var ssGuiWid = SsGui.offsetWidth;
			SsGui.style.position = "absolute";
			SsGui.style.top = parseInt( ( bodyHgt - ssGuiHgt ) / 2 ) + "px";
			SsGui.style.left = parseInt( ( bodyWid - ssGuiWid ) / 2 ) + "px";
			//SsGui.style.backgroundColor = "rgb( 204,204,204 )";

		}

		if( SS.ImgOverlay ) {
			var OverlayPos = SS.getCoordinates( document.images.slideShow.parentNode );
			SS.ImgOverlay.style.left = OverlayPos[ 0 ] + "px";
			SS.ImgOverlay.style.top = OverlayPos[ 1 ] + "px";
		}

	}

	//------------------------------------ METHOD: SS ------------------------------------
	function showSlide() {

		if( this.NextImage ) {

			this.showMsg();
			var TheImage = document.images.slideShow;
			var widNew = Images[ this.slideNum ][ 1 ];
			var hgtNew = Images[ this.slideNum ][ 2 ];
			var imgArea = widNew * hgtNew;

			checkDim( this.NextImage.src, widNew, hgtNew );

			////////// Dissolve: winIE, Mozilla & Safari //////////
			if( this.forward && this.dissolve && ( winIE || ( MZ && imgArea <= this.maxDissolveMZ ) || ( SF && Settings.dissolveSF ) ) && Settings.transNum >= 1 && this.speedActual > this.SPEED_FAST ) {

				var nNewImg = ( Images.length == this.slideNum ) ? 0 : this.slideNum;
				var nOldImg = ( nNewImg == 0 ) ? Images.length - 1 : nNewImg - 1;

				// Place image that was just showing on bottom
				TheImage.width = Images[ nOldImg ][ 1 ];
				TheImage.height = Images[ nOldImg ][ 2 ];
				TheImage.src = Settings.folder + Images[ nOldImg ][ 0 ];

				if( Settings.borderWid && Images[ nOldImg ][ 4 ] ) TheImage.style.borderColor = "rgb( " + getRGB( Images[ nOldImg ][ 4 ] ) + " )";

				var imgStyle = ( Settings.borderWid && Images[ nNewImg ][ 4 ] ) ? " style='border:" + Settings.borderWid + "px solid rgb(" + getRGB( Images[ nNewImg ][ 4 ] ) + ");'" : "";

				var newImg = "<img name='slideShowNew' src='" + Settings.folder + Images[ nNewImg ][ 0 ] + "' width='" + Images[ nNewImg ][ 1 ] + "' height='" + Images[ nNewImg ][ 2 ] + "' title='" + TheImage.title + "'" + imgStyle + " onmousedown='SS.imgClickHandler( event );' onContextMenu='return SS.rightClick( this, event );' class='ssImage'>";

				// Create overlay off-screen
				if( !SS.ImgOverlay ) {
					SS.ImgOverlay = document.createElement( "DIV" );
					SS.ImgOverlay.style.textAlign = "center";
					SS.ImgOverlay.style.top = ( screen.height * -1 ) + "px";
					SS.ImgOverlay.style.left = ( screen.width * -1 ) + "px";
					SS.ImgOverlay.style.zIndex = 1000;
					SS.ImgOverlay.style.position = "absolute";
					SS.ImgOverlay.style.backgroundColor = "rgb( " + Settings.SS.bkgColor + " )";
					document.body.appendChild( SS.ImgOverlay );
				}

				// Re-size overlay
				SS.ImgOverlay.style.width = this.maxImgWid + "px";
				SS.ImgOverlay.style.height = this.maxImgHgt + "px";

				// Make overlay transparent
				if( winIE ) SS.ImgOverlay.style.visibility = "hidden";
				if( MZ ) SS.ImgOverlay.style.opacity = 0;
				else SS.ImgOverlay.style.opacity = 0;

				// Move transparent overlay into position
				var OverlayPos = SS.getCoordinates( TheImage.parentNode );
				SS.ImgOverlay.style.left = OverlayPos[ 0 ] + "px";
				SS.ImgOverlay.style.top = OverlayPos[ 1 ] + "px";

				// Fade-in overlay
				SS.ImgOverlay.innerHTML = newImg;
				if( winIE ) startFade( SS.ImgOverlay, Settings.transNum, Settings.transDur, 0, 0, 0 );
				else fadeIn( SS.ImgOverlay );
			}

			else { // No transitions: going backwards
				if( this.ImgOverlay ) {
					document.body.removeChild( this.ImgOverlay );
					this.ImgOverlay = null;
				}
				TheImage.style.visibility = "hidden";
				TheImage.width = widNew;
				TheImage.height = hgtNew;
				if( Settings.borderWid && Images[ this.slideNum ][ 4 ] )
					TheImage.style.borderColor = "rgb( " + getRGB( Images[ this.slideNum ][ 4 ] ) + " )";
				TheImage.src = this.NextImage.src;
				TheImage.style.visibility = "visible";
			}

			this.dissolve = true;
			this.forward = true;

		}

	}
	//------------------------------------ METHOD: SS ------------------------------------
	function showMsg() {

		if( Settings.SS.console ) {

			var imgTitle = Images[ this.slideNum ][ 3 ];
			var colon = ( imgTitle ) ? ": " : "";
			var slideNumDisplay = this.slideNum - this.nFirstSlide + 1;
			if( slideNumDisplay < 1 ) slideNumDisplay = Images.length + slideNumDisplay;
			var slideCount = slideNumDisplay + " of " + Images.length

			if( imgTitle == "*" )
				imgTitle = Settings.pageTitle;
			else if( imgTitle.indexOf( "*+" ) == 0 )
				imgTitle = Settings.pageTitle + imgTitle.split( "+" )[ 1 ];
			else if( imgTitle.indexOf( "+*" ) >= 0 )
				imgTitle = imgTitle.split( "+" )[ 0 ] + Settings.pageTitle;
			else if( imgTitle == "_" )
				imgTitle = Images[ this.slideNum ][ 0 ];

			document.getElementById( "ssConsole" ).innerHTML = slideCount + colon + imgTitle;

		}
	}
	//------------------------------------ METHOD: SS ------------------------------------
	function skipErrantSlide() {
		if( local || SS.speedActual == SS.SPEED_FAST ) {
			if( !SS.errReported ) {
				alert( "Slide #" + ( SS.slideNum + 1 ) + "; " + SS.NextImage.src + " failed to load" );
				SS.errReported = true;
			}
		}
		SS.NextImage = null;
	}

	//------------------------------------ METHOD: SS ------------------------------------

	function preLoadNext() {

		var recursionTimer = 100;

		this.slideDelay += recursionTimer;

		if( !this.NextImage ) {

			if( this.SPEED_FAST != this.speedActual && this.forward )
				this.speedActual = Images[ this.slideNum ][ 5 ] * 1000;

			this.slideNum++;
			if( this.slideNum == Images.length ) this.slideNum = 0;
			this.NextImage = new Image();
			this.NextImage.onerror = this.skipErrantSlide;
			this.NextImage.src = Settings.folder + Images[ this.slideNum ][ 0 ];
		}

		if( this.NextImage && this.NextImage.complete && this.slideDelay > this.speedActual ) {
			this.slideDelay = 0;
			this.showSlide();
			this.NextImage = null;
			clearTimeout( this.preLoadTimer );
			this.preLoadNext();
			if( Settings.SS.controls && document.getElementById( "BackBut" ) )
				document.getElementById( "BackBut" ).disabled = false;
			if( Settings.SS.scrollSlide )
				window.scroll( Settings.SS.scrollSlide[ 0 ], Settings.SS.scrollSlide[ 1 ] );
		}
		else
			this.preLoadTimer = setTimeout( "SS.preLoadNext()", recursionTimer );

	}
	//------------------------------------ METHOD: SS ------------------------------------
	function imgClickHandler( e ) {

		if( !e ) e = window.event;

		if( e.ctrlKey || e.metaKey ) {
			if( this.speedActual == this.SPEED_FAST )
				this.speedActual = Settings.SS.speed * 1000;
			else
				this.speedActual = this.SPEED_FAST;
		}
		if( e.shiftKey ) {
			if( this.running )
				this.pauseSS( true );
			else
				this.pauseSS( false );
		}
	}
	//------------------------------------ METHOD: SS ------------------------------------

	function back()  {
		if( Settings.SS.console ) document.getElementById( "ssConsole" ).innerHTML = this.msg.pleaseWait;
		clearTimeout( this.preLoadTimer );
		this.forward = false;
		this.slideNum -= 3;
		if( this.slideNum == -2 ) this.slideNum = Images.length - 2;
		if( this.slideNum == -3 ) this.slideNum = Images.length - 3;
		this.NextImage = null;
		this.speedActual = Settings.SS.speed;
		this.pauseSS( false );
		if( Settings.SS.scrollToTopOnJump != -1 ) window.scroll( 0, Settings.SS.scrollToTopOnJump );
	}

	//------------------------------------ METHOD: SS ------------------------------------

	function next()  {
		if( Settings.SS.console ) document.getElementById( "ssConsole" ).innerHTML = this.msg.pleaseWait;
		clearTimeout( this.preLoadTimer );
		this.forward = true;
		this.speedActual = Settings.SS.speed;
		this.pauseSS( false );
		if( Settings.SS.scrollToTopOnJump != -1 ) window.scroll( 0, Settings.SS.scrollToTopOnJump );
	}
	//--------------------------------------------------------------------------------------

	function pauseSS( pause ) {

		var Button = ( this.buttons ) ? document.getElementById( "PauseBut" ) : null;
		var HighSpeed = document.getElementById( "HighSpeed" );
		if( HighSpeed && this.speedActual != this.SPEED_FAST ) {
			if( SF )
				HighSpeed.value = "Hi-Speed";
			else
				HighSpeed.className = "ssButton";
			HighSpeed.title = "Run at Hi-Speed";
		}

		if( pause ) {
			if( SF ) {
				if( Button ) Button.value = "Run";
			}
			else {
				if( Button ) Button.className = "ssButtonOn";
			}
			clearTimeout( this.preLoadTimer );
			this.running = false;
			if( Button ) Button.title = "Resume";
		}
		else {
			this.slideDelay = Settings.SS.speed * 1000 + 1;
			this.preLoadNext();
			if( Button ) {
				if( SF ) Button.value = "Pause";
				Button.className = "ssButton";
				Button.title = "Pause";
			}
			this.running = true;
		}
		if( window.DW ) DW.removeWin();
	}

	//------------------------------------ METHOD: SS ------------------------------------

	function changeSpeed( Button ) {

		if( this.speedActual == this.SPEED_FAST ) {
			SS.speedActual = Settings.SS.speed * 1000;
			if( SF )
				Button.value = "Hi-Speed";
			else
				Button.className = "ssButton";
			Button.title = "Run at Hi-Speed";
		}

		else {
			this.speedActual = this.SPEED_FAST;
			if( SF )
				Button.value = "Lo-Speed";
			else
				Button.className = "ssButtonOn";
			Button.title = "Revert to normal speed";
		}
		this.forward = true;
		this.pauseSS( false );

	}
	//------------------------------------ METHOD: SS ------------------------------------

	function getControls() {

		this.buttons = true;

		htm =

		"<input type='button' id='BackBut' class='ssButton' value='&lt;&lt;' onClick='SS.back();' title='" + this.msg.back + "'>&nbsp;";

		if( this.automated ) htm +=
			"&nbsp;<input name='PauseBut' class='ssButton' id='PauseBut' type='button' value='Pause' onClick='SS.speedActual = Settings.SS.speed; SS.pauseSS( ( ( SS.running ) ? true : false ) );' title='Pause'" + ( ( SF ) ? " style='width:60px;'" : "" ) +">&nbsp;";

		if( this.userIsAdministrator )
			htm += "&nbsp;<input id='HighSpeed' class='ssButton' type='button' value='Hi-Speed' onClick='SS.changeSpeed( this );' title='Run at Hi-Speed'" + ( ( SF ) ? " style='width:80px;'" : "" ) +">&nbsp;";

		htm +=
			"&nbsp;<input type='button' id='NextBut' class='ssButton' value='&gt;&gt;' onClick='SS.next();' title='" + this.msg.next + "'>";

		return htm;
	}

	//------------------------------------ METHOD: SS ------------------------------------
	// Called one time by getGUI just before onLoad.
	// Tip: When setting up a custom SS (no buttons & w/o calling getGUI) mimic html table structure defined in getGUI method

	function init() {
		var maxWid = -1, maxHgt = -1, bordWid = Settings.borderWid * 2;

		//sets image border-color if undefined & set longest photo caption
		for( var i = 0; i < Images.length; i++ ) {
			if( Images[ i ][ 1 ] > maxWid ) maxWid = Images[ i ][ 1 ];
			if( Images[ i ][ 2 ] > maxHgt ) maxHgt = Images[ i ][ 2 ];
			if( Images[ i ][ 3 ] )
				Images[ i ][ 3 ] = Images[ i ][ 3 ].replace( /\^/g, "\"" ).replace( /\[/g, "<div class='ssCaptionOtherLines'>" ).replace( /]/g, "</div>" );
			if( !Images[ i ][ 4 ] ) Images[ i ][ 4 ] = Settings.borderCol;
			if( !Images[ i ][ 5 ] ) Images[ i ][ 5 ] = Settings.SS.speed;
			checkImgName( Images[ i ][ 0 ] );
		}
		this.maxImgWid = maxWid + bordWid;
		this.maxImgHgt = maxHgt + bordWid;
	}

	//------------------------------------ METHOD: SS ------------------------------------

	function rightClick( Photo, evt ) {

		if( this.userIsAdministrator ) {
			SS.speedActual = Settings.SS.speed;
			this.pauseSS( true );
			var nImages = Images.length;
			var indexNum = ( this.slideNum > 0 ) ? this.slideNum - 1 : nImages - 1;
			var Img = Images[ indexNum ];
			var wid = Img[ 1 ], hgt = Img[ 2 ], tnWid = -1, tnHgt = -1, longestEdge = 150;

			var shape = ( wid > hgt ) ? "horizontal" : ( ( wid < hgt ) ? "vertical" : "square" );

			if( shape == "horizontal" ) {
				tnWid = longestEdge;
				tnHgt = parseInt( hgt * longestEdge / wid );
			}
			else {
				tnWid = parseInt( wid * longestEdge / hgt );
				tnHgt = longestEdge;
			}
			var fileSize = Photo.fileSize;
			if( fileSize ) fileSize = Math.round( fileSize / 1000 ) + " KB";

			var htm = "" +

			"<table align='left' border='0' cellspacing='0' cellpadding='0'>" +
				"<tr>" +
					"<td align=center valign=top>" +
						"<img src='" + Photo.src + "' width='" + tnWid + "' height='" + tnHgt + "'>" +
					"</td>" +
					"<td align=center valign=top style='padding:4px;'>" +
						"<table align='center' border='0' cellspacing='0' cellpadding='0' class='dwText'>" +
							"<tr><td align=right>Name:&nbsp;</td><td align=left>" + Img[ 0 ] + "</td></tr>" +
							"<tr><td align=right>Number:&nbsp;</td><td align=left>" + ( ( this.slideNum > 0 ) ? this.slideNum : nImages ) + " of " + Images.length + "</td></tr>" +
							"<tr><td align=right>Dimensions:&nbsp;</td><td align=left>" + wid + " &times; " + hgt + " px; " + shape + "</td></tr>" +
							( ( fileSize ) ? "<tr><td align=right valign=top>File Size:&nbsp;</td><td align=left>" + fileSize + "</td></tr>" : "" ) +
							( ( typeof Img[ 3 ] == "string" ) ? "<tr><td align=right valign=top> Caption:&nbsp;</td><td align=left>" + Img[ 3 ] + "</td></tr>" : "" ) +
							"<tr><td align=left colspan=2>Slide-Show paused, <a href='javascript:SS.dissolve=false; SS.pauseSS( false );' class='dwLink'>click here</a> to resume</td></tr>" +
						"</table>" +
					"</td>" +
				"</table>";

			DW.createWindow( [ "Image Properties", htm ], [ 0, 500, 0 ], Photo, evt );

			return false;
		}
		else
			return ( Settings.disableRightClick ) ? false : true;

	}

	//------------------------------------ METHOD: SS ------------------------------------

	function getGUI( guiAlign, consoleLoc, buttonsLoc ) {

		this.init();
		var imgStyle = ( Settings.borderWid && Images[ this.slideNum ][ 4 ] ) ? " style='border-color:rgb(" + getRGB( Images[ this.slideNum ][ 4 ] ) + ");'" : "";
		var img1Title = ( Images[ 0 ][ 3 ] ) ? Images[ 0 ][ 3 ].replace( /\^/g, "\"" ) : "";

		var console = "", buttons = "";

		// Initialize with longest title because console height is measured & set permanently using it
		if( Settings.SS.console )
			console =
			"<tr>" +
				"<td align='center'>" +
					// Never let console width exceed largest image width
					"<div class='ssCaption' id='ssConsole' style='visibility:hidden; width:" + this.maxImgWid + "px;'>X</div>" +
				"</td>" +
			"</tr>";

		if( Settings.SS.controls )
			buttons =
			"<tr id='SSButtons'>" +
				"<td align='center'>" +
					"<div class='ssControls' style='white-space:nowrap;'>" +
						SS.getControls() +
					"</div>" +
				"</td>" +
			"</tr>";

		var htm =

		"<table align='" + guiAlign + "' border='0' cellspacing='0' cellpadding='0' id='SsGui' class='ssGUI'>";

		if( Settings.pageTitle )
			htm +=
			"<tr>" +
				"<td align='center'>" +
					"<div class='ssTnTitle'>" +
						Settings.pageTitle +
					"</div>" +
				"</td>" +
			"</tr>";

			if( buttonsLoc == "above" )
				htm += buttons;

			if( consoleLoc == "above" )
				htm += console;

		// imageConsoleHeightIsFixed normally set to 1 to keep buttons from jumping up & down w/ varying image heights

			htm +=
			"<tr>" +
				"<td valign='top' align='center'>" +
					"<table align='center' border='0' cellspacing='0' cellpadding='0'>" +
						"<tr>" +
							"<td valign='top'>" +
								"<table align='center' border='0' cellspacing='0' cellpadding='0'>" +
									"<tr>" +
										"<td align='center' valign='top' style='width:" + this.maxImgWid + "px;" + ( ( Settings.SS.imageConsoleHeightIsFixed ) ? " height:" + this.maxImgHgt + "px;" : "" ) + "'>" +
											"<img name='slideShow' src='" + Settings.folder + Images[ this.slideNum ][ 0 ] + "' onError='SS.skipErrantSlide(); SS.preLoadNext(); this.slideDelay = this.speedActual + 1;' width='" + Images[ this.slideNum ][ 1 ] + "' height='" + Images[ this.slideNum ][ 2 ] + "' title='Slide-Show' onmousedown='SS.imgClickHandler( event );'" + imgStyle + " galleryimg='no' onAbort='this.src=this.src;' class='ssImage' onContextMenu='return SS.rightClick( this, event );'>" +
										"</td>" +
									"</tr>";

								if( consoleLoc == "below" )
									htm += console;

								if( buttonsLoc == "below" )
									htm += buttons;

								htm +=
								"</table>" +
							"</td>" +
						"</tr>" +
					"</table>" +
				"</td>" +
			"</tr>" +
		"</table>";

		if( this.popUp )
			htm += "<div style='position:absolute; top:0%; right:1%; margin:10px 15px 0px 0px;' id='SSExitPopUp'><a href='javascript:void(0);' onClick='window.close(); return false;' onMouseover='this.title=SS.msg.ssExit;' class='ssExitPopUp'>Exit</a></div>";

		return htm;
	}

}

///////////////////////////////////////// END SLIDE SHOW: SS ////////////////////////////////////////


///////////////////////////////// BEGIN COOKIE FUNCTIONS /////////////////////////////////

function getCookieDomain() {

	var cookieDomain = null;
	if( live && theHost ) {
		var Host = theHost.split( "." ), hLen = Host.length;
		if( hLen >= 2 )
			cookieDomain = "." + Host[ hLen - 2 ] + "." + Host[ hLen - 1 ];
	}
	return cookieDomain;

}
//--------------- Cookie Library ---------------

function getCookieVal( offset ) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//--------------- Cookie Library ---------------
function GetCookie( name ) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

//--------------- Cookie Library ---------------
//                  req,  req,  optional
function SetCookie( name, value, expires ) {
	var path = "/", domain = getCookieDomain(), secure = null;
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//--------------- Cookie Library ---------------
function DeleteCookie( name ) {
	var path = "/", domain = getCookieDomain();
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//--------------- Cookie Library: String Prototype ---------------
//                       req,  req,       opt
function recordToCookie( key, value, CookieExpDate ) {

	var cookieName = this.toString();
	var data = GetCookie( cookieName ); if( !data ) data = "";

	// In unlikely event user input special delimiters, replace them english definitions
	value = value.replace( /&/g, "and" ).replace( /=/g, "is" );

	// Split old cookie data
	var KeyVals = data.split( "&" );
	var existingKey = 0;

	// Scan old cookie data. If key already exists then update the value it contains
	for( var i = 0; i < KeyVals.length; i++ ) {
		var ThisPair = KeyVals[ i ].split( "=" );
		if( key == ThisPair[ 0 ] ) {
			if( value ) // Set new value
				KeyVals[ i ] = key + "=" + value;
			else // value is empty string so remove this entry
				KeyVals.splice( i, 1 );
			data = KeyVals.join( "&" );
			existingKey = 1;
			break;
		}
	}

	// Otherwise, existing key does not exist so append new key/value pair to end of string
	if( value && !existingKey )
		data += ( ( data ) ? "&" : "" ) + key + "=" + value;

	if( data )
		SetCookie( cookieName, data, ( ( CookieExpDate ) ? CookieExpDate : null ) );
	else
		DeleteCookie ( cookieName );

	// alert( GetCookie( cookieName ) );
}
String.prototype.recordToCookie = recordToCookie;

var expDate12Mon = new Date();
expDate12Mon.setTime ( expDate12Mon.getTime() + ( 24 * 60 * 60 * 365 * 1000 ) ); // 1 year

///////////////////////////////// END COOKIE FUNCTIONS /////////////////////////////////

function getEmailLink( subject ) {

	if( subject )
		subject = "?subject=" + escape( subject );

	return "<a href='mailto:" + DB.Contact.Email + subject + "' title='Send us an e-mail' class='dwLink'>" + DB.Contact.Email + "</a>";
}
//--------------------------------------------------------------------------------------
function largePic( cap, wid, hgt, Link, evt ) {

	if( window.DW ) {
		DW.createWindow( [ cap, "imgSrc=" + Link.href ], [ 0, wid, hgt ], Link, evt );
		return false;
	}
	else
		return true;
}

//---------------------------------------------------------------------------------------

function showHawaiiTime() {

	var gmtOffset = 10; // for Hawaii
	var now = new Date();
	var difhrs = now.getTimezoneOffset()/60;
	var lochrs = now.getHours();
	GMThours = lochrs + difhrs;
	now.setHours( GMThours - gmtOffset );

	var am_pm = "AM";
	var hours = now.getHours();

	if( hours >= 12 ) am_pm = "PM";
	if( hours >= 13 ) hours -= 12;
	if( hours == 0 ) hours = "12";

	var minutes = now.getMinutes();
	if( minutes < 10 ) minutes = "0" + minutes;

	var seconds = now.getSeconds();
	if( seconds < 10 ) seconds = "0" + seconds;
	try{
		document.getElementById( "hawaii_time" ).innerHTML = hours + ":"  + minutes + ":"  + seconds + " " + am_pm;
	}
	catch( Err ) {}
	finally{ setTimeout( "showHawaiiTime()", 1000 ); }
}

///////////////////////////////// DYNAMIC WINDOW DW /////////////////////////////////
/*
	ACCESSOR VARS:  IE, MZ, SF, winIE
	ACCESSOR FUNC:  None
	ACCESSOR CLASS: dw*, off
*/

//--------------------------------- OBJECT CONSTRUCTOR DW ---------------------------------

function DynamicWindow( transNum, transDur ) {

	var htm =

	"<div>" +
		"<table align='center' border='0' cellspacing='0' cellpadding='0' class='contactUs'>" +

			"<tr>" +
				"<td valign='top' align='right'>" +
					"<div style='margin:0px 0px 0px 0px;' class='noWrap'>Name:</div>" +
				"</td>" +
				"<td valign='top'>" +
					"<div style='margin:0px 0px 0px 6px;'>" + DB.Contact.Name + "</div>" +
				"</td>" +
			"</tr>" +

			"<tr>" +
				"<td>" +
					"<div style='margin:4px 0px 0px 6px;'>" + DB.Contact.Address1 + "<br>" + DB.Contact.Address2 + "</div>" +
				"</td>" +
			"</tr>" +

			"<tr>" +
				"<td valign='top' align='right'>" +
					"<div style='margin:4px 0px 0px 0px;' class='noWrap'>Primary Tel:</div>" +
				"</td>" +
				"<td>" +
					"<div style='margin:4px 0px 0px 6px;'>" + DB.Contact.PhonePrimary + "</div>" +
				"</td>" +
			"</tr>";

			if( DB.Contact.PhoneOther ) htm +=

			"<tr>" +
				"<td valign='top' align='right'>" +
					"<div style='margin:4px 0px 0px 0px;' class='noWrap'>Other Tel:</div>" +
				"</td>" +
				"<td>" +
					"<div style='margin:4px 0px 0px 6px;'>" + DB.Contact.PhoneOther + "</div>" +
				"</td>" +
			"</tr>";

			htm +=
		

			"<tr>" +
				"<td align='right'>" +
					"<div style='margin:4px 0px 0px 0px;' class='noWrap'>Send E-Mail:</div>" +
				"</td>" +
				"<td>" +
					"<div style='margin:4px 0px 0px 6px;'>" + getEmailLink( "Haena Beach Hale Web-Site Inquiry" ) + "</div>" +
				"</td>" +
			"</tr>" +

		"</table>" +
	"</div>";

	this.ContactUs = [ "Contact Us", htm ];

	// Editable Settings
	this.dissolveMZ = 1;
	this.dissolveSF = 1;
	this.addImageOverlay = 1;
	this.gDisableContextImgMenu = 1;

	this.Msg = new Array();
	this.Msg.fullSize = "View this image full-size";


	// Do not edit past this line -------------------------
	if( GetCookie( "userWithWritePrivileges" ) ) this.gDisableContextImgMenu = 0;
	window.gClickPos = null;
	this.maxDissolve = 1000 * 1000;
	this.transNum = ( transNum ) ? transNum :   2;
	this.transDur = ( transDur ) ? transDur : 0.8;

	// Variables
	this.dWinOffsetX = 0;
	this.dWinOffsetY = 0;
	this.Window = null;
	this.overTitleBar = false;
	this.Photo = null;
	this.disableContextImgMenu = false;
	this.TheBody = null;

	// Methods
	this.createWindow = createWindow;
	this.showImg = showImg;
	this.keepInWin = keepInWin;
	this.getClickPosition = getClickPosition;
	this.getData = getData;
	this.loadingImage = loadingImage;
	this.mouseDown = mouseDown;
	this.mouseMove = mouseMove;
	this.removeWin = removeWin;
	this.mouseUp = mouseUp;

	document.onmousedown = this.mouseDown;
	document.onmousemove = this.mouseMove;
	document.onmouseup = this.mouseUp;

	//------------------------------------- METHOD DW -------------------------------------

	//                     req      req     opt      opt       opt         opt           opt
	function createWindow( dataSrc, WinDim, TheLink, theEvent, bodyMargin, RequestedPos, disableContextImgMenu ) {

		this.TheBody = ( document.compatMode && document.compatMode != "BackCompat" ) ? document.documentElement : document.body;

		if( TheLink ) TheLink.blur();

		if( !bodyMargin ) bodyMargin = 0;
		this.disableContextImgMenu = ( typeof disableContextImgMenu == "boolean" ) ? disableContextImgMenu : this.gDisableContextImgMenu;

		var Data = getData( dataSrc, TheLink ), title, body;

		title = Data[ 0 ].replace( /\^\^/g, "'" );
		title = title.replace( /\^/g, "\"" );
		body = Data[ 1 ].replace( /\^\^/g, "'" );
		body = body.replace( /\^/g, "\"" );

		// Read vals from 3-member WindowDimension, if image then get wid/hgt from tag
		var showImg = ( body.indexOf( "imgSrc=" ) == 0 );
		// overflow:auto creates vert scroll bars if content does not fit
		var scrollStyle = ( WinDim[ 0 ] ) ? " overflow:auto;" : "";
		var winWid = WinDim[ 1 ];
		var winHgt = WinDim[ 2 ];

		// Read vals from optional 4-member RequestedPosition
		var clickPos       = ( RequestedPos ) ? ( RequestedPos[ 0 ] == 1 ) : true;
		var aboveClkPos    = ( RequestedPos ) ? ( RequestedPos[ 0 ] == 2 ) : false;
		var topCent        = ( RequestedPos ) ? ( RequestedPos[ 0 ] == 3 ) : false;
		var center         = ( RequestedPos ) ? ( RequestedPos[ 0 ] == 4 ) : false;
		var botCent        = ( RequestedPos ) ? ( RequestedPos[ 0 ] == 5 ) : false;
		var xOffset        = ( RequestedPos ) ? RequestedPos[ 1 ] : 0;
		var yOffset        = ( RequestedPos ) ? RequestedPos[ 2 ] : 10;

		if( showImg ) {
			var mzDissolve = ( MZ && this.dissolveMZ && ( winWid * winHgt <= this.maxDissolve ) );
			var sfDissolve = ( SF && this.dissolveSF );

			// Create image tag
			var body = "<img src='" + body.split( "imgSrc=" )[ 1 ] + "' width='" + winWid + "' height='" + winHgt + "' border='0' hspace='0' vspace='0' galleryimg='no' style='" + getOpacity( sfDissolve, mzDissolve ) + "' onload='DW.showImg( this );' onAbort='this.src=this.src;'" + ">";

			this.title = title; // Store actual title

			var loading = "Loading Image<span id='dot1' class='dotOff'>.</span><span id='dot2' class='dotOff'>.</span><span id='dot3' class='dotOff'>.</span><span id='dot4' class='dotOff'>.</span>";

			// Multi-line title
			if( title.indexOf( "[" ) != -1 ) {
				title = title.replace( /^.*?\[/, loading + "[" );
				title = title.replace( /\[/g, "<div class='dwTitleLine2Off'>" );
				title = title.replace( /]/g, "</div>" );
			}
			// Single-line title
			else
				title = loading;
		}

		var Window = document.getElementById( "dWinID" );
		if( Window ) document.body.removeChild( Window );

		var NewWindow = document.createElement( "DIV" ), scrollSt, bodyHgtSt;

		bodyHgtStyle = ( winHgt ) ? " height:" + winHgt + "px;" : "";
		NewWindow.id = "dWinID";
		NewWindow.className = "dwWin";
		document.body.appendChild( NewWindow );
		NewWindow.style.visibility = "hidden"
		NewWindow.style.position = "absolute";
		NewWindow.style.width = ( IE && document.compatMode != "CSS1Compat" ) ? ( winWid + 2 * parseInt( NewWindow.currentStyle[ "borderWidth" ] ) ) + "px" : winWid + "px";
		NewWindow.style.top = ( screen.height * -1 ) + "px";
		NewWindow.style.left = ( screen.width * -1 ) + "px";
		NewWindow.style.zIndex = 10000;

		var myWindow = "" +

		"<div class='dwTitleRow' id='dwTitleRowID'>" +
			"<table align='center' border='0' cellspacing='0' cellpadding='0'>" +
				"<tr>" +
					"<td class='dwTitle' style='width:100%; text-align:center;' onmouseover='DW.overTitleBar=true;' onmouseout='DW.overTitleBar=false;' id='dwTitleTd1ID'>" +
						"<div id='dwTitleBarID'>" +
							title +
						"</div>" +
					"</td>" +
					"<td valign='top' id='dwTitleTd2ID'>" +
						"<a href='javascript:DW.removeWin();' onMouseOver='self.status=this.title; return true;' onMouseOut='self.status=\"\"; return true;' title='Close' class='dwX'>&times;</a>" +
					"</td>" +
				"</tr>" +
			"</table>" +
		"</div>" +

		"<div class='" + ( ( showImg ) ? "dwBodyParentImg" : "dwBodyParent" ) + "' style='width:100%;" + bodyHgtStyle + scrollStyle + "'>" +
			"<div class='dwBody' id='dwBodyID' style='margin:" + bodyMargin + "px;'>" +
				body +
			"</div>" +
		"</div>";

		NewWindow.innerHTML = myWindow;
		var xPos = 0, yPos = 0;

		if( clickPos || aboveClkPos ) {

			if( theEvent )
				var ClickPos = this.getClickPosition( theEvent );
			// If null it allows for successive pop-ups to be based on original click position
			else if( window.gClickPos )
				var ClickPos = gClickPos;

			window.gClickPos = ClickPos;
			xPos = ClickPos[ 0 ];

			var vPortWid = ( document.body.clientWidth ) ? document.body.clientWidth : window.innerWidth;
			var skew = Math.round( 100 * xPos / vPortWid ) / 100;
			xPos = xPos - ( skew * NewWindow.offsetWidth );

			// 1) Place at click position & add offset (if any)
			if( clickPos )
				yPos = ClickPos[ 1 ] + yOffset;

			// 2) Place above click position & add offset (if any)
			else
				yPos = ClickPos[ 1 ] - NewWindow.offsetHeight + yOffset;

		}

		// 3, 4 or 5) vAlign: Top center (3), Center (4) or Bot Center (5)
		else if( topCent || center || botCent ) {

			var scrollX, scrollY, bodyWid, bodyHgt;

			if( IE ) {
				scrollX = this.TheBody.scrollLeft;
				scrollY = this.TheBody.scrollTop;
				bodyWid = this.TheBody.clientWidth;
				bodyHgt = this.TheBody.clientHeight;
			}
			else {
				scrollX = window.pageXOffset;
				scrollY = window.pageYOffset;
				bodyWid = window.innerWidth;
				bodyHgt = window.innerHeight;
			}

			winHgt = NewWindow.offsetHeight;
			winWid = NewWindow.offsetWidth;

			xPos = parseInt( ( bodyWid - winWid ) / 2 + scrollX + xOffset );
			if( topCent ) yPos = parseInt( scrollY + yOffset );
			else if( center ) yPos = parseInt( ( bodyHgt - winHgt ) / 2 + scrollY + yOffset );
			else yPos = parseInt( bodyHgt - winHgt + scrollY + yOffset );

		}
		else { // RequestedPos[ 0 ] = 10 - 17: Places window around a component

			var Component = document.getElementById( RequestedPos[ 3 ] );
			var CurComponent = Component;
			var parPosAbs = false;
			while( CurComponent ) {
				if( SF ) {
					if( !parPosAbs ) parPosAbs = ( CurComponent.style.position == "absolute" );
					if( parPosAbs && CurComponent == Body ) break;
				}
				yPos += CurComponent.offsetTop;
				xPos += CurComponent.offsetLeft;
				CurComponent = CurComponent.offsetParent;
			}

			switch( RequestedPos[ 0 ] ) {


				case 10: // above left
					xPos += xOffset;
					yPos -= NewWindow.offsetHeight - yOffset;
					break;

				case 11: // above right
					xPos += Component.offsetWidth + xOffset;
					yPos -= NewWindow.offsetHeight - yOffset;
					break;

				case 12: // right top
					xPos += Component.offsetWidth + xOffset;
					yPos += yOffset;
					break;

				case 13: // right bottom
					xPos += Component.offsetWidth + xOffset;
					yPos += Component.offsetHeight + yOffset;
					break;

				case 14: // below right
					xPos += xOffset;
					yPos += Component.offsetHeight + yOffset;
					break;

				case 15: // below left
					xPos += Component.offsetWidth + xOffset - NewWindow.offsetWidth;
					yPos += Component.offsetHeight + yOffset;
					break;

				case 16: // left below
					xPos += xOffset - NewWindow.offsetWidth;
					yPos += Component.offsetHeight + yOffset;
					break;

				case 17: // left top
					xPos += xOffset - NewWindow.offsetWidth;
					yPos += yOffset;
					break;

				default:
					alert( "Switch/Case Error at DW.createWindow: RequestedPos[ 0 ] has a value of " + RequestedPos[ 0 ] + " which is invalid." );

			}
		}

		var NewWindowPos = this.keepInWin( NewWindow, xPos, yPos );
		xPos = Math.round( NewWindowPos[ 0 ] );
		yPos = Math.round( NewWindowPos[ 1 ] );

		NewWindow.style.left = xPos + "px";
		NewWindow.style.top  = yPos + "px";


		if( showImg && this.addImageOverlay ) {

			window.onscroll = function() {
				var Overlay = document.getElementById( "dwOverlay" );
				if( Overlay ) document.body.removeChild( Overlay );
			}

			var Overlay = document.createElement( "DIV" );
			Overlay.id = "dwOverlay";
			Overlay.className = "dwOverlay";

			Overlay.onclick = function( event ) {
				document.body.removeChild( this );
			}

			document.body.appendChild( Overlay );

			// Add overlay
			try {
				// Modified 10/29/2007
				//Overlay.style.width  = ( IE ) ? this.TheBody.clientWidth + "px" : this.TheBody.scrollWidth + "px";
				//Overlay.style.height = ( IE ) ? this.TheBody.clientHeight + "px" : this.TheBody.scrollHeight + "px";

				var wid = ( this.TheBody.scrollWidth > this.TheBody.clientWidth ) ? this.TheBody.scrollWidth : this.TheBody.clientWidth;
				var hgt = ( this.TheBody.scrollHeight > this.TheBody.clientHeight ) ? this.TheBody.scrollHeight : this.TheBody.clientHeight;
				Overlay.style.width  = wid + "px";
				Overlay.style.height = hgt + "px";
			}
			catch( Err ) {
				document.body.removeChild( Overlay );
			}
		}


		NewWindow.style.visibility = "visible";

		if( showImg )
			this.loadingImage();

	}

	//------------------------------------- METHOD DW -------------------------------------

	function loadingImage() {

		var Dot1 = document.getElementById( "dot1" );
		var Dot2 = document.getElementById( "dot2" );
		var Dot3 = document.getElementById( "dot3" );
		var Dot4 = document.getElementById( "dot4" );

		if( Dot1 && Dot2 && Dot3 && Dot4 ) {
			if( Dot1.className == "dotOff" )
				Dot1.className = "dotOn";
			else if( Dot2.className == "dotOff" )
				Dot2.className = "dotOn";
			else if( Dot3.className == "dotOff" )
				Dot3.className = "dotOn";
			else if( Dot4.className == "dotOff" )
				Dot4.className = "dotOn";
			else {
				Dot1.className = "dotOff";
				Dot2.className = "dotOff";
				Dot3.className = "dotOff";
				Dot4.className = "dotOff";
			}
			setTimeout( "DW.loadingImage()", 300 );
		}
	}

	//------------------------------------- METHOD DW -------------------------------------

	function showImg( Photo ) {

		Photo.onclick = DW.removeWin;
		Photo.oncontextmenu = function() { if( DW.disableContextImgMenu ) return false; };
		Photo.title = "Click to close";
		Photo.style.cursor = ( IE ) ? "hand" : "pointer";

		try {
			checkDim( Photo.src, Photo.width, Photo.height );

			var title = this.title;
			title = title.replace( /\[/g, "<div class='dwTitleLine2'>" ).replace( /]/g, "</div>" );
			document.getElementById( "dwTitleBarID" ).innerHTML = title;

			var mzDissolve = ( MZ && this.dissolveMZ && ( Photo.width * Photo.height <= this.maxDissolve ) );
			var sfDissolve = ( SF && this.dissolveSF );

			startFade( Photo, this.transNum, this.transDur, 0, sfDissolve, mzDissolve );
		}
		catch( Err ) {
			self.status = "Exception thrown at method DW.showImg...";
		}

	}

	//------------------------------------- METHOD DW -------------------------------------

	function keepInWin( NewWindow, leftEdge, topEdge ) {

		var bodyHgt = ( IE ) ? this.TheBody.clientHeight : window.innerHeight;
		var bodyWid = ( IE ) ? this.TheBody.clientWidth : window.innerWidth;

		// Prevent window from going off bottom & top of page
		var winHgt = NewWindow.offsetHeight;
		var yOffset = ( IE ) ? this.TheBody.scrollTop : window.pageYOffset;
		var vScreenPos = topEdge - yOffset;
		var vSkew = bodyHgt - vScreenPos;
		if( vSkew < winHgt + 10 ) topEdge -= winHgt - vSkew + 10; // bottom edge
		else if( vScreenPos < 10 ) topEdge = 10 + yOffset; // top edge

		// Prevent window from going off right & left edges
		var winWid = NewWindow.offsetWidth;
		var xOffset = ( IE ) ? this.TheBody.scrollLeft : window.pageXOffset;
		var hScreenPos = leftEdge - xOffset;
		var hSkew = bodyWid - hScreenPos;
		if( hSkew < winWid + 10 ) { // right edge
			leftEdge -= winWid - hSkew + 10;
			// Vert scroll bar is present
			if( !IE && this.TheBody.scrollHeight > bodyHgt ) leftEdge -= 15;
		}
		else if( hScreenPos < 10 ) leftEdge = 10 + xOffset; // left edge

		return[ leftEdge, topEdge ];
	}
	//------------------------------------- METHOD DW -------------------------------------

	function getClickPosition( theEvent ) {

		try {
			if( IE ) {
				var x = event.clientX + this.TheBody.scrollLeft;
				var y = event.clientY + this.TheBody.scrollTop;
			}
			else {
				var x = theEvent.pageX;
				var y = theEvent.pageY;
			}
		}
		// Catch exceptions when action does not create an event, like when
		// creating window from MZ selecting pull-down
		catch( err ) {
			var x = 0;
			var y = 0;
		}

		return[ x, y ];
	}
	//------------------------------------- METHOD DW -------------------------------------

	function getData( dataSrc, TheLink ) {

		// Get the data...
		if( dataSrc == "nextSibling" ) {

			// If we have old innerHTML then put it back where it belongs
			if( eval( "typeof this.LastSrc" ) == "object" )
				eval( "this.LastSrc.innerHTML = this.lastData" );

			try {
				var DataSource = ( TheLink.nextSibling.innerHTML ) ? TheLink.nextSibling : TheLink.nextSibling.nextSibling;
			}
			catch( err ) { alert( "EXCEPTION: Data source not found" ); return false; }

			try {
				var Title = ( DataSource.firstChild.innerHTML ) ? DataSource.firstChild : DataSource.firstChild.nextSibling;
				var title = Title.innerHTML;
			}
			catch( err ) { alert( "EXCEPTION: Title source not found" ); return false; }

			try {
				var Body = ( Title.nextSibling.innerHTML ) ? Title.nextSibling : Title.nextSibling.nextSibling;
				var body = Body.innerHTML;
			}
			catch( err ) { alert( "EXCEPTION: Body source not found" ); return false; }

			// Record this Source as Object & record innerHTML
			eval( "this.LastSrc = DataSource" );
			eval( "this.lastData = DataSource.innerHTML" );
			DataSource.innerHTML = "";

		}
		else {
			var title = dataSrc[ 0 ];
			var body  = dataSrc[ 1 ];
		}

		return[ title, body ];

	}

	//------------------------------------- METHOD DW -------------------------------------
	// Record x & y offset within dWin and set this.Window
	function mouseDown( e ) {

		if( DW.overTitleBar ) {

			this.Window = document.getElementById("dWinID");

			if( IE ) {
				this.dWinOffsetX = event.offsetX;
				this.dWinOffsetY = event.offsetY;
			}
			else {
				this.dWinOffsetX = e.layerX;
				this.dWinOffsetY = e.layerY;
				return false;
			}
		}
	}

	//------------------------------------- METHOD DW -------------------------------------

	function mouseMove( e ) {
		if( this.Window ) {

			var ClickPos = DW.getClickPosition( e );
			// Don not let user move menu off left or top edge of screen
			if( ClickPos[ 0 ] <= 0 ||  ClickPos[ 1 ] <= 0 ) {
				this.Window = null;
				return false;
			}

			if( IE ) {
				if( event.button != 1 ) return false; // mouse moved off screen
				this.Window.style.left = ( event.clientX - this.dWinOffsetX + DW.TheBody.scrollLeft ) + "px";
				this.Window.style.top = ( event.clientY - this.dWinOffsetY + DW.TheBody.scrollTop ) + "px";
				return false;
			}

			else {
				this.Window.style.top = ( e.pageY - this.dWinOffsetY ) + "px";
				this.Window.style.left = ( e.pageX - this.dWinOffsetX ) + "px";
			 }
		 }
	}

	//------------------------------------- METHOD DW -------------------------------------

	// called by x only or clicking photo. Do not remove inner HTML by setting it to an empty string
	function removeWin() {
		var Window = document.getElementById( "dWinID" );
		if( Window ) document.body.removeChild( Window );
		var Overlay = document.getElementById( "dwOverlay" );
		if( Overlay ) document.body.removeChild( Overlay );

	}

	//------------------------------------- METHOD DW -------------------------------------

	function mouseUp() { this.Window = null; }

}

////////////////////////////////// END DYNAMIC WINDOW //////////////////////////////////

//////////////////////////// START OPEN BROWSER WIN: PopUp ////////////////////////////

/*
ACCESSOR VAR: None
ACCESSOR FUN: None
*/

function PopUp() {

	this.winName = "HaenaBeachHaleWin";
	this.PrinterFriendlyContactInfo = null;
	this.printerFriendlyCss = "code/agents-printer-friendly.css";

	// Do not edit past this line -------------------------
	this.Win = null;
	this.openWin = openWin;
	this.printerFriendly = printerFriendly;
	this.closeWin = closeWin;
	this.linkToWin = linkToWin;

	//------------------------------------ METHOD: PopUp ------------------------------------

	//                req,  opt,  opt,  opt,  opt,  opt,  opt,  opt,   opt,    opt,
	function openWin( url, wWid, wHgt, wPos, tBar, lBar, sBar, mBar, scBar, reSize ) {

		this.closeWin();

		if( typeof wWid == "undefined" ) wWid = .8;
		if( typeof wHgt == "undefined" ) wHgt = .6;
		if( typeof wPos == "undefined" ) wPos = 1;
		if( typeof tBar == "undefined" ) tBar = 1;
		if( typeof lBar == "undefined" ) lBar = 1;
		if( typeof sBar == "undefined" ) sBar = 1;
		if( typeof mBar == "undefined" ) mBar = 1;
		if( typeof scBar == "undefined" ) scBar = 1;
		if( typeof reSize == "undefined" ) reSize = 1;

		var avWid = screen.availWidth - 10;
		var avHgt = screen.availHeight - 30;

		if( wWid < 1 ) wWid = wWid * avWid;
		if( wHgt < 1 ) wHgt = wHgt * avHgt;

		if( wWid > avWid * 0.90 || wWid == 1 ) wWid = avWid * 0.90;
		if( wHgt > avHgt * 0.70 || wHgt == 1 ) wHgt = avHgt * 0.70;

		var leftPos = 0;
		var topPos = 0;

		switch( wPos ) {
			case 1: // top middle
				leftPos = parseInt( ( avWid - wWid ) / 2 );
				break;

			case 2: // center middle
				leftPos = parseInt( ( avWid - wWid ) / 2 );
				topPos =  parseInt( ( avHgt - wHgt ) / 2 );
				break;
		}

		this.Win = window.open(url,PopUp.winName,"toolbar="+tBar+",location="+lBar+",directories=0,status="+sBar+",menubar="+mBar+",scrollbars="+scBar+",resizable="+reSize+",width="+wWid+",height="+wHgt+",top="+topPos+",left="+leftPos);

	}

	//------------------------------------ METHOD: PopUp ------------------------------------
	// Classes are pf*
	// Explicitily define pf sections w/ ids of pfContent1,2,3,etc and/or hide sections by setting them with pfHide class (display:none) defined in printer-friendly.css file only

	//                        opt           opt
	function printerFriendly( removeImages, ExcludedPfContentSections ) {

		// Got excluded sections so set class to pfHide, which is only defined in printer-friendly.css
		if( ExcludedPfContentSections ) {
			for( var i = 0; i < ExcludedPfContentSections.length; i++ ) {
				if( document.getElementById( ExcludedPfContentSections[ i ] ) )
					document.getElementById( ExcludedPfContentSections[ i ] ).className = "pfHide";
			}
		}

		var nTitle = 1;
		var pageTitle = "";
		while( document.getElementById( "pfTitle" + nTitle ) ) {
			pageTitle += document.getElementById( "pfTitle" + nTitle ).innerHTML + " ";
			// Remove hyperlinks
			pageTitle = pageTitle.replace( /<a\s.*?>/gi , "" );
			pageTitle = pageTitle.replace( /<\/a.*?>/gi , "" );
			nTitle++;
		}

		var pfPageTitle = ( pageTitle ) ? pageTitle : document.title;

		var htm =
		"<html>" +
			"<head>" +
				"<title>" + document.title + "</title>" +
				"<link rel='stylesheet' href='" + this.printerFriendlyCss + "' type='text\/css'>" +
			"</head>";
			htm += ( live ) ? "<body onLoad='if( window.print ) window.print();'>" : "<body>";
			htm +=
			"<div class='pfTitle'>" + pfPageTitle + "</div>" +
			"<div class='pfOtherData'>" + theHost;

			if( this.PrinterFriendlyContactInfo ) {
				for( var i = 0; i < this.PrinterFriendlyContactInfo.length; i++ ) {
					htm += this.PrinterFriendlyContactInfo[ i ][ 0 ] + eval( this.PrinterFriendlyContactInfo[ i ][ 1 ] ) + this.PrinterFriendlyContactInfo[ i ][ 2 ];
				}
			}

			htm += "</div>";

			var nContent = 1;
			outer:
			while( document.getElementById( "pfContent" + nContent ) ) {

				var content = document.getElementById( "pfContent" + nContent ).innerHTML;

				// Remove hyperlinks
				content = content.replace( /<a\s.*?>/gi , "" );
				content = content.replace( /<\/a.*?>/gi , "" );

				if( removeImages )
					content = content.replace( /<img\s.*?>/gi , "" );

				// Get rid all script sections as they may cause js errors since include files not present
				content = content.replace( /<script[\d\D]*?<\/script>/gi , "" );
				htm += content;
				nContent++;
			}

			if( document.getElementById( "pfFooter" ) )
				htm += "<p class='pfFooter'>" + document.getElementById( "pfFooter" ).innerHTML + "</p>";

			htm +=
			"</body>" +
		"</html>";


		if( nContent > 1 ) {
			this.closeWin();
			this.openWin( "", 1 );
			this.Win.document.write( htm );
			this.Win.document.close();
		}
		else
			reportError( "Error at PopUp.printerFriendly", "No printer friendly sections (pfContent*) found..." );

		// Got excluded sections so set class to pfShow, which is only defined in printer-friendly.css
		if( ExcludedPfContentSections ) {
			for( var i = 0; i < ExcludedPfContentSections.length; i++ ) {
				if( document.getElementById( ExcludedPfContentSections[ i ] ) )
					document.getElementById( ExcludedPfContentSections[ i ] ).className = "pfShow";
			}
		}
	}
	//------------------------------------ METHOD: PopUp ------------------------------------

	function closeWin() {
		try {
			if( this.Win && this.Win.open && !this.Win.closed ) {
				this.Win.close();
				this.Win = null;
			}
		}
		catch( e ) {}
	}
	//------------------------------------ METHOD: PopUp ------------------------------------

	function linkToWin() {
		if( PopUp && PopUp.Win && PopUp.Win.registered ) {
			if( PopUp.Win.MyOpener != self ) PopUp.Win.MyOpener = self;
		}
		else setTimeout( "PopUp.linkToWin()", 250 );
	}
}

PopUp = new PopUp();

////////////////////////////// END OPEN BROWSER WIN: PopUp /////////////////////////////



///////////////////////////////// Begin Object FileWriter FW /////////////////////////////////

function FileWriter() {

	// Notes & Buttons can be customized on a per client basis

	////////// 1) HTML //////////
	this.HtmNotes = "A couple tips to remember..." +
	"<ol>" +
		"<li>Just Published but don't see your changes? Then press Reload</li>" +
		"<li>Completely hosed a page? Go to Help &rarr; Restore</li>" +
	"</ol>";

	// Edit html buttons
	this.HtmButtons =
	"<button onClick='FW.insertTags( \"<br>\", \"\", \"EditedHTML\" ); return false;' title='Inserts line-break tag at cursor position' class='htmlTags'>&lt;br&gt;</button>" +

	"<button onClick='FW.insertTags( \"<b>\", \"</b>\", \"EditedHTML\" ); return false;' title='Inserts bold tags around highlighted text' class='htmlTags'><b>B</b></button>" +

	"<button onClick='FW.insertTags( \"<i>\", \"</i>\", \"EditedHTML\" ); return false;' title='Inserts italic tags around highlighted text' class='htmlTags'><i>I</i></button>";



		////////// 2) JS	 //////////

		this.JsNotes = "";

		this.JsButtons = ( fileName == "ss.aspx" ) ? "<button onClick='FW.insertTags( \"[\\\"\\\",750,500,\\\"\\\"],\", \"\", \"EditedJS\" ); return false;' title='Insert new blank data structure at cursor position' class='htmlTags'>Add New Data Structure</button> &nbsp;" : "<button onClick='FW.insertTags( \"[\\\"\\\",420,280],\", \"\", \"EditedJS\" ); return false;' title='Insert new blank data structure at cursor position' class='htmlTags'>Add New Data Structure</button> &nbsp;";

		this.JsButtons +=	"<button onClick='FW.insertTags( \"\\\\\\\"\", \"\\\\\\\"\", \"EditedJS\" ); return false;' title='Surrounds text you have highlighted with double quotes' class='htmlTags'>\\\"Escape\\\"</button>";

		var dim = ( fileName == "ss.aspx" ) ? "500 pixels high" : "exactly 420 &times; 280 pixels";

		this.JsNotes = "The Images Array below controls the photos that show on the slide-show and ALL these images must be sized to " + dim + ". Need help? Here's <a href='javascript:PopUp.openWin( \"http://www.davidregier.com/webdesign/other/images.html?ss=ss\" );' class='fw' title='Preparing images for the Slide-Show'>instructions</a> on preparing images for your slide-show." +

		"<ol>" +

			"<li>Right-click a photo to get image-properties & pause the slide-show.</li>" +

			"<li>To add a new photo you will first prepare & <a href='javascript:PopUp.openWin( \"uploader.aspx\", 650, 300, 2, 0, 0, 0, 0, 0, 0 );' title='Upload files to the server' class='fw'>upload</a> the large image per the instructions above.</li>" +

			"<li>Then enter a new blank line at the position you would like your new photo to appear.</li>" +

			"<li>With your cursor at the beginning of the new line, click the \"Add New Data Structure\" button. A blank data structure is auto-inserted.</li>" +

			"<li>Fill out the photo information. From left to right it is: (1) Photo Filename, within double quotes. (2) Photo width in pixels. (3) Photo height in pixels." + ( ( fileName == "ss.aspx" ) ? " (4) Description, if none, leave blank (empty double quotes)." : "" ) + "</li>";

			if( fileName == "ss.aspx" ) this.JsNotes +=
				"<li>On rare occasions, you may need to use double quotes w/i the Description (4th field). If so, you must first \"escape the text\" you are quoting. Here's how: (1) Highlight the text you would like quoted. (2) Click Escape.</li>";

	this.JsNotes +=
	"</ol>";

	////////// 3) XML //////////
	this.XmlNotes =

	"<div class='underline'>Here's why you may need to edit this XML data:</div>" +
	"<ol>" +

		"<li>Change contact information like Name, Address, Phone, etc.</li>" +

		"<li>To change Administrator Names, E-mails, Passwords & Editing Privileges" +
			"<ol class='fSize10' type='a'>" +
				"<li>Set it to yes to allow administrator to edit that particular data type</li>" +
				"<li>Set it to no to prohibit administrator from editing that particular data type</li>" +
			"</ol>" +
		"</li>" +

		"<li>To add new administrators. There are several blank administrator records for you. Anytime you need to add a new administrator just fill one out & publish, here's some tips:" +
			"<ol class='fSize10' type='a'>" +
				"<li>Give each new administrator a completely new & unique password.</li>" +
				"<li>By setting the editing-privileges (for each of the data types) to &ldquo;no&rdquo;, the new administrator can only edit the calendar. They will not see the HTML, JavaScript or XML text boxes.</li>" +
				"<li>Set subscribe-to-calendar-updates to &ldquo;yes&rdquo; to receive an e-mail update whenever the calendar is published.</li>" +
				"<li>Set subscribe-to-send-mail-list to &ldquo;yes&rdquo; to be included in the read-all pop-up email list.</li>" +
			"</ol>" +
		"</li>" +

		"<li>To change number of past & future months calendar will show, values must be whole numbers.</li>" +

		"<li>To change calendar read-all password.</li>" +

		"<li>To change e-mail address where website generated error messages (if any) are delivered.</li>" +

	"</ol>";

	// Additional admin links (if any) otherwise set empty str
	this.AdminLinks =  " &#149; <a href='javascript:PopUp.openWin( \"uploader.aspx\", 650, 300, 2, 0, 0, 1, 0, 0, 0 );' title='Upload files to the server' class='fw'>Upload</a>";

	// Do not edit past this line -------------------------
	this.forceLogin = forceLogin;
	this.forceLogin();
	this.getLogInGUI = getLogInGUI;
	this.logIn = logIn;
	this.recordPW = recordPW;
	if( qStr && qStr.getVal( "user" ) && qStr.getVal( "pw" ) && !qStr.getVal( "ms" ) )
		document.location.replace( document.location.href + "&ms=" + new Date().getTime() );
	if( !GetCookie( "userWithWritePrivileges" ) ) return;

	// Methods
	this.dataUnmodified = dataUnmodified;
	this.help = help;
	this.showHelp = showHelp;
	this.restore = restore;
	this.insertTags = insertTags;
	this.init = init;
	this.checkContent = checkContent;
	this.resetUI = resetUI;
	this.reLoad = reLoad;
	this.logOff = logOff;

	this.cursorReadyHtm = false;
	this.cursorReadyJS = false;
	this.init();


	//------------------------------------- Method FW -------------------------------------

	function forceLogin() {

		try	{
			// Only true if user tries to log-in while another administrator is already logged in
			if( window.LastAdministrator ) {

				var lastAdminFull = LastAdministrator[ 0 ];
				var loggedIn = new Date( LastAdministrator[ 1 ] ).toLocaleString();

				// SF/Mac Mail chokes on single quotes in sub or body

				var sub = "Are you logged onto " + theHost + " right now?";
				sub = ( SF ) ? sub : escape( sub );

				var body = "\r\n\r\n" + lastAdminFull + ", are you logged onto the site as Administrator right now? I am trying to log-in and I am getting a warning indicating you logged-in on " + loggedIn + " and are still logged in!\r\nThe current time on my computer is " + new Date().toLocaleString();
				body = ( SF ) ? body : escape( body );

				var htm = "<div class='fwForceLogin'>" +

					"Hello " + qStr.getVal( "user" ).replace( /_/g, " " ) + ". " + lastAdminFull + " logged in on " + loggedIn + ". " + lastAdminFull + " is either presently logged in or may have failed to log-out!<br><br>" +

					"In order to protect the integrity of our data, two or more users editing the same data at the same time is prohibited. With that in mind, you can:" +

				 "<ol style='margin-top:6px; margin-bottom:6px;'>" +

						"<li style='margin-bottom:2px;'>Wait until " + lastAdminFull + " logs out.</li>" +

						"<li style='margin-bottom:2px;'>Email " + lastAdminFull + " at <a href='mailto:" +  DB.Administrators[ lastAdminFull ] + "?subject=" + sub + "&body=" + body + "' title='Send e-mail asking if this person is logged-in' class='dwLink'>" + DB.Administrators[ lastAdminFull ] + "</a> to ask.</li>" +

						( ( fileName == "calendar.aspx" ) ? "<li style='margin-bottom:2px;'><a href='calendar.aspx?pw=" + rapw + "' title='You can read-all booking info but you cannot edit it' class='dwLink'>Load the calendar</a> with read-all access, because you only need to get info not edit it...</li>" : "" ) +

						"<li><a href='" + document.location.href + "' onClick='SetCookie( \"forcedLogin\", \"yes\" ); return true;' title='Logs you in & forces out other active administrator (if any)' class='dwLink'>Force Log-In</a> now because you know that " + lastAdminFull + " failed to log-out last time and is NOT actively logged-in. Note that you will terminate " + lastAdminFull + "'s session if logged-in right now.</li>" +

				 "</ol>" +

			 "</div>";

				DW.createWindow( [ "Concurrent Administrator Conflict", htm ], [0,540,0], null, null, 6, [4,0,0] );
			}
		}

		catch( Err ) {
			if( local ) {
				var err = "";
				for( member in Err ) err += member + ": " + Err[ member ] + "\n";
				alert( "Exception at method FW.forceLogin:\n\n" + err );
			}
			else {
				setTimeout( "FW.forceLogin();", 250 );
				self.status = "Initializing File Writer: FW.forceLogin()...";
			}
		}

	}

	//------------------------------------- Method FW -------------------------------------

	function showHelp( Link ) {

		var PlsMin = Link.previousSibling;
		var Content = Link.nextSibling;

		if( Content.className == "fw1" ) {
			Content.className = "fw0";
			PlsMin.innerHTML = "+";
		}
		else {
			Content.className = "fw1";
			PlsMin.innerHTML = "-";
		}
	}

	//------------------------------------- Method FW -------------------------------------

	function help( nType, Link, evt ) {

		// sub function
		function getHelpTxt( helpType ) {

			var htm =

			"<div class='fwHelpSect'>" +
				"<a href='javascript:void(0)' onClick='FW.showHelp(this.nextSibling);' class='fwPlusMinus'>+</a><a href='javascript:void(0);' onClick='FW.showHelp(this);' class='dwLink'>Reload & Cache</a>" +
				"<div class='fw0'>" +

					"<u>Cache Defined</u>: All browsers seamlessly store all recent pages that you have visited on your hard drive. This process is called \"caching\" and it greatly speeds up your web browsing because your browser is able to later retrieve these web pages off your hard drive much quicker than downloading them again from the server.<br><br>" +

					"<u>Caching will cause problems for you</u> because after you press Publish, and the page reloads, you may be looking at a past cached version of that page rather than the most recent version which you just published and are naturally expecting to see.<br><br>" +

					"<u>Remember this mantra</u> & you will eliminate cache frustrations forever!<br>" +
					"&nbsp;&nbsp;\"Just Published but don't see your changes? Then press Reload\"" +
				"</div>" +
			"</div>" +

			"<div class='fwHelpSect'>" +
				"<a href='javascript:void(0)' onClick='FW.showHelp(this.nextSibling);' class='fwPlusMinus'>+</a><a href='javascript:void(0);' onClick='FW.showHelp(this);' class='dwLink'>Publish " + helpType + "</a>" +
				"<div class='fw0'>" +
					"Press Publish-" + helpType + " after you have made your edits. Your changes will be permanently written to file and the page will be reloaded. After the page reloads, verify your changes. If you don't see them press Reload.";

					if( helpType == "XML" )
						htm += " Changes made to XML data update across entire site immediately";

					htm +=
				"</div>" +
			"</div>" +

			"<div class='fwHelpSect'>" +
				"<a href='javascript:void(0)' onClick='FW.showHelp(this.nextSibling);' class='fwPlusMinus'>+</a><a href='javascript:void(0);' onClick='FW.showHelp(this);' class='dwLink'>Reset</a>" +
				"<div class='fw0'>" +
					"Press Reset if you made edit(s) but then changed your mind or you just want to start over! The content in the text-box will revert back to original start-up values since you last published." +
				"</div>" +
			"</div>" +

			"<div class='fwHelpSect'>" +
				"<a href='javascript:void(0)' onClick='FW.showHelp(this.nextSibling);' class='fwPlusMinus'>+</a><a href='javascript:void(0);' onClick='FW.showHelp(this);' class='dwLink'>Restore</a>" +
				"<div class='fw0'>" +

					"Restore is the ultimate \"safety net\" and more powerful that reset because it let's you go back to an earlier date & time. If you made a mistake, which you only realized after publishing, then try restore." +

					"<div align='center' style='margin:4px 0px 0px 0px;'><form>";
						if( helpType == "HTML" ) {
							var BackUpHTM = document.AspForm.BackUpHTM;

							htm += "<input type='button' value='Restore To:' onClick='return FW.restore( \"RestoreHTM\" );' title='Restore this file to a prior selected time' />&nbsp;&nbsp;";

							htm += "<select id='BackUpHTM_PopUp' title='Select a prior restore point'>";

							if( BackUpHTM.length > 1 ) {
								for( var i = 0; i < BackUpHTM.length; i++ )
									htm += ( i == 0 ) ?  "<option value='" + BackUpHTM[ i ].value + "'>Undo Restore</option>" : "<option value='" + BackUpHTM[ i ].value + "'" + ( ( i == 1 ) ? " selected='selected'" : "" ) + ">" + i + ". " + BackUpHTM[ i ].text + "</option>";
							}
							else
								htm += "<option value=''>" + BackUpHTM[ 0 ].text + "</option>";

							htm += "</select>";
						}
						else if( helpType == "JavaScript" ) {
							var BackUpJS = document.AspForm.BackUpJS;

							htm += "<input type='button' value='Restore To:' onClick='return FW.restore( \"RestoreJS\" );' title='Restore this file to a prior selected time' />&nbsp;&nbsp;";

							htm += "<select id='BackUpJS_PopUp' title='Select a prior restore point'>";

							if( BackUpJS.length > 1 ) {
								for( var i = 0; i < BackUpJS.length; i++ )
									htm += ( i == 0 ) ?  "<option value='" + BackUpJS[ i ].value + "'>Undo Restore</option>" : "<option value='" + BackUpJS[ i ].value + "'" + ( ( i == 1 ) ? " selected='selected'" : "" ) + ">" + i + ". " + BackUpJS[ i ].text + "</option>";
							}
							else
								htm += "<option value=''>" + BackUpJS[ 0 ].text + "</option>";

							htm += "</select>";
						}
						else {
							var BackUpXML = document.AspForm.BackUpXML;

							htm += "<input type='button' value='Restore To:' onClick='return FW.restore( \"RestoreXML\" );' title='Restore this file to a prior selected time' />&nbsp;&nbsp;";

							htm += "<select id='BackUpXML_PopUp' title='Select a prior restore point'>";

							if( BackUpXML.length > 1 ) {
								for( var i = 0; i < BackUpXML.length; i++ )
									htm += ( i == 0 ) ?  "<option value='" + BackUpXML[ i ].value + "'>Undo Restore</option>" : "<option value='" + BackUpXML[ i ].value + "'" + ( ( i == 1 ) ? " selected='selected'" : "" ) + ">" + i + ". " + BackUpXML[ i ].text + "</option>";
							}
							else
								htm += "<option value=''>" + BackUpXML[ 0 ].text + "</option>";

							htm += "</select>";
						}
					htm += "</form></div>" +

					"<ol style='margin-top:4px; margin-bottom:4px;'>" +

						"<li style='margin-left:-10px;'>Select a restore date. They will be listed & numbered with the most recent at the top. The date & times reported are based on the server's time zone.</li>" +

						"<li style='margin-left:-10px;'>If you don't know which date to select, try the immediate prior backup. It will be #1 and selected for you by default. \"Restore To\" the selected date & time. If that doesn't help try #2, #3 and so on...</li>" +

						"<li style='margin-left:-10px;'>After restoring, if it appears the problem is not resolved, first press reload before doing another restore.</li>" +

						"<li style='margin-left:-10px;'>The restore process itself is completely reversible and you can go back in time, then come forward again. After performing restore(s), you can even come right back to where you began by restoring to &ldquo;Undo Restore&rdquo; from the top of the list.</li>" +

					"</ol>" +
				"</div>" +
			"</div>" +

			"<div class='fwHelpSect'>" +
				"<a href='javascript:void(0)' onClick='FW.showHelp(this.nextSibling);' class='fwPlusMinus'>+</a><a href='javascript:void(0);' onClick='FW.showHelp(this);' class='dwLink'>About " + helpType + "</a>" +
				"<div class='fw0'>";

					if( helpType == "HTML" )
						htm += "<ol style='margin-top:4px; margin-bottom:4px;'><li style='margin-left:-10px;'>HTML (<b>H</b>yper <b>T</b>ext <b>M</b>arkup <b>L</b>anguage) is a web formating language: <a href='javascript:PopUp.openWin( \"http://en.wikipedia.org/wiki/Html\" );' class='dwLink'>Learn more</a></li><li style='margin-left:-10px;'>Need help with your HTML skills? Try <a href='javascript:PopUp.openWin( \"http://www.w3schools.com/html/html_primary.asp\" );' class='dwLink'>W3schools.com</a></li></ol>";

					else if( helpType == "JavaScript" )
						htm += "JavaScript is a popular web programming language: <a href='javascript:PopUp.openWin( \"http://en.wikipedia.org/wiki/JavaScript\" );' class='dwLink'>Learn more</a>";

					else
						htm += "XML (e<b>X</b>tensible <b>M</b>arkup <b>L</b>anguage) is a web data-base language: <a href='javascript:PopUp.openWin( \"http://en.wikipedia.org/wiki/Xml\" );' class='dwLink'>Learn more</a>";

				htm +=
				"</div>" +
			"</div>";

			return htm;
		}

		var DataSrc;

		switch( nType ) {

			case 1:
				DataSrc = [ "Publishing HTML", getHelpTxt( "HTML" ) ];
				break;

			case 2:
				DataSrc = [ "Publishing JavaScript", getHelpTxt( "JavaScript" ) ];
				break;

			case 3:
				DataSrc = [ "Publishing XML", getHelpTxt( "XML" ) ] ;
				break;

		}

		if( window.DW ) DW.createWindow( DataSrc, [1,600,300], Link, evt, 6, [2,0,-15] );
	}

	//------------------------------------- Method FW -------------------------------------

	function restore( aspJob ) {

		var Form = document.AspForm;

		if(
				aspJob == "RestoreHTM" && Form.BackUpHTM && Form.BackUpHTM[ Form.BackUpHTM.selectedIndex ].value == "" ||
				aspJob == "RestoreJS" && Form.BackUpJS && Form.BackUpJS[ Form.BackUpJS.selectedIndex ].value == "" ||
				aspJob == "RestoreXML" && Form.BackUpXML && Form.BackUpXML[ Form.BackUpXML.selectedIndex ].value == ""
			) {
			alert( "No action taken: There are no restore dates..." );
			return false;
		}

		switch( aspJob ) {
			case "RestoreHTM": Form.BackUpHTM.selectedIndex = document.getElementById( "BackUpHTM_PopUp" ).selectedIndex; break;
			case "RestoreJS": Form.BackUpJS.selectedIndex = document.getElementById( "BackUpJS_PopUp" ).selectedIndex; break;
			case "RestoreXML": Form.BackUpXML.selectedIndex = document.getElementById( "BackUpXML_PopUp" ).selectedIndex; break;
			default: alert( "Switch/Case Error at FW.restore" );
		}

		Form.ASP_Job.value = aspJob;
		Form.submit();
	}
	//------------------------------------- Method FW -------------------------------------


	function insertTags( tagOpen, tagClose, TextBoxID ) {

		var editHTML = ( TextBoxID == "EditedHTML" );
		var editDATA = !editHTML;

		if( this.cursorReadyHtm && editHTML || this.cursorReadyJS && editDATA ) {

			var TextArea = document.getElementById( TextBoxID );

			if( IE ) {
				var theSelection = document.selection.createRange().text;
				TextArea.focus();
				if( theSelection.charAt(theSelection.length - 1) == " " ) { // exclude ending space char, if any
					theSelection = theSelection.substring(0, theSelection.length - 1);
					document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
				}
				else
					document.selection.createRange().text = tagOpen + theSelection + tagClose;

			}

			else {
				var replaced = false;
				var startPos = TextArea.selectionStart;
				var endPos = TextArea.selectionEnd;
				if( endPos - startPos )
					replaced = true;

				var scrollTop = TextArea.scrollTop;

				var myText = (TextArea.value).substring(startPos, endPos );

				if( myText.charAt(myText.length - 1 ) == " " ) // exclude ending space char, if any
					subst = tagOpen + myText.substring(0, ( myText.length - 1 ) ) + tagClose + " ";
				else
					subst = tagOpen + myText + tagClose;

				TextArea.value = TextArea.value.substring(0, startPos ) + subst +
					TextArea.value.substring(endPos, TextArea.value.length );
				TextArea.focus();

				if( replaced ) {
					var cPos = startPos+( tagOpen.length + myText.length + tagClose.length );
					TextArea.selectionStart = cPos;
					TextArea.selectionEnd = cPos;
				}
				else {
					TextArea.selectionStart = startPos + tagOpen.length;
					TextArea.selectionEnd = startPos + tagOpen.length + myText.length;
				}
				TextArea.scrollTop = scrollTop;

			}
			// reposition cursor if possible
			if( TextArea.createTextRange )
			TextArea.caretPos = document.selection.createRange().duplicate();
		}
		else {
			if( !tagClose )
				alert( "To auto-insert you must place your cursor at the location where you are inserting into." );
			else
				alert( "To auto-insert you must first highlight the text you would like formatted." );
		}

	}
	//------------------------------------- Method FW -------------------------------------

	function init() {

		var help = "About Caching, Reload, Publish, Reset & Restore";
		var justPub = "Refresh page to override cached (old) version";
		try	{

			var EditContainerHTM = document.getElementById( "EditContainerHTM" );

			// Init HTML Section
			if( EditContainerHTM && EditContainerHTM.className == "on" ) {

				// Title, Notes & Buttons can each be overloaded on a per-page basis (if needed)
				var HtmTitle = document.getElementById( "HtmTitle" );
				if( HtmTitle.innerHTML == "" ) HtmTitle.innerHTML = "HTML CONTENT FOR THIS PAGE";

				var HtmNotes = document.getElementById( "HtmNotes" );
				if( HtmNotes.innerHTML == "" ) HtmNotes.innerHTML = this.HtmNotes;

				var HtmButtons = document.getElementById( "HtmButtons" );
				if( HtmButtons.innerHTML == "" ) HtmButtons.innerHTML = this.HtmButtons;

				var EditedHTML = document.getElementById( "EditedHTML" );
				EditedHTML.onfocus = function() {
					this.title = "Edit text then press \"Publish HTML\"";
					self.status = this.title;
					FW.cursorReadyHtm = true;
				}
				EditedHTML.onblur = function() { self.status=""; }

				var HelpHTM = document.getElementById( "HelpHTM" );
				HelpHTM.onmouseover = function() { this.title = help; }

				var ReloadHTM = document.getElementById( "ReloadHTM" );
				ReloadHTM.onmouseover = function() { this.title = justPub; }
				ReloadHTM.onclick = function() { FW.reLoad( "EditedHTML" ); }

				var PublishHTM = document.getElementById( "PublishHTM" );
				PublishHTM.onmouseover = function() { this.title = "Save HTML"; }
				PublishHTM.onclick = function() { return FW.checkContent( 1 ); }

				var ResetHTM = document.getElementById( "ResetHTM" );
				ResetHTM.onmouseover = function() { this.title = "Revert HTML back to original values since you last published"; }
				ResetHTM.onclick = function() { FW.resetUI( "EditedHTML" ); }
			}

			// Init JS Section
			var EditContainerJS = document.getElementById( "EditContainerJS" );
			if( EditContainerJS && EditContainerJS.className == "on" ) {

				// Title, Notes & Buttons can each be overloaded on a per-page basis (if needed)
				var JsTitle = document.getElementById( "JsTitle" );
				if( JsTitle.innerHTML == "" ) JsTitle.innerHTML = "JAVASCRIPT DATA";

				var JsNotes = document.getElementById( "JsNotes" );
				if( JsNotes.innerHTML == "" ) JsNotes.innerHTML = this.JsNotes;

				var JsButtons = document.getElementById( "JsButtons" );
				if( JsButtons.innerHTML == "" ) JsButtons.innerHTML = this.JsButtons;

				var EditedJS = document.getElementById( "EditedJS" );
				EditedJS.onfocus = function() {
					this.title = "Edit data then press \"Publish JavaScript\"";
					self.status = this.title;
					FW.cursorReadyJS = true;
				}
				EditedJS.onblur = function() { self.status=""; }

				var HelpJS = document.getElementById( "HelpJS" );
				HelpJS.onmouseover = function() { this.title = help; }

				var ReloadJS = document.getElementById( "ReloadJS" );
				ReloadJS.onmouseover = function() { this.title = justPub; }
				ReloadJS.onclick = function() { FW.reLoad( "EditedJS" ); }

				var PublishJS = document.getElementById( "PublishJS" );
				PublishJS.onmouseover = function() { this.title = "Save JavaScript"; }
				PublishJS.onclick = function() { return FW.checkContent( 2 ); }

				var ResetJS = document.getElementById( "ResetJS" );
				ResetJS.onmouseover = function() { this.title = "Revert JavaScript back to original values since you last published"; }
				ResetJS.onclick = function() { FW.resetUI( "EditedJS" ); }
			}

			// Init XML Section
			var EditContainerXML = document.getElementById( "EditContainerXML" );
			if( EditContainerXML && EditContainerXML.className == "on" ) {

				// Title, Notes & Buttons can each be overloaded on a per-page basis (if needed)
				var XmlTitle = document.getElementById( "XmlTitle" );
				if( XmlTitle.innerHTML == "" ) XmlTitle.innerHTML = "GLOBAL XML DATA";

				var XmlNotes = document.getElementById( "XmlNotes" );
				if( XmlNotes.innerHTML == "" ) XmlNotes.innerHTML = this.XmlNotes;

				var EditedXML = document.getElementById( "EditedXML" );
				EditedXML.onfocus = function() {
					this.title = "Edit data then press \"Publish XML\"";
 					self.status = this.title;
				}
				EditedXML.onblur = function() { self.status=""; }

				var HelpXML = document.getElementById( "HelpXML" );
				HelpXML.onmouseover = function() { this.title = help; }

				var ReloadXML = document.getElementById( "ReloadXML" );
				ReloadXML.onmouseover = function() { this.title = justPub; }
				ReloadXML.onclick = function() { FW.reLoad( "EditedXML" ); }

				var PublishXML = document.getElementById( "PublishXML" );
				PublishXML.onmouseover = function() { this.title = "Save XML"; }
				PublishXML.onclick = function() { return FW.checkContent( 3 ); }

				var ResetXML = document.getElementById( "ResetXML" );
				ResetXML.onmouseover = function() { this.title = "Revert XML back to original values since you last published"; }
				ResetXML.onclick = function() { FW.resetUI( "EditedXML" ); }
			}

			var htm =
			"<div class='otherFunctions'>" +
				"<a href='javascript:FW.logOff();' title='Log off as administrator' class='fw'>Log Off</a>";
				htm += this.AdminLinks;
			htm +=
			"</div>";

			document.getElementById( "fwBottomRow" ).innerHTML = htm;

			self.status = "";

		}
		catch( Err ) {
			if( local ) {
				var err = "";
				for( member in Err ) err += member + ": " + Err[ member ] + "\n";
				alert( "Exception at method FW.init:\n\n" + err );
			}
			else {
				setTimeout( "FW.init();", 250 );
				self.status = "Initializing File Writer: FW.init()...";
			}
		}
	}
	//------------------------------------- Method FW -------------------------------------

	function checkContent( dataType ) {

		function subDisableTextBoxes( htm, js, xml ) {

			if( htm && document.getElementById( "EditedHTML" ) )
				document.getElementById( "EditedHTML" ).disabled = true;

			if( js && document.getElementById( "EditedJS" ) )
				document.getElementById( "EditedJS" ).disabled = true;

			if( xml && document.getElementById( "EditedXML" ) )
				document.getElementById( "EditedXML" ).disabled = true;
		}

		var Form = document.AspForm;

		var EditedHTML = Form.EditedHTML;
		var EditedJS = Form.EditedJS;
		var EditedXML = Form.EditedXML;

		// HTML
		if( dataType == 1 ) {

			if( this.dataUnmodified( dataType ) ) {
				alert( "Edit the text then press Publish HTML..." );
				EditedHTML.focus();
				FW.cursorReadyHtm = false;
				return false;
			}
			else {
				EditedHTML.value = EditedHTML.value.trim();
				document.getElementById( "PublishHTM" ).disabled = true;
				Form.Which_Button.value = "html";
				subDisableTextBoxes( 0, 1, 1 );
			}
		}

		// JS
		else if( dataType == 2 ) {

			if( this.dataUnmodified( dataType ) ) {
				alert( "Edit the data then press Publish JavaScript..." );
				EditedJS.focus();
				FW.cursorReadyJS = false;
				return false;
			}
			else {
				try {
					eval( EditedJS.value );
				}
				catch( Err ) {
					var err = "";
					for( member in Err ) err += member + ": " + Err[ member ] + "\n";
					alert( "Sorry, you have mistakenly broken JavaScript's rigid syntax. As a result, the file cannot be saved to disk. Fix the error & try again or click \"Reset\"...\n\n" + err );
				return false;
				}
				EditedJS.value = EditedJS.value.trim();
				document.getElementById( "PublishJS" ).disabled = true;
				Form.Which_Button.value = "js";
				subDisableTextBoxes( 1, 0, 1 );
			}
		}

		// XML
		else {

			if( this.dataUnmodified( dataType ) ) {
				alert( "Edit the text then press Publish XML..." );
				EditedXML.focus();
				return false;
			}
			else {

				var textOrig = EditedXML.defaultValue;
				var textNew = EditedXML.value.trim();

				var xmlOrig = textOrig.replace( />[^<>]*</g, "><" );
				var nLinesOrig = textOrig.split( "\n" ).length;

				var xmlNew = textNew.replace( />[^<>]*</g, "><" );
				var nLinesNew = textNew.split( "\n" ).length;

				if( xmlOrig == xmlNew && nLinesOrig == nLinesNew ) {

					var xml = EditedXML.value;

					xml = xml.replace( /&amp;/g, "a_m_p_e_r_s_a_n_d" );
					xml = xml.replace( /\\\"/g, "q_u_o_t_e" );

					xml = xml.replace( /&/g, "&amp;" );
					xml = xml.replace( /\"/g, "\\\"" );

					xml = xml.replace( /q_u_o_t_e/g, "\\\"" );
					xml = xml.replace( /a_m_p_e_r_s_a_n_d/g, "&amp;" );

					EditedXML.value = xml;

					document.getElementById( "PublishXML" ).disabled = true;
					Form.Which_Button.value = "xml";
					subDisableTextBoxes( 1, 1, 0 );
				}
				else {
					var err = ", as a result, the file cannot be saved to disk. Please edit the data only then press Publish XML.\n\n==> Fix the error & try again or click \"Reset\"";

					if( nLinesOrig != nLinesNew )
						alert( "ERROR: You have added or removed lines" + err );
					else
						alert( "ERROR: You have edited XML tag(s)" + err );
					EditedXML.focus();
					return false;
				}
			}

			// Trim white-space (if any) around values
			var xml = EditedXML.value.trim();
			var XML = xml.split( ">" );
			for( var i = 0; i < XML.length; i++ )
				XML[ i ] = XML[ i ].replace( /^ +/g, "" );
			xml = XML.join( ">" );

			var XML = xml.split( "</" );
			for( var i = 0; i < XML.length; i++ )
				if( XML[ i ].indexOf( "<" ) >= 0 ) XML[ i ] = XML[ i ].replace( / +$/g, "" );
			xml = XML.join( "</" );

			EditedXML.value = xml;
		}

		Form.ASP_Job.value = "File_Writer";
		Form.submit();
		return true;
	}
	//------------------------------------- function FileWriter -------------------------------------

	function dataUnmodified( dataType ) {

		var Form = document.AspForm; dateUnedited = "", dateEdited = "";

		switch( dataType ) {

			case 1: // HTML
				dateUnedited = Form.EditedHTML.value;
				dateEdited = Form.EditedHTML.defaultValue;
				break;

			case 2: // JS
				dateUnedited = Form.EditedJS.value;
				dateEdited = Form.EditedJS.defaultValue;
				break;

			case 3: // XML
				dateUnedited = Form.EditedXML.value;
				dateEdited = Form.EditedXML.defaultValue;
				break;

			default: alert( "Switch/Case Error at FW.dataUnmodified; Bad dataType: " + dataType );

		}
		return ( dateUnedited.replace( /\r/g, "" ).replace( /\n/g, "" ) == dateEdited.replace( /\r/g, "" ).replace( /\n/g, "" ) );
	}
	//------------------------------------- Method FW -------------------------------------

	function resetUI( TextBox ) {
		if( TextBox == "EditedHTML" ) this.cursorReadyHtm = false;
		else if( TextBox == "EditedJS" ) this.cursorReadyJS = false;
		eval( "document.AspForm." + TextBox + ".value = document.AspForm." + TextBox + ".defaultValue;" );
	}
	//------------------------------------- Method FW -------------------------------------

	function reLoad( TextBox ) {

		if( eval( "document.AspForm." + TextBox + ".value" ) == eval( "document.AspForm." + TextBox + ".defaultValue" ) )
			document.location.reload( true );
		else if( confirm ( "You have made edits but have not saved (published) them. Your unpublished edits will be lost upon reloading this page. Do you still want to reload?\n\n1) Click OK to reload, unpublished edits will be lost.\n2) Click Cancel to stop the page from reloading." ) )
			document.location.reload( true );

	}
	//------------------------------------- Method FW -------------------------------------

	function logOff() {
		var qStrOut = ( qStr ) ? qStr + "&logoff=yes" : "logoff=yes";
		document.location.replace( fileName + "?" + qStrOut );
	}

	//------------------------------ Method FW ------------------------------
	// This method takes user name/pw from log-in popup GUI and sends it to server (in query string)

	function logIn() {

		var Form = document.LogIn;

		var userNameFW = Form.user.value;

		if( userNameFW == "" ) {
			alert( "Please enter your user name" );
			Form.user.focus();
			return false;
		}

		else if( Form.pw.value == "" ) {
			alert( "Please enter your password" );
			Form.pw.focus();
			return false;
		}
		else {
			if( Form.remember_pw.checked ) {
				var pwOut = "";
				var pwIn = Form.pw.value;
				for( var i = 0; i <= pwIn.length; i++ ) pwOut = pwIn.charAt(i) + pwOut;
				SetCookie( "pwFW", pwOut, expDate12Mon );
			}
			else
				DeleteCookie( "pwFW" );
		}

		if( userNameFW )
			SetCookie( "userNameFW", userNameFW, expDate12Mon );

		// If we got an existing qStr maintain it but remove log-in related name/val pairs if any
		var qStrExisting = qStr;
		if( qStrExisting ) {

			var user = qStr.getVal( "user" );
			if( user != null )
				qStrExisting = qStrExisting.split( "user=" + user ).join( "" );

			var pw = qStr.getVal( "pw" );
			if( pw != null )
				qStrExisting = qStrExisting.split( "pw=" + pw ).join( "" );

			var ms = qStr.getVal( "ms" );
			if( ms != null )
				qStrExisting = qStrExisting.split( "ms=" + ms ).join( "" );

			var logoff = qStr.getVal( "logoff" );
			if( logoff != null )
				qStrExisting = qStrExisting.split( "logoff=" + logoff ).join( "" );

			var forcedOut = qStr.getVal( "forcedOut" );
			if( forcedOut != null )
				qStrExisting = qStrExisting.split( "forcedOut=" + forcedOut ).join( "" );

			qStrExisting += "&";
			qStrExisting = qStrExisting.replace( /\&{2,}/g, "&" );
		}

		var url = fileName + "?" + qStrExisting + "user=" + Form.user.value + "&pw=" + Form.pw.value + "&ms=" + new Date().getTime();

		document.location.replace( url );

	}

	//------------------------------ Method FW ------------------------------
	// Called onClick of Remember Me

	function recordPW( CheckBox ) {

		if( CheckBox.checked ) {
			var pw = document.LogIn.pw.value;
			if( pw ) {
				var pwOut = "";
				for( var i = 0; i <= pw.length; i++ ) pwOut = pw.charAt(i) + pwOut;
				SetCookie( "pwFW", pwOut, expDate12Mon );
			}
		}
		else
			DeleteCookie( "pwFW" );
	}

	//------------------------------ Method FW ------------------------------
	// This method launches Log-In pop-up GUI

	function getLogInGUI( evt ) {

		if( !evt ) evt = window.event;

		var userNameFW = ( GetCookie( "userNameFW" ) ) ? GetCookie( "userNameFW" ) : "";
		var pwFW = ( GetCookie( "pwFW" ) ) ? GetCookie( "pwFW" ) : "";
		var pwOut = "";
		if( pwFW )
			for( var i = 0; i <= pwFW.length; i++ ) pwOut = pwFW.charAt(i) + pwOut;
		var pwChecked = ( pwFW ) ? " checked" : "";

		var gui =

		"<form name='LogIn' style='margin:0px;'>" +
			"<table align='center' border='0' cellspacing='0' cellpadding='0'>" +
				"<tr>" +
					"<td>" +
						"<table align='center' border='0' cellspacing='0' cellpadding='0'>" +

							// User Name
							"<tr>" +
								"<td class='fwField' style='padding-top:6px;'>" +
									"User Name" +
								"</td>" +
								"<td class='fwValue' style='padding-top:6px;' id='tdBookingID'>" +
									"<input type='text' name='user' class='fwText' title='Enter your user-name' value='" + userNameFW + "' onkeypress='if( window.event && window.event.keyCode == 13 || event.which == 13 ) { FW.logIn(); return false; }' />" +
								"</td>" +
							"</tr>" +

							// Password
							"<tr>" +
								"<td class='fwField' style='padding-top:6px;'>" +
									"Password" +
								"</td>" +
								"<td class='fwValue' style='padding-top:6px;' id='tdBookingID'>" +
									"<input type='password' name='pw' autocomplete='off' value='" + pwOut + "' class='fwText' title='Enter your password' onkeypress='if( window.event && window.event.keyCode == 13 || event.which == 13 ) { FW.logIn(); return false; }' />" +
								"</td>" +
							"</tr>" +

							// Remember Me
							"<tr>" +
								"<td align='center' colspan='2' class='fwValue' style='padding-top:6px; white-space:nowrap;'>" +
									"<input type='checkbox' id='remember_pw' name='remember_pw' onClick='FW.recordPW( this );'" + pwChecked + " /><label for='remember_pw'> Remember Me</label>" +
								"</td>" +
							"</tr>" +

							// OK/Cancel Buttons
							"<tr>" +
								"<td align='center' colspan='2' style='padding:10px 0px 0px 0px; white-space:nowrap;'>" +
									"<input type='button' name='OK' value='OK' class='logInButtons' onClick='return FW.logIn();' />" +
									"<input type='button' value='Cancel' class='logInButtons' onClick='DW.removeWin();' />" +
								"</td>" +
							"</tr>" +

						"</table>" +
					"</td>" +
				"</tr>" +
			"</table>" +
		"</form>";

		DW.createWindow( [ "Administrator Log-In", gui ], [0,300,0], null, evt, 6 );

		if( userNameFW && pwFW )
			setTimeout( "document.LogIn.OK.focus();", 100 );
		else if( userNameFW )
			setTimeout( "document.LogIn.pw.focus();", 100 );
		else
			setTimeout( "document.LogIn.user.focus();", 100 );

	}

} ///////////////////////////////// End Object FileWriter FW /////////////////////////////////



//////////////////////////////// START DYNAMIC INDEX DI ////////////////////////////////

/*

ACCESSOR VARIABLES: fileName
ACCESSOR FUNCTIONS: Cookie
ACCESSOR STYLES: di*, img.diTn, img.diTnOn
*/

//-------------------------------- OBJECT CONSTRUCTOR DI --------------------------------
//                     bool optional
function DynamicIndex( setEvtHandlers ) {

	// Begin User Settings -------------------------
	this.msg = new Array();
	this.msg.show = "Click to show Content";
	this.msg.hide = "Click to hide Content";

	// Do not edit past this line -------------------------
	this.getPlusMinus = getPlusMinus;
	this.onClickMore = onClickMore;
	this.reset = reset;
	this.switchDisplay = switchDisplay;
	this.showTip = showTip;
	this.maintainState = maintainState;
	this.setEventHandlers = setEventHandlers;
	if( setEvtHandlers ) this.setEventHandlers();


	//------------------------------------ METHOD DI ------------------------------------
	// This method to be customized on a per/client basis. It contains additional onClick functionality (if any)

	function onClickMore( Link, evt ) {}

	//------------------------------------ METHOD DI ------------------------------------

	function setEventHandlers() {

		try {
			var AllLinks = document.getElementsByTagName( "a" );
			for ( var i = 0; i < AllLinks.length; i++ ) {

				// Clickable Link
				if( AllLinks[ i ].className == "diHeading" ) {
					AllLinks[ i ].onclick = function( event ) { if( window.DI ) { DI.onClickMore( this, event ); DI.switchDisplay( this ); } }
					AllLinks[ i ].onmouseover = function() { if( window.DI ) DI.showTip( this ); return true; }
				}
				// Plus/Minus Sign
				if( AllLinks[ i ].className == "diPlusMinus" ) {
					AllLinks[ i ].onclick = function( event ) { if( window.DI ) { DI.onClickMore( this.nextSibling, event ); DI.switchDisplay( this.nextSibling ); } }
					AllLinks[ i ].onmouseover = function() { if( window.DI ) DI.showTip( this.nextSibling ); return true; }
				}
			}
			self.status = "";
		}
		catch( Err ) {
			self.status = "Initializing DI.setEventHandlers() method, one moment please...";
			setTimeout( "DI.setEventHandlers();", 250 );
		}

	}


	//------------------------------------ METHOD DI ------------------------------------

	function maintainState() {

		try {
			// Use the file name as cookie name
			var path = document.location.pathname;
			var delimeter = ( path.indexOf( "\\" ) >= 0 ) ? "\\" : "/";
			this.cookieName = fileName.split( "." )[ 0 ];
			var diState = GetCookie( this.cookieName );

			if( diState ) {

				var AllLinks = document.getElementsByTagName( "a" );
				var DiState = diState.split( "_" );

				// Loop all links on page
				for ( var i = 0; i < AllLinks.length; i++ ) {
					for( var k in DiState ) {
						if( DiState[ k ] && parseInt( DiState[ k ] ) == i ) {
							try{ DI.switchDisplay( AllLinks[ i ], AllLinks[ i ].id ) } catch( e ){};
						}
					}
				}
			}
			self.status = "";
		}
		catch( Err ) {
			self.status = "Initializing DI.maintainState() method, one moment please...";
			setTimeout( "DI.maintainState();", 250 );
		}
	}

	//------------------------------------ METHOD DI ------------------------------------

	function getPlusMinus( Link ) { return Link.previousSibling; }

	//------------------------------------ METHOD DI ------------------------------------

	function reset( OtherID ) {
		for( var i = 0; i < OtherID.length; i++ ) {
			var PlusMinus = document.getElementById( "plusMinus_" + OtherID[ i ] );
			if( PlusMinus ) {
				PlusMinus.innerHTML = "-";
				this.switchDisplay( null, OtherID[ i ] );
			}
			else {
				alert( "ERROR: DI.reset unable to initialize PlusMinus as an Object.\nPROBLEM: \"plusMinus_" + OtherID[ i ] + "\" cannot be found." );
				return;
			}
		}
	}
	//------------------------------------ METHOD DI ------------------------------------

	function switchDisplay( Link, contentID, focuserID ) {

		if( !Link ) Link = document.getElementById( contentID );
		var PlusMinus = getPlusMinus( Link );
		var expanding = ( PlusMinus.innerHTML == "+" ), contracting = !expanding;

		// It there is a photo caption then activate it
		var Caption = document.getElementById( "caption_" + Link.id );
		if( Caption)
			Caption.className = ( expanding ) ? "diCaptionOn" : "diCaptionOff";

		// It there is an image then activate it
		var Img = document.getElementById( "img_" + Link.id );
		if( Img )
			Img.className = ( expanding ) ? "diTnOn" : "diTn";

		PlusMinus.innerHTML = ( expanding ) ? "-" : "+";

		var AllLinks = document.getElementsByTagName( "a" );

		var valOld = GetCookie( this.cookieName ), valNew = "";

		// Record State; loop all links on page
		for ( var i = 0; i < AllLinks.length; i++ ) {

			// Found link just clicked
			if( AllLinks[ i ] == Link ) {
				// Existing cookie present
				if( valOld ) {
					var key = "_" + i + "_";
					// this i value already recorded
					if( valOld.indexOf( key ) >= 0 ) {
						// Remove this entry
						if( contracting ) {
							var ValOld = valOld.split( key );
							valNew = ( ( ValOld[ 0 ] ) ? ValOld[ 0 ] : "" ) + "_" + ( ( ValOld[ 1 ] ) ? ValOld[ 1 ] : "" );
							( valNew == "_" ) ? DeleteCookie( this.cookieName ) : SetCookie( this.cookieName, valNew );
						}
						break;
					}
					if( expanding ) valNew = valOld + i + "_";
				}
				else if( expanding ) // First expansion; no cookie set
					valNew = "_" + i + "_";

				if( valNew )
					SetCookie( this.cookieName, valNew );
				break;
			}
		}

		if( contentID )
			var Content = document.getElementById( "content_" + contentID );
		else
			var Content = ( Link.parentNode.nextSibling.style ) ? Link.parentNode.nextSibling : Link.parentNode.nextSibling.nextSibling;

		try{
			Content.style.display = ( contracting ) ? "none" : "block";
		}
		catch( Err ) {
			var problem = ( contentID ) ? "\nPROBLEM: \"content_" + contentID + "\" cannot be found." : "";
			alert( "ERROR: DI.switchDisplay unable to initialize Content as an Object." + problem );
		}

		if( focuserID && expanding ) {
			var FocusCont = document.getElementById( focuserID );
			FocusCont.innerHTML = "<a href='javascript:void(0);'>.</a>";
			var FocusLink = FocusCont.firstChild;
			FocusLink.focus();
			Link.focus();
			FocusCont.innerHTML = "";
		}
		showTip( Link );

	}

	//------------------------------------ METHOD DI ------------------------------------

	function showTip( Link, msgOn, msgOff ) {

		var PlusMinus = getPlusMinus( Link );

		if( PlusMinus.innerHTML == "+" ) {
			Link.title = ( msgOn ) ? msgOn : DI.msg.show;
			PlusMinus.title = ( msgOn ) ? msgOn : DI.msg.show;
		}
		else {
			Link.title = ( msgOff ) ? msgOff : DI.msg.hide;
			PlusMinus.title = ( msgOff ) ? msgOff : DI.msg.hide;
		}

	}

}
//////////////////////////////// END DYNAMIC DI ////////////////////////////////

function initPage() {
	try {

		// Disable link for current page
		var Links = document.links;
		for( var i = 0; i < Links.length; i++ ) {

			var LinkComponents = Links[ i ].href.split( "/" );
			var file = LinkComponents[ LinkComponents.length - 1 ].replace( /\?.*/, "" );
			if( file.toLowerCase() == fileName.toLowerCase() ) {
				if( Links[ i ].className == "navBot" )
					Links[ i ].className = "navBotDisabled";
				if( Links[ i ].className == "navTop" )
					Links[ i ].className = "navTopDisabled";
			}
			if( fileName == "default.aspx" ) {
				document.getElementById( "HomeBullet" ).className = "off";
				document.getElementById( "HomeLink" ).className = "off";
			}
		}

		var publicUser = !GetCookie( "userWithWritePrivileges" );
		var Images = document.images;
		for( var i = 0; i < Images.length; i++ ) {
			if( publicUser ) Images[ i ].oncontextmenu = function() { return false; }
			if( Images[ i ].className == "tn" || Images[ i ].className == "tnLeft" || Images[ i ].className == "tnRight" )
				Images[ i ].title = Msg.enlarge;
		}

		self.status = "";
	}
	catch( Err ) {
		if( local ) alert( Err );
		self.status = "Initializing at initPage()...";
		setTimeout( "initPage()", 200 );
	}
}
//--------------------------------------------------------------------------------------

function initHomepage() {
	try {
		var Body = ( IE && document.compatMode == "CSS1Compat" ) ? document.documentElement : document.body;
		var bodyHeight = ( IE ) ? Body.clientHeight : window.innerHeight;
		var contentHeight = parseInt( document.getElementById( "content" ).style.height );
		var marginTop = Math.round( ( bodyHeight - contentHeight ) / 2 ) - 30;
		if( marginTop < 0 ) marginTop = 0;
		document.getElementById( "content" ).style.marginTop = marginTop + "px";
		SS.repositionElements();
		if( !GetCookie( "userWithWritePrivileges" ) )
			document.getElementById( "content" ).oncontextmenu = function() { return false; }
		self.status = "";
	}
	catch( Err ) {
		self.status = "Exception at function initHomepage(), trying again...";
		setTimeout( "initHomepage();", 100 );
	}
}
//--------------------------------------------------------------------------------------

function getLogInGUI( event ) {
	FW.getLogInGUI( event );
}
