//---        Floh's Homepage, (c) 1996-2006 by Florian Dirscherl, Germany      ---//
//---        http://floh.org/                                                  ---//
//---        Designed in JavaScript 1.1                                        ---//
//--------------------------------------------------------------------------------//
//--- Functions:
//---   - Autoexec
//---   - changeObject
//---   - CookieGet
//---   - CookieSet
//---   - DaysDue
//---   - GetField
//---   - GetQuote
//---   - Header
//---   - LoadList
//---   - PrepareLine
//---   - SubMenu
//---   - UTCDate
//---   - WriteLine
//---------------------------------//

//----------------------//
//--- Environment    ---//
//----------------------//

//--- Technical Definitions -------//
var G_Browser     = "";                    // Type of Browser used
var G_Temp        = "";                    // String Buffer for Comparisons
var G_STMin       =  60*1000;              // System Time: 1 Minute
var G_STHour      =  60*G_STMin;           // System Time: 1 Hour
var G_STDay       =  24*G_STHour;          // System Time: 1 Day
var G_STYear      = 365*G_STDay;           // System Time: 1 Year

switch (navigator.appName) {               // Analyse Browser Type
	case "Netscape" : 
		G_Browser = "NS"; 
		break;
	default : 
		G_Browser = "IE"; 
		break;
}

//--- Global Definitions ----------//

var G_ImgPreload = true;                   // Impage preload flag

var G_MenuHeaderDelimit = ":<br>";         // Delimiter for Page Menu Header
var G_MenuLineDelimit = " | ";             // Delimiter for Page Menu Line items

var G_Quotes = String.fromCharCode(34);    // Quote sign (")
var G_Path = "";                           // Pointer to MFD_Main document
var G_FileDummy = "dummy.htm";             // Name of Dummy frame src file (Ad-catch)
var G_FileFooter = "footer.htm";           // Name of Footer frame src file
var G_FrameDummy = "MFD_Dummy";            // Name of Dummy frame (Ad-catch)
var G_FrameFooter = "MFD_Footer";          // Name of Footer frame 
var G_FrameMain = "MFD_Main";              // Name of Main frame
var G_MainExist = 0;                       // Indicator whether MFD_Main exists
var G_Target = "";                         // Frame target

var G_Quote = new Array();                 // Quote container

var G_GeneralCss = "bin/general.css";      // Style definitions file
var G_GeneralJs  = "bin/general.js";       // Javascript file
var G_ToolboxJs  = "bin/toolbox.js";       // Javascript file
var G_IDIndex    = "Content";              // Name of HTML page-index DIV-element 

switch(G_Browser) {                        // By Browser
	case "IE" : 
		G_Temp = this.name.substr(0,4);
		break;
	case "NS" :
		G_Temp = this.name.substr(0,4);
		break; 
}

if(G_Temp == "MFD_") {                     // Was page called via Start page?
	G_Path      = "parent." + G_FrameMain + ".";
	G_MainExist = 1;
	G_Target    = "TARGET=" + G_Quotes + G_FrameMain + G_Quotes + " ";
}

//---------------------------------//
//--- Function    : Autoexec
//--- Date        : 10.01.2001
//--- Parameter   : 
//--- Description : Function to be executed on each page on loading
//--------------------------------//
function Autoexec() {
	// Set the window name in a frame environment to what's defined in the 
	// title tag of the window that executes this function

	top.document.title = "http://floh.org/ . . . . . Floh's " + document.title + " . . . . . "; 
}

//---------------------------------//
//--- Function    : changeObject
//--- Date        : 06.04.2001
//--- Parameter   : P_Type   (Type of attribute to be changed)
//---               P_Object (Object to be changed
//---                         Note:depending on the P_Type, the HTML tag is labeled 
//---                              in different ways.
//---                         I.e.: src           -> NAME=
//---                               value         -> NAME= 
//---                               className     -> NAME= 
//---                               selectedIndex -> ID= 
//---                               innerHTML     -> ID= )
//---               P_Value  (New value to be assigned)
//--- Description : assign passed images to respective objects
//---------------------------------//

function changeObject(P_Type, P_Object, P_Value) {
	var I_Object;

	switch (P_Type) {
		case "src" :
			if (document.images && (G_ImgPreload == true)) 
				document[P_Object].src = P_Value;
			break;
		case "value" :
			P_Object.value = P_Value;
			break;
		case "radio" :
			P_Object.checked = true;
			break;
		case "selectedIndex" :
			P_Object.selectedIndex = P_Value;
			break;
	default :
			switch(G_Browser) {                        // By Browser
				case "NS" :
					I_Object = document.getElementById(P_Object);
					I_Object[P_Type] = P_Value;
					break; 
				case "IE" : 
				default   :
					document.all[P_Object][P_Type] = P_Value;
					break;
				}
			break;
	}
 }

//---------------------------------//
//--- Function    : CookieGet
//--- Date        : 28.05.2001
//--- Parameter   : P_ID  (Parameter Name)
//--- Returns     : Parameter value or -1
//--- Description : Reads a parameter from a cookie
//---------------------------------//

function CookieGet(P_ID) {
	var I_Value = P_ID + "="
	var I_Start = 0;
	var I_End   = 0;
	if (document.cookie.length > 0) { // if there are any cookies
		I_Start = document.cookie.indexOf(I_Value)

		if (I_Start != -1) {                     // if cookie exists
			I_Start += I_Value.length;           // intify value positionin cookie
			I_End    = document.cookie.indexOf(";", I_Start);
			if (I_End == -1) I_End = document.cookie.length;
			return unescape(document.cookie.substring(I_Start, I_End));
		}
	}
	return -1;
 }

//---------------------------------//
//--- Function    : CookieSet
//--- Date        : 28.05.2001
//--- Parameter   : P_ID       (Variable to be stored in the cookie)
//---               P_Value    (Value to be assigned to P_ID)
//---               P_Expire   (Expiry of the cookie)
//--- Description : Stores a Parameter in a cookie
//---------------------------------//

function CookieSet(P_ID, P_Value, P_Expire) {
	var I_Now    = new Date();
	var I_Expire = new Date(I_Now.getTime() + P_Expire);
	if(P_Value == "") P_Value = 0;   
	document.cookie = P_ID+"="+P_Value+"; expires="+I_Expire.toGMTString()+";";
}

//---------------------------------//
//--- Function    : DaysDue
//--- Date        : 24.05.2001
//--- Parameter   : P_Date (Due date in format YYYY,MM,DD)
//--- Description : Number of days until specific due date arrives
//---------------------------------//

function DaysDue(P_Name, P_Date) {
	var I_Object   = "";               // Object reference buffer
	var I_Content  = "";               // Content Field Buffer
	var I_Now      = new Date();
	var I_DueDate  = new Date(P_Date);
	var I_Delta    = I_DueDate.getTime() - I_Now.getTime();
	var I_Days     = Math.floor(I_Delta / (24 * 60 * 60 * 1000));

	//- Date Calculation -----//
	if (I_Days > 0) {
		I_Content = "Countdown to " + P_Name + ": " + I_Days + " days";
	} else if (I_Days = 0) {
		I_Days = I_Days * (-1) + 1;
		I_Content =  "Today is " + P_Name;
	} else {
		I_Days = I_Days * (-1);
		I_Content =  P_Name + " has past " + I_Days + " days ago!";
	}

	changeObject("innerHTML", G_IDIndex, I_Content);
}

//---------------------------------//
//--- Function    : GetField
//--- Date        : 27.05.2001
//--- Parameter   : P_Field     (Vector from which field is extracted)
//---               P_Selector  (number of the element to be returned)
//--- Return      : Extracted field
//--- Description : Read subvectors from an array field
//---------------------------------//

function GetField(P_Field, P_Selector) {
	var I_Result    = "";
	var I_FirstChar =  0;
	var I_LastChar  = -1;
	var i           =  0;

	for(i=1; i<=P_Selector; i++) {
		I_FirstChar = I_LastChar + 1;
		I_LastChar  = P_Field.indexOf(TB_Delimiter, I_FirstChar);
		if(I_LastChar < 0) I_LastChar = P_Field.length;
	}

	I_Result = P_Field.substring(I_FirstChar,I_LastChar);
	return I_Result;
 }

//---------------------------------//
//--- Function    : GetQuote
//--- Date        : 29.10.2002
//--- Parameter   : P_Element (Placeholder to receive output)
//--- Return      : 
//--- Description : Displays a 'Quote of the day' from the internet
//---------------------------------//

function GetQuote(P_Element) {
	var I_Date = new Date();
    var I_Day  = I_Date.getDate();
    var I_Body = ""; 

	switch(P_Element) {
		case "Quote" :
			LoadQuote();

		 	I_Body  = "<TABLE CLASS=ln CLEAR=ALL ALIGN=CENTER WIDTH=80%>";
			I_Body += "<TR><TD><CENTER><DIV CLASS=lh>Quote of the Day</DIV>";
		    I_Body += G_Quote[I_Day];
			I_Body += "</CENTER></TD></TR></TABLE>";
			break;
	 }

	if(G_Quote[I_Day] != "") changeObject("innerHTML", P_Element, I_Body);
 }

//---------------------------------//
//--- Function    : Header
//--- Date        : 30.05.2001
//--- Parameter   : P_Title    (Name of the page)
//---               P_Icon     (Icon for the title)
//--- Retuns      : Header string for the DHTML Page
//--- Description : Generate DHTML Header
//---------------------------------//

function Header(P_Title, P_Icon) {
	// Define DHTML constants
	var i = 0;

	// Load Header
	var I_Result  = "<HTML><HEAD><TITLE>Results: " + P_Title + "</TITLE>" + "\n";

	for(i=2;i<arguments.length;i++) {
		if(arguments[i].search(/css$/) >-1) {     // include style sheet
			I_Result += "<LINK REL=stylesheet TYPE='text/css' HREF='" + arguments[i] + "'>\n";
		} else {                                  // include JavaScript
			I_Result += "<SCRIPT language='javascript' src='" + arguments[i] + "' type='text/javascript'></SCRIPT>\n";
		}
	}

	I_Result += "</HEAD><BODY>" + "\n";
	I_Result += "<DIV class=ln>" + "\n";
	I_Result += "<TABLE ALIGN=CENTER>" + "\n";
	I_Result += "<TD ALIGN=left VALIGN=MIDDLE><img src=\"" + P_Icon + "\"></TD>" + "\n";
	I_Result += "<TD ALIGN=left VALIGN=MIDDLE CLASS=pt>" + P_Title + "</TD>" + "\n";
	I_Result += "</TABLE><P><P>" + "\n";
	return I_Result;
}

//---------------------------------//
//--- Function    : LoadList
//--- Date        : 24.05.2001
//--- Parameter   : P_Formfield (List field which is to be loaded)
//---               P_Buffer    (Cookie Referece for initial value)
//---               P_VIndex    (Indicates how to handle option 
//---                            values: -1 = as per parameter list
//---                                 other = start index (numeric)
//---               P_Default   (selected parameter)
//---               arguments   (list values to be loaded)
//--- Description : Load a list element with values
//---------------------------------//

function LoadList(P_Formfield, P_Buffer, P_VIndex, P_Default) {
	var I_Counter = 0;                     // List index
	var I_CStart  = 0;                     // List start inidcator
	var I_Buffer  = CookieGet(P_Buffer);   // String operation Buffer
	var I_Vector  = new Array();
	var I_VBuffer = 0;                      // Vector Buffer for loop

	// Determine whether standard system arrays are used
	switch(LoadList.arguments[4]) {
		case -1 :                   // Vector is kept in global array 'TB_CityTime'
			I_Vector = TB_CityTime;
			break;
		case -2 :                   // Vector is kept in global array 'TB_Currency'
			I_Vector = TB_Currency;
			break;
		case -3 :                   // Vector is kept in global array 'TB_STerms'
			I_Vector = TB_STerms;
			break;
		default :
			I_Vector  = arguments;    // read function arguments
			I_Counter = I_CStart = 4;
	}

	// Move the selected array to the list object
	for(I_Counter; I_Counter<I_Vector.length; I_Counter++) {
		I_VBuffer = I_Vector[I_Counter];

		// If field is a vector field then extract first subfield
		if(isNaN(I_VBuffer))
			if(I_VBuffer.indexOf(TB_Delimiter) > -1)
				I_VBuffer = GetField(I_VBuffer, 1);

		// Add field to options list
		P_Formfield.options[I_Counter - I_CStart] = new Option(I_VBuffer);

		// Check whether option value receives a generated index
		if(P_VIndex > -1) P_Formfield.options[I_Counter - I_CStart].value = P_VIndex + I_Counter - I_CStart;
		else P_Formfield.options[I_Counter - I_CStart].value = I_VBuffer;
	}

	// Select cookie value. If no cookie is stored, use system default.
	if (I_Buffer == -1) {
		P_Formfield.selectedIndex = P_Default;
	} else {
		P_Formfield.selectedIndex = I_Buffer;
	}
}

//---------------------------------//
//--- Function    : PrepareLine
//--- Date        : 10.01.2001
//--- Parameter   : P_Title      (Page title)
//---               P_Image      (Image/Photo to be displayed)
//---               P_Icon       (Icon to be displayed next to the title)
//---               P_Comment    (Comment to be included under the image)
//--- Description : Generate HTML Page to display a commented picture
//--------------------------------//

function PrepareLine(P_Title, P_Image, P_Icon, P_Comment) {
	var I_Msg = Header(P_Title, P_Icon, G_GeneralCss);
	I_Msg += "<CENTER>" + "\n";

	if (P_Image.substr(0,1) != "<") {
		I_Msg += "<IMG SRC=\"" + P_Image + "\">" + "\n";
	} else {
		I_Msg += P_Image + "\n";
	}
	I_Msg += "<P>" + P_Comment + "</CENTER><P>" + "\n";
	I_Msg += "<IFRAME NAME=\"" + G_FrameFooter + "\" SRC=\"" + G_FileFooter + "\" SCROLLING=NO HSPACE=0 WIDTH=100% HEIGHT=60 FRAMEBORDER=0></IFRAME>\n";
	I_Msg += "<IFRAME NAME=\"" + G_FrameDummy +"\" SRC=\"" + G_FileDummy + "\" SCROLLING=NO HSPACE=0 WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>\n";
	I_Msg += "</DIV></BODY></HTML>" + "\n";
	I_Msg += "" + "\n";

	writeLine(I_Msg, "");
}

//---------------------------------//
//--- Function    : SubMenu
//--- Date        : 02.04.2001
//--- Parameter   : P_Action   (Switch menu "on" and "off")
//---               arguments  (submenu items - ID and description)
//--- Description : Generate a Index menu 
//---------------------------------//

function SubMenu(P_Action) {
	var I_Body = "";
	var I_Class = "";
	var I_Delimiter = "";
	var I_Title = "";

	// Write the menu line into layer "Content" ----------------------------//
	switch (P_Action) {
		case "on" :
			// Add the sub-menu item lines
			for (i=1; i < arguments.length; i+=2) {
				// Remove special Characters from the label
				I_Title = arguments[i+1].replace(/\./, "");
				I_Title = I_Title.replace(/ /, "");
				while(I_Title.search(/ /) != -1)
					I_Title = I_Title.replace(/ /, "");

				// Set values for Header/Line entries
				if(i == 1) {                      // Header Line
					I_Class = "mlc-h";
					I_Delimiter = G_MenuHeaderDelimit; }
				else {                            // Item Line
					I_Class = "mlc-l";
					I_Delimiter = G_MenuLineDelimit; }

				// Build the menu line
				if(i > 3) I_Body += I_Delimiter;

				I_Body += "<A CLASS=" + I_Class + "n ID=i" + I_Title + " \n";
				I_Body += "onMouseover=" + G_Quotes + "changeObject('className', 'i" + I_Title + "', '" + I_Class + "a');" + G_Quotes + "\n";
				I_Body += "onMouseout=" + G_Quotes + "changeObject('className', 'i" + I_Title + "', '" + I_Class + "n');" + G_Quotes + "\n";
				I_Body += "HREF='" + arguments[i] + "'>" + arguments[i+1] + "</A>";

				// Add Header Line Delimiter
				if(i == 1) I_Body += I_Delimiter;

				// Add Line Break for readability
				I_Body += "\n";
			}

			// Activate the sub-menu layer ----------------------------
			changeObject("className", G_IDIndex, "mlc-on");
			break;

		// Hide the sub-menu layer
		case "off" :
			changeObject("className", G_IDIndex, "mlc-off");
			break;
	};
	I_Body += "<BR><BR>";
	changeObject("innerHTML", G_IDIndex, I_Body);
}

//---------------------------------//
//--- Function    : UTCDate
//--- Date        : 26.05.2001
//--- Parameter   : P_Type     (l = Long : long date, time and location
//---                           s = Short: date&Time no location
//---                           t = Time : Time only)
//---                           u = UTC  : UTC only)
//---               P_Date     (Date to be converted into UTC-Format)
//---               P_UTC      (Time difference to UTC+0)
//---               P_Location (Location information to be included in the format)
//---               P_DLS      (Additional hours for daylight savings)
//--- Return      : Formated date string
//--- Description : Formats a time stamp into 
//---------------------------------//
function UTCDate(P_Type, P_Date, P_UTC, P_Location, P_DLS) {
	var I_Result   = "";                    // Return value
	var I_Month    = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var I_MonthSel = I_Month[P_Date.getMonth()];

	var I_UTC      = String(Math.abs(P_UTC));
	var I_UTC_s    = (Math.abs(P_UTC)<1000)?0:1
	var I_UTC_h    = Number(I_UTC.substr(0,1+I_UTC_s));
		I_UTC_h   *= (P_UTC>=0) ? 1 : -1;
		I_UTC_h    = Math.abs(I_UTC_h + P_DLS);
	var I_UTC_m    = I_UTC.substr(1+I_UTC_s,I_UTC.length);
	var I_Hours    = 0;                     // DLS relevant hours

	var I_ODate    = "";                    // Output date string
	var I_OTime    = "";                    // Output time string
	var I_OUTC     = "";                    // Output UTC string

	// Generate the date string
	// The short Date has the Month abbreviated to 3 characters
	if(P_Type=="s") I_MonthSel = I_MonthSel.substr(0,3);
	I_ODate=P_Date.getDate()+"."+I_MonthSel+"."+P_Date.getYear();

	// Generate the time string
	I_OTime  =(P_Date.getHours()<10)   ? "0" : "";
	I_OTime  =P_Date.getHours()+":"+P_Date.getMinutes();
	I_OTime +=(P_Date.getMinutes()<10) ? "0" : "";

	I_OUTC   ="UTC";
	I_OUTC  +=(P_UTC>=0) ? "+" : "-";

	if(Math.abs(P_UTC)==0) { 
		I_OUTC +="00:00";
	} else {
		I_OUTC +=(Math.abs(P_UTC)<1000) ? "0" : ""; 
		I_OUTC +=I_UTC_h+":"+I_UTC_m;
		I_OUTC +=(P_DLS>0) ? " DLS" : "";
	}

	switch(P_Type) {
		case "u" :
			I_Result  = I_ODate+"  "+I_OTime+"  "+I_OUTC
			break;
		case "t" :
			I_Result  = I_OTime;
			break;
		case "s" :
			I_Result  = I_ODate+"  "+I_OTime+"  "+I_OUTC;
			break;
		case "l" :
			I_Result  = I_ODate+"  "+I_OTime+"  ";
			if(P_Location!="") I_Result +=P_Location+" "
			I_Result += I_OUTC;
			break;
	}
	return I_Result;
 }

//---------------------------------//
//--- Function    : WriteLine
//--- Date        : 10.01.2001
//--- Parameter   : P_Msg        (HTML Page Content)
//---               P_Frame      (Target Frame)
//--- Description : Generate a HTML Page dynamically
//---------------------------------//

function writeLine(P_Msg, P_Frame) {
	if (P_Frame == "") {
		document.open();
		document.write(P_Msg);
		document.close();
	} else {
		var target = eval('parent.' + P_Frame + '.document');
		target.open();
		target.write(P_Msg);
		target.close();
	}
}