/*<![CDATA[*/
/**
 * functions.js - Bibliothek mit uebergreifenden JavaScript Funktionen
 *
 * Copyright (c) 2008    die.interaktiven GmbH & Co. KG
 *                       Agentur für digitale Medien
 *                       Eisenmarkt 1
 *                       35578 Wetzlar
 *                       Germany
 *
 *                       Fon: +49 (0)64 41 / 39 86 19 - 0
 *                       Fax: +49 (0)64 41 / 39 86 19 - 9
 *                       Web: www.die-interaktiven.de
 *
 * Alle Rechte vorbehalten. Unberechtigte Kopie und Weiter-
 * verwendung nicht gestattet.
 *
 */

var DOCUMENT_ROOT = '/';

function doStart()
{
	if(window.location.search.indexOf('druck') != -1)
	{
		setStyle('druck');
	}
	
	setLoginText();
	
	setStatus('GeckoLogic');

	showLightbox();
}

function setLoginText()
{
	try
	{
		document.getElementById('login-username').value = 'E-Mail eingeben';
		
		document.getElementById('login-username').onfocus = (function() { if(this.value == 'E-Mail eingeben') this.value = ''; });
		
		document.getElementById('login-username').onblur = (function() { if(this.value == '') this.value = 'E-Mail eingeben'; });
		
		document.getElementById('login-password').value = 'Passwort eingeben';
		
		document.getElementById('login-password').onfocus = (function() { if(this.value == 'Passwort eingeben') this.value = ''; });
		
		document.getElementById('login-password').onblur = (function() { if(this.value == '') this.value = 'Passwort eingeben'; });
	}
	catch(e)
	{
		void(0);
	}
}

function checkLogin(oForm)
{
	try
	{
		if(trim(oForm.elements['password'].value) == '')
		{
			alert('Bitte geben Sie einen Passwort ein!');
		
			oForm.elements['password'].focus();
		
			return false;
		}
	}
	catch (e)
	{
		void(0);
	}
	
	return true;
}

function doAjaxLoad(iPlz, sUrl)
{
	try
	{
		$("#locationSearchResult").load(sUrl, {plz: iPlz, ajax: '1'}, 
			function (responseText, textStatus, XMLHttpRequest)
			{
				switch(textStatus)
				{
					case "success":	break;
					case "timeout":
					case "error":
					case "notmodified":
					case "parsererror":
					default:	sHtml = '<span class="error"><div class="image"><img src="/fileadmin/geckologic/website/images/locationsearch-map.gif" width="50" height="70" alt="Deutschlandkarte"/></div><div class="content"><h2 class="title">Es ist ein Fehler aufgetreten</h2><div class="text"><p>Bitte starten Sie eine neue Suche.<br/><br/>&raquo; <a href="'+window.location.pathname+'?lsr=1&amp;noscript=1">neue Suche starten</a></p></div><span class="clear">&nbsp;</span></div></span>';
								$("#locationSearchResult").html(sHtml);
				}
			}
		);
	}
	catch(e)
	{
		sHtml = '<span class="error"><div class="image"><img src="/fileadmin/geckologic/website/images/locationsearch-map.gif" width="50" height="70" alt="Deutschlandkarte"/></div><div class="content"><h2 class="title">Es ist ein Fehler aufgetreten</h2><div class="text"><p>Bitte starten Sie eine neue Suche.<br/><br/>&raquo; <a href="'+window.location.pathname+'?lsr=1&amp;noscript=1">neue Suche starten</a></p></div><span class="clear">&nbsp;</span></div></span>';
		$("#locationSearchResult").html(sHtml);
	}
}

function doAjaxReset(sUrl)
{
	try
	{
		$("#locationSearchResult").load(sUrl, {lsr: '1', ajax: '1'}, 
			function (responseText, textStatus, XMLHttpRequest)
			{
				switch(textStatus)
				{
					case "success":	break;
					case "timeout":
					case "error":
					case "notmodified":
					case "parsererror":
					default:	sHtml = '<span class="error"><div class="image"><img src="/fileadmin/geckologic/website/images/locationsearch-map.gif" width="50" height="70" alt="Deutschlandkarte"/></div><div class="content"><h2 class="title">Es ist ein Fehler aufgetreten</h2><div class="text"><p>Bitte starten Sie eine neue Suche.<br/><br/>&raquo; <a href="'+window.location.pathname+'?lsr=1&amp;noscript=1">neue Suche starten</a></p></div><span class="clear">&nbsp;</span></div></span>';
								$("#locationSearchResult").html(sHtml);
				}
			}
		);
	}
	catch(e)
	{
		sHtml = '<span class="error"><div class="image"><img src="/fileadmin/geckologic/website/images/locationsearch-map.gif" width="50" height="70" alt="Deutschlandkarte"/></div><div class="content"><h2 class="title">Es ist ein Fehler aufgetreten</h2><div class="text"><p>Bitte starten Sie eine neue Suche.<br/><br/>&raquo; <a href="'+window.location.pathname+'?lsr=1&amp;noscript=1">neue Suche starten</a></p></div><span class="clear">&nbsp;</span></div></span>';
		$("#locationSearchResult").html(sHtml);
	}
}

function doLocationSearch(oForm, sUrl)
{
	try
	{
		var iPlz = trim(oForm.elements['plz'].value);
		
		if(isNaN(iPlz) || iPlz.length != 5)
		{
			alert('Bitte pr\u00FCfen Sie Ihre eingegebene Postleitzahl.');
			
			oForm.elements['plz'].focus();
			
			return false;
		}
		
		sHtml = '<span class="search"><div class="loading"><img src="/fileadmin/geckologic/website/images/loader-geo.gif" width="24" height="24" alt="Ladebalken" title="Einen Moment bitte, lade ..."/></div></span>';
		
		$("#locationSearchResult").html(sHtml);
		
		//window.setTimeout("doAjaxLoad('"+iPlz+"', '"+sUrl+"')", 1000);
		doAjaxLoad(iPlz, sUrl);
		
		return false;
	}
	catch(e)
	{
		return true;
	}
}

function resetLocationSearch(sUrl)
{
	try
	{
		sHtml = '<span class="search"><div class="loading"><img src="/fileadmin/geckologic/website/images/loader-geo.gif" width="24" height="24" alt="Ladebalken" title="Einen Moment bitte, lade ..."/></div></span>';
		
		$("#locationSearchResult").html(sHtml);
		
		//window.setTimeout("doAjaxReset('"+sUrl+"')", 500);
		doAjaxReset(sUrl);
		
		return false;
	}
	catch(e)
	{
		return true;
	}
}

function doRedirect(oObject)
{
	location.href = oObject.getElementsByTagName('a')[0].href;

	return false;
}

function showDepartment()
{
	return true;
}

function checkHarvest(oForm)
{
	return true;
}

function hidefocus(element)
{ 
	if(element.blur) 
	{ 
		element.blur(); 
	} 
}

function showLightbox()
{
	try
	{
		
		/*
		if(iPageLangCode)
		{
			switch(iPageLangCode)
			{
				case 0: var sTxtImage = 'Bild';
						var sTxtOf = 'von';
						break;

				case 1: var sTxtImage = 'Image';
						var sTxtOf = 'from';
						break;

				case 2: var sTxtImage = 'Image';
						var sTxtOf = 'from';
						break;

				default: var sTxtImage = 'Bild';
						 var sTxtOf = 'von';
						 break;
			}
		}
		*/

		if(location.href.indexOf('/en/') > 0)
		{
			var sTxtImage = 'Image';
			var sTxtOf = 'from';
		}
		else if (location.href.indexOf('/es/') > 0)
		{
			var sTxtImage = 'Image';
			var sTxtOf = 'from';
		}
		else
		{
			var sTxtImage = 'Bild';
			var sTxtOf = 'von';
		}
		

		$('a[@rel*=lightbox]').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.4,
			imageLoading:  'fileadmin/geckovoltaik-panels/website/images/lightbox-ico-loading.gif',
			imageBtnClose: 'fileadmin/geckovoltaik-panels/website/images/lightbox-btn-close.gif',
			imageBtnPrev:  'fileadmin/geckovoltaik-panels/website/images/lightbox-btn-prev.gif',
			imageBtnNext:  'fileadmin/geckovoltaik-panels/website/images/lightbox-btn-next.gif',
			imageBlank:  'fileadmin/geckovoltaik-panels/website/images/lightbox-blank.gif',
			txtImage: sTxtImage,
			txtOf: sTxtOf
       	 });

	}
	catch(e)
	{
		void(0);
	}
}

window.onload = doStart;
/*]]>*/