/* Global Variables */
	var schwarzStatus;
	var weissStatus;
	var zeileStatus;


/* Eisen Keys */
	document.onkeydown = function(e)
		{
		// Capture IE Event
			if(window.event)
				{
				e = window.event;
				}

		// Determine Key Code
			keyCard = e.keyCode;

		// Re-actions
			switch(keyCard)
				{
				case 27 : // Escape
					// Close any open Schwarz Windows
						if(schwarzStatus == '1')
							{
							eisenJS_Schwarz_CLOSE();
							}

					// Close any open Weiss Screens
						if(weissStatus == '1')
							{
							eisenJS_Weiss_CLOSE();
							}

					// Close any open Eisen Axt Zeile
						if(zeileStatus == '1')
							{
							eisenAxt_RESET();
							}

					break;
				}
		}


/* Eisen Knallfenster */

	function eisenJS_KnallFenster(kf_anchor,kf_name,kf_arguments,kf_alternate)
		{
		// Open New Window
			kf_name = window.open(kf_anchor,kf_name,kf_arguments);

		// Test if New Window was Blocked
			if(kf_name == null)
				{
				// Test if Alterate Text was Set
					if(kf_alternate && kf_alternate != '')
						{
						// Alert Alternate Text
							alert(kf_alternate);
							return false;
						}
					else
						{
						// Follow Link
							return true;
						}
				}
			else
				// Focus on New Window
					if(window.focus)
						{
						kf_name.focus()
						return false;
						}
		}


/* Eisen Mail */

	function eisenJS_Mail(em_To,em_From,em_ReplyTo,em_ReturnPath,em_Subject,em_PlainText,em_HTML)
		{
		// Display Verarbeitung
			eisenJS_Verarbeitung_DISPLAY();

		// Create XML HTTP Object
			var req = false;

			if(window.XMLHttpRequest)
				{
				req = new XMLHttpRequest();
				}
			else if(window.ActiveXObject)
				{
				req = new ActiveXObject('Microsoft.XMLHTTP');
				}

		// Configure Asynchronous Action
			req.open('POST','Scripts/EisenPHP_Mailer.php');
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

		// Configure Callback Action
			req.onreadystatechange = function()
				{
				if(req.readyState == '4' && req.status == '200')
					{
					// Remove Verarbeitung
						eisenJS_Verarbeitung_REMOVE();
					}
				}

		// Send Request
			req.send('em_To=' + em_To + '&em_From=' + em_From + '&em_ReplyTo=' + em_ReplyTo + '&em_ReturnPath=' + em_ReturnPath + '&em_Subject=' + em_Subject + '&em_PlainText=' + em_PlainText + '&em_HTML=' + em_HTML);
		}


/* Eisen Verarbeitung */

	function eisenJS_Verarbeitung_DISPLAY()
		{
		document.getElementById('Eisen_Verarbeitung').style.display = 'block';
		}

	function eisenJS_Verarbeitung_REMOVE()
		{
		document.getElementById('Eisen_Verarbeitung').style.display = 'none';
		}


/* Eisen Schwarz */

	function eisenJS_Schwarz_OPEN(sz_x,sz_title,sz_weiss,sz_width,sz_height,sz_method)
		{
		// Hide all Embeds
			// Select all Embed Objects
				embeds = document.getElementsByTagName('embed');

			// Loop through Array of Embed Objects and Hide
				for(var i = 0; i < embeds.length; i++)
					{
					embeds[i].style.visibility = 'hidden';
					}

		// Hide all Objects
			// Select all Object Objects
				objects = document.getElementsByTagName('object');

			// Loop through Array of Object Objects and Hide
				for(var i = 0; i < objects.length; i++)
					{
					objects[i].style.visibility = 'hidden';
					}

		// Determine Dimensions and X/Y Positions
			// Set Default Dimensions if Un-specified
				if(!sz_width)
					{
					sz_width = '400';
					}

				if(!sz_height)
					{
					sz_height = '300';
					}

			// Browser Dimensions
				// Width
					if(window.innerWidth)
						{
						win_width = window.innerWidth;
						}
					else if(document.body.offsetWidth)
						{
						win_width = document.body.offsetWidth;
						}
					else
						{
						win_width = '750';
						}

				// Height
					if(window.innerHeight)
						{
						win_height = window.innerHeight;
						}
					else if(document.documentElement.clientHeight)
						{
						win_height = document.documentElement.clientHeight;
						}
					else
						{
						win_height = '420';
						}

			// X/Y Positions of Schwarz Window
				sz_xPos = (win_width - sz_width) / 2;
				sz_yPos = (win_height - sz_height) / 2;

		// Display Weiss Screen
			if(sz_weiss == '1')
				{
				eisenJS_Weiss_OPEN();
				}

		// Style and Display Schwarz Window
			document.getElementById('Eisen_Schwarz_Main_Content').style.width = sz_width + 'px';
			document.getElementById('Eisen_Schwarz_Main_Content').style.height = sz_height + 'px';
			document.getElementById('Eisen_Schwarz').style.left = sz_xPos + 'px';
			if(document.all)
				{
				document.getElementById('Eisen_Schwarz').style.marginTop = sz_yPos + 'px';
				}
			else
				{
				document.getElementById('Eisen_Schwarz').style.top = sz_yPos + 'px';
				}
			document.getElementById('Eisen_Schwarz').style.display = 'block';

		// Display Schwarz Title
			if(sz_title != '')
				{
				document.getElementById('Eisen_Schwarz_Head_Title').innerHTML = sz_title;
				}

		// Display Schwarz Content
			// Determine if Content is Internal or External
				if(sz_method == 'external')
					{
					// Display Verarbeitung
						eisenJS_Verarbeitung_DISPLAY();

					// Create XML HTTP Object
						var req = false;

						if(window.XMLHttpRequest)
							{
							req = new XMLHttpRequest();
							}
						else if(window.ActiveXObject)
							{
							req = new ActiveXObject('Microsoft.XMLHTTP');
							}

					// Configure Asynchronous Action
						req.open('GET',sz_x);

					// Configure Callback Action
						req.onreadystatechange = function()
							{
							if(req.readyState == '4')
								{
								// Remove Verarbeitung
									eisenJS_Verarbeitung_REMOVE();

								// Generate Output
									switch(req.status)
										{
										case 200 : // Okay
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = req.responseText;
											break;

										case 206 : // Partial Content
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = req.responseText;
											alert('Only part of the information you requested was downloaded.\n\nIf you encounter further errors, please check your internet connection, refresh this page, then try again.');
											break;

										case 400 : // Bad Request
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>There was an error with your request. Please double-check your spelling, syntax and try again.</p>';
											break;

										case 401 : // Un-authorised
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>Please login to view the requested information.</p>';
											break;

										case 403 : // Forbidden
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>The server is too busy to respond to your request at this time. Please try again in a few moments.</p>';
											break;

										case 404 : // File Not Found
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>The information you requested was not found.</p>';
											break;

										case 408 : // Request Time-out
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>Your request has timed-out. Please try again in a few moments.</p>';
											break;

										case 500 : // Internal Server Error
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>Internal server error. Please try again in a few moments.</p>';
											break;

										default: // General Error
											document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '<p>An error occured while responding to your request. Please refresh this page and try again.</p>';
										}
								}
							}

					// Send Request
						req.send(null);
					}
				else if(!sz_method || sz_method == 'internal')
					{
					// Write Internal HTML
						document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = sz_x;
					}

		// Set Schwarz Status Variables
			schwarzStatus = '1';
		}

	function eisenJS_Schwarz_CLOSE()
		{
		// Remove Eisen Schwarz Window
			document.getElementById('Eisen_Schwarz').style.display = 'none';

		// Close Weiss Screen if Open
			if(weissStatus == '1')
				{
				eisenJS_Weiss_CLOSE();
				}

		// Clear Inner HTML
			document.getElementById('Eisen_Schwarz_Head_Title').innerHTML = '';
			document.getElementById('Eisen_Schwarz_Main_Content').innerHTML = '';

		// Show all Embeds
			// Select all Embed Objects
				embeds = document.getElementsByTagName('embed');

			// Loop through Array of Embed Objects and Show
				for(var i = 0; i < embeds.length; i++)
					{
					embeds[i].style.visibility = 'visible';
					}

		// Show all Objects
			// Select all Object Objects
				objects = document.getElementsByTagName('object');

			// Loop through Array of Object Objects and Show
				for(var i = 0; i < objects.length; i++)
					{
					objects[i].style.visibility = 'visible';
					}

		// Re-set Schwarz Status Variable
			schwarzStatus = '0';
		}


/* Eisen Weiss */

	function eisenJS_Weiss_OPEN(x,method)
		{
		// Hide all Forms
			// Select all Form Objects
				forms = document.getElementsByTagName('form');

			// Loop through Array of Form Objects and Hide
				for(var i = 0; i < forms.length; i++)
					{
					forms[i].style.visibility = 'hidden';
					}

		// Hide all Embeds
			// Select all Embed Objects
				embeds = document.getElementsByTagName('embed');

			// Loop through Array of Embed Objects and Hide
				for(var i = 0; i < embeds.length; i++)
					{
					embeds[i].style.visibility = 'hidden';
					}

		// Hide all Objects
			// Select all Object Objects
				objects = document.getElementsByTagName('object');

			// Loop through Array of Object Objects and Hide
				for(var i = 0; i < objects.length; i++)
					{
					objects[i].style.visibility = 'hidden';
					}

		// Display Weiss Screen
			document.getElementById('Eisen_Weiss').style.display = 'block';

		// Display Weiss Content
			// Test if Content was Sent
				if(x && x != '')
					{
					// Generate HTML for Close Link
						y = '<img id="Eisen_Weiss_Close" src="images/Eisen_Weiss_Close.png" alt="X" title="Close" style="float:right; padding:5px; cursor:pointer;" onclick="eisenJS_Weiss_CLOSE();" />';

					// Determine if Content is Internal or External
						if(method == 'external')
							{
							// Display Verarbeitung
								eisenJS_Verarbeitung_DISPLAY();

							// Create XML HTTP Object
								var req = false;

								if(window.XMLHttpRequest)
									{
									req = new XMLHttpRequest();
									}
								else if(window.ActiveXObject)
									{
									req = new ActiveXObject('Microsoft.XMLHTTP');
									}

							// Configure Asynchronous Action
								req.open('GET',x);

							// Configure Callback Action
								req.onreadystatechange = function()
									{
									if(req.readyState == '4')
										{
										// Remove Verarbeitung
											eisenJS_Verarbeitung_REMOVE();

										// Generate Output
											switch(req.status)
												{
												case 200 : // Okay
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + req.responseText;
													break;

												case 206 : // Partial Content
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + req.responseText;
													alert('Only part of the information you requested was downloaded.\n\nIf you encounter further errors, please check your internet connection, refresh this page, then try again.');
													break;

												case 400 : // Bad Request
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'There was an error with your request. Please double-check your spelling, syntax and try again.';
													break;

												case 401 : // Un-authorised
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'Please login to view the requested information.';
													break;

												case 403 : // Forbidden
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'The server is too busy to respond to your request at this time. Please try again in a few moments.';
													break;
		
												case 404 : // File Not Found
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'The information you requested was not found.';
													break;

												case 408 : // Request Time-out
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'Your request has timed-out. Please try again in a few moments.';
													break;

												case 500 : // Internal Server Error
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'Internal server error. Please try again in a few moments.';
													break;

												default: // General Error
													document.getElementById('Eisen_Weiss_Content').innerHTML = y + 'An error occured while responding to your request. Please refresh this page and try again.';
												}
										}
									}

							// Send Request
								req.send(null);
							}
						else if(!method || method == 'internal')
							{
							// Write Internal HTML
								document.getElementById('Eisen_Weiss_Content').innerHTML = y + x;
							}
					}

		// Set Weiss Status Variable
			weissStatus = '1';
		}

	function eisenJS_Weiss_CLOSE()
		{
		// Remove Eisen Weiss Screen
			document.getElementById('Eisen_Weiss').style.display = 'none';

		// Clear Inner HTML
			document.getElementById('Eisen_Weiss_Content').innerHTML = '';

		// Show all Forms
			// Select all Form Objects
				forms = document.getElementsByTagName('form');

			// Loop through Array of Form Objects and Show
				for(var i = 0; i < forms.length; i++)
					{
					forms[i].style.visibility = 'visible';
					}

		// Show all Embeds
			// Select all Embed Objects
				embeds = document.getElementsByTagName('embed');

			// Loop through Array of Embed Objects and Show
				for(var i = 0; i < embeds.length; i++)
					{
					embeds[i].style.visibility = 'visible';
					}

		// Show all Objects
			// Select all Object Objects
				objects = document.getElementsByTagName('object');

			// Loop through Array of Object Objects and Show
				for(var i = 0; i < objects.length; i++)
					{
					objects[i].style.visibility = 'visible';
					}

		// Re-set Weiss Status Variable
			weissStatus = '0';
		}


/* Weiss Back */

	window.onbeforeunload = function()
		{
		if(schwarzStatus == '1')
			{
			eisenJS_Schwarz_CLOSE();
			return false;
			}

		if(weissStatus == '1')
			{
			eisenJS_Weiss_CLOSE();
			return false;
			}
		}